Various fixes. Allow global disabling of cheats.

This commit is contained in:
Brandon Wright 2018-04-26 11:15:20 -05:00
parent 0d102b72ff
commit cb531670e5
8 changed files with 76 additions and 12 deletions

View File

@ -217,6 +217,7 @@ struct SCheatGroup
struct SCheatData
{
std::vector<struct SCheatGroup> g;
bool8 enabled;
uint8 CWRAM[0x20000];
uint8 CSRAM[0x10000];
uint8 CIRAM[0x2000];
@ -269,6 +270,8 @@ bool8 S9xLoadCheatFile (const char *filename);
bool8 S9xSaveCheatFile (const char *filename);
void S9xUpdateCheatsInMemory (void);
bool8 S9xImportCheatsFromDatabase (const char *filename);
void S9xCheatsDisable (void);
void S9xCheatsEnable (void);
void S9xInitCheatData (void);
void S9xInitWatchedAddress (void);

View File

@ -429,9 +429,11 @@ void S9xDisableCheat (SCheat *c)
if (!c->enabled)
return;
S9xUpdateCheatInMemory (c);
c->enabled = false;
if (!Cheat.enabled)
return;
if (c->conditional && !c->cond_true)
return;
@ -478,6 +480,10 @@ void S9xEnableCheat (SCheat *c)
return;
c->enabled = true;
if (!Cheat.enabled)
return;
byte = S9xGetByteFree(c->address);
if (c->conditional)
@ -511,8 +517,8 @@ void S9xDisableCheatGroup (uint32 num)
for (i = 0; i < Cheat.g[num].c.size (); i++)
{
S9xDisableCheat (&Cheat.g[num].c[i]);
}
Cheat.g[num].enabled = false;
}
@ -650,6 +656,9 @@ void S9xUpdateCheatsInMemory (void)
unsigned int i;
unsigned int j;
if (!Cheat.enabled)
return;
for (i = 0; i < Cheat.g.size (); i++)
{
for (j = 0; j < Cheat.g[i].c.size (); j++)
@ -705,8 +714,6 @@ bool8 S9xLoadCheatFile (const char *filename)
if (!bml)
return FALSE;
S9xDeleteCheats ();
n = bml_find_sub (bml, "cartridge");
if (n)
{
@ -724,7 +731,10 @@ bool8 S9xSaveCheatFile (const char *filename)
FILE *file = NULL;
if (Cheat.g.size () == 0)
{
remove (filename);
return TRUE;
}
file = fopen (filename, "w");
@ -738,13 +748,17 @@ bool8 S9xSaveCheatFile (const char *filename)
for (i = 0; i < Cheat.g.size (); i++)
{
char *txt = S9xCheatGroupToText (i);
fprintf (file,
" cheat%s\n"
" description: %s\n"
" code: %s\n\n",
" code: %s\n",
(Cheat.g[i].enabled ? " enabled" : ""),
Cheat.g[i].name,
S9xCheatGroupToText (i));
txt);
delete[] txt;
}
fclose (file);
@ -752,6 +766,44 @@ bool8 S9xSaveCheatFile (const char *filename)
return TRUE;
}
void S9xCheatsDisable (void)
{
unsigned int i;
if (!Cheat.enabled)
return;
for (i = 0; i < Cheat.g.size (); i++)
{
if (Cheat.g[i].enabled)
{
S9xDisableCheatGroup (i);
Cheat.g[i].enabled = TRUE;
}
}
Cheat.enabled = FALSE;
}
void S9xCheatsEnable (void)
{
unsigned int i;
if (Cheat.enabled)
return;
Cheat.enabled = TRUE;
for (i = 0; i < Cheat.g.size (); i++)
{
if (Cheat.g[i].enabled)
{
Cheat.g[i].enabled = FALSE;
S9xEnableCheatGroup (i);
}
}
}
bool8 S9xImportCheatsFromDatabase (const char *filename)
{
bml_node *bml;

View File

@ -217,6 +217,7 @@ Snes9xConfig::load_defaults (void)
netplay_last_host [0] = '\0';
netplay_last_port = 6096;
modal_dialogs = 1;
S9xCheatsEnable ();
rewind_granularity = 5;
rewind_buffer_size = 0;

View File

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

View File

@ -1787,8 +1787,6 @@ bool8 CMemory::LoadROMInt (int32 ROMfillSize)
S9xReset();
S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
return (TRUE);
}
@ -1953,7 +1951,6 @@ bool8 CMemory::LoadMultiCartInt ()
S9xReset();
S9xInitCheatData();
S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
return (TRUE);
}

