Project1

标题: 脑残物Custom RGSS Player(Game.exe) [打印本页]

作者: 英顺的马甲    时间: 2015-3-26 10:27
标题: 脑残物Custom RGSS Player(Game.exe)
本帖最后由 英顺的马甲 于 2015-3-26 16:46 编辑

前几天比较看得懂c++后拿了第三方RGSS Player来改,于是就出了此脑残物

这脑残物对普通人来说比较有用的功能就只有会自动加载与exe同目录内fonts文件夹里的字体
不过这个exe有个缺点,那就是并不是所有的RGSS10XX.dll都支持(目前已知肯定支持的有原版的)
杀毒信息:https://www.virustotal.com/en/file/cba1f55c2ac3bc31e47ddf99897482e41600fe022db05bbb5bac40d24a90e3c6/analysis/1427335101/
下载:
EXE与源码.rar (64.99 KB, 下载次数: 163)

如果你完全不懂API或c++之类的请回头

EXE源码,大神勿喷(其实喷也没关系)
额外功能

带有WndProc的范例: Custom RGSS Player.rar (2.97 MB, 下载次数: 321)

@晴兰 @orzfly @yangff 求吐槽
作者: taroxd    时间: 2015-3-26 12:42
本帖最后由 taroxd 于 2015-3-26 12:45 编辑

我是来调戏论坛高亮的,不过论坛高亮竟然没出事情

RUBY 代码复制
  1. module WND
  2. WM_ACTIVATE=0x0006
  3. WM_ACTIVATEAPP=0x001C
  4. WM_AFXFIRST=0x0360
  5. WM_AFXLAST=0x037F
  6. WM_APP=0x8000
  7. WM_APPCOMMAND=0x0319
  8. WM_ASKCBFORMATNAME=0x030C
  9. WM_CANCELJOURNAL=0x004B
  10. WM_CANCELMODE=0x001F
  11. WM_CAPTURECHANGED=0x0215
  12. WM_CHANGECBCHAIN=0x030D
  13. WM_CHANGEUISTATE=0x0127
  14. WM_CHAR=0x0102
  15. WM_CHARTOITEM=0x002F
  16. WM_CHILDACTIVATE=0x0022
  17. WM_CLEAR=0x0303
  18. WM_CLOSE=0x0010
  19. WM_COMMAND=0x0111
  20. WM_COMMNOTIFY=0x0044
  21. WM_COMPACTING=0x0041
  22. WM_COMPAREITEM=0x0039
  23. WM_CONTEXTMENU=0x007B
  24. WM_COPY=0x0301
  25. WM_COPYDATA=0x004A
  26. WM_CREATE=0x0001
  27. WM_CTLCOLORBTN=0x0135
  28. WM_CTLCOLORDLG=0x0136
  29. WM_CTLCOLOREDIT=0x0133
  30. WM_CTLCOLORLISTBOX=0x0134
  31. WM_CTLCOLORMSGBOX=0x0132
  32. WM_CTLCOLORSCROLLBAR=0x0137
  33. WM_CTLCOLORSTATIC=0x0138
  34. WM_CUT=0x0300
  35. WM_DEADCHAR=0x0103
  36. WM_DELETEITEM=0x002D
  37. WM_DESTROY=0x0002
  38. WM_DESTROYCLIPBOARD=0x0307
  39. WM_DEVICECHANGE=0x0219
  40. WM_DEVMODECHANGE=0x001B
  41. WM_DISPLAYCHANGE=0x007E
  42. WM_DRAWCLIPBOARD=0x0308
  43. WM_DRAWITEM=0x002B
  44. WM_DROPFILES=0x0233
  45. WM_ENABLE=0x000A
  46. WM_ENDSESSION=0x0016
  47. WM_ENTERIDLE=0x0121
  48. WM_ENTERMENULOOP=0x0211
  49. WM_ENTERSIZEMOVE=0x0231
  50. WM_ERASEBKGND=0x0014
  51. WM_EXITMENULOOP=0x0212
  52. WM_EXITSIZEMOVE=0x0232
  53. WM_FONTCHANGE=0x001D
  54. WM_GETDLGCODE=0x0087
  55. WM_GETFONT=0x0031
  56. WM_GETHOTKEY=0x0033
  57. WM_GETICON=0x007F
  58. WM_GETMINMAXINFO=0x0024
  59. WM_GETOBJECT=0x003D
  60. WM_GETTEXT=0x000D
  61. WM_GETTEXTLENGTH=0x000E
  62. WM_HANDHELDFIRST=0x0358
  63. WM_HANDHELDLAST=0x035F
  64. WM_HELP=0x0053
  65. WM_HOTKEY=0x0312
  66. WM_HSCROLL=0x0114
  67. WM_HSCROLLCLIPBOARD=0x030E
  68. WM_ICONERASEBKGND=0x0027
  69. WM_IME_CHAR=0x0286
  70. WM_IME_COMPOSITION=0x010F
  71. WM_IME_COMPOSITIONFULL=0x0284
  72. WM_IME_CONTROL=0x0283
  73. WM_IME_ENDCOMPOSITION=0x010E
  74. WM_IME_KEYDOWN=0x0290
  75. WM_IME_KEYLAST=0x010F
  76. WM_IME_KEYUP=0x0291
  77. WM_IME_NOTIFY=0x0282
  78. WM_IME_REQUEST=0x0288
  79. WM_IME_SELECT=0x0285
  80. WM_IME_SETCONTEXT=0x0281
  81. WM_IME_STARTCOMPOSITION=0x010D
  82. WM_INITDIALOG=0x0110
  83. WM_INITMENU=0x0116
  84. WM_INITMENUPOPUP=0x0117
  85. WM_INPUT=0x00FF
  86. WM_INPUTLANGCHANGE=0x0051
  87. WM_INPUTLANGCHANGEREQUEST=0x0050
  88. WM_KEYDOWN=0x0100
  89. WM_KEYFIRST=0x0100
  90. WM_KEYLAST=0x0109
  91. WM_KEYUP=0x0101
  92. WM_KILLFOCUS=0x0008
  93. WM_LBUTTONDBLCLK=0x0203
  94. WM_LBUTTONDOWN=0x0201
  95. WM_LBUTTONUP=0x0202
  96. WM_MBUTTONDBLCLK=0x0209
  97. WM_MBUTTONDOWN=0x0207
  98. WM_MBUTTONUP=0x0208
  99. WM_MDIACTIVATE=0x0222
  100. WM_MDICASCADE=0x0227
  101. WM_MDICREATE=0x0220
  102. WM_MDIDESTROY=0x0221
  103. WM_MDIGETACTIVE=0x0229
  104. WM_MDIICONARRANGE=0x0228
  105. WM_MDIMAXIMIZE=0x0225
  106. WM_MDINEXT=0x0224
  107. WM_MDIREFRESHMENU=0x0234
  108. WM_MDIRESTORE=0x0223
  109. WM_MDISETMENU=0x0230
  110. WM_MDITILE=0x0226
  111. WM_MEASUREITEM=0x002C
  112. WM_MENUCHAR=0x0120
  113. WM_MENUCOMMAND=0x0126
  114. WM_MENUDRAG=0x0123
  115. WM_MENUGETOBJECT=0x0124
  116. WM_MENURBUTTONUP=0x0122
  117. WM_MENUSELECT=0x011F
  118. WM_MOUSEACTIVATE=0x0021
  119. WM_MOUSEFIRST=0x0200
  120. WM_MOUSEHOVER=0x02A1
  121. WM_MOUSELAST=0x020D
  122. WM_MOUSELAST=0x0209
  123. WM_MOUSELAST=0x020A
  124. WM_MOUSELEAVE=0x02A3
  125. WM_MOUSEMOVE=0x0200
  126. WM_MOUSEWHEEL=0x020A
  127. WM_MOVE=0x0003
  128. WM_MOVING=0x0216
  129. WM_NCACTIVATE=0x0086
  130. WM_NCCALCSIZE=0x0083
  131. WM_NCCREATE=0x0081
  132. WM_NCDESTROY=0x0082
  133. WM_NCHITTEST=0x0084
  134. WM_NCLBUTTONDBLCLK=0x00A3
  135. WM_NCLBUTTONDOWN=0x00A1
  136. WM_NCLBUTTONUP=0x00A2
  137. WM_NCMBUTTONDBLCLK=0x00A9
  138. WM_NCMBUTTONDOWN=0x00A7
  139. WM_NCMBUTTONUP=0x00A8
  140. WM_NCMOUSEHOVER=0x02A0
  141. WM_NCMOUSELEAVE=0x02A2
  142. WM_NCMOUSEMOVE=0x00A0
  143. WM_NCPAINT=0x0085
  144. WM_NCRBUTTONDBLCLK=0x00A6
  145. WM_NCRBUTTONDOWN=0x00A4
  146. WM_NCRBUTTONUP=0x00A5
  147. WM_NCXBUTTONDBLCLK=0x00AD
  148. WM_NCXBUTTONDOWN=0x00AB
  149. WM_NCXBUTTONUP=0x00AC
  150. WM_NEXTDLGCTL=0x0028
  151. WM_NEXTMENU=0x0213
  152. WM_NOTIFY=0x004E
  153. WM_NOTIFYFORMAT=0x0055
  154. WM_NULL=0x0000
  155. WM_PAINT=0x000F
  156. WM_PAINTCLIPBOARD=0x0309
  157. WM_PAINTICON=0x0026
  158. WM_PALETTECHANGED=0x0311
  159. WM_PALETTEISCHANGING=0x0310
  160. WM_PARENTNOTIFY=0x0210
  161. WM_PASTE=0x0302
  162. WM_PENWINFIRST=0x0380
  163. WM_PENWINLAST=0x038F
  164. WM_POWER=0x0048
  165. WM_POWERBROADCAST=0x0218
  166. WM_PRINT=0x0317
  167. WM_PRINTCLIENT=0x0318
  168. WM_QUERYDRAGICON=0x0037
  169. WM_QUERYENDSESSION=0x0011
  170. WM_QUERYNEWPALETTE=0x030F
  171. WM_QUERYOPEN=0x0013
  172. WM_QUERYUISTATE=0x0129
  173. WM_QUEUESYNC=0x0023
  174. WM_QUIT=0x0012
  175. WM_RBUTTONDBLCLK=0x0206
  176. WM_RBUTTONDOWN=0x0204
  177. WM_RBUTTONUP=0x0205
  178. WM_RENDERALLFORMATS=0x0306
  179. WM_RENDERFORMAT=0x0305
  180. WM_SETCURSOR=0x0020
  181. WM_SETFOCUS=0x0007
  182. WM_SETFONT=0x0030
  183. WM_SETHOTKEY=0x0032
  184. WM_SETICON=0x0080
  185. WM_SETREDRAW=0x000B
  186. WM_SETTEXT=0x000C
  187. WM_SETTINGCHANGE=0x001A
  188. WM_SHOWWINDOW=0x0018
  189. WM_SIZE=0x0005
  190. WM_SIZECLIPBOARD=0x030B
  191. WM_SIZING=0x0214
  192. WM_SPOOLERSTATUS=0x002A
  193. WM_STYLECHANGED=0x007D
  194. WM_STYLECHANGING=0x007C
  195. WM_SYNCPAINT=0x0088
  196. WM_SYSCHAR=0x0106
  197. WM_SYSCOLORCHANGE=0x0015
  198. WM_SYSCOMMAND=0x0112
  199. WM_SYSDEADCHAR=0x0107
  200. WM_SYSKEYDOWN=0x0104
  201. WM_SYSKEYUP=0x0105
  202. WM_TABLET_FIRST=0x02C0
  203. WM_TABLET_LAST=0x02DF
  204. WM_TCARD=0x0052
  205. WM_THEMECHANGED=0x031A
  206. WM_TIMECHANGE=0x001E
  207. WM_TIMER=0x0113
  208. WM_UNDO=0x0304
  209. WM_UNICHAR=0x0109
  210. WM_UNINITMENUPOPUP=0x0125
  211. WM_UPDATEUISTATE=0x0128
  212. WM_USER=0x0400
  213. WM_USERCHANGED=0x0054
  214. WM_VKEYTOITEM=0x002E
  215. WM_VSCROLL=0x0115
  216. WM_VSCROLLCLIPBOARD=0x030A
  217. WM_WINDOWPOSCHANGED=0x0047
  218. WM_WINDOWPOSCHANGING=0x0046
  219. WM_WININICHANGE=0x001A
  220. WM_WTSSESSION_CHANGE=0x02B1
  221. WM_XBUTTONDBLCLK=0x020D
  222. WM_XBUTTONDOWN=0x020B
  223. WM_XBUTTONUP=0x020C
  224. API_CWP=Win32API.new('user32.dll','CallWindowProc','llill','l')
  225. API_SWL=Win32API.new('user32.dll','SetWindowLong','lil','l')
  226. API_RMM=Win32API.new('kernel32.dll','RtlMoveMemory','lpi','v')
  227. module_function
  228. def bind
  229. const_set(:ADDR_OWP,API_SWL.call(hWnd,-4,ADDR_NWP))
  230. API_RMM.call(ADDR_AOWP,[ADDR_OWP].pack('L'),4)
  231. instance_eval{undef :bind}
  232. end
  233. def origWndProc(hwnd,message,wParam,lParam)
  234. return API_CWP.call(ADDR_OWP,hwnd,message,wParam,lParam)
  235. end
  236. def WndProc(hwnd,message,wParam,lParam)
  237. return WND.origWndProc(hwnd,message,wParam,lParam)
  238. end
  239. def __call_wndproc(ptr_ret,ptr_state,hwnd,message,wParam,lParam)
  240. ret=WND.WndProc(hwnd,message,wParam,lParam)
  241. ret=ret.eql?(true)?1:ret.eql?(false)?0:ret
  242. API_RMM.call(ptr_ret,[ret.to_i].pack('L'),4)
  243. API_RMM.call(ptr_state,[1].pack('i'),1)
  244. end
  245. end

