mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 13:20:27 -06:00
Split out code for serializing/deserializing cheat lines
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
#include "Core/GeckoCodeConfig.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -176,8 +177,10 @@ std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localI
|
||||
{
|
||||
GeckoCode::Code new_code;
|
||||
// TODO: support options
|
||||
new_code.original_line = line;
|
||||
ss >> std::hex >> new_code.address >> new_code.data;
|
||||
if (std::optional<GeckoCode::Code> code = DeserializeLine(line))
|
||||
new_code = *code;
|
||||
else
|
||||
new_code.original_line = line;
|
||||
gcode.codes.push_back(new_code);
|
||||
}
|
||||
break;
|
||||
@ -251,4 +254,23 @@ void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes)
|
||||
inifile.SetLines("Gecko_Enabled", enabled_lines);
|
||||
inifile.SetLines("Gecko_Disabled", disabled_lines);
|
||||
}
|
||||
|
||||
std::optional<GeckoCode::Code> DeserializeLine(const std::string& line)
|
||||
{
|
||||
std::vector<std::string> items = SplitString(line, ' ');
|
||||
|
||||
GeckoCode::Code code;
|
||||
code.original_line = line;
|
||||
|
||||
if (items.size() < 2)
|
||||
return std::nullopt;
|
||||
|
||||
if (!TryParse(items[0], &code.address, 16))
|
||||
return std::nullopt;
|
||||
if (!TryParse(items[1], &code.data, 16))
|
||||
return std::nullopt;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
} // namespace Gecko
|
||||
|
Reference in New Issue
Block a user