Skip to content

Commit

Permalink
Core: add option to apply memory patch to not store the existing valu…
Browse files Browse the repository at this point in the history
…e (used during locking)
  • Loading branch information
iwubcode committed Dec 23, 2022
1 parent 190cf5a commit 31bf9d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions Source/Core/Core/Debugger/PPCDebugInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h"

void ApplyMemoryPatch(Common::Debug::MemoryPatch& patch)
void ApplyMemoryPatch(Common::Debug::MemoryPatch& patch, bool store_existing_value)
{
if (patch.value.empty())
return;
Expand All @@ -36,9 +36,16 @@ void ApplyMemoryPatch(Common::Debug::MemoryPatch& patch)

for (u32 offset = 0; offset < size; ++offset)
{
const u8 value = PowerPC::HostRead_U8(address + offset);
PowerPC::HostWrite_U8(patch.value[offset], address + offset);
patch.value[offset] = value;
if (store_existing_value)
{
const u8 value = PowerPC::HostRead_U8(address + offset);
PowerPC::HostWrite_U8(patch.value[offset], address + offset);
patch.value[offset] = value;
}
else
{
PowerPC::HostWrite_U8(patch.value[offset], address + offset);
}

if (((address + offset) % 4) == 3)
PowerPC::ScheduleInvalidateCacheThreadSafe(Common::AlignDown(address + offset, 4));
Expand All @@ -53,7 +60,7 @@ void ApplyMemoryPatch(Common::Debug::MemoryPatch& patch)
void PPCPatches::ApplyExistingPatch(std::size_t index)
{
auto& patch = m_patches[index];
ApplyMemoryPatch(patch);
ApplyMemoryPatch(patch, false);
}

void PPCPatches::Patch(std::size_t index)
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Debugger/PPCDebugInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "Common/DebugInterface.h"
#include "Core/NetworkCaptureLogger.h"

void ApplyMemoryPatch(Common::Debug::MemoryPatch& patch);
void ApplyMemoryPatch(Common::Debug::MemoryPatch& patch, bool store_existing_value = true);

class PPCPatches final : public Common::Debug::MemoryPatches
{
Expand Down

0 comments on commit 31bf9d0

Please sign in to comment.