public RGSSReader() { infoDown = onAnimationsInfoDown; dataDown = onAnimationFrameDataDown; timingDown = onAnimationFrameTimingDown; rxdataPath = null; animations = null; id = 0; dll = new DllInvoke("rgss.dll"); ((RGSSInitialize)dll.Invoke("RGSSInitialize", typeof(RGSSInitialize)))(dll.getLib()); IntPtr rb_define_module = IntPtr.Add(dll.getLib(), 0x20400); RGSSDefineModule rbDefineModule = (RGSSDefineModule)Marshal.GetDelegateForFunctionPointer(rb_define_module, typeof(RGSSDefineModule)); IntPtr fux2 = rbDefineModule(Marshal.StringToCoTaskMemAnsi("Fux2")); IntPtr rb_define_module_function = IntPtr.Add(dll.getLib(), 0x20B50); RGSSDefineModuleFunction rbDefineModuleFunction = (RGSSDefineModuleFunction)Marshal.GetDelegateForFunctionPointer(rb_define_module_function, typeof(RGSSDefineModuleFunction)); rbDefineModuleFunction(fux2, Marshal.StringToCoTaskMemAnsi("sendAnimationsInfo"), Marshal.GetFunctionPointerForDelegate(infoDown), 1); rbDefineModuleFunction(fux2, Marshal.StringToCoTaskMemAnsi("sendAnimationFramesData"), Marshal.GetFunctionPointerForDelegate(dataDown), 1); rbDefineModuleFunction(fux2, Marshal.StringToCoTaskMemAnsi("sendAnimationTimingData"), Marshal.GetFunctionPointerForDelegate(timingDown), 2); eval = (RGSSEval)dll.Invoke("RGSSEval", typeof(RGSSEval)); }
static void TestDynamicDllImport(string path) { Directory.SetCurrentDirectory(path); dllHandle = LoadLibrary(@"System\RGSS301.dll"); Console.WriteLine("Loaded library"); if (dllHandle == IntPtr.Zero) { return; } IntPtr addr = GetProcAddress(dllHandle, "RGSSInitialize3"); Console.WriteLine($"RGSSInitialize3 Address {addr}"); if (addr == IntPtr.Zero) { return; } RGSSInitialize3 init = (RGSSInitialize3)Marshal.GetDelegateForFunctionPointer(addr, typeof(RGSSInitialize3)); init(); IntPtr addr2 = GetProcAddress(dllHandle, "RGSSEval"); Console.WriteLine($"RGSSEval Address {addr2}"); if (addr2 == IntPtr.Zero) { return; } RGSSEval eval = (RGSSEval)Marshal.GetDelegateForFunctionPointer(addr2, typeof(RGSSEval)); int ret = eval(@"# encoding: utf-8 F = 'rgss_search_events.txt' version = 0 version = 1 if !Dir.glob('*.rxproj').empty? version = 2 if !Dir.glob('*.rvproj').empty? version = 3 if !Dir.glob('*.rvproj2').empty? V = version def encode(str) [str].pack('m0') end class Mat def initialize v, n @v = v @n = n end def === n return false unless @v == V @n === n end end def xp(n) Mat.new 1, n end def vx(n) Mat.new 2, n end def va(n) Mat.new 3, n end if version == 0 out = ['!', encode('invalid project: not found *.rvproj2')].join(' ') File.open(file, 'w') { |f| f.puts out } else out = []; mapids = [] ext = [nil, 'rxdata', 'rvdata', 'rvdata2'][version] if File.exist? ""Data/MapInfos.#{ext}"" mapinfos = load_data ""Data/MapInfos.#{ext}"" mapinfos.each do |i, v| mapids << i out << ['M', i, encode(v.name)].join(' ') end end if File.exist? ""Data/System.#{ext}"" systems = load_data ""Data/System.#{ext}"" systems.switches.each_with_index do |s, i| next if s == nil || s == '' out << ['S', i, encode(s)].join(' ') end systems.variables.each_with_index do |s, i| next if s == nil || s == '' out << ['V', i, encode(s)].join(' ') end end mapids.each do |mapid| file = ""Data/Map%03d.#{ext}"" % mapid next if !File.exist?(file) map = load_data file map.events.each_value do |e| e.pages.each_with_index do |page, pageid| s = []; v = [] if page.condition.switch1_valid s << page.condition.switch1_id end if page.condition.switch2_valid s << page.condition.switch2_id end if page.condition.variable_valid v << page.condition.variable_id end page.list.each do |command| params = command.parameters case command.code when 111 # if case params[0] when 0 # switch s << params[1] when 1 # variable v << params[1] if params[2] != 0 v << params[3] end end when 121 # switch = (params[0]..params[1]).each do |i| s << i end when 122 # var = if params[3] == 1 v << params[4] end (params[0]..params[1]).each do |i| v << i end when 201, vx(202), va(202) # transfer if params[0] != 0 v << params[1] v << params[2] v << params[3] end when xp(202), vx(203), va(203) # move event if params[1] == 1 v << params[2] v << params[3] end when 231 # show pic if params[3] != 0 v << params[4] v << params[5] end when 232 # move pic if params[3] != 0 v << params[4] v << params[5] end when va(285) # get location info if params[2] != 0 v << params[3] v << params[4] end v << params[0] when 301 # battle if @params[0] == 1 v << @params[1] end end end s = s.uniq s = s.empty? ? '0' : encode(s.join(' ')) v = v.uniq v = v.empty? ? '0' : encode(v.join(' ')) name = e.name.empty? ? '0' : encode(e.name) out << [mapid, e.id, pageid, e.x, e.y, s, v, name].join(' ') end end end File.open(F, 'w') { |f| f.puts out } end "); Console.WriteLine(ret); }
public void Refresh() { string AppName = GetAppName(ProjectPath); Directory.SetCurrentDirectory(ProjectPath); string DllFile = ReadIni("Game", "Library"); if (hModule == IntPtr.Zero) { hModule = LoadLibrary(DllFile); } IntPtr addrInit = GetProcAddress(hModule, GetInitFuncName(Version)); RGSSInitialize Init = (RGSSInitialize)Marshal.GetDelegateForFunctionPointer(addrInit, typeof(RGSSInitialize)); Init(); IntPtr addrEval = GetProcAddress(hModule, "RGSSEval"); RGSSEval Eval = (RGSSEval)Marshal.GetDelegateForFunctionPointer(addrEval, typeof(RGSSEval)); if (File.Exists("rgss_search_event.rb")) { Eval(File.ReadAllText("rgss_search_event.rb")); } else if (Eval(Text) == 6) { Reason = ErrorReason.RGSSError; ShowReason(); } IntPtr addrFin = GetProcAddress(hModule, "RGSSFinalize"); RGSSFinalize Fin = (RGSSFinalize)Marshal.GetDelegateForFunctionPointer(addrFin, typeof(RGSSFinalize)); Fin(); EventPages.Clear(); if (!File.Exists("rgss_search_events.txt")) { return; } foreach (string line in File.ReadLines("rgss_search_events.txt")) { string[] tokens = line.Split(null); if (tokens.Length == 0) { continue; } switch (tokens[0]) { case "M": { if (tokens.Length != 3) { break; } if (Int32.TryParse(tokens[1], out int MapId)) { try { byte[] bytes = Convert.FromBase64String(tokens[2]); string MapName = Encoding.UTF8.GetString(bytes); MapNames.Add(MapId, MapName); } catch { } } break; } case "S": { if (tokens.Length != 3) { break; } if (Int32.TryParse(tokens[1], out int SwitchId)) { try { byte[] bytes = Convert.FromBase64String(tokens[2]); string SwitchName = Encoding.UTF8.GetString(bytes); Switches.Add(SwitchId, SwitchName); } catch { } } break; } case "V": { if (tokens.Length != 3) { break; } if (Int32.TryParse(tokens[1], out int VariableId)) { try { byte[] bytes = Convert.FromBase64String(tokens[2]); string VariableName = Encoding.UTF8.GetString(bytes); Variables.Add(VariableId, VariableName); } catch { } } break; } case "E": { if (tokens.Length != 9) { break; } EventPage page = new EventPage(); if (!Int32.TryParse(tokens[1], out int MapId)) { break; } page.MapId = MapId; if (!Int32.TryParse(tokens[2], out int EventId)) { break; } page.EventId = EventId; if (!Int32.TryParse(tokens[3], out int PageNumber)) { break; } page.PageNumber = PageNumber; if (!Int32.TryParse(tokens[4], out int X)) { break; } page.X = X; if (!Int32.TryParse(tokens[5], out int Y)) { break; } page.Y = Y; try { List <int> Switches = new List <int>(); byte[] bytes = Convert.FromBase64String(tokens[6]); string switches = Encoding.UTF8.GetString(bytes); foreach (string s in switches.Split(null)) { if (!Int32.TryParse(s, out int SwitchId)) { continue; } Switches.Add(SwitchId); } page.Switches = Switches.ToArray(); } catch { page.Switches = new int[0]; } try { List <int> Variables = new List <int>(); byte[] bytes = Convert.FromBase64String(tokens[7]); string variables = Encoding.UTF8.GetString(bytes); foreach (string s in variables.Split(null)) { if (!Int32.TryParse(s, out int VariableId)) { continue; } Variables.Add(VariableId); } page.Variables = Variables.ToArray(); } catch { page.Variables = new int[0]; } try { byte[] bytes = Convert.FromBase64String(tokens[8]); string name = Encoding.UTF8.GetString(bytes); page.Name = name; } catch { } EventPages.Add(page); break; } } } }