Cheats: Add check for valid game genie code format

- Partially reverts changes in 0b362afcc0
- Checks the codestring if its a valid game genie code before attempting
  to decode it. If code fails, then assume it to be a pro action replay
cheat.

Issue: Cheats where failing because a value of 0 in the decoder does not
mean an error.

Fix https://github.com/libretro/libretro-fceumm/issues/384
This commit is contained in:
negativeExponent
2020-09-09 11:33:36 +08:00
parent 96744ba2ab
commit f4ef507222
2 changed files with 28 additions and 10 deletions

View File

@@ -332,33 +332,27 @@ int FCEUI_DecodeGG(const char *str, uint16 *a, uint8 *v, int *c) {
if (s != 6 && s != 8) return(0);
t = GGtobin(*str++);
if (!t) return (0);
V |= (t & 0x07);
V |= (t & 0x08) << 4;
t = GGtobin(*str++);
if (!t) return (0);
V |= (t & 0x07) << 4;
A |= (t & 0x08) << 4;
t = GGtobin(*str++);
if (!t) return (0);
A |= (t & 0x07) << 4;
/* if(t&0x08) return(0); */ /* 8-character code?! */
t = GGtobin(*str++);
if (!t) return (0);
A |= (t & 0x07) << 12;
A |= (t & 0x08);
t = GGtobin(*str++);
if (!t) return (0);
A |= (t & 0x07);
A |= (t & 0x08) << 8;
if (s == 6) {
t = GGtobin(*str++);
if (!t) return (0);
A |= (t & 0x07) << 8;
V |= (t & 0x08);
@@ -368,17 +362,14 @@ int FCEUI_DecodeGG(const char *str, uint16 *a, uint8 *v, int *c) {
return(1);
} else {
t = GGtobin(*str++);
if (!t) return (0);
A |= (t & 0x07) << 8;
C |= (t & 0x08);
t = GGtobin(*str++);
if (!t) return (0);
C |= (t & 0x07);
C |= (t & 0x08) << 4;
t = GGtobin(*str++);
if (!t) return (0);
C |= (t & 0x07) << 4;
V |= (t & 0x08);
*a = A;