X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fcheat.c;h=a016aeec8820e7533da6a1f1377b87784f018440;hb=HEAD;hp=9ce7ed8dd21f6ba2e6d5d62425033b777f87f99c;hpb=9c27c2051287b235fe0dba18a74b3863a3062646;p=pcsx_rearmed.git diff --git a/libpcsxcore/cheat.c b/libpcsxcore/cheat.c index 9ce7ed8d..2727fd23 100644 --- a/libpcsxcore/cheat.c +++ b/libpcsxcore/cheat.c @@ -19,6 +19,8 @@ #include "psxcommon.h" #include "r3000a.h" #include "psxmem.h" +#include "misc.h" +#include "../frontend/plugin_lib.h" // in_keystate for D4 #include "cheat.h" @@ -108,6 +110,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 +185,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 +204,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; @@ -206,6 +229,10 @@ void ApplyCheats() { psxMu16ref(addr) = SWAPu16(val); break; + case CHEAT_SCRATCHPAD16: // 1F + psxHs16ref(addr) = SWAPu16(val); + break; + case CHEAT_INC16: psxMu16ref(addr) = SWAPu16(psxMu16(addr) + val); break; @@ -297,6 +324,20 @@ void ApplyCheats() { if (PSXMu16(addr) <= val) j++; // skip the next code break; + + case CHEAT_BUTTONS1_16: { // D4 + u16 keys = in_keystate[0]; + keys = (keys << 8) | (keys >> 8); + if (keys != val) + j++; // skip the next code + break; + } + + default: + SysPrintf("unhandled cheat %d,%d code %08X\n", + i, j, CheatCodes[j].Addr); + Cheats[i].WasEnabled = Cheats[i].Enabled = 0; + break; } } } @@ -319,8 +360,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; @@ -328,7 +369,7 @@ int AddCheat(const char *descr, char *code) { p2 = code; while (c) { - unsigned int t1, t2; + unsigned int t1, t2, r; while (*p2 != '\n' && *p2 != '\0') p2++; @@ -341,9 +382,11 @@ int AddCheat(const char *descr, char *code) { t1 = 0; t2 = 0; - sscanf(p1, "%x %x", &t1, &t2); + r = sscanf(p1, "%x %x", &t1, &t2); - if (t1 > 0x10000000) { + if (r != 2) + SysPrintf("cheat %d: couldn't parse '%s'\n", NumCodes, p1); + else if (t1 >= 0x10000000) { if (NumCodes >= NumCodesAllocated) { NumCodesAllocated += ALLOC_INCREMENT; @@ -370,6 +413,7 @@ int AddCheat(const char *descr, char *code) { return -1; } + Cheats[NumCheats].Descr = strdup(descr[0] ? descr : _("(Untitled)")); NumCheats++; return 0; } @@ -378,6 +422,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];