Custom Game.exe Source Code

I was a bit fed up that the only custom Game.exe projects out there were written in simplified Chinese and they are 100% written in 1 main file.

I basically rewrote it in English and hid the windows specific functions (and types) behind some classes, so the bulk of the RGSS stuff is in main.cpp and there is an RGSS3 binding written in RGSS3.h and .cpp as a class.

xiGameSrc.zip

this is by no means tidy code, but hopefully things are easier to navigate compared to the other custom game.exe projects.

This is a visual c++ 2013 project for RGSS3 projects.
Wow. I have way too many things to play around with but this just made top of the list. There's exciting stuff being done these days :o

Potentially daft question, but would this is aid cross-platforming?
Yes it would if someone were to rewrite the DLLs, I can very easily write this to be a cross platform executable but it still relies on the original windows DLLs
Xilef wrote:
Yes it would if someone were to rewrite the DLLs, I can very easily write this to be a cross platform executable but it still relies on the original windows DLLs


Meh, this is why theory and I embedded Ruby directly into an executable we were working on.
I think it's worth re-writing the RGSS libraries so .so and .dylib creation is possible.

I'm at the stage of trying to get Ruby hooks in my own executable right now :U
Also I think there should be some Licensing issues with this. Are you allowed to distribute RGSS DLL with this custom Game.exe like that? One workaround I see is distributing the game without it but making the user download RTP (of which you can probably only use the RGSS DLL).
@Drago del Fato : When we distribute our game, we are allowed, RPG Maker put the RGSS DLL in the installer.
@Xilef : Your program can only launch games in debug mode for the moment x)
But it's a good way to do it: using classes :3
Now for the Ruby hooks you'll have a lot of matters, good luck to find how to properly call the ruby functions...
@Nuri Yuri
Just because they distribute it themselves doesn't mean they allow everyone to distribute them in any way they please. RGSS DLL, in this instance, is being used in a way it was not intended for (i.e. by a custom Game.exe) so they might have a problem with this, I'm not a lawyer though.

@Xilef
What kind of Ruby hooks do you actually mean?
Using this exe or not, the actual game still must be made in RPG Maker, so it shouldn't be a problem. Don't quote me on that though. You're still distributing a game made with RPG Maker, you've just neglected to include their exe to run it and added your own.
Drago del Fato, there are no licensing issues as this is a clean-room program, it has no RGSS code and does not supply any RGSS code, you can use any compatible DLL with this program and it'll be fine.

And yes, the Eval() method in the RGSS3 class will set the $TEST flag to true, change that to false to stop the debug mode.
(You can also just not code anything that uses $TEST, as none of debug mode is hard coded, it can all be taken out.)
Seems the way most people hook with RGSS3 is abuse the Eval function and call some Win32API stuff to initialise their bindings, which is not ideal at all.

I remember discussing the idea of having custom DLL code running on a thread with a messaging system between RGSS and the thread so as to run the Win32API with little over-head, sounds a bit painful but if we can't find the addresses of the other ruby functions:
viewtopic.php?f=48&t=75669

