diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/memory/cheat_engine.cpp | 36 |
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 | ||
| 21 | namespace Core::Memory { | 21 | namespace Core::Memory { |
| 22 | 22 | namespace { | |
| 23 | constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12}; | 23 | constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12}; |
| 24 | constexpr u32 KEYPAD_BITMASK = 0x3FFFFFF; | 24 | constexpr u32 KEYPAD_BITMASK = 0x3FFFFFF; |
| 25 | 25 | ||
| 26 | std::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 | |||
| 26 | StandardVmCallbacks::StandardVmCallbacks(Core::System& system, const CheatProcessMetadata& metadata) | 40 | StandardVmCallbacks::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 | ||
| 83 | TextCheatParser::~TextCheatParser() = default; | 97 | TextCheatParser::~TextCheatParser() = default; |
| 84 | 98 | ||
| 85 | namespace { | ||
| 86 | template <char match> | ||
| 87 | std::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 | |||
| 101 | std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const { | 99 | std::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 | } |