From 5fd0ba0d6725d6e0f9da2a3ff86b4c28fb085bc1 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 23 Feb 2025 22:49:08 -0800 Subject: [PATCH] GBA Cheats: Let VBA-style codes patch ROM (fixes #3423) --- CHANGES | 1 + src/gba/cheats.c | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 6b2bff781..f998666bc 100644 --- a/CHANGES +++ b/CHANGES @@ -30,6 +30,7 @@ Other fixes: - FFmpeg: Fix failing to record videos with CRF video (fixes mgba.io/i/3368) - GB Core: Fix cloning savedata when backing file is outdated (fixes mgba.io/i/3388) - GBA: Fix getting game info for multiboot ROMs + - GBA Cheats: Let VBA-style codes patch ROM (fixes mgba.io/i/3423) - GBA Core: Fix booting into BIOS when skip BIOS is enabled - GBA Hardware: Fix loading states unconditionally overwriting GPIO memory - mGUI: Load parent directory if last used directory is missing (fixes mgba.io/i/3379) diff --git a/src/gba/cheats.c b/src/gba/cheats.c index d055194be..4fb23b1de 100644 --- a/src/gba/cheats.c +++ b/src/gba/cheats.c @@ -180,14 +180,25 @@ bool GBACheatAddVBALine(struct GBACheatSet* cheats, const char* line) { return false; } - struct mCheat* cheat = mCheatListAppend(&cheats->d.list); - cheat->address = address; - cheat->operandOffset = 0; - cheat->addressOffset = 0; - cheat->repeat = 1; - cheat->type = CHEAT_ASSIGN; - cheat->width = width; - cheat->operand = value; + if (address < GBA_BASE_ROM0 || address >= GBA_BASE_SRAM) { + struct mCheat* cheat = mCheatListAppend(&cheats->d.list); + memset(cheat, 0, sizeof(*cheat)); + cheat->address = address; + cheat->operandOffset = 0; + cheat->addressOffset = 0; + cheat->repeat = 1; + cheat->type = CHEAT_ASSIGN; + cheat->width = width; + cheat->operand = value; + } else { + struct mCheatPatch* patch = mCheatPatchListAppend(&cheats->d.romPatches); + memset(patch, 0, sizeof(*patch)); + patch->width = width; + patch->address = address; + patch->segment = 0; + patch->value = value; + patch->check = false; + } return true; }