Cheat: Add raw format and multiline cheat support

- Add handling raw cheat formats
Fix https://github.com/libretro/libretro-fceumm/issues/378

- Add multiline cheat support
This commit is contained in:
negativeExponent
2020-08-31 10:37:59 +08:00
parent 0b3c232f6a
commit 3e50be9cb9

View File

@@ -1966,25 +1966,45 @@ void retro_cheat_reset(void)
void retro_cheat_set(unsigned index, bool enabled, const char *code) void retro_cheat_set(unsigned index, bool enabled, const char *code)
{ {
char name[256]; char name[256];
char temp[256];
char *codepart;
uint16 a; uint16 a;
uint8 v; uint8 v;
int c; int c;
int type = 1; int type = 1;
int ret = 0;
if (code == NULL)
return;
sprintf(name, "N/A"); sprintf(name, "N/A");
strcpy(temp, code);
codepart = strtok(temp, "+,;._ ");
if (FCEUI_DecodeGG(code, &a, &v, &c)) while (codepart)
goto input_cheat; {
if ((strlen(codepart) == 7) && (codepart[4]==':'))
/* Not a Game Genie code. */ {
/* raw code format */
if (FCEUI_DecodePAR(code, &a, &v, &c, &type)) c = -1;
goto input_cheat; codepart[4] = '\0';
a = strtoul(codepart, NULL, 16);
/* Not a Pro Action Replay code. */ v = strtoul(codepart + 5, NULL, 16);
FCEUI_AddCheat(name, a, v, c, type);
return; log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (Raw)\n", codepart);
input_cheat: }
FCEUI_AddCheat(name, a, v, c, type); else if (FCEUI_DecodeGG(codepart, &a, &v, &c))
{
FCEUI_AddCheat(name, a, v, c, type);
log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (GG)\n", codepart);
}
else if (FCEUI_DecodePAR(codepart, &a, &v, &c, &type))
{
FCEUI_AddCheat(name, a, v, c, type);
log_cb.log(RETRO_LOG_DEBUG, "Cheat code added: '%s' (PAR)\n", codepart);
}
codepart = strtok(NULL,"+,;._ ");
}
} }
typedef struct cartridge_db typedef struct cartridge_db