def old_parse_trainer_header_at(address, map_group=None, map_id=None, rom=None, debug=True): bank = pointers.calculate_bank(address) bytes = rom_interval(address, 12, rom=rom, strings=False) bit_number = bytes[0] + (bytes[1] << 8) trainer_group = bytes[2] trainer_id = bytes[3] text_when_seen_ptr = calculate_pointer_from_bytes_at(address+4, bank=bank) text_when_seen = parse_text_engine_script_at(text_when_seen_ptr, map_group=map_group, map_id=map_id, debug=debug) text_when_trainer_beaten_ptr = calculate_pointer_from_bytes_at(address+6, bank=bank) text_when_trainer_beaten = parse_text_engine_script_at(text_when_trainer_beaten_ptr, map_group=map_group, map_id=map_id, debug=debug) if [ord(rom[address+8]), ord(rom[address+9])] == [0, 0]: script_when_lost_ptr = 0 script_when_lost = None else: logging.debug("parsing script-when-lost") script_when_lost_ptr = calculate_pointer_from_bytes_at(address+8, bank=bank) script_when_lost = None silver_avoids = [0xfa53] if script_when_lost_ptr > 0x4000 and not script_when_lost_ptr in silver_avoids: script_when_lost = parse_script_engine_script_at(script_when_lost_ptr, map_group=map_group, map_id=map_id, debug=debug) logging.debug("parsing script-talk-again") # or is this a text? script_talk_again_ptr = calculate_pointer_from_bytes_at(address+10, bank=bank) script_talk_again = None if script_talk_again_ptr > 0x4000: script_talk_again = parse_script_engine_script_at(script_talk_again_ptr, map_group=map_group, map_id=map_id, debug=debug) return { "bit_number": bit_number, "trainer_group": trainer_group, "trainer_id": trainer_id, "text_when_seen_ptr": text_when_seen_ptr, "text_when_seen": text_when_seen, "text_when_trainer_beaten_ptr": text_when_trainer_beaten_ptr, "text_when_trainer_beaten": text_when_trainer_beaten, "script_when_lost_ptr": script_when_lost_ptr, "script_when_lost": script_when_lost, "script_talk_again_ptr": script_talk_again_ptr, "script_talk_again": script_talk_again, }
def test_parse_text_engine_script_at(self): p = parse_text_engine_script_at(0x197185, debug=False) self.assertEqual(len(p.commands), 2) self.assertEqual(len(p.commands[0]["lines"]), 41)
def test_parse_text_engine_script_at(self): p = parse_text_engine_script_at(0x197185, debug=False) self.assertEqual(len(p.commands), 1) self.assertEqual(p.commands[0].to_asm().count("\n"), 40)
def old_parse_trainer_header_at(address, map_group=None, map_id=None, rom=None, debug=True): bank = pointers.calculate_bank(address) bytes = rom_interval(address, 12, rom=rom, strings=False) bit_number = bytes[0] + (bytes[1] << 8) trainer_group = bytes[2] trainer_id = bytes[3] text_when_seen_ptr = calculate_pointer_from_bytes_at(address + 4, bank=bank) text_when_seen = parse_text_engine_script_at(text_when_seen_ptr, map_group=map_group, map_id=map_id, debug=debug) text_when_trainer_beaten_ptr = calculate_pointer_from_bytes_at(address + 6, bank=bank) text_when_trainer_beaten = parse_text_engine_script_at( text_when_trainer_beaten_ptr, map_group=map_group, map_id=map_id, debug=debug) if [ord(rom[address + 8]), ord(rom[address + 9])] == [0, 0]: script_when_lost_ptr = 0 script_when_lost = None else: logging.debug("parsing script-when-lost") script_when_lost_ptr = calculate_pointer_from_bytes_at(address + 8, bank=bank) script_when_lost = None silver_avoids = [0xfa53] if script_when_lost_ptr > 0x4000 and not script_when_lost_ptr in silver_avoids: script_when_lost = parse_script_engine_script_at( script_when_lost_ptr, map_group=map_group, map_id=map_id, debug=debug) logging.debug("parsing script-talk-again") # or is this a text? script_talk_again_ptr = calculate_pointer_from_bytes_at(address + 10, bank=bank) script_talk_again = None if script_talk_again_ptr > 0x4000: script_talk_again = parse_script_engine_script_at( script_talk_again_ptr, map_group=map_group, map_id=map_id, debug=debug) return { "bit_number": bit_number, "trainer_group": trainer_group, "trainer_id": trainer_id, "text_when_seen_ptr": text_when_seen_ptr, "text_when_seen": text_when_seen, "text_when_trainer_beaten_ptr": text_when_trainer_beaten_ptr, "text_when_trainer_beaten": text_when_trainer_beaten, "script_when_lost_ptr": script_when_lost_ptr, "script_when_lost": script_when_lost, "script_talk_again_ptr": script_talk_again_ptr, "script_talk_again": script_talk_again, }