From 8b902bc4616b461fb638989b01b087d008ef0f23 Mon Sep 17 00:00:00 2001 From: rischdev Date: Sat, 29 Nov 2025 23:52:04 -0500 Subject: [PATCH] MMBN6: Fixed an issue with generating a large number of seeds that includes a Gregar and Falzar seed. Fixed an issue with adding characters to a byte array that were out of bounds when generating text bytes --- worlds/mmbn6/BN6RomUtils.py | 6 +++--- worlds/mmbn6/Rom.py | 42 ++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/worlds/mmbn6/BN6RomUtils.py b/worlds/mmbn6/BN6RomUtils.py index 97e62317ba99..4d5c4db798dd 100644 --- a/worlds/mmbn6/BN6RomUtils.py +++ b/worlds/mmbn6/BN6RomUtils.py @@ -99,11 +99,11 @@ def generate_text_bytes(message) -> bytearray: return bytearray(char_to_hex(c) for c in message) def char_to_hex(c) -> int: - if c in charDict: + if c in charDict and 0 <= charDict[c] <= 255: return charDict[c] else: - # If the character doesn't exist, return the star character - return 0xE4E5 + # If the character doesn't exist, or is out of range for a single byte value, return the star character + return 0x25 def generate_chip_get(chip, code, amt) -> bytearray: chip_bytes = int16_to_byte_list_le(chip) diff --git a/worlds/mmbn6/Rom.py b/worlds/mmbn6/Rom.py index 3093fccbda6a..67bc9fadb70d 100644 --- a/worlds/mmbn6/Rom.py +++ b/worlds/mmbn6/Rom.py @@ -339,19 +339,33 @@ def get_base_rom_path(file_name: str = "", game_version: str = "") -> str: return file_name -def get_base_rom_bytes(file_name: str = "") -> bytes: - base_rom_bytes = getattr(get_base_rom_bytes, "base_rom_bytes", None) - if not base_rom_bytes: - file_name = get_base_rom_path(file_name) - base_rom_bytes = bytes(open(file_name, "rb").read()) - - basemd5 = hashlib.md5() - basemd5.update(base_rom_bytes) - if CHECKSUM_GREG != basemd5.hexdigest() and CHECKSUM_FALZ != basemd5.hexdigest(): - raise Exception('Supplied Base Rom does not match US GBA Gregar or US GBA Falzar Version.' - 'Please provide the correct ROM version') - - get_base_rom_bytes.base_rom_bytes = base_rom_bytes +def get_base_rom_bytes(file_name: str = "", game_version: str = "") -> bytes: + if game_version == "gregar": + base_rom_bytes = getattr(get_base_rom_bytes, "gregar_base_rom_bytes", None) + if not base_rom_bytes: + file_name = get_base_rom_path(file_name) + base_rom_bytes = bytes(open(file_name, "rb").read()) + + basemd5 = hashlib.md5() + basemd5.update(base_rom_bytes) + if CHECKSUM_GREG != basemd5.hexdigest(): + raise Exception('Supplied Base Rom does not match US GBA Gregar.' + 'Please provide the correct ROM version') + + get_base_rom_bytes.gregar_base_rom_bytes = base_rom_bytes + else: + base_rom_bytes = getattr(get_base_rom_bytes, "falzar_base_rom_bytes", None) + if not base_rom_bytes: + file_name = get_base_rom_path(file_name) + base_rom_bytes = bytes(open(file_name, "rb").read()) + + basemd5 = hashlib.md5() + basemd5.update(base_rom_bytes) + if CHECKSUM_GREG != basemd5.hexdigest() and CHECKSUM_FALZ != basemd5.hexdigest(): + raise Exception('Supplied Base Rom does not match US GBA Falzar Version.' + 'Please provide the correct ROM version') + + get_base_rom_bytes.falzar_base_rom_bytes = base_rom_bytes return base_rom_bytes @@ -362,7 +376,7 @@ def get_patched_rom_bytes(file_name: str = "", game_version: str = "") -> bytes: Which should contain all changed text banks and assembly code """ import pkgutil - base_rom_bytes = get_base_rom_bytes(file_name) + base_rom_bytes = get_base_rom_bytes(file_name, game_version) if game_version == "gregar": patch_bytes = pkgutil.get_data(__name__, "data/bn6g-ap-patch.bsdiff") else: