Skip to content

Instantly share code, notes, and snippets.

@syureri
Last active September 25, 2020 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syureri/08270ddab8b818ad5c484d893ca77e0d to your computer and use it in GitHub Desktop.
Save syureri/08270ddab8b818ad5c484d893ca77e0d to your computer and use it in GitHub Desktop.
#include "RGSS3.hpp"
#include <Windows.h>
namespace RGSS3
{
pfn_rb_funcall2 rb_funcall2 = nullptr;
pfn_rb_define_class rb_define_class = nullptr;
pfn_rb_intern rb_intern = nullptr;
pfn_rb_define_module rb_define_module = nullptr;
pfn_rb_define_module_function rb_define_module_function = nullptr;
pfn_rb_define_global_const rb_define_global_const = nullptr;
pfn_rb_eval_string_protect rb_eval_string_protect = nullptr;
pfn_rb_eval_string rb_eval_string = nullptr;
pfn_rb_protect rb_protect = nullptr;
pfn_rb_scan_args rb_scan_args = nullptr;
pfn_rb_class_new_instance rb_class_new_instance = nullptr;
pfn_rb_define_method rb_define_method = nullptr;
pfn_rb_str_new rb_str_new = nullptr;
pfn_rb_ary_new rb_ary_new = nullptr;
pfn_rb_iv_set rb_iv_set = nullptr;
pfn_rb_include_module rb_include_module = nullptr;
pfn_rb_define_global_function rb_define_global_function = nullptr;
pfn_rb_define_const rb_define_const = nullptr;
pfn_rb_define_alloc_func rb_define_alloc_func = nullptr;
pfn_rb_undef_alloc_func rb_undef_alloc_func = nullptr;
pfn_rb_define_singleton_method rb_define_singleton_method = nullptr;
pfn_rb_define_private_method rb_define_private_method = nullptr;
pfn_rb_attr rb_attr = nullptr;
pfn_rb_newobj rb_newobj = nullptr;
pfn_rb_iv_get rb_iv_get = nullptr;
pfn_rb_ary_aref rb_ary_aref = nullptr;
pfn_rb_check_type rb_check_type = nullptr;
pfn_rb_raise rb_raise = nullptr;
pfn_rb_sprintf rb_sprintf = nullptr;
pfn_rb_obj_is_kind_of rb_obj_is_kind_of = nullptr;
pfn_rb_safe_level rb_safe_level = nullptr;
pfn_rb_num2dbl rb_num2dbl = nullptr;
pfn_rgss_load_rgssad_file rgss_load_rgssad_file = nullptr;
pfn_RGSSSetupRTP RGSSSetupRTP = nullptr;
pfn_RGSSSetupFonts RGSSSetupFonts = nullptr;
pfn_RGSSInitialize3 RGSSInitialize3 = nullptr;
pfn_RGSSEval RGSSEval = nullptr;
pfn_RGSSErrorMessage RGSSErrorMessage = nullptr;
pfn_RGSSGetRTPPath RGSSGetRTPPath = nullptr;
pfn_RGSSGetPathWithRTP RGSSGetPathWithRTP = nullptr;
pfn_RGSSFinalize RGSSFinalize = nullptr;
VALUE rb_cNumeric;
VALUE rb_cFloat;
VALUE rb_cString;
VALUE rb_cBasicObject;
VALUE rb_mKernel;
VALUE rb_cClass;
VALUE rb_cObject;
VALUE rb_eIndexError;
VALUE rb_eArgError;
VALUE rb_eTypeError;
void* rgssLib = nullptr;
void Load()
{
HMODULE lib = LoadLibraryW(LR"(System\RGSS301.dll)");
if (!lib)
return;
rgssLib = lib;
DWORD libAddr = reinterpret_cast<DWORD>(lib);
#define RGSS_STRINGIFY_WRAP(x) #x
#define RGSS_STRINGIFY(x) RGSS_STRINGIFY_WRAP(x)
#define RGSS_LOAD_FUNC(name) name = reinterpret_cast<pfn_##name>(GetProcAddress(lib, RGSS_STRINGIFY(name)))
RGSS_LOAD_FUNC(RGSSSetupRTP);
RGSS_LOAD_FUNC(RGSSSetupFonts);
RGSS_LOAD_FUNC(RGSSInitialize3);
RGSS_LOAD_FUNC(RGSSEval);
RGSS_LOAD_FUNC(RGSSErrorMessage);
RGSS_LOAD_FUNC(RGSSGetRTPPath);
RGSS_LOAD_FUNC(RGSSGetPathWithRTP);
RGSS_LOAD_FUNC(RGSSFinalize);
#define RGSS_LOAD_RUBY_FUNC(name) name = reinterpret_cast<pfn_##name>(libAddr + addr_##name);
RGSS_LOAD_RUBY_FUNC(rb_funcall2);
RGSS_LOAD_RUBY_FUNC(rb_define_class);
RGSS_LOAD_RUBY_FUNC(rb_intern);
RGSS_LOAD_RUBY_FUNC(rb_define_module);
RGSS_LOAD_RUBY_FUNC(rb_define_module_function);
RGSS_LOAD_RUBY_FUNC(rb_define_global_const);
RGSS_LOAD_RUBY_FUNC(rb_eval_string_protect);
RGSS_LOAD_RUBY_FUNC(rb_eval_string);
RGSS_LOAD_RUBY_FUNC(rb_protect);
RGSS_LOAD_RUBY_FUNC(rb_scan_args);
RGSS_LOAD_RUBY_FUNC(rb_class_new_instance);
RGSS_LOAD_RUBY_FUNC(rb_define_method);
RGSS_LOAD_RUBY_FUNC(rb_str_new);
RGSS_LOAD_RUBY_FUNC(rb_ary_new);
RGSS_LOAD_RUBY_FUNC(rb_iv_set);
RGSS_LOAD_RUBY_FUNC(rb_include_module);
RGSS_LOAD_RUBY_FUNC(rb_define_global_function);
RGSS_LOAD_RUBY_FUNC(rb_define_const);
RGSS_LOAD_RUBY_FUNC(rb_define_alloc_func);
RGSS_LOAD_RUBY_FUNC(rb_undef_alloc_func);
RGSS_LOAD_RUBY_FUNC(rb_define_singleton_method);
RGSS_LOAD_RUBY_FUNC(rb_define_private_method);
RGSS_LOAD_RUBY_FUNC(rb_attr);
RGSS_LOAD_RUBY_FUNC(rb_newobj);
RGSS_LOAD_RUBY_FUNC(rb_iv_get);
RGSS_LOAD_RUBY_FUNC(rb_ary_aref);
RGSS_LOAD_RUBY_FUNC(rb_check_type);
RGSS_LOAD_RUBY_FUNC(rb_raise);
RGSS_LOAD_RUBY_FUNC(rb_sprintf);
RGSS_LOAD_RUBY_FUNC(rb_obj_is_kind_of);
RGSS_LOAD_RUBY_FUNC(rb_safe_level);
RGSS_LOAD_RUBY_FUNC(rb_num2dbl);
#define RGSS_LOAD_RUBY_CLASS(name) name = *reinterpret_cast<VALUE*>(libAddr + addr_##name)
RGSS_LOAD_RUBY_CLASS(rb_cNumeric);
RGSS_LOAD_RUBY_CLASS(rb_cFloat);
RGSS_LOAD_RUBY_CLASS(rb_cString);
RGSS_LOAD_RUBY_CLASS(rb_cBasicObject);
RGSS_LOAD_RUBY_CLASS(rb_cClass);
RGSS_LOAD_RUBY_CLASS(rb_cObject);
RGSS_LOAD_RUBY_CLASS(rb_mKernel);
RGSS_LOAD_RUBY_CLASS(rb_eIndexError);
RGSS_LOAD_RUBY_CLASS(rb_eArgError);
RGSS_LOAD_RUBY_CLASS(rb_eTypeError);
#undef RGSS_STRINGIFY_WRAP
#undef RGSS_STRINGIFY
#undef RGSS_LOAD_RUBY_CLASS
#undef RGSS_LOAD_RUBY_FUNC
#undef RGSS_LOAD_FUNC
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment