From e10b3308c2b5b046f138f534477068d857e2b5c8 Mon Sep 17 00:00:00 2001 From: JoshuaMK <60854312+JoshuaMKW@users.noreply.github.com> Date: Sun, 23 Oct 2022 18:41:15 -0500 Subject: [PATCH 1/3] Fix patch corruption using find_if instead of remove_if --- Source/Core/Common/Debug/MemoryPatches.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Common/Debug/MemoryPatches.cpp b/Source/Core/Common/Debug/MemoryPatches.cpp index cbe7258bed..cd44708e15 100644 --- a/Source/Core/Common/Debug/MemoryPatches.cpp +++ b/Source/Core/Common/Debug/MemoryPatches.cpp @@ -44,7 +44,7 @@ const std::vector& MemoryPatches::GetPatches() const void MemoryPatches::UnsetPatch(u32 address) { - const auto it = std::remove_if(m_patches.begin(), m_patches.end(), + const auto it = std::find_if(m_patches.begin(), m_patches.end(), [address](const auto& patch) { return patch.address == address; }); if (it == m_patches.end()) From 2594447c2589a2575d71129291151fb99b9a1f3f Mon Sep 17 00:00:00 2001 From: JoshuaMK <60854312+JoshuaMKW@users.noreply.github.com> Date: Sun, 23 Oct 2022 18:42:34 -0500 Subject: [PATCH 2/3] Have UnsetPatch only unset the argument address --- Source/Core/Common/Debug/MemoryPatches.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Source/Core/Common/Debug/MemoryPatches.cpp b/Source/Core/Common/Debug/MemoryPatches.cpp index cd44708e15..43ed9efd49 100644 --- a/Source/Core/Common/Debug/MemoryPatches.cpp +++ b/Source/Core/Common/Debug/MemoryPatches.cpp @@ -50,14 +50,8 @@ void MemoryPatches::UnsetPatch(u32 address) if (it == m_patches.end()) return; - const std::size_t size = m_patches.size(); - std::size_t index = size - std::distance(it, m_patches.end()); - while (index < size) - { - DisablePatch(index); - ++index; - } - m_patches.erase(it, m_patches.end()); + const std::size_t index = std::distance(m_patches.begin(), it); + RemovePatch(index); } void MemoryPatches::EnablePatch(std::size_t index) From e2f4400f4941def98af3e2b30696f531baada7a7 Mon Sep 17 00:00:00 2001 From: JoshuaMK <60854312+JoshuaMKW@users.noreply.github.com> Date: Sun, 23 Oct 2022 18:44:12 -0500 Subject: [PATCH 3/3] Make SetPatch responsible for overwriting old patches --- Source/Core/Common/Debug/MemoryPatches.cpp | 3 ++- Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/Debug/MemoryPatches.cpp b/Source/Core/Common/Debug/MemoryPatches.cpp index 43ed9efd49..8dd9b5716d 100644 --- a/Source/Core/Common/Debug/MemoryPatches.cpp +++ b/Source/Core/Common/Debug/MemoryPatches.cpp @@ -32,6 +32,7 @@ void MemoryPatches::SetPatch(u32 address, u32 value) void MemoryPatches::SetPatch(u32 address, std::vector value) { + UnsetPatch(address); const std::size_t index = m_patches.size(); m_patches.emplace_back(address, std::move(value)); Patch(index); @@ -45,7 +46,7 @@ const std::vector& MemoryPatches::GetPatches() const void MemoryPatches::UnsetPatch(u32 address) { const auto it = std::find_if(m_patches.begin(), m_patches.end(), - [address](const auto& patch) { return patch.address == address; }); + [address](const auto& patch) { return patch.address == address; }); if (it == m_patches.end()) return; diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp index cdccd40732..06676c4b21 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp @@ -513,7 +513,6 @@ void CodeViewWidget::SetAddress(u32 address, SetAddressUpdate update) void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace) { - PowerPC::debug_interface.UnsetPatch(address); PowerPC::debug_interface.SetPatch(address, replace == ReplaceWith::BLR ? 0x4e800020 : 0x60000000); Update(); } @@ -823,7 +822,6 @@ void CodeViewWidget::OnReplaceInstruction() if (dialog.exec() == QDialog::Accepted) { - PowerPC::debug_interface.UnsetPatch(addr); PowerPC::debug_interface.SetPatch(addr, dialog.GetCode()); Update(); }