예제 #1
0
 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)
예제 #2
0
    def read(self, reader: ByteIO):

        entry = reader.tell()
        self.vertex_count = reader.read_uint32()
        self.vertex_offset = reader.read_uint32()
        self.index_count = reader.read_uint32()
        self.index_offset = reader.read_uint32()
        self.strip_count = reader.read_uint32()
        self.strip_offset = reader.read_uint32()
        self.flags = StripGroupFlags(reader.read_uint8())
        global extra_8
        if extra_8:
            self.topology_indices_count = reader.read_uint32()
            self.topology_offset = reader.read_uint32()

        with reader.save_current_pos():
            reader.seek(entry + self.index_offset)
            for _ in range(self.index_count):
                self.vtx_indexes.append(reader.read_uint16())
            reader.seek(entry + self.vertex_offset)
            for _ in range(self.vertex_count):
                SourceVtxVertex().read(reader, self)
            reader.seek(entry + self.strip_offset)
            for _ in range(self.strip_count):
                SourceVtxStrip().read(reader, self)
            if extra_8:
                reader.seek(entry + self.topology_offset)
                # for _ in range(self.topology_indices_count):
                self.topology = (reader.read_bytes(self.topology_indices_count * 2))

        return self
예제 #3
0
    def read(self, reader: ByteIO, MDL: SourceMdlFileData):
        entry = reader.tell()
        self.entry = entry
        self.baseHeaderOffset = reader.read_int32()
        self.nameOffset = reader.read_int32()
        self.theName = reader.read_from_offset(entry + self.nameOffset, reader.read_ascii_string)
        self.fps = reader.read_float()
        self.flags = self.STUDIO(reader.read_uint32())
        self.frameCount = reader.read_uint32()
        self.movementCount = reader.read_uint32()
        self.movementOffset = reader.read_uint32()

        self.unused1 = [reader.read_uint32() for _ in range(6)]
        self.animBlock = reader.read_uint32()
        self.animOffset = reader.read_uint32()


        self.ikRuleCount = reader.read_uint32()
        self.ikRuleOffset = reader.read_uint32()
        self.animblockIkRuleOffset = reader.read_uint32()
        self.localHierarchyCount = reader.read_uint32()
        self.localHierarchyOffset = reader.read_uint32()


        self.sectionOffset = reader.read_uint32()
        self.sectionFrameCount = reader.read_uint32()

        self.spanFrameCount = reader.read_uint16()
        self.spanCount = reader.read_uint16()
        self.spanOffset = reader.read_uint32()
        self.spanStallTime = reader.read_float()
        self.fileOffsetStart2 = entry + self.spanOffset
        self.fileOffsetEnd2 = entry + self.spanOffset-1
        if self.spanFrameCount!=0 or self.spanCount!=0 or self.spanOffset!=0 or self.spanStallTime!=0:
            for bone_index in range(len(MDL.bones)):
                bone = MDL.bones[bone_index] #type: SourceMdlBone
                if bone.flags & SourceMdlBone.BONE_HAS_SAVEFRAME_POS:
                    self.fileOffsetEnd2 += self.spanCount * 6
                if bone.flags & SourceMdlBone.BONE_HAS_SAVEFRAME_ROT:
                    self.fileOffsetEnd2 += self.spanCount * 8




        return self
예제 #4
0
 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
예제 #5
0
 def read(self, reader: ByteIO):
     fourcc = reader.read_bytes(4)
     assert tuple(fourcc) == self.SIG, 'Invalid KV Signature'
     encoding = reader.read_bytes(16)
     assert tuple(encoding) == self.ENCODING, 'Unrecognized KV3 Encoding'
     format = reader.read_bytes(16)
     assert tuple(format) == self.FORMAT, 'Unrecognised KV3 Format'
     self.flags = reader.read_bytes(4)
     if self.flags[3] & 0x80:
         self.buffer.write_bytes(
             reader.read_bytes(self.info_block.block_size -
                               (reader.tell() -
                                self.info_block.absolute_offset)))
     working = True
     while reader.tell() != reader.size() and working:
         block_mask = reader.read_uint16()
         for i in range(16):
             if block_mask & (1 << i) > 0:
                 offset_and_size = reader.read_uint16()
                 offset = ((offset_and_size & 0xFFF0) >> 4) + 1
                 size = (offset_and_size & 0x000F) + 3
                 lookup_size = offset if offset < size else size
                 entry = self.buffer.tell()
                 self.buffer.seek(entry - offset)
                 data = self.buffer.read_bytes(lookup_size)
                 self.buffer.seek(entry)
                 while size > 0:
                     self.buffer.write_bytes(
                         data[:lookup_size if lookup_size < size else size])
                     size -= lookup_size
             else:
                 data = reader.read_int8()
                 self.buffer.write_int8(data)
             if self.buffer.size() == (self.flags[2] << 16) + (
                     self.flags[1] << 8) + self.flags[0]:
                 working = False
                 break
     self.buffer.seek(0)
     string_count = self.buffer.read_uint32()
     for i in range(string_count):
         self.strings.append(self.buffer.read_ascii_string())
     self.parse(self.buffer, self.kv, True)
     self.buffer.close()
     del self.buffer
예제 #6
0
    def read(self, reader: ByteIO):
        self.version = reader.read_uint32()
        if self.version!=7:
            if self.version == 402653184:
                reader.insert_begin(b'\x07')
                self.version = reader.read_uint32()
                print('VTX FILE WAS "PROTECTED", but screew it :P')
            else:
                raise NotImplementedError('VTX version {} is not supported!'.format(self.version))
        self.vertex_cache_size = reader.read_uint32()
        self.max_bones_per_strip = reader.read_uint16()
        self.max_bones_per_tri = reader.read_uint16()
        self.max_bones_per_vertex = reader.read_uint32()
        self.checksum = reader.read_uint32()
        self.lodCount = reader.read_uint32()
        self.material_replacement_list_offset = reader.read_uint32()
        self.bodyPartCount = reader.read_uint32()
        self.bodyPartOffset = reader.read_uint32()
        global max_bones_per_vertex
        max_bones_per_vertex = self.max_bones_per_vertex
        if self.bodyPartOffset > 0:

            reader.seek(self.bodyPartOffset)
            try:
                for _ in range(self.bodyPartCount):
                    self.vtx_body_parts.append(SourceVtxBodyPart().read(reader))
            except struct.error:
                global extra_8
                extra_8 = False
                self.vtx_body_parts.clear()
                reader.seek(self.bodyPartOffset)
                for _ in range(self.bodyPartCount):
                    self.vtx_body_parts.append(SourceVtxBodyPart().read(reader))
        if self.material_replacement_list_offset > 0:
            reader.seek(self.material_replacement_list_offset)
            for _ in range(self.lodCount):
                self.material_replacement_lists.append(MaterialReplacementList().read(reader))
예제 #7
0
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)
예제 #8
0
    def read(self, reader: ByteIO, stripgroup: SourceVtxStripGroup):
        entry = reader.tell()
        self.index_count = reader.read_uint32()
        self.index_mesh_index = reader.read_uint32()
        self.vertex_count = reader.read_uint32()
        self.vertex_mesh_index = reader.read_uint32()
        self.bone_count = reader.read_uint16()
        self.flags = StripHeaderFlags(reader.read_uint8())
        self.bone_state_change_count = reader.read_uint32()
        self.bone_state_change_offset = reader.read_uint32()
        global extra_8
        if extra_8:
            self.topology_indices_count = reader.read_int32()
            self.topology_offset = reader.read_int32()
        # print('Strip end',reader.tell())

        stripgroup.vtx_strips.append(self)
예제 #9
0
 def read(self, reader: ByteIO):
     self.value_16bit = reader.read_uint16()
     return self
예제 #10
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))