From 1e55157a6e5a9e1a9b22a054acfce41682c97739 Mon Sep 17 00:00:00 2001 From: Daryl Borth Date: Sun, 12 Aug 2018 16:36:31 -0600 Subject: [PATCH] fix cheats not working --- source/cheatmgr.cpp | 23 ++++++++++++++++++----- source/menu.cpp | 6 ++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/source/cheatmgr.cpp b/source/cheatmgr.cpp index 5f181a4..36f94b1 100644 --- a/source/cheatmgr.cpp +++ b/source/cheatmgr.cpp @@ -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; diff --git a/source/menu.cpp b/source/menu.cpp index 06ae6d1..f12eb8b 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -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(); }