GB: Fix applying a patch that changes the cartridge mapper (fixes #3077)

This commit is contained in:
Vicki Pfau 2023-12-11 22:05:55 -08:00
parent 256143944a
commit 3a5642fcb8
2 changed files with 10 additions and 0 deletions

View File

@ -26,6 +26,7 @@ Emulation fixes:
Other fixes: Other fixes:
- Core: Fix inconsistencies with setting game-specific overrides (fixes mgba.io/i/2963) - Core: Fix inconsistencies with setting game-specific overrides (fixes mgba.io/i/2963)
- Debugger: Fix writing to specific segment in command-line debugger - Debugger: Fix writing to specific segment in command-line debugger
- GB: Fix applying a patch that changes the cartridge mapper (fixes mgba.io/i/3077)
- GBA Savedata: Fix crash when resizing flash save games for RTC data - GBA Savedata: Fix crash when resizing flash save games for RTC data
- mGUI: Fix cases where an older save state screenshot would be shown. (fixes mgba.io/i/2183) - mGUI: Fix cases where an older save state screenshot would be shown. (fixes mgba.io/i/2183)
- Qt: Fix savestate preview sizes with different scales (fixes mgba.io/i/2560) - Qt: Fix savestate preview sizes with different scales (fixes mgba.io/i/2560)

View File

@ -455,6 +455,9 @@ void GBApplyPatch(struct GB* gb, struct Patch* patch) {
if (patchedSize > GB_SIZE_CART_MAX) { if (patchedSize > GB_SIZE_CART_MAX) {
patchedSize = GB_SIZE_CART_MAX; patchedSize = GB_SIZE_CART_MAX;
} }
const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100];
uint8_t type = cart->type;
void* newRom = anonymousMemoryMap(GB_SIZE_CART_MAX); void* newRom = anonymousMemoryMap(GB_SIZE_CART_MAX);
if (!patch->applyPatch(patch, gb->memory.rom, gb->pristineRomSize, newRom, patchedSize)) { if (!patch->applyPatch(patch, gb->memory.rom, gb->pristineRomSize, newRom, patchedSize)) {
mappedMemoryFree(newRom, GB_SIZE_CART_MAX); mappedMemoryFree(newRom, GB_SIZE_CART_MAX);
@ -473,6 +476,12 @@ void GBApplyPatch(struct GB* gb, struct Patch* patch) {
} }
gb->memory.rom = newRom; gb->memory.rom = newRom;
gb->memory.romSize = patchedSize; gb->memory.romSize = patchedSize;
cart = (const struct GBCartridge*) &gb->memory.rom[0x100];
if (cart->type != type) {
gb->memory.mbcType = GB_MBC_AUTODETECT;
GBMBCInit(gb);
}
gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize); gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize);
gb->cpu->memory.setActiveRegion(gb->cpu, gb->cpu->pc); gb->cpu->memory.setActiveRegion(gb->cpu, gb->cpu->pc);
} }