Core: Save the disabling of default enabled codes

The previous commit adjusted the code for loading
and this commit adjusts the code for saving.
This commit is contained in:
JosJuice 2020-12-10 15:21:04 +01:00
parent 366cfd0f8c
commit d77a9ad1b6
7 changed files with 48 additions and 14 deletions

View File

@ -266,6 +266,12 @@ std::vector<ARCode> LoadCodes(const IniFile& global_ini, const IniFile& local_in
}
ReadEnabledAndDisabled(*ini, "ActionReplay", &codes);
if (ini == &global_ini)
{
for (ARCode& code : codes)
code.default_enabled = code.enabled;
}
}
return codes;
@ -275,21 +281,27 @@ void SaveCodes(IniFile* local_ini, const std::vector<ARCode>& codes)
{
std::vector<std::string> lines;
std::vector<std::string> enabled_lines;
std::vector<std::string> disabled_lines;
for (const ActionReplay::ARCode& code : codes)
{
if (code.enabled)
enabled_lines.emplace_back("$" + code.name);
enabled_lines.emplace_back('$' + code.name);
else if (code.default_enabled)
disabled_lines.emplace_back('$' + code.name);
if (code.user_defined)
{
lines.emplace_back("$" + code.name);
lines.emplace_back('$' + code.name);
for (const ActionReplay::AREntry& op : code.ops)
{
lines.emplace_back(fmt::format("{:08X} {:08X}", op.cmd_addr, op.value));
}
}
}
local_ini->SetLines("ActionReplay_Enabled", enabled_lines);
local_ini->SetLines("ActionReplay_Disabled", disabled_lines);
local_ini->SetLines("ActionReplay", lines);
}

View File

@ -29,6 +29,7 @@ struct ARCode
std::string name;
std::vector<AREntry> ops;
bool enabled = false;
bool default_enabled = false;
bool user_defined = false;
};

View File

@ -29,6 +29,7 @@ public:
std::vector<std::string> notes;
bool enabled = false;
bool default_enabled = false;
bool user_defined = false;
bool Exist(u32 address, u32 data) const;

View File

@ -192,6 +192,12 @@ std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localI
}
ReadEnabledAndDisabled(*ini, "Gecko", &gcodes);
if (ini == &globalIni)
{
for (GeckoCode& code : gcodes)
code.default_enabled = code.enabled;
}
}
return gcodes;
@ -210,12 +216,8 @@ static std::string MakeGeckoCodeTitle(const GeckoCode& code)
}
// used by the SaveGeckoCodes function
static void SaveGeckoCode(std::vector<std::string>& lines, std::vector<std::string>& enabledLines,
const GeckoCode& gcode)
static void SaveGeckoCode(std::vector<std::string>& lines, const GeckoCode& gcode)
{
if (gcode.enabled)
enabledLines.push_back('$' + gcode.name);
if (!gcode.user_defined)
return;
@ -235,14 +237,21 @@ static void SaveGeckoCode(std::vector<std::string>& lines, std::vector<std::stri
void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes)
{
std::vector<std::string> lines;
std::vector<std::string> enabledLines;
std::vector<std::string> enabled_lines;
std::vector<std::string> disabled_lines;
for (const GeckoCode& geckoCode : gcodes)
{
SaveGeckoCode(lines, enabledLines, geckoCode);
if (geckoCode.enabled)
enabled_lines.emplace_back('$' + geckoCode.name);
else if (geckoCode.default_enabled)
disabled_lines.emplace_back('$' + geckoCode.name);
SaveGeckoCode(lines, geckoCode);
}
inifile.SetLines("Gecko", lines);
inifile.SetLines("Gecko_Enabled", enabledLines);
inifile.SetLines("Gecko_Enabled", enabled_lines);
inifile.SetLines("Gecko_Disabled", disabled_lines);
}
} // namespace Gecko

View File

@ -110,6 +110,12 @@ void LoadPatchSection(const std::string& section, std::vector<Patch>& patches, I
}
ReadEnabledAndDisabled(*ini, section, &patches);
if (ini == &globalIni)
{
for (Patch& patch : patches)
patch.default_enabled = patch.enabled;
}
}
}

View File

@ -34,6 +34,7 @@ struct Patch
std::string name;
std::vector<PatchEntry> entries;
bool enabled = false;
bool default_enabled = false;
bool user_defined = false; // False if this code is shipped with Dolphin.
};

View File

@ -129,21 +129,24 @@ void PatchesWidget::SavePatches()
{
std::vector<std::string> lines;
std::vector<std::string> lines_enabled;
std::vector<std::string> lines_disabled;
for (const auto& patch : m_patches)
{
if (patch.enabled)
lines_enabled.push_back("$" + patch.name);
lines_enabled.emplace_back('$' + patch.name);
else if (patch.default_enabled)
lines_disabled.emplace_back('$' + patch.name);
if (!patch.user_defined)
continue;
lines.push_back("$" + patch.name);
lines.emplace_back('$' + patch.name);
for (const auto& entry : patch.entries)
{
lines.push_back(StringFromFormat("0x%08X:%s:0x%08X", entry.address,
PatchEngine::PatchTypeAsString(entry.type), entry.value));
lines.emplace_back(StringFromFormat("0x%08X:%s:0x%08X", entry.address,
PatchEngine::PatchTypeAsString(entry.type), entry.value));
}
}
@ -151,6 +154,7 @@ void PatchesWidget::SavePatches()
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
game_ini_local.SetLines("OnFrame_Enabled", lines_enabled);
game_ini_local.SetLines("OnFrame_Disabled", lines_disabled);
game_ini_local.SetLines("OnFrame", lines);
game_ini_local.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");