diff --git a/source/fceultra/cheat.cpp b/source/fceultra/cheat.cpp index db4b7f9..a94681d 100644 --- a/source/fceultra/cheat.cpp +++ b/source/fceultra/cheat.cpp @@ -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;xtype == 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 (); +} diff --git a/source/ngc/cheatmgr.h b/source/ngc/cheatmgr.h new file mode 100644 index 0000000..0663e19 --- /dev/null +++ b/source/ngc/cheatmgr.h @@ -0,0 +1,14 @@ +/**************************************************************************** + * FCE Ultra 0.98.12 + * Nintendo Wii/Gamecube Port + * + * Tantric 2009 + * + * cheatmgr.h + * + * Cheat handling + ***************************************************************************/ + +void SetupCheats(); + +extern int numcheats; diff --git a/source/ngc/fceuload.cpp b/source/ngc/fceuload.cpp index 87daa45..3c61280 100644 --- a/source/ngc/fceuload.cpp +++ b/source/ngc/fceuload.cpp @@ -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; } diff --git a/source/ngc/fceusupport.h b/source/ngc/fceusupport.h index 1c7b570..eb6a3a0 100644 --- a/source/ngc/fceusupport.h +++ b/source/ngc/fceusupport.h @@ -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); diff --git a/source/ngc/filebrowser.cpp b/source/ngc/filebrowser.cpp index 32ef749..9700ebf 100644 --- a/source/ngc/filebrowser.cpp +++ b/source/ngc/filebrowser.cpp @@ -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); diff --git a/source/ngc/gui/gui.h b/source/ngc/gui/gui.h index 8718ee0..99c92a3 100644 --- a/source/ngc/gui/gui.h +++ b/source/ngc/gui/gui.h @@ -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); diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 21deaf6..f50fbc8 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -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; diff --git a/source/ngc/preferences.cpp b/source/ngc/preferences.cpp index 086855d..3b049a8 100644 --- a/source/ngc/preferences.cpp +++ b/source/ngc/preferences.cpp @@ -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