diff --git a/src/core/patchmanager.cc b/src/core/patchmanager.cc index bbd36c504..cba311454 100644 --- a/src/core/patchmanager.cc +++ b/src/core/patchmanager.cc @@ -72,13 +72,14 @@ void PCSX::PatchManager::undoPatch(Patch& patch) { patch.active = false; } -PCSX::PatchManager::Patch::Type PCSX::PatchManager::findPatch(uint32_t address) const { +int PCSX::PatchManager::findPatch(uint32_t address) const { + int idx = 0; for (const Patch& patch : m_patches) { if (patch.addr == address) { - return patch.type; + return idx; } } - return PCSX::PatchManager::Patch::Type::None; + return -1; } void PCSX::PatchManager::deletePatch(uint32_t index) { diff --git a/src/core/patchmanager.h b/src/core/patchmanager.h index ed884223d..d81f402d2 100644 --- a/src/core/patchmanager.h +++ b/src/core/patchmanager.h @@ -48,7 +48,7 @@ class PatchManager { Patch& getPatch(int index) { return m_patches[index]; } int registerPatch(uint32_t address, Patch::Type type); - PatchManager::Patch::Type findPatch(uint32_t address) const; + int findPatch(uint32_t address) const; void deletePatch(uint32_t index); void deleteAllPatches(); void deactivateAll(); diff --git a/src/gui/widgets/assembly.cc b/src/gui/widgets/assembly.cc index f02cee83d..81513bf87 100644 --- a/src/gui/widgets/assembly.cc +++ b/src/gui/widgets/assembly.cc @@ -789,28 +789,29 @@ settings, otherwise debugging features may not work.)"); } if (absAddr < 0x00800000) { PatchManager& pm = *g_emulator->m_patchManager; - PatchManager::Patch::Type patchType = pm.findPatch(dispAddr); - switch (patchType) { - case PatchManager::Patch::Type::None: - if (ImGui::MenuItem(_("Patch in Return"))) { - pm.registerPatch(dispAddr, PatchManager::Patch::Type::Return); - } - if (ImGui::MenuItem(_("Patch in NOP"))) { - pm.registerPatch(dispAddr, PatchManager::Patch::Type::NOP); - } - break; - - case PatchManager::Patch::Type::Return: - if (ImGui::MenuItem(_("Remove Return Patch"))) { - pm.undoPatch(dispAddr); - } - break; + int patchIdx = pm.findPatch(dispAddr); + if (patchIdx == -1) { + if (ImGui::MenuItem(_("Patch in Return"))) { + pm.registerPatch(dispAddr, PatchManager::Patch::Type::Return); + } + if (ImGui::MenuItem(_("Patch in NOP"))) { + pm.registerPatch(dispAddr, PatchManager::Patch::Type::NOP); + } + } else { + PatchManager::Patch& patch = pm.getPatch(patchIdx); + switch (patch.type) { + case PatchManager::Patch::Type::Return: + if (ImGui::MenuItem(_("Delete Return Patch"))) { + pm.deletePatch(patchIdx); + } + break; - case PatchManager::Patch::Type::NOP: - if (ImGui::MenuItem(_("Remove NOP Patch"))) { - pm.undoPatch(dispAddr); - } - break; + case PatchManager::Patch::Type::NOP: + if (ImGui::MenuItem(_("Delete NOP Patch"))) { + pm.deletePatch(patchIdx); + } + break; + } } if (ImGui::MenuItem(_("Assemble"))) { diff --git a/src/gui/widgets/patches.cc b/src/gui/widgets/patches.cc index 57f5442c0..f4945f8bc 100644 --- a/src/gui/widgets/patches.cc +++ b/src/gui/widgets/patches.cc @@ -102,9 +102,18 @@ void PCSX::Widgets::Patches::draw(const char* title) { patchManager.deactivateAll(); } - ImGui::SameLine(); - if (ImGui::Button(_("Delete All"))) { - patchManager.deleteAllPatches(); + if (patchManager.getNumPatches() > 0) { + ImGui::SameLine(); + if (ImGui::Button(_("Delete All"))) { + ImGui::OpenPopup("delpatches_popup"); + } + if (ImGui::BeginPopup("delpatches_popup")) { + ImGui::TextUnformatted(_("Delete all Patches?")); + if (ImGui::Button(_("Delete##patches"))) { + patchManager.deleteAllPatches(); + } + ImGui::EndPopup(); + } } }