Skip to content

Commit

Permalink
Cheat menu access from gameScreen + minor bugfix +
Browse files Browse the repository at this point in the history
Invalidate JIT for 0xE/0xD checks
  • Loading branch information
LunaMoo committed Jun 20, 2016
1 parent 0519b3e commit 19c347e
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Core/CwCheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void __CheatStart() {
if (!File::Exists(activeCheatFile)) {
FILE *f = File::OpenCFile(activeCheatFile, "wb");
if (f) {
fwrite("\xEF\xBB\xBF", 1, 3, f);
fwrite("\xEF\xBB\xBF\n", 1, 4, f);
fclose(f);
}
if (!File::Exists(activeCheatFile)) {
Expand Down Expand Up @@ -595,6 +595,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;
Expand Down Expand Up @@ -714,6 +715,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;
Expand Down
67 changes: 64 additions & 3 deletions UI/CwCheatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Core/Core.h"
#include "Core/Config.h"
#include "Core/CwCheat.h"
#include "Core/Host.h"
#include "Core/MIPS/JitCommon/JitCommon.h"

#include "UI/OnScreenDisplay.h"
Expand All @@ -40,10 +41,71 @@ static bool enableAll = false;
static std::vector<std::string> cheatList;
static CWCheatEngine *cheatEngine2;
static std::deque<bool> bEnableCheat;
std::string gamePath_;


CwCheatScreen::CwCheatScreen(std::string gamePath)
: UIDialogScreenWithBackground() {
gamePath_ = gamePath;
}

inline void trim2(std::string& str) {
size_t pos = str.find_last_not_of(' ');
if (pos != std::string::npos) {
str.erase(pos + 1);
pos = str.find_first_not_of(' ');
if (pos != std::string::npos) str.erase(0, pos);
}
else str.erase(str.begin(), str.end());
}

void CwCheatScreen::CreateCodeList() {
cheatEngine2 = new CWCheatEngine();
cheatList = cheatEngine2->GetCodesList();
std::string line;
std::vector<std::string> codesList; // Read from INI here

GameInfo *info = g_gameInfoCache->GetInfo(NULL, gamePath_, 0);
std::string discID;
if (info && info->paramSFOLoaded) {

discID = info->paramSFO.GetValueString("DISC_ID");
}

activeCheatFile = GetSysDirectory(DIRECTORY_CHEATS) + discID + ".ini";
File::CreateFullPath(GetSysDirectory(DIRECTORY_CHEATS));

if (!File::Exists(activeCheatFile)) {
FILE *f = File::OpenCFile(activeCheatFile, "wb");
if (f) {
fwrite("\xEF\xBB\xBF\n", 1, 4, f);
fclose(f);
std::fstream fs;
File::OpenCPPFile(fs, activeCheatFile, std::ios::in);
}
if (!File::Exists(activeCheatFile)) {
I18NCategory *err = GetI18NCategory("Error");
host->NotifyUserMessage(err->T("Unable to create cheat file, disk may be full"));
}

}
#ifdef _WIN32
std::ifstream list(ConvertUTF8ToWString(activeCheatFile));
#else
std::ifstream list(activeCheatFile.c_str());
#endif
if (!list) {
cheatList = codesList;
}
for (int i = 0; !list.eof(); i++) {
getline(list, line, '\n');
if (line.length() > 3 && (line.substr(0, 1) == "_" || line.substr(0, 2) == "//")) {
codesList.push_back(line);
}
}
for (size_t i = 0; i < codesList.size(); i++) {
trim2(codesList[i]);
}
cheatList = codesList;

bEnableCheat.clear();
formattedList_.clear();
for (size_t i = 0; i < cheatList.size(); i++) {
Expand All @@ -56,7 +118,6 @@ void CwCheatScreen::CreateCodeList() {
bEnableCheat.push_back(false);
}
}
delete cheatEngine2;
}

void CwCheatScreen::CreateViews() {
Expand Down
1 change: 1 addition & 0 deletions UI/CwCheatScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions UI/GameScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions UI/GameScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
2 changes: 1 addition & 1 deletion UI/PauseScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 19c347e

Please sign in to comment.