Fixed a bug when reading/writing TEX1 section if there are 0 textures
@@ -138,15 +138,17 @@ class TEX1(J3DChunk):
texture = BTI(self.data, bti_header_offset)
self.textures.append(texture)
+ self.texture_names = []
+ self.textures_by_name = OrderedDict()
+
self.string_section_offset = read_u32(self.data, 0x10)
self.num_strings = read_u16(self.data, self.string_section_offset)
self.string_unknown_1 = read_u16(self.data, self.string_section_offset+2)
+ if self.num_strings > 0:
self.string_unknown_2 = read_u16(self.data, self.string_section_offset+4)
self.string_data_offset = read_u16(self.data, self.string_section_offset+6)
self.string_unknown_3 = read_bytes(self.data, self.string_section_offset+8, self.string_data_offset-8)
- self.texture_names = []
- self.textures_by_name = OrderedDict()
offset_in_string_list = self.string_data_offset
for texture in self.textures:
filename = read_str_until_null_character(self.data, self.string_section_offset + offset_in_string_list)
@@ -210,6 +212,7 @@ class TEX1(J3DChunk):
write_u32(self.data, 0x10, self.string_section_offset)
write_u16(self.data, self.string_section_offset, self.num_strings)
write_u16(self.data, self.string_section_offset+2, self.string_unknown_1)
+ if self.num_strings > 0:
write_u16(self.data, self.string_section_offset+4, self.string_unknown_2)
write_u16(self.data, self.string_section_offset+6, self.string_data_offset)
write_bytes(self.data, self.string_section_offset+8, self.string_unknown_3)
