From ae69c8f8c462c4a01b40628d7bd4b9004f8a72dc Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 19 Jul 2023 21:09:44 +0300 Subject: [PATCH] [Cheats] Split gateway and AR --- CMakeLists.txt | 3 ++- include/action_replay.hpp | 22 ++++++++++++++++++++++ include/cheats.hpp | 30 +++++++++++++++++------------- src/core/action_replay.cpp | 14 ++++++++++++++ src/core/cheats.cpp | 25 +++++++++++++++++++++++-- 5 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 include/action_replay.hpp create mode 100644 src/core/action_replay.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 867f1e81..1d9c5b07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ endif() set(SOURCE_FILES src/main.cpp src/emulator.cpp src/io_file.cpp src/config.cpp src/core/CPU/cpu_dynarmic.cpp src/core/CPU/dynarmic_cycles.cpp src/core/memory.cpp src/renderer.cpp src/core/renderer_null/renderer_null.cpp - src/httpserver.cpp src/stb_image_write.c src/core/cheats.cpp + src/httpserver.cpp src/stb_image_write.c src/core/cheats.cpp src/core/action_replay.cpp ) set(CRYPTO_SOURCE_FILES src/core/crypto/aes_engine.cpp) set(KERNEL_SOURCE_FILES src/core/kernel/kernel.cpp src/core/kernel/resource_limits.cpp @@ -150,6 +150,7 @@ set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/termcolor.hpp include/result/result_gsp.hpp include/result/result_kernel.hpp include/result/result_os.hpp include/crypto/aes_engine.hpp include/metaprogramming.hpp include/PICA/pica_vertex.hpp include/config.hpp include/services/ir_user.hpp include/httpserver.hpp include/cheats.hpp + include/action_replay.hpp ) set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp diff --git a/include/action_replay.hpp b/include/action_replay.hpp new file mode 100644 index 00000000..4b5ab709 --- /dev/null +++ b/include/action_replay.hpp @@ -0,0 +1,22 @@ +#pragma once +#include +#include + +#include "helpers.hpp" + +class ActionReplay { + using Cheat = std::vector; // A cheat is really just a bunch of u32 opcodes + + u32 offset1, offset2; // Memory offset registers. Non-persistent. + u32 data1, data2; // Data offset registers. Non-persistent. + u32 storage1, storage2; // Storage registers. Persistent. + + // When an instruction does not specify which offset or data register to use, we use the "active" one + // Which is by default #1 and may be changed by certain AR operations + u32 *activeOffset, *activeData; + + public: + ActionReplay(); + void runCheat(const Cheat& cheat); + void reset(); +}; \ No newline at end of file diff --git a/include/cheats.hpp b/include/cheats.hpp index 22843544..ca69fa33 100644 --- a/include/cheats.hpp +++ b/include/cheats.hpp @@ -2,23 +2,27 @@ #include #include +#include "action_replay.hpp" #include "helpers.hpp" -class ActionReplay { - using Cheat = std::vector; // A cheat is really just a bunch of u32 opcodes - std::vector cheats; - - u32 offset1, offset2; // Memory offset registers. Non-persistent. - u32 data1, data2; // Data offset registers. Non-persistent. - u32 storage1, storage2; // Storage registers. Persistent. - - // When an instruction does not specify which offset or data register to use, we use the "active" one - // Which is by default #1 and may be changed by certain AR operations - u32 *activeOffset, *activeData; - +class Cheats { public: - ActionReplay(); + enum class CheatType { + ActionReplay, // CTRPF cheats + Gateway, + }; + + struct Cheat { + CheatType type; + std::vector instructions; + }; + + Cheats(); void addCheat(const Cheat& cheat); void runCheats(); void reset(); + + private: + ActionReplay ar; // An ActionReplay cheat machine for executing CTRPF codes + std::vector cheats; }; \ No newline at end of file diff --git a/src/core/action_replay.cpp b/src/core/action_replay.cpp new file mode 100644 index 00000000..293d879e --- /dev/null +++ b/src/core/action_replay.cpp @@ -0,0 +1,14 @@ +#include "action_replay.hpp" + +ActionReplay::ActionReplay() { reset(); } + +void ActionReplay::reset() { + // Default value of storage regs is 0 + storage1 = 0; + storage2 = 0; +} + +void ActionReplay::runCheat(const Cheat& cheat) { + // Set offset and data registers to 0 at the start of a cheat + data1 = data2 = offset1 = offset2 = 0; +} \ No newline at end of file diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index a797d092..9443670e 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -1,5 +1,26 @@ #include "cheats.hpp" -ActionReplay::ActionReplay() { reset(); } +Cheats::Cheats() { reset(); } -void ActionReplay::reset() { cheats.clear(); } \ No newline at end of file +void Cheats::reset() { + cheats.clear(); // Unload loaded cheats + ar.reset(); // Reset AR boi +} + +void Cheats::runCheats() { + for (const Cheat& cheat : cheats) { + switch (cheat.type) { + case CheatType::ActionReplay: { + ar.runCheat(cheat.instructions); + break; + } + + case CheatType::Gateway: { + Helpers::panic("Gateway cheats not supported yet! Only Action Replay is supported!"); + break; + } + + default: Helpers::panic("Unknown cheat type"); + } + } +} \ No newline at end of file