From d28663179836c96c477c76c9dd977a91a75a055e Mon Sep 17 00:00:00 2001 From: marecl Date: Mon, 28 Jul 2025 15:52:23 +0200 Subject: [PATCH] Patch is enabled only when game version matches patch version (#3336) Removed redundancies from CheatsPatches::onSaveButtonClicked() --- src/qt_gui/cheats_patches.cpp | 66 ++++++++++++----------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/src/qt_gui/cheats_patches.cpp b/src/qt_gui/cheats_patches.cpp index 67f616f87..4132bddca 100644 --- a/src/qt_gui/cheats_patches.cpp +++ b/src/qt_gui/cheats_patches.cpp @@ -389,61 +389,41 @@ void CheatsPatches::onSaveButtonClicked() { xmlWriter.writeStartElement(xmlReader.name().toString()); QString name = xmlReader.attributes().value("Name").toString(); + QString version = xmlReader.attributes().value("AppVer").toString(); + + bool versionMatch = version == m_gameVersion; bool isEnabled = false; - bool hasIsEnabled = false; bool foundPatchInfo = false; // Check and update the isEnabled attribute for (const QXmlStreamAttribute& attr : xmlReader.attributes()) { - if (attr.name() == QStringLiteral("isEnabled")) { - hasIsEnabled = true; - auto it = m_patchInfos.find(name); - 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()); - } + if (attr.name() == QStringLiteral("isEnabled")) + continue; + xmlWriter.writeAttribute(attr.name().toString(), attr.value().toString()); } - if (!hasIsEnabled) { - auto it = m_patchInfos.find(name); - if (it != m_patchInfos.end()) { - QCheckBox* checkBox = findCheckBoxByName(it->name); + auto it = m_patchInfos.find(name); + 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) { + versionMatch = true; 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"); + } + if (foundPatchInfo) { + xmlWriter.writeAttribute("isEnabled", + (isEnabled && versionMatch) ? "true" : "false"); } } else { xmlWriter.writeStartElement(xmlReader.name().toString());