2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
2010-01-27 23:20:37 +01:00
|
|
|
* Snes9x Nintendo Wii/Gamecube Port
|
2008-08-14 00:44:59 +02:00
|
|
|
*
|
2010-01-27 23:20:37 +01:00
|
|
|
* Tantric 2008-2010
|
2008-08-07 05:25:02 +02:00
|
|
|
*
|
|
|
|
* cheatmgr.cpp
|
|
|
|
*
|
|
|
|
* Cheat handling
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2010-04-13 00:39:41 +02:00
|
|
|
|
2009-11-25 07:35:14 +01:00
|
|
|
#include "port.h"
|
2008-08-07 05:25:02 +02:00
|
|
|
#include "cheats.h"
|
2008-08-12 05:25:16 +02:00
|
|
|
|
2010-03-22 00:43:54 +01:00
|
|
|
#include "snes9xgx.h"
|
2008-12-18 19:36:30 +01:00
|
|
|
#include "fileop.h"
|
2009-03-11 18:28:37 +01:00
|
|
|
#include "filebrowser.h"
|
2008-08-07 07:19:17 +02:00
|
|
|
|
2018-08-11 22:56:31 +02:00
|
|
|
#define MAX_CHEATS 100
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
extern SCheatData Cheat;
|
2008-08-12 05:25:16 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2010-04-01 23:34:35 +02:00
|
|
|
* LoadCheatFile
|
2008-08-12 05:25:16 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2010-04-01 23:34:35 +02:00
|
|
|
static bool LoadCheatFile (int length)
|
2008-08-12 05:25:16 +02:00
|
|
|
{
|
|
|
|
uint8 data [28];
|
|
|
|
int offset = 0;
|
|
|
|
|
2018-08-13 00:36:31 +02:00
|
|
|
while (offset < length) {
|
2018-08-11 22:56:31 +02:00
|
|
|
if(Cheat.g.size() >= MAX_CHEATS || (length - offset) < 28)
|
2009-04-16 09:18:38 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
memcpy (data, savebuffer+offset, 28);
|
|
|
|
offset += 28;
|
|
|
|
|
2018-08-11 22:56:31 +02:00
|
|
|
SCheat c;
|
|
|
|
char name[21];
|
|
|
|
char cheat[10];
|
|
|
|
c.byte = data[1];
|
|
|
|
c.address = data[2] | (data[3] << 8) | (data[4] << 16);
|
|
|
|
memcpy (name, &data[8], 20);
|
|
|
|
name[20] = 0;
|
|
|
|
|
|
|
|
snprintf (cheat, 10, "%x=%x", c.address, c.byte);
|
|
|
|
S9xAddCheatGroup (name, cheat);
|
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
|
|
|
|
2018-08-13 00:36:31 +02:00
|
|
|
void ToggleCheat(uint32 num) {
|
|
|
|
if(Cheat.g[num].enabled) {
|
|
|
|
S9xDisableCheatGroup(num);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
S9xEnableCheatGroup(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=0; i < Cheat.g.size(); i++) {
|
|
|
|
if(Cheat.g[i].enabled) {
|
|
|
|
Cheat.enabled = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Cheat.enabled = FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
2009-11-25 07:35:14 +01:00
|
|
|
WiiSetupCheats()
|
2008-08-07 05:25:02 +02:00
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
char filepath[1024];
|
|
|
|
int offset = 0;
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2009-10-02 00:35:12 +02:00
|
|
|
if(!MakeFilePath(filepath, FILE_CHEAT))
|
2008-11-12 08:50:39 +01:00
|
|
|
return;
|
|
|
|
|
2008-09-27 21:52:11 +02:00
|
|
|
AllocSaveBuffer();
|
|
|
|
|
2009-10-02 00:35:12 +02:00
|
|
|
offset = LoadFile(filepath, SILENT);
|
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)
|
2010-04-13 00:39:41 +02:00
|
|
|
LoadCheatFile (offset);
|
2008-09-27 21:52:11 +02:00
|
|
|
|
|
|
|
FreeSaveBuffer ();
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|