08-05-2024, 07:49 PM
(05-16-2024, 05:15 AM)DerVVulfman Wrote: I've been thinking about RPG Editors... Its always the map that confuses people when it comes to making an editor. Well, the map is saved in the very same converted text format (rxdata, rvdata... whatever) as the rest of the game data in the ruby editions of RPGMaker.Time for a follow-up.
I decided to post a little script here that is my examination...
Yes, I am still investigating and doing fun hacks to the RPGMaker structure. But this time, I wondered about the scripts database itself!
You see, the scripts are nothing more than text files that are loaded into the game. BUT they can be ... massive. So the scripts database is not only converted from txt format into an .rxdata (or like) format, but the editor also COMPRESSES the text files to save space!
Fortunately, I looked into it, found it uses ZLIB compression (and there are a few areas like RUBY-DOC that describes it), so I found a means to extract each script into something... legible!
Code:
module Script_list
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def self.main
#
# Access the script database
script_search
#
end
#--------------------------------------------------------------------------
# * Search project script database
#--------------------------------------------------------------------------
def self.script_search
#
path_test = "Data/Scripts.rxdata" # Define scripts database file
scripts_db = load_data(path_test) # Load file into memory
list_size = scripts_db.size # Acquire total number of scripts
#
# Cycle through them all
for i in 0...list_size # Cycle through all scripts
a_script = scripts_db[i] # Acquire each individual script
end
#
# --------------------------------------
# Last script in list is 'Main'.
# Scripts are listed top-down
#
# Below is analysis
# --------------------------------------
#
p a_script # A whole record for one script
p a_script[0] # Numeric value currently unknown
p a_script[1] # Script name in editor
p a_script[2] # Script code - encoded/compressed
#
new_text = tool_inflate(a_script[2]) # Decoding the script code
p new_text # The script code unencoded shown
#
end
#--------------------------------------------------------------------------
# * ZLib Tool Inflate
# data_text : text to be inflated/expanded from encryption
#--------------------------------------------------------------------------
def self.tool_inflate(data_text)
#
zlib_tool = Zlib::Inflate.new() # Create the ZLib Inflate tool
new_text = zlib_tool.inflate(data_text) # Decrypt/expand with the tool
zlib_tool.finish # Show work done
zlib_tool.close # Close the tool
return new_text # Return the expanded text
#
end
#--------------------------------------------------------------------------
# * ZLib Tool Deflate
# data_text : text to be compressed/encrypted
# level : a defined compression level (see comments)
#--------------------------------------------------------------------------
def self.deflate(data_text, level = Zlib::BEST_COMPRESSION)
#
# Zlib::DEFAULT_COMPRESSION (-1)
# Zlib::NO_COMPRESSION 0
# Zlib::BEST_SPEED 1
# Zlib::BEST_COMPRESSION 9
#
zlib_tool = Zlib::Deflate.new(level) # Create the ZLib Inflate tool
new_text = zlib_tool.deflate(data_text, Zlib::FINISH) # Encrypt until done
zlib_tool.close # Close the tool
return new_text # Return the expanded text
#
end
end
# This executes at start
Script_list.main
Indeed, this right here can let me open up any script from the database and read it as text IN the game. And I have included a method that 'compresses' any code into the necessary form which can be properly saved.
Currently, I am only confused as to the purpose of the 'numeric values' attached to each script as identified in my above code.