From 9c9769c380c2c41ba9386ec533d83849a37f7e30 Mon Sep 17 00:00:00 2001 From: cottonvibes Date: Mon, 17 May 2010 01:56:54 +0000 Subject: [PATCH] Since we don't have a proper cheating system in pcsx2 yet, we're going back to the pnach system for game cheats. This means you can put your cheats in "\cheats\*.pnach" and pcsx2 will read them from there. Notes: I have included some persona 4 cheats as an example in this commit... Also note that currently the "Enable Patches" menu item also pertains to cheats (as well as database file patches). I will add a separate "Enable Cheats" menu item in the future... git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3030 96395faa-99c1-11dd-bbfe-3dabce05a288 --- bin/cheats/DE37E046.pnach | 15 +++++++ pcsx2/DataBase_Loader.h | 2 + pcsx2/Patch.cpp | 86 ++++++++++++++++++++++++++++----------- pcsx2/Patch.h | 10 ++--- pcsx2/R5900.cpp | 16 ++++++-- 5 files changed, 98 insertions(+), 31 deletions(-) create mode 100644 bin/cheats/DE37E046.pnach diff --git a/bin/cheats/DE37E046.pnach b/bin/cheats/DE37E046.pnach new file mode 100644 index 0000000000..7eec098dc9 --- /dev/null +++ b/bin/cheats/DE37E046.pnach @@ -0,0 +1,15 @@ +comment=Persona 4 Cheats + +// Max Courage +//patch=1,EE,007973F4,word,000000FF + +// Inf Money +//patch=1,EE,2079B68C,word,05F5E0FF + +// Inf Health +patch=1,EE,207973CC,word,000003E7 +patch=1,EE,007973CC,word,000003E7 + +// Inf Spirit +patch=1,EE,207973CE,word,000003E7 +patch=1,EE,007973CE,word,000003E7 diff --git a/pcsx2/DataBase_Loader.h b/pcsx2/DataBase_Loader.h index dae52b014b..e978635914 100644 --- a/pcsx2/DataBase_Loader.h +++ b/pcsx2/DataBase_Loader.h @@ -373,6 +373,8 @@ static wxString compatToStringWX(int compat) { } } +// Load Game Settings found in database +// (game fixes, round modes, clamp modes, etc...) static void loadGameSettings(DataBase_Loader* gameDB) { if (gameDB && gameDB->gameLoaded()) { SSE_MXCSR eeMX = EmuConfig.Cpu.sseMXCSR; diff --git a/pcsx2/Patch.cpp b/pcsx2/Patch.cpp index 5104e403c5..a25f75558b 100644 --- a/pcsx2/Patch.cpp +++ b/pcsx2/Patch.cpp @@ -20,6 +20,7 @@ #include "IopCommon.h" #include "Patch.h" #include "DataBase_Loader.h" +#include IniPatch Patch[ MAX_PATCH ]; @@ -409,28 +410,26 @@ void inifile_command( const wxString& cmd ) int code = PatchTableExecute( set, commands ); } -// This routine recieves a file from inifile_read, trims it, +// This routine receives a string containing patches, trims it, // Then sends the command to be parsed. -void inifile_process(string& s) +void TrimPatches(string& s) { String_Stream ss(s); wxString buff; - while (!ss.finished()) - { + while (!ss.finished()) { buff = ss.getLineWX(); - //Console.Error("%s", buff.ToAscii()); - inifile_trim(buff); - if (!buff.IsEmpty()) inifile_command(buff); - } + inifile_trim(buff); + if (!buff.IsEmpty()) inifile_command(buff); + } } -// This routine creates a pnach filename from the games crc, -// loads it, trims the commands, and sends them to be parsed. -void inifile_read(const wxString& name ) +// This routine loads patches from the game database +// Returns number of patches loaded +int InitPatches(const wxString& name) { bool patchFound = false; string patch; - string crc = string(name.ToAscii()); + string crc = string(name.ToUTF8().data()); patchnumber = 0; if (GameDB && GameDB->gameLoaded()) { @@ -446,9 +445,55 @@ void inifile_read(const wxString& name ) if (patchFound) { Console.WriteLn(Color_Green, "Patch found!"); - inifile_process(patch); + TrimPatches(patch); } else Console.WriteLn(Color_Gray, "No patch found. Resuming execution without a patch (this is NOT an error)."); + + Console.WriteLn("Patches Loaded: %d", patchnumber); + return patchnumber; +} + +// This routine receives a file from inifile_read, trims it, +// Then sends the command to be parsed. +void inifile_process(wxTextFile &f1 ) +{ + for (uint i = 0; i < f1.GetLineCount(); i++) + { + inifile_trim(f1[i]); + if (!f1[i].IsEmpty()) inifile_command(f1[i]); + } +} + +// This routine loads cheats from *.pnach files +// Returns number of cheats loaded +// Note: Should be called after InitPatches() +int InitCheats(const wxString& name) +{ + wxTextFile f1; + wxString buffer; + int cheatsNumber = patchnumber; + + // FIXME : We need to add a 'cheats' folder to the AppConfig, and use that instead. --air + + buffer = Path::Combine(L"cheats", name + L".pnach"); + + if(!f1.Open(buffer) && wxFileName::IsCaseSensitive()) + { + f1.Open( Path::Combine(L"cheats", name.Upper() + L".pnach") ); + } + + if(!f1.IsOpened()) + { + Console.WriteLn( Color_Gray, "No cheats found. Resuming execution without cheats..." ); + return 0; + } + + Console.WriteLn( Color_Green, "Cheats found!"); + inifile_process( f1 ); + + cheatsNumber = patchnumber - cheatsNumber; + Console.WriteLn("Cheats Loaded: %d", cheatsNumber); + return cheatsNumber; } void _ApplyPatch(IniPatch *p) @@ -526,13 +571,6 @@ void ApplyPatch(int place) } } -int InitPatch(const wxString& crc) -{ - inifile_read(crc); - Console.WriteLn("patchnumber: %d", patchnumber); - return patchnumber; -} - void ResetPatch( void ) { patchnumber = 0; @@ -611,9 +649,11 @@ namespace PatchFunc void gametitle( const wxString& text1, const wxString& text2 ) { - Console.WriteLn( L"gametitle: " + text2 ); - strgametitle = text2; - Console.SetTitle( strgametitle ); + // Setting Game Title through patches is obsolete now + // Use database instead! + //Console.WriteLn( L"gametitle: " + text2 ); + //strgametitle = text2; + //Console.SetTitle( strgametitle ); } struct PatchPieces diff --git a/pcsx2/Patch.h b/pcsx2/Patch.h index 3f930897be..422b67fa1e 100644 --- a/pcsx2/Patch.h +++ b/pcsx2/Patch.h @@ -55,12 +55,12 @@ namespace PatchFunc PATCHTABLEFUNC roundmode; } -void inifile_read( const wxString& name ); -void inifile_command( const wxString& cmd ); -void inifile_trim( wxString& buffer ); +int InitCheats(const wxString& name); +void inifile_command(const wxString& cmd); +void inifile_trim(wxString& buffer); -int InitPatch(const wxString& crc); -int AddPatch(int Mode, int Place, int Address, int Size, u64 data); +int InitPatches(const wxString& name); +int AddPatch(int Mode, int Place, int Address, int Size, u64 data); void ApplyPatch( int place = 1); void ResetPatch( void ); diff --git a/pcsx2/R5900.cpp b/pcsx2/R5900.cpp index 5612139150..52ce32ee90 100644 --- a/pcsx2/R5900.cpp +++ b/pcsx2/R5900.cpp @@ -582,6 +582,7 @@ void __fastcall eeGameStarting() wxString gameSerial = L" [" + DiscID + L"]"; wxString gameCompat = L" [Status = Unknown]"; wxString gamePatch = L""; + wxString gameCheats = L""; if (GameDB && GameDB->gameLoaded()) { int compat = GameDB->getInt("Compat"); @@ -591,15 +592,24 @@ void __fastcall eeGameStarting() } if (EmuConfig.EnablePatches) { - int patches = InitPatch(gameCRC); + int patches = InitPatches(gameCRC); if (patches) { wxString pString( wxsFormat( L"%d", patches ) ); gamePatch = L" [Patches = " + pString + L"]"; } loadGameSettings(GameDB); } - - Console.SetTitle(gameName + gameSerial + gameCompat + gamePatch); + + // ToDo: EmuConfig.EnableCheats option... + if (EmuConfig.EnablePatches) { + int cheats = InitCheats(gameCRC); + if (cheats) { + wxString cString( wxsFormat( L"%d", cheats ) ); + gameCheats = L" [Cheats = " + cString + L"]"; + } + } + + Console.SetTitle(gameName + gameSerial + gameCompat + gamePatch + gameCheats); GetMTGS().SendGameCRC(ElfCRC); g_GameStarted = true;