Some help with the guess-work would be cool...!
  1. http://www.opensource.apple.com/source/ ... variable.c
  2. http://rxr.whitequark.org/mri/source/ex ... 1.8.7-p370
  3. optlink
  4.  
  5. //Ruby
  6. rb_warning
  7. rb_warn  //rb_warn("no super class for `%s', Object assumed", name);
  8. rb_raise
  9. rb_raise2 10026210 //rb_raise(rb_eTypeError, "can't make subclass of Class");
  10. rb_name_error  //rb_name_error(id, "%s is already defined", name)
  11. rb_to_id
  12. global_id
  13. rb_global_entry
  14. rb_intern 100481B0
  15. rb_id2name
  16. rb_check_type
  17. rb_secure
  18. rb_alias 10031AE0
  19. rb_attr
  20. rb_fatal
  21. rb_block_given_p 10069E00
  22. //rb_need_block 10069E30
  23. LONG2NUM
  24. rb_yield
  25. rb_equal
  26. rb_check_type_string
  27. rb_class_new_instance
  28. rb_class_superclass
  29. rb_define_alloc_func 10032C00
  30. rb_undef_alloc_func
  31. rb_data_object_alloc
  32. rb_obj_alloc
  33. rb_obj_call_init
  34. //rb_add_method
  35. str_new 100361A0 //ATTENTION METHODE D4APPEL DIFFERENTE ! __fastcall ? Nop, c'est pas du fastcall c'est de l'optimisation de gros bourrin.
  36. rb_str_new 10036290 //ATTENTION METHODE D4APPEL DIFFERENTE !
  37. rb_str_new2 10036340 //ATTENTION METHODE D4APPEL DIFFERENTE !
  38. ary_new 10088D20
  39. rb_ary_new 10088DC0 //???
  40. rb_ary_new2 10088DA0
  41. rb_ary_new3 10088DD0
  42. rb_ary_new4 10088E50
  43. ---
  44.  
  45. //
  46. rgss_print
  47. rgss_p
  48. //rgss_init
  49.  
  50.  
  51. //Eval
  52. rb_f_eval
  53. eval
  54. rb_eval_string
  55. ---
  56.  
  57. <!BASIC RUBY FUNC>
  58. //String
  59. rb_str_cmp_m  1
  60. rb_str_equal  1
  61. rb_str_hash_m  0
  62. rb_str_casecmp  1
  63. rb_str_plus  1
  64. rb_str_times  1
  65. rb_str_format_m  1
  66. rb_str_aref_m  -1
  67. rb_str_aset_m  -1
  68. rb_str_insert  2
  69. rb_str_length  0
  70. rb_str_empty  0
  71. rb_str_match  1
  72. rb_str_match_m  1
  73. rb_str_succ  0
  74. rb_str_succ_bang  0
  75. rb_str_upto_m  -1
  76. rb_str_index_m  -1
  77. rb_str_rindex_m  -1
  78. rb_str_replace  1
  79. rb_str_to_i  -1
  80. rb_str_to_f  0
  81. rb_str_to_s  0
  82. rb_str_inspect  0
  83. rb_str_dump  0
  84. rb_str_upcase  0
  85. rb_str_downcase  0
  86. rb_str_capitalize  0
  87. rb_str_swapcase  0
  88. rb_str_upcase_bang  0
  89. rb_str_downcase_bang  0
  90. rb_str_capitalize_bang  0
  91. rb_str_swapcase_bang  0
  92. rb_str_hex  0
  93. rb_str_oct  0
  94. rb_str_split_m  -1
  95. rb_str_reverse  0
  96. rb_str_reverse_bang  0
  97. rb_str_concat  1
  98. rb_str_crypt  1
  99. rb_str_intern  0
  100. rb_str_include  1
  101. rb_str_scan  1
  102. rb_str_ljust  -1
  103. rb_str_rjust  -1
  104. rb_str_center  -1
  105. rb_str_sub  -1
  106. rb_str_gsub  -1
  107. rb_str_chop  0
  108. rb_str_chomp  -1
  109. rb_str_strip  0
  110. rb_str_lstrip  0
  111. rb_str_rstrip  0
  112. rb_str_sub_bang  -1
  113. rb_str_gsub_bang  -1
  114. rb_str_chop_bang  0
  115. rb_str_chomp_bang  -1
  116. rb_str_strip_bang  0
  117. rb_str_lstrip_bang  0
  118. rb_str_rstrip_bang  0
  119. rb_str_tr  2
  120. rb_str_tr_s  2
  121. rb_str_delete  -1
  122. rb_str_squeeze  -1
  123. rb_str_count  -1
  124. rb_str_tr_bang  2
  125. rb_str_tr_s_bang  2
  126. rb_str_delete_bang  -1
  127. rb_str_squeeze_bang  -1
  128. rb_str_each_line  -1
  129.  
  130.  
  131. ---
  132.  
  133. //Array
  134. rb_ary_aref  -1
  135. rb_ary_fetch  -1
  136. rb_ary_index  -1
  137. rb_ary_rindex  -1
  138. rb_ary_aset  -1
  139. rb_ary_insert  -1
  140. rb_ary_each_index  0
  141. rb_ary_reverse_each  0
  142. rb_ary_length  0
  143. rb_ary_empty_p  0
  144. //rb_ary_reverse
  145. rb_ary_reverse_bang  0
  146. rb_ary_reverse_m  0
  147. rb_ary_transpose  0
  148. rb_ary_replace  1
  149. rb_ary_fill  -1
  150. rb_ary_times  1
  151. rb_ary_equal  1
  152. rb_ary_to_s  0
  153. rb_ary_inspect  0
  154. rb_ary_eql  1
  155. rb_ary_at  1
  156. rb_ary_first  -1
  157. rb_ary_last  -1
  158. rb_ary_concat  1
  159. rb_ary_push_m  -1
  160. rb_ary_unshift  -1
  161. rb_ary_each  0
  162. rb_ary_join_m  -1
  163. rb_ary_sort  0
  164. rb_ary_sort_bang  0
  165. rb_ary_collect  0
  166. rb_ary_collect_bang  0
  167. rb_ary_delete  1
  168. rb_ary_delete_at_m  1
  169. rb_ary_reject  0
  170. rb_ary_reject_bang  0
  171. rb_ary_clear  0
  172. rb_ary_includes  1
  173. rb_ary_compact  0
  174. rb_ary_compact_bang  0
  175. ---
  176.  
  177. //Hash
  178. rb_hash_equal  1
  179. rb_hash_aref  1
  180. rb_hash_aset  2
  181. rb_hash_default  -1
  182. rb_hash_set_default  1
  183. rb_hash_index  1
  184. rb_hash_indexes  -1
  185. rb_hash_size  0
  186. rb_hash_empty_p  0
  187. rb_hash_each  0
  188. rb_hash_sort  0
  189. rb_hash_keys  0
  190. rb_hash_values  0
  191. rb_hash_shift  0
  192. rb_hash_delete  1
  193. rb_hash_select  0
  194. rb_hash_reject  0
  195. rb_hash_reject_bang  0
  196. rb_hash_clear  0
  197. rb_hash_invert  0
  198. rb_hash_has_key  1
  199. rb_hash_has_value  1
  200. <!BASIC RUBY FUNC>
  201.  
  202. //Class Variable
  203. rb_mod_remove_cvar
  204. rb_define_class_variable
  205. rb_cvar_defined
  206. mod_av_set
  207. rb_cvar_get
  208. rb_cvar_set
  209. rb_cv_get
  210. rb_cv_set
  211. ---
  212.  
  213. //Constantes
  214. rb_const_set
  215. rb_define_const
  216. rb_const_defined_at
  217. rb_const_defined
  218. rb_const_defined_from
  219. rb_const_defined_0
  220. rb_mod_remove_const
  221. rb_const_get_at
  222. rb_const_get
  223. rb_const_get_from
  224. rb_const_get_0
  225. rb_define_global_const
  226. ---
  227.  
  228. //Instance Variable
  229. rb_ivar_get
  230. rb_attr_get
  231. rb_ivar_set
  232. rb_ivar_defined
  233. rb_obj_remove_instance_variable
  234. rb_iv_get
  235. rb_iv_set
  236. ---
  237.  
  238. //Global Variable
  239. rb_gv_set
  240. rb_gv_get
  241. rb_gvar_defined
  242. ---
  243.  
  244. //Object
  245. rb_obj_clone
  246. rb_obj_dup
  247. ---
  248.  
  249. //Class
  250. rb_funcall2
  251. rb_funcall3
  252. rb_define_sigleton_method 1005F050
  253. rb_define_method 1005EDE0
  254. rb_define_global_function 1005F0E0
  255. rb_define_module
  256. rb_define_class_under
  257. rb_define_class 1005E5B0
  258. rb_define_module_under
  259. rb_class_new
  260. rb_define_class_id
  261. rb_class_boot
  262. rb_set_class_path
  263. rb_class_inherited
  264. rb_mod_included_modules
  265. rb_mod_include_p
  266. rb_mod_ancestors
  267. rb_singleton_class
  268. rb_define_private_method 1005EE10
  269. rb_define_module_function
  270. rb_define_alias 1005F130
  271. rb_define_attr
  272. rb_scan_args
  273. rb_undef_method 1005EE40
  274. rb_include_module 1005EA30
  275. ---
  276.  
  277. ruby_xmalloc
  278. ruby_xrealloc
  279. ruby_xfree 100563E0
  280. ruby_xcalloc
  281.  
  282. //ENDEF FUNCT//
  283.  
  284.  
  285. //T_NYANYANYA
  286. T_Class=
  287. T_Module=
  288.  
  289.  
  290. Macros :
  291. #define FIXNUM_P(a) a&0x00000001
  292. #define SYMBOL_P(a) (a&0x000000FF)==0x0e
  293. #define NIL_P(a) a==0x04
  294.  
  295. RGSSInitialize 100035C0
  296. RGSSGameMain 100036E0
  297. RGSSSetupRTP 10003740
  298.  
  299.  
  300. Classes
  301.     kAudio ,
  302.     kGraphics ,
  303.     kInput ,
  304.     kObject 102AC098,
  305.     kModule 102AC08C,
  306.     kClass ,
  307.     kKernel 102AC080,
  308.     kNilClass ,
  309.     kSymbol ,
  310.     kTrueClass ,
  311.     kData ,
  312.     kFalseClass ,
  313.     kArray 102ABFE8,
  314.     kString 102AC070,
  315.     kFloat ,
  316.     kInteger ,
  317.     kNumeric ,
  318.     kSprite ,
  319.     kBitmap ,
  320.     kViewport ,
  321.     kRect ,
  322.     kTone ,
  323.     kColor ,
  324.     kFont ,
  325.   eTypeError ,
  326.   eArgError 102AC108,
  327.   eIndexError ,
  328.   eException ,
  329.   eStandardError ,
  330.   kHash
