diff --git a/include/cheats.hpp b/include/cheats.hpp index be370c24..c8d7c763 100644 --- a/include/cheats.hpp +++ b/include/cheats.hpp @@ -26,7 +26,11 @@ class Cheats { void reset(); void run(); + void clear(); + bool haveCheats() const { return cheatsLoaded; } + private: ActionReplay ar; // An ActionReplay cheat machine for executing CTRPF codes std::vector cheats; + bool cheatsLoaded = false; }; \ No newline at end of file diff --git a/include/emulator.hpp b/include/emulator.hpp index d738aef3..8782fb1f 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -43,9 +43,6 @@ class Emulator { SDL_GameController* gameController = nullptr; int gameControllerID; - // Shows whether we've loaded any action replay codes - bool haveCheats = false; - // Variables to keep track of whether the user is controlling the 3DS analog stick with their keyboard // This is done so when a gamepad is connected, we won't automatically override the 3DS analog stick settings with the gamepad's state // And so the user can still use the keyboard to control the analog diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index 8bf5e316..618460c5 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -3,11 +3,19 @@ Cheats::Cheats(Memory& mem, HIDService& hid) : ar(mem, hid) { reset(); } void Cheats::reset() { - cheats.clear(); // Unload loaded cheats - ar.reset(); // Reset ActionReplay + clear(); // Clear loaded cheats + ar.reset(); // Reset ActionReplay } -void Cheats::addCheat(const Cheat& cheat) { cheats.push_back(cheat); } +void Cheats::addCheat(const Cheat& cheat) { + cheats.push_back(cheat); + cheatsLoaded = true; +} + +void Cheats::clear() { + cheats.clear(); + cheatsLoaded = false; +} void Cheats::run() { for (const Cheat& cheat : cheats) { diff --git a/src/emulator.cpp b/src/emulator.cpp index bcca5ffa..9d933bd7 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -93,7 +93,6 @@ void Emulator::reset(ReloadOption reload) { // We're resetting without reloading the ROM, so yeet cheats if (reload == ReloadOption::NoReload) { - haveCheats = false; cheats.reset(); } @@ -357,7 +356,8 @@ void Emulator::runFrame() { srv.sendGPUInterrupt(GPUInterrupt::VBlank0); srv.sendGPUInterrupt(GPUInterrupt::VBlank1); - if (haveCheats) [[unlikely]] { + // Run cheats if any are loaded + if (cheats.haveCheats()) [[unlikely]] { cheats.run(); } }