From 89d5d80d19086eb10a7a6c904394fbfb1d025982 Mon Sep 17 00:00:00 2001 From: sSAR <138690654+zUltimaPG3D@users.noreply.github.com> Date: Tue, 8 Apr 2025 18:10:11 +0200 Subject: [PATCH 1/3] feat: fix save bitmap saving/loading --- mkxp-z/Kawariki-patches/patches.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mkxp-z/Kawariki-patches/patches.rb b/mkxp-z/Kawariki-patches/patches.rb index bf3a3b2..cb59e44 100644 --- a/mkxp-z/Kawariki-patches/patches.rb +++ b/mkxp-z/Kawariki-patches/patches.rb @@ -2,6 +2,17 @@ # See preload.rb for Patch implementation module Preload + swap_chan = """ +def self.swap_chan(d, w) + rs = w*4 + r = d.bytes.each_slice(rs).map { |rw| rw.pack('C*') } + fd = r.reverse.join + c = fd.unpack('C*').each_slice(4).to_a + s = c.map { |r, g, b, a| [b, g, r, a] } + s.flatten.pack('C*') +end +""" + Patches = [ # Ports Patch.new("Zeus Fullscreen: Use mkxp builtin fullscreen instead (Alt+Enter)") @@ -179,6 +190,14 @@ module Preload .include?("def update_parallax") .sub!('@parallax.ox = $game_map.calc_parallax_x(@parallax.bitmap)', "begin; @parallax.ox = $game_map.calc_parallax_x(@parallax.bitmap)") .sub!('@parallax.oy = $game_map.calc_parallax_y(@parallax.bitmap)', "@parallax.oy = $game_map.calc_parallax_y(@parallax.bitmap); rescue; end"), + Patch.new("CHANGED: Save bitmap fix") + .if? {|script| script.name == "Save"} + .if? {|script| script.context[:rgss_version] == 2} + .include?("RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')") + .include?("RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')") + .sub!("RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')", swap_chan) + .sub!('RtlMoveMemory_pi.call(data, address, data.length)', "data = Bitmap.swap_chan(self.raw_data, width)") + .sub!('RtlMoveMemory_ip.call(b.address, Zlib::Inflate.inflate(zdata), w * h * 4)', "b.raw_data = self.swap_chan(Zlib::Inflate.inflate(zdata), w)"), # Generic Inline Patches Patch.new("Disable all font effects") .flag?(:no_font_effects) # KAWARIKI_MKXP_NO_FONT_EFFECTS From 03aac1a3fdb720001b77610d0f5bb67d3a501cc8 Mon Sep 17 00:00:00 2001 From: sSAR <138690654+zUltimaPG3D@users.noreply.github.com> Date: Mon, 21 Apr 2025 18:00:37 +0200 Subject: [PATCH 2/3] chore: implement kernel32::RtlMoveMemory --- mkxp-z/Kawariki-patches/libs/Win32API.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mkxp-z/Kawariki-patches/libs/Win32API.rb b/mkxp-z/Kawariki-patches/libs/Win32API.rb index 358c152..f0f267d 100644 --- a/mkxp-z/Kawariki-patches/libs/Win32API.rb +++ b/mkxp-z/Kawariki-patches/libs/Win32API.rb @@ -285,7 +285,9 @@ module Win32API end - + RtlMoveMemory = ->(dest, src, length) do + dest[0, length] = src[0, length] + end From 2c4b99c68ba24681270d63b70680f34c9f69b6ca Mon Sep 17 00:00:00 2001 From: sSAR <138690654+zUltimaPG3D@users.noreply.github.com> Date: Mon, 21 Apr 2025 18:02:07 +0200 Subject: [PATCH 3/3] chore: implement RtlMoveMemory in the other kawariki-patches as well --- Kawariki-patches/libs/Win32API.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Kawariki-patches/libs/Win32API.rb b/Kawariki-patches/libs/Win32API.rb index cbcf263..2541363 100644 --- a/Kawariki-patches/libs/Win32API.rb +++ b/Kawariki-patches/libs/Win32API.rb @@ -256,6 +256,9 @@ module Win32API #Preload.require "PreloadIni.rb" #Preload::Ini.writeIniString filename, appname, keyname, value end + RtlMoveMemory = ->(dest, src, length) do + dest[0, length] = src[0, length] + end end module User32