From: notaz Date: Sun, 22 Jul 2012 21:29:46 +0000 (+0300) Subject: cheat: add some undo logic X-Git-Tag: r15~16 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c843d964027089a747453afc0b07d0eac5835d9;p=pcsx_rearmed.git cheat: add some undo logic --- diff --git a/frontend/main.c b/frontend/main.c index 9d3cc333..15eae716 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -342,6 +342,7 @@ static void parse_cwcheat(void) } Cheats[NumCheats].Descr = strdup(name); Cheats[NumCheats].Enabled = 0; + Cheats[NumCheats].WasEnabled = 0; Cheats[NumCheats].First = NumCodes; Cheats[NumCheats].n = 0; NumCheats++; diff --git a/libpcsxcore/cheat.c b/libpcsxcore/cheat.c index 9ce7ed8d..a016aeec 100644 --- a/libpcsxcore/cheat.c +++ b/libpcsxcore/cheat.c @@ -108,6 +108,7 @@ void LoadCheats(const char *filename) { Cheats[NumCheats].Descr = strdup(buf + 1); Cheats[NumCheats].Enabled = 0; } + Cheats[NumCheats].WasEnabled = 0; Cheats[NumCheats].First = NumCodes; @@ -182,11 +183,15 @@ void SaveCheats(const char *filename) { // apply all enabled cheats void ApplyCheats() { int i, j, k, endindex; + int was_enabled; for (i = 0; i < NumCheats; i++) { + was_enabled = Cheats[i].WasEnabled; if (!Cheats[i].Enabled) { - continue; + if (!Cheats[i].WasEnabled) + continue; } + Cheats[i].WasEnabled = Cheats[i].Enabled; // process all cheat codes endindex = Cheats[i].First + Cheats[i].n; @@ -197,6 +202,22 @@ void ApplyCheats() { u16 val = CheatCodes[j].Val; u32 taddr; + if (!was_enabled) { + switch (type) { + case CHEAT_CONST16: + CheatCodes[j].OldVal = psxMu16(addr); + break; + case CHEAT_CONST8: + CheatCodes[j].OldVal = psxMu8(addr); + break; + } + } + else if (!Cheats[i].Enabled) { + val = CheatCodes[j].OldVal; + if (type != CHEAT_CONST16 && type != CHEAT_CONST8) + continue; + } + switch (type) { case CHEAT_CONST8: psxMu8ref(addr) = (u8)val; @@ -321,6 +342,7 @@ int AddCheat(const char *descr, char *code) { Cheats[NumCheats].Descr = strdup(descr[0] ? descr : _("(Untitled)")); Cheats[NumCheats].Enabled = 0; + Cheats[NumCheats].WasEnabled = 0; Cheats[NumCheats].First = NumCodes; Cheats[NumCheats].n = 0; diff --git a/libpcsxcore/cheat.h b/libpcsxcore/cheat.h index c533b93f..b3d8bc4a 100644 --- a/libpcsxcore/cheat.h +++ b/libpcsxcore/cheat.h @@ -26,6 +26,7 @@ extern "C" { typedef struct { uint32_t Addr; uint16_t Val; + uint16_t OldVal; } CheatCode; typedef struct { @@ -33,6 +34,7 @@ typedef struct { int First; // index of the first cheat code int n; // number of cheat codes for this cheat int Enabled; + int WasEnabled; } Cheat; void ClearAllCheats();