From 908f202d75eca1e0555b91a046e6e22b5ef24ee3 Mon Sep 17 00:00:00 2001 From: CrazyBloo Date: Tue, 27 Aug 2024 06:07:51 -0400 Subject: [PATCH] Fix an issue with mask patches not being saved --- src/common/memory_patcher.cpp | 11 +++++------ src/qt_gui/cheats_patches.cpp | 29 +++++++++++++++++++++++++++-- src/qt_gui/cheats_patches.h | 1 - 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/common/memory_patcher.cpp b/src/common/memory_patcher.cpp index fd602e48..81f5d0b6 100644 --- a/src/common/memory_patcher.cpp +++ b/src/common/memory_patcher.cpp @@ -6,13 +6,13 @@ #include "common/logging/log.h" #include "common/path_util.h" #ifdef ENABLE_QT_GUI +#include #include #include #include -#include #include #include -#include +#include #endif #include "memory_patcher.h" @@ -93,9 +93,8 @@ QString convertValueToHex(const QString& type, const QString& valueStr) { void OnGameLoaded() { - // We use the QT headers for the xml and json parsing, this define is only true on QT builds - #ifdef ENABLE_QT_GUI - printf("we good?\n"); +// We use the QT headers for the xml and json parsing, this define is only true on QT builds +#ifdef ENABLE_QT_GUI QString patchDir = QString::fromStdString(Common::FS::GetUserPath(Common::FS::PathType::PatchesDir).string()); @@ -236,7 +235,7 @@ void OnGameLoaded() { } else { LOG_INFO(Loader, "Patches loaded successfully"); } - #endif +#endif ApplyPendingPatches(); } diff --git a/src/qt_gui/cheats_patches.cpp b/src/qt_gui/cheats_patches.cpp index c96672e6..ee97af43 100644 --- a/src/qt_gui/cheats_patches.cpp +++ b/src/qt_gui/cheats_patches.cpp @@ -300,6 +300,7 @@ void CheatsPatches::onSaveButtonClicked() { QString name = xmlReader.attributes().value("Name").toString(); bool isEnabled = false; bool hasIsEnabled = false; + bool foundPatchInfo = false; // Check and update the isEnabled attribute for (const QXmlStreamAttribute& attr : xmlReader.attributes()) { @@ -309,10 +310,24 @@ void CheatsPatches::onSaveButtonClicked() { if (it != m_patchInfos.end()) { QCheckBox* checkBox = findCheckBoxByName(it->name); if (checkBox) { + foundPatchInfo = true; isEnabled = checkBox->isChecked(); xmlWriter.writeAttribute("isEnabled", isEnabled ? "true" : "false"); } } + if (!foundPatchInfo) { + auto maskIt = m_patchInfos.find(name + " (any version)"); + if (maskIt != m_patchInfos.end()) { + QCheckBox* checkBox = findCheckBoxByName(maskIt->name); + if (checkBox) { + foundPatchInfo = true; + isEnabled = checkBox->isChecked(); + xmlWriter.writeAttribute("isEnabled", + isEnabled ? "true" : "false"); + } + } + } + } else { xmlWriter.writeAttribute(attr.name().toString(), attr.value().toString()); } @@ -323,9 +338,20 @@ void CheatsPatches::onSaveButtonClicked() { if (it != m_patchInfos.end()) { QCheckBox* checkBox = findCheckBoxByName(it->name); if (checkBox) { + foundPatchInfo = true; isEnabled = checkBox->isChecked(); } } + if (!foundPatchInfo) { + auto maskIt = m_patchInfos.find(name + " (any version)"); + if (maskIt != m_patchInfos.end()) { + QCheckBox* checkBox = findCheckBoxByName(maskIt->name); + if (checkBox) { + foundPatchInfo = true; + isEnabled = checkBox->isChecked(); + } + } + } xmlWriter.writeAttribute("isEnabled", isEnabled ? "true" : "false"); } } else { @@ -369,7 +395,7 @@ QCheckBox* CheatsPatches::findCheckBoxByName(const QString& name) { QWidget* widget = item->widget(); QCheckBox* checkBox = qobject_cast(widget); if (checkBox) { - if (checkBox->text() == name) { + if (checkBox->text().toStdString().find(name.toStdString()) != std::string::npos) { return checkBox; } } @@ -1089,7 +1115,6 @@ void CheatsPatches::applyPatch(const QString& patchName, bool enabled) { } } - bool CheatsPatches::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverLeave) { QCheckBox* checkBox = qobject_cast(obj); diff --git a/src/qt_gui/cheats_patches.h b/src/qt_gui/cheats_patches.h index d4e473c1..0be0bed4 100644 --- a/src/qt_gui/cheats_patches.h +++ b/src/qt_gui/cheats_patches.h @@ -58,7 +58,6 @@ private: void applyCheat(const QString& modName, bool enabled); void applyPatch(const QString& patchName, bool enabled); - // Event Filtering bool eventFilter(QObject* obj, QEvent* event);