Merge pull request #12446 from lioncash/patch
Core/PatchEngine: Get rid of global system accessors
This commit is contained in:
commit
7f01c1ed5b
|
@ -170,7 +170,7 @@ void PatchEngineCallback(Core::System& system, u64 userdata, s64 cycles_late)
|
||||||
s64 next_schedule = 0;
|
s64 next_schedule = 0;
|
||||||
|
|
||||||
// Try to patch mem and run the Action Replay
|
// Try to patch mem and run the Action Replay
|
||||||
if (PatchEngine::ApplyFramePatches())
|
if (PatchEngine::ApplyFramePatches(system))
|
||||||
{
|
{
|
||||||
next_schedule = vi_interval - cycles_pruned;
|
next_schedule = vi_interval - cycles_pruned;
|
||||||
cycles_pruned = 0;
|
cycles_pruned = 0;
|
||||||
|
|
|
@ -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.
|
// 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)
|
static bool IsStackValid(const Core::CPUThreadGuard& guard)
|
||||||
{
|
{
|
||||||
auto& system = Core::System::GetInstance();
|
const auto& ppc_state = guard.GetSystem().GetPPCState();
|
||||||
auto& ppc_state = system.GetPPCState();
|
|
||||||
|
|
||||||
DEBUG_ASSERT(ppc_state.msr.DR && ppc_state.msr.IR);
|
DEBUG_ASSERT(ppc_state.msr.DR && ppc_state.msr.IR);
|
||||||
|
|
||||||
// Check the stack pointer
|
// Check the stack pointer
|
||||||
u32 SP = ppc_state.gpr[1];
|
const u32 SP = ppc_state.gpr[1];
|
||||||
if (!PowerPC::MMU::HostIsRAMAddress(guard, SP))
|
if (!PowerPC::MMU::HostIsRAMAddress(guard, SP))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Read the frame pointer from the stack (find 2nd frame from top), assert that it makes sense
|
// 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) ||
|
if (next_SP <= SP || !PowerPC::MMU::HostIsRAMAddress(guard, next_SP) ||
|
||||||
!PowerPC::MMU::HostIsRAMAddress(guard, next_SP + 4))
|
!PowerPC::MMU::HostIsRAMAddress(guard, next_SP + 4))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check the link register makes sense (that it points to a valid IBAT address)
|
// 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);
|
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);
|
std::erase(s_on_frame_memory, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ApplyFramePatches()
|
bool ApplyFramePatches(Core::System& system)
|
||||||
{
|
{
|
||||||
auto& system = Core::System::GetInstance();
|
const auto& ppc_state = system.GetPPCState();
|
||||||
auto& ppc_state = system.GetPPCState();
|
|
||||||
|
|
||||||
ASSERT(Core::IsCPUThread());
|
ASSERT(Core::IsCPUThread());
|
||||||
Core::CPUThreadGuard guard(system);
|
Core::CPUThreadGuard guard(system);
|
||||||
|
|
|
@ -13,6 +13,10 @@ namespace Common
|
||||||
{
|
{
|
||||||
class IniFile;
|
class IniFile;
|
||||||
}
|
}
|
||||||
|
namespace Core
|
||||||
|
{
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace PatchEngine
|
namespace PatchEngine
|
||||||
{
|
{
|
||||||
|
@ -57,7 +61,7 @@ void LoadPatches();
|
||||||
void AddMemoryPatch(std::size_t index);
|
void AddMemoryPatch(std::size_t index);
|
||||||
void RemoveMemoryPatch(std::size_t index);
|
void RemoveMemoryPatch(std::size_t index);
|
||||||
|
|
||||||
bool ApplyFramePatches();
|
bool ApplyFramePatches(Core::System& system);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
void Reload();
|
void Reload();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue