示例#1
0
 def write_count(self, archive, count: int):
     count_address = self.location_strategy.read_base_address(archive)
     writer = BinArchiveWriter(archive, count_address)
     if self.width == 1:
         writer.write_u8(count)
     elif self.width == 2:
         writer.write_u16(count)
     else:
         writer.write_u32(count)
示例#2
0
    def _set_support_type_helper(self, owner, other, new_support_type):
        reader = self._open_reader_at_table(owner["Support ID"].value)
        reader.seek(reader.tell() + 2)
        count = reader.read_u16()
        supports_start = reader.tell()
        target_index = self._find_index_of_support_with_character(
            reader, other, count)
        target_address = supports_start + target_index * 0xC + 0x4

        writer = BinArchiveWriter(self.archive, target_address)
        writer.write_u32(new_support_type)
示例#3
0
    def _add_support_to_table(self, character1, character2, support_type, tag):
        # Jump to the target support table.
        master_support_table_address = self._get_master_support_table_address()
        reader = BinArchiveReader(self.archive, master_support_table_address)
        target_support_id = character1["Support ID"].value
        reader.seek(reader.tell() + target_support_id * 4 + 4)
        reader.seek(reader.read_internal_pointer() + 2)  # Skip the owner id.

        # Update the support count.
        writer = BinArchiveWriter(self.archive, reader.tell())
        old_count = reader.read_u16()
        writer.write_u16(old_count + 1)

        # Create the new support.
        new_support_address = writer.tell() + old_count * 0xC
        self.archive.allocate(new_support_address, 0xC, False)
        writer.seek(new_support_address)
        writer.write_u16(character2["ID"].value)
        writer.write_u16(old_count)
        writer.write_u32(support_type)
        writer.write_u32(tag)
示例#4
0
    def _create_support_table(self, character):
        # First, increment master support table count.
        master_support_table_address = self._get_master_support_table_address()
        writer = BinArchiveWriter(self.archive, master_support_table_address)
        reader = BinArchiveReader(self.archive, master_support_table_address)
        old_count = reader.read_u32()
        writer.write_u32(old_count + 1)

        # Next, create a pointer to the new table.
        pointer_address = master_support_table_address + old_count * 4 + 4
        self.archive.allocate(pointer_address, 4, False)
        destination = self.archive.size()
        self.archive.set_internal_pointer(pointer_address, destination)

        # Generate and assign a support ID for the character
        support_id = self._find_next_support_id()
        character["Support ID"].value = support_id

        # Allocate and format the new table.
        writer.seek(destination)
        self.archive.allocate_at_end(4)
        writer.write_u16(support_id)