From 3266c20e3f27a459449b77214182be3f0332e8f4 Mon Sep 17 00:00:00 2001 From: PavelBARABANOV Date: Wed, 23 Sep 2026 00:36:47 +0200 Subject: [PATCH] [ips_layer] read magic from IPS file and fix EOF check (#4469) - [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions). - [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md) - [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability. ------------------- PatchIPS was reading the magic bytes from the target file instead of the IPS patch, and IsEOF used a strict > comparison that never matched for 3-byte IPS EOF markers. This caused IPS patches to be silently skipped, breaking the Russian localization mod for Persona 5. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4469 Reviewed-by: lizzie Reviewed-by: CamilleLaVey --- src/core/file_sys/ips_layer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp index 5a0ddb44f8..32e9041017 100644 --- a/src/core/file_sys/ips_layer.cpp +++ b/src/core/file_sys/ips_layer.cpp @@ -35,19 +35,22 @@ static IPSFileType IdentifyMagic(std::span magic) { } static bool IsEOF(IPSFileType type, std::span magic) { - return (type == IPSFileType::IPS && magic.size() > 3 && std::memcmp(magic.data(), "EOF", 3) == 0) - || (type == IPSFileType::IPS32 && magic.size() > 4 && std::memcmp(magic.data(), "EEOF", 4) == 0); + return (type == IPSFileType::IPS && magic.size() >= 3 && std::memcmp(magic.data(), "EOF", 3) == 0) + || (type == IPSFileType::IPS32 && magic.size() >= 4 && std::memcmp(magic.data(), "EEOF", 4) == 0); } VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { if (in == nullptr || ips == nullptr) return nullptr; - auto in_data = in->ReadAllBytes(); - auto const type = IdentifyMagic(in_data); + const auto type = IdentifyMagic(ips->ReadBytes(0x5)); if (type == IPSFileType::Error) return nullptr; + auto in_data = in->ReadAllBytes(); + if (in_data.size() == 0) + return nullptr; + std::vector temp(type == IPSFileType::IPS ? 3 : 4); u64 offset = 5; // After header while (ips->Read(temp.data(), temp.size(), offset) == temp.size()) {