Expand to see the code.

I've shearched some functions, rb_define_sigleton_method, rb_define_method , rb_define_global_function , rb_define_class should work with the __cdecl calling convention...
Nuri Yuri wrote:
I've shearched some functions, rb_define_sigleton_method, rb_define_method , rb_define_global_function , rb_define_class should work with the __cdecl calling convention...

I can see that what you've posted is for RGSS1xx, we're dealing with RGSS301 which as you know is pretty well locked down (I have seen some assembly style function calling used around it [__fastcall maybe?], so that might be something I'll try next).

All I can find in RGSS301 that are C declared are the functions below:
Content Hidden Show
RGSSAddRTPPath 0x100046d0 0x000046d0 1 (0x1) RGSS301.dll
RGSSAudioFinalize 0x100036b0 0x000036b0 2 (0x2) RGSS301.dll
RGSSAudioInitialize 0x10003610 0x00003610 3 (0x3) RGSS301.dll
RGSSClearRTPPath 0x100046f0 0x000046f0 4 (0x4) RGSS301.dll
RGSSErrorMessage 0x100040f0 0x000040f0 5 (0x5) RGSS301.dll
RGSSErrorType 0x100040d0 0x000040d0 6 (0x6) RGSS301.dll
RGSSEval 0x10003760 0x00003760 7 (0x7) RGSS301.dll
RGSSFinalize 0x10003600 0x00003600 8 (0x8) RGSS301.dll
RGSSGameMain 0x10003700 0x00003700 10 (0xa) RGSS301.dll
RGSSGC 0x10004720 0x00004720 9 (0x9) RGSS301.dll
RGSSGetBool 0x10003790 0x00003790 11 (0xb) RGSS301.dll
RGSSGetDouble 0x10003840 0x00003840 12 (0xc) RGSS301.dll
RGSSGetInt 0x100037c0 0x000037c0 13 (0xd) RGSS301.dll
RGSSGetPathWithRTP 0x10004120 0x00004120 14 (0xe)
RGSSGetRTPPath 0x100046b0 0x000046b0 15 (0xf)
RGSSGetStringACP 0x10003a00 0x00003a00 16 (0x10)
RGSSGetStringUTF16 0x10003b70 0x00003b70 17 (0x11)


I tried a brute-force approach with testing every pointer on the DLL from 0x0 to 0x10FFFFFF for the rb_define_module and running an in-game script that detects for the module to exist but none of those pointers worked, so I'm out of ideas time to do some analysis of __fastcall.
You're using RGSS301.dll XD
My pointers are for RGSS300.dll, can you send me RGSS301.dll ?

You'll never find anything by using Ruby, eval should probably not call rb_define_anything but rb_module_new that won't help you to create a module because it's like Module.new x)

Edit : Just forget about _fastcall, it isn't fastcall it's some new optimisation feature that send arguments in random register before calling the function when the function isn't exported.
RGSS301.dll comes with VXAce, I was unable to locate 300, care to send me 300?

Here's 301
www.battleworldrpg.net/hbgames/RGSS301.dll

Of course, I'd rather get this working on 301 because that's the version that every gets these days when they use VXAce
I got RMVX.Ace the day it was released so I've the RGSS300.dll x)
https://www.mediafire.com/?gbw8yb2gk80o7cl

I'll watch how it's done in RGSS301.dll ^^
From looking at those address I can see that my brute force programming detected ruby functions around those RGSS10X pointers you posted earlier, but I had no way of testing their functions, how did you figure them out for RMXP?

Edit: meant to write 300 not 10x, still getting confused with all these DLLs hanging around
Well those are standard ruby API functions which are always incorporated when you embed Ruby and they haven't changed much even today (I'm working currently with Ruby 2.1.0 on my engine and I didn't have to change a thing) so there is high chance that you can use them even here, but if they aren't in export table of the DLL there isn't much you can do about it, also take note that those are C functions, not C++.
The RGSS and Ruby functions are programmed in C/C++ so to make ruby functions work, the rb_define_method/class/module/etc... function should be called somewhere in the RGSS DLL.

For the functions like ruby_xfree, ruby_xmalloc or the functions like rb_gv_get that are called nowhere, I just watch something that looks like the assembly version of them.
To test them :
  1. typedef VALUE (*frb_gv_set)(char* name,VALUE* val);
  2. //(char* name,VALUE* val);
  3. #define rb_gv_set(name,val) ((frb_gv_set)0x100B7300)(name,val)
Expand to see the code.

  1.     //Validation du mode de fonctionnement du RGSS
  2.     if(wcscmp(lpCmdLine, TEXT("btest")) == 0)
  3.     {BattleTest=2;}
  4.     rb_gv_set("BTEST",&BattleTest);
Expand to see the code.

I started to search function's pointers in RGSS301 :
  1. http://www.opensource.apple.com/source/ ... variable.c
  2. http://rxr.whitequark.org/mri/source/ex ... 1.8.7-p370
  3. optlink
  4.  
  5. //Ruby
  6. rb_warning
  7. rb_warn  //rb_warn("no super class for `%s', Object assumed", name);
  8. rb_raise
  9. rb_raise2 //rb_raise(rb_eTypeError, "can't make subclass of Class");
  10. rb_name_error  //rb_name_error(id, "%s is already defined", name)
  11. rb_to_id
  12. global_id
  13. rb_global_entry
  14. rb_intern
  15. rb_intern2 100483E0 //rb_intern2("str",size)
  16. rb_id2name
  17. rb_check_type
  18. rb_secure
  19. rb_alias
  20. rb_attr
  21. rb_fatal
  22. rb_block_given_p
  23. //rb_need_block
  24. LONG2NUM
  25. rb_yield
  26. rb_equal
  27. rb_check_type_string
  28. rb_class_new_instance
  29. rb_class_superclass
  30. rb_define_alloc_func 10032E20
  31. rb_undef_alloc_func 100316A0
  32. rb_data_object_alloc
  33. rb_obj_alloc
  34. rb_obj_call_init
  35. //rb_add_method
  36. str_new //ATTENTION METHODE D4APPEL DIFFERENTE ! __fastcall ? Nop, c'est pas du fastcall c'est de l'optimisation de gros bourrin.
  37. rb_str_new //ATTENTION METHODE D4APPEL DIFFERENTE !
  38. rb_str_new2 //ATTENTION METHODE D4APPEL DIFFERENTE !
  39. ary_new
  40. rb_ary_new //???
  41. rb_ary_new2
  42. rb_ary_new3
  43. rb_ary_new4
  44. ---
  45.  
  46. //
  47. rgss_print
  48. rgss_p
  49. //rgss_init
  50.  
  51.  
  52. //Eval
  53. rb_f_eval
  54. eval
  55. rb_eval_string
  56. ---
  57.  
  58. <!BASIC RUBY FUNC>
  59. //String
  60. rb_str_cmp_m  1
  61. rb_str_equal  1
  62. rb_str_hash_m  0
  63. rb_str_casecmp  1
  64. rb_str_plus  1
  65. rb_str_times  1
  66. rb_str_format_m  1
  67. rb_str_aref_m  -1
  68. rb_str_aset_m  -1
  69. rb_str_insert  2
  70. rb_str_length  0
  71. rb_str_empty  0
  72. rb_str_match  1
  73. rb_str_match_m  1
  74. rb_str_succ  0
  75. rb_str_succ_bang  0
  76. rb_str_upto_m  -1
  77. rb_str_index_m  -1
  78. rb_str_rindex_m  -1
  79. rb_str_replace  1
  80. rb_str_to_i  -1
  81. rb_str_to_f  0
  82. rb_str_to_s  0
  83. rb_str_inspect  0
  84. rb_str_dump  0
  85. rb_str_upcase  0
  86. rb_str_downcase  0
  87. rb_str_capitalize  0
  88. rb_str_swapcase  0
  89. rb_str_upcase_bang  0
  90. rb_str_downcase_bang  0
  91. rb_str_capitalize_bang  0
  92. rb_str_swapcase_bang  0
  93. rb_str_hex  0
  94. rb_str_oct  0
  95. rb_str_split_m  -1
  96. rb_str_reverse  0
  97. rb_str_reverse_bang  0
  98. rb_str_concat  1
  99. rb_str_crypt  1
  100. rb_str_intern  0
  101. rb_str_include  1
  102. rb_str_scan  1
  103. rb_str_ljust  -1
  104. rb_str_rjust  -1
  105. rb_str_center  -1
  106. rb_str_sub  -1
  107. rb_str_gsub  -1
  108. rb_str_chop  0
  109. rb_str_chomp  -1
  110. rb_str_strip  0
  111. rb_str_lstrip  0
  112. rb_str_rstrip  0
  113. rb_str_sub_bang  -1
  114. rb_str_gsub_bang  -1
  115. rb_str_chop_bang  0
  116. rb_str_chomp_bang  -1
  117. rb_str_strip_bang  0
  118. rb_str_lstrip_bang  0
  119. rb_str_rstrip_bang  0
  120. rb_str_tr  2
  121. rb_str_tr_s  2
  122. rb_str_delete  -1
  123. rb_str_squeeze  -1
  124. rb_str_count  -1
  125. rb_str_tr_bang  2
  126. rb_str_tr_s_bang  2
  127. rb_str_delete_bang  -1
  128. rb_str_squeeze_bang  -1
  129. rb_str_each_line  -1
  130.  
  131.  
  132. ---
  133.  
  134. //Array
  135. rb_ary_aref  -1
  136. rb_ary_fetch  -1
  137. rb_ary_index  -1
  138. rb_ary_rindex  -1
  139. rb_ary_aset  -1
  140. rb_ary_insert  -1
  141. rb_ary_each_index  0
  142. rb_ary_reverse_each  0
  143. rb_ary_length  0
  144. rb_ary_empty_p  0
  145. //rb_ary_reverse
  146. rb_ary_reverse_bang  0
  147. rb_ary_reverse_m  0
  148. rb_ary_transpose  0
  149. rb_ary_replace  1
  150. rb_ary_fill  -1
  151. rb_ary_times  1
  152. rb_ary_equal  1
  153. rb_ary_to_s  0
  154. rb_ary_inspect  0
  155. rb_ary_eql  1
  156. rb_ary_at  1
  157. rb_ary_first  -1
  158. rb_ary_last  -1
  159. rb_ary_concat  1
  160. rb_ary_push_m  -1
  161. rb_ary_unshift  -1
  162. rb_ary_each  0
  163. rb_ary_join_m  -1
  164. rb_ary_sort  0
  165. rb_ary_sort_bang  0
  166. rb_ary_collect  0
  167. rb_ary_collect_bang  0
  168. rb_ary_delete  1
  169. rb_ary_delete_at_m  1
  170. rb_ary_reject  0
  171. rb_ary_reject_bang  0
  172. rb_ary_clear  0
  173. rb_ary_includes  1
  174. rb_ary_compact  0
  175. rb_ary_compact_bang  0
  176. ---
  177.  
  178. //Hash
  179. rb_hash_equal  1
  180. rb_hash_aref  1
  181. rb_hash_aset  2
  182. rb_hash_default  -1
  183. rb_hash_set_default  1
  184. rb_hash_index  1
  185. rb_hash_indexes  -1
  186. rb_hash_size  0
  187. rb_hash_empty_p  0
  188. rb_hash_each  0
  189. rb_hash_sort  0
  190. rb_hash_keys  0
  191. rb_hash_values  0
  192. rb_hash_shift  0
  193. rb_hash_delete  1
  194. rb_hash_select  0
  195. rb_hash_reject  0
  196. rb_hash_reject_bang  0
  197. rb_hash_clear  0
  198. rb_hash_invert  0
  199. rb_hash_has_key  1
  200. rb_hash_has_value  1
  201. <!BASIC RUBY FUNC>
  202.  
  203. //Class Variable
  204. rb_mod_remove_cvar
  205. rb_define_class_variable
  206. rb_cvar_defined
  207. mod_av_set
  208. rb_cvar_get
  209. rb_cvar_set
  210. rb_cv_get
  211. rb_cv_set
  212. ---
  213.  
  214. //Constantes
  215. rb_const_set
  216. rb_define_const
  217. rb_const_defined_at
  218. rb_const_defined
  219. rb_const_defined_from
  220. rb_const_defined_0
  221. rb_mod_remove_const
  222. rb_const_get_at
  223. rb_const_get
  224. rb_const_get_from
  225. rb_const_get_0
  226. rb_define_global_const 10068320
  227. ---
  228.  
  229. //Instance Variable
  230. rb_ivar_get
  231. rb_attr_get
  232. rb_ivar_set
  233. rb_ivar_defined
  234. rb_obj_remove_instance_variable
  235. rb_iv_get
  236. rb_iv_set
  237. ---
  238.  
  239. //Global Variable
  240. rb_gv_set
  241. rb_gv_get
  242. rb_gvar_defined
  243. ---
  244.  
  245. //Object
  246. rb_obj_clone
  247. rb_obj_dup
  248. ---
  249.  
  250. //Class
  251. rb_funcall2
  252. rb_funcall3
  253. rb_define_sigleton_method 1005F1E0
  254. rb_define_method 1005EF70
  255. rb_define_global_function 1005F270
  256. rb_define_module 1005E990
  257. rb_define_class_under
  258. rb_define_class 1005E740
  259. rb_define_module_under
  260. rb_class_new
  261. rb_define_class_id
  262. rb_class_boot
  263. rb_set_class_path
  264. rb_class_inherited
  265. rb_mod_included_modules
  266. rb_mod_include_p
  267. rb_mod_ancestors
  268. rb_singleton_class
  269. rb_define_private_method 1005EFA0
  270. rb_define_module_function
  271. rb_define_alias 1005F2C0
  272. rb_define_attr
  273. rb_scan_args
  274. rb_undef_method 1005EFD0
  275. rb_include_module 1005EBC0
  276. ---
  277.  
  278. ruby_xmalloc
  279. ruby_xrealloc
  280. ruby_xfree
  281. ruby_xcalloc
  282.  
  283. //ENDEF FUNCT//
  284.  
  285.  
  286.  
  287. Macros :
  288. #define FIXNUM_P(a) a&0x00000001
  289. #define SYMBOL_P(a) (a&0x000000FF)==0x0e
  290. #define NIL_P(a) a==0x04
  291.  
  292. RGSSInitialize
  293. RGSSGameMain
  294. RGSSSetupRTP
  295.  
  296.  
  297. Classes
  298.     kAudio ,
  299.     kGraphics ,
  300.     kInput ,
  301.     kObject 102AC098,
  302.     kModule ,
  303.     kClass ,
  304.     kKernel 102AC080,
  305.     kNilClass 102AC090,
  306.     kSymbol ,
  307.     kTrueClass 102AC094,
  308.     kData 102AC078,
  309.     kFalseClass 102AC088,
  310.     kArray 102ABFE8,
  311.     kString ,
  312.     kFloat ,
  313.     kInteger ,
  314.     kNumeric ,
  315.     kSprite ,
  316.     kBitmap ,
  317.     kViewport ,
  318.     kRect ,
  319.     kTone ,
  320.     kColor ,
  321.     kFont ,
  322.   eTypeError ,
  323.   eArgError ,
  324.   eIndexError ,
  325.   eException ,
  326.   eStandardError ,
  327.   kHash
Expand to see the code.

@Drago del Fato : Using ruby API will make your Game crash, I tried Win32API.new("socket.so","Init_Socket","","").call() looong time ago and the result was "RGSS Player a cessé de fonctionner.". But it's right : the arguments of the functions didn't change.
@Nuri Yuri
When I was saying Ruby API I didn't mean using it from RGSS (btw it's not possible to load a mingw/gcc compiled .so library with MSVC compiled Ruby. Took me a while to learn that one. :/). I meant using it directly from Game.exe (i.e. the same thing you just wrote).

