unless $ORIGINAL_SCENE_SAVE
$ORIGINAL_SCENE_SAVE = Scene_Save.clone
$ORIGINAL_SCENE_LOAD = Scene_Load.clone
$ORIGINAL_WINDOW_SAVEFILE = Window_SaveFile.clone
end
class Scene_Save < $ORIGINAL_SCENE_SAVE
def on_decision(filename)
super(filename)
buffer = ""
File.open(filename, "rb"){|f|buffer = Zlib::Deflate.deflate(f.read)}
File.open(filename, "wb"){|f|f.write [Zlib.crc32(buffer), buffer].pack("La*")}
end
end
class Scene_Load < $ORIGINAL_SCENE_LOAD
def on_decision(filename)
crc = 0; buffer = ""
File.open(filename, "rb"){|f|crc, buffer = f.read.unpack("La*")}
File.open(filename, "wb"){|f|f.write Zlib::Inflate.inflate(buffer)} if crc == Zlib.crc32(buffer)
super(filename)
end
end
class Window_SaveFile < $ORIGINAL_WINDOW_SAVEFILE
def initialize(index, filename)
@file_exist = FileTest.exist?(filename)
if @file_exist
File.open(filename, "rb"){|f|@crc, @buffer = f.read.unpack("La*")}
File.open(filename, "wb"){|f|f.write Zlib::Inflate.inflate(@buffer)}
end
super(index, filename)
if @file_exist
File.open(filename, "wb"){|f|f.write [@crc, @buffer].pack("La*")}
end
end
end