diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 7939946081..f2a7a39348 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -8,12 +8,9 @@ #include "Core/Config.h" const static std::string CHEATS_DIR = "cheats"; - -static std::string activeCheatFile; static int CheatEvent = -1; std::string gameTitle; static CWCheatEngine *cheatEngine; - void hleCheat(u64 userdata, int cyclesLate); void trim2(std::string& str); @@ -23,7 +20,7 @@ void __CheatInit() { // Cheats aren't working on Android yet - need to figure out the directory structure #ifndef ANDROID gameTitle = g_paramSFO.GetValueString("DISC_ID"); - activeCheatFile = CHEATS_DIR + "/" + gameTitle +".ini"; + activeCheatFile = CHEATS_DIR + "/" + gameTitle + ".ini"; File::CreateFullPath(CHEATS_DIR); if (g_Config.bEnableCheats) { @@ -60,6 +57,7 @@ void hleCheat(u64 userdata, int cyclesLate) { g_Config.bReloadCheats = false; } if (g_Config.bEnableCheats) { + cheatEngine->Run(); } } diff --git a/Core/CwCheat.h b/Core/CwCheat.h index 69d40f0527..8a3a283385 100644 --- a/Core/CwCheat.h +++ b/Core/CwCheat.h @@ -11,7 +11,7 @@ void __CheatInit(); void __CheatShutdown(); - +static std::string activeCheatFile; std::vector makeCodeParts(std::vector CodesList); class CWCheatEngine { @@ -24,7 +24,9 @@ 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 26d208e711..bc68b77c3f 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -50,20 +50,20 @@ #include "UI/GameInfoCache.h" #include "UI/MiscScreens.h" #include "UI/CwCheatScreen.h" +#include "UI/view.h" extern void DrawBackground(float alpha); static CWCheatEngine *cheatEngine2; std::vector CwCheatScreen::CreateCodeList() { - std::vector cheatList, formattedList; cheatEngine2 = new CWCheatEngine(); cheatList = cheatEngine2->GetCodesList(); - 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; + locations.push_back(i); } if (cheatList[i].substr(0, 3) == "_C0") { formattedList.push_back(cheatList[i].substr(3)); @@ -94,10 +94,50 @@ void CwCheatScreen::CreateViews() { root_->Add(rightScroll); rightColumn->Add(new ItemHeader(k->T("Cheats"))); for (size_t i = 0; i < formattedList.size(); i++) { - const char * name = formattedList[i].c_str(); - rightColumn->Add(new CheckBox(&enableCheat[i], k->T(name)))->OnClick.Handle(this, &CwCheatScreen::OnCheckBox);; + name = formattedList[i].c_str(); + rightColumn->Add(new CheatCheckBox(&enableCheat[i], k->T(name)))->OnClick.Handle(this, &CwCheatScreen::OnCheckBox); } + } 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]; + } + os.close(); + +} +void CwCheatScreen::processFileOff(std::string deactivatedString) { + is.open(activeCheatFile.c_str()); + +} + +void CheatCheckBox::Draw(UIContext &dc) { + ClickableItem::Draw(dc); + int paddingX = 12; + int paddingY = 8; + + int image = *toggle_ ? dc.theme->checkOn : dc.theme->checkOff; + + Style style = dc.theme->itemStyle; + if (!IsEnabled()) + style = dc.theme->itemDisabledStyle; + + dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), style.fgColor, ALIGN_VCENTER); + dc.Draw()->DrawImage(image, bounds_.x2() - paddingX, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_RIGHT | ALIGN_VCENTER); } \ No newline at end of file diff --git a/UI/CwCheatScreen.h b/UI/CwCheatScreen.h index 625154180e..6492e59a2d 100644 --- a/UI/CwCheatScreen.h +++ b/UI/CwCheatScreen.h @@ -18,18 +18,60 @@ #include "base/functional.h" #include "ui/view.h" #include "ui/ui_screen.h" +#include "ui/ui_context.h" #include "../Core/CwCheat.h" #include "UI/MiscScreens.h" +using namespace UI; class CwCheatScreen : public UIDialogScreenWithBackground { public: CwCheatScreen() {} std::vector CreateCodeList(); + std::ifstream is; + std::ofstream os; + void processFileOn(std::string activatedCheat); + void processFileOff(std::string deactivatedCheat); + const char * name; + std::string activatedCheat, deactivatedCheat; protected: virtual void CreateViews(); private: UI::EventReturn OnCheckBox(UI::EventParams ¶ms); bool enableCheat [64]; - + std::vector cheatList, formattedList; + std::vector locations; + }; + +class CheatCheckBox : public ClickableItem, public CwCheatScreen { +public: + CheatCheckBox(bool *toggle, const std::string &text, const std::string &smallText = "", LayoutParams *layoutParams = 0) + : ClickableItem(layoutParams), toggle_(toggle), text_(text) { + OnClick.Handle(this, &CheatCheckBox::OnClicked); + } + + virtual void Draw(UIContext &dc); + + EventReturn OnClicked(EventParams &e) { + if (toggle_) { + *toggle_ = !(*toggle_); + } + if (*toggle_ == true) + { + activatedCheat = text_; + processFileOn(activatedCheat); + } + if (*toggle_ == false) + { + deactivatedCheat = text_; + processFileOff(deactivatedCheat); + } + return EVENT_DONE; + } +private: + bool *toggle_; + std::string text_; + std::string smallText_; + +}; \ No newline at end of file diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 05821d0883..611435adeb 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -686,7 +686,9 @@ void GamePauseScreen::CreateViews() { rightColumnItems->Add(new Choice(i->T("Continue")))->OnClick.Handle(this, &GamePauseScreen::OnContinue); rightColumnItems->Add(new Choice(i->T("Game Settings")))->OnClick.Handle(this, &GamePauseScreen::OnGameSettings); - rightColumnItems->Add(new Choice(i->T("Cheats")))->OnClick.Handle(this, &GamePauseScreen::OnCwCheat); + if (g_Config.bEnableCheats) { + rightColumnItems->Add(new Choice(i->T("Cheats")))->OnClick.Handle(this, &GamePauseScreen::OnCwCheat); + } rightColumnItems->Add(new Choice(i->T("Exit to menu")))->OnClick.Handle(this, &GamePauseScreen::OnExitToMenu); UI::EventParams e;