Skip to content

Commit

Permalink
Merge pull request #1801 from rocketz/Breakpoints-improvements
Browse files Browse the repository at this point in the history
Patch System fixes/improvements
  • Loading branch information
nicolasnoble authored Nov 18, 2024
2 parents 3c9b655 + 80b4745 commit ffc32ac
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
7 changes: 4 additions & 3 deletions src/core/patchmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/patchmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
43 changes: 22 additions & 21 deletions src/gui/widgets/assembly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"))) {
Expand Down
15 changes: 12 additions & 3 deletions src/gui/widgets/patches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down

0 comments on commit ffc32ac

Please sign in to comment.