Save-Point
Rpg Maker Scripts Storing Algorithm for Scripters - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Tutorials (https://www.save-point.org/forum-19.html)
+--- Thread: Rpg Maker Scripts Storing Algorithm for Scripters (/thread-4369.html)



Rpg Maker Scripts Storing Algorithm for Scripters - Narzew - 09-18-2012

Hello. I'm explained the RMXP/VX/VXA scripts.rxdata structure and want to explain it to all.

It has an array structure.

Firstly, it's unique script ID. (??) (I wanna check more..)
Secondly, it's script name.
Thirdly, it's Zlib compressed script source.

For Example :

Script.rxdata =
[
[23333439, "*First script", Zlib["source_code_of_script1"]],
[39283232, "*Second script", Zlib["source_code_of_script2"]]
]

The algorithm is not fully checked. It's works with unpacking. I'm not test it with packing too.
If you want to build scripts.rxdata use 0 as first argument :)
The second and third is 100 % checked.
I must check the first unique ID generation :)
I'll add it so soon.

Nice working.

Some practice :

Content Hidden

Nice working.


RE: Rpg Maker Scripts Storing Algorithm for Scripters - hanetzer - 07-27-2013

As always this is an entirely too useful script; I've used it to load the entire Scripts.rxdat into my irb session. As a monument to the eternity of the internet here is the script:
Code:
require 'zlib'
def save_data(obj, filename)
  File.open(filename, "wb") { |f|
    Marshal.dump(obj, f)
  }
end

def load_data(filename)
  File.open(filename, "rb") { |f|
    obj = Marshal.load(f)
  }
end
script = load_data("Data/Scripts.rxdata")
script.each {|s| TOPLEVEL_BINDING.eval(Zlib::Inflate.inflate(s.at(2)))  }
Something along these lines must be embedded into the RGSS dll or Game.exe; This is what starts the actual Ruby Game Process.


RE: Rpg Maker Scripts Storing Algorithm for Scripters - hanetzer - 03-06-2014

Heyo!
Been fiddling with this for the sake of the ReGaL engine, and made a bit of what I'd call an improvement to it; instead of one large text file, It now dumps to individual files for each script; my code (thanks for the start Narzew):
Code:
def save_script(scriptfile='Data/Scripts.rxdata')
  script = load_data(scriptfile)
  script.each {|s|
    file = File.open(s.at(1), 'wb')
    file.write(Zlib::Inflate.inflate(s.at(2)))
    file.close
  }
end
Next I'll see about writing a script to reconstitute the individual files into the Scripts.rxdata file


RE: Rpg Maker Scripts Storing Algorithm for Scripters - hanetzer - 03-15-2014

I have completed your script; It can now be used to 1. Write scripts from Scripts.rxdata to individual script files and 2. Reconstitute the scripts from the individual scripts saved from the first use.

The resultant Scripts.rxdata is in fact a perfect binary match for the original, sharing the same md5sum and sha512sum. Note, this is only because the dumped scripts were not edited; but, obviously, if you make changes to the script it will affect the output of the final scriptfile. I only state the fact its identical because it proves the process is perfect.
Code:
#!/usr/bin/env ruby
require 'zlib'
def load_data(filename)
  File.open(filename, "rb") { |f|
    obj = Marshal.load(f)
  }
end

def save_data(obj, filename)
  File.open(filename, "wb") { |f|
    Marshal.dump(obj, f)
  }
end

def dump_script(scriptfile, scriptindex)
  script = load_data(scriptfile)
  script.each { |s|
    file = File.open(s.at(1), 'wb')
    file.write(Zlib::Inflate.inflate(s.at(2)))
    file.close
    s.delete_at(2)
    save_data(script, scriptindex)
  }
end
def assemble_scripts(scriptindex, scriptfile)
  index = load_data(scriptindex)
  index.each { |s|
    file = File.readlines(s.at(1))
    s.push(Zlib::Deflate.deflate(file.join))
    save_data(index, scriptfile)
  }
end
Usage:
dissassemble_scripts("Scripts.rxdata", "ScriptIndex.dat") will write out all the scripts in Scripts.rxdata into individual script text files and save an index file as ScriptIndex.dat
assemble_scripts("ScriptIndex.dat", "Scripts.rxdata") will reconstitute the (edited, if so desired) scripts using the index we saved as ScriptIndex.dat and save the reconstituted file as Scripts.rxdata; I've not tested with a file named Scripts.rxdata actually existing, so not sure if it will work (I had deleted the file after disassembly in order to make sure I wasn't simply seeing the original Scripts.rxdata and assuming success)