Esempio n. 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)
Esempio n. 2
0
    def _remove_support_from_table(self, owner, other):
        # Update count.
        reader = self._open_reader_at_table(owner["Support ID"].value)
        reader.seek(reader.tell() + 2)
        writer = BinArchiveWriter(self.archive, reader.tell())
        old_count = reader.read_u16()
        writer.write_u16(old_count - 1)

        # Deallocate the support.
        target_index = self._find_index_of_support_with_character(
            reader, other, old_count)
        target_address = writer.tell() + target_index * 0xC
        self.archive.deallocate(target_address, 0xC, False)

        # Shift supports numbers back.
        writer.seek(target_address + 2)
        for i in range(target_index, old_count - 1):
            writer.write_u16(i)
            writer.seek(writer.tell() + 0xA)
Esempio n. 3
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)
Esempio n. 4
0
    def _add_support_to_table(self, character1, character2, support_type):
        # 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(0x1)  # Support tag. Still figuring this part out.