#=============================================================================== # RVDATA Compression # By Jet10985 (Jet) # Inspired by: Exhydra #=============================================================================== # This script will compress .rvdata files in your data directory, to save space # and to prevent hacking the data easily. # This script also compresses new save files. # This script has: 0 customization options. #=============================================================================== # Overwritten Methods: # None #------------------------------------------------------------------------------- # Aliased methods: # Object: load_data, save_data #=============================================================================== =begin This script will compress .rvdata everytime the game is started in TEST MODE. Not battle test, but just Test mode. This is to make sure the files are of the latest version. -------------------------------------------------------------------------------- Before releasing your game, or releasing updates, you should run the game in test mode to update the compressed files. Before compiling your game, you should remove (DO NOT DELETE) the regular .rvdata files. -------------------------------------------------------------------------------- This script does not compress Scripts.rvdata, do not remove it when you release your game. -------------------------------------------------------------------------------- This script will also compress save files, which means if you remove this script and then attempt to load a save game that was made while this script was active, it won't work. =end if $TEST && $@.nil? array = Dir.entries("Data") array.each {|a| next if [".", ".."].include?(a) next unless !a.include?(".crvdata") && !a.include?("Scripts.rvdata") if File.directory?("Data/#{a}") Dir.entries("Data/#{a}").each {|v| next if [".", ".."].include?(v) array.push("#{a}/#{v}") } next end t = Zlib::Deflate.deflate(Marshal.dump(load_data("Data/#{a}")), 9) save_data(t, "Data/#{a.gsub(".rvdata", "")}.crvdata") } end class Object alias jet1828_load_data load_data unless $@ def load_data(string) return $RGSS_SCRIPTS if string.include?("Scripts") string.gsub!(".rvdata", ".crvdata") f = Zlib::Inflate.inflate(jet1828_load_data(string)) return Marshal.load(f) end alias jet1838_save_data save_data unless $@ def save_data(var, file) f = Zlib::Deflate.deflate(Marshal.dump(var), 9) jet1838_save_data(f, "#{file.gsub(".rvdata", "")}.crvdata") end end module JetSaveMarshal def self.dump(object, io) Marshal.dump(Zlib::Deflate.deflate(Marshal.dump(object), 9), io) end def self.load(io) return Marshal.load(Zlib::Inflate.inflate(Marshal.load(io))) end end class Scene_File alias jet2846_write_save_data write_save_data unless $@ def write_save_data(*args, &block) old_marshal = Object.const_get(:Marshal) Scene_File.const_set(:Marshal, JetSaveMarshal) jet2846_write_save_data(*args, &block) Scene_File.const_set(:Marshal, old_marshal) end alias jet2846_read_save_data read_save_data unless $@ def read_save_data(*args, &block) old_marshal = Object.const_get(:Marshal) Scene_File.const_set(:Marshal, JetSaveMarshal) jet2846_read_save_data(*args, &block) Scene_File.const_set(:Marshal, old_marshal) end end class Window_SaveFile alias jet2756_load_gamedata load_gamedata unless $@ def load_gamedata(*args, &block) old_marshal = Object.const_get(:Marshal) Window_SaveFile.const_set(:Marshal, JetSaveMarshal) jet2756_load_gamedata(*args, &block) Window_SaveFile.const_set(:Marshal, old_marshal) end end