GBA Cheats: Use an enum for GSA versions

This commit is contained in:
Vicki Pfau 2017-09-29 22:25:51 -07:00
parent 3d39e2a041
commit 845ecfe81e
4 changed files with 33 additions and 26 deletions

View File

@ -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;
}
}

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <mgba/internal/gba/cheats.h>
#include "gba/cheats/gameshark.h"
#include "gba/cheats/parv3.h"
#include <mgba/internal/gba/gba.h>
#include <mgba-util/string.h>
@ -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;

View File

@ -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);

View File

@ -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;