Fix a couple bugs. Change cheats on unix to work like they used to.

This commit is contained in:
Brandon Wright 2018-04-30 16:44:17 -05:00
parent 831176983a
commit e69fd7c50e
6 changed files with 44 additions and 15 deletions

View File

@ -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;

View File

@ -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 *);

View File

@ -195,8 +195,6 @@ S9xOpenROM (const char *rom_filename)
if (loaded)
{
Memory.LoadSRAM (S9xGetFilename (".srm", SRAM_DIR));
S9xDeleteCheats ();
S9xLoadCheatFile (S9xGetFilename (".cht", CHEAT_DIR));
}
else
{

View File

@ -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));

View File

@ -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 <code> Supply a Game Genie code");
S9xMessage(S9X_INFO, S9X_USAGE, "-actionreplay <code> Supply a Pro-Action Reply code");
S9xMessage(S9X_INFO, S9X_USAGE, "-goldfinger <code> Supply a Gold Finger code");
S9xMessage(S9X_INFO, S9X_USAGE, "-cheatcode <code> 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

View File

@ -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;