Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- advapi32 = Fiddle.dlopen('advapi32.dll')
- RegOpenKeyExA = Fiddle::Function.new(
- advapi32['RegOpenKeyExA'],
- [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_UINT, Fiddle::TYPE_UINT, Fiddle::TYPE_VOIDP],
- Fiddle::TYPE_LONG
- )
- RegQueryValueExA = Fiddle::Function.new(
- advapi32['RegQueryValueExA'],
- [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
- Fiddle::TYPE_LONG
- )
- RegCloseKey = Fiddle::Function.new(
- advapi32['RegCloseKey'],
- [Fiddle::TYPE_VOIDP],
- Fiddle::TYPE_LONG
- )
- HKEY_LOCAL_MACHINE = 0x80000002
- KEY_READ = 0x20019
- ERROR_SUCCESS = 0
- def read_registry_value(key_path, value_name)
- hkey = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
- key_path_utf8 = key_path.encode('UTF-8') + "\0"
- value_name_utf8 = value_name.encode('UTF-8') + "\0"
- result = RegOpenKeyExA.call(HKEY_LOCAL_MACHINE, key_path_utf8, 0, KEY_READ, hkey)
- if result != ERROR_SUCCESS
- raise "Failed to open registry key. Error code: #{result}"
- end
- data_type = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
- data_size = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
- data_size[0, 4] = [260].pack('L')
- data = Fiddle::Pointer.malloc(260)
- result = RegQueryValueExA.call(hkey.ptr.to_i, value_name_utf8, nil, data_type, data, data_size)
- if result != ERROR_SUCCESS
- RegCloseKey.call(hkey)
- raise "Failed to query registry value. Error code: #{result}"
- end
- value = data.to_s(data_size[0, 4].unpack('L')[0]).strip
- RegCloseKey.call(hkey)
- value
- end
- key_path = 'SOFTWARE\Enterbrain\RGSS3\RTP'
- value_name = 'RPGVXAce'
- rtp_path = read_registry_value(key_path, value_name)
- if rtp_path
- puts "The path is: #{rtp_path.force_encoding(Encoding.default_external).encode('UTF-8')}"
- Runtime.add_path(rtp_path)
- Runtime.reload_cache
- end
- begin
- rgss_main { SceneManager.run }
- rescue Exception => e
- scripts = load_data('Data/Scripts.rvdata2')
- regex = /{(\d+)}/
- e_message = e.message
- error_message = e_message.split('#').first
- error_class = e_message.split(':').first.split('<').last
- if e.class.to_s != "SystemExit"
- backtrace = e.backtrace.join("\n").gsub(regex) { |match| scripts[$1.to_i][1] }
- log_entry = "Error type: #{e.class}\n" + "Error message: #{error_message}#{error_class}\n" + "Backtrace:\n#{backtrace}\n"
- File.open("Logs/#{Time.now.strftime("Log-%Y-%m-%d-%H-%M-%S")}.txt", "w+") do |f|
- f.write(log_entry)
- end
- raise "Error type: #{e.class}\n" + "Error message: #{error_message}#{error_class}\n\n" + "Line: #{e.backtrace[0].gsub(regex) { |match| scripts[$1.to_i][1] }}\n\n"+ "Time: #{Time.now.strftime("%Y-%m-%d-%H-%M-%S")}"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement