diff --git a/Source/Core/Core/HW/SystemTimers.cpp b/Source/Core/Core/HW/SystemTimers.cpp index 988604d926..0a1ce4466f 100644 --- a/Source/Core/Core/HW/SystemTimers.cpp +++ b/Source/Core/Core/HW/SystemTimers.cpp @@ -170,7 +170,7 @@ void PatchEngineCallback(Core::System& system, u64 userdata, s64 cycles_late) s64 next_schedule = 0; // Try to patch mem and run the Action Replay - if (PatchEngine::ApplyFramePatches()) + if (PatchEngine::ApplyFramePatches(system)) { next_schedule = vi_interval - cycles_pruned; cycles_pruned = 0; diff --git a/Source/Core/Core/PatchEngine.cpp b/Source/Core/Core/PatchEngine.cpp index 74fe5c7f7e..b1477aa8e5 100644 --- a/Source/Core/Core/PatchEngine.cpp +++ b/Source/Core/Core/PatchEngine.cpp @@ -294,21 +294,22 @@ static void ApplyMemoryPatches(const Core::CPUThreadGuard& guard, // We require at least 2 stack frames, if the stack is shallower than that then it won't work. static bool IsStackValid(const Core::CPUThreadGuard& guard) { - auto& system = Core::System::GetInstance(); - auto& ppc_state = system.GetPPCState(); + const auto& ppc_state = guard.GetSystem().GetPPCState(); DEBUG_ASSERT(ppc_state.msr.DR && ppc_state.msr.IR); // Check the stack pointer - u32 SP = ppc_state.gpr[1]; + const u32 SP = ppc_state.gpr[1]; if (!PowerPC::MMU::HostIsRAMAddress(guard, SP)) return false; // Read the frame pointer from the stack (find 2nd frame from top), assert that it makes sense - u32 next_SP = PowerPC::MMU::HostRead_U32(guard, SP); + const u32 next_SP = PowerPC::MMU::HostRead_U32(guard, SP); if (next_SP <= SP || !PowerPC::MMU::HostIsRAMAddress(guard, next_SP) || !PowerPC::MMU::HostIsRAMAddress(guard, next_SP + 4)) + { return false; + } // Check the link register makes sense (that it points to a valid IBAT address) const u32 address = PowerPC::MMU::HostRead_U32(guard, next_SP + 4); @@ -328,10 +329,9 @@ void RemoveMemoryPatch(std::size_t index) std::erase(s_on_frame_memory, index); } -bool ApplyFramePatches() +bool ApplyFramePatches(Core::System& system) { - auto& system = Core::System::GetInstance(); - auto& ppc_state = system.GetPPCState(); + const auto& ppc_state = system.GetPPCState(); ASSERT(Core::IsCPUThread()); Core::CPUThreadGuard guard(system); diff --git a/Source/Core/Core/PatchEngine.h b/Source/Core/Core/PatchEngine.h index 9232e4b099..95c379957a 100644 --- a/Source/Core/Core/PatchEngine.h +++ b/Source/Core/Core/PatchEngine.h @@ -13,6 +13,10 @@ namespace Common { class IniFile; } +namespace Core +{ +class System; +} namespace PatchEngine { @@ -57,7 +61,7 @@ void LoadPatches(); void AddMemoryPatch(std::size_t index); void RemoveMemoryPatch(std::size_t index); -bool ApplyFramePatches(); +bool ApplyFramePatches(Core::System& system); void Shutdown(); void Reload();