mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
cheat_engine: Convert ExtractName into a non-template function
We don't need to create two separate instantiations of the same code, we can simply make the character template argument a regular function parameter.
This commit is contained in:
parent
ba7eb5abf4
commit
3a8464cde2
1 changed files with 17 additions and 19 deletions
|
@ -19,10 +19,24 @@
|
||||||
#include "core/memory/cheat_engine.h"
|
#include "core/memory/cheat_engine.h"
|
||||||
|
|
||||||
namespace Core::Memory {
|
namespace Core::Memory {
|
||||||
|
namespace {
|
||||||
constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12};
|
constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12};
|
||||||
constexpr u32 KEYPAD_BITMASK = 0x3FFFFFF;
|
constexpr u32 KEYPAD_BITMASK = 0x3FFFFFF;
|
||||||
|
|
||||||
|
std::string_view ExtractName(std::string_view data, std::size_t start_index, char match) {
|
||||||
|
auto end_index = start_index;
|
||||||
|
while (data[end_index] != match) {
|
||||||
|
++end_index;
|
||||||
|
if (end_index > data.size() ||
|
||||||
|
(end_index - start_index - 1) > sizeof(CheatDefinition::readable_name)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.substr(start_index, end_index - start_index);
|
||||||
|
}
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
StandardVmCallbacks::StandardVmCallbacks(Core::System& system, const CheatProcessMetadata& metadata)
|
StandardVmCallbacks::StandardVmCallbacks(Core::System& system, const CheatProcessMetadata& metadata)
|
||||||
: metadata(metadata), system(system) {}
|
: metadata(metadata), system(system) {}
|
||||||
|
|
||||||
|
@ -82,22 +96,6 @@ CheatParser::~CheatParser() = default;
|
||||||
|
|
||||||
TextCheatParser::~TextCheatParser() = default;
|
TextCheatParser::~TextCheatParser() = default;
|
||||||
|
|
||||||
namespace {
|
|
||||||
template <char match>
|
|
||||||
std::string_view ExtractName(std::string_view data, std::size_t start_index) {
|
|
||||||
auto end_index = start_index;
|
|
||||||
while (data[end_index] != match) {
|
|
||||||
++end_index;
|
|
||||||
if (end_index > data.size() ||
|
|
||||||
(end_index - start_index - 1) > sizeof(CheatDefinition::readable_name)) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return data.substr(start_index, end_index - start_index);
|
|
||||||
}
|
|
||||||
} // Anonymous namespace
|
|
||||||
|
|
||||||
std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
|
std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
|
||||||
std::vector<CheatEntry> out(1);
|
std::vector<CheatEntry> out(1);
|
||||||
std::optional<u64> current_entry;
|
std::optional<u64> current_entry;
|
||||||
|
@ -114,7 +112,7 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto name = ExtractName<'}'>(data, i + 1);
|
const auto name = ExtractName(data, i + 1, '}');
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -131,7 +129,7 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
|
||||||
current_entry = out.size();
|
current_entry = out.size();
|
||||||
out.emplace_back();
|
out.emplace_back();
|
||||||
|
|
||||||
const auto name = ExtractName<']'>(data, i + 1);
|
const auto name = ExtractName(data, i + 1, ']');
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue