From 9839164817d46d614f630ff441eace8c069b29a4 Mon Sep 17 00:00:00 2001 From: digiholic Date: Fri, 21 Jul 2023 11:00:44 -0600 Subject: [PATCH] MMBN3: Fixes crash when checking certain locations (#2003) --- worlds/mmbn3/BN3RomUtils.py | 2 ++ worlds/mmbn3/Rom.py | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/worlds/mmbn3/BN3RomUtils.py b/worlds/mmbn3/BN3RomUtils.py index ede86782..18a2a1f4 100644 --- a/worlds/mmbn3/BN3RomUtils.py +++ b/worlds/mmbn3/BN3RomUtils.py @@ -25,6 +25,8 @@ charDict = { "BowneGlobal10": 0x7D, "BowneGlobal11": 0x7E, '\n': 0xE8, 'ω': 0x6C } +dictChar = {v: k for k, v in charDict.items()} + undernet_item_indices = [27, 28, 29, 30, 31, 32, 58, 34, 34] diff --git a/worlds/mmbn3/Rom.py b/worlds/mmbn3/Rom.py index e759706c..79da50e5 100644 --- a/worlds/mmbn3/Rom.py +++ b/worlds/mmbn3/Rom.py @@ -7,9 +7,9 @@ import hashlib import bsdiff4 from .lz10 import gba_decompress, gba_compress -from .BN3RomUtils import ArchiveToReferences, read_u16_le, read_u32_le, int16_to_byte_list_le, int32_to_byte_list_le,\ +from .BN3RomUtils import ArchiveToReferences, read_u16_le, read_u32_le, int16_to_byte_list_le, int32_to_byte_list_le, \ generate_progressive_undernet, ArchiveToSizeComp, ArchiveToSizeUncomp, generate_item_message, \ - generate_external_item_message, generate_text_bytes + generate_external_item_message, generate_text_bytes, dictChar from .Items import ItemType @@ -45,29 +45,42 @@ class ArchiveScript: self.messageBoxes = [] message_box = [] + # message_box_chars = [] command_index = 0 + byte_index = 0 for byte in message_bytes: + byte_index += 1 if command_index <= 0 and (byte == 0xE9 or byte == 0xE7): if byte == 0xE9: # More textboxes to come, don't end it yet message_box.append(byte) + # message_box_chars.append(hex(byte)) self.messageBoxes.append(message_box) else: # It's the end of the script, add another message to end it after this one self.messageBoxes.append(message_box) self.messageBoxes.append([0xE7]) + message_box = [] + message_box_chars = [] else: - if command_index <- 0: + if command_index <= 0: # We can hit a command that might contain an E9 or an E7. If we do, skip checking the next few bytes if byte == 0xF6: # CheckItem command_index = 7 if byte == 0xF3: # CheckFlag - command_index = 7 + # For whatever reason, the "Check Navi Customizer" command is one byte shorter than the other + # Check flags. If the next byte is 0x28, our command is only 5 bytes long. + if message_bytes[byte_index] == 0x28: + command_index = 5 + else: + command_index = 6 if byte == 0xF2: # FlagSet command_index = 4 command_index -= 1 message_box.append(byte) + # message_box_chars.append(dictChar[byte] if byte in dictChar else hex(byte)) + # If there's still bytes left over, add them even if we didn't hit an end if len(message_box) > 0: self.messageBoxes.append(message_box)