cheat file support

This commit is contained in:
dborth 2009-07-22 01:58:45 +00:00
parent 0c5fb7f088
commit 3a63751d24
9 changed files with 198 additions and 30 deletions

View File

@ -157,14 +157,13 @@ void FCEU_PowerCheats()
RebuildSubCheats();
}
static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type);
static void CheatMemErr(void)
{
FCEUD_PrintError("Error allocating memory for cheat data.");
}
/* This function doesn't allocate any memory for "name" */
static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type)
int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type)
{
struct CHEATF *temp;
if(!(temp=(struct CHEATF *)malloc(sizeof(struct CHEATF))))
@ -381,7 +380,7 @@ int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int ty
}
savecheats=1;
RebuildSubCheats();
return(1);
}
@ -944,7 +943,7 @@ void UpdateFrozenList(void)
//The purpose of this function is to keep an up to date list of addresses that are currently frozen
//and make these accessible to other dialogs that deal with memory addresses such as
//memwatch, hex editor, ramfilter, etc.
int x;
FrozenAddresses.clear(); //Clear vector and repopulate
for(x=0;x<numsubcheats;x++)
@ -953,4 +952,4 @@ void UpdateFrozenList(void)
//FCEU_printf("Address %d: %d \n",x,FrozenAddresses[x]); //Debug
}
//FCEUI_DispMessage("FrozenCount: %d",FrozenAddressCount);//Debug
}
}

145
source/ngc/cheatmgr.cpp Normal file
View File

@ -0,0 +1,145 @@
/****************************************************************************
* FCE Ultra 0.98.12
* Nintendo Wii/Gamecube Port
*
* Tantric 2008-2009
*
* cheatmgr.cpp
*
* Cheat handling
***************************************************************************/
#include "fceugx.h"
#include "fceusupport.h"
#include "fileop.h"
#include "filebrowser.h"
#include "cheat.h"
#include "menu.h"
int numcheats = 0;
/****************************************************************************
* LoadCheats
*
* Loads cheat file from save buffer
* Custom version of FCEU_LoadGameCheats()
***************************************************************************/
static int LoadCheats (int length)
{
unsigned int addr;
unsigned int val;
unsigned int status;
unsigned int type;
unsigned int compare;
int x;
char *namebuf;
int tc=0;
char * linebreak = strtok((char *)savebuffer, "\n");
while(linebreak != NULL)
{
char *tbuf=linebreak+1;
int doc=0;
addr=val=compare=status=type=0;
if(tbuf[0]=='S')
{
tbuf++;
type=1;
}
else type=0;
if(tbuf[0]=='C')
{
tbuf++;
doc=1;
}
if(tbuf[0]==':')
{
tbuf++;
status=0;
}
else status=1;
if(doc)
{
char *neo=&tbuf[4+2+2+1+1+1];
if(sscanf(tbuf,"%04x%*[:]%02x%*[:]%02x",&addr,&val,&compare)!=3)
continue;
namebuf=(char *)malloc(strlen(neo)+1);
strcpy(namebuf,neo);
}
else
{
char *neo=&tbuf[4+2+1+1];
if(sscanf(tbuf,"%04x%*[:]%02x",&addr,&val)!=2)
continue;
namebuf=(char *)malloc(strlen(neo)+1);
strcpy(namebuf,neo);
}
for(x=0;x<(int)strlen(namebuf);x++)
{
if(namebuf[x]==10 || namebuf[x]==13)
{
namebuf[x]=0;
break;
}
else if(namebuf[x]<0x20) namebuf[x]=' ';
}
AddCheatEntry(namebuf,addr,val,doc?compare:-1,status,type);
FCEUI_ToggleCheat(tc); // turn cheat off
tc++;
// find next line break
linebreak = strtok(NULL, "\n");
}
RebuildSubCheats();
return tc;
}
/****************************************************************************
* SetupCheats
*
* Erases any prexisting cheats, loads cheats from a cheat file
* Called when a ROM is first loaded
***************************************************************************/
void
SetupCheats()
{
FCEU_PowerCheats();
numcheats = 0;
if(GameInfo->type == GIT_NSF)
return;
char filepath[1024];
int offset = 0;
int method = GCSettings.SaveMethod;
if(method == METHOD_AUTO)
method = autoSaveMethod(SILENT);
if(method == METHOD_AUTO)
return;
if(!MakeFilePath(filepath, FILE_CHEAT, method))
return;
AllocSaveBuffer();
offset = LoadFile(filepath, method, SILENT);
// load cheat file if present
if(offset > 0)
numcheats = LoadCheats(offset);
FreeSaveBuffer ();
}

