Skip to content

Commit cb53167

Browse files
committed
Various fixes. Allow global disabling of cheats.
1 parent 0d102b7 commit cb53167

File tree

8 files changed

+76
-12
lines changed

8 files changed

+76
-12
lines changed

cheats.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ struct SCheatGroup
217217
struct SCheatData
218218
{
219219
std::vector<struct SCheatGroup> g;
220+
bool8 enabled;
220221
uint8 CWRAM[0x20000];
221222
uint8 CSRAM[0x10000];
222223
uint8 CIRAM[0x2000];
@@ -269,6 +270,8 @@ bool8 S9xLoadCheatFile (const char *filename);
269270
bool8 S9xSaveCheatFile (const char *filename);
270271
void S9xUpdateCheatsInMemory (void);
271272
bool8 S9xImportCheatsFromDatabase (const char *filename);
273+
void S9xCheatsDisable (void);
274+
void S9xCheatsEnable (void);
272275

273276
void S9xInitCheatData (void);
274277
void S9xInitWatchedAddress (void);

cheats2.cpp

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,11 @@ void S9xDisableCheat (SCheat *c)
429429
if (!c->enabled)
430430
return;
431431

432-
S9xUpdateCheatInMemory (c);
433432
c->enabled = false;
434433

434+
if (!Cheat.enabled)
435+
return;
436+
435437
if (c->conditional && !c->cond_true)
436438
return;
437439

@@ -478,6 +480,10 @@ void S9xEnableCheat (SCheat *c)
478480
return;
479481

480482
c->enabled = true;
483+
484+
if (!Cheat.enabled)
485+
return;
486+
481487
byte = S9xGetByteFree(c->address);
482488

483489
if (c->conditional)
@@ -511,8 +517,8 @@ void S9xDisableCheatGroup (uint32 num)
511517
for (i = 0; i < Cheat.g[num].c.size (); i++)
512518
{
513519
S9xDisableCheat (&Cheat.g[num].c[i]);
514-
515520
}
521+
516522
Cheat.g[num].enabled = false;
517523
}
518524

@@ -650,6 +656,9 @@ void S9xUpdateCheatsInMemory (void)
650656
unsigned int i;
651657
unsigned int j;
652658

659+
if (!Cheat.enabled)
660+
return;
661+
653662
for (i = 0; i < Cheat.g.size (); i++)
654663
{
655664
for (j = 0; j < Cheat.g[i].c.size (); j++)
@@ -705,8 +714,6 @@ bool8 S9xLoadCheatFile (const char *filename)
705714
if (!bml)
706715
return FALSE;
707716

708-
S9xDeleteCheats ();
709-
710717
n = bml_find_sub (bml, "cartridge");
711718
if (n)
712719
{
@@ -724,7 +731,10 @@ bool8 S9xSaveCheatFile (const char *filename)
724731
FILE *file = NULL;
725732

726733
if (Cheat.g.size () == 0)
734+
{
735+
remove (filename);
727736
return TRUE;
737+
}
728738

729739
file = fopen (filename, "w");
730740

@@ -738,20 +748,62 @@ bool8 S9xSaveCheatFile (const char *filename)
738748

739749
for (i = 0; i < Cheat.g.size (); i++)
740750
{
751+
char *txt = S9xCheatGroupToText (i);
752+
741753
fprintf (file,
742754
" cheat%s\n"
743755
" description: %s\n"
744-
" code: %s\n\n",
756+
" code: %s\n",
745757
(Cheat.g[i].enabled ? " enabled" : ""),
746758
Cheat.g[i].name,
747-
S9xCheatGroupToText (i));
759+
txt);
760+
761+
delete[] txt;
748762
}
749763

750764
fclose (file);
751765

752766
return TRUE;
753767
}
754768

769+
void S9xCheatsDisable (void)
770+
{
771+
unsigned int i;
772+
773+
if (!Cheat.enabled)
774+
return;
775+
776+
for (i = 0; i < Cheat.g.size (); i++)
777+
{
778+
if (Cheat.g[i].enabled)
779+
{
780+
S9xDisableCheatGroup (i);
781+
Cheat.g[i].enabled = TRUE;
782+
}
783+
}
784+
785+
Cheat.enabled = FALSE;
786+
}
787+
788+
void S9xCheatsEnable (void)
789+
{
790+
unsigned int i;
791+
792+
if (Cheat.enabled)
793+
return;
794+
795+
Cheat.enabled = TRUE;
796+
797+
for (i = 0; i < Cheat.g.size (); i++)
798+
{
799+
if (Cheat.g[i].enabled)
800+
{
801+
Cheat.g[i].enabled = FALSE;
802+
S9xEnableCheatGroup (i);
803+
}
804+
}
805+
}
806+
755807
bool8 S9xImportCheatsFromDatabase (const char *filename)
756808
{
757809
bml_node *bml;

gtk/src/gtk_config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ Snes9xConfig::load_defaults (void)
217217
netplay_last_host [0] = '\0';
218218
netplay_last_port = 6096;
219219
modal_dialogs = 1;
220+
S9xCheatsEnable ();
220221

221222
rewind_granularity = 5;
222223
rewind_buffer_size = 0;

gtk/src/gtk_s9x.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ S9xOpenROM (const char *rom_filename)
195195
if (loaded)
196196
{
197197
Memory.LoadSRAM (S9xGetFilename (".srm", SRAM_DIR));
198+
S9xDeleteCheats ();
198199
S9xLoadCheatFile (S9xGetFilename (".cht", CHEAT_DIR));
199200
}
200201
else

memmap.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,8 +1787,6 @@ bool8 CMemory::LoadROMInt (int32 ROMfillSize)
17871787

17881788
S9xReset();
17891789

1790-
S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
1791-
17921790
return (TRUE);
17931791
}
17941792

@@ -1953,7 +1951,6 @@ bool8 CMemory::LoadMultiCartInt ()
19531951
S9xReset();
19541952

19551953
S9xInitCheatData();
1956-
S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
19571954

19581955
return (TRUE);
19591956
}

snes9x.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ void S9xLoadConfigFiles (char **argv, int argc)
386386
Settings.ForceInterleaved2 = conf.GetBool("ROM::Interleaved2", false);
387387
Settings.ForceInterleaveGD24 = conf.GetBool("ROM::InterleaveGD24", false);
388388
Settings.ApplyCheats = conf.GetBool("ROM::Cheat", false);
389+
Cheat.enabled = false;
389390
Settings.NoPatch = !conf.GetBool("ROM::Patch", true);
390391
Settings.IgnorePatchChecksum = conf.GetBool("ROM::IgnorePatchChecksum", false);
391392

@@ -785,6 +786,10 @@ char * S9xParseArgs (char **argv, int argc)
785786
{
786787
S9xMessage(S9X_ERROR, S9X_GAME_GENIE_CODE_ERROR, "Code format invalid");
787788
}
789+
else
790+
{
791+
S9xEnableCheatGroup (Cheat.g.size() - 1);
792+
}
788793
}
789794
else
790795
S9xUsage();

unix/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
OS = `uname -s -r -m|sed \"s/ /-/g\"|tr \"[A-Z]\" \"[a-z]\"|tr \"/()\" \"___\"`
99
BUILDDIR = .
1010

11-
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
11+
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
1212
DEFS = -DMITSHM
1313

1414
ifdef S9XDEBUGGER

unix/unix.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,8 @@ void S9xExit (void)
16191619
#endif
16201620

16211621
Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR));
1622-
S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
1622+
if (Settings.ApplyCheats)
1623+
S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
16231624
S9xResetSaveTimer(FALSE);
16241625

16251626
S9xUnmapAllControls();
@@ -1787,7 +1788,11 @@ int main (int argc, char **argv)
17871788

17881789
NSRTControllerSetup();
17891790
Memory.LoadSRAM(S9xGetFilename(".srm", SRAM_DIR));
1790-
S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
1791+
if (Settings.ApplyCheats)
1792+
{
1793+
S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
1794+
S9xCheatsEnable ();
1795+
}
17911796

17921797
CPU.Flags = saved_flags;
17931798
Settings.StopEmulation = FALSE;

0 commit comments

Comments
 (0)