mirror of
https://github.com/dborth/fceugx.git
synced 2025-01-07 14:28:18 +01:00
cheat file support
This commit is contained in:
parent
0c5fb7f088
commit
3a63751d24
@ -157,14 +157,13 @@ void FCEU_PowerCheats()
|
|||||||
RebuildSubCheats();
|
RebuildSubCheats();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type);
|
|
||||||
static void CheatMemErr(void)
|
static void CheatMemErr(void)
|
||||||
{
|
{
|
||||||
FCEUD_PrintError("Error allocating memory for cheat data.");
|
FCEUD_PrintError("Error allocating memory for cheat data.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function doesn't allocate any memory for "name" */
|
/* 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;
|
struct CHEATF *temp;
|
||||||
if(!(temp=(struct CHEATF *)malloc(sizeof(struct CHEATF))))
|
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;
|
savecheats=1;
|
||||||
RebuildSubCheats();
|
RebuildSubCheats();
|
||||||
|
|
||||||
return(1);
|
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
|
//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
|
//and make these accessible to other dialogs that deal with memory addresses such as
|
||||||
//memwatch, hex editor, ramfilter, etc.
|
//memwatch, hex editor, ramfilter, etc.
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
FrozenAddresses.clear(); //Clear vector and repopulate
|
FrozenAddresses.clear(); //Clear vector and repopulate
|
||||||
for(x=0;x<numsubcheats;x++)
|
for(x=0;x<numsubcheats;x++)
|
||||||
@ -953,4 +952,4 @@ void UpdateFrozenList(void)
|
|||||||
//FCEU_printf("Address %d: %d \n",x,FrozenAddresses[x]); //Debug
|
//FCEU_printf("Address %d: %d \n",x,FrozenAddresses[x]); //Debug
|
||||||
}
|
}
|
||||||
//FCEUI_DispMessage("FrozenCount: %d",FrozenAddressCount);//Debug
|
//FCEUI_DispMessage("FrozenCount: %d",FrozenAddressCount);//Debug
|
||||||
}
|
}
|
||||||
|
145
source/ngc/cheatmgr.cpp
Normal file
145
source/ngc/cheatmgr.cpp
Normal 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
14
source/ngc/cheatmgr.h
Normal 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;
|
@ -24,6 +24,7 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "fileop.h"
|
#include "fileop.h"
|
||||||
#include "filebrowser.h"
|
#include "filebrowser.h"
|
||||||
|
#include "cheatmgr.h"
|
||||||
|
|
||||||
bool romLoaded = false;
|
bool romLoaded = false;
|
||||||
|
|
||||||
@ -138,10 +139,7 @@ int GCMemROM(int method, int size)
|
|||||||
|
|
||||||
FCEU_ResetPalette();
|
FCEU_ResetPalette();
|
||||||
FCEU_ResetMessages(); // Save state, status messages, etc.
|
FCEU_ResetMessages(); // Save state, status messages, etc.
|
||||||
|
SetupCheats();
|
||||||
//if(GameInfo->type!=GIT_NSF)
|
|
||||||
// FCEU_LoadGameCheats(0);
|
|
||||||
|
|
||||||
ResetAudio();
|
ResetAudio();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
extern unsigned char * nesrom;
|
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 FDSLoad(const char *name, FCEUFILE *fp);
|
||||||
extern int iNESLoad(const char *name, FCEUFILE *fp, int o);
|
extern int iNESLoad(const char *name, FCEUFILE *fp, int o);
|
||||||
extern int UNIFLoad(const char *name, FCEUFILE *fp);
|
extern int UNIFLoad(const char *name, FCEUFILE *fp);
|
||||||
|
@ -271,6 +271,10 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi
|
|||||||
sprintf(folder, GCSettings.LoadFolder);
|
sprintf(folder, GCSettings.LoadFolder);
|
||||||
sprintf(file, "disksys.rom");
|
sprintf(file, "disksys.rom");
|
||||||
break;
|
break;
|
||||||
|
case FILE_CHEAT:
|
||||||
|
sprintf(folder, GCSettings.CheatFolder);
|
||||||
|
sprintf(file, "%s.cht", romFilename);
|
||||||
|
break;
|
||||||
case FILE_PREF:
|
case FILE_PREF:
|
||||||
sprintf(folder, appPath);
|
sprintf(folder, appPath);
|
||||||
sprintf(file, "%s", PREF_FILE_NAME);
|
sprintf(file, "%s", PREF_FILE_NAME);
|
||||||
|
@ -58,7 +58,7 @@ extern FreeTypeGX *fontSystem[];
|
|||||||
#define PAGESIZE 8
|
#define PAGESIZE 8
|
||||||
#define SAVELISTSIZE 6
|
#define SAVELISTSIZE 6
|
||||||
#define MAX_SAVES 20
|
#define MAX_SAVES 20
|
||||||
#define MAX_OPTIONS 30
|
#define MAX_OPTIONS 150
|
||||||
#define MAX_KEYBOARD_DISPLAY 32
|
#define MAX_KEYBOARD_DISPLAY 32
|
||||||
|
|
||||||
typedef void (*UpdateCallback)(void * e);
|
typedef void (*UpdateCallback)(void * e);
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "fceuload.h"
|
#include "fceuload.h"
|
||||||
#include "filelist.h"
|
#include "filelist.h"
|
||||||
|
#include "cheatmgr.h"
|
||||||
|
|
||||||
#define THREAD_SLEEP 100
|
#define THREAD_SLEEP 100
|
||||||
|
|
||||||
@ -1873,7 +1874,7 @@ static int MenuGameSettings()
|
|||||||
GuiImage controllerBtnIcon(&iconController);
|
GuiImage controllerBtnIcon(&iconController);
|
||||||
GuiButton controllerBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight());
|
GuiButton controllerBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight());
|
||||||
controllerBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
controllerBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||||
controllerBtn.SetPosition(0, 250);
|
controllerBtn.SetPosition(-125, 250);
|
||||||
controllerBtn.SetLabel(&controllerBtnTxt);
|
controllerBtn.SetLabel(&controllerBtnTxt);
|
||||||
controllerBtn.SetImage(&controllerBtnImg);
|
controllerBtn.SetImage(&controllerBtnImg);
|
||||||
controllerBtn.SetImageOver(&controllerBtnImgOver);
|
controllerBtn.SetImageOver(&controllerBtnImgOver);
|
||||||
@ -1934,7 +1935,7 @@ static int MenuGameSettings()
|
|||||||
w.Append(&mappingBtn);
|
w.Append(&mappingBtn);
|
||||||
w.Append(&videoBtn);
|
w.Append(&videoBtn);
|
||||||
w.Append(&controllerBtn);
|
w.Append(&controllerBtn);
|
||||||
//w.Append(&cheatsBtn);
|
w.Append(&cheatsBtn);
|
||||||
w.Append(&closeBtn);
|
w.Append(&closeBtn);
|
||||||
w.Append(&backBtn);
|
w.Append(&backBtn);
|
||||||
|
|
||||||
@ -1958,14 +1959,14 @@ static int MenuGameSettings()
|
|||||||
{
|
{
|
||||||
ControllerWindow();
|
ControllerWindow();
|
||||||
}
|
}
|
||||||
/*else if(cheatsBtn.GetState() == STATE_CLICKED)
|
else if(cheatsBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
cheatsBtn.ResetState();
|
cheatsBtn.ResetState();
|
||||||
if(Cheat.num_cheats > 0)
|
if(numcheats > 0)
|
||||||
menu = MENU_GAMESETTINGS_CHEATS;
|
menu = MENU_GAMESETTINGS_CHEATS;
|
||||||
else
|
else
|
||||||
InfoPrompt("Cheats file not found!");
|
InfoPrompt("Cheats file not found!");
|
||||||
}*/
|
}
|
||||||
else if(closeBtn.GetState() == STATE_CLICKED)
|
else if(closeBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
menu = MENU_EXIT;
|
menu = MENU_EXIT;
|
||||||
@ -2000,16 +2001,22 @@ static int MenuGameSettings()
|
|||||||
* Displays a list of cheats available, and allows the user to enable/disable
|
* Displays a list of cheats available, and allows the user to enable/disable
|
||||||
* them.
|
* them.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
/*
|
|
||||||
static int MenuGameCheats()
|
static int MenuGameCheats()
|
||||||
{
|
{
|
||||||
int menu = MENU_NONE;
|
int menu = MENU_NONE;
|
||||||
int ret;
|
int ret;
|
||||||
u16 i = 0;
|
u16 i = 0;
|
||||||
OptionList options;
|
OptionList options;
|
||||||
|
char *name; // cheat name
|
||||||
|
int status; // cheat status (on/off)
|
||||||
|
|
||||||
for(i=0; i < Cheat.num_cheats; i++)
|
for(i=0; i < numcheats; i++)
|
||||||
sprintf (options.name[i], "%s", Cheat.c[i].name);
|
{
|
||||||
|
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;
|
options.length = i;
|
||||||
|
|
||||||
@ -2050,6 +2057,7 @@ static int MenuGameCheats()
|
|||||||
GuiOptionBrowser optionBrowser(552, 248, &options);
|
GuiOptionBrowser optionBrowser(552, 248, &options);
|
||||||
optionBrowser.SetPosition(0, 108);
|
optionBrowser.SetPosition(0, 108);
|
||||||
optionBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
optionBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||||
|
optionBrowser.SetCol2Position(350);
|
||||||
|
|
||||||
HaltGui();
|
HaltGui();
|
||||||
GuiWindow w(screenwidth, screenheight);
|
GuiWindow w(screenwidth, screenheight);
|
||||||
@ -2063,15 +2071,13 @@ static int MenuGameCheats()
|
|||||||
{
|
{
|
||||||
usleep(THREAD_SLEEP);
|
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();
|
ret = optionBrowser.GetClickedOption();
|
||||||
|
|
||||||
if(Cheat.c[ret].enabled)
|
if(ret >= 0)
|
||||||
S9xDisableCheat(ret);
|
{
|
||||||
else
|
FCEUI_ToggleCheat(ret);
|
||||||
S9xEnableCheat(ret);
|
sprintf (options.value[ret], "%s", options.value[ret][1] == 'f' ? "On" : "Off");
|
||||||
|
}
|
||||||
|
|
||||||
if(backBtn.GetState() == STATE_CLICKED)
|
if(backBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
@ -2084,7 +2090,6 @@ static int MenuGameCheats()
|
|||||||
mainWindow->Remove(&titleTxt);
|
mainWindow->Remove(&titleTxt);
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* MenuSettingsMappings
|
* MenuSettingsMappings
|
||||||
@ -3774,9 +3779,9 @@ MainMenu (int menu)
|
|||||||
case MENU_GAMESETTINGS_VIDEO:
|
case MENU_GAMESETTINGS_VIDEO:
|
||||||
currentMenu = MenuSettingsVideo();
|
currentMenu = MenuSettingsVideo();
|
||||||
break;
|
break;
|
||||||
/*case MENU_GAMESETTINGS_CHEATS:
|
case MENU_GAMESETTINGS_CHEATS:
|
||||||
currentMenu = MenuGameCheats();
|
currentMenu = MenuGameCheats();
|
||||||
break;*/
|
break;
|
||||||
case MENU_SETTINGS:
|
case MENU_SETTINGS:
|
||||||
currentMenu = MenuSettings();
|
currentMenu = MenuSettings();
|
||||||
break;
|
break;
|
||||||
|
@ -125,7 +125,7 @@ preparePrefsData (int method)
|
|||||||
createXMLSetting("SaveMethod", "Save Method", toStr(GCSettings.SaveMethod));
|
createXMLSetting("SaveMethod", "Save Method", toStr(GCSettings.SaveMethod));
|
||||||
createXMLSetting("LoadFolder", "Load Folder", GCSettings.LoadFolder);
|
createXMLSetting("LoadFolder", "Load Folder", GCSettings.LoadFolder);
|
||||||
createXMLSetting("SaveFolder", "Save Folder", GCSettings.SaveFolder);
|
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));
|
createXMLSetting("VerifySaves", "Verify Memory Card Saves", toStr(GCSettings.VerifySaves));
|
||||||
|
|
||||||
createXMLSection("Network", "Network Settings");
|
createXMLSection("Network", "Network Settings");
|
||||||
@ -281,7 +281,7 @@ decodePrefsData (int method)
|
|||||||
loadXMLSetting(&GCSettings.SaveMethod, "SaveMethod");
|
loadXMLSetting(&GCSettings.SaveMethod, "SaveMethod");
|
||||||
loadXMLSetting(GCSettings.LoadFolder, "LoadFolder", sizeof(GCSettings.LoadFolder));
|
loadXMLSetting(GCSettings.LoadFolder, "LoadFolder", sizeof(GCSettings.LoadFolder));
|
||||||
loadXMLSetting(GCSettings.SaveFolder, "SaveFolder", sizeof(GCSettings.SaveFolder));
|
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");
|
loadXMLSetting(&GCSettings.VerifySaves, "VerifySaves");
|
||||||
|
|
||||||
// Network Settings
|
// Network Settings
|
||||||
|
Loading…
Reference in New Issue
Block a user