作者: 长虹剑    时间: 2015-8-19 13:17
本帖最后由 长虹剑 于 2015-8-20 15:06 编辑

@英顺的马甲  百度空间的链接失效了,你给的参考链接打不开,不知哪里还有。
还有我很想知道RGSSxxx.dll到底是如何调用的,如何用纯ruby来启动程序,或者如何才能在我自己的ruby程序中使用RGSS的内置类。

请问楼主是如何知道 dll 里面有 RGSSEval,RGSSGameMain 等函数的,并且如何知道是用顺序,也就是楼主破解了dll了?我想知道如何破解,还有在rgss300.dll中RGSSInitialize是不存在的,所以如何给rgss300重写个启动器呢?

请给一个思路
@晴兰  


作者: 长虹剑    时间: 2015-8-20 15:14
用纯ruby实现Game.exe 目前写到这里了,参照你的那个程序写的,目前还没有写窗口的生成,打算就是完全调用Winapi实现。 还有本来想基于rgss3写的,但是你给的这个例子不能用,我也不知道dll有什么,怎么用。
  1. # -*- coding:utf-8 -*-
  2. require 'Win32API'
  3. require 'pathname'
  4. require 'iniparse'  #读取ini文件
  5. require 'cstruct/win32struct'


  6. MAX_PATH=100
  7. Gameini="Game.ini"
  8. #----------
  9. #FindWindow=Win32API.new("user32", "FindWindow", ['P','P'], 'L')
  10. LoadLibraryA=Win32API.new("kernel32", "LoadLibraryA", ['P'], 'L')
  11. GetProcAddress=Win32API.new("kernel32", "GetProcAddress", ['L','P'], 'L')
  12. #-------
  13. szAppPath=Pathname.new(File.dirname(__FILE__)).realpath
  14. #puts Dir.getwd  获得当前的执行目录 ***
  15. Dir.chdir(szAppPath) #改变当前目录

  16. hd_gameini=IniParse.parse( File.read "#{Gameini}" )
  17. szLibrary=hd_gameini["Game"]["Library"]
  18. szTitle=hd_gameini["Game"]["Title"]
  19. szScripts=hd_gameini["Game"]["Scripts"]

  20. #通过核心库加载程序
  21. hRgssCore = LoadLibraryA.Call(szLibrary);
  22. pRGSSEval=Win32API.new(szLibrary, "RGSSEval", ['P'], 'I') # 这种方式只是使用,根本没加入内存
  23. #pRGSSEval=GetProcAddress.Call(hRgssCore,"RGSSEval") #之后就不会用了
  24. pRGSSSetupRTP=Win32API.new(szLibrary, "RGSSSetupRTP", ['P','P','I'], 'B')
  25. pRGSSInitialize=Win32API.new(szLibrary, "RGSSInitialize", 'L', 'L')
  26. pRGSSGameMain=Win32API.new(szLibrary, "RGSSGameMain", ['L','P','P'], 'V')
  27. #puts Win32API::COLOR_WINDOWFRAME

  28. pRGSSInitialize.Call(hRgssCore)
  29. pRGSSEval.Call(" s=Sprite.new "); #不报错
  30. pRGSSEval.Call(" p 12*7+2 "); #正常显示了
  31. #还差窗口显示


  32. #puts pRGSSEval
  33. #pRGSSEval.Call("$DEBUG = true");
  34. #exit

  35. #hInstance=FindWindow.Call("ConsoleWindowClass",nil)  