14
source/ngc/cheatmgr.h Normal file
View File

@ -0,0 +1,14 @@
/****************************************************************************
* FCE Ultra 0.98.12
* Nintendo Wii/Gamecube Port
*
* Tantric 2009
*
* cheatmgr.h
*
* Cheat handling
***************************************************************************/
void SetupCheats();
extern int numcheats;

View File

@ -24,6 +24,7 @@
#include "menu.h"
#include "fileop.h"
#include "filebrowser.h"
#include "cheatmgr.h"
bool romLoaded = false;
@ -138,10 +139,7 @@ int GCMemROM(int method, int size)
FCEU_ResetPalette();
FCEU_ResetMessages(); // Save state, status messages, etc.
//if(GameInfo->type!=GIT_NSF)
// FCEU_LoadGameCheats(0);
SetupCheats();
ResetAudio();
return 1;
}

View File

@ -23,6 +23,9 @@
extern unsigned char * nesrom;
void RebuildSubCheats(void);
int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type);
extern int FDSLoad(const char *name, FCEUFILE *fp);
extern int iNESLoad(const char *name, FCEUFILE *fp, int o);
extern int UNIFLoad(const char *name, FCEUFILE *fp);

View File

@ -271,6 +271,10 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi
sprintf(folder, GCSettings.LoadFolder);
sprintf(file, "disksys.rom");
break;
case FILE_CHEAT:
sprintf(folder, GCSettings.CheatFolder);
sprintf(file, "%s.cht", romFilename);
break;
case FILE_PREF:
sprintf(folder, appPath);
sprintf(file, "%s", PREF_FILE_NAME);

View File

@ -58,7 +58,7 @@ extern FreeTypeGX *fontSystem[];
#define PAGESIZE 8
#define SAVELISTSIZE 6
#define MAX_SAVES 20
#define MAX_OPTIONS 30
#define MAX_OPTIONS 150
#define MAX_KEYBOARD_DISPLAY 32
typedef void (*UpdateCallback)(void * e);

View File

