示例#1
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)
示例#2
0
    def to_bin(self):
        archive = fefeditor2.create_bin_archive()
        result = []
        self._write_shift_jis(result, self.title)
        for (key, value) in self._messages.items():
            archive.set_mapped_pointer(len(result), key)
            self._write_utf16(result, value)

        archive.allocate_at_end(len(result))
        writer = BinArchiveWriter(archive)
        writer.write_bytes(result)
        return archive
示例#3
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)
示例#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)
示例#5
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)
示例#6
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)
示例#7
0
 def commit_changes(self):
     location = self.location_strategy.read_base_address(self.archive)
     writer = BinArchiveWriter(self.archive, location)
     for prop in self.element.values():
         prop.write(writer)
示例#8
0
 def commit_changes(self):
     base_location = self.location_strategy.read_base_address(self.archive)
     writer = BinArchiveWriter(self.archive, base_location)
     for elem in self.entries:
         for (_, prop) in elem.items():
             prop.write(writer)