复制代码

作者: 英顺的马甲    时间: 2015-8-21 17:19
RUBY 代码复制下载
  1. # coding: gbk
  2. require 'win32api'
  3.  
  4. def err_msg(format, *args)
  5.         Win32API.new('user32', 'MessageBox', 'lppl', 'i').call(@hWnd ? @hWnd : 0, format % args, @title, 16)
  6.         stop
  7. end
  8.  
  9. def stop
  10.         Win32API.new('kernel32', 'FreeLibrary', 'l', 'i').call(@hRGSSCore) if @hRGSSCore and @hRGSSCore != 0
  11.         Win32API.new('user32', 'DestroyWindow', 'l', 'i').call(@hWnd) if @hWnd and @hWnd != 0
  12.         Win32API.new('user32', 'UnregisterClass', 'pl', 'i').call(WndClassName, @hInstance)
  13.         exit
  14. end
  15.  
  16. WndClassName = "RGSS Player"
  17. DefaultLibrary = "RGSS102J.dll"
  18. DefaultTitle = "Untitled"
  19. DefaultScripts = "Data\\Scripts.rxdata"
  20.  
  21. @library = [0].pack('C') * 100
  22. @title = [0].pack('C') * 100
  23. @scripts = [0].pack('C') * 100
  24.  
  25. @hInstance = Win32API.new('kernel32', 'GetModuleHandle', 'l', 'l').call(0)
  26. Win32API.new('user32', 'ShowWindow', 'li', 'i').call(Win32API.new('kernel32', 'GetConsoleWindow', 'v', 'l').call, 0)
  27.  
  28. @inipath = File.basename(__FILE__).sub(/\.rb$/i, '.ini')
  29. @inipath = File.join(Dir.pwd, @inipath).gsub(/\//, "\\")
  30. if File.exist?(@inipath)
  31.         gpps = Win32API.new('kernel32', 'GetPrivateProfileString', 'ppppip', 'i')
  32.         gpps.call('Game', 'Library', DefaultLibrary, @library, 100, @inipath)
  33.         gpps.call('Game', 'Title', DefaultTitle, @title, 100, @inipath)
  34.         gpps.call('Game', 'Scripts', DefaultScripts, @scripts, 100, @inipath)
  35.         @library.delete([0].pack('C'))
  36.         @title.delete([0].pack('C'))
  37.         @scripts.delete([0].pack('C'))
  38. else
  39.         @library = DefaultLibrary
  40.         @title = DefaultTitle
  41.         @scripts = DefaultScripts
  42. end
  43.  
  44. if File.exist?(File.basename(__FILE__).sub(/\.rb$/i, '.rgssad'))
  45.         @rgssad = File.basename(__FILE__).sub(/\.rb$/i, '.rgssad')
  46.         @rgssad = File.join(Dir.pwd, @rgssad).gsub(/\//, "\\")
  47. end       
  48.  
  49. @wndclass = [
  50.         43, # style
  51.         Win32API.new('kernel32', 'GetProcAddress', 'lp', 'l').call(
  52.                 Win32API.new('kernel32', 'LoadLibrary', 'p', 'l').call('User32.dll'),
  53.                 'DefWindowProcW'), # wndproc
  54.         0, # class extra
  55.         0, # wnd extra
  56.         @hInstance,
  57.         Win32API.new('user32', 'LoadIcon', 'll', 'l').call(0, 32512), # icon
  58.         Win32API.new('user32', 'LoadCursor', 'll', 'l').call(0, 32512), # cursor
  59.         Win32API.new('gdi32', 'GetStockObject', 'i', 'l').call(4), # brush
  60.         0, # menu name
  61.         WndClassName # class name
  62. ].pack('ILiiLLLLLp')
  63.  
  64. temp = Win32API.new('user32', 'RegisterClass', 'p', 'l').call(@wndclass)
  65. err_msg("注册窗口类失败 %s。", WndClassName) if temp == 0
  66.  
  67. gsm = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
  68.  
  69. width = gsm.call(7) * 2 + 640
  70. height = gsm.call(8) * 2 + gsm.call(4) + 480
  71. x = (gsm.call(0) - width) / 2
  72. y = (gsm.call(1) - height) / 2
  73.  
  74. @hWnd = Win32API.new('user32','CreateWindowExA','lpplllllllll','l').call(
  75.         0x100, WndClassName, @title, 0x90CA0000, x, y, width, height, 0, 0, @hInstance, 0)
  76. err_msg("创建窗口失败 %s。", @title) if @hWnd == 0
  77.  
  78. @hRGSSCore = Win32API.new('kernel32', 'LoadLibrary', 'p', 'l').call(@library)
  79. err_msg("加载RGSS核心库失败 %s。", @library) if @hRGSSCore == 0
  80.  
  81. def get_check(ary)
  82.         begin
  83.                 Kernel.const_set(ary[0], Win32API.new(@library, *ary))
  84.         rescue Exception
  85.                 err_msg("获取RGSS核心库导出函数失败 %s。", ary[0])
  86.         end
  87. end
  88. get_check(%w{RGSSEval p i})
  89. get_check(%w{RGSSInitialize l v})
  90. get_check(%w{RGSSGameMain lpl v})
  91. get_check(%w{RGSSSetupRTP ppi})
  92. undef :get_check
  93.  
  94. rtpname = [0].pack('C') * 1024
  95. if (RGSSSetupRTP.call(@inipath, rtpname, 1024) == 0)
  96.         err_msg("没有发现 RGSS-RTP %s。", rtpname.delete([0].pack('C')))
  97. end
  98.  
  99. RGSSInitialize.call(@hRGSSCore)
  100. if ARGV.include?("btest")
  101.         RGSSEval.call("$DEBUG = true; $BTEST = true")
  102.         @rgssad = nil
  103. elsif ARGV.include?('debug')
  104.         RGSSEval.call("$DEBUG = true")
  105. end
  106.  
  107. RGSSGameMain.call(@hWnd, @scripts, @rgssad ? rgssad.object_id * 2 + 16 : 0)
  108.  
  109. stop

作者: 长虹剑    时间: 2015-8-21 20:45
多谢楼主,看了你的程序真的让我大开眼见,没想到winapi还可以这样用,让程序减少了不少。其实今天中午我的程序也写完了,但是有300行之多,主要是定义了半天cstruct。刚才看了你的程序,下载后在我这里运行不了,所以就想到用你的程序来简化我的程序。本来想另外开帖,又觉得是在这个帖里面长大的所以就放在这里了。

示例工程如下   RGSS纯ruby启动器.zip (1.13 MB, 下载次数: 120)
程序代码如下
  1. # -*- coding:utf-8 -*-
  2. =begin
  3. 参考资料
  4. https://rpg.blue/thread-377723-1-1.html  想法来源(后来还用楼主的脚本重新改写)
  5. http://skandhas.iteye.com/blog/809806 解决了创建windows窗口的问题
  6. 有些windows的常量没有定义需要查看MSDN

  7. http://rpg.blue/thread-282803-1-1.html  解决了最后读不了脚本文件的问题

  8. 解决不了的问题
  9. 1.RTP无法加载(也不知道加载是什么原理)
  10. 2.想知道RGSS.dll是如何实现的
  11. 3.RGSSGameMain 究竟干了什么,为什么之前的RGSSEval不能使用Sprite
  12. =end

  13. require 'Win32API'
  14. require 'pathname'
  15. require 'iniparse'  #读取ini文件

  16. RGSSversion=3 # 1 or 3
  17. Gameini="Game_debug.ini" #"Game.ini"
  18. WndClassName = "Pure Ruby Window For RGSS"
  19. @title=WndClassName
  20. #--------
  21. szAppPath=Pathname.new(File.dirname(__FILE__)).realpath
  22. #puts Dir.getwd  获得当前的执行目录 ***
  23. Dir.chdir(szAppPath) #改变当前目录
  24. #-------------
  25. #隐藏掉控制台
  26. #Win32API.new('user32', 'ShowWindow', 'li', 'i').call(
  27. #    Win32API.new('kernel32', 'GetConsoleWindow', 'v', 'l').call, 0)

  28. #-------------
  29. @hInstance = Win32API.new('kernel32', 'GetModuleHandle', 'l', 'l').call(0)
  30. @wndclass = [
  31.         43, # style
  32.         Win32API.new('kernel32', 'GetProcAddress', 'lp', 'l').call(
  33.                 Win32API.new('kernel32', 'LoadLibrary', 'p', 'l').call('User32.dll'),
  34.                 'DefWindowProcW'), # wndproc
  35.         0, # class extra
  36.         0, # wnd extra
  37.         @hInstance,
  38.         Win32API.new('user32', 'LoadIcon', 'll', 'l').call(0, 32512), # icon
  39.         Win32API.new('user32', 'LoadCursor', 'll', 'l').call(0, 32512), # cursor
  40.         Win32API.new('gdi32', 'GetStockObject', 'i', 'l').call(4), # brush
  41.         0, # menu name
  42.         WndClassName # class name
  43. ].pack('ILiiLLLLLp')

  44. atom = Win32API.new('user32', 'RegisterClass', 'p', 'l').call(@wndclass)
  45. atom &=0x0000ffff
  46. return if atom==0
  47. #在第一个实现的脚本中atom本来是要用在WndClassName位置的
  48. x=200; y=100; width=640 ; height=480
  49. @hWnd = Win32API.new('user32','CreateWindowExA','lpplllllllll','l').call(
  50.         0x100, WndClassName, @title, 0x90CA0000, x, y, width, height, 0, 0, @hInstance, 0)
  51. #-------------
  52. hd_gameini=IniParse.parse( File.read "#{Gameini}" )
  53. szLibrary=hd_gameini["Game"]["Library"]
  54. szTitle  =hd_gameini["Game"]["Title"]
  55. szScripts=hd_gameini["Game"]["Scripts"]
  56. szRtpName=hd_gameini["Game"]["RTP"]
  57. @title=szTitle
  58. #通过核心库加载程序
  59. @hRgssCore = Win32API.new('kernel32', 'LoadLibrary', 'p', 'l').call(szLibrary)
  60. pRGSSEval=Win32API.new(szLibrary, "RGSSEval", ['P'], 'I')
  61. pRGSSSetupRTP=Win32API.new(szLibrary, "RGSSSetupRTP", ['P','P','I'], 'B')
  62. pRGSSInitialize=if RGSSversion==3
  63.     Win32API.new(szLibrary, "RGSSInitialize3", 'L', 'L')
  64. elsif RGSSversion==1
  65.     Win32API.new(szLibrary, "RGSSInitialize", 'L', 'L')
  66. end
  67. pRGSSGameMain=Win32API.new(szLibrary, "RGSSGameMain", ['L','P','P'], 'V')
  68. #puts Win32API::COLOR_WINDOWFRAME
  69. def stop
  70.         Win32API.new('kernel32', 'FreeLibrary', 'l', 'i').call(@hRGSSCore) if @hRGSSCore and @hRGSSCore != 0
  71.         Win32API.new('user32', 'DestroyWindow', 'l', 'i').call(@hWnd) if @hWnd and @hWnd != 0
  72.         Win32API.new('user32', 'UnregisterClass', 'pl', 'i').call(WndClassName, @hInstance)
  73.         exit
  74. end

  75. #RTP就是不行
  76. szRtpName= [0].pack('C') * 1024
  77. p pRGSSSetupRTP.Call("#{Gameini}", szRtpName, 1024)

  78. pRGSSInitialize.Call(@hRgssCore)  # 没有这个就不行,说明还是有关系的

  79. szScripts="Scripts.rvdata2"

  80. class String
  81.   MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  82.   WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
  83.   def to_uni
  84.     len = MultiByteToWideChar.call 65001, 0, self, -1, nil, 0
  85.     buf = "\0" * (len * 2 + 2)
  86.     MultiByteToWideChar.call 65001, 0, self, -1, buf, buf.size / 2

  87.     buf
  88.   end

  89.   def from_uni
  90.     len = WideCharToMultiByte.call 65001, 0, (self.respond_to?(:force_encoding) ? self.force_encoding("ASCII-8BIT") : self) + "\000\000", -1, nil, 0, nil, nil
  91.     ret = "\0" * len
  92.     WideCharToMultiByte.call 65001, 0, self, -1, ret, ret.size, nil, nil

  93.     self.respond_to?(:force_encoding) ?
  94.     ret.force_encoding("ASCII-8BIT").delete("\000") :
  95.     ret.delete("\000")
  96.   end
  97. end

  98. pRGSSGameMain.call(@hWnd,szScripts.to_uni,"") #必须这样才行

  99. stop
复制代码

作者: 浮云半仙    时间: 2016-1-20 20:46
本帖最后由 浮云半仙 于 2016-1-20 20:47 编辑

看了各位大神的代码,本蒟蒻深受启发,然而最终我只写出来个窗口...(并不了解RGSS的dll{:2_276:})
  1. #encoding:utf-8

  2. require 'Win32API'
  3. unless defined?(Ocra)
  4. Win32API.new("user32", "ShowWindow", "li", "i").call(Win32API.new("kernel32", "GetConsoleWindow", 'l', 'l').call(0),0)
  5. #隐藏控制台
  6. end

  7. WS_OVERLAPPEDWINDOW         = 0xcf0000
  8. WS_VISIBLE         = 0x10000000
  9. IDI_APPLICATION  = 32512
  10. SW_HIDE  = 0
  11. SW_NORMAL  = 1
  12. IDC_ARROW = 32512
  13. COLOR_WINDOW = 5

  14. GetLastError = Win32API.new("kernel32", "GetLastError", nil, "i")
  15. GetProcAddress = Win32API.new("kernel32", "GetProcAddress", "lp", "l")
  16. GetModuleHandle = Win32API.new("kernel32", "GetModuleHandle", "l", "l")
  17. GetModuleHandleByName = Win32API.new("kernel32", "GetModuleHandle", "p", "l")
  18. LoadLibrary = Win32API.new("kernel32", "LoadLibrary", "p", "l")
  19. RegisterClass = Win32API.new("user32", "RegisterClass", "p", "i")
  20. FreeLibrary = Win32API.new("kernel32", "FreeLibrary", "l", "i")
  21. CreateWindowEx = Win32API.new("user32", "CreateWindowEx", "lppliiiillll", "l")
  22. MessageBox = Win32API.new("user32", "MessageBox", "ippi", "i")
  23. GetMessage = Win32API.new("user32", "GetMessage","plll", "i")
  24. DispatchMessage = Win32API.new("user32", "DispatchMessage", "p", "i")

  25. def msg_box(title, text)
  26.         MessageBox.call(0, text.to_s, title.to_s, 0)
  27. end

  28. unless defined?(Ocra)

  29. classname = "win32appruby233"                #窗口类名
  30. hInstance = GetModuleHandle.call 0                         #程序实例句柄
  31. hDll = LoadLibrary.call "user32.dll"                #加载user32.dll
  32. Win32API.new("user32", "UnregisterClass", "pl", "i").call(classname, hInstance)
  33. #先反注册一下窗口类名...然而八成没啥用...

  34. ar_DefWindowProc = GetProcAddress.call hDll, "DefWindowProcW"
  35. #user32.dll里面DefWindowProcW的地址

  36. wc = [0, ar_DefWindowProc, 0, 0, hInstance,
  37.                 Win32API.new("user32", "LoadIcon", "ll", "l").call(hInstance, IDI_APPLICATION),
  38.                 Win32API.new("user32", "LoadCursor", "ll", "l").call(hInstance, IDC_ARROW),
  39.                 COLOR_WINDOW + 1,           #窗体颜色
  40.                 0,
  41.                 classname].pack("lllllllllp")
  42. #参见WNDCLASS结构体,打包地址,句柄可以用 'l'
  43.                
  44. if RegisterClass.call(wc) == 0
  45.         msg_box "Error!", "Fail to register window class, Error code:#{GetLastError.call}"
  46.         exit
  47. end

  48. hWnd = CreateWindowEx.call(0, classname, "Ruby big law is good",  #title
  49.                                                         WS_VISIBLE | WS_OVERLAPPEDWINDOW,   #style
  50.                                                         200, 100, 544, 416,           #x, y, width, height   
  51.                                                         0, 0,
  52.                                                         hInstance, 0)
  53. #参见CreateWindowEx的参数

  54. Win32API.new("user32", "ShowWindow", "li", "i").call hWnd, SW_NORMAL
  55. #让窗口显示出来

  56. if hWnd == 0
  57.         msg_box("Error!", "Fail to CreateWindow")
  58.         exit
  59. end

  60. msg = "0"*24       #MSG结构体的大小为24byte,开够空间
  61. while GetMessage.call(msg, 0, 0, 0)   #消息循环
  62.         DispatchMessage.call(msg)
  63. end

  64. Win32API.new("user32", "UnregisterClass", "pl", "i").call(classname, hInstance)

  65. end
复制代码
膜拜各位神犇
BTW:win10上运行不了,报错注册窗口类失败。貌似win10上GetProcAddress一直返回0...好奇怪...{:2_278:}
作者: 浮云半仙    时间: 2016-1-22 21:29
taroxd 发表于 2015-3-26 12:42
我是来调戏论坛高亮的,不过论坛高亮竟然没出事情

{:2_270:}求解..ADDR_NWP,ADDR_AOWP怎么粗来的{:2_271:}




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1