diff --git a/cheats2.cpp b/cheats2.cpp index 4809ef32..1ec688fb 100644 --- a/cheats2.cpp +++ b/cheats2.cpp @@ -744,6 +744,8 @@ static void S9xLoadCheatsFromBMLNode (bml_node *n) tmp = bml_find_sub(c, "description"); desc = tmp->data; + if (!desc) + desc = (char *) ""; tmp = bml_find_sub(c, "code"); code = tmp->data; @@ -751,7 +753,7 @@ static void S9xLoadCheatsFromBMLNode (bml_node *n) if (bml_find_sub(c, "enabled")) enabled = true; - if (desc && code && !S9xCheatIsDuplicate (desc, code)) + if (code && !S9xCheatIsDuplicate (desc, code)) { int index = S9xAddCheatGroup (desc, code); @@ -773,8 +775,6 @@ bool8 S9xLoadCheatFileClassic (const char *filename) if (!fs) return (FALSE); - S9xDeleteCheats (); - while (fread ((void *) data, 1, 28, fs) == 28) { SCheat c; @@ -855,7 +855,7 @@ bool8 S9xSaveCheatFile (const char *filename) " description: %s\n" " code: %s\n", (Cheat.g[i].enabled ? " enabled" : ""), - Cheat.g[i].name, + (Cheat.g[i].name ? Cheat.g[i].name : ""), txt); delete[] txt; diff --git a/display.h b/display.h index ad508300..014e0b6f 100644 --- a/display.h +++ b/display.h @@ -215,6 +215,7 @@ enum s9x_getdirtype void S9xUsage (void); char * S9xParseArgs (char **, int); +void S9xParseArgsForCheats (char **, int); void S9xLoadConfigFiles (char **, int); void S9xSetInfoString (const char *); diff --git a/gtk/src/gtk_s9x.cpp b/gtk/src/gtk_s9x.cpp index 5300cfd6..be14a751 100644 --- a/gtk/src/gtk_s9x.cpp +++ b/gtk/src/gtk_s9x.cpp @@ -195,8 +195,6 @@ S9xOpenROM (const char *rom_filename) if (loaded) { Memory.LoadSRAM (S9xGetFilename (".srm", SRAM_DIR)); - S9xDeleteCheats (); - S9xLoadCheatFile (S9xGetFilename (".cht", CHEAT_DIR)); } else { diff --git a/memmap.cpp b/memmap.cpp index a522179a..b3903422 100644 --- a/memmap.cpp +++ b/memmap.cpp @@ -1787,6 +1787,7 @@ bool8 CMemory::LoadROMInt (int32 ROMfillSize) S9xReset(); + S9xDeleteCheats(); S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR)); return (TRUE); @@ -1952,6 +1953,7 @@ bool8 CMemory::LoadMultiCartInt () S9xReset(); + S9xDeleteCheats(); S9xInitCheatData(); S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR)); diff --git a/snes9x.cpp b/snes9x.cpp index 33ac9640..080d166a 100644 --- a/snes9x.cpp +++ b/snes9x.cpp @@ -584,9 +584,8 @@ void S9xUsage (void) // PATCH/CHEAT OPTIONS S9xMessage(S9X_INFO, S9X_USAGE, "-nopatch Do not apply any available IPS/UPS patches"); S9xMessage(S9X_INFO, S9X_USAGE, "-cheat Apply saved cheats"); - S9xMessage(S9X_INFO, S9X_USAGE, "-gamegenie Supply a Game Genie code"); - S9xMessage(S9X_INFO, S9X_USAGE, "-actionreplay Supply a Pro-Action Reply code"); - S9xMessage(S9X_INFO, S9X_USAGE, "-goldfinger Supply a Gold Finger code"); + S9xMessage(S9X_INFO, S9X_USAGE, "-cheatcode Supply a cheat code in Game Genie,"); + S9xMessage(S9X_INFO, S9X_USAGE, " Pro-Action Replay, or Raw format (address=byte)"); S9xMessage(S9X_INFO, S9X_USAGE, ""); #ifdef NETPLAY_SUPPORT @@ -625,6 +624,31 @@ void S9xUsage (void) exit(1); } +void S9xParseArgsForCheats (char **argv, int argc) +{ + for (int i = 1; i < argc; i++) + { + if (!strcasecmp(argv[i], "-gamegenie") || + !strcasecmp(argv[i], "-actionreplay") || + !strcasecmp(argv[i], "-cheatcode")) + { + if (i + 1 < argc) + { + if (S9xAddCheatGroup ("Unknown", argv[++i]) < 0) + { + S9xMessage(S9X_ERROR, S9X_GAME_GENIE_CODE_ERROR, "Code format invalid"); + } + else + { + S9xEnableCheatGroup (Cheat.g.size() - 1); + } + } + else + S9xUsage(); + } + } +} + char * S9xParseArgs (char **argv, int argc) { for (int i = 1; i < argc; i++) @@ -778,7 +802,9 @@ char * S9xParseArgs (char **argv, int argc) if (!strcasecmp(argv[i], "-cheat")) Settings.ApplyCheats = TRUE; else - if (!strcasecmp(argv[i], "-gamegenie") || !strcasecmp(argv[i], "-actionreplay")) + if (!strcasecmp(argv[i], "-gamegenie") || + !strcasecmp(argv[i], "-actionreplay") || + !strcasecmp(argv[i], "-cheatcode")) { if (i + 1 < argc) { @@ -795,7 +821,6 @@ char * S9xParseArgs (char **argv, int argc) S9xUsage(); } else - // NETPLAY OPTIONS #ifdef NETPLAY_SUPPORT diff --git a/unix/unix.cpp b/unix/unix.cpp index 380c028d..b9ff0b52 100644 --- a/unix/unix.cpp +++ b/unix/unix.cpp @@ -1619,10 +1619,8 @@ void S9xExit (void) #endif Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR)); - if (Settings.ApplyCheats) - S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR)); S9xResetSaveTimer(FALSE); - + S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR)); S9xUnmapAllControls(); S9xDeinitDisplay(); Memory.Deinit(); @@ -1699,6 +1697,7 @@ int main (int argc, char **argv) S9xLoadConfigFiles(argv, argc); rom_filename = S9xParseArgs(argv, argc); + S9xDeleteCheats(); make_snes9x_dirs(); @@ -1786,14 +1785,18 @@ int main (int argc, char **argv) exit(1); } + S9xDeleteCheats(); + S9xCheatsEnable(); NSRTControllerSetup(); Memory.LoadSRAM(S9xGetFilename(".srm", SRAM_DIR)); + if (Settings.ApplyCheats) { S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR)); - S9xCheatsEnable (); } + S9xParseArgsForCheats(argv, argc); + CPU.Flags = saved_flags; Settings.StopEmulation = FALSE;