def __init__(self, file_object_data_wrapper: FileObjectDataWrapper): file_object_data_wrapper.read_bytes(5) for n in (8, 4): count = file_object_data_wrapper.read_uint_32() file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(count * n) file_object_data_wrapper.indent(-1)
def __init__(self, file_object_data_wrapper: FileObjectDataWrapper): count1 = file_object_data_wrapper.read_uint_32() self.width = self.height = int(count1**0.5) self.image_ids = [] for n in range(count1): file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(1) self.image_ids.append(file_object_data_wrapper.read_id()) file_object_data_wrapper.indent(-1)
def __init__(self, file_object_data_wrapper: FileObjectDataWrapper): file_object_data_wrapper.read_bytes(4) count = file_object_data_wrapper.read_uint_32() for _ in range(count): file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(2) file_object_data_wrapper.indent(-1) file_object_data_wrapper.read_file() file_object_data_wrapper.read_bytes(4)
def __init__(self, py_ubi_forge, file_object_data_wrapper: FileObjectDataWrapper): file_object_data_wrapper.read_bytes(4) count = file_object_data_wrapper.read_uint_32() for _ in range(count): file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(2) file_object_data_wrapper.indent(-1) py_ubi_forge.read_file.get_data_recursive(file_object_data_wrapper) file_object_data_wrapper.read_bytes(4)
def __init__(self, py_ubi_forge, file_object_data_wrapper: FileObjectDataWrapper): count1 = file_object_data_wrapper.read_uint_32() self.files = [] for _ in range(count1): file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(2) self.files.append(file_object_data_wrapper.read_id()) file_object_data_wrapper.indent(-1) file_object_data_wrapper.out_file_write('\n') count2 = file_object_data_wrapper.read_uint_32() # seems to be about the same or slightly less than count1 self.cell_id = file_object_data_wrapper.read_uint_32() file_object_data_wrapper.read_bytes(4) # this might be part of the previous as a 64 bit uint
def __init__(self, py_ubi_forge, file_object_data_wrapper: FileObjectDataWrapper): check_byte = file_object_data_wrapper.read_uint_8( ) # checkbyte 03 to continue (other stuff to not? have seen 00 with data after) if check_byte == 0: for _ in range(2): py_ubi_forge.read_file.get_data_recursive( file_object_data_wrapper) file_object_data_wrapper.out_file_write('Transformation Matrix\n') self.transformation_matrix = file_object_data_wrapper.read_numpy( numpy.float32, 64).reshape((4, 4), order='F') file_object_data_wrapper.out_file_write('\n') count1 = file_object_data_wrapper.read_uint_32() if count1 > 10000: py_ubi_forge.log.warn(__name__, 'error reading entity file') # convert to an actual logger raise Exception self.nested_files = [] for _ in range(count1): file_object_data_wrapper.out_file_write('\n') file_object_data_wrapper.indent() if file_object_data_wrapper.read_bytes(2) not in [ b'\x04\x00', b'\x00\x01' ]: # 04 00 raise Exception file_object_data_wrapper.indent(-1) self.nested_files.append( py_ubi_forge.read_file.get_data_recursive( file_object_data_wrapper)) file_object_data_wrapper.out_file_write('\n') file_object_data_wrapper.read_bytes(43) # data layer filter # 4 count, more data in here sometimes for _ in range(3): py_ubi_forge.read_file.get_data_recursive(file_object_data_wrapper) # 03 end file? check_byte_2 = file_object_data_wrapper.read_uint_8() if check_byte_2 == 0: py_ubi_forge.read_file.get_data_recursive(file_object_data_wrapper) elif check_byte_2 != 3: raise Exception file_object_data_wrapper.out_file_write('\n')
def get_data_recursive(self, file_object_data_wrapper: FileObjectDataWrapper): """ Call this function in file reader methods to access other file types in the same file :param file_object_data_wrapper: The input raw data :return: objects defined in the plugins """ file_object_data_wrapper.out_file_write('\n') file_object_data_wrapper.read_id() file_type = file_object_data_wrapper.read_type() if file_type in self.readers: file_object_data_wrapper.indent() ret = self.readers[file_type](self.pyUbiForge, file_object_data_wrapper) file_object_data_wrapper.indent(-1) return ret else: raise Exception( f'File type {file_type} does not have a file reader')
def __init__(self, file_object_data_wrapper: FileObjectDataWrapper): file_object_data_wrapper.read_bytes(2) self.entity: Entity = file_object_data_wrapper.read_file() count1 = file_object_data_wrapper.read_uint_32() file_object_data_wrapper.indent() for _ in range(count1): file_object_data_wrapper.read_file() file_object_data_wrapper.indent(-1) count2 = file_object_data_wrapper.read_uint_32() file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(4 * count2) file_object_data_wrapper.indent(-1) file_object_data_wrapper.read_uint_32() # coord 1 file_object_data_wrapper.read_uint_32() # coord 2 file_object_data_wrapper.read_bytes(1)
def __init__(self, py_ubi_forge, file_object_data_wrapper: FileObjectDataWrapper): for length in [2, 2, 1, 1, 4, 2, 2]: total_count = file_object_data_wrapper.read_uint_32() file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(total_count * length) file_object_data_wrapper.indent(-1) found_count = 0 empty_count = 0 filled_count = 0 # probably not right but this seems to work while found_count < total_count or empty_count != filled_count + 1: check_byte = file_object_data_wrapper.read_uint_8() if check_byte == 0: sub_file_container = py_ubi_forge.read_file.get_data_recursive(file_object_data_wrapper) found_count += sub_file_container.count if sub_file_container.count > 0: filled_count += 1 else: empty_count += 1 elif check_byte == 3: filled_count += 1 continue else: raise Exception(f'{__name__}: check_byte is not in 0, 3') file_object_data_wrapper.read_bytes(8) count = file_object_data_wrapper.read_uint_32() for _ in range(count): check_byte = file_object_data_wrapper.read_bytes(1) py_ubi_forge.read_file.get_data_recursive(file_object_data_wrapper) count = file_object_data_wrapper.read_uint_32() for _ in range(count): file_object_data_wrapper.read_bytes(4) file_object_data_wrapper.read_bytes(1) for _ in range(7): file_object_data_wrapper.read_bytes(4) py_ubi_forge.read_file.get_data_recursive(file_object_data_wrapper)
def __init__(self, py_ubi_forge, file_object_data_wrapper: FileObjectDataWrapper): file_object_data_wrapper.read_bytes(2) self.entity: Entity = py_ubi_forge.read_file.get_data_recursive( file_object_data_wrapper) count1 = file_object_data_wrapper.read_uint_32() file_object_data_wrapper.indent() for _ in range(count1): py_ubi_forge.read_file.get_data_recursive(file_object_data_wrapper) file_object_data_wrapper.indent(-1) count2 = file_object_data_wrapper.read_uint_32() file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(4 * count2) file_object_data_wrapper.indent(-1) file_object_data_wrapper.read_uint_32() # coord 1 file_object_data_wrapper.read_uint_32() # coord 2 file_object_data_wrapper.read_bytes(1)
def __init__(self, file_object_data_wrapper: FileObjectDataWrapper): file_object_data_wrapper.read_uint_32() # should always be equal to 0 for n in (4, 4, 4, 1, 12, 12, 12, 12, 4, 4): count = file_object_data_wrapper.read_uint_32() file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(count * n) file_object_data_wrapper.indent(-1) file_object_data_wrapper.read_bytes(1) for n in (4, 2, 2): count = file_object_data_wrapper.read_uint_32() file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(count * n) file_object_data_wrapper.indent(-1) for _ in range(file_object_data_wrapper.read_uint_32()): file_object_data_wrapper.read_file() file_object_data_wrapper.read_bytes(2) file_object_data_wrapper.read_id() file_object_data_wrapper.read_bytes(1)
def __init__(self, file_object_data_wrapper: FileObjectDataWrapper): file_object_data_wrapper.read_bytes(8 * 4) # FFF0FFF0 count1 = file_object_data_wrapper.read_uint_32() self.count = count1 if count1 == 0: pass elif 0 < count1 < 100000: file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(count1 * 4) file_object_data_wrapper.indent(-1) else: raise Exception('Probably an issue here') count2 = file_object_data_wrapper.read_uint_32() if count2 == 0: pass elif 0 < count2 < 100000: file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(count2) file_object_data_wrapper.indent(-1) file_object_data_wrapper.read_bytes(2) # \x03\x03 else: raise Exception('Probably an issue here')
def __init__(self, py_ubi_forge, file_object_data_wrapper: FileObjectDataWrapper): file_object_data_wrapper.read_type() for _ in range(2): check = file_object_data_wrapper.read_bytes(1) if check != b'\x03': file_object_data_wrapper.read_id() for _ in range(2): file_object_data_wrapper.read_bytes(32) # ? file_object_data_wrapper.read_bytes(5) count = file_object_data_wrapper.read_uint_32() for _ in range(count): file_object_data_wrapper.indent() file_object_data_wrapper.read_bytes(1) py_ubi_forge.read_file.get_data_recursive(file_object_data_wrapper) file_object_data_wrapper.indent(-1) count = file_object_data_wrapper.read_uint_32() for _ in range(count): file_object_data_wrapper.indent() file_object_data_wrapper.read_type() file_object_data_wrapper.indent(-1) # check = file_object_data_wrapper.read_bytes(1) file_object_data_wrapper.read_bytes(13)
def __init__(self, model_file: FileObjectDataWrapper): BaseModel.__init__(self) model_file.out_file_write('\n') model_file.read_bytes(1) # skip an empty byte self.type = model_file.read_bytes(4) model_file.read_bytes(1) a_count = model_file.read_uint_32() for a in range(a_count * 2): check = model_file.read_uint_8() while check == 3: check = model_file.read_uint_8() model_file.read_bytes(1) pyUbiForge.read_file.get_data_recursive(model_file) if a_count > 0: model_file.read_bytes(1) bone_count = model_file.read_uint_32() self._bones = [] for _ in range(bone_count): self._bones.append( pyUbiForge.read_file.get_data_recursive(model_file)) self.bounding_box = model_file.read_numpy(numpy.float32, 32).reshape(2, 4) model_file.out_file_write(f'{self.bounding_box}\n') model_file.read_bytes(1) model_file.read_id() if model_file.read_type( ) == "FC9E1595": # this part should get moved to a different file technically model_file.read_bytes(4) model_file.out_file_write('Typeswitch\n') self.type_switch = model_file.read_bytes(1) use_blocks = 0 if self.type_switch == b'\x00': model_file.read_id() model_file.read_type() model_file.read_bytes(5) model_file.out_file_write('Vert table width\n') vert_table_width = model_file.read_uint_32() mesh_face_block_sum = model_file.read_uint_32( ) # = sum(mesh_face_blocks) bounding_box2 = model_file.read_numpy(numpy.float32, 24).reshape(2, 3) mesh_face_block_count = model_file.read_uint_32() shadow_face_block_count = model_file.read_uint_32() model_file.out_file_write('Mesh Face Blocks\n') mesh_face_blocks = model_file.read_numpy( numpy.uint32, 4 * mesh_face_block_count) shadow_face_blocks = model_file.read_numpy( numpy.uint32, 4 * shadow_face_block_count) model_file.read_uint_32() use_blocks = model_file.read_uint_8() # use blocks? model_file.out_file_write('\nVert table\n') vert_table_length = model_file.read_uint_32() self.vert_count = vert_table_length / vert_table_width if vert_table_width == 16: vert_table = model_file.read_numpy( [ ('v', numpy.int16, 3), ('sc', numpy.int16), ('', numpy.int16, 2), # not sure what this is ('vt', numpy.int16, 2) ], vert_table_length) elif vert_table_width == 20: vert_table = model_file.read_numpy( [ ('v', numpy.int16, 3), ('sc', numpy.int16), ('n', numpy.int16, 3), ('', numpy.int16), # not sure what this is ('vt', numpy.int16, 2) ], vert_table_length) elif vert_table_width == 24: vert_table = model_file.read_numpy( [ ('v', numpy.int16, 3), ('sc', numpy.int16), ('n', numpy.int16, 3), ('', numpy.int16, 3), # not sure what this is ('vt', numpy.int16, 2) ], vert_table_length) elif vert_table_width == 28: vert_table = model_file.read_numpy( [ ('v', numpy.int16, 3), ('sc', numpy.int16), ('n', numpy.int16, 3), ('', numpy.int16, 3), # not sure what this is ('vt', numpy.int16, 2), ('', numpy.int16, 2), # not sure what this is ], vert_table_length) elif vert_table_width == 32: vert_table = model_file.read_numpy( [ ('v', numpy.int16, 3), ('sc', numpy.int16), ('n', numpy.int16, 3), ('', numpy.int16, 3), # not sure what this is ('vt', numpy.int16, 2), ('bn', numpy.uint8, 4), ('bw', numpy.uint8, 4) ], vert_table_length) elif vert_table_width == 36: vert_table = model_file.read_numpy( [ ('v', numpy.int16, 3), ('sc', numpy.int16), ('n', numpy.int16, 3), ('', numpy.int16, 3), # not sure what this is ('vt', numpy.int16, 2), ('', numpy.int16, 2), # not sure what this is ('bn', numpy.uint8, 4), ('bw', numpy.uint8, 4) ], vert_table_length) elif vert_table_width == 40: vert_table = model_file.read_numpy( [ ('v', numpy.int16, 3), ('sc', numpy.int16), ('n', numpy.int16, 3), ('', numpy.int16, 3), # not sure what this is ('vt', numpy.int16, 2), ('bn', numpy.uint8, 8), ('bw', numpy.uint8, 8) ], vert_table_length) elif vert_table_width == 48: vert_table = model_file.read_numpy( [ ('v', numpy.int16, 3), ('sc', numpy.int16), ('n', numpy.int16, 3), ('', numpy.int16, 3), # not sure what this is ('vt', numpy.int16, 2), ('', numpy.int16, 2), # not sure what this is ('bn', numpy.uint8, 8), ('bw', numpy.uint8, 8), ('', numpy.int16, 2), # not sure what this is ], vert_table_length) else: logging.warning( f'Not yet implemented!\n\nvertTableWidth = {vert_table_width}' ) raise Exception() self._vertices = vert_table['v'].astype( numpy.float) * numpy.sign(vert_table['sc'].reshape( -1, 1)) / 2**15 # self._vertices *= numpy.sum(bounding_box2, 0) / numpy.amax(self.vertices, 0) self._texture_vertices = vert_table['vt'].astype( numpy.float) / 2048.0 self._texture_vertices[:, 1] *= -1 if 'n' in vert_table: self._normals = vert_table['n'].astype(numpy.float) self.vert_table = vert_table model_file.out_file_write('Face table\n') face_table_length = model_file.read_uint_32() self._faces = model_file.read_numpy(numpy.uint16, face_table_length).reshape( -1, 3) # self._faces = numpy.split(face_table, numpy.cumsum(mesh_face_blocks * 64)[:-1]) # # # mesh_face_blocks_x64 = numpy.cumsum(mesh_face_blocks * 64) # mesh_face_blocks_x64[-1] = # mesh_face_blocks[-1] =* 64 * 6 == face_table_length: # self._faces = [face_table[64*mesh_face_blocks[index-1]:64*block_count] for index, block_count in enumerate(mesh_face_blocks)] # self._faces = [face_table[:64 * block_count] if index==0 else face_table[64*mesh_face_blocks[index-1]:64*block_count] for index, block_count in enumerate(mesh_face_blocks)] for _ in range(3): count = model_file.read_uint_32() model_file.read_bytes(count) model_file.read_id() model_file.read_type() model_file.read_bytes(3) model_file.out_file_write('Mesh Table\n') mesh_count = model_file.read_uint_32() self._meshes = model_file.read_numpy( [ ('file_id', numpy.uint64), ('file_type', numpy.uint32), ('verts_used', numpy.uint32), # this is not always perfect ('', numpy.uint32), ('vert_count', numpy.uint32), ('faces_used_x3', numpy.uint32), ('face_count', numpy.uint32), ('', numpy.uint32) ], 36 * mesh_count) if self._faces is not None: if use_blocks == 1: self._faces = numpy.split( self._faces, numpy.cumsum(mesh_face_blocks * 64)[:-1]) for index in range(len(self._faces)): self._faces[index] = self._faces[index][:self.meshes[ 'face_count'][index]] # strip the end of the block if index >= 1: self._faces[index] += self._faces[index - 1].max( ) + 1 # add the vertex offset (each block starts from 0) else: faces = self._faces self._faces = [] for faces_used_x3, face_count, verts_used in zip( self.meshes['faces_used_x3'], self.meshes['face_count'], self.meshes['verts_used']): self._faces.append( faces[int(faces_used_x3 / 3):int(faces_used_x3 / 3) + face_count] + verts_used) model_file.out_file_write('Shadow Table\n') shadow_count = model_file.read_uint_32() shadow_table = model_file.read_numpy([ ('file_id', numpy.uint64), ('file_type', numpy.uint32), ('X', numpy.uint32), ('', numpy.uint32), ('Y', numpy.uint32), ('Z', numpy.uint32), ('W', numpy.uint32), ('', numpy.uint32), ], 36 * shadow_count) model_file.out_file_write(f'{shadow_table}\n') for index in range(2): count = model_file.read_uint_32() model_file.indent() model_file.read_bytes(count) model_file.indent(-1) model_file.out_file_write('Skin Data Table\n') skin_count = model_file.read_uint_32() skin_table = model_file.read_numpy([('file_id', numpy.uint64), ('file_type', numpy.uint32), ('', numpy.int8), ('', numpy.uint32), ('bone_count', numpy.uint16), ('', numpy.int8, 11), ('bones', numpy.uint16, 128)], 286 * skin_count) model_file.out_file_write(f'{skin_table}\n') model_file.read_bytes(8) model_file.out_file_write('Model Scale?\n') model_scale = model_file.read_float_32( ) # model scale? (looks to be the magnitude of sc in the vert table) self._vertices *= model_scale model_file.out_file_write('Material Table\n') material_count = model_file.read_uint_32() material_table = model_file.read_numpy([('', numpy.uint16), ('file_id', numpy.uint64)], 10 * material_count) model_file.out_file_write(f'{material_table}\n') self._materials = material_table['file_id'] model_file.read_rest() else: raise Exception("Error reading model file!")
def __init__(self, file_object_data_wrapper: FileObjectDataWrapper): check_byte = file_object_data_wrapper.read_uint_8( ) # checkbyte 03 to continue (other stuff to not? have seen 00 with data after) if check_byte == 0: for _ in range(2): file_object_data_wrapper.read_file() file_object_data_wrapper.out_file_write('Transformation Matrix\n') self.transformation_matrix = file_object_data_wrapper.read_numpy( numpy.float32, 64).reshape((4, 4), order='F') file_object_data_wrapper.out_file_write('\n') count1 = file_object_data_wrapper.read_uint_32() if count1 > 10000: logging.warning('error reading entity file') # convert to an actual logger raise Exception self.nested_files = [] for _ in range(count1): file_object_data_wrapper.out_file_write('\n') file_object_data_wrapper.indent() if file_object_data_wrapper.read_bytes(2) not in [ b'\x04\x00', b'\x00\x01' ]: # 04 00 raise Exception file_object_data_wrapper.indent(-1) self.nested_files.append(file_object_data_wrapper.read_file()) # float * 7 # 37 bytes # 2 bytes # float # bouding box # id # type # float32 * 6 # int32 # entity descriptor # 19 bytes file_object_data_wrapper.out_file_write('\n') file_object_data_wrapper.read_bytes(43) # data layer filter # 4 count, more data in here sometimes for _ in range(3): file_object_data_wrapper.read_file() # 03 end file? check_byte_2 = file_object_data_wrapper.read_uint_8() if check_byte_2 == 0: file_object_data_wrapper.read_file() elif check_byte_2 != 3: raise Exception file_object_data_wrapper.out_file_write('\n')