X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fcheat.c;h=a016aeec8820e7533da6a1f1377b87784f018440;hb=HEAD;hp=21d88b8e628d1644f2051de64b5f38aa0faf821b;hpb=ef79bbde537d6b9c745a7d86cb9df1d04c35590d;p=pcsx_rearmed.git diff --git a/libpcsxcore/cheat.c b/libpcsxcore/cheat.c index 21d88b8e..2727fd23 100644 --- a/libpcsxcore/cheat.c +++ b/libpcsxcore/cheat.c @@ -19,16 +19,18 @@ #include "psxcommon.h" #include "r3000a.h" #include "psxmem.h" +#include "misc.h" +#include "../frontend/plugin_lib.h" // in_keystate for D4 #include "cheat.h" Cheat *Cheats = NULL; int NumCheats = 0; -static int NumCheatsAllocated = 0; +int NumCheatsAllocated = 0; CheatCode *CheatCodes = NULL; int NumCodes = 0; -static int NumCodesAllocated = 0; +int NumCodesAllocated = 0; s8 *prevM = NULL; u32 *SearchResults = NULL; @@ -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];