SHARE
TWEET

extract.rb

polectron Mar 27th, 2020 (edited) 199 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # frozen_string_literal: true
  2.  
  3. require 'zlib'
  4. require 'fileutils'
  5.  
  6. def pbFindScript(a, name)
  7.   a.each do |i|
  8.     next unless i
  9.     return i if i[1] == name
  10.   end
  11.   nil
  12. end
  13.  
  14. def load_data(fname)
  15.   File.open(fname, 'rb') do |f|
  16.     data = Marshal.load(f)
  17.     for d in data
  18.       d[1].force_encoding("UTF-8")
  19.     end
  20.     return data
  21.   end
  22. end
  23.  
  24. def extract_all_scripts
  25.   # msgwindow=Kernel.pbCreateMessageWindow
  26.   # Kernel.pbMessageDisplay(msgwindow,_INTL("Por favor, espera.\\wtnp[0]"))
  27.  
  28.   p 'Extrayendo scripts...'
  29.  
  30.   FileUtils.mkdir_p('export') unless File.directory?('export')
  31.  
  32.   File.open('export/export_info.txt', 'w') do |info|
  33.     info.puts("scripts\n")
  34.     begin
  35.       scripts = load_data('Data/Scripts.rxdata')
  36.       scripts ||= []
  37.     rescue StandardError => e
  38.       puts 'No se ha podido cargar Scripts.rxdata'
  39.       scripts = []
  40.     end
  41.  
  42.     scripts.each do |script|
  43.       if script[1].include?("\\") || script[1].include?("/") || script[1].include?(":") || script[1].include?("*") || script[1].include?("?") || script[1].include?("\"") || script[1].include?("<") || script[1].include?(">") || script[1].include?("|")
  44.         p "El script #{script[1]} tiene un nombre inválido, corrígelo antes de volver a intentar exportar los scripts."
  45.         gets
  46.         exit
  47.       end
  48.     end
  49.  
  50.     scripts.each do |script|
  51.       next if script[1].match(/=+/)
  52.       File.open("export/#{script[1]}.rb", 'wb') do |file|
  53.         file.write(Zlib::Inflate.inflate(script[2]))
  54.       end
  55.       info.puts("#{script[0]},#{script[1]}\n")
  56.     end
  57.  
  58.     info.puts("#-------------------\n")
  59.  
  60.     info.puts("constants\n")
  61.  
  62.     begin
  63.       scripts = load_data('Data/Constants.rxdata')
  64.       scripts ||= []
  65.     rescue StandardError
  66.       puts 'No se ha podido cargar Constants.rxdata'
  67.       scripts = []
  68.     end
  69.  
  70.     scripts.each do |script|
  71.       File.open("export/#{script[1]}.rb", 'wb') do |file|
  72.         file.write(Zlib::Inflate.inflate(script[2]))
  73.       end
  74.       info.puts("#{script[0]},#{script[1]}\n")
  75.     end
  76.   end
  77.   # Kernel.pbMessageDisplay(msgwindow, "Extracción finalizada")
  78.   # Kernel.pbDisposeMessageWindow(msgwindow)
  79.   p 'Extracción finalizada.'
  80. end
  81.  
  82. extract_all_scripts
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top