From 17d94cd3586223aa023a0ef998868727bf24af9f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 29 Oct 2022 17:56:47 -0700 Subject: [PATCH] SaveState: Restore replacements in only one place. --- Core/HLE/ReplaceTables.cpp | 3 ++- Core/MIPS/x86/Jit.cpp | 2 +- Core/SaveState.cpp | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Core/HLE/ReplaceTables.cpp b/Core/HLE/ReplaceTables.cpp index 85817a49e3..3797e660e2 100644 --- a/Core/HLE/ReplaceTables.cpp +++ b/Core/HLE/ReplaceTables.cpp @@ -1652,7 +1652,8 @@ std::map SaveAndClearReplacements() { std::map saved; for (auto it = replacedInstructions.begin(), end = replacedInstructions.end(); it != end; ++it) { const u32 addr = it->first; - const u32 curInstr = Memory::Read_U32(addr); + // This will not retain jit blocks. + const u32 curInstr = Memory::Read_Opcode_JIT(addr).encoding; if (MIPS_IS_REPLACEMENT(curInstr)) { saved[addr] = curInstr; Memory::Write_U32(it->second, addr); diff --git a/Core/MIPS/x86/Jit.cpp b/Core/MIPS/x86/Jit.cpp index 266b97da00..97f32b7b72 100644 --- a/Core/MIPS/x86/Jit.cpp +++ b/Core/MIPS/x86/Jit.cpp @@ -591,7 +591,7 @@ void Jit::Comp_ReplacementFunc(MIPSOpcode op) { // Not sure about the cause. Memory::Opcode origInstruction = Memory::Read_Instruction(GetCompilerPC(), true); if (origInstruction.encoding == op.encoding) { - ERROR_LOG(HLE, "Replacement broken (savestate problem?): %08x", op.encoding); + ERROR_LOG(HLE, "Replacement broken (savestate problem?): %08x at %08x", op.encoding, GetCompilerPC()); return; } diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index bf9f3070ca..148e4307d1 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -316,7 +316,11 @@ namespace SaveState } else { Memory::DoState(p); } - RestoreSavedReplacements(savedReplacements); + + // Don't bother restoring if reading, we'll deal with that in KernelModuleDoState. + // In theory, different functions might have been runtime loaded in the state. + if (p.mode != p.MODE_READ) + RestoreSavedReplacements(savedReplacements); MemoryStick_DoState(p); currentMIPS->DoState(p);