diff --git a/src/gba/cheats.c b/src/gba/cheats.c index 6e799aae4..b17244c76 100644 --- a/src/gba/cheats.c +++ b/src/gba/cheats.c @@ -150,26 +150,26 @@ static bool GBACheatAddAutodetect(struct GBACheatSet* set, uint32_t op1, uint32_ o2 = op2; if (gsaP > maxProbability) { maxProbability = gsaP; - GBACheatSetGameSharkVersion(set, 1); + GBACheatSetGameSharkVersion(set, GBA_GS_GSAV1); } GBACheatDecryptGameShark(&o1, &o2, GBACheatProActionReplaySeeds); parP = GBACheatProActionReplayProbability(o1, o2); if (parP > maxProbability) { maxProbability = parP; - GBACheatSetGameSharkVersion(set, 3); + GBACheatSetGameSharkVersion(set, GBA_GS_PARV3); } rgsaP = GBACheatGameSharkProbability(op1, op1); if (rgsaP > maxProbability) { maxProbability = rgsaP; - GBACheatSetGameSharkVersion(set, 2); + GBACheatSetGameSharkVersion(set, GBA_GS_GSAV1_RAW); } rparP = GBACheatProActionReplayProbability(op1, op1); if (rparP > maxProbability) { maxProbability = rparP; - GBACheatSetGameSharkVersion(set, 4); + GBACheatSetGameSharkVersion(set, GBA_GS_PARV3_RAW); } if (set->gsaVersion < 3) { @@ -304,19 +304,19 @@ static void GBACheatParseDirectives(struct mCheatSet* set, const struct StringLi for (d = 0; d < StringListSize(directives); ++d) { const char* directive = *StringListGetConstPointer(directives, d); if (strcmp(directive, "GSAv1") == 0) { - GBACheatSetGameSharkVersion(cheats, 1); + GBACheatSetGameSharkVersion(cheats, GBA_GS_GSAV1); continue; } if (strcmp(directive, "GSAv1 raw") == 0) { - GBACheatSetGameSharkVersion(cheats, 2); + GBACheatSetGameSharkVersion(cheats, GBA_GS_GSAV1_RAW); continue; } if (strcmp(directive, "PARv3") == 0) { - GBACheatSetGameSharkVersion(cheats, 3); + GBACheatSetGameSharkVersion(cheats, GBA_GS_PARV3); continue; } if (strcmp(directive, "PARv3 raw") == 0) { - GBACheatSetGameSharkVersion(cheats, 4); + GBACheatSetGameSharkVersion(cheats, GBA_GS_PARV3_RAW); continue; } } diff --git a/src/gba/cheats/gameshark.c b/src/gba/cheats/gameshark.c index 0c4270ee6..e95b23b54 100644 --- a/src/gba/cheats/gameshark.c +++ b/src/gba/cheats/gameshark.c @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include +#include "gba/cheats/gameshark.h" #include "gba/cheats/parv3.h" #include #include @@ -73,17 +74,19 @@ void GBACheatReseedGameShark(uint32_t* seeds, uint16_t params, const uint8_t* t1 } } -void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, int version) { +void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, enum GBACheatGameSharkVersion version) { cheats->gsaVersion = version; switch (version) { - case 1: - case 2: + case GBA_GS_GSAV1: + case GBA_GS_GSAV1_RAW: memcpy(cheats->gsaSeeds, GBACheatGameSharkSeeds, 4 * sizeof(uint32_t)); break; - case 3: - case 4: + case GBA_GS_PARV3: + case GBA_GS_PARV3_RAW: memcpy(cheats->gsaSeeds, GBACheatProActionReplaySeeds, 4 * sizeof(uint32_t)); break; + default: + break; } } @@ -197,15 +200,13 @@ bool GBACheatAddGameShark(struct GBACheatSet* set, uint32_t op1, uint32_t op2) { snprintf(line, sizeof(line), "%08X %08X", op1, op2); switch (set->gsaVersion) { - case 0: - case 3: - case 4: - GBACheatSetGameSharkVersion(set, 1); + default: + GBACheatSetGameSharkVersion(set, GBA_GS_GSAV1); // Fall through - case 1: + case GBA_GS_GSAV1: GBACheatDecryptGameShark(&o1, &o2, set->gsaSeeds); // Fall through - case 2: + case GBA_GS_GSAV1_RAW: return GBACheatAddGameSharkRaw(set, o1, o2); } return false; diff --git a/src/gba/cheats/gameshark.h b/src/gba/cheats/gameshark.h index af4d10469..a4130714b 100644 --- a/src/gba/cheats/gameshark.h +++ b/src/gba/cheats/gameshark.h @@ -12,10 +12,18 @@ CXX_GUARD_START extern const uint32_t GBACheatGameSharkSeeds[4]; +enum GBACheatGameSharkVersion { + GBA_GS_NOT_SET = 0, + GBA_GS_GSAV1 = 1, + GBA_GS_GSAV1_RAW = 2, + GBA_GS_PARV3 = 3, + GBA_GS_PARV3_RAW = 4 +}; + struct GBACheatSet; void GBACheatDecryptGameShark(uint32_t* op1, uint32_t* op2, const uint32_t* seeds); void GBACheatReseedGameShark(uint32_t* seeds, uint16_t params, const uint8_t* t1, const uint8_t* t2); -void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, int version); +void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, enum GBACheatGameSharkVersion version); bool GBACheatAddGameSharkRaw(struct GBACheatSet* cheats, uint32_t op1, uint32_t op2); int GBACheatGameSharkProbability(uint32_t op1, uint32_t op2); diff --git a/src/gba/cheats/parv3.c b/src/gba/cheats/parv3.c index 71bd31c15..d2c9df589 100644 --- a/src/gba/cheats/parv3.c +++ b/src/gba/cheats/parv3.c @@ -301,15 +301,13 @@ bool GBACheatAddProActionReplay(struct GBACheatSet* set, uint32_t op1, uint32_t snprintf(line, sizeof(line), "%08X %08X", op1, op2); switch (set->gsaVersion) { - case 0: - case 1: - case 2: - GBACheatSetGameSharkVersion(set, 3); + default: + GBACheatSetGameSharkVersion(set, GBA_GS_PARV3); // Fall through - case 3: + case GBA_GS_PARV3: GBACheatDecryptGameShark(&o1, &o2, set->gsaSeeds); // Fall through - case 4: + case GBA_GS_PARV3_RAW: return GBACheatAddProActionReplayRaw(set, o1, o2); } return false;