aboutsummaryrefslogtreecommitdiff
path: root/src/core/memory/cheat_engine.h
diff options
context:
space:
mode:
authorZach Hilman <zachhilman@gmail.com>2019-05-30 19:35:03 -0400
committerZach Hilman <zachhilman@gmail.com>2019-09-21 21:44:22 -0400
commit7d41c1f52390abb47e67d3fc43310e9d87fbd862 (patch)
tree79a4891115f3efd039b98cc47d63380d811021b1 /src/core/memory/cheat_engine.h
parent12aa127df3826857149bfc4b787cfb7df3fdcafe (diff)
cheat_engine: Move to memory and strip VM
This is to go with the Atmosphere VM port, now it just contains the callbacks needed for the interface between DmntCheatVm and yuzu, along with the cheat parsers.
Diffstat (limited to 'src/core/memory/cheat_engine.h')
-rw-r--r--src/core/memory/cheat_engine.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/core/memory/cheat_engine.h b/src/core/memory/cheat_engine.h
new file mode 100644
index 000000000..0f012e9b5
--- /dev/null
+++ b/src/core/memory/cheat_engine.h
@@ -0,0 +1,86 @@
+// Copyright 2018 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <atomic>
+#include <vector>
+#include "common/common_types.h"
+#include "core/memory/dmnt_cheat_types.h"
+#include "core/memory/dmnt_cheat_vm.h"
+
+namespace Core {
+class System;
+}
+
+namespace Core::Timing {
+class CoreTiming;
+struct EventType;
+} // namespace Core::Timing
+
+namespace Memory {
+
+class StandardVmCallbacks : public DmntCheatVm::Callbacks {
+public:
+ StandardVmCallbacks(const Core::System& system, const CheatProcessMetadata& metadata);
+ ~StandardVmCallbacks() override;
+
+ void MemoryRead(VAddr address, void* data, u64 size) override;
+ void MemoryWrite(VAddr address, const void* data, u64 size) override;
+ u64 HidKeysDown() override;
+ void DebugLog(u8 id, u64 value) override;
+ void CommandLog(std::string_view data) override;
+
+private:
+ VAddr SanitizeAddress(VAddr address) const;
+
+ const CheatProcessMetadata& metadata;
+ const Core::System& system;
+};
+
+// Intermediary class that parses a text file or other disk format for storing cheats into a
+// CheatList object, that can be used for execution.
+class CheatParser {
+public:
+ virtual ~CheatParser();
+
+ virtual std::vector<CheatEntry> Parse(const Core::System& system,
+ std::string_view data) const = 0;
+};
+
+// CheatParser implementation that parses text files
+class TextCheatParser final : public CheatParser {
+public:
+ ~TextCheatParser() override;
+
+ std::vector<CheatEntry> Parse(const Core::System& system, std::string_view data) const override;
+};
+
+// Class that encapsulates a CheatList and manages its interaction with memory and CoreTiming
+class CheatEngine final {
+public:
+ CheatEngine(Core::System& system_, std::vector<CheatEntry> cheats_,
+ const std::array<u8, 0x20>& build_id);
+ ~CheatEngine();
+
+ void Initialize();
+ void SetMainMemoryParameters(VAddr main_region_begin, u64 main_region_size);
+
+ void Reload(std::vector<CheatEntry> cheats);
+
+private:
+ void FrameCallback(u64 userdata, s64 cycles_late);
+
+ DmntCheatVm vm;
+ CheatProcessMetadata metadata;
+
+ std::vector<CheatEntry> cheats;
+ std::atomic_bool is_pending_reload{false};
+
+ Core::Timing::EventType* event{};
+ Core::Timing::CoreTiming& core_timing;
+ Core::System& system;
+};
+
+} // namespace Memory