---

It might be useful to know that there is a workaround to loading ruby extensions with embedded ruby, it's just that they have to be loaded statically (which also means a lot of fiddling with ruby code). I currently can load both DL (had to change the code a little) and Zlib extensions statically (but not Socket extension though, but I've coded my own network interaction, I'm not giving up though xD). Just be sure to use extern "C" { } to specify the call to Init_extname() while in C++.
Nuri Yuri wrote:
The RGSS and Ruby functions are programmed in C/C++ so to make ruby functions work, the rb_define_method/class/module/etc... function should be called somewhere in the RGSS DLL.

For the functions like ruby_xfree, ruby_xmalloc or the functions like rb_gv_get that are called nowhere, I just watch something that looks like the assembly version of them.
To test them :
  1. typedef VALUE (*frb_gv_set)(char* name,VALUE* val);
  2. //(char* name,VALUE* val);
  3. #define rb_gv_set(name,val) ((frb_gv_set)0x100B7300)(name,val)
Expand to see the code.

  1.     //Validation du mode de fonctionnement du RGSS
  2.     if(wcscmp(lpCmdLine, TEXT("btest")) == 0)
  3.     {BattleTest=2;}
  4.     rb_gv_set("BTEST",&BattleTest);
Expand to see the code.

I started to search function's pointers in RGSS301 :
  1. http://www.opensource.apple.com/source/ ... variable.c
  2. http://rxr.whitequark.org/mri/source/ex ... 1.8.7-p370
  3. optlink
  4.  
  5. //Ruby
  6. rb_warning
  7. rb_warn  //rb_warn("no super class for `%s', Object assumed", name);
  8. rb_raise
  9. rb_raise2 //rb_raise(rb_eTypeError, "can't make subclass of Class");
  10. rb_name_error  //rb_name_error(id, "%s is already defined", name)
  11. rb_to_id
  12. global_id
  13. rb_global_entry
  14. rb_intern
  15. rb_intern2 100483E0 //rb_intern2("str",size)
  16. rb_id2name
  17. rb_check_type
  18. rb_secure
  19. rb_alias
  20. rb_attr
  21. rb_fatal
  22. rb_block_given_p
  23. //rb_need_block
  24. LONG2NUM
  25. rb_yield
  26. rb_equal
  27. rb_check_type_string
  28. rb_class_new_instance
  29. rb_class_superclass
  30. rb_define_alloc_func 10032E20
  31. rb_undef_alloc_func 100316A0
  32. rb_data_object_alloc
  33. rb_obj_alloc
  34. rb_obj_call_init
  35. //rb_add_method
  36. str_new //ATTENTION METHODE D4APPEL DIFFERENTE ! __fastcall ? Nop, c'est pas du fastcall c'est de l'optimisation de gros bourrin.
  37. rb_str_new //ATTENTION METHODE D4APPEL DIFFERENTE !
  38. rb_str_new2 //ATTENTION METHODE D4APPEL DIFFERENTE !
  39. ary_new
  40. rb_ary_new //???
  41. rb_ary_new2
  42. rb_ary_new3
  43. rb_ary_new4
  44. ---
  45.  
  46. //
  47. rgss_print
  48. rgss_p
  49. //rgss_init
  50.  
  51.  
  52. //Eval
  53. rb_f_eval
  54. eval
  55. rb_eval_string
  56. ---
  57.  
  58. <!BASIC RUBY FUNC>
  59. //String
  60. rb_str_cmp_m  1
  61. rb_str_equal  1
  62. rb_str_hash_m  0
  63. rb_str_casecmp  1
  64. rb_str_plus  1
  65. rb_str_times  1
  66. rb_str_format_m  1
  67. rb_str_aref_m  -1
  68. rb_str_aset_m  -1
  69. rb_str_insert  2
  70. rb_str_length  0
  71. rb_str_empty  0
  72. rb_str_match  1
  73. rb_str_match_m  1
  74. rb_str_succ  0
  75. rb_str_succ_bang  0
  76. rb_str_upto_m  -1
  77. rb_str_index_m  -1
  78. rb_str_rindex_m  -1
  79. rb_str_replace  1
  80. rb_str_to_i  -1
  81. rb_str_to_f  0
  82. rb_str_to_s  0
  83. rb_str_inspect  0
  84. rb_str_dump  0
  85. rb_str_upcase  0
  86. rb_str_downcase  0
  87. rb_str_capitalize  0
  88. rb_str_swapcase  0
  89. rb_str_upcase_bang  0
  90. rb_str_downcase_bang  0
  91. rb_str_capitalize_bang  0
  92. rb_str_swapcase_bang  0
  93. rb_str_hex  0
  94. rb_str_oct  0
  95. rb_str_split_m  -1
  96. rb_str_reverse  0
  97. rb_str_reverse_bang  0
  98. rb_str_concat  1
  99. rb_str_crypt  1
  100. rb_str_intern  0
  101. rb_str_include  1
  102. rb_str_scan  1
  103. rb_str_ljust  -1
  104. rb_str_rjust  -1
  105. rb_str_center  -1
  106. rb_str_sub  -1
  107. rb_str_gsub  -1
  108. rb_str_chop  0
  109. rb_str_chomp  -1
  110. rb_str_strip  0
  111. rb_str_lstrip  0
  112. rb_str_rstrip  0
  113. rb_str_sub_bang  -1
  114. rb_str_gsub_bang  -1
  115. rb_str_chop_bang  0
  116. rb_str_chomp_bang  -1
  117. rb_str_strip_bang  0
  118. rb_str_lstrip_bang  0
  119. rb_str_rstrip_bang  0
  120. rb_str_tr  2
  121. rb_str_tr_s  2
  122. rb_str_delete  -1
  123. rb_str_squeeze  -1
  124. rb_str_count  -1
  125. rb_str_tr_bang  2
  126. rb_str_tr_s_bang  2
  127. rb_str_delete_bang  -1
  128. rb_str_squeeze_bang  -1
  129. rb_str_each_line  -1
  130.  
  131.  
  132. ---
  133.  
  134. //Array
  135. rb_ary_aref  -1
  136. rb_ary_fetch  -1
  137. rb_ary_index  -1
  138. rb_ary_rindex  -1
  139. rb_ary_aset  -1
  140. rb_ary_insert  -1
  141. rb_ary_each_index  0
  142. rb_ary_reverse_each  0
  143. rb_ary_length  0
  144. rb_ary_empty_p  0
  145. //rb_ary_reverse
  146. rb_ary_reverse_bang  0
  147. rb_ary_reverse_m  0
  148. rb_ary_transpose  0
  149. rb_ary_replace  1
  150. rb_ary_fill  -1
  151. rb_ary_times  1
  152. rb_ary_equal  1
  153. rb_ary_to_s  0
  154. rb_ary_inspect  0
  155. rb_ary_eql  1
  156. rb_ary_at  1
  157. rb_ary_first  -1
  158. rb_ary_last  -1
  159. rb_ary_concat  1
  160. rb_ary_push_m  -1
  161. rb_ary_unshift  -1
  162. rb_ary_each  0
  163. rb_ary_join_m  -1
  164. rb_ary_sort  0
  165. rb_ary_sort_bang  0
  166. rb_ary_collect  0
  167. rb_ary_collect_bang  0
  168. rb_ary_delete  1
  169. rb_ary_delete_at_m  1
  170. rb_ary_reject  0
  171. rb_ary_reject_bang  0
  172. rb_ary_clear  0
  173. rb_ary_includes  1
  174. rb_ary_compact  0
  175. rb_ary_compact_bang  0
  176. ---
  177.  
  178. //Hash
  179. rb_hash_equal  1
  180. rb_hash_aref  1
  181. rb_hash_aset  2
  182. rb_hash_default  -1
  183. rb_hash_set_default  1
  184. rb_hash_index  1
  185. rb_hash_indexes  -1
  186. rb_hash_size  0
  187. rb_hash_empty_p  0
  188. rb_hash_each  0
  189. rb_hash_sort  0
  190. rb_hash_keys  0
  191. rb_hash_values  0
  192. rb_hash_shift  0
  193. rb_hash_delete  1
  194. rb_hash_select  0
  195. rb_hash_reject  0
  196. rb_hash_reject_bang  0
  197. rb_hash_clear  0
  198. rb_hash_invert  0
  199. rb_hash_has_key  1
  200. rb_hash_has_value  1
  201. <!BASIC RUBY FUNC>
  202.  
  203. //Class Variable
  204. rb_mod_remove_cvar
  205. rb_define_class_variable
  206. rb_cvar_defined
  207. mod_av_set
  208. rb_cvar_get
  209. rb_cvar_set
  210. rb_cv_get
  211. rb_cv_set
  212. ---
  213.  
  214. //Constantes
  215. rb_const_set
  216. rb_define_const
  217. rb_const_defined_at
  218. rb_const_defined
  219. rb_const_defined_from
  220. rb_const_defined_0
  221. rb_mod_remove_const
  222. rb_const_get_at
  223. rb_const_get
  224. rb_const_get_from
  225. rb_const_get_0
  226. rb_define_global_const 10068320
  227. ---
  228.  
  229. //Instance Variable
  230. rb_ivar_get
  231. rb_attr_get
  232. rb_ivar_set
  233. rb_ivar_defined
  234. rb_obj_remove_instance_variable
  235. rb_iv_get
  236. rb_iv_set
  237. ---
  238.  
  239. //Global Variable
  240. rb_gv_set
  241. rb_gv_get
  242. rb_gvar_defined
  243. ---
  244.  
  245. //Object
  246. rb_obj_clone
  247. rb_obj_dup
  248. ---
  249.  
  250. //Class
  251. rb_funcall2
  252. rb_funcall3
  253. rb_define_sigleton_method 1005F1E0
  254. rb_define_method 1005EF70
  255. rb_define_global_function 1005F270
  256. rb_define_module 1005E990
  257. rb_define_class_under
  258. rb_define_class 1005E740
  259. rb_define_module_under
  260. rb_class_new
  261. rb_define_class_id
  262. rb_class_boot
  263. rb_set_class_path
  264. rb_class_inherited
  265. rb_mod_included_modules
  266. rb_mod_include_p
  267. rb_mod_ancestors
  268. rb_singleton_class
  269. rb_define_private_method 1005EFA0
  270. rb_define_module_function
  271. rb_define_alias 1005F2C0
  272. rb_define_attr
  273. rb_scan_args
  274. rb_undef_method 1005EFD0
  275. rb_include_module 1005EBC0
  276. ---
  277.  
  278. ruby_xmalloc
  279. ruby_xrealloc
  280. ruby_xfree
  281. ruby_xcalloc
  282.  
  283. //ENDEF FUNCT//
  284.  
  285.  
  286.  
  287. Macros :
  288. #define FIXNUM_P(a) a&0x00000001
  289. #define SYMBOL_P(a) (a&0x000000FF)==0x0e
  290. #define NIL_P(a) a==0x04
  291.  
  292. RGSSInitialize
  293. RGSSGameMain
  294. RGSSSetupRTP
  295.  
  296.  
  297. Classes
  298.     kAudio ,
  299.     kGraphics ,
  300.     kInput ,
  301.     kObject 102AC098,
  302.     kModule ,
  303.     kClass ,
  304.     kKernel 102AC080,
  305.     kNilClass 102AC090,
  306.     kSymbol ,
  307.     kTrueClass 102AC094,
  308.     kData 102AC078,
  309.     kFalseClass 102AC088,
  310.     kArray 102ABFE8,
  311.     kString ,
  312.     kFloat ,
  313.     kInteger ,
  314.     kNumeric ,
  315.     kSprite ,
  316.     kBitmap ,
  317.     kViewport ,
  318.     kRect ,
  319.     kTone ,
  320.     kColor ,
  321.     kFont ,
  322.   eTypeError ,
  323.   eArgError ,
  324.   eIndexError ,
  325.   eException ,
  326.   eStandardError ,
  327.   kHash
