赞 | 59 |
VIP | 321 |
好人卡 | 140 |
积分 | 66 |
经验 | 179075 |
最后登录 | 2024-6-19 |
在线时间 | 1275 小时 |
Lv4.逐梦者 (版主) 百合控
- 梦石
- 0
- 星屑
- 6643
- 在线时间
- 1275 小时
- 注册时间
- 2013-8-21
- 帖子
- 3657
|
本帖最后由 余烬之中 于 2017-10-28 00:47 编辑
来了兴趣,折腾了一阵
以前只给 VA 写过 Bitmap 功能拓展之类的,完全用不上什么 rb_define_module
不过写起来倒也不难,毕竟半云都搞出了 ProjectGap,函数地址直接抄来就行了(由醋瞎黄姬友情提供)
搞了一下午+一晚上,其实主要时间都花在修玄学 msys2 的 mingw32 g++(并且没修好改用 msvc cl 了)
仍然是给 VA 写的,也没什么好解释的,还是一个雏形,只要能够给猫叔提供一点启发我就满足了(逃
编辑:RGSS301.dll,不过理论上自己能搞到函数地址的话通用(逃
未严格测试
// License: RBLv1(https://rpg.blue/thread-403387-1-1.html) // headers #include <windows.h> #include <climits> #include <tchar.h> // defines #define RGSSAPI extern "C" __declspec(dllexport) typedef unsigned long VALUE; typedef unsigned long ID; typedef long SIGNED_VALUE; #define RUBY_FIXNUM_FLAG 0x01 #define Qfalse ((VALUE)0) #define QTrue ((VALUE)2) #define Qnil ((VALUE)4) #define Qundef ((VALUE)6) #define FIX2LONG(x) ((long)(((SIGNED_VALUE)x)>>1)) #define FIX2ULONG(x) (((x>>1))&LONG_MAX) #define FIX2INT(x) ((int)FIX2LONG(x)) #define FIX2UINT(x) ((unsigned int)FIX2ULONG(x)) #define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1|RUBY_FIXNUM_FLAG)) #define FIXNUM_MAX ((unsigned long)(LONG_MAX>>1)) #define FIXNUM_MIN ((long)LONG_MIN>>(int)1) #define FIXNUM_P(x) ((((SIGNED_VALUE)(x))&RUBY_FIXNUM_FLAG)!=0) #define POSFIXABLE(ul) (ul<=FIXNUM_MAX) #define NEGFIXABLE(l) ( l>=FIXNUM_MIN) #define FIXABLE(l) (NEGFIXABLE(l)&&(l<=0||POSFIXABLE(l))) #define def(func, ret, ...) typedef ret(*T##func)(__VA_ARGS__); T##func func // function return type arguments def(RGSSEval, int, const char*); def(rb_define_module, VALUE, const char*); def(rb_define_module_function, void, VALUE, const char*, void*, int); #undef def // extension main VALUE add(VALUE self, VALUE a, VALUE b) { return INT2FIX(FIX2INT(a)+FIX2INT(b)); } RGSSAPI void Test() { VALUE Test = rb_define_module("Test"); rb_define_module_function(Test, "add", add, 2); } // Initialize void Initialize() { HMODULE hRGSSLIB; TCHAR PATH[MAX_PATH]; TCHAR RGSSLIB[MAX_PATH]; GetCurrentDirectory(MAX_PATH, PATH); _tcsncat_s(PATH, MAX_PATH, _T("\\Game.ini"), MAX_PATH); GetPrivateProfileString(_T("Game"), _T("Library"), NULL, RGSSLIB, MAX_PATH, PATH); hRGSSLIB = GetModuleHandle(RGSSLIB); #define setproc(proc, func) func = (T##func)GetProcAddress(hRGSSLIB, #proc) #define setaddr(addr, func) func = (T##func)((DWORD)addr+(DWORD)hRGSSLIB) // set function setproc(RGSSEval, RGSSEval); setaddr(0x5E990, rb_define_module); setaddr(0x5F1E0, rb_define_module_function); #undef setaddr #undef setproc } class Init { public: Init() { Initialize(); } } init;
// License: RBLv1(https://rpg.blue/thread-403387-1-1.html)
// headers
#include <windows.h>
#include <climits>
#include <tchar.h>
// defines
#define RGSSAPI extern "C" __declspec(dllexport)
typedef unsigned long VALUE;
typedef unsigned long ID;
typedef long SIGNED_VALUE;
#define RUBY_FIXNUM_FLAG 0x01
#define Qfalse ((VALUE)0)
#define QTrue ((VALUE)2)
#define Qnil ((VALUE)4)
#define Qundef ((VALUE)6)
#define FIX2LONG(x) ((long)(((SIGNED_VALUE)x)>>1))
#define FIX2ULONG(x) (((x>>1))&LONG_MAX)
#define FIX2INT(x) ((int)FIX2LONG(x))
#define FIX2UINT(x) ((unsigned int)FIX2ULONG(x))
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1|RUBY_FIXNUM_FLAG))
#define FIXNUM_MAX ((unsigned long)(LONG_MAX>>1))
#define FIXNUM_MIN ((long)LONG_MIN>>(int)1)
#define FIXNUM_P(x) ((((SIGNED_VALUE)(x))&RUBY_FIXNUM_FLAG)!=0)
#define POSFIXABLE(ul) (ul<=FIXNUM_MAX)
#define NEGFIXABLE(l) ( l>=FIXNUM_MIN)
#define FIXABLE(l) (NEGFIXABLE(l)&&(l<=0||POSFIXABLE(l)))
#define def(func, ret, ...) typedef ret(*T##func)(__VA_ARGS__); T##func func
// function return type arguments
def(RGSSEval, int, const char*);
def(rb_define_module, VALUE, const char*);
def(rb_define_module_function, void, VALUE, const char*, void*, int);
#undef def
// extension main
VALUE add(VALUE self, VALUE a, VALUE b) {
return INT2FIX(FIX2INT(a)+FIX2INT(b));
}
RGSSAPI void Test() {
VALUE Test = rb_define_module("Test");
rb_define_module_function(Test, "add", add, 2);
}
// Initialize
void Initialize() {
HMODULE hRGSSLIB;
TCHAR PATH[MAX_PATH];
TCHAR RGSSLIB[MAX_PATH];
GetCurrentDirectory(MAX_PATH, PATH);
_tcsncat_s(PATH, MAX_PATH, _T("\\Game.ini"), MAX_PATH);
GetPrivateProfileString(_T("Game"), _T("Library"), NULL, RGSSLIB, MAX_PATH, PATH);
hRGSSLIB = GetModuleHandle(RGSSLIB);
#define setproc(proc, func) func = (T##func)GetProcAddress(hRGSSLIB, #proc)
#define setaddr(addr, func) func = (T##func)((DWORD)addr+(DWORD)hRGSSLIB)
// set function
setproc(RGSSEval, RGSSEval);
setaddr(0x5E990, rb_define_module);
setaddr(0x5F1E0, rb_define_module_function);
#undef setaddr
#undef setproc
}
class Init {
public:
Init() {
Initialize();
}
} init;
|
评分
-
查看全部评分
|