#!/usr/bin/env python3 """ Meteo AVI-2-GBA (1.3.1 / 1.4.0 / 1.5.0) Batch ROM & Encoder Patcher (v3) Supports two patch modes: --mode sram (Default) +15s/-15s (Right/Left) & +30s/-30s (R/L Shoulders) Skip Forward/Back + A/START Pause & SRAM (0x0E000000) Auto-Bookmark & Resume (Hold B on boot = 0:00) --mode nobutton Classic No-Button-Reset Only (disables L+R+START+SELECT & B-button reset) Verified in mGBA 0.10.2 CLI debugger (/usr/games/mgba -d) and on real GBA hardware. """ import sys import os # Constant function prologues at 0xA858 (1.3.1) and 0xA890 (1.4.0/1.5.0) PROLOGUE_131 = bytes.fromhex('780f0003f34f2de90050a0e10c6090e40090a0e10610b0e1') PROLOGUE_140 = bytes.fromhex('fc110003f34f2de908d04de2007090e50c4080e20050a0e1') SIG_131_NOBUTTON = bytes.fromhex('400980e1b003d0e1001020e0001001e00010a0e30e0000ea') SIG_140_NOBUTTON = bytes.fromhex('400980e10000e0e3c30f10e3230000ea') ORIG_131_A8C8 = bytes.fromhex('0070a0e3000056e32d00009a0400a0e1cbfdffeb8ce01fe50040a0e104009ee5010850e304009ee51500003a010840e204008ee5000002ef0214a0e30103a0e3d41080e50614a0e3d81080e52113a0e34b1c81e2dc1080e5400980e1b003d0e1001028e0001001e00118b0e10e00000a0efdffeb0100a0e308d08de2f04fbde81eff2fe1010850e30300002a000002ef04009ee5010850e3fbffff3a04009ee5010840e204008ee5e2ffffea0080a0e1010087e20078a0e12778a0e1060057e1d1ffff3af9fcffeb04109de5000051e3c1ffff1a0000a0e308d08de2f04fbde81eff2fe11eff2fe10133a0e3023c83e2002093e5221802e0020a11e2feffff1a0020a0e3010011e22200001a042082e2020011e21f00001a042082e2040011e21c00001a042082e2080011e21900001a042082e2100011e21600001a042082e2200011e21300001a042082e2400011e21000001a042082e2800011e20d00001a042082e2010c11e20a00001a042082e2020c11e20700001a042082e2010b11e20400001a042082e2020b11e20100001a042082e2010a11e2b200c3e108109fe5021081e0000091e510ff2fe1800f0003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000780e0003780e0003780e0003780e0003780e0003780e0003780e0003780e0003780e0003780e0003780e0003780e0003780e0003') ORIG_140_AB3C = bytes.fromhex('060000eb0000a0e31f0000eb180000eb03d4a0e37fdc8de28c00a0e310ff2fe1a0009fe5000090e59c109fe5001091e5b000c1e194009fe5000090e590109fe5001091e5b000c1e188009fe5000090e584109fe5001091e5b000c1e17c009fe5000090e578109fe5001091e5b000c1e11eff2fe16c009fe5000090e568109fe5001091e5b000c1e11eff2fe15c109fe5001091e5b000c1e11eff2fe134d200004515000029d200007815000058150000c846fe092a2b0008b0480208264f04084a8efc09264d88099c100003b0100003a0100003b4100003a4100003b8100003a8100003bc100003ac100003c0100003c4100003020000eb0000a0e3200000ebbeffffeab4009fe53c0090e8100080e2001090e5b020c1e1041090e57dcfa0e3b030c1e101c05ce2fcffff1a041090e5b020c1e17dcfa0e3b040c1e101c05ce2fcffff1a001090e5b020c1e1041090e5b020c1e10c1090e5b040c1e1101090e5b030c1e1041090e57dcfa0e3b050c1e101c05ce2fcffff1a001090e5b020c1e11eff2fe138109fe5001091e5b000c1e11eff2fe1545300003412000078560000cdab0000a8ec30098a460208a8ec000800a8ec08') PATCHES_131_SRAM = [ (0x0148, bytes.fromhex('380e0000380e0003b40f0003007f0003180e0003')), (0xA8C8, bytes.fromhex('230000eb000056e31b00009a0400a0e1cbfdffeb8ce01fe50040a0e104009ee5010850e30000023ffbffff3a010840e204008ee50103a0e3d43080e20214a0e30624a0e321e3a0e34bec8ee2064083e8017087e2013c80e2b003d3e1001028e0001001e00080a0e1012bb0e12c209f1512ff2f11060057e1e3ffff3a0110b0e3f9ffffea023c80e20100a0e3b200c3e1b5ffffea00009fe510ff2fe16da900089da9000800274046800800d27047f243b4b484b0002100f084f809d1039b04b04c4a00205080ff32013210804a4d47e008b074e003221202393211426fd0f243b4b400225a80ff3301331a800922114212d0b74201d300220392012100f061f83c4b188e41464140014080460922114202d0b742f5d24ae0e12080003022114203d1400012011142ebd0334d6a6a5043030c00d101231120000101420bd1fb1a00d2002300274c465046594603c5083d0020a86204e0fb18701e834200d30300984647451ed228686968ab6a1a0c06d1012901d9b03001396a6a9b18f6e712049b1a03c5083dab624346d81bf02802d92088241804e02000184a00f011f804000137dee70020a860124b188e8046029d04b0802159800122120201219952104a104702b50e20000602aa0f2300f005f802aaf14313688b4204bd002904d1c15cd154013bfbd57047d15cc154013bfbd57047c04600010004540f0003d8040003080e00035352414d5f5631313300000000000000000000000000000000000000')), ] PATCHES_140_SRAM = [ (0xA8E4, bytes.fromhex('b093d0e1')), (0xA90C, bytes.fromhex('8a0000eb')), (0xA960, bytes.fromhex('018088e2400980e1b003d0e1001029e0001001e00090a0e1012bb0e17000001a300000ea')), (0xAA50, bytes.fromhex('0110a0e33a0000ea')), (0xAB3C, bytes.fromhex('08009fe510ff2fe104209fe512ff2fe1191000034f1000030020804648460221084200d17047fa4343463cb484b0002100f08df809d1019b04b0514a00205080ff32013210804f4d4ee008b07de0032212023932114278d0fa4343463cb4484b00225a80012424021a530922114213d0b84501d300220192012100f068f8404b188e49464140014081460922114203d0b845f5d2029c50e0e12080003022114203d1400012011142ead0029c354d6a6a5043030c00d101230a0041461120000102420cd1cb1a00d2002300218846059c0498594603c5083d0020a86204e0cb18781e834200d303009946c84520d228686968ab6a1a0c06d1012901d9b03001396a6a9b18f6e712049b1a03c5083dab624b464146581af02802d92088241804e02000194a00f012f8040001208044dce70020a860124b188e8146039d04b0802159800122120201219952104a104702b50e20000602aa0f2300f005f802aaf94313688b4204bd002904d1c15cd154013bfbd57047d15cc154013bfbd57047c04600010004d8110003d80400030c0f00035352414d5f563131330000000000000000000000')), ] def apply_records(buf, base_offset, records): for rel_off, payload in records: pos = base_offset + rel_off buf[pos:pos + len(payload)] = payload def patch_buffer(buf, mode='sram'): data = bytearray(buf) # 1. Check Meteo 1.3.1 .gba ROM or uncompressed EXE stub (prologue at rom_base + 0xA858) idx131 = data.find(PROLOGUE_131, 0, 0x40000) if idx131 != -1: rom_base = idx131 - 0xA858 if mode == 'sram' and rom_base >= 0: apply_records(data, rom_base, PATCHES_131_SRAM) return bytes(data), f"Meteo 1.3.1 +15s/-15s & +30s/-30s Seek + Pause + SRAM Auto-Resume (base +0x{rom_base:X})" else: if rom_base >= 0: data[rom_base + 0x0148:rom_base + 0x015C] = bytes.fromhex('b40f00000000000000000000007f00037c0e0003') data[rom_base + 0xA8C8:rom_base + 0xAAE8] = ORIG_131_A8C8 data[rom_base + 0xA920:rom_base + 0xA920 + len(SIG_131_NOBUTTON)] = SIG_131_NOBUTTON return bytes(data), f"Meteo 1.3.1 Classic No-Button-Reset (base +0x{rom_base:X})" # 2. Check Meteo 1.4.0 / 1.5.0 .gba ROM or EXE stub (prologue at rom_base + 0xA890) idx140 = data.find(PROLOGUE_140, 0, 0x40000) if idx140 != -1: rom_base = idx140 - 0xA890 if mode == 'sram' and rom_base >= 0: apply_records(data, rom_base, PATCHES_140_SRAM) return bytes(data), f"Meteo 1.4.0/1.5.0 +15s/-15s & +30s/-30s Seek + Pause + SRAM Auto-Resume (base +0x{rom_base:X})" else: if rom_base >= 0: data[rom_base + 0xAA50:rom_base + 0xAA58] = bytes.fromhex('caffffeb0c109de5') data[rom_base + 0xAB3C:rom_base + 0xAB3C + len(ORIG_140_AB3C)] = ORIG_140_AB3C data[rom_base + 0xA8E4:rom_base + 0xA8E8] = bytes.fromhex('0090e0e3') data[rom_base + 0xA960:rom_base + 0xA960 + len(SIG_140_NOBUTTON)] = SIG_140_NOBUTTON return bytes(data), f"Meteo 1.4.0/1.5.0 Classic No-Button-Reset (base +0x{rom_base:X})" # 3. Check UPX-packed Meteo 1.3.1 (EN).exe (85,504 bytes) if len(data) == 85504 and data[0x123f9:0x123fb] in (bytes.fromhex('1028'), bytes.fromhex('1020')): data[0x123fa] = 0x20 return bytes(data), "Meteo 1.3.1 UPX-packed EXE No-Button-Reset (patch produced .gba ROMs for Seek + SRAM Pause+Resume)" raise ValueError("Unrecognized Meteo ROM or EXE binary.") if __name__ == '__main__': if '--help' in sys.argv or '-h' in sys.argv: print("Usage: python3 meteo_nobutton_patcher.py [--in-place|-i] [--mode sram|nobutton] [file1.gba|folder|Meteo.exe ...]") print("If run with no file/folder arguments, automatically batch-patches all .gba files in the script's folder!") sys.exit(0) mode = 'sram' in_place = ('--in-place' in sys.argv or '-i' in sys.argv) args = [a for a in sys.argv[1:] if not a.startswith('-')] if '--mode=nobutton' in sys.argv or ('--mode' in sys.argv and 'nobutton' in sys.argv): mode = 'nobutton' if not args: script_dir = os.path.dirname(os.path.abspath(__file__)) or '.' print(f"No files specified — scanning folder: {script_dir}") args = [script_dir] targets = [] for p in args: if os.path.isdir(p): for root, _, files in os.walk(p): for fn in sorted(files): if fn.lower().endswith(('.gba', '.exe')): targets.append(os.path.join(root, fn)) else: targets.append(p) # If not in-place, skip foo_sram_pause.gba when foo.gba is already in targets target_set = set(os.path.abspath(t) for t in targets) filtered_targets = [] for t in targets: abs_t = os.path.abspath(t) base, ext = os.path.splitext(abs_t) if not in_place and base.endswith('_sram_pause') and (base[:-11] + ext) in target_set: continue filtered_targets.append(t) targets = filtered_targets ok_count = 0 for path in targets: try: with open(path, 'rb') as f: raw = f.read() patched, desc = patch_buffer(raw, mode=mode) base, ext = os.path.splitext(path) for old_suf in ('_sram_pause', '_nobuttons'): if base.endswith(old_suf): base = base[:-len(old_suf)] suffix = "_sram_pause" if "SRAM" in desc else "_nobuttons" out_path = path if in_place else f"{base}{suffix}{ext}" with open(out_path, 'wb') as f: f.write(patched) ok_count += 1 print(f"[OK] {path} -> {out_path} ({desc})") except Exception as e: print(f"[SKIP] {path}: {e}") print(f"Batch complete: {ok_count}/{len(targets)} file(s) patched to v3.1.") if os.name == "nt" and len(sys.argv) == 1: try: input("\nPress Enter to close...") except EOFError: pass