Advertisement
LeonMMS

Main

Dec 2nd, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.65 KB | None | 0 0
  1. advapi32 = Fiddle.dlopen('advapi32.dll')
  2. RegOpenKeyExA = Fiddle::Function.new(
  3.   advapi32['RegOpenKeyExA'],
  4.   [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_UINT, Fiddle::TYPE_UINT, Fiddle::TYPE_VOIDP],
  5.   Fiddle::TYPE_LONG
  6. )
  7. RegQueryValueExA = Fiddle::Function.new(
  8.   advapi32['RegQueryValueExA'],
  9.   [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
  10.   Fiddle::TYPE_LONG
  11. )
  12. RegCloseKey = Fiddle::Function.new(
  13.   advapi32['RegCloseKey'],
  14.   [Fiddle::TYPE_VOIDP],
  15.   Fiddle::TYPE_LONG
  16. )
  17. HKEY_LOCAL_MACHINE = 0x80000002
  18. KEY_READ = 0x20019
  19. ERROR_SUCCESS = 0
  20.  
  21. def read_registry_value(key_path, value_name)
  22.   hkey = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
  23.   key_path_utf8 = key_path.encode('UTF-8') + "\0"
  24.   value_name_utf8 = value_name.encode('UTF-8') + "\0"
  25.   result = RegOpenKeyExA.call(HKEY_LOCAL_MACHINE, key_path_utf8, 0, KEY_READ, hkey)
  26.   if result != ERROR_SUCCESS
  27.     raise "Failed to open registry key. Error code: #{result}"
  28.   end
  29.   data_type = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
  30.   data_size = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
  31.   data_size[0, 4] = [260].pack('L')
  32.   data = Fiddle::Pointer.malloc(260)
  33.   result = RegQueryValueExA.call(hkey.ptr.to_i, value_name_utf8, nil, data_type, data, data_size)
  34.   if result != ERROR_SUCCESS
  35.     RegCloseKey.call(hkey)
  36.     raise "Failed to query registry value. Error code: #{result}"
  37.   end
  38.   value = data.to_s(data_size[0, 4].unpack('L')[0]).strip
  39.   RegCloseKey.call(hkey)
  40.   value
  41. end
  42.  
  43. key_path = 'SOFTWARE\Enterbrain\RGSS3\RTP'
  44. value_name = 'RPGVXAce'
  45. rtp_path = read_registry_value(key_path, value_name)
  46. if rtp_path
  47.   puts "The path is: #{rtp_path.force_encoding(Encoding.default_external).encode('UTF-8')}"
  48.   Runtime.add_path(rtp_path)
  49.   Runtime.reload_cache
  50. end
  51. begin
  52.   rgss_main { SceneManager.run }
  53. rescue Exception => e
  54.   scripts = load_data('Data/Scripts.rvdata2')
  55.   regex = /{(\d+)}/
  56.   e_message = e.message
  57.   error_message = e_message.split('#').first
  58.   error_class = e_message.split(':').first.split('<').last
  59.   if e.class.to_s != "SystemExit"
  60.     backtrace = e.backtrace.join("\n").gsub(regex) { |match| scripts[$1.to_i][1] }
  61.     log_entry = "Error type: #{e.class}\n" + "Error message: #{error_message}#{error_class}\n" + "Backtrace:\n#{backtrace}\n"
  62.  
  63.     File.open("Logs/#{Time.now.strftime("Log-%Y-%m-%d-%H-%M-%S")}.txt", "w+") do |f|
  64.       f.write(log_entry)
  65.     end
  66.     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")}"
  67.   end
  68. end
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement