Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 def read(self, reader: ByteIO, block_info: InfoBlock = None):
     self.info_block = block_info
     entry = reader.tell()
     self.name_offset = reader.read_int32()
     self.name = reader.read_from_offset(entry + self.name_offset,
                                         reader.read_ascii_string)
     self.count = reader.read_int16()
     self.on_disc_size = reader.read_int16()
     entry = reader.tell()
     self.indirection_bytes_offset = reader.read_int32()
     self.indirection_level = reader.read_int32()
     with reader.save_current_pos():
         reader.seek(entry + self.indirection_bytes_offset)
         indir_level = self.indirection_level if self.indirection_level < 10 else 10
         for _ in range(indir_level):
             self.indirection_bytes.append(reader.read_int8())
     self.data_type = reader.read_int32()
     self.type = KeyValueDataType(reader.read_int16())
     reader.skip(2)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
 def read(self, reader: ByteIO):
     self.introspection_version = reader.read_int32()
     self.s_id = reader.read_int32()
     entry = reader.tell()
     self.name_offset = reader.read_int32()
     self.name = reader.read_from_offset(entry + self.name_offset,
                                         reader.read_ascii_string)
     self.disc_crc = reader.read_int32()
     self.user_version = reader.read_int32()
     self.disc_size = reader.read_int16()
     self.aligment = reader.read_int16()
     self.base_struct_id = reader.read_int32()
     entry = reader.tell()
     self.field_offset = reader.read_int32()
     self.field_count = reader.read_int32()
     self.struct_flags = reader.read_int32()
     with reader.save_current_pos():
         reader.seek(entry + self.field_offset)
         for n in range(self.field_count):
             field = NTROStructField(self)
             field.read(reader)
             self.fields.append(field)
Exemplo n.º 5
0
 def read(self, reader: ByteIO):
     self.animXValueOffset = reader.read_int16()
     self.animYValueOffset = reader.read_int16()
     self.animZValueOffset = reader.read_int16()
Exemplo n.º 6
0
    def read(self, frame_count, anim_section, mdl: SourceMdlFileData, reader: ByteIO):
        anim_entry = reader.tell()
        self.boneIndex = reader.read_uint8()
        print('BoneIndex:',self.boneIndex)
        try:
            self.bone_name = mdl.bones[self.boneIndex].name
        except:
            self.bone_name = "ERROR"
        print('BoneName:',self.bone_name)
        if self.boneIndex == 255:
            reader.skip(3)
            return self, 0
        if self.boneIndex >= mdl.bone_count:
            print('Bone index out of range {} - {}'.format(self.boneIndex, mdl.bone_count))
            return self, 0
        self.flags = reader.read_uint8()
        self.sflags = self.STUDIO_ANIM.get_flags(self.flags)
        self.nextSourceMdlAnimationOffset = reader.read_int16()
        pdata = reader.tell()
        print('Seq flag',self.flags,self.sflags)
        if (self.flags & self.STUDIO_ANIM.RAWROT2) > 0:
            with reader.save_current_pos():
                reader.seek(pdata)
                self.theRot64bits.read(reader)
                print('Rot 64',self.theRot64bits)

        if (self.flags & self.STUDIO_ANIM.RAWROT) > 0:
            with reader.save_current_pos():
                reader.seek(pdata)
                self.theRot48bits.read(reader)
                print('Rot 48', self.theRot48bits)

        if (self.flags & self.STUDIO_ANIM.RAWPOS) > 0:
            with reader.save_current_pos():
                reader.seek(pdata+(((self.flags & self.STUDIO_ANIM.RAWROT) != 0)*6) + ((self.flags & self.STUDIO_ANIM.RAWROT2) != 0)*8)
                self.thePos.read(reader)
                print('Pos', self.thePos)

        if (self.flags & self.STUDIO_ANIM.ANIMROT) > 0:
            with reader.save_current_pos():
                rotV_entry = reader.tell()
                reader.seek(pdata)
                self.theRotV.read(reader)
                self.theRotV.read_values(rotV_entry, frame_count, reader)
                print('Rot V', self.theRotV)

        if (self.flags & self.STUDIO_ANIM.ANIMPOS) > 0:
            with reader.save_current_pos():
                reader.seek(((self.flags & self.STUDIO_ANIM.ANIMPOS)!=0) + pdata)
                posV_entry = reader.tell()
                self.thePosV.read(reader)
                self.thePosV.read_values(posV_entry, frame_count, reader)
                print('Pos V', self.thePosV)
        print('\n')
        pprint(self.__dict__)
        print('\n')
        if self.nextSourceMdlAnimationOffset == 0:
            print('DONE WITH ANIMATIONS')
            reader.seek(pdata)
            return self, -1
        else:
            nextAnimationInputFileStreamPosition = anim_entry + self.nextSourceMdlAnimationOffset
            if nextAnimationInputFileStreamPosition < reader.tell():
                print('PROBLEM! Should not be going backwards in file.')
                # raise BufferError('PROBLEM! Should not be going backwards in file.')
            reader.seek(nextAnimationInputFileStreamPosition)

        anim_section.append(self)

        return self, 1
Exemplo n.º 7
0
 def read_from_buffer(self, reader: ByteIO):
     if self.format == DXGI_FORMAT.R32G32B32_FLOAT:
         return [
             reader.read_float()
             for _ in range(self.format.name.count('32'))
         ]
     elif self.format == DXGI_FORMAT.R32G32B32_UINT:
         return [
             reader.read_uint32()
             for _ in range(self.format.name.count('32'))
         ]
     elif self.format == DXGI_FORMAT.R32G32B32_SINT:
         return [
             reader.read_int32()
             for _ in range(self.format.name.count('32'))
         ]
     elif self.format == DXGI_FORMAT.R32G32B32A32_FLOAT:
         return [
             reader.read_float()
             for _ in range(self.format.name.count('32'))
         ]
     elif self.format == DXGI_FORMAT.R32G32B32A32_UINT:
         return [
             reader.read_uint32()
             for _ in range(self.format.name.count('32'))
         ]
     elif self.format == DXGI_FORMAT.R32G32B32A32_SINT:
         return [
             reader.read_int32()
             for _ in range(self.format.name.count('32'))
         ]
     elif self.format == DXGI_FORMAT.R16G16_FLOAT:
         return [
             short_to_float(reader.read_int16())
             for _ in range(self.format.name.count('16'))
         ]
     elif self.format == DXGI_FORMAT.R32G32_FLOAT:
         return [
             short_to_float(reader.read_float())
             for _ in range(self.format.name.count('32'))
         ]
     elif self.format == DXGI_FORMAT.R16G16_SINT:
         return [
             reader.read_int16()
             for _ in range(self.format.name.count('16'))
         ]
     elif self.format == DXGI_FORMAT.R16G16_UINT:
         return [
             reader.read_uint16()
             for _ in range(self.format.name.count('16'))
         ]
     elif self.format == DXGI_FORMAT.R8G8B8A8_SNORM:
         return [
             reader.read_int8() for _ in range(self.format.name.count('8'))
         ]
     elif self.format == DXGI_FORMAT.R8G8B8A8_UNORM:
         return [
             reader.read_uint8() for _ in range(self.format.name.count('8'))
         ]
     elif self.format == DXGI_FORMAT.R8G8B8A8_UINT:
         return [
             reader.read_uint8() for _ in range(self.format.name.count('8'))
         ]
     else:
         raise NotImplementedError('Unknown buffer format {}'.format(
             self.format.name))