summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/memory/cheat_engine.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp
index 68d09d350..29284a42d 100644
--- a/src/core/memory/cheat_engine.cpp
+++ b/src/core/memory/cheat_engine.cpp
@@ -19,10 +19,24 @@
19#include "core/memory/cheat_engine.h" 19#include "core/memory/cheat_engine.h"
20 20
21namespace Core::Memory { 21namespace Core::Memory {
22 22namespace {
23constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12}; 23constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12};
24constexpr u32 KEYPAD_BITMASK = 0x3FFFFFF; 24constexpr u32 KEYPAD_BITMASK = 0x3FFFFFF;
25 25
26std::string_view ExtractName(std::string_view data, std::size_t start_index, char match) {
27 auto end_index = start_index;
28 while (data[end_index] != match) {
29 ++end_index;
30 if (end_index > data.size() ||
31 (end_index - start_index - 1) > sizeof(CheatDefinition::readable_name)) {
32 return {};
33 }
34 }
35
36 return data.substr(start_index, end_index - start_index);
37}
38} // Anonymous namespace
39
26StandardVmCallbacks::StandardVmCallbacks(Core::System& system, const CheatProcessMetadata& metadata) 40StandardVmCallbacks::StandardVmCallbacks(Core::System& system, const CheatProcessMetadata& metadata)
27 : metadata(metadata), system(system) {} 41 : metadata(metadata), system(system) {}
28 42
@@ -82,22 +96,6 @@ CheatParser::~CheatParser() = default;
82 96
83TextCheatParser::~TextCheatParser() = default; 97TextCheatParser::~TextCheatParser() = default;
84 98
85namespace {
86template <char match>
87std::string_view ExtractName(std::string_view data, std::size_t start_index) {
88 auto end_index = start_index;
89 while (data[end_index] != match) {
90 ++end_index;
91 if (end_index > data.size() ||
92 (end_index - start_index - 1) > sizeof(CheatDefinition::readable_name)) {
93 return {};
94 }
95 }
96
97 return data.substr(start_index, end_index - start_index);
98}
99} // Anonymous namespace
100
101std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const { 99std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
102 std::vector<CheatEntry> out(1); 100 std::vector<CheatEntry> out(1);
103 std::optional<u64> current_entry; 101 std::optional<u64> current_entry;
@@ -114,7 +112,7 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
114 return {}; 112 return {};
115 } 113 }
116 114
117 const auto name = ExtractName<'}'>(data, i + 1); 115 const auto name = ExtractName(data, i + 1, '}');
118 if (name.empty()) { 116 if (name.empty()) {
119 return {}; 117 return {};
120 } 118 }
@@ -131,7 +129,7 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
131 current_entry = out.size(); 129 current_entry = out.size();
132 out.emplace_back(); 130 out.emplace_back();
133 131
134 const auto name = ExtractName<']'>(data, i + 1); 132 const auto name = ExtractName(data, i + 1, ']');
135 if (name.empty()) { 133 if (name.empty()) {
136 return {}; 134 return {};
137 } 135 }