X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fcheat.c;h=e0cf411e081b6a5c0cf54299ffbd0b42830df271;hb=65722e0455a2a42eece5e67ce2e92bfac03e1368;hp=9ce7ed8dd21f6ba2e6d5d62425033b777f87f99c;hpb=9c27c2051287b235fe0dba18a74b3863a3062646;p=pcsx_rearmed.git diff --git a/libpcsxcore/cheat.c b/libpcsxcore/cheat.c index 9ce7ed8d..e0cf411e 100644 --- a/libpcsxcore/cheat.c +++ b/libpcsxcore/cheat.c @@ -19,6 +19,7 @@ #include "psxcommon.h" #include "r3000a.h" #include "psxmem.h" +#include "misc.h" #include "cheat.h" @@ -108,6 +109,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 +184,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 +203,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; @@ -319,8 +341,8 @@ 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; @@ -370,6 +392,7 @@ int AddCheat(const char *descr, char *code) { return -1; } + Cheats[NumCheats].Descr = strdup(descr[0] ? descr : _("(Untitled)")); NumCheats++; return 0; } @@ -378,6 +401,7 @@ void RemoveCheat(int index) { assert(index >= 0 && index < NumCheats); free(Cheats[index].Descr); + Cheats[index].Descr = NULL; while (index < NumCheats - 1) { Cheats[index] = Cheats[index + 1];