diff options
author | notaz | 2012-07-23 00:29:46 +0300 |
---|---|---|
committer | notaz | 2012-07-23 00:29:46 +0300 |
commit | 2c843d964027089a747453afc0b07d0eac5835d9 (patch) | |
tree | 50cff87de84f7a4cd5dc79ed3e31eae8c64228fa | |
parent | 9c27c2051287b235fe0dba18a74b3863a3062646 (diff) | |
download | pcsx_rearmed-2c843d964027089a747453afc0b07d0eac5835d9.tar.gz pcsx_rearmed-2c843d964027089a747453afc0b07d0eac5835d9.tar.bz2 pcsx_rearmed-2c843d964027089a747453afc0b07d0eac5835d9.zip |
cheat: add some undo logic
-rw-r--r-- | frontend/main.c | 1 | ||||
-rw-r--r-- | libpcsxcore/cheat.c | 24 | ||||
-rw-r--r-- | libpcsxcore/cheat.h | 2 |
3 files changed, 26 insertions, 1 deletions
diff --git a/frontend/main.c b/frontend/main.c index 9d3cc33..15eae71 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 9ce7ed8..a016aee 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 c533b93..b3d8bc4 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(); |