View File

@ -386,6 +386,7 @@ void S9xLoadConfigFiles (char **argv, int argc)
Settings.ForceInterleaved2 = conf.GetBool("ROM::Interleaved2", false);
Settings.ForceInterleaveGD24 = conf.GetBool("ROM::InterleaveGD24", false);
Settings.ApplyCheats = conf.GetBool("ROM::Cheat", false);
Cheat.enabled = false;
Settings.NoPatch = !conf.GetBool("ROM::Patch", true);
Settings.IgnorePatchChecksum = conf.GetBool("ROM::IgnorePatchChecksum", false);
@ -785,6 +786,10 @@ char * S9xParseArgs (char **argv, int argc)
{
S9xMessage(S9X_ERROR, S9X_GAME_GENIE_CODE_ERROR, "Code format invalid");
}
else
{
S9xEnableCheatGroup (Cheat.g.size() - 1);
}
}
else
S9xUsage();

View File

@ -8,7 +8,7 @@
OS = `uname -s -r -m|sed \"s/ /-/g\"|tr \"[A-Z]\" \"[a-z]\"|tr \"/()\" \"___\"`
BUILDDIR = .
OBJECTS = ../apu/apu.o ../apu/bapu/dsp/sdsp.o ../apu/bapu/dsp/SPC_DSP.o ../apu/bapu/smp/smp.o ../apu/bapu/smp/smp_state.o ../bsx.o ../c4.o ../c4emu.o ../cheats.o ../cheats2.o ../clip.o ../conffile.o ../controls.o ../cpu.o ../cpuexec.o ../cpuops.o ../crosshairs.o ../dma.o ../dsp.o ../dsp1.o ../dsp2.o ../dsp3.o ../dsp4.o ../fxinst.o ../fxemu.o ../gfx.o ../globals.o ../logger.o ../memmap.o ../msu1.o ../movie.o ../obc1.o ../ppu.o ../stream.o ../sa1.o ../sa1cpu.o ../screenshot.o ../sdd1.o ../sdd1emu.o ../seta.o ../seta010.o ../seta011.o ../seta018.o ../snapshot.o ../snes9x.o ../spc7110.o ../srtc.o ../tile.o ../filter/2xsai.o ../filter/blit.o ../filter/epx.o ../filter/hq2x.o ../filter/snes_ntsc.o ../statemanager.o ../sha256.o unix.o x11.o
OBJECTS = ../apu/apu.o ../apu/bapu/dsp/sdsp.o ../apu/bapu/dsp/SPC_DSP.o ../apu/bapu/smp/smp.o ../apu/bapu/smp/smp_state.o ../bsx.o ../c4.o ../c4emu.o ../cheats.o ../cheats2.o ../clip.o ../conffile.o ../controls.o ../cpu.o ../cpuexec.o ../cpuops.o ../crosshairs.o ../dma.o ../dsp.o ../dsp1.o ../dsp2.o ../dsp3.o ../dsp4.o ../fxinst.o ../fxemu.o ../gfx.o ../globals.o ../logger.o ../memmap.o ../msu1.o ../movie.o ../obc1.o ../ppu.o ../stream.o ../sa1.o ../sa1cpu.o ../screenshot.o ../sdd1.o ../sdd1emu.o ../seta.o ../seta010.o ../seta011.o ../seta018.o ../snapshot.o ../snes9x.o ../spc7110.o ../srtc.o ../tile.o ../filter/2xsai.o ../filter/blit.o ../filter/epx.o ../filter/hq2x.o ../filter/snes_ntsc.o ../statemanager.o ../sha256.o ../bml.o unix.o x11.o
DEFS = -DMITSHM
ifdef S9XDEBUGGER

View File

@ -1619,7 +1619,8 @@ void S9xExit (void)
#endif
Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR));
S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
if (Settings.ApplyCheats)
S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
S9xResetSaveTimer(FALSE);
S9xUnmapAllControls();
@ -1787,7 +1788,11 @@ int main (int argc, char **argv)
NSRTControllerSetup();
Memory.LoadSRAM(S9xGetFilename(".srm", SRAM_DIR));
S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
if (Settings.ApplyCheats)
{
S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
S9xCheatsEnable ();
}
CPU.Flags = saved_flags;
Settings.StopEmulation = FALSE;