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_calculate_pointer_from_bytes_at(self):
     addr1 = calculate_pointer_from_bytes_at(0x100, bank=False)
     self.assertEqual(addr1, 0xc300)
     addr2 = calculate_pointer_from_bytes_at(0x100, bank=True)
     self.assertEqual(addr2, 0x2ec3)
Exemple #3
0
 def test_calculate_pointer_from_bytes_at(self):
     addr1 = calculate_pointer_from_bytes_at(0x100, bank=False)
     self.assertEqual(addr1, 0xc300)
     addr2 = calculate_pointer_from_bytes_at(0x100, bank=True)
     self.assertEqual(addr2, 0x2ec3)
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 old_parse_signpost_bytes(some_bytes,
                             bank=None,
                             map_group=None,
                             map_id=None,
                             rom=None,
                             debug=True):
    assert len(some_bytes) % signpost_byte_size == 0, "wrong number of bytes"
    signposts = []
    for bytes in helpers.grouper(some_bytes, count=signpost_byte_size):
        y = int(bytes[0], 16)
        x = int(bytes[1], 16)
        func = int(bytes[2], 16)

        additional = {}
        if func in [0, 1, 2, 3, 4]:
            logging.debug(
                "parsing signpost script.. signpost is at x={x} y={y}".format(
                    x=x, y=y))
            script_ptr_byte1 = int(bytes[3], 16)
            script_ptr_byte2 = int(bytes[4], 16)
            script_pointer = script_ptr_byte1 + (script_ptr_byte2 << 8)

            script_address = None
            script = None

            script_address = pointers.calculate_pointer(script_pointer, bank)
            script = parse_script_engine_script_at(script_address,
                                                   map_group=map_group,
                                                   map_id=map_id)

            additional = {
                "script_ptr": script_pointer,
                "script_pointer": {
                    "1": script_ptr_byte1,
                    "2": script_ptr_byte2
                },
                "script_address": script_address,
                "script": script,
            }
        elif func in [5, 6]:
            logging.debug(
                "parsing signpost script.. signpost is at x={x} y={y}".format(
                    x=x, y=y))

            ptr_byte1 = int(bytes[3], 16)
            ptr_byte2 = int(bytes[4], 16)
            pointer = ptr_byte1 + (ptr_byte2 << 8)
            address = pointers.calculate_pointer(pointer, bank)
            bit_table_byte1 = ord(rom[address])
            bit_table_byte2 = ord(rom[address + 1])
            script_ptr_byte1 = ord(rom[address + 2])
            script_ptr_byte2 = ord(rom[address + 3])
            script_address = calculate_pointer_from_bytes_at(address + 2,
                                                             bank=bank)
            script = parse_script_engine_script_at(script_address,
                                                   map_group=map_group,
                                                   map_id=map_id)

            additional = {
                "bit_table_bytes": {
                    "1": bit_table_byte1,
                    "2": bit_table_byte2
                },
                "script_ptr": script_ptr_byte1 + (script_ptr_byte2 << 8),
                "script_pointer": {
                    "1": script_ptr_byte1,
                    "2": script_ptr_byte2
                },
                "script_address": script_address,
                "script": script,
            }
        else:
            logging.debug(".. type 7 or 8 signpost not parsed yet.")

        spost = {
            "y": y,
            "x": x,
            "func": func,
        }
        spost.update(additional)
        signposts.append(spost)
    return signposts
def old_parse_signpost_bytes(some_bytes, bank=None, map_group=None, map_id=None, rom=None, debug=True):
    assert len(some_bytes) % signpost_byte_size == 0, "wrong number of bytes"
    signposts = []
    for bytes in helpers.grouper(some_bytes, count=signpost_byte_size):
        y = int(bytes[0], 16)
        x = int(bytes[1], 16)
        func = int(bytes[2], 16)

        additional = {}
        if func in [0, 1, 2, 3, 4]:
            logging.debug(
                "parsing signpost script.. signpost is at x={x} y={y}"
                .format(x=x, y=y)
            )
            script_ptr_byte1 = int(bytes[3], 16)
            script_ptr_byte2 = int(bytes[4], 16)
            script_pointer = script_ptr_byte1 + (script_ptr_byte2 << 8)

            script_address = None
            script = None

            script_address = pointers.calculate_pointer(script_pointer, bank)
            script = parse_script_engine_script_at(script_address, map_group=map_group, map_id=map_id)

            additional = {
            "script_ptr": script_pointer,
            "script_pointer": {"1": script_ptr_byte1, "2": script_ptr_byte2},
            "script_address": script_address,
            "script": script,
            }
        elif func in [5, 6]:
            logging.debug(
                "parsing signpost script.. signpost is at x={x} y={y}"
                .format(x=x, y=y)
            )

            ptr_byte1 = int(bytes[3], 16)
            ptr_byte2 = int(bytes[4], 16)
            pointer = ptr_byte1 + (ptr_byte2 << 8)
            address = pointers.calculate_pointer(pointer, bank)
            bit_table_byte1 = ord(rom[address])
            bit_table_byte2 = ord(rom[address+1])
            script_ptr_byte1 = ord(rom[address+2])
            script_ptr_byte2 = ord(rom[address+3])
            script_address = calculate_pointer_from_bytes_at(address+2, bank=bank)
            script = parse_script_engine_script_at(script_address, map_group=map_group, map_id=map_id)

            additional = {
            "bit_table_bytes": {"1": bit_table_byte1, "2": bit_table_byte2},
            "script_ptr": script_ptr_byte1 + (script_ptr_byte2 << 8),
            "script_pointer": {"1": script_ptr_byte1, "2": script_ptr_byte2},
            "script_address": script_address,
            "script": script,
            }
        else:
            logging.debug(".. type 7 or 8 signpost not parsed yet.")

        spost = {
            "y": y,
            "x": x,
            "func": func,
        }
        spost.update(additional)
        signposts.append(spost)
    return signposts