summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2021-06-21 19:56:27 +0200
committerJosJuice <josjuice@gmail.com>2021-08-28 17:34:28 +0200
commitfb96ecb7da563d8b66ce4083db239da402e3aebc (patch)
tree3ad0ed52bc6b101c4cb48d9527e168c9fed9ce78 /Source
parent48161953662b9d77c4ece357f6f16814dd0c5f58 (diff)
Move patch saving code to PatchEngine
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/PatchEngine.cpp53
-rw-r--r--Source/Core/Core/PatchEngine.h5
-rw-r--r--Source/Core/DolphinQt/Config/PatchesWidget.cpp44
3 files changed, 54 insertions, 48 deletions
diff --git a/Source/Core/Core/PatchEngine.cpp b/Source/Core/Core/PatchEngine.cpp
index 0a815b37b1..afd20df61c 100644
--- a/Source/Core/Core/PatchEngine.cpp
+++ b/Source/Core/Core/PatchEngine.cpp
@@ -14,6 +14,8 @@
#include <string>
#include <vector>
+#include <fmt/format.h>
+
#include "Common/Assert.h"
#include "Common/IniFile.h"
#include "Common/StringUtil.h"
@@ -43,8 +45,8 @@ const char* PatchTypeAsString(PatchType type)
return s_patch_type_strings.at(static_cast<int>(type));
}
-void LoadPatchSection(const std::string& section, std::vector<Patch>& patches, IniFile& globalIni,
- IniFile& localIni)
+void LoadPatchSection(const std::string& section, std::vector<Patch>* patches,
+ const IniFile& globalIni, const IniFile& localIni)
{
const IniFile* inis[2] = {&globalIni, &localIni};
@@ -64,7 +66,7 @@ void LoadPatchSection(const std::string& section, std::vector<Patch>& patches, I
// Take care of the previous code
if (!currentPatch.name.empty())
{
- patches.push_back(currentPatch);
+ patches->push_back(currentPatch);
}
currentPatch.entries.clear();
@@ -110,19 +112,56 @@ void LoadPatchSection(const std::string& section, std::vector<Patch>& patches, I
if (!currentPatch.name.empty() && !currentPatch.entries.empty())
{
- patches.push_back(currentPatch);
+ patches->push_back(currentPatch);
}
- ReadEnabledAndDisabled(*ini, section, &patches);
+ ReadEnabledAndDisabled(*ini, section, patches);
if (ini == &globalIni)
{
- for (Patch& patch : patches)
+ for (Patch& patch : *patches)
patch.default_enabled = patch.enabled;
}
}
}
+void SavePatchSection(IniFile* local_ini, const std::vector<Patch>& patches)
+{
+ std::vector<std::string> lines;
+ std::vector<std::string> lines_enabled;
+ std::vector<std::string> lines_disabled;
+
+ for (const auto& patch : patches)
+ {
+ if (patch.enabled != patch.default_enabled)
+ (patch.enabled ? lines_enabled : lines_disabled).emplace_back('$' + patch.name);
+
+ if (!patch.user_defined)
+ continue;
+
+ lines.emplace_back('$' + patch.name);
+
+ for (const auto& entry : patch.entries)
+ {
+ if (!entry.conditional)
+ {
+ lines.emplace_back(fmt::format("0x{:08X}:{}:0x{:08X}", entry.address,
+ PatchEngine::PatchTypeAsString(entry.type), entry.value));
+ }
+ else
+ {
+ lines.emplace_back(fmt::format("0x{:08X}:{}:0x{:08X}:0x{:08X}", entry.address,
+ PatchEngine::PatchTypeAsString(entry.type), entry.value,
+ entry.comparand));
+ }
+ }
+ }
+
+ local_ini->SetLines("OnFrame_Enabled", lines_enabled);
+ local_ini->SetLines("OnFrame_Disabled", lines_disabled);
+ local_ini->SetLines("OnFrame", lines);
+}
+
static void LoadSpeedhacks(const std::string& section, IniFile& ini)
{
std::vector<std::string> keys;
@@ -161,7 +200,7 @@ void LoadPatches()
IniFile globalIni = SConfig::GetInstance().LoadDefaultGameIni();
IniFile localIni = SConfig::GetInstance().LoadLocalGameIni();
- LoadPatchSection("OnFrame", s_on_frame, globalIni, localIni);
+ LoadPatchSection("OnFrame", &s_on_frame, globalIni, localIni);
// Check if I'm syncing Codes
if (Config::Get(Config::SESSION_CODE_SYNC_OVERRIDE))
diff --git a/Source/Core/Core/PatchEngine.h b/Source/Core/Core/PatchEngine.h
index 2c6c60d21d..f3c4d3d6ac 100644
--- a/Source/Core/Core/PatchEngine.h
+++ b/Source/Core/Core/PatchEngine.h
@@ -42,8 +42,9 @@ struct Patch
const char* PatchTypeAsString(PatchType type);
int GetSpeedhackCycles(const u32 addr);
-void LoadPatchSection(const std::string& section, std::vector<Patch>& patches, IniFile& globalIni,
- IniFile& localIni);
+void LoadPatchSection(const std::string& section, std::vector<Patch>* patches,
+ const IniFile& globalIni, const IniFile& localIni);
+void SavePatchSection(IniFile* local_ini, const std::vector<Patch>& patches);
void LoadPatches();
bool ApplyFramePatches();
void Shutdown();
diff --git a/Source/Core/DolphinQt/Config/PatchesWidget.cpp b/Source/Core/DolphinQt/Config/PatchesWidget.cpp
index fd16714d94..2c08d932c0 100644
--- a/Source/Core/DolphinQt/Config/PatchesWidget.cpp
+++ b/Source/Core/DolphinQt/Config/PatchesWidget.cpp
@@ -7,8 +7,6 @@
#include <QListWidget>
#include <QPushButton>
-#include <fmt/format.h>
-
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Common/StringUtil.h"
@@ -28,7 +26,7 @@ PatchesWidget::PatchesWidget(const UICommon::GameFile& game)
IniFile game_ini_default = SConfig::GetInstance().LoadDefaultGameIni(m_game_id, m_game_revision);
- PatchEngine::LoadPatchSection("OnFrame", m_patches, game_ini_default, game_ini_local);
+ PatchEngine::LoadPatchSection("OnFrame", &m_patches, game_ini_default, game_ini_local);
CreateWidgets();
ConnectWidgets();
@@ -128,44 +126,12 @@ void PatchesWidget::OnRemove()
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 != patch.default_enabled)
- (patch.enabled ? lines_enabled : lines_disabled).emplace_back('$' + patch.name);
-
- if (!patch.user_defined)
- continue;
-
- lines.emplace_back('$' + patch.name);
-
- for (const auto& entry : patch.entries)
- {
- if (!entry.conditional)
- {
- lines.emplace_back(fmt::format("0x{:08X}:{}:0x{:08X}", entry.address,
- PatchEngine::PatchTypeAsString(entry.type), entry.value));
- }
- else
- {
- lines.emplace_back(fmt::format("0x{:08X}:{}:0x{:08X}:0x{:08X}", entry.address,
- PatchEngine::PatchTypeAsString(entry.type), entry.value,
- entry.comparand));
- }
- }
- }
+ const std::string ini_path = File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini";
IniFile game_ini_local;
- 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");
+ game_ini_local.Load(ini_path);
+ PatchEngine::SavePatchSection(&game_ini_local, m_patches);
+ game_ini_local.Save(ini_path);
}
void PatchesWidget::Update()