From 2c843d964027089a747453afc0b07d0eac5835d9 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 23 Jul 2012 00:29:46 +0300 Subject: cheat: add some undo logic --- libpcsxcore/cheat.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'libpcsxcore/cheat.c') 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; -- cgit v1.2.3