From 778c518a376d2f59b66a1f669295c4ed4daec545 Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Mon, 20 Jun 2016 00:18:35 +0200 Subject: [PATCH 1/4] Cheat menu access from gameScreen + minor bugfix + Invalidate JIT for 0xE/0xD checks And big thanks to [Unknown] for help:3 --- Core/CwCheat.cpp | 41 +++++++++++++++++++++++++---------------- Core/CwCheat.h | 3 ++- UI/CwCheatScreen.cpp | 15 ++++++++++++++- UI/CwCheatScreen.h | 1 + UI/GameScreen.cpp | 10 ++++++++++ UI/GameScreen.h | 1 + UI/PauseScreen.cpp | 2 +- 7 files changed, 54 insertions(+), 19 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index d3a1474c6ce2..b524eda8a6a1 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -39,21 +39,7 @@ static void __CheatStart() { gameTitle = g_paramSFO.GetValueString("DISC_ID"); - activeCheatFile = GetSysDirectory(DIRECTORY_CHEATS) + gameTitle + ".ini"; - File::CreateFullPath(GetSysDirectory(DIRECTORY_CHEATS)); - - if (!File::Exists(activeCheatFile)) { - FILE *f = File::OpenCFile(activeCheatFile, "wb"); - if (f) { - fwrite("\xEF\xBB\xBF", 1, 3, f); - fclose(f); - } - if (!File::Exists(activeCheatFile)) { - I18NCategory *err = GetI18NCategory("Error"); - host->NotifyUserMessage(err->T("Unable to create cheat file, disk may be full")); - } - - } + cheatEngine->CreateCheatFile(); cheatEngine = new CWCheatEngine(); cheatEngine->CreateCodeList(); @@ -153,6 +139,24 @@ static inline std::vector makeCodeParts(const std::vectorNotifyUserMessage(err->T("Unable to create cheat file, disk may be full")); + } + + } +} + void CWCheatEngine::CreateCodeList() { //Creates code list to be used in function GetNextCode initialCodesList = GetCodesList(); std::string currentcode, codename; @@ -263,7 +267,10 @@ inline void trim2(std::string& str) { else str.erase(str.begin(), str.end()); } -std::vector CWCheatEngine::GetCodesList() { //Reads the entire cheat list from the appropriate .ini. +std::vector CWCheatEngine::GetCodesList(std::string file) { //Reads the entire cheat list from the appropriate .ini. + if (file.empty()) { + file = activeCheatFile; + } std::string line; std::vector codesList; // Read from INI here #ifdef _WIN32 @@ -595,6 +602,7 @@ void CWCheatEngine::Run() { bool is8Bit = (arg >> 28) == 0x2; addr = GetAddress(comm & 0x0FFFFFFF); if (Memory::IsValidAddress(addr)) { + InvalidateICache(addr, 4); int memoryValue = is8Bit ? Memory::Read_U8(addr) : Memory::Read_U16(addr); int testValue = arg & (is8Bit ? 0xFF : 0xFFFF); bool executeNextLines = false; @@ -714,6 +722,7 @@ void CWCheatEngine::Run() { bool is8Bit = (comm >> 24) == 0xE1; addr = GetAddress(arg & 0x0FFFFFFF); if (Memory::IsValidAddress(addr)) { + InvalidateICache(addr, 4); int memoryValue = is8Bit ? Memory::Read_U8(addr) : Memory::Read_U16(addr); int testValue = comm & (is8Bit ? 0xFF : 0xFFFF); bool executeNextLines = false; diff --git a/Core/CwCheat.h b/Core/CwCheat.h index baf118b0b13b..29463604a617 100644 --- a/Core/CwCheat.h +++ b/Core/CwCheat.h @@ -21,8 +21,9 @@ bool CheatsInEffect(); class CWCheatEngine { public: CWCheatEngine(); - std::vector GetCodesList(); + std::vector GetCodesList(std::string file = ""); void CreateCodeList(); + void CreateCheatFile(); void Exit(); void Run(); std::vector GetNextCode(); diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index 7f6481709c75..d26195df7f1e 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -40,10 +40,23 @@ static bool enableAll = false; static std::vector cheatList; static CWCheatEngine *cheatEngine2; static std::deque bEnableCheat; +static std::string gamePath_; + + +CwCheatScreen::CwCheatScreen(std::string gamePath) + : UIDialogScreenWithBackground() { + gamePath_ = gamePath; +} void CwCheatScreen::CreateCodeList() { + GameInfo *info = g_gameInfoCache->GetInfo(NULL, gamePath_, 0); + if (info && info->paramSFOLoaded) { + gameTitle = info->paramSFO.GetValueString("DISC_ID"); + } cheatEngine2 = new CWCheatEngine(); - cheatList = cheatEngine2->GetCodesList(); + cheatEngine2->CreateCheatFile(); + cheatList = cheatEngine2->GetCodesList(activeCheatFile); + bEnableCheat.clear(); formattedList_.clear(); for (size_t i = 0; i < cheatList.size(); i++) { diff --git a/UI/CwCheatScreen.h b/UI/CwCheatScreen.h index dfc8a4d5797e..af4379ad28f3 100644 --- a/UI/CwCheatScreen.h +++ b/UI/CwCheatScreen.h @@ -26,6 +26,7 @@ extern std::string gameTitle; class CwCheatScreen : public UIDialogScreenWithBackground { public: + CwCheatScreen(std::string gamePath); CwCheatScreen() {} void CreateCodeList(); void processFileOn(std::string activatedCheat); diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index b8b3b9fb53bd..2aa40c8dc80a 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -25,6 +25,7 @@ #include "ui/ui_context.h" #include "ui/view.h" #include "ui/viewgroup.h" +#include "UI/CwCheatScreen.h" #include "UI/EmuScreen.h" #include "UI/GameScreen.h" #include "UI/GameSettingsScreen.h" @@ -49,6 +50,7 @@ void GameScreen::CreateViews() { I18NCategory *di = GetI18NCategory("Dialog"); I18NCategory *ga = GetI18NCategory("Game"); + I18NCategory *pa = GetI18NCategory("Pause"); // Information in the top left. // Back button to the bottom left. @@ -113,6 +115,9 @@ void GameScreen::CreateViews() { #ifdef _WIN32 rightColumnItems->Add(new Choice(ga->T("Show In Folder")))->OnClick.Handle(this, &GameScreen::OnShowInFolder); #endif + if (g_Config.bEnableCheats) { + rightColumnItems->Add(new Choice(pa->T("Cheats")))->OnClick.Handle(this, &GameScreen::OnCwCheat); + } } UI::EventReturn GameScreen::OnCreateConfig(UI::EventParams &e) @@ -205,6 +210,11 @@ UI::EventReturn GameScreen::OnShowInFolder(UI::EventParams &e) { return UI::EVENT_DONE; } +UI::EventReturn GameScreen::OnCwCheat(UI::EventParams &e) { + screenManager()->push(new CwCheatScreen(gamePath_)); + return UI::EVENT_DONE; +} + UI::EventReturn GameScreen::OnSwitchBack(UI::EventParams &e) { screenManager()->finishDialog(this, DR_OK); return UI::EVENT_DONE; diff --git a/UI/GameScreen.h b/UI/GameScreen.h index af82cbed96c6..a97e8085699f 100644 --- a/UI/GameScreen.h +++ b/UI/GameScreen.h @@ -55,6 +55,7 @@ class GameScreen : public UIDialogScreenWithGameBackground { UI::EventReturn OnShowInFolder(UI::EventParams &e); UI::EventReturn OnCreateConfig(UI::EventParams &e); UI::EventReturn OnDeleteConfig(UI::EventParams &e); + UI::EventReturn OnCwCheat(UI::EventParams &e); // As we load metadata in the background, we need to be able to update these after the fact. UI::Thin3DTextureView *texvGameIcon_; diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index 2f1339089a25..d843e86302f4 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -405,7 +405,7 @@ UI::EventReturn GamePauseScreen::OnRewind(UI::EventParams &e) { } UI::EventReturn GamePauseScreen::OnCwCheat(UI::EventParams &e) { - screenManager()->push(new CwCheatScreen()); + screenManager()->push(new CwCheatScreen(gamePath_)); return UI::EVENT_DONE; } From 6c14b82005433313b5c3a0b5ec5a49b50f0a9d45 Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Mon, 20 Jun 2016 11:32:31 +0200 Subject: [PATCH 2/4] Fix #8448 properly, in case we fail to generate ID. Limit homebrew ini file generation to UI. --- Core/CwCheat.cpp | 4 +++- UI/CwCheatScreen.cpp | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index b524eda8a6a1..727fd7d5024a 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -39,7 +39,9 @@ static void __CheatStart() { gameTitle = g_paramSFO.GetValueString("DISC_ID"); - cheatEngine->CreateCheatFile(); + if (gameTitle != "") { //this only generates ini files on boot, let's leave homebrew ini file for UI + cheatEngine->CreateCheatFile(); + } cheatEngine = new CWCheatEngine(); cheatEngine->CreateCodeList(); diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index d26195df7f1e..f738de52d43c 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -214,6 +214,10 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams ¶ms) { } UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams ¶ms) { + if (gameTitle.length() != 9) { + WARN_LOG(COMMON, "CWCHEAT: Incorrect ID(%s) - can't import cheats.", gameTitle.c_str()); + return UI::EVENT_DONE; + } std::string line; std::vector title; bool finished = false, skip = false; From 27a616c765ca99fd9a3503434510da7ceb4207de Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Tue, 21 Jun 2016 00:15:29 +0200 Subject: [PATCH 3/4] Name homebrew games ini files differently --- UI/CwCheatScreen.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index f738de52d43c..bc79389a0cba 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -53,6 +53,19 @@ void CwCheatScreen::CreateCodeList() { if (info && info->paramSFOLoaded) { gameTitle = info->paramSFO.GetValueString("DISC_ID"); } + std::size_t lslash = gamePath_.find_last_of("/"); + std::size_t lastdot = gamePath_.find_last_of("."); + std::string extension = gamePath_.substr(lastdot + 1); + for (int i = 0; i < extension.size(); i++) { + extension[i] = tolower(extension[i]); + } + if (extension != "iso" && extension != "cso" && extension != "pbp" || gameTitle == "") { + if (extension == "elf") { + gameTitle = "ELF000000"; + } else { + gameTitle = gamePath_.substr(lslash + 1); + } + } cheatEngine2 = new CWCheatEngine(); cheatEngine2->CreateCheatFile(); cheatList = cheatEngine2->GetCodesList(activeCheatFile); From 101df1da2b734657ba74c6306f1493bacef11a26 Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Tue, 21 Jun 2016 06:29:26 +0200 Subject: [PATCH 4/4] Ooops;3, remove leftover --- Core/CwCheat.cpp | 5 +---- Core/CwCheat.h | 2 +- UI/CwCheatScreen.cpp | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 727fd7d5024a..6ef40c749894 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -269,10 +269,7 @@ inline void trim2(std::string& str) { else str.erase(str.begin(), str.end()); } -std::vector CWCheatEngine::GetCodesList(std::string file) { //Reads the entire cheat list from the appropriate .ini. - if (file.empty()) { - file = activeCheatFile; - } +std::vector CWCheatEngine::GetCodesList() { //Reads the entire cheat list from the appropriate .ini. std::string line; std::vector codesList; // Read from INI here #ifdef _WIN32 diff --git a/Core/CwCheat.h b/Core/CwCheat.h index 29463604a617..be8b27be9f02 100644 --- a/Core/CwCheat.h +++ b/Core/CwCheat.h @@ -21,7 +21,7 @@ bool CheatsInEffect(); class CWCheatEngine { public: CWCheatEngine(); - std::vector GetCodesList(std::string file = ""); + std::vector GetCodesList(); void CreateCodeList(); void CreateCheatFile(); void Exit(); diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index bc79389a0cba..23c55effead2 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -68,7 +68,7 @@ void CwCheatScreen::CreateCodeList() { } cheatEngine2 = new CWCheatEngine(); cheatEngine2->CreateCheatFile(); - cheatList = cheatEngine2->GetCodesList(activeCheatFile); + cheatList = cheatEngine2->GetCodesList(); bEnableCheat.clear(); formattedList_.clear();