Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch System fixes/improvements #1801

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a bit cleaner to use std::optional<unsigned> for this, but that'll do for now.

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
@@ -1,4 +1,4 @@
/***************************************************************************

Check notice on line 1 in src/gui/widgets/assembly.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 1011 to 1013, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.
* Copyright (C) 2019 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -789,28 +789,29 @@
}
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;
}

Check warning on line 814 in src/gui/widgets/assembly.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

PCSX::Widgets::Assembly::draw already has high cyclomatic complexity, and now it increases in Lines of Code from 617 to 619. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check notice on line 814 in src/gui/widgets/assembly.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Bumpy Road Ahead

PCSX::Widgets::Assembly::draw increases from 27 to 28 logical blocks with deeply nested code, threshold is one single block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Check warning on line 814 in src/gui/widgets/assembly.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Deep, Nested Complexity

PCSX::Widgets::Assembly::draw increases in nested complexity depth from 6 to 7, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.
}

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 @@
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();
}

Check warning on line 116 in src/gui/widgets/patches.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

PCSX::Widgets::Patches::draw increases in cyclomatic complexity from 15 to 18, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 116 in src/gui/widgets/patches.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Bumpy Road Ahead

PCSX::Widgets::Patches::draw increases from 3 to 5 logical blocks with deeply nested code, threshold is one single block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
}
}

Expand Down
Loading