@ -42,6 +42,7 @@
#include "menu.h"
#include "fceuload.h"
#include "filelist.h"
#include "cheatmgr.h"
#define THREAD_SLEEP 100
@ -1873,7 +1874,7 @@ static int MenuGameSettings()
GuiImage controllerBtnIcon(&iconController);
GuiButton controllerBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight());
controllerBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
controllerBtn.SetPosition(0, 250);
controllerBtn.SetPosition(-125, 250);
controllerBtn.SetLabel(&controllerBtnTxt);
controllerBtn.SetImage(&controllerBtnImg);
controllerBtn.SetImageOver(&controllerBtnImgOver);
@ -1934,7 +1935,7 @@ static int MenuGameSettings()
w.Append(&mappingBtn);
w.Append(&videoBtn);
w.Append(&controllerBtn);
//w.Append(&cheatsBtn);
w.Append(&cheatsBtn);
w.Append(&closeBtn);
w.Append(&backBtn);
@ -1958,14 +1959,14 @@ static int MenuGameSettings()
{
ControllerWindow();
}
/*else if(cheatsBtn.GetState() == STATE_CLICKED)
else if(cheatsBtn.GetState() == STATE_CLICKED)
{
cheatsBtn.ResetState();
if(Cheat.num_cheats > 0)
if(numcheats > 0)
menu = MENU_GAMESETTINGS_CHEATS;
else
InfoPrompt("Cheats file not found!");
}*/
}
else if(closeBtn.GetState() == STATE_CLICKED)
{
menu = MENU_EXIT;
@ -2000,16 +2001,22 @@ static int MenuGameSettings()
* Displays a list of cheats available, and allows the user to enable/disable
* them.
***************************************************************************/
/*
static int MenuGameCheats()
{
int menu = MENU_NONE;
int ret;
u16 i = 0;
OptionList options;
char *name; // cheat name
int status; // cheat status (on/off)
for(i=0; i < Cheat.num_cheats; i++)
sprintf (options.name[i], "%s", Cheat.c[i].name);
for(i=0; i < numcheats; i++)
{
FCEUI_GetCheat(i,&name,NULL,NULL,NULL,&status,NULL);
sprintf (options.name[i], "%s", name);
sprintf (options.value[i], status ? "On" : "Off");
}
options.length = i;
@ -2050,6 +2057,7 @@ static int MenuGameCheats()
GuiOptionBrowser optionBrowser(552, 248, &options);
optionBrowser.SetPosition(0, 108);
optionBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
optionBrowser.SetCol2Position(350);
HaltGui();
GuiWindow w(screenwidth, screenheight);
@ -2063,15 +2071,13 @@ static int MenuGameCheats()
{
usleep(THREAD_SLEEP);
for(i=0; i < Cheat.num_cheats; i++)
sprintf (options.value[i], "%s", Cheat.c[i].enabled == true ? "On" : "Off");
ret = optionBrowser.GetClickedOption();
if(Cheat.c[ret].enabled)
S9xDisableCheat(ret);
else
S9xEnableCheat(ret);
if(ret >= 0)
{
FCEUI_ToggleCheat(ret);
sprintf (options.value[ret], "%s", options.value[ret][1] == 'f' ? "On" : "Off");
}
if(backBtn.GetState() == STATE_CLICKED)
{
@ -2084,7 +2090,6 @@ static int MenuGameCheats()
mainWindow->Remove(&titleTxt);
return menu;
}
*/
/****************************************************************************
* MenuSettingsMappings
@ -3774,9 +3779,9 @@ MainMenu (int menu)
case MENU_GAMESETTINGS_VIDEO:
currentMenu = MenuSettingsVideo();
break;
/*case MENU_GAMESETTINGS_CHEATS:
case MENU_GAMESETTINGS_CHEATS:
currentMenu = MenuGameCheats();
break;*/
break;
case MENU_SETTINGS:
currentMenu = MenuSettings();
break;

View File

@ -125,7 +125,7 @@ preparePrefsData (int method)
createXMLSetting("SaveMethod", "Save Method", toStr(GCSettings.SaveMethod));
createXMLSetting("LoadFolder", "Load Folder", GCSettings.LoadFolder);
createXMLSetting("SaveFolder", "Save Folder", GCSettings.SaveFolder);
//createXMLSetting("CheatFolder", "Cheats Folder", GCSettings.CheatFolder);
createXMLSetting("CheatFolder", "Cheats Folder", GCSettings.CheatFolder);
createXMLSetting("VerifySaves", "Verify Memory Card Saves", toStr(GCSettings.VerifySaves));
createXMLSection("Network", "Network Settings");
@ -281,7 +281,7 @@ decodePrefsData (int method)
loadXMLSetting(&GCSettings.SaveMethod, "SaveMethod");
loadXMLSetting(GCSettings.LoadFolder, "LoadFolder", sizeof(GCSettings.LoadFolder));
loadXMLSetting(GCSettings.SaveFolder, "SaveFolder", sizeof(GCSettings.SaveFolder));
//loadXMLSetting(GCSettings.CheatFolder, "CheatFolder", sizeof(GCSettings.CheatFolder));
loadXMLSetting(GCSettings.CheatFolder, "CheatFolder", sizeof(GCSettings.CheatFolder));
loadXMLSetting(&GCSettings.VerifySaves, "VerifySaves");
// Network Settings