all repos — mgba @ 8ee270f3f6b5d7e09fef98a374f37bbae947f4d2

mGBA Game Boy Advance Emulator

GB Serialize: Fix game title check
Vicki Pfau vi@endrift.com
Sat, 19 Aug 2017 12:01:04 -0700
commit

8ee270f3f6b5d7e09fef98a374f37bbae947f4d2

parent

ce07344c7d87d8759fee16a64df78c516ee599bc

2 files changed, 9 insertions(+), 4 deletions(-)

jump to
M CHANGESCHANGES

@@ -33,6 +33,7 @@ - ARM: Fix MSR when T bit is set

- GB Video: Fix potential hang when ending mode 0 - GB Memory: Fix HDMA count starting in mode 0 (fixes mgba.io/i/855) - GB Memory: Actually load latch time from savestate + - GB Serialize: Fix game title check Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
M src/gb/serialize.csrc/gb/serialize.c

@@ -23,7 +23,7 @@ STORE_32LE(gb->romCrc32, 0, &state->romCrc32);

STORE_32LE(gb->timing.masterCycles, 0, &state->masterCycles); if (gb->memory.rom) { - memcpy(state->title, ((struct GBCartridge*) gb->memory.rom)->titleLong, sizeof(state->title)); + memcpy(state->title, ((struct GBCartridge*) &gb->memory.rom[0x100])->titleLong, sizeof(state->title)); } else { memset(state->title, 0, sizeof(state->title)); }

@@ -86,9 +86,13 @@ mLOG(GB_STATE, WARN, "Old savestate: expected %08X, got %08X, continuing anyway", GB_SAVESTATE_MAGIC + GB_SAVESTATE_VERSION, ucheck);

} bool canSgb = ucheck >= GB_SAVESTATE_MAGIC + 2; - if (gb->memory.rom && memcmp(state->title, ((struct GBCartridge*) gb->memory.rom)->titleLong, sizeof(state->title))) { - mLOG(GB_STATE, WARN, "Savestate is for a different game"); - error = true; + if (gb->memory.rom && memcmp(state->title, ((struct GBCartridge*) &gb->memory.rom[0x100])->titleLong, sizeof(state->title))) { + LOAD_32LE(ucheck, 0, &state->versionMagic); + if (ucheck > GB_SAVESTATE_MAGIC + 2 || memcmp(state->title, ((struct GBCartridge*) gb->memory.rom)->titleLong, sizeof(state->title))) { + // There was a bug in previous versions where the memory address being compared was wrong + mLOG(GB_STATE, WARN, "Savestate is for a different game"); + error = true; + } } LOAD_32LE(ucheck, 0, &state->romCrc32); if (ucheck != gb->romCrc32) {