Expand to see the code.

@Drago del Fato : Using ruby API will make your Game crash, I tried Win32API.new("socket.so","Init_Socket","","").call() looong time ago and the result was "RGSS Player a cessé de fonctionner.". But it's right : the arguments of the functions didn't change.

That address for define module didn't work for me the first time round, I'll try them all out tonight and see about writting a wrapper to easily get native classes into RGSS.
rb_define_module don't work ?
It's weird x)
Where would I call the define class and define methods in the exe? Just before GameMain or after initialise3 or anywhere else? I'm getting a crash with define_class at the moment

EDIT: Got it all working now, guess it's time to write a wrapper for this stuff

When I have time I'll search for the rb_define_class_variable rb_data_object_alloc pointers

EDIT2: As an update on where I'm going with this, I'm attempting to get an OpenGL render loop on top of the game screen, I have some ideas for this and some tests have proven successful (I can insert OpenGL draw calls, albeit they flicker like crazy because it's mixed with GDI).

What I'm going to try is drawing OpenGL to a framebuffer and copying the memory to an RGSS3 picture, which can be drawn by the game when it wants, I need some help with accessing the picture class though, so if anyone wants to help me here then please do
Xilef wrote:
Where would I call the define class and define methods in the exe? Just before GameMain or after initialise3 or anywhere else? I'm getting a crash with define_class at the moment

EDIT: Got it all working now, guess it's time to write a wrapper for this stuff

When I have time I'll search for the rb_define_class_variable rb_data_object_alloc pointers

EDIT2: As an update on where I'm going with this, I'm attempting to get an OpenGL render loop on top of the game screen, I have some ideas for this and some tests have proven successful (I can insert OpenGL draw calls, albeit they flicker like crazy because it's mixed with GDI).

What I'm going to try is drawing OpenGL to a framebuffer and copying the memory to an RGSS3 picture, which can be drawn by the game when it wants, I need some help with accessing the picture class though, so if anyone wants to help me here then please do


The picture class, or the bitmap class? If it's the bitmap class, there are some copies of a .dll source in my post history that take the address for a bitmap that Ruby provides, and loads them into moddable memory.
Glitchfinder wrote:
The picture class, or the bitmap class? If it's the bitmap class, there are some copies of a .dll source in my post history that take the address for a bitmap that Ruby provides, and loads them into moddable memory.

I don't see an exposed bitmap class for RGSS3, I was going to go and mess about with the picture class until I find a handle to something vaguely bitmap-esque.

Anything that gives access to a raw image that can be displayed within a standard RGSS3 game is what I'm looking for

Is Sprite_Picture useful at all for this?
Xilef wrote:
Glitchfinder wrote:
The picture class, or the bitmap class? If it's the bitmap class, there are some copies of a .dll source in my post history that take the address for a bitmap that Ruby provides, and loads them into moddable memory.

I don't see an exposed bitmap class for RGSS3, I was going to go and mess about with the picture class until I find a handle to something vaguely bitmap-esque.

Anything that gives access to a raw image that can be displayed within a standard RGSS3 game is what I'm looking for

Is Sprite_Picture useful at all for this?


I got the data via having a Bitmap instance in RGSS, and passing it to the dll via bitmapInstance.__ID__, I think. It's been a while since I've done it, so I'm not sure what the specific call was. You can find one of the posts with a .dll source here, if you want to take a look. And, I just checked to be sure. RGSS, RGSS2, and RGSS3 all use the Bitmap class, as stated.
Okay thanks, I found the source so I'm all set, cheers.

EDIT: The .__id__ left shift thing doesn't seem to work (At least with RGSS301), so I'm scratching my head at this point

Perhaps there is a different calling convention between Win32API and an internal call
You can send a bitmap to a C function or create the bitmap in the function before returning it ^^'
  1. VALUE Graphics_snap_to_bitmap(VALUE self)
  2. {
  3.     VALUE args[2]={GWidth,GHeight};
  4.     VALUE obitmap=rb_class_new_instance(2,args,RGSSConst(kBitmap));
  5. //Some stuff -._-.
  6.     memcpy(RBITMAP(obitmap)->bm->bminfo->lastRow,lpbitmap,dwBmpSize);
  7. //Some cleaning stuff -._-.
  8.     return obitmap;
  9. }
Expand to see the code.
I'm currently trying to send the bitmap to a C function

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=77867