Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CWC improvements/fixes #8818

Merged
merged 4 commits into from
Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions Core/CwCheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,8 @@ 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"));
}

if (gameTitle != "") { //this only generates ini files on boot, let's leave homebrew ini file for UI
cheatEngine->CreateCheatFile();
}

cheatEngine = new CWCheatEngine();
Expand Down Expand Up @@ -153,6 +141,24 @@ static inline std::vector<std::string> makeCodeParts(const std::vector<std::stri
return finalList;
}

void CWCheatEngine::CreateCheatFile() {
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\n", 1, 4, f);
fclose(f);
}
if (!File::Exists(activeCheatFile)) {
I18NCategory *err = GetI18NCategory("Error");
host->NotifyUserMessage(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;
Expand Down Expand Up @@ -263,7 +269,10 @@ inline void trim2(std::string& str) {
else str.erase(str.begin(), str.end());
}

std::vector<std::string> CWCheatEngine::GetCodesList() { //Reads the entire cheat list from the appropriate .ini.
std::vector<std::string> CWCheatEngine::GetCodesList(std::string file) { //Reads the entire cheat list from the appropriate .ini.
if (file.empty()) {
file = activeCheatFile;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I suppose this isn't doing anything since activeCheatFile is being set otherwise.

-[Unknown]

}
std::string line;
std::vector<std::string> codesList; // Read from INI here
#ifdef _WIN32
Expand Down Expand Up @@ -595,6 +604,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 +724,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
3 changes: 2 additions & 1 deletion Core/CwCheat.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ bool CheatsInEffect();
class CWCheatEngine {
public:
CWCheatEngine();
std::vector<std::string> GetCodesList();
std::vector<std::string> GetCodesList(std::string file = "");
void CreateCodeList();
void CreateCheatFile();
void Exit();
void Run();
std::vector<int> GetNextCode();
Expand Down
32 changes: 31 additions & 1 deletion UI/CwCheatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,36 @@ static bool enableAll = false;
static std::vector<std::string> cheatList;
static CWCheatEngine *cheatEngine2;
static std::deque<bool> 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");
}
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();
cheatList = cheatEngine2->GetCodesList();
cheatEngine2->CreateCheatFile();
cheatList = cheatEngine2->GetCodesList(activeCheatFile);

bEnableCheat.clear();
formattedList_.clear();
for (size_t i = 0; i < cheatList.size(); i++) {
Expand Down Expand Up @@ -201,6 +227,10 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams &params) {
}

UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams &params) {
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<std::string> title;
bool finished = false, skip = false;
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