def __init__(self, filepath): try: from Source2.Blocks.NTRO import NTRO from Source2.Blocks.REDI import REDI from Source2.Blocks.RERP import RERL from Source2.Blocks.VBIB import VBIB from Source2.Blocks.DATA import DATA except: from .Blocks.NTRO import NTRO from .Blocks.REDI import REDI from .Blocks.RERP import RERL from .Blocks.VBIB import VBIB from .Blocks.DATA import DATA print('Reading {}'.format(filepath)) self.reader = ByteIO( path=filepath, copy_data_from_handle=False, ) self.filepath = Path(filepath) self.filename = self.filepath.stem self.filepath = os.path.abspath(os.path.dirname(filepath)) self.header = CompiledHeader() self.header.read(self.reader) self.blocks_info = [] # type: List[InfoBlock] self.rerl = RERL(self) self.nrto = NTRO(self) self.redi = REDI(self) self.vbib = VBIB(self) self.data = DATA(self) self.available_resources = {}
def read_header00(self, reader: ByteIO): self.id = ''.join(list([chr(reader.read_uint8()) for _ in range(4)])) self.version = reader.read_uint32() print('Found MDL version', self.version) # self.checksum = reader.read_uint32() self.name = reader.read_ascii_string(64) self.file_size = reader.read_uint32()
def read(self, reader: ByteIO, stripgroup: SourceVtxStripGroup): global max_bones_per_vertex self.bone_weight_index = [reader.read_uint8() for _ in range(max_bones_per_vertex)] self.bone_count = reader.read_uint8() self.original_mesh_vertex_index = reader.read_uint16() self.bone_id = [reader.read_uint8() for _ in range(max_bones_per_vertex)] stripgroup.vtx_vertexes.append(self)
def read(self, reader: ByteIO): self.r_id = reader.read_int64() entry = reader.tell() self.resource_name_offset = reader.read_int64() if self.resource_name_offset: self.resource_name = reader.read_from_offset( entry + self.resource_name_offset, reader.read_ascii_string)
def read(self, reader: ByteIO): entry = reader.tell() self.material_id = reader.read_int16() self.replacement_material_name_offset = reader.read_int32() self.replacement_material_name = reader.read_from_offset(self.replacement_material_name_offset, reader.read_ascii_string) return self
def __init__(self, filepath): self.reader = ByteIO(path=filepath + '.mdl', copy_data_from_handle=False, ) self.filename = os.path.basename(filepath + '.mdl')[:-4] self.file_data = SourceMdlFileDataV10() self.file_data.read(self.reader) self.read_bones() self.read_bone_controllers() self.read_skin_families()
def read(self, reader: ByteIO): entry = reader.tell() self.model_count, self.model_offset = reader.read_fmt('II') with reader.save_current_pos(): reader.seek(entry + self.model_offset) for _ in range(self.model_count): self.vtx_models.append(SourceVtxModel().read(reader)) return self
def read(self, reader: ByteIO): entry = reader.tell() self.lodCount, self.lodOffset = reader.read_fmt('ii') with reader.save_current_pos(): if self.lodCount > 0 and self.lodOffset != 0: reader.seek(entry + self.lodOffset) for _ in range(self.lodCount): self.vtx_model_lods.append(SourceVtxModelLod().read(reader, self)) return self
def read(self, reader: ByteIO): self.endframeIndex = reader.read_uint32() self.motionFlags = reader.read_uint32() self.v0 = reader.read_float() self.v1 = reader.read_float() self.angle = reader.read_float() self.vector.read(reader) self.position.read(reader) return self
def read_struct(self, reader: ByteIO): # print('Reading struct {}'.format(self.name)) struct_data = {} entry = reader.tell() for field in self.fields: reader.seek(entry + field.on_disc_size) struct_data[field.name] = field.read_field(reader) # print(struct_data) reader.seek(entry + self.disc_size) # print(struct_data) return struct_data
def read(self, reader: ByteIO, block_info: InfoBlock = None): self.info_block = block_info with reader.save_current_pos(): fourcc = reader.read_bytes(4) if tuple(fourcc) == (0x56, 0x4B, 0x56, 0x03): kv = BinaryKeyValue(self.info_block) kv.read(reader) self.data = kv.kv else: for struct in self.valve_file.nrto.structs[:1]: self.data[struct.name] = struct.read_struct(reader)
def read(self, reader: ByteIO): entry = reader.tell() self.replacements_count = reader.read_int32() self.replacement_offset = reader.read_int32() with reader.save_current_pos(): reader.seek(entry + self.replacement_offset) for _ in range(self.replacements_count): mat = MaterialReplacement() mat.read(reader) self.replacements.append(mat) return self
class SourceMdlFile10: def __init__(self, filepath): self.reader = ByteIO(path=filepath + '.mdl', copy_data_from_handle=False, ) self.filename = os.path.basename(filepath + '.mdl')[:-4] self.file_data = SourceMdlFileDataV10() self.file_data.read(self.reader) self.read_bones() self.read_bone_controllers() self.read_skin_families() # self.read_attachments() # self.read_mouths() # self.read_bone_flex_drivers() # self.read_flex_controllers_ui() # self.read_body_parts() # self.read_textures() # self.read_texture_paths() # self.build_flex_frames() # self.prepare_models() # # self.read_local_animation_descs() # self.read_sequences() # # print(self.mdl) def read_bones(self): if self.file_data.bone_count > 0: pb = Progress_bar(desc='Reading bones', max_=self.file_data.bone_count, len_=20) self.reader.seek(self.file_data.bone_offset, 0) for i in range(self.file_data.bone_count): pb.draw() SourceMdlBone().read(self.reader, self.file_data) pb.increment(1) pb.draw() def read_bone_controllers(self): if self.file_data.bone_controller_count > 0: pb = Progress_bar(desc='Reading Bone Controllers', max_=self.file_data.bone_controller_count, len_=20) for _ in range(self.file_data.bone_controller_count): pb.draw() SourceMdlBoneController().read(self.reader, self.file_data) pb.increment(1) def read_skin_families(self): if self.file_data.skin_family_count and self.file_data.skin_reference_count: self.reader.seek(self.file_data.skin_family_offset) for _ in range(self.file_data.skin_family_count): skin_ref = [] for _ in range(self.file_data.skin_reference_count): skin_ref.append(self.reader.read_int16()) self.file_data.skin_families.append(skin_ref) def test(self): for bone in self.file_data.bones: print(bone)
def read(self, reader: ByteIO): entry = reader.tell() self.name = reader.read_ascii_string() reader.seek(entry + 36) self.format = DXGI_FORMAT(reader.read_int32()) self.offset = reader.read_uint32() reader.skip(12)
def read(self, reader: ByteIO): entry = reader.tell() self.nameOffset = reader.read_uint32() self.thePathFileName = reader.read_from_offset( entry + self.nameOffset, reader.read_ascii_string) self.flags = reader.read_uint32() self.used = reader.read_uint32() self.unused1 = reader.read_uint32() self.materialP = reader.read_uint32() self.clientMaterialP = reader.read_uint32() self.unused = [reader.read_uint32() for _ in range(5)]
def __init__(self, path=None, file=None): if path: self.reader = ByteIO(path=path + ".vvd") elif file: self.reader = file self.file_data = SourceVvdFileData() self.file_data.read(self.reader)
def read(self, reader: ByteIO): self.boneWeight.read(reader) self.position.read(reader) self.normal.read(reader) self.texCoordX = reader.read_float() self.texCoordY = reader.read_float() return self
def read(self, reader: ByteIO): entry = reader.tell() self.string_offset = reader.read_int32() self.string = reader.read_from_offset(entry + self.string_offset, reader.read_ascii_string) entry = reader.tell() self.compiler_identifier_offset = reader.read_int32() self.compiler_identifier = reader.read_from_offset(entry + self.compiler_identifier_offset, reader.read_ascii_string) self.fingerprint = reader.read_uint32() self.user_data = reader.read_uint32()
def parse(self, reader: ByteIO, parent=None, in_array=False): name = None parent = parent if not in_array: string_id = reader.read_uint32() name = "ERROR" if string_id == -1 else self.strings[string_id] add = lambda v: parent.update({name: v} ) if not in_array else parent.append(v) data_type = reader.read_int8() flag_info = KVFlag.Nothing if data_type & 0x80: data_type &= 0x7F flag_info = KVFlag(reader.read_int8()) if data_type == KVType.NULL: add(None) return if data_type == KVType.BOOLEAN: add(reader.read_int8() > 0) return if data_type == KVType.INTEGER: add(reader.read_int64()) return if data_type == KVType.DOUBLE: add(reader.read_double()) return if data_type == KVType.STRING: string_id = reader.read_int32() if string_id == -1: add(None) return add(self.strings[string_id]) return if data_type == KVType.ARRAY: size = reader.read_uint32() arr = [] for _ in range(size): self.parse(reader, arr, True) add(arr) return if data_type == KVType.OBJECT: size = reader.read_uint32() tmp = {} for _ in range(size): self.parse(reader, tmp, False) add(tmp) if not parent: parent = tmp return parent
def __init__(self, path=None, file=None): self.final = False if path: self.reader = ByteIO(path=path + ".dx90.vtx") elif file: self.reader = file # print('Reading VTX file') self.vtx = SourceVtxFileData() self.read_source_vtx_header()
def read(self, reader: ByteIO): entry = reader.tell() self.content_relative_name_offset = reader.read_int32() self.content_relative_name = reader.read_from_offset(entry + self.content_relative_name_offset, reader.read_ascii_string) entry = reader.tell() self.content_search_path_offset = reader.read_int32() self.content_search_path = reader.read_from_offset(entry + self.content_search_path_offset, reader.read_ascii_string) self.file_crc = reader.read_int32() self.flag = reader.read_int32()
def read(self, reader: ByteIO): entry = reader.tell() self.parameter_name_offset = reader.read_int32() self.parameter_name = reader.read_from_offset(entry + self.parameter_name_offset, reader.read_ascii_string) entry = reader.tell() self.parameter_type_offset = reader.read_int32() self.parameter_type = reader.read_from_offset(entry + self.parameter_type_offset, reader.read_ascii_string) self.fingerprint = reader.read_uint32() self.fingerprint_default = reader.read_uint32()
def read(self, reader: ByteIO): entry = reader.tell() self.scale = [reader.read_uint32() for _ in range(6)] self.offset = [reader.read_uint32() for _ in range(6)] for offset in self.offset: with reader.save_current_pos(): reader.seek(entry + offset) self.theAnimValues.append(SourceMdlAnimationValue(reader.read_uint16())) return self
def read(self, reader: ByteIO): entry = reader.tell() self.strip_group_count = reader.read_uint32() self.strip_group_offset = reader.read_uint32() self.flags = reader.read_uint8() with reader.save_current_pos(): if self.strip_group_offset > 0: reader.seek(entry + self.strip_group_offset) for _ in range(self.strip_group_count): self.vtx_strip_groups.append(SourceVtxStripGroup().read(reader)) return self
def read(self, reader: ByteIO, mdl: SourceMdlFileDataV10): self.boneIndex = reader.read_uint32() self.type = reader.read_uint32() self.startBlah = reader.read_uint32() self.endBlah = reader.read_uint32() self.restIndex = reader.read_uint32() self.inputField = reader.read_uint32() if mdl.version > 10: self.unused = [reader.read_uint32() for _ in range(8)] mdl.bone_controllers.append(self) return self
def read(self,reader:ByteIO): entry = reader.tell() self.cycle = reader.read_float() self.eventIndex = reader.read_uint32() self.eventType = reader.read_uint32() self.options = [reader.read_uint8() for _ in range(64)] self.nameOffset = reader.read_uint32() if self.nameOffset: self.theName = reader.read_from_offset(self.nameOffset+entry,reader.read_ascii_string) else: self.theName = str(self.eventIndex) return self
def read(self, reader: ByteIO, model: SourceVtxModel): entry = reader.tell() self.lod = len(model.vtx_model_lods) self.meshCount = reader.read_uint32() self.meshOffset = reader.read_uint32() self.switchPoint = reader.read_float() with reader.save_current_pos(): if self.meshOffset > 0: reader.seek(entry + self.meshOffset) for _ in range(self.meshCount): self.vtx_meshes.append(SourceVtxMesh().read(reader)) return self
class IndexBuffer(Dummy): def __init__(self): self.count = 0 self.size = 0 self.offset = 0 self.unk1 = 0 self.unk2 = 0 self.total_size = 0 self.buffer = None # type:ByteIO self.indexes = [] def __repr__(self): return '<IndexBuffer indexes:{} size:{}>'.format(self.count, self.size) def read(self, reader: ByteIO): self.count = reader.read_uint32() self.size = reader.read_uint32() self.unk1 = reader.read_uint32() self.unk2 = reader.read_uint32() entry = reader.tell() self.offset = reader.read_uint32() self.total_size = reader.read_uint32() with reader.save_current_pos(): reader.seek(entry + self.offset) assert self.total_size == self.size * self.count self.buffer = ByteIO(byte_object=reader.read_bytes(self.count * self.size)) self.read_buffer() def read_buffer(self): for n in range(0, self.count, 3): polygon = [ self.buffer.read_uint16(), self.buffer.read_uint16(), self.buffer.read_uint16() ] self.indexes.append(polygon)
def read(self, reader: ByteIO): entry = reader.tell() self.name_offset = reader.read_int32() self.name = reader.read_from_offset(entry + self.name_offset, reader.read_ascii_string) entry = reader.tell() self.value_offset = reader.read_int32() self.value = reader.read_from_offset(entry + self.value_offset, reader.read_ascii_string)
def read(self, reader: ByteIO, mdl: SourceMdlFileDataV10): self.boneOffset = reader.tell() self.name = reader.read_ascii_string(32) self.parentBoneIndex = reader.read_int32() self.flags = reader.read_int32() self.boneControllerIndex = [reader.read_int32() for _ in range(6)] self.position.read(reader) self.rotation.read(reader) self.scale = [reader.read_float() for _ in range(6)] mdl.bones.append(self)