From ce74423381a1b0727601100ad2c9b5e0752eadf6 Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Wed, 31 May 2017 11:58:24 +0200 Subject: [PATCH] Simplify some cwc detection code, respect _C2 as activation. --- Core/CwCheat.cpp | 15 ++++++--------- UI/CwCheatScreen.cpp | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index e515c44ee..677a1b53c 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -172,8 +172,12 @@ void CWCheatEngine::CreateCodeList() { //Creates code list to be used in functio if (initialCodesList[i].substr(0,2) == "//") { continue; //Line indicates comment, also not needed for cheats. } - if (initialCodesList[i].substr(0,3) == "_C1") { - cheatEnabled = true; + if (initialCodesList[i].substr(0,2) == "_C") { + if (initialCodesList[i].substr(2, 1) == "0") { + cheatEnabled = false; + } else { + cheatEnabled = true; + } codename = initialCodesList[i]; codename.erase (codename.begin(), codename.begin()+4); codeNameList.push_back(codename); //Import names for GUI, will be implemented later. @@ -192,13 +196,6 @@ void CWCheatEngine::CreateCodeList() { //Creates code list to be used in functio } continue; } - if (initialCodesList[i].substr(0,3) == "_C0") { - cheatEnabled = false; - codename = initialCodesList[i]; - codename.erase (codename.begin(), codename.begin()+4); - codeNameList.push_back(codename); //Import names for GUI, will be implemented later. - continue; - } } parts = makeCodeParts(codelist); } diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index 8eebd778a..a86c45d38 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -65,13 +65,13 @@ void CwCheatScreen::CreateCodeList() { bEnableCheat.clear(); formattedList_.clear(); for (size_t i = 0; i < cheatList.size(); i++) { - if (cheatList[i].substr(0, 3) == "_C1") { + if (cheatList[i].substr(0, 2) == "_C") { formattedList_.push_back(cheatList[i].substr(4)); - bEnableCheat.push_back(true); - } - if (cheatList[i].substr(0, 3) == "_C0") { - formattedList_.push_back(cheatList[i].substr(4)); - bEnableCheat.push_back(false); + if (cheatList[i].substr(2, 1) == "0") { + bEnableCheat.push_back(false); + } else { + bEnableCheat.push_back(true); + } } } delete cheatEngine2; @@ -136,11 +136,12 @@ UI::EventReturn CwCheatScreen::OnEnableAll(UI::EventParams ¶ms) { enableAll = !enableAll; File::OpenCPPFile(fs, activeCheatFile, std::ios::out); for (int j = 0; j < (int)cheatList.size(); j++) { - if (enableAll == 1 && cheatList[j].substr(0, 3) == "_C0"){ - cheatList[j].replace(0, 3, "_C1"); - } - else if (enableAll == 0 && cheatList[j].substr(0, 3) == "_C1") { - cheatList[j].replace(0, 3, "_C0"); + if (cheatList[j].substr(0, 2) == "_C") { + if (cheatList[j].substr(2, 1) == "0" && enableAll) { + cheatList[j].replace(2, 1, "1"); + } else if (cheatList[j].substr(2, 1) != "0" && !enableAll) { + cheatList[j].replace(2, 1, "0"); + } } } for (size_t y = 0; y < bEnableCheat.size(); y++) { @@ -206,7 +207,7 @@ UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams ¶ms) { if (finished == false){ getline(fs, line); } - if (line.substr(0, 3) == "_C0" || line.substr(0, 3) == "_C1") { + if (line.substr(0, 2) == "_C") { //Test if cheat already exists in cheatList for (size_t j = 0; j < formattedList_.size(); j++) { if (line.substr(4) == formattedList_[j]) {