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
This commit is contained in:
cottonvibes 2010-05-17 01:56:54 +00:00
parent 16dfd5c9fc
commit 9c9769c380
5 changed files with 98 additions and 31 deletions

15
bin/cheats/DE37E046.pnach Normal file
View File

@ -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

View File

@ -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;

View File

@ -20,6 +20,7 @@
#include "IopCommon.h"
#include "Patch.h"
#include "DataBase_Loader.h"
#include <wx/textfile.h>
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

View File

@ -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 );

View File

@ -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;