fix cheats not working

This commit is contained in:
Daryl Borth 2018-08-12 16:36:31 -06:00
parent a9f851a19f
commit 1e55157a6e
2 changed files with 20 additions and 9 deletions

View File

@ -32,8 +32,7 @@ static bool LoadCheatFile (int length)
uint8 data [28];
int offset = 0;
while (offset < length)
{
while (offset < length) {
if(Cheat.g.size() >= MAX_CHEATS || (length - offset) < 28)
break;
@ -43,7 +42,6 @@ static bool LoadCheatFile (int length)
SCheat c;
char name[21];
char cheat[10];
c.enabled = (data[0] & 4) == 0;
c.byte = data[1];
c.address = data[2] | (data[3] << 8) | (data[4] << 16);
memcpy (name, &data[8], 20);
@ -55,6 +53,23 @@ static bool LoadCheatFile (int length)
return true;
}
void ToggleCheat(uint32 num) {
if(Cheat.g[num].enabled) {
S9xDisableCheatGroup(num);
}
else {
S9xEnableCheatGroup(num);
}
for(int i=0; i < Cheat.g.size(); i++) {
if(Cheat.g[i].enabled) {
Cheat.enabled = TRUE;
return;
}
}
Cheat.enabled = FALSE;
}
/****************************************************************************
* SetupCheats
*
@ -64,8 +79,6 @@ static bool LoadCheatFile (int length)
void
WiiSetupCheats()
{
S9xDeleteCheats();
char filepath[1024];
int offset = 0;

View File

@ -44,6 +44,7 @@
#include "snes9x/cheats.h"
extern SCheatData Cheat;
extern void ToggleCheat(uint32);
#define THREAD_SLEEP 100
@ -2148,10 +2149,7 @@ static int MenuGameCheats()
if(ret >= 0)
{
if(Cheat.g[ret].enabled)
S9xDisableCheatGroup(ret);
else
S9xEnableCheatGroup(ret);
ToggleCheat(ret);
sprintf (options.value[ret], "%s", Cheat.g[ret].enabled == true ? "On" : "Off");
optionBrowser.TriggerUpdate();
}