2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
2008-09-12 07:28:40 +02:00
|
|
|
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
2008-08-14 00:44:59 +02:00
|
|
|
*
|
2008-08-07 05:25:02 +02:00
|
|
|
* Tantric August 2008
|
|
|
|
*
|
|
|
|
* cheatmgr.cpp
|
|
|
|
*
|
|
|
|
* Cheat handling
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-07 05:25:02 +02:00
|
|
|
|
|
|
|
#include "memmap.h"
|
|
|
|
#include "cheats.h"
|
2008-08-12 05:25:16 +02:00
|
|
|
|
2008-09-09 19:36:48 +02:00
|
|
|
#include "snes9xGX.h"
|
2008-08-12 05:25:16 +02:00
|
|
|
#include "fileop.h"
|
2008-08-10 05:14:39 +02:00
|
|
|
#include "filesel.h"
|
2008-08-12 05:25:16 +02:00
|
|
|
#include "smbop.h"
|
|
|
|
#include "menudraw.h"
|
2008-08-07 07:19:17 +02:00
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
extern SCheatData Cheat;
|
2008-08-12 05:25:16 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* NGCLoadCheatFile
|
|
|
|
*
|
|
|
|
* Loads cheat file from save buffer
|
|
|
|
* Custom version of S9xLoadCheatFile()
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-12 05:25:16 +02:00
|
|
|
|
2008-09-27 21:52:11 +02:00
|
|
|
bool NGCLoadCheatFile (int length)
|
2008-08-12 05:25:16 +02:00
|
|
|
{
|
|
|
|
Cheat.num_cheats = 0;
|
|
|
|
|
|
|
|
uint8 data [28];
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
while (offset < length)
|
|
|
|
{
|
2008-08-14 00:44:59 +02:00
|
|
|
if(Cheat.num_cheats < MAX_CHEATS)
|
|
|
|
{
|
|
|
|
memcpy (data, savebuffer+offset, 28);
|
|
|
|
offset += 28;
|
|
|
|
|
|
|
|
Cheat.c [Cheat.num_cheats].enabled = (data [0] & 4) == 0;
|
|
|
|
Cheat.c [Cheat.num_cheats].byte = data [1];
|
|
|
|
Cheat.c [Cheat.num_cheats].address = data [2] | (data [3] << 8) | (data [4] << 16);
|
|
|
|
Cheat.c [Cheat.num_cheats].saved_byte = data [5];
|
|
|
|
Cheat.c [Cheat.num_cheats].saved = (data [0] & 8) != 0;
|
|
|
|
memmove (Cheat.c [Cheat.num_cheats].name, &data [8], 20);
|
|
|
|
Cheat.c [Cheat.num_cheats++].name [20] = 0;
|
|
|
|
}
|
2008-08-12 05:25:16 +02:00
|
|
|
}
|
|
|
|
|
2008-09-27 21:52:11 +02:00
|
|
|
return true;
|
2008-08-12 05:25:16 +02:00
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* SetupCheats
|
|
|
|
*
|
|
|
|
* Erases any prexisting cheats, loads cheats from a cheat file
|
|
|
|
* Called when a ROM is first loaded
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-07 05:25:02 +02:00
|
|
|
void
|
|
|
|
SetupCheats()
|
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
char filepath[1024];
|
|
|
|
int offset = 0;
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
S9xInitCheatData ();
|
|
|
|
S9xDeleteCheats ();
|
|
|
|
|
2008-08-10 05:14:39 +02:00
|
|
|
int method = GCSettings.SaveMethod;
|
|
|
|
|
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
method = autoSaveMethod();
|
|
|
|
|
2008-09-27 21:52:11 +02:00
|
|
|
AllocSaveBuffer();
|
|
|
|
|
2008-08-10 05:14:39 +02:00
|
|
|
if(method == METHOD_SD || method == METHOD_USB)
|
2008-08-08 09:57:01 +02:00
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
if(ChangeFATInterface(method, NOTSILENT))
|
|
|
|
{
|
|
|
|
sprintf (filepath, "%s/%s/%s.cht", ROOTFATDIR, GCSettings.CheatFolder, Memory.ROMFilename);
|
|
|
|
offset = LoadBufferFromFAT (filepath, SILENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(method == METHOD_SMB)
|
|
|
|
{
|
|
|
|
sprintf (filepath, "%s/%s.cht", GCSettings.CheatFolder, Memory.ROMFilename);
|
|
|
|
offset = LoadBufferFromSMB (filepath, SILENT);
|
2008-08-08 09:57:01 +02:00
|
|
|
}
|
2008-08-07 07:19:17 +02:00
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
// load cheat file if present
|
2008-08-12 05:25:16 +02:00
|
|
|
if(offset > 0)
|
2008-08-07 07:19:17 +02:00
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
if(NGCLoadCheatFile (offset))
|
2008-08-07 05:25:02 +02:00
|
|
|
{
|
|
|
|
// disable all cheats loaded from the file
|
|
|
|
for (uint16 i = 0; i < Cheat.num_cheats; i++)
|
|
|
|
S9xDisableCheat(i);
|
|
|
|
}
|
|
|
|
}
|
2008-09-27 21:52:11 +02:00
|
|
|
|
|
|
|
FreeSaveBuffer ();
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|