2008-08-07 03:25:02 +00:00
|
|
|
/****************************************************************************
|
2010-01-27 22:20:37 +00:00
|
|
|
* Snes9x Nintendo Wii/Gamecube Port
|
2008-08-13 22:44:59 +00:00
|
|
|
*
|
2010-01-27 22:20:37 +00:00
|
|
|
* Tantric 2008-2010
|
2008-08-07 03:25:02 +00:00
|
|
|
*
|
|
|
|
* cheatmgr.cpp
|
|
|
|
*
|
|
|
|
* Cheat handling
|
2008-09-12 05:28:40 +00:00
|
|
|
***************************************************************************/
|
2008-08-07 03:25:02 +00:00
|
|
|
|
2010-04-12 22:39:41 +00:00
|
|
|
|
2009-11-25 06:35:14 +00:00
|
|
|
#include "port.h"
|
2008-08-07 03:25:02 +00:00
|
|
|
#include "cheats.h"
|
2008-08-12 03:25:16 +00:00
|
|
|
|
2010-03-21 23:43:54 +00:00
|
|
|
#include "snes9xgx.h"
|
2008-12-18 18:36:30 +00:00
|
|
|
#include "fileop.h"
|
2009-03-11 17:28:37 +00:00
|
|
|
#include "filebrowser.h"
|
2008-08-07 05:19:17 +00:00
|
|
|
|
2008-08-07 03:25:02 +00:00
|
|
|
extern SCheatData Cheat;
|
2008-08-12 03:25:16 +00:00
|
|
|
|
|
|
|
/****************************************************************************
|
2010-04-01 21:34:35 +00:00
|
|
|
* LoadCheatFile
|
2008-08-12 03:25:16 +00:00
|
|
|
*
|
|
|
|
* Loads cheat file from save buffer
|
|
|
|
* Custom version of S9xLoadCheatFile()
|
2008-09-12 05:28:40 +00:00
|
|
|
***************************************************************************/
|
2008-08-12 03:25:16 +00:00
|
|
|
|
2010-04-01 21:34:35 +00:00
|
|
|
static bool LoadCheatFile (int length)
|
2008-08-12 03:25:16 +00:00
|
|
|
{
|
|
|
|
uint8 data [28];
|
|
|
|
int offset = 0;
|
|
|
|
|
2018-08-16 08:41:30 -06:00
|
|
|
while (offset < length)
|
|
|
|
{
|
|
|
|
if(Cheat.num_cheats >= MAX_CHEATS || (length - offset) < 28)
|
2009-04-16 07:18:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
memcpy (data, savebuffer+offset, 28);
|
|
|
|
offset += 28;
|
|
|
|
|
2018-08-16 08:41:30 -06:00
|
|
|
Cheat.c [Cheat.num_cheats].enabled = 0; // cheats always off
|
|
|
|
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;
|
|
|
|
memcpy (Cheat.c [Cheat.num_cheats].name, &data[8], 20);
|
|
|
|
Cheat.c [Cheat.num_cheats].name[20] = 0;
|
|
|
|
Cheat.num_cheats++;
|
2008-08-12 03:25:16 +00:00
|
|
|
}
|
2008-09-27 19:52:11 +00:00
|
|
|
return true;
|
2008-08-12 03:25:16 +00:00
|
|
|
}
|
2008-08-07 03:25:02 +00:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* SetupCheats
|
|
|
|
*
|
|
|
|
* Erases any prexisting cheats, loads cheats from a cheat file
|
|
|
|
* Called when a ROM is first loaded
|
2008-09-12 05:28:40 +00:00
|
|
|
***************************************************************************/
|
2008-08-07 03:25:02 +00:00
|
|
|
void
|
2009-11-25 06:35:14 +00:00
|
|
|
WiiSetupCheats()
|
2008-08-07 03:25:02 +00:00
|
|
|
{
|
2018-08-16 08:41:30 -06:00
|
|
|
memset(Cheat.c, 0, sizeof(Cheat.c));
|
|
|
|
Cheat.num_cheats = 0;
|
|
|
|
|
2008-08-12 03:25:16 +00:00
|
|
|
char filepath[1024];
|
|
|
|
int offset = 0;
|
2008-08-07 03:25:02 +00:00
|
|
|
|
2009-10-01 22:35:12 +00:00
|
|
|
if(!MakeFilePath(filepath, FILE_CHEAT))
|
2008-11-12 07:50:39 +00:00
|
|
|
return;
|
|
|
|
|
2008-09-27 19:52:11 +00:00
|
|
|
AllocSaveBuffer();
|
|
|
|
|
2009-10-01 22:35:12 +00:00
|
|
|
offset = LoadFile(filepath, SILENT);
|
2008-08-07 05:19:17 +00:00
|
|
|
|
2008-08-07 03:25:02 +00:00
|
|
|
// load cheat file if present
|
2008-08-12 03:25:16 +00:00
|
|
|
if(offset > 0)
|
2010-04-12 22:39:41 +00:00
|
|
|
LoadCheatFile (offset);
|
2008-09-27 19:52:11 +00:00
|
|
|
|
|
|
|
FreeSaveBuffer ();
|
2008-08-07 03:25:02 +00:00
|
|
|
}
|