diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index f2a7a39348..e479d170d1 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -10,6 +10,7 @@ const static std::string CHEATS_DIR = "cheats"; static int CheatEvent = -1; std::string gameTitle; +std::string activeCheatFile; static CWCheatEngine *cheatEngine; void hleCheat(u64 userdata, int cyclesLate); void trim2(std::string& str); @@ -73,7 +74,6 @@ void CWCheatEngine::CreateCodeList() { //Creates code list to be used in functio initialCodesList = GetCodesList(); std::string currentcode, codename; std::vector codelist; - for (size_t i = 0; i < initialCodesList.size(); i ++) { if (initialCodesList[i].substr(0,2) == "_S") { continue; //Line indicates Disc ID, not needed for cheats diff --git a/Core/CwCheat.h b/Core/CwCheat.h index 8a3a283385..1d26944399 100644 --- a/Core/CwCheat.h +++ b/Core/CwCheat.h @@ -11,7 +11,6 @@ void __CheatInit(); void __CheatShutdown(); -static std::string activeCheatFile; std::vector makeCodeParts(std::vector CodesList); class CWCheatEngine { @@ -24,9 +23,7 @@ public: void Exit(); void Run(); std::vector GetNextCode(); - static std::string gActiveCheatFile; - void ActiveFileCopy(); private: void SkipCodes(int count); diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index bc68b77c3f..331f12bfc3 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -16,29 +16,13 @@ // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #include "android/app-android.h" -#include "base/logging.h" -#include "gfx_es2/glsl_program.h" -#include "gfx_es2/gl_state.h" -#include "gfx_es2/fbo.h" #include "input/input_state.h" #include "ui/ui.h" #include "i18n/i18n.h" -#include "Common/KeyMap.h" - -#include "Core/Config.h" -#include "Core/CoreTiming.h" -#include "Core/CoreParameter.h" #include "Core/Core.h" -#include "Core/Host.h" -#include "Core/System.h" -#include "GPU/GPUState.h" -#include "GPU/GPUInterface.h" -#include "Core/HLE/sceCtrl.h" -#include "Core/HLE/sceDisplay.h" -#include "Core/Debugger/SymbolMap.h" #include "UI/OnScreenDisplay.h" #include "UI/ui_atlas.h" @@ -52,26 +36,27 @@ #include "UI/CwCheatScreen.h" #include "UI/view.h" - +static std::vector cheatList; extern void DrawBackground(float alpha); static CWCheatEngine *cheatEngine2; std::vector CwCheatScreen::CreateCodeList() { cheatEngine2 = new CWCheatEngine(); cheatList = cheatEngine2->GetCodesList(); + int j = 0; for (size_t i = 0; i < cheatList.size(); i++) { if (cheatList[i].substr(0, 3) == "_C1") { - formattedList.push_back(cheatList[i].substr(3)); - enableCheat[i] = true; + formattedList.push_back(cheatList[i].substr(4)); + enableCheat[j++] = true; locations.push_back(i); } if (cheatList[i].substr(0, 3) == "_C0") { - formattedList.push_back(cheatList[i].substr(3)); - enableCheat[i] = false; + formattedList.push_back(cheatList[i].substr(4)); + enableCheat[j++] = false; } } - + delete cheatEngine2; return formattedList; } void CwCheatScreen::CreateViews() { @@ -82,7 +67,7 @@ void CwCheatScreen::CreateViews() { root_ = new LinearLayout(ORIENT_HORIZONTAL); LinearLayout *leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(200, FILL_PARENT)); - leftColumn->Add(new Choice(k->T("Back")))->OnClick.Handle(this, &UIScreen::OnBack); + leftColumn->Add(new Choice(k->T("Back")))->OnClick.Handle(this, &CwCheatScreen::OnBack); ScrollView *rightScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)); @@ -99,32 +84,51 @@ void CwCheatScreen::CreateViews() { } } +UI::EventReturn CwCheatScreen::OnBack(UI::EventParams ¶ms) +{ + screenManager()->finishDialog(this, DR_OK); + g_Config.bReloadCheats = true; + return UI::EVENT_DONE; +} UI::EventReturn CwCheatScreen::OnCheckBox(UI::EventParams ¶ms) { + return UI::EVENT_DONE; } void CwCheatScreen::processFileOn(std::string activatedCheat) { - //visible test - //bool check; - //LinearLayout *rightColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)); - //rightColumn->Add(new CheatCheckBox(&check, "name")); - - is.open(activeCheatFile.c_str()); + for (int i = 0; i < cheatList.size(); i++) { if (cheatList[i].substr(4) == activatedCheat) { cheatList[i] = "_C1 " + activatedCheat; } } - is.close(); + os.open(activeCheatFile.c_str()); for (int j = 0; j < cheatList.size(); j++) { os << cheatList[j]; + if (j < cheatList.size() - 1) { + os << "\n"; + } } os.close(); - + } -void CwCheatScreen::processFileOff(std::string deactivatedString) { - is.open(activeCheatFile.c_str()); +void CwCheatScreen::processFileOff(std::string deactivatedCheat) { + + for (int i = 0; i < cheatList.size(); i++) { + if (cheatList[i].substr(4) == deactivatedCheat) { + cheatList[i] = "_C0 " + deactivatedCheat; + } + } + os.open(activeCheatFile.c_str()); + for (int j = 0; j < cheatList.size(); j++) { + os << cheatList[j]; + if (j < cheatList.size() - 1) { + os << "\n"; + } + } + os.close(); + } void CheatCheckBox::Draw(UIContext &dc) { diff --git a/UI/CwCheatScreen.h b/UI/CwCheatScreen.h index 6492e59a2d..fafa97574e 100644 --- a/UI/CwCheatScreen.h +++ b/UI/CwCheatScreen.h @@ -21,7 +21,9 @@ #include "ui/ui_context.h" #include "../Core/CwCheat.h" #include "UI/MiscScreens.h" +#include "UI/GameSettingsScreen.h" using namespace UI; +extern std::string activeCheatFile; class CwCheatScreen : public UIDialogScreenWithBackground { public: @@ -33,13 +35,15 @@ public: void processFileOff(std::string deactivatedCheat); const char * name; std::string activatedCheat, deactivatedCheat; + UI::EventReturn OnBack(UI::EventParams ¶ms); protected: virtual void CreateViews(); private: UI::EventReturn OnCheckBox(UI::EventParams ¶ms); + bool enableCheat [64]; - std::vector cheatList, formattedList; + std::vector formattedList; std::vector locations; }; @@ -57,12 +61,14 @@ public: if (toggle_) { *toggle_ = !(*toggle_); } - if (*toggle_ == true) + bool temp; + temp = *toggle_; + if (temp == 1) { activatedCheat = text_; processFileOn(activatedCheat); } - if (*toggle_ == false) + if (temp == 0) { deactivatedCheat = text_; processFileOff(deactivatedCheat);