diff --git a/Crowbar/Core/- Application/AppEnums.vb b/Crowbar/Core/- Application/AppEnums.vb index d64db330..699ae576 100644 --- a/Crowbar/Core/- Application/AppEnums.vb +++ b/Crowbar/Core/- Application/AppEnums.vb @@ -189,4 +189,19 @@ Public Module AppEnums [Decimal] End Enum + Public Enum BoltonType + Hair + Glasses + Masks + Bracelet1 + Bracelet2 + Earring1 + Earring2 + Hat + Ring1 + Ring2 + Pin1 + Pin2 + End Enum + End Module diff --git a/Crowbar/Core/- Application/AppSettings.vb b/Crowbar/Core/- Application/AppSettings.vb index ec872f84..12e4d15e 100644 --- a/Crowbar/Core/- Application/AppSettings.vb +++ b/Crowbar/Core/- Application/AppSettings.vb @@ -767,6 +767,16 @@ Public Class AppSettings End Set End Property + Public Property IsPostal3IsChecked() As Boolean + Get + Return Me.theIsPostal3IsChecked + End Get + Set(ByVal value As Boolean) + Me.theIsPostal3IsChecked = value + NotifyPropertyChanged("IsPostal3IsChecked") + End Set + End Property + Public Property DecompileRemovePathFromSmdMaterialFileNamesIsChecked() As Boolean Get Return Me.theDecompileRemovePathFromSmdMaterialFileNamesIsChecked @@ -1913,6 +1923,7 @@ Public Class AppSettings Private theDecompileVertexAnimationVtaFileIsChecked As Boolean Private theDecompileProceduralBonesVrdFileIsChecked As Boolean + Private theIsPostal3IsChecked As Boolean Private theDecompileDeclareSequenceQciFileIsChecked As Boolean Private theDecompileFolderForEachModelIsChecked As Boolean diff --git a/Crowbar/Core/GameModel/- Base/SourceModel.vb b/Crowbar/Core/GameModel/- Base/SourceModel.vb index 447613f0..45993401 100644 --- a/Crowbar/Core/GameModel/- Base/SourceModel.vb +++ b/Crowbar/Core/GameModel/- Base/SourceModel.vb @@ -116,12 +116,25 @@ Public MustInherit Class SourceModel Dim id As String id = inputFileReader.ReadChars(4) - version = inputFileReader.ReadInt32() + If id = "LZMA" Then + Throw New FormatException("File with header ID (first 4 bytes of file) of 'LZMA' (without quotes) means it is a compressed model file. Please decompress it first with the QuickBMS script.") + End If + If id = "TSDI" Then + Dim bytes() As Byte = inputFileReader.ReadBytes(4) + Dim b1 As Integer = (bytes(0) >> 0) And &HFF + Dim b2 As Integer = (bytes(1) >> 8) And &HFF + Dim b3 As Integer = (bytes(2) >> 16) And &HFF + Dim b4 As Integer = (bytes(3) >> 24) And &HFF + version = b1 << 24 Or b2 << 16 Or b3 << 8 Or b4 << 0 + Else + version = inputFileReader.ReadInt32() + End If + If id = "MDLZ" Then If version <> 14 Then Throw New FormatException("File with header ID (first 4 bytes of file) of 'MDLZ' (without quotes) does not have expected MDL version of 14. MDL file is not a GoldSource- or Source-engine MDL file.") End If - ElseIf id <> "IDST" Then + ElseIf id <> "IDST" And id <> "TSDI" Then Throw New FormatException("File does not have expected MDL header ID (first 4 bytes of file) of 'IDST' or 'MDLZ' (without quotes). MDL file is not a GoldSource- or Source-engine MDL file.") End If Catch ex As FormatException diff --git a/Crowbar/Core/GameModel/- Base/SourceQcFile.vb b/Crowbar/Core/GameModel/- Base/SourceQcFile.vb index bcdc563c..974daae7 100644 --- a/Crowbar/Core/GameModel/- Base/SourceQcFile.vb +++ b/Crowbar/Core/GameModel/- Base/SourceQcFile.vb @@ -260,7 +260,11 @@ Public Class SourceQcFile length = textureFileNameMaxLengths(textureFileNameIndex) 'NOTE: Need at least "+ 2" to account for the double-quotes. - line += LSet("""" + aTextureFileName + """", length + 3) + If TheApp.Settings.IsPostal3IsChecked AndAlso textureFileNameIndex = 0 Then + line += LSet("""#Skin" + skinFamilyIndex.ToString() + """ """ + aTextureFileName + """", length + 16) + Else + line += LSet("""" + aTextureFileName + """", length + 3) + End If Next 'line += " " diff --git a/Crowbar/Core/GameModel/CompiledFiles/PhyFile/SourcePhyFile.vb b/Crowbar/Core/GameModel/CompiledFiles/PhyFile/SourcePhyFile.vb index c4a59f12..a92670b6 100644 --- a/Crowbar/Core/GameModel/CompiledFiles/PhyFile/SourcePhyFile.vb +++ b/Crowbar/Core/GameModel/CompiledFiles/PhyFile/SourcePhyFile.vb @@ -17,10 +17,54 @@ Public Class SourcePhyFile #Region "Methods" + ' Big endian binary reader functions + Public Function ReadInt32BE() As Integer + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(4) + Dim b1 As Integer = (bytes(0) >> 0) And &HFF + Dim b2 As Integer = (bytes(1) >> 8) And &HFF + Dim b3 As Integer = (bytes(2) >> 16) And &HFF + Dim b4 As Integer = (bytes(3) >> 24) And &HFF + + Return b1 << 24 Or b2 << 16 Or b3 << 8 Or b4 << 0 + End Function + + Public Function ReadInt16BE() As Short + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(2) + 'Dim b1 As Integer = (bytes(0) >> 0) And &HFF + 'Dim b2 As Integer = (bytes(1) >> 8) And &HFF + Array.Reverse(bytes) + + 'Return CShort(b1 << 8 Or b2 << 0) + Return BitConverter.ToInt16(bytes, 0) + End Function + + Public Function ReadUInt16BE() As UShort + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(2) + Dim b1 As Integer = (bytes(0) >> 0) And &HFF + Dim b2 As Integer = (bytes(1) >> 8) And &HFF + + Return CUShort(b1 << 8 Or b2 << 0) + End Function + + Public Function ReadSingleBE() As Single + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(4) + 'Dim b1 As Integer = (bytes(0) >> 0) And &HFF + 'Dim b2 As Integer = (bytes(1) >> 8) And &HFF + 'Dim b3 As Integer = (bytes(2) >> 16) And &HFF + 'Dim b4 As Integer = (bytes(3) >> 24) And &HFF + 'Dim num As Single = b1 << 24 Or b2 << 16 Or b3 << 8 Or b4 << 0 + Array.Reverse(bytes) + Dim num As Single = BitConverter.ToSingle(bytes, 0) + + Return num + End Function + Public Sub ReadSourcePhyHeader() Dim fileOffsetStart As Long Dim fileOffsetEnd As Long + Me.thePhyFileData.isBigEndian = False + fileOffsetStart = Me.theInputFileReader.BaseStream.Position ' Offsets: 0x00, 0x04, 0x08, 0x0C (12) @@ -29,10 +73,34 @@ Public Class SourcePhyFile '00 00 00 00 '12 00 00 00 '1f de 9d 20 - Me.thePhyFileData.size = Me.theInputFileReader.ReadInt32() - Me.thePhyFileData.id = Me.theInputFileReader.ReadInt32() - Me.thePhyFileData.solidCount = Me.theInputFileReader.ReadInt32() - Me.thePhyFileData.checksum = Me.theInputFileReader.ReadInt32() + + If Me.theInputFileReader.ReadInt32() > 16 Then + ' Possibly big endian, let's confirm this + Me.theInputFileReader.BaseStream.Seek(-4, SeekOrigin.Current) + If ReadInt32BE() = 16 Then + ' Big endian file + Me.thePhyFileData.isBigEndian = True + Me.theInputFileReader.BaseStream.Seek(-4, SeekOrigin.Current) + Else + ' Nevermind, continue as normal + Me.theInputFileReader.BaseStream.Seek(-4, SeekOrigin.Current) + End If + Else + ' Nevermind, continue as normal + Me.theInputFileReader.BaseStream.Seek(-4, SeekOrigin.Current) + End If + + If Me.thePhyFileData.isBigEndian Then + Me.thePhyFileData.size = ReadInt32BE() + Me.thePhyFileData.id = ReadInt32BE() + Me.thePhyFileData.solidCount = ReadInt32BE() + Me.thePhyFileData.checksum = ReadInt32BE() + Else + Me.thePhyFileData.size = Me.theInputFileReader.ReadInt32() + Me.thePhyFileData.id = Me.theInputFileReader.ReadInt32() + Me.thePhyFileData.solidCount = Me.theInputFileReader.ReadInt32() + Me.thePhyFileData.checksum = Me.theInputFileReader.ReadInt32() + End If 'NOTE: If header size ever increases, this will at least skip over extra stuff. Me.theInputFileReader.BaseStream.Seek(fileOffsetStart + Me.thePhyFileData.size, SeekOrigin.Begin) @@ -68,7 +136,12 @@ Public Class SourcePhyFile fileOffsetStart = Me.theInputFileReader.BaseStream.Position 'b8 01 00 00 size - collisionData.size = Me.theInputFileReader.ReadInt32() + If Me.thePhyFileData.isBigEndian Then + collisionData.size = ReadInt32BE() + Else + collisionData.size = Me.theInputFileReader.ReadInt32() + End If + nextSolidDataStreamPosition = Me.theInputFileReader.BaseStream.Position + collisionData.size phyDataStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -76,7 +149,7 @@ Public Class SourcePhyFile Dim vphyId(3) As Char vphyId = Me.theInputFileReader.ReadChars(4) Me.theInputFileReader.BaseStream.Seek(phyDataStreamPosition, SeekOrigin.Begin) - If vphyId <> "VPHY" Then + If vphyId <> "VPHY" And vphyId <> "YHPV" Then Me.ReadPhyData_VERSION37() Else Me.ReadPhyData_VERSION48() @@ -95,17 +168,37 @@ Public Class SourcePhyFile 'd0 00 00 00 '29 00 00 00 '04 15 00 00 - vertexDataOffset = Me.theInputFileReader.ReadInt32() + If Me.thePhyFileData.isBigEndian Then + vertexDataOffset = ReadInt32BE() + Else + vertexDataOffset = Me.theInputFileReader.ReadInt32() + End If + vertexDataStreamPosition = faceDataStreamPosition + vertexDataOffset - convexMesh.theBoneIndex = Me.theInputFileReader.ReadInt32() - 1 + If Me.thePhyFileData.isBigEndian Then + convexMesh.theBoneIndex = ReadInt32BE() - 1 + Else + convexMesh.theBoneIndex = Me.theInputFileReader.ReadInt32() - 1 + End If + Me.theBoneIndexes.Add(convexMesh.theBoneIndex) - ' flags: has_children: (self.flags >> 0) & 3 ' 0 = false; > 0 true - convexMesh.flags = Me.theInputFileReader.ReadInt32() + If Me.thePhyFileData.isBigEndian Then + ' flags: has_children: (self.flags >> 0) & 3 ' 0 = false; > 0 true + convexMesh.flags = ReadInt32BE() + + '0c 00 00 00 count of lines after this (00 - 0b) + triangleCount = ReadInt16BE() + ReadInt16BE() + Else + ' flags: has_children: (self.flags >> 0) & 3 ' 0 = false; > 0 true + convexMesh.flags = Me.theInputFileReader.ReadInt32() + + '0c 00 00 00 count of lines after this (00 - 0b) + triangleCount = Me.theInputFileReader.ReadInt32() + End If - '0c 00 00 00 count of lines after this (00 - 0b) - triangleCount = Me.theInputFileReader.ReadInt32() '00 b0 00 00 ' 00 00 06 00 ' vertex index 00 @@ -162,12 +255,23 @@ Public Class SourcePhyFile ' de 7f For i As Integer = 0 To triangleCount - 1 Dim phyTriangle As New SourcePhyFace() - triangleIndex = Me.theInputFileReader.ReadByte() - Me.theInputFileReader.ReadByte() + If Me.thePhyFileData.isBigEndian Then + Me.theInputFileReader.ReadByte() + triangleIndex = Me.theInputFileReader.ReadByte() + Else + triangleIndex = Me.theInputFileReader.ReadByte() + Me.theInputFileReader.ReadByte() + End If + Me.theInputFileReader.ReadUInt16() For j As Integer = 0 To 2 - phyTriangle.vertexIndex(j) = Me.theInputFileReader.ReadUInt16() + If Me.thePhyFileData.isBigEndian Then + phyTriangle.vertexIndex(j) = ReadUInt16BE() + Else + phyTriangle.vertexIndex(j) = Me.theInputFileReader.ReadUInt16() + End If + Me.theInputFileReader.ReadUInt16() If Not vertices.Contains(phyTriangle.vertexIndex(j)) Then vertices.Add(phyTriangle.vertexIndex(j)) @@ -200,10 +304,17 @@ Public Class SourcePhyFile For i As Integer = 0 To vertices.Count - 1 Dim phyVertex As New SourcePhyVertex() - phyVertex.vertex.x = Me.theInputFileReader.ReadSingle() - phyVertex.vertex.y = Me.theInputFileReader.ReadSingle() - phyVertex.vertex.z = Me.theInputFileReader.ReadSingle() - w = Me.theInputFileReader.ReadSingle() + If Me.thePhyFileData.isBigEndian Then + phyVertex.vertex.x = ReadSingleBE() + phyVertex.vertex.y = ReadSingleBE() + phyVertex.vertex.z = ReadSingleBE() + w = ReadSingleBE() + Else + phyVertex.vertex.x = Me.theInputFileReader.ReadSingle() + phyVertex.vertex.y = Me.theInputFileReader.ReadSingle() + phyVertex.vertex.z = Me.theInputFileReader.ReadSingle() + w = Me.theInputFileReader.ReadSingle() + End If convexMesh0Vertices.Add(phyVertex) Next @@ -304,8 +415,13 @@ Public Class SourcePhyFile '00 01 version? '00 00 model type? - tempInt = Me.theInputFileReader.ReadUInt16() - tempInt = Me.theInputFileReader.ReadUInt16() + If Me.thePhyFileData.isBigEndian Then + tempInt = ReadUInt16BE() + tempInt = ReadUInt16BE() + Else + tempInt = Me.theInputFileReader.ReadUInt16() + tempInt = Me.theInputFileReader.ReadUInt16() + End If '9c 01 00 00 surface size? might be size of remaining solid struct after "axisMapSize?" field ' Seems to be size of data struct from VPHY field to last section of CollisionData. diff --git a/Crowbar/Core/GameModel/CompiledFiles/PhyFile/SourcePhyFileData.vb b/Crowbar/Core/GameModel/CompiledFiles/PhyFile/SourcePhyFileData.vb index 43ae4f98..3b9d062b 100644 --- a/Crowbar/Core/GameModel/CompiledFiles/PhyFile/SourcePhyFileData.vb +++ b/Crowbar/Core/GameModel/CompiledFiles/PhyFile/SourcePhyFileData.vb @@ -36,5 +36,6 @@ Public Class SourcePhyFileData Public theSourcePhyPhysCollisionModelMostUsedValues As SourcePhyPhysCollisionModel Public theSourcePhyCollisionText As String Public theSourcePhyMaxConvexPieces As Integer + Public isBigEndian As Boolean End Class diff --git a/Crowbar/Core/GameModel/CompiledFiles/VtxFile/VtxFile07/SourceVtxFile07.vb b/Crowbar/Core/GameModel/CompiledFiles/VtxFile/VtxFile07/SourceVtxFile07.vb index 110c71ed..1ebdaf95 100644 --- a/Crowbar/Core/GameModel/CompiledFiles/VtxFile/VtxFile07/SourceVtxFile07.vb +++ b/Crowbar/Core/GameModel/CompiledFiles/VtxFile/VtxFile07/SourceVtxFile07.vb @@ -17,33 +17,116 @@ Public Class SourceVtxFile07 #Region "Methods" + ' Big endian binary reader functions + Public Function ReadInt32BE() As Integer + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(4) + Dim b1 As Integer = (bytes(0) >> 0) And &HFF + Dim b2 As Integer = (bytes(1) >> 8) And &HFF + Dim b3 As Integer = (bytes(2) >> 16) And &HFF + Dim b4 As Integer = (bytes(3) >> 24) And &HFF + + Return b1 << 24 Or b2 << 16 Or b3 << 8 Or b4 << 0 + End Function + + Public Function ReadInt16BE() As Short + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(2) + 'Dim b1 As Integer = (bytes(0) >> 0) And &HFF + 'Dim b2 As Integer = (bytes(1) >> 8) And &HFF + Array.Reverse(bytes) + + 'Return CShort(b1 << 8 Or b2 << 0) + Return BitConverter.ToInt16(bytes, 0) + End Function + + Public Function ReadUInt16BE() As UShort + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(2) + Dim b1 As Integer = (bytes(0) >> 0) And &HFF + Dim b2 As Integer = (bytes(1) >> 8) And &HFF + + Return CUShort(b1 << 8 Or b2 << 0) + End Function + + Public Function ReadSingleBE() As Single + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(4) + 'Dim b1 As Integer = (bytes(0) >> 0) And &HFF + 'Dim b2 As Integer = (bytes(1) >> 8) And &HFF + 'Dim b3 As Integer = (bytes(2) >> 16) And &HFF + 'Dim b4 As Integer = (bytes(3) >> 24) And &HFF + 'Dim num As Single = b1 << 24 Or b2 << 16 Or b3 << 8 Or b4 << 0 + Array.Reverse(bytes) + Dim num As Single = BitConverter.ToSingle(bytes, 0) + + Return num + End Function + Public Sub ReadSourceVtxHeader() Dim fileOffsetStart As Long Dim fileOffsetEnd As Long fileOffsetStart = Me.theInputFileReader.BaseStream.Position - ' Offset: 0x00 - Me.theVtxFileData.version = Me.theInputFileReader.ReadInt32() + If Me.theInputFileReader.ReadInt32() > 7 Then + ' Possibly big endian, let's confirm this + Me.theInputFileReader.BaseStream.Seek(-4, SeekOrigin.Current) + If ReadInt32BE() = 7 Then + ' Big endian file + Me.theVtxFileData.isBigEndian = True + Me.theInputFileReader.BaseStream.Seek(-4, SeekOrigin.Current) + Else + ' Nevermind, continue as normal + Me.theInputFileReader.BaseStream.Seek(-4, SeekOrigin.Current) + End If + Else + ' Nevermind, continue as normal + Me.theInputFileReader.BaseStream.Seek(-4, SeekOrigin.Current) + End If + + If Me.theVtxFileData.isBigEndian Then + ' Offset: 0x00 + Me.theVtxFileData.version = ReadInt32BE() + + ' Offsets: 0x04, 0x08, 0x0A (10), 0x0C (12) + Me.theVtxFileData.vertexCacheSize = ReadInt32BE() + Me.theVtxFileData.maxBonesPerStrip = ReadUInt16BE() + Me.theVtxFileData.maxBonesPerTri = ReadUInt16BE() + Me.theVtxFileData.maxBonesPerVertex = ReadInt32BE() + + ' Offset: 0x10 (16) + Me.theVtxFileData.checksum = ReadInt32BE() + + ' Offset: 0x14 (20) + Me.theVtxFileData.lodCount = ReadInt32BE() + + ' Offset: 0x18 (24) + Me.theVtxFileData.materialReplacementListOffset = ReadInt32BE() + + ' Offsets: 0x1C (28), 0x20 (32) + Me.theVtxFileData.bodyPartCount = ReadInt32BE() + Me.theVtxFileData.bodyPartOffset = ReadInt32BE() + Else + ' Offset: 0x00 + Me.theVtxFileData.version = Me.theInputFileReader.ReadInt32() - ' Offsets: 0x04, 0x08, 0x0A (10), 0x0C (12) - Me.theVtxFileData.vertexCacheSize = Me.theInputFileReader.ReadInt32() - Me.theVtxFileData.maxBonesPerStrip = Me.theInputFileReader.ReadUInt16() - Me.theVtxFileData.maxBonesPerTri = Me.theInputFileReader.ReadUInt16() - Me.theVtxFileData.maxBonesPerVertex = Me.theInputFileReader.ReadInt32() + ' Offsets: 0x04, 0x08, 0x0A (10), 0x0C (12) + Me.theVtxFileData.vertexCacheSize = Me.theInputFileReader.ReadInt32() + Me.theVtxFileData.maxBonesPerStrip = Me.theInputFileReader.ReadUInt16() + Me.theVtxFileData.maxBonesPerTri = Me.theInputFileReader.ReadUInt16() + Me.theVtxFileData.maxBonesPerVertex = Me.theInputFileReader.ReadInt32() - ' Offset: 0x10 (16) - Me.theVtxFileData.checksum = Me.theInputFileReader.ReadInt32() + ' Offset: 0x10 (16) + Me.theVtxFileData.checksum = Me.theInputFileReader.ReadInt32() - ' Offset: 0x14 (20) - Me.theVtxFileData.lodCount = Me.theInputFileReader.ReadInt32() + ' Offset: 0x14 (20) + Me.theVtxFileData.lodCount = Me.theInputFileReader.ReadInt32() - ' Offset: 0x18 (24) - Me.theVtxFileData.materialReplacementListOffset = Me.theInputFileReader.ReadInt32() + ' Offset: 0x18 (24) + Me.theVtxFileData.materialReplacementListOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0x1C (28), 0x20 (32) + Me.theVtxFileData.bodyPartCount = Me.theInputFileReader.ReadInt32() + Me.theVtxFileData.bodyPartOffset = Me.theInputFileReader.ReadInt32() + End If - ' Offsets: 0x1C (28), 0x20 (32) - Me.theVtxFileData.bodyPartCount = Me.theInputFileReader.ReadInt32() - Me.theVtxFileData.bodyPartOffset = Me.theInputFileReader.ReadInt32() fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theVtxFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "VTX File Header (Actual version: " + Me.theVtxFileData.version.ToString() + "; override version: 7)") @@ -107,8 +190,13 @@ Public Class SourceVtxFile07 materialReplacementListInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aMaterialReplacementList As New SourceVtxMaterialReplacementList07() - aMaterialReplacementList.replacementCount = Me.theInputFileReader.ReadInt32() - aMaterialReplacementList.replacementOffset = Me.theInputFileReader.ReadInt32() + If Me.theVtxFileData.isBigEndian Then + aMaterialReplacementList.replacementCount = ReadInt32BE() + aMaterialReplacementList.replacementOffset = ReadInt32BE() + Else + aMaterialReplacementList.replacementCount = Me.theInputFileReader.ReadInt32() + aMaterialReplacementList.replacementOffset = Me.theInputFileReader.ReadInt32() + End If Me.theVtxFileData.theVtxMaterialReplacementLists.Add(aMaterialReplacementList) @@ -145,8 +233,13 @@ Public Class SourceVtxFile07 bodyPartInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aBodyPart As New SourceVtxBodyPart07() - aBodyPart.modelCount = Me.theInputFileReader.ReadInt32() - aBodyPart.modelOffset = Me.theInputFileReader.ReadInt32() + If Me.theVtxFileData.isBigEndian Then + aBodyPart.modelCount = ReadInt32BE() + aBodyPart.modelOffset = ReadInt32BE() + Else + aBodyPart.modelCount = Me.theInputFileReader.ReadInt32() + aBodyPart.modelOffset = Me.theInputFileReader.ReadInt32() + End If Me.theVtxFileData.theVtxBodyParts.Add(aBodyPart) @@ -179,8 +272,13 @@ Public Class SourceVtxFile07 modelInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aModel As New SourceVtxModel07() - aModel.lodCount = Me.theInputFileReader.ReadInt32() - aModel.lodOffset = Me.theInputFileReader.ReadInt32() + If Me.theVtxFileData.isBigEndian Then + aModel.lodCount = ReadInt32BE() + aModel.lodOffset = ReadInt32BE() + Else + aModel.lodCount = Me.theInputFileReader.ReadInt32() + aModel.lodOffset = Me.theInputFileReader.ReadInt32() + End If aBodyPart.theVtxModels.Add(aModel) @@ -218,9 +316,16 @@ Public Class SourceVtxFile07 modelLodInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aModelLod As New SourceVtxModelLod07() - aModelLod.meshCount = Me.theInputFileReader.ReadInt32() - aModelLod.meshOffset = Me.theInputFileReader.ReadInt32() - aModelLod.switchPoint = Me.theInputFileReader.ReadSingle() + If Me.theVtxFileData.isBigEndian Then + aModelLod.meshCount = ReadInt32BE() + aModelLod.meshOffset = ReadInt32BE() + aModelLod.switchPoint = ReadSingleBE() + Else + aModelLod.meshCount = Me.theInputFileReader.ReadInt32() + aModelLod.meshOffset = Me.theInputFileReader.ReadInt32() + aModelLod.switchPoint = Me.theInputFileReader.ReadSingle() + End If + aModelLod.theVtxModelLodUsesFacial = False aModel.theVtxModelLods.Add(aModelLod) @@ -258,8 +363,14 @@ Public Class SourceVtxFile07 meshInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aMesh As New SourceVtxMesh07() - aMesh.stripGroupCount = Me.theInputFileReader.ReadInt32() - aMesh.stripGroupOffset = Me.theInputFileReader.ReadInt32() + If Me.theVtxFileData.isBigEndian Then + aMesh.stripGroupCount = ReadInt32BE() + aMesh.stripGroupOffset = ReadInt32BE() + Else + aMesh.stripGroupCount = Me.theInputFileReader.ReadInt32() + aMesh.stripGroupOffset = Me.theInputFileReader.ReadInt32() + End If + aMesh.flags = Me.theInputFileReader.ReadByte() aModelLod.theVtxMeshes.Add(aMesh) @@ -321,12 +432,22 @@ Public Class SourceVtxFile07 aMesh.theVtxStripGroups = New List(Of SourceVtxStripGroup07)(aMesh.stripGroupCount) For j As Integer = 0 To aMesh.stripGroupCount - 1 Dim aStripGroup As New SourceVtxStripGroup07() - aStripGroup.vertexCount = Me.theInputFileReader.ReadInt32() - aStripGroup.vertexOffset = Me.theInputFileReader.ReadInt32() - aStripGroup.indexCount = Me.theInputFileReader.ReadInt32() - aStripGroup.indexOffset = Me.theInputFileReader.ReadInt32() - aStripGroup.stripCount = Me.theInputFileReader.ReadInt32() - aStripGroup.stripOffset = Me.theInputFileReader.ReadInt32() + If Me.theVtxFileData.isBigEndian Then + aStripGroup.vertexCount = ReadInt32BE() + aStripGroup.vertexOffset = ReadInt32BE() + aStripGroup.indexCount = ReadInt32BE() + aStripGroup.indexOffset = ReadInt32BE() + aStripGroup.stripCount = ReadInt32BE() + aStripGroup.stripOffset = ReadInt32BE() + Else + aStripGroup.vertexCount = Me.theInputFileReader.ReadInt32() + aStripGroup.vertexOffset = Me.theInputFileReader.ReadInt32() + aStripGroup.indexCount = Me.theInputFileReader.ReadInt32() + aStripGroup.indexOffset = Me.theInputFileReader.ReadInt32() + aStripGroup.stripCount = Me.theInputFileReader.ReadInt32() + aStripGroup.stripOffset = Me.theInputFileReader.ReadInt32() + End If + aStripGroup.flags = Me.theInputFileReader.ReadByte() aMesh.theVtxStripGroups.Add(aStripGroup) @@ -356,12 +477,22 @@ Public Class SourceVtxFile07 stripGroupInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aStripGroup As New SourceVtxStripGroup07() - aStripGroup.vertexCount = Me.theInputFileReader.ReadInt32() - aStripGroup.vertexOffset = Me.theInputFileReader.ReadInt32() - aStripGroup.indexCount = Me.theInputFileReader.ReadInt32() - aStripGroup.indexOffset = Me.theInputFileReader.ReadInt32() - aStripGroup.stripCount = Me.theInputFileReader.ReadInt32() - aStripGroup.stripOffset = Me.theInputFileReader.ReadInt32() + If Me.theVtxFileData.isBigEndian Then + aStripGroup.vertexCount = ReadInt32BE() + aStripGroup.vertexOffset = ReadInt32BE() + aStripGroup.indexCount = ReadInt32BE() + aStripGroup.indexOffset = ReadInt32BE() + aStripGroup.stripCount = ReadInt32BE() + aStripGroup.stripOffset = ReadInt32BE() + Else + aStripGroup.vertexCount = Me.theInputFileReader.ReadInt32() + aStripGroup.vertexOffset = Me.theInputFileReader.ReadInt32() + aStripGroup.indexCount = Me.theInputFileReader.ReadInt32() + aStripGroup.indexOffset = Me.theInputFileReader.ReadInt32() + aStripGroup.stripCount = Me.theInputFileReader.ReadInt32() + aStripGroup.stripOffset = Me.theInputFileReader.ReadInt32() + End If + aStripGroup.flags = Me.theInputFileReader.ReadByte() ''TEST: Did not work for both Engineeer and doom. @@ -376,8 +507,13 @@ Public Class SourceVtxFile07 'End If 'TEST: If Me.theStripGroupAndStripUseExtraFields Then - aStripGroup.topologyIndexCount = Me.theInputFileReader.ReadInt32() - aStripGroup.topologyIndexOffset = Me.theInputFileReader.ReadInt32() + If Me.theVtxFileData.isBigEndian Then + aStripGroup.topologyIndexCount = ReadInt32BE() + aStripGroup.topologyIndexOffset = ReadInt32BE() + Else + aStripGroup.topologyIndexCount = Me.theInputFileReader.ReadInt32() + aStripGroup.topologyIndexOffset = Me.theInputFileReader.ReadInt32() + End If End If aMesh.theVtxStripGroups.Add(aStripGroup) @@ -457,7 +593,12 @@ Public Class SourceVtxFile07 aVertex.boneWeightIndex(i) = Me.theInputFileReader.ReadByte() Next aVertex.boneCount = Me.theInputFileReader.ReadByte() - aVertex.originalMeshVertexIndex = Me.theInputFileReader.ReadUInt16() + If Me.theVtxFileData.isBigEndian Then + aVertex.originalMeshVertexIndex = ReadUInt16BE() + Else + aVertex.originalMeshVertexIndex = Me.theInputFileReader.ReadUInt16() + End If + For i As Integer = 0 To MAX_NUM_BONES_PER_VERT - 1 aVertex.boneId(i) = Me.theInputFileReader.ReadByte() Next @@ -493,7 +634,11 @@ Public Class SourceVtxFile07 For j As Integer = 0 To aStripGroup.indexCount - 1 'modelInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - aStripGroup.theVtxIndexes.Add(Me.theInputFileReader.ReadUInt16()) + If Me.theVtxFileData.isBigEndian Then + aStripGroup.theVtxIndexes.Add(ReadUInt16BE()) + Else + aStripGroup.theVtxIndexes.Add(Me.theInputFileReader.ReadUInt16()) + End If 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -528,18 +673,39 @@ Public Class SourceVtxFile07 stripInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aStrip As New SourceVtxStrip07() - aStrip.indexCount = Me.theInputFileReader.ReadInt32() - aStrip.indexMeshIndex = Me.theInputFileReader.ReadInt32() - aStrip.vertexCount = Me.theInputFileReader.ReadInt32() - aStrip.vertexMeshIndex = Me.theInputFileReader.ReadInt32() - aStrip.boneCount = Me.theInputFileReader.ReadInt16() + If Me.theVtxFileData.isBigEndian Then + aStrip.indexCount = ReadInt32BE() + aStrip.indexMeshIndex = ReadInt32BE() + aStrip.vertexCount = ReadInt32BE() + aStrip.vertexMeshIndex = ReadInt32BE() + aStrip.boneCount = ReadInt16BE() + Else + aStrip.indexCount = Me.theInputFileReader.ReadInt32() + aStrip.indexMeshIndex = Me.theInputFileReader.ReadInt32() + aStrip.vertexCount = Me.theInputFileReader.ReadInt32() + aStrip.vertexMeshIndex = Me.theInputFileReader.ReadInt32() + aStrip.boneCount = Me.theInputFileReader.ReadInt16() + End If + aStrip.flags = Me.theInputFileReader.ReadByte() - aStrip.boneStateChangeCount = Me.theInputFileReader.ReadInt32() - aStrip.boneStateChangeOffset = Me.theInputFileReader.ReadInt32() + + If Me.theVtxFileData.isBigEndian Then + aStrip.boneStateChangeCount = ReadInt32BE() + aStrip.boneStateChangeOffset = ReadInt32BE() + Else + aStrip.boneStateChangeCount = Me.theInputFileReader.ReadInt32() + aStrip.boneStateChangeOffset = Me.theInputFileReader.ReadInt32() + End If + 'TEST: If Me.theStripGroupAndStripUseExtraFields Then - aStrip.unknownBytes01 = Me.theInputFileReader.ReadInt32() - aStrip.unknownBytes02 = Me.theInputFileReader.ReadInt32() + If Me.theVtxFileData.isBigEndian Then + aStrip.unknownBytes01 = ReadInt32BE() + aStrip.unknownBytes02 = ReadInt32BE() + Else + aStrip.unknownBytes01 = Me.theInputFileReader.ReadInt32() + aStrip.unknownBytes02 = Me.theInputFileReader.ReadInt32() + End If End If aStripGroup.theVtxStrips.Add(aStrip) @@ -578,7 +744,11 @@ Public Class SourceVtxFile07 'topologyInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim topologyIndex As UShort - topologyIndex = Me.theInputFileReader.ReadUInt16() + If Me.theVtxFileData.isBigEndian Then + topologyIndex = ReadUInt16BE() + Else + topologyIndex = Me.theInputFileReader.ReadUInt16() + End If aStripGroup.theVtxTopologyIndexes.Add(topologyIndex) @@ -627,8 +797,13 @@ Public Class SourceVtxFile07 'fileOffsetStart = Me.theInputFileReader.BaseStream.Position Dim aBoneStateChange As New SourceVtxBoneStateChange07() - aBoneStateChange.hardwareId = Me.theInputFileReader.ReadInt32() - aBoneStateChange.newBoneId = Me.theInputFileReader.ReadInt32() + If Me.theVtxFileData.isBigEndian Then + aBoneStateChange.hardwareId = ReadInt32BE() + aBoneStateChange.newBoneId = ReadInt32BE() + Else + aBoneStateChange.hardwareId = Me.theInputFileReader.ReadInt32() + aBoneStateChange.newBoneId = Me.theInputFileReader.ReadInt32() + End If aStrip.theVtxBoneStateChanges.Add(aBoneStateChange) @@ -667,8 +842,13 @@ Public Class SourceVtxFile07 materialReplacementInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aMaterialReplacement As New SourceVtxMaterialReplacement07() - aMaterialReplacement.materialIndex = Me.theInputFileReader.ReadInt16() - aMaterialReplacement.nameOffset = Me.theInputFileReader.ReadInt32() + If Me.theVtxFileData.isBigEndian Then + aMaterialReplacement.materialIndex = ReadInt16BE() + aMaterialReplacement.nameOffset = ReadInt32BE() + Else + aMaterialReplacement.materialIndex = Me.theInputFileReader.ReadInt16() + aMaterialReplacement.nameOffset = Me.theInputFileReader.ReadInt32() + End If aMaterialReplacementList.theVtxMaterialReplacements.Add(aMaterialReplacement) diff --git a/Crowbar/Core/GameModel/CompiledFiles/VtxFile/VtxFile07/SourceVtxFileData07.vb b/Crowbar/Core/GameModel/CompiledFiles/VtxFile/VtxFile07/SourceVtxFileData07.vb index 572d1997..2ebe1ca5 100644 --- a/Crowbar/Core/GameModel/CompiledFiles/VtxFile/VtxFile07/SourceVtxFileData07.vb +++ b/Crowbar/Core/GameModel/CompiledFiles/VtxFile/VtxFile07/SourceVtxFileData07.vb @@ -63,4 +63,6 @@ Public theVtxBodyParts As List(Of SourceVtxBodyPart07) Public theVtxMaterialReplacementLists As List(Of SourceVtxMaterialReplacementList07) + Public isBigEndian As Boolean + End Class diff --git a/Crowbar/Core/GameModel/CompiledFiles/VvdFile/VvdFile04/SourceVvdFile04.vb b/Crowbar/Core/GameModel/CompiledFiles/VvdFile/VvdFile04/SourceVvdFile04.vb index 24c3bed8..60d7160b 100644 --- a/Crowbar/Core/GameModel/CompiledFiles/VvdFile/VvdFile04/SourceVvdFile04.vb +++ b/Crowbar/Core/GameModel/CompiledFiles/VvdFile/VvdFile04/SourceVvdFile04.vb @@ -17,23 +17,92 @@ Public Class SourceVvdFile04 #Region "Methods" + ' Big endian binary reader functions + Public Function ReadInt32BE() As Integer + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(4) + Dim b1 As Integer = (bytes(0) >> 0) And &HFF + Dim b2 As Integer = (bytes(1) >> 8) And &HFF + Dim b3 As Integer = (bytes(2) >> 16) And &HFF + Dim b4 As Integer = (bytes(3) >> 24) And &HFF + + Return b1 << 24 Or b2 << 16 Or b3 << 8 Or b4 << 0 + End Function + + Public Function ReadInt16BE() As Short + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(2) + 'Dim b1 As Integer = (bytes(0) >> 0) And &HFF + 'Dim b2 As Integer = (bytes(1) >> 8) And &HFF + Array.Reverse(bytes) + + 'Return CShort(b1 << 8 Or b2 << 0) + Return BitConverter.ToInt16(bytes, 0) + End Function + + Public Function ReadUInt16BE() As UShort + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(2) + Dim b1 As Integer = (bytes(0) >> 0) And &HFF + Dim b2 As Integer = (bytes(1) >> 8) And &HFF + + Return CUShort(b1 << 8 Or b2 << 0) + End Function + + Public Function ReadSingleBE() As Single + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(4) + 'Dim b1 As Integer = (bytes(0) >> 0) And &HFF + 'Dim b2 As Integer = (bytes(1) >> 8) And &HFF + 'Dim b3 As Integer = (bytes(2) >> 16) And &HFF + 'Dim b4 As Integer = (bytes(3) >> 24) And &HFF + 'Dim num As Single = b1 << 24 Or b2 << 16 Or b3 << 8 Or b4 << 0 + Array.Reverse(bytes) + Dim num As Single = BitConverter.ToSingle(bytes, 0) + + Return num + End Function + Public Sub ReadSourceVvdHeader() Dim fileOffsetStart As Long Dim fileOffsetEnd As Long fileOffsetStart = Me.theInputFileReader.BaseStream.Position + Me.theVvdFileData.isBigEndian = False + Me.theVvdFileData.id = Me.theInputFileReader.ReadChars(4) - Me.theVvdFileData.version = Me.theInputFileReader.ReadInt32() - Me.theVvdFileData.checksum = Me.theInputFileReader.ReadInt32() - Me.theVvdFileData.lodCount = Me.theInputFileReader.ReadInt32() + + ' Check if this is a Xbox 360 VVD + If Me.theVvdFileData.id = "VSDI" Then + Me.theVvdFileData.isBigEndian = True + End If + + If Me.theVvdFileData.isBigEndian Then + Me.theVvdFileData.version = ReadInt32BE() + Me.theVvdFileData.checksum = ReadInt32BE() + Me.theVvdFileData.lodCount = ReadInt32BE() + Else + Me.theVvdFileData.version = Me.theInputFileReader.ReadInt32() + Me.theVvdFileData.checksum = Me.theInputFileReader.ReadInt32() + Me.theVvdFileData.lodCount = Me.theInputFileReader.ReadInt32() + End If + For i As Integer = 0 To MAX_NUM_LODS - 1 - Me.theVvdFileData.lodVertexCount(i) = Me.theInputFileReader.ReadInt32() + If Me.theVvdFileData.isBigEndian Then + Me.theVvdFileData.lodVertexCount(i) = ReadInt32BE() + Else + Me.theVvdFileData.lodVertexCount(i) = Me.theInputFileReader.ReadInt32() + End If Next - Me.theVvdFileData.fixupCount = Me.theInputFileReader.ReadInt32() - Me.theVvdFileData.fixupTableOffset = Me.theInputFileReader.ReadInt32() - Me.theVvdFileData.vertexDataOffset = Me.theInputFileReader.ReadInt32() - Me.theVvdFileData.tangentDataOffset = Me.theInputFileReader.ReadInt32() + + If Me.theVvdFileData.isBigEndian Then + Me.theVvdFileData.fixupCount = ReadInt32BE() + Me.theVvdFileData.fixupTableOffset = ReadInt32BE() + Me.theVvdFileData.vertexDataOffset = ReadInt32BE() + Me.theVvdFileData.tangentDataOffset = ReadInt32BE() + Else + Me.theVvdFileData.fixupCount = Me.theInputFileReader.ReadInt32() + Me.theVvdFileData.fixupTableOffset = Me.theInputFileReader.ReadInt32() + Me.theVvdFileData.vertexDataOffset = Me.theInputFileReader.ReadInt32() + Me.theVvdFileData.tangentDataOffset = Me.theInputFileReader.ReadInt32() + End If fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theVvdFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "VVD File Header") @@ -64,7 +133,12 @@ Public Class SourceVvdFile04 Dim boneWeight As New SourceBoneWeight() 'boneWeightingIsIncorrect = False For x As Integer = 0 To MAX_NUM_BONES_PER_VERT - 1 - weight = Me.theInputFileReader.ReadSingle() + If Me.theVvdFileData.isBigEndian Then + weight = ReadSingleBE() + Else + weight = Me.theInputFileReader.ReadSingle() + End If + boneWeight.weight(x) = weight 'If weight > 1 Then ' boneWeightingIsIncorrect = True @@ -87,14 +161,26 @@ Public Class SourceVvdFile04 'End If aStudioVertex.boneWeight = boneWeight - aStudioVertex.positionX = Me.theInputFileReader.ReadSingle() - aStudioVertex.positionY = Me.theInputFileReader.ReadSingle() - aStudioVertex.positionZ = Me.theInputFileReader.ReadSingle() - aStudioVertex.normalX = Me.theInputFileReader.ReadSingle() - aStudioVertex.normalY = Me.theInputFileReader.ReadSingle() - aStudioVertex.normalZ = Me.theInputFileReader.ReadSingle() - aStudioVertex.texCoordX = Me.theInputFileReader.ReadSingle() - aStudioVertex.texCoordY = Me.theInputFileReader.ReadSingle() + If Me.theVvdFileData.isBigEndian Then + aStudioVertex.positionX = ReadSingleBE() + aStudioVertex.positionY = ReadSingleBE() + aStudioVertex.positionZ = ReadSingleBE() + aStudioVertex.normalX = ReadSingleBE() + aStudioVertex.normalY = ReadSingleBE() + aStudioVertex.normalZ = ReadSingleBE() + aStudioVertex.texCoordX = ReadSingleBE() + aStudioVertex.texCoordY = ReadSingleBE() + Else + aStudioVertex.positionX = Me.theInputFileReader.ReadSingle() + aStudioVertex.positionY = Me.theInputFileReader.ReadSingle() + aStudioVertex.positionZ = Me.theInputFileReader.ReadSingle() + aStudioVertex.normalX = Me.theInputFileReader.ReadSingle() + aStudioVertex.normalY = Me.theInputFileReader.ReadSingle() + aStudioVertex.normalZ = Me.theInputFileReader.ReadSingle() + aStudioVertex.texCoordX = Me.theInputFileReader.ReadSingle() + aStudioVertex.texCoordY = Me.theInputFileReader.ReadSingle() + End If + If mdlVersion >= 54 AndAlso mdlVersion <= 59 Then Me.theInputFileReader.ReadSingle() Me.theInputFileReader.ReadSingle() @@ -127,10 +213,18 @@ Public Class SourceVvdFile04 For j As Integer = 0 To vertexCount - 1 Dim aSourceVector4D As New SourceVector4D() - aSourceVector4D.x = Me.theInputFileReader.ReadSingle() - aSourceVector4D.y = Me.theInputFileReader.ReadSingle() - aSourceVector4D.z = Me.theInputFileReader.ReadSingle() - aSourceVector4D.w = Me.theInputFileReader.ReadSingle() + If Me.theVvdFileData.isBigEndian Then + aSourceVector4D.x = ReadSingleBE() + aSourceVector4D.y = ReadSingleBE() + aSourceVector4D.z = ReadSingleBE() + aSourceVector4D.w = ReadSingleBE() + Else + aSourceVector4D.x = Me.theInputFileReader.ReadSingle() + aSourceVector4D.y = Me.theInputFileReader.ReadSingle() + aSourceVector4D.z = Me.theInputFileReader.ReadSingle() + aSourceVector4D.w = Me.theInputFileReader.ReadSingle() + End If + Me.theVvdFileData.theTangents.Add(aSourceVector4D) Next @@ -150,9 +244,16 @@ Public Class SourceVvdFile04 For fixupIndex As Integer = 0 To Me.theVvdFileData.fixupCount - 1 Dim aFixup As New SourceVvdFixup04() - aFixup.lodIndex = Me.theInputFileReader.ReadInt32() - aFixup.vertexIndex = Me.theInputFileReader.ReadInt32() - aFixup.vertexCount = Me.theInputFileReader.ReadInt32() + If Me.theVvdFileData.isBigEndian Then + aFixup.lodIndex = ReadInt32BE() + aFixup.vertexIndex = ReadInt32BE() + aFixup.vertexCount = ReadInt32BE() + Else + aFixup.lodIndex = Me.theInputFileReader.ReadInt32() + aFixup.vertexIndex = Me.theInputFileReader.ReadInt32() + aFixup.vertexCount = Me.theInputFileReader.ReadInt32() + End If + Me.theVvdFileData.theFixups.Add(aFixup) Next @@ -190,8 +291,18 @@ Public Class SourceVvdFile04 'FROM: [49] csgo_studiomdl\public\studio.h ' int m_count; // Number of individual extra attribute chunks ' int m_totalbytes; // Total size of extra attribute data (all chunks plus header and index) - Dim extraDataCount As Integer = Me.theInputFileReader.ReadInt32() - Dim extraDataByteCount As Integer = Me.theInputFileReader.ReadInt32() + ' Dim extraDataCount As Integer = Me.theInputFileReader.ReadInt32() + ' Dim extraDataByteCount As Integer = Me.theInputFileReader.ReadInt32() + Dim extraDataCount As Integer + Dim extraDataByteCount As Integer + + If Me.theVvdFileData.isBigEndian Then + extraDataCount = ReadInt32BE() + extraDataByteCount = ReadInt32BE() + Else + extraDataCount = Me.theInputFileReader.ReadInt32() + extraDataByteCount = Me.theInputFileReader.ReadInt32() + End If fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theVvdFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "ExtraDataCount = " + extraDataCount.ToString() + "; ExtraDataByteCount = " + extraDataByteCount.ToString()) @@ -204,17 +315,30 @@ Public Class SourceVvdFile04 For i As Integer = 0 To extraDataCount - 1 Dim anExtraData As New SourceVvdExtraData04() - anExtraData.type = CType(Me.theInputFileReader.ReadInt32(), SourceVvdExtraData04.ExtraVertexAttributeType) - anExtraData.offset = Me.theInputFileReader.ReadInt32() - anExtraData.bytesPerVertex = Me.theInputFileReader.ReadInt32() + If Me.theVvdFileData.isBigEndian Then + anExtraData.type = CType(ReadInt32BE(), SourceVvdExtraData04.ExtraVertexAttributeType) + anExtraData.offset = ReadInt32BE() + anExtraData.bytesPerVertex = ReadInt32BE() + Else + anExtraData.type = CType(Me.theInputFileReader.ReadInt32(), SourceVvdExtraData04.ExtraVertexAttributeType) + anExtraData.offset = Me.theInputFileReader.ReadInt32() + anExtraData.bytesPerVertex = Me.theInputFileReader.ReadInt32() + End If + Me.theVvdFileData.theExtraDatas.Add(anExtraData) anExtraData.theTextureCoordinates = New List(Of SourceTextureCoordinates)(vertexCount) For j As Integer = 0 To vertexCount - 1 Dim aTextureCoordinates As New SourceTextureCoordinates() - aTextureCoordinates.X = Me.theInputFileReader.ReadSingle() - aTextureCoordinates.Y = Me.theInputFileReader.ReadSingle() + If Me.theVvdFileData.isBigEndian Then + aTextureCoordinates.X = ReadSingleBE() + aTextureCoordinates.Y = ReadSingleBE() + Else + aTextureCoordinates.X = Me.theInputFileReader.ReadSingle() + aTextureCoordinates.Y = Me.theInputFileReader.ReadSingle() + End If + anExtraData.theTextureCoordinates.Add(aTextureCoordinates) Next Next diff --git a/Crowbar/Core/GameModel/CompiledFiles/VvdFile/VvdFile04/SourceVvdFileData04.vb b/Crowbar/Core/GameModel/CompiledFiles/VvdFile/VvdFile04/SourceVvdFileData04.vb index 7918cd54..b2748dcc 100644 --- a/Crowbar/Core/GameModel/CompiledFiles/VvdFile/VvdFile04/SourceVvdFileData04.vb +++ b/Crowbar/Core/GameModel/CompiledFiles/VvdFile/VvdFile04/SourceVvdFileData04.vb @@ -47,4 +47,6 @@ Public Class SourceVvdFileData04 Public theTangents As List(Of SourceVector4D) Public theVertexes As List(Of SourceVertex) + Public isBigEndian As Boolean + End Class diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlBolton.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlBolton.vb new file mode 100644 index 00000000..bd5a901f --- /dev/null +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlBolton.vb @@ -0,0 +1,11 @@ +Public Class SourceMdlBolton + Public Sub New() + 'Nothing here + End Sub + + Public type As Integer + + Public szmodelnameindex As Integer + + Public theModelName As String +End Class diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlPrefab.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlPrefab.vb new file mode 100644 index 00000000..d763dc6d --- /dev/null +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlPrefab.vb @@ -0,0 +1,17 @@ +Public Class SourceMdlPrefab + Public Sub New() + 'Nothing here + End Sub + + Public sznameindex As Integer + + Public theName As String + + Public skin As Integer + + Public boltonsmask As Integer + + Public bodypartsindex As Integer + + Public theBodyParts As List(Of Byte) +End Class diff --git a/Crowbar/Core/GameModel/SourceModel49/SourceMdlFile49.vb b/Crowbar/Core/GameModel/SourceModel49/SourceMdlFile49.vb index 0b0b14d6..29d79e5b 100644 --- a/Crowbar/Core/GameModel/SourceModel49/SourceMdlFile49.vb +++ b/Crowbar/Core/GameModel/SourceModel49/SourceMdlFile49.vb @@ -24,6 +24,48 @@ Public Class SourceMdlFile49 #Region "Methods" + ' Big endian binary reader functions + Public Function ReadInt32BE() As Integer + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(4) + Dim b1 As Integer = (bytes(0) >> 0) And &HFF + Dim b2 As Integer = (bytes(1) >> 8) And &HFF + Dim b3 As Integer = (bytes(2) >> 16) And &HFF + Dim b4 As Integer = (bytes(3) >> 24) And &HFF + + Return b1 << 24 Or b2 << 16 Or b3 << 8 Or b4 << 0 + End Function + + Public Function ReadInt16BE() As Short + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(2) + 'Dim b1 As Integer = (bytes(0) >> 0) And &HFF + 'Dim b2 As Integer = (bytes(1) >> 8) And &HFF + Array.Reverse(bytes) + + 'Return CShort(b1 << 8 Or b2 << 0) + Return BitConverter.ToInt16(bytes, 0) + End Function + + Public Function ReadUInt16BE() As UShort + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(2) + Dim b1 As Integer = (bytes(0) >> 0) And &HFF + Dim b2 As Integer = (bytes(1) >> 8) And &HFF + + Return CUShort(b1 << 8 Or b2 << 0) + End Function + + Public Function ReadSingleBE() As Single + Dim bytes() As Byte = Me.theInputFileReader.ReadBytes(4) + 'Dim b1 As Integer = (bytes(0) >> 0) And &HFF + 'Dim b2 As Integer = (bytes(1) >> 8) And &HFF + 'Dim b3 As Integer = (bytes(2) >> 16) And &HFF + 'Dim b4 As Integer = (bytes(3) >> 24) And &HFF + 'Dim num As Single = b1 << 24 Or b2 << 16 Or b3 << 8 Or b4 << 0 + Array.Reverse(bytes) + Dim num As Single = BitConverter.ToSingle(bytes, 0) + + Return num + End Function + Public Sub ReadMdlHeader00(ByVal logDescription As String) Dim fileOffsetStart As Long Dim fileOffsetEnd As Long @@ -32,14 +74,30 @@ Public Class SourceMdlFile49 Me.theMdlFileData.id = Me.theInputFileReader.ReadChars(4) Me.theMdlFileData.theID = Me.theMdlFileData.id - Me.theMdlFileData.version = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.checksum = Me.theInputFileReader.ReadInt32() + ' Check if this is a Xbox 360 MDL + If Me.theMdlFileData.theID = "TSDI" OrElse Me.theMdlFileData.theID = "GADI" Then + Me.theMdlFileData.isBigEndian = True + End If + + If Me.theMdlFileData.isBigEndian Then + Me.theMdlFileData.version = ReadInt32BE() + + Me.theMdlFileData.checksum = ReadInt32BE() + Else + Me.theMdlFileData.version = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.checksum = Me.theInputFileReader.ReadInt32() + End If Me.theMdlFileData.name = Me.theInputFileReader.ReadChars(64) Me.theMdlFileData.theModelName = CStr(Me.theMdlFileData.name).Trim(Chr(0)) - Me.theMdlFileData.fileSize = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + Me.theMdlFileData.fileSize = ReadInt32BE() + Else + Me.theMdlFileData.fileSize = Me.theInputFileReader.ReadInt32() + End If Me.theMdlFileData.theActualFileSize = Me.theInputFileReader.BaseStream.Length fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 @@ -57,93 +115,182 @@ Public Class SourceMdlFile49 fileOffsetStart = Me.theInputFileReader.BaseStream.Position - ' Offsets: 0x50, 0x54, 0x58 - Me.theMdlFileData.eyePosition.x = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.eyePosition.y = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.eyePosition.z = Me.theInputFileReader.ReadSingle() - - ' Offsets: 0x5C, 0x60, 0x64 - Me.theMdlFileData.illuminationPosition.x = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.illuminationPosition.y = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.illuminationPosition.z = Me.theInputFileReader.ReadSingle() - - ' Offsets: 0x68, 0x6C, 0x70 - Me.theMdlFileData.hullMinPosition.x = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.hullMinPosition.y = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.hullMinPosition.z = Me.theInputFileReader.ReadSingle() - - ' Offsets: 0x74, 0x78, 0x7C - Me.theMdlFileData.hullMaxPosition.x = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.hullMaxPosition.y = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.hullMaxPosition.z = Me.theInputFileReader.ReadSingle() - - ' Offsets: 0x80, 0x84, 0x88 - Me.theMdlFileData.viewBoundingBoxMinPosition.x = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.viewBoundingBoxMinPosition.y = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.viewBoundingBoxMinPosition.z = Me.theInputFileReader.ReadSingle() - - ' Offsets: 0x8C, 0x90, 0x94 - Me.theMdlFileData.viewBoundingBoxMaxPosition.x = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.viewBoundingBoxMaxPosition.y = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.viewBoundingBoxMaxPosition.z = Me.theInputFileReader.ReadSingle() - - ' Offsets: 0x98 - Me.theMdlFileData.flags = Me.theInputFileReader.ReadInt32() - - ' Offsets: 0x9C (156), 0xA0 - Me.theMdlFileData.boneCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.boneOffset = Me.theInputFileReader.ReadInt32() - - ' Offsets: 0xA4, 0xA8 - Me.theMdlFileData.boneControllerCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.boneControllerOffset = Me.theInputFileReader.ReadInt32() - - ' Offsets: 0xAC (172), 0xB0 - Me.theMdlFileData.hitboxSetCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.hitboxSetOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + ' Offsets: 0x50, 0x54, 0x58 + Me.theMdlFileData.eyePosition.x = ReadSingleBE() + Me.theMdlFileData.eyePosition.y = ReadSingleBE() + Me.theMdlFileData.eyePosition.z = ReadSingleBE() + + ' Offsets: 0x5C, 0x60, 0x64 + Me.theMdlFileData.illuminationPosition.x = ReadSingleBE() + Me.theMdlFileData.illuminationPosition.y = ReadSingleBE() + Me.theMdlFileData.illuminationPosition.z = ReadSingleBE() + + ' Offsets: 0x68, 0x6C, 0x70 + Me.theMdlFileData.hullMinPosition.x = ReadSingleBE() + Me.theMdlFileData.hullMinPosition.y = ReadSingleBE() + Me.theMdlFileData.hullMinPosition.z = ReadSingleBE() + + ' Offsets: 0x74, 0x78, 0x7C + Me.theMdlFileData.hullMaxPosition.x = ReadSingleBE() + Me.theMdlFileData.hullMaxPosition.y = ReadSingleBE() + Me.theMdlFileData.hullMaxPosition.z = ReadSingleBE() + + ' Offsets: 0x80, 0x84, 0x88 + Me.theMdlFileData.viewBoundingBoxMinPosition.x = ReadSingleBE() + Me.theMdlFileData.viewBoundingBoxMinPosition.y = ReadSingleBE() + Me.theMdlFileData.viewBoundingBoxMinPosition.z = ReadSingleBE() + + ' Offsets: 0x8C, 0x90, 0x94 + Me.theMdlFileData.viewBoundingBoxMaxPosition.x = ReadSingleBE() + Me.theMdlFileData.viewBoundingBoxMaxPosition.y = ReadSingleBE() + Me.theMdlFileData.viewBoundingBoxMaxPosition.z = ReadSingleBE() + + ' Offsets: 0x98 + Me.theMdlFileData.flags = ReadInt32BE() + + ' Offsets: 0x9C (156), 0xA0 + Me.theMdlFileData.boneCount = ReadInt32BE() + Me.theMdlFileData.boneOffset = ReadInt32BE() + + ' Offsets: 0xA4, 0xA8 + Me.theMdlFileData.boneControllerCount = ReadInt32BE() + Me.theMdlFileData.boneControllerOffset = ReadInt32BE() + + ' Offsets: 0xAC (172), 0xB0 + Me.theMdlFileData.hitboxSetCount = ReadInt32BE() + Me.theMdlFileData.hitboxSetOffset = ReadInt32BE() + Else + ' Offsets: 0x50, 0x54, 0x58 + Me.theMdlFileData.eyePosition.x = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.eyePosition.y = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.eyePosition.z = Me.theInputFileReader.ReadSingle() + + ' Offsets: 0x5C, 0x60, 0x64 + Me.theMdlFileData.illuminationPosition.x = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.illuminationPosition.y = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.illuminationPosition.z = Me.theInputFileReader.ReadSingle() + + ' Offsets: 0x68, 0x6C, 0x70 + Me.theMdlFileData.hullMinPosition.x = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.hullMinPosition.y = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.hullMinPosition.z = Me.theInputFileReader.ReadSingle() + + ' Offsets: 0x74, 0x78, 0x7C + Me.theMdlFileData.hullMaxPosition.x = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.hullMaxPosition.y = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.hullMaxPosition.z = Me.theInputFileReader.ReadSingle() + + ' Offsets: 0x80, 0x84, 0x88 + Me.theMdlFileData.viewBoundingBoxMinPosition.x = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.viewBoundingBoxMinPosition.y = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.viewBoundingBoxMinPosition.z = Me.theInputFileReader.ReadSingle() + + ' Offsets: 0x8C, 0x90, 0x94 + Me.theMdlFileData.viewBoundingBoxMaxPosition.x = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.viewBoundingBoxMaxPosition.y = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.viewBoundingBoxMaxPosition.z = Me.theInputFileReader.ReadSingle() + + ' Offsets: 0x98 + Me.theMdlFileData.flags = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0x9C (156), 0xA0 + Me.theMdlFileData.boneCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.boneOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0xA4, 0xA8 + Me.theMdlFileData.boneControllerCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.boneControllerOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0xAC (172), 0xB0 + Me.theMdlFileData.hitboxSetCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.hitboxSetOffset = Me.theInputFileReader.ReadInt32() + End If + 'FROM: StudioMdl for MDL48 and MDL49 '#define MAXSTUDIOHITBOXSETNAME 64 If Me.theMdlFileData.hitboxSetCount > 64 Then Me.theMdlFileData.hitboxSetCount = 64 End If - ' Offsets: 0xB4 (180), 0xB8 - Me.theMdlFileData.localAnimationCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.localAnimationOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + ' Offsets: 0xB4 (180), 0xB8 + Me.theMdlFileData.localAnimationCount = ReadInt32BE() + Me.theMdlFileData.localAnimationOffset = ReadInt32BE() - ' Offsets: 0xBC (188), 0xC0 (192) - Me.theMdlFileData.localSequenceCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.localSequenceOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0xBC (188), 0xC0 (192) + Me.theMdlFileData.localSequenceCount = ReadInt32BE() + Me.theMdlFileData.localSequenceOffset = ReadInt32BE() - ' Offsets: 0xC4, 0xC8 - Me.theMdlFileData.activityListVersion = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.eventsIndexed = Me.theInputFileReader.ReadInt32() + ' Offsets: 0xC4, 0xC8 + Me.theMdlFileData.activityListVersion = ReadInt32BE() + Me.theMdlFileData.eventsIndexed = ReadInt32BE() - ' Offsets: 0xCC (204), 0xD0 (208) - Me.theMdlFileData.textureCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.textureOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0xCC (204), 0xD0 (208) + Me.theMdlFileData.textureCount = ReadInt32BE() + Me.theMdlFileData.textureOffset = ReadInt32BE() - ' Offsets: 0xD4 (212), 0xD8 - Me.theMdlFileData.texturePathCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.texturePathOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0xD4 (212), 0xD8 + Me.theMdlFileData.texturePathCount = ReadInt32BE() + Me.theMdlFileData.texturePathOffset = ReadInt32BE() - ' Offsets: 0xDC, 0xE0 (224), 0xE4 (228) - Me.theMdlFileData.skinReferenceCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.skinFamilyCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.skinFamilyOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0xDC, 0xE0 (224), 0xE4 (228) + Me.theMdlFileData.skinReferenceCount = ReadInt32BE() + Me.theMdlFileData.skinFamilyCount = ReadInt32BE() + Me.theMdlFileData.skinFamilyOffset = ReadInt32BE() - ' Offsets: 0xE8 (232), 0xEC (236) - Me.theMdlFileData.bodyPartCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.bodyPartOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0xE8 (232), 0xEC (236) + Me.theMdlFileData.bodyPartCount = ReadInt32BE() + Me.theMdlFileData.bodyPartOffset = ReadInt32BE() - ' Offsets: 0xF0 (240), 0xF4 (244) - Me.theMdlFileData.localAttachmentCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.localAttachmentOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0xF0 (240), 0xF4 (244) + Me.theMdlFileData.localAttachmentCount = ReadInt32BE() + Me.theMdlFileData.localAttachmentOffset = ReadInt32BE() + + ' Offsets: 0xF8, 0xFC, 0x0100 + Me.theMdlFileData.localNodeCount = ReadInt32BE() + Me.theMdlFileData.localNodeOffset = ReadInt32BE() + Me.theMdlFileData.localNodeNameOffset = ReadInt32BE() + Else + ' Offsets: 0xB4 (180), 0xB8 + Me.theMdlFileData.localAnimationCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.localAnimationOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0xBC (188), 0xC0 (192) + Me.theMdlFileData.localSequenceCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.localSequenceOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0xC4, 0xC8 + Me.theMdlFileData.activityListVersion = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.eventsIndexed = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0xCC (204), 0xD0 (208) + Me.theMdlFileData.textureCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.textureOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0xD4 (212), 0xD8 + Me.theMdlFileData.texturePathCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.texturePathOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0xDC, 0xE0 (224), 0xE4 (228) + Me.theMdlFileData.skinReferenceCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.skinFamilyCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.skinFamilyOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0xE8 (232), 0xEC (236) + Me.theMdlFileData.bodyPartCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.bodyPartOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0xF0 (240), 0xF4 (244) + Me.theMdlFileData.localAttachmentCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.localAttachmentOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0xF8, 0xFC, 0x0100 + Me.theMdlFileData.localNodeCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.localNodeOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.localNodeNameOffset = Me.theInputFileReader.ReadInt32() + End If - ' Offsets: 0xF8, 0xFC, 0x0100 - Me.theMdlFileData.localNodeCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.localNodeOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.localNodeNameOffset = Me.theInputFileReader.ReadInt32() 'FROM: StudioMdl for MDL48 and MDL49 'EXTERN char *g_xnodename[100]; 'EXTERN Int g_xnode[100][100]; @@ -151,32 +298,61 @@ Public Class SourceMdlFile49 Me.theMdlFileData.localNodeCount = 100 End If - ' Offsets: 0x0104 (), 0x0108 () - Me.theMdlFileData.flexDescCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.flexDescOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + ' Offsets: 0x0104 (), 0x0108 () + Me.theMdlFileData.flexDescCount = ReadInt32BE() + Me.theMdlFileData.flexDescOffset = ReadInt32BE() + + ' Offsets: 0x010C (), 0x0110 () + Me.theMdlFileData.flexControllerCount = ReadInt32BE() + Me.theMdlFileData.flexControllerOffset = ReadInt32BE() + + ' Offsets: 0x0114 (), 0x0118 () + Me.theMdlFileData.flexRuleCount = ReadInt32BE() + Me.theMdlFileData.flexRuleOffset = ReadInt32BE() + + ' Offsets: 0x011C (), 0x0120 () + Me.theMdlFileData.ikChainCount = ReadInt32BE() + Me.theMdlFileData.ikChainOffset = ReadInt32BE() - ' Offsets: 0x010C (), 0x0110 () - Me.theMdlFileData.flexControllerCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.flexControllerOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0x0124 (), 0x0128 () + Me.theMdlFileData.mouthCount = ReadInt32BE() + Me.theMdlFileData.mouthOffset = ReadInt32BE() + + ' Offsets: 0x012C (), 0x0130 () + Me.theMdlFileData.localPoseParamaterCount = ReadInt32BE() + Me.theMdlFileData.localPoseParameterOffset = ReadInt32BE() + + ' Offsets: 0x0134 () + Me.theMdlFileData.surfacePropOffset = ReadInt32BE() + Else + ' Offsets: 0x0104 (), 0x0108 () + Me.theMdlFileData.flexDescCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.flexDescOffset = Me.theInputFileReader.ReadInt32() - ' Offsets: 0x0114 (), 0x0118 () - Me.theMdlFileData.flexRuleCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.flexRuleOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0x010C (), 0x0110 () + Me.theMdlFileData.flexControllerCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.flexControllerOffset = Me.theInputFileReader.ReadInt32() - ' Offsets: 0x011C (), 0x0120 () - Me.theMdlFileData.ikChainCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.ikChainOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0x0114 (), 0x0118 () + Me.theMdlFileData.flexRuleCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.flexRuleOffset = Me.theInputFileReader.ReadInt32() - ' Offsets: 0x0124 (), 0x0128 () - Me.theMdlFileData.mouthCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.mouthOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0x011C (), 0x0120 () + Me.theMdlFileData.ikChainCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.ikChainOffset = Me.theInputFileReader.ReadInt32() - ' Offsets: 0x012C (), 0x0130 () - Me.theMdlFileData.localPoseParamaterCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.localPoseParameterOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0x0124 (), 0x0128 () + Me.theMdlFileData.mouthCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.mouthOffset = Me.theInputFileReader.ReadInt32() - ' Offsets: 0x0134 () - Me.theMdlFileData.surfacePropOffset = Me.theInputFileReader.ReadInt32() + ' Offsets: 0x012C (), 0x0130 () + Me.theMdlFileData.localPoseParamaterCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.localPoseParameterOffset = Me.theInputFileReader.ReadInt32() + + ' Offsets: 0x0134 () + Me.theMdlFileData.surfacePropOffset = Me.theInputFileReader.ReadInt32() + End If 'TODO: Same as some lines below. Move to a separate function. If Me.theMdlFileData.surfacePropOffset > 0 Then @@ -195,25 +371,48 @@ Public Class SourceMdlFile49 Me.theMdlFileData.theSurfacePropName = "" End If - ' Offsets: 0x0138 (312), 0x013C (316) - Me.theMdlFileData.keyValueOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.keyValueSize = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + ' Offsets: 0x0138 (312), 0x013C (316) + Me.theMdlFileData.keyValueOffset = ReadInt32BE() + Me.theMdlFileData.keyValueSize = ReadInt32BE() + + Me.theMdlFileData.localIkAutoPlayLockCount = ReadInt32BE() + Me.theMdlFileData.localIkAutoPlayLockOffset = ReadInt32BE() + + Me.theMdlFileData.mass = ReadSingleBE() + Me.theMdlFileData.contents = ReadInt32BE() + + Me.theMdlFileData.includeModelCount = ReadInt32BE() + Me.theMdlFileData.includeModelOffset = ReadInt32BE() + + Me.theMdlFileData.virtualModelP = ReadInt32BE() + + Me.theMdlFileData.animBlockNameOffset = ReadInt32BE() + Me.theMdlFileData.animBlockCount = ReadInt32BE() + Me.theMdlFileData.animBlockOffset = ReadInt32BE() + Me.theMdlFileData.animBlockModelP = ReadInt32BE() + Else + ' Offsets: 0x0138 (312), 0x013C (316) + Me.theMdlFileData.keyValueOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.keyValueSize = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.localIkAutoPlayLockCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.localIkAutoPlayLockOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.localIkAutoPlayLockCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.localIkAutoPlayLockOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.mass = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.contents = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.mass = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.contents = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.includeModelCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.includeModelOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.includeModelCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.includeModelOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.virtualModelP = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.virtualModelP = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.animBlockNameOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.animBlockCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.animBlockOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.animBlockModelP = Me.theInputFileReader.ReadInt32() + End If - Me.theMdlFileData.animBlockNameOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.animBlockCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.animBlockOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.animBlockModelP = Me.theInputFileReader.ReadInt32() If Me.theMdlFileData.animBlockCount > 0 Then If Me.theMdlFileData.animBlockNameOffset > 0 Then inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -236,8 +435,13 @@ Public Class SourceMdlFile49 Me.theMdlFileData.theAnimBlocks = New List(Of SourceMdlAnimBlock)(Me.theMdlFileData.animBlockCount) For offset As Integer = 0 To Me.theMdlFileData.animBlockCount - 1 Dim anAnimBlock As New SourceMdlAnimBlock() - anAnimBlock.dataStart = Me.theInputFileReader.ReadInt32() - anAnimBlock.dataEnd = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anAnimBlock.dataStart = ReadInt32BE() + anAnimBlock.dataEnd = ReadInt32BE() + Else + anAnimBlock.dataStart = Me.theInputFileReader.ReadInt32() + anAnimBlock.dataEnd = Me.theInputFileReader.ReadInt32() + End If Me.theMdlFileData.theAnimBlocks.Add(anAnimBlock) Next @@ -249,30 +453,57 @@ Public Class SourceMdlFile49 End If End If - Me.theMdlFileData.boneTableByNameOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + Me.theMdlFileData.boneTableByNameOffset = ReadInt32BE() - Me.theMdlFileData.vertexBaseP = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.indexBaseP = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.vertexBaseP = ReadInt32BE() + Me.theMdlFileData.indexBaseP = ReadInt32BE() - Me.theMdlFileData.directionalLightDot = Me.theInputFileReader.ReadByte() + Me.theMdlFileData.directionalLightDot = Me.theInputFileReader.ReadByte() - Me.theMdlFileData.rootLod = Me.theInputFileReader.ReadByte() + Me.theMdlFileData.rootLod = Me.theInputFileReader.ReadByte() - Me.theMdlFileData.allowedRootLodCount_VERSION48 = Me.theInputFileReader.ReadByte() + Me.theMdlFileData.allowedRootLodCount_VERSION48 = Me.theInputFileReader.ReadByte() - Me.theMdlFileData.unused = Me.theInputFileReader.ReadByte() + Me.theMdlFileData.unused = Me.theInputFileReader.ReadByte() - Me.theMdlFileData.zeroframecacheindex_VERSION44to47 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.zeroframecacheindex_VERSION44to47 = ReadInt32BE() - Me.theMdlFileData.flexControllerUiCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.flexControllerUiOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.flexControllerUiCount = ReadInt32BE() + Me.theMdlFileData.flexControllerUiOffset = ReadInt32BE() - Me.theMdlFileData.vertAnimFixedPointScale = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.surfacePropLookup = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.vertAnimFixedPointScale = ReadSingleBE() + Me.theMdlFileData.surfacePropLookup = ReadInt32BE() + + Me.theMdlFileData.studioHeader2Offset = ReadInt32BE() + + Me.theMdlFileData.unused2 = ReadInt32BE() + Else + Me.theMdlFileData.boneTableByNameOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.studioHeader2Offset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.vertexBaseP = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.indexBaseP = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unused2 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.directionalLightDot = Me.theInputFileReader.ReadByte() + + Me.theMdlFileData.rootLod = Me.theInputFileReader.ReadByte() + + Me.theMdlFileData.allowedRootLodCount_VERSION48 = Me.theInputFileReader.ReadByte() + + Me.theMdlFileData.unused = Me.theInputFileReader.ReadByte() + + Me.theMdlFileData.zeroframecacheindex_VERSION44to47 = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.flexControllerUiCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.flexControllerUiOffset = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.vertAnimFixedPointScale = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.surfacePropLookup = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.studioHeader2Offset = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.unused2 = Me.theInputFileReader.ReadInt32() + End If fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, logDescription) @@ -291,41 +522,92 @@ Public Class SourceMdlFile49 fileOffsetStart = Me.theInputFileReader.BaseStream.Position - Me.theMdlFileData.sourceBoneTransformCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.sourceBoneTransformOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.illumPositionAttachmentNumber = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.maxEyeDeflection = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.linearBoneOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + Me.theMdlFileData.sourceBoneTransformCount = ReadInt32BE() + Me.theMdlFileData.sourceBoneTransformOffset = ReadInt32BE() + Me.theMdlFileData.illumPositionAttachmentNumber = ReadInt32BE() + Me.theMdlFileData.maxEyeDeflection = ReadSingleBE() + Me.theMdlFileData.linearBoneOffset = ReadInt32BE() + Else + Me.theMdlFileData.sourceBoneTransformCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.sourceBoneTransformOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.illumPositionAttachmentNumber = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.maxEyeDeflection = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.linearBoneOffset = Me.theInputFileReader.ReadInt32() + End If 'TODO: According to MDL v48 source code, the following fields are not used. ' Test various MDL v48 models to see if any use these. + If TheApp.Settings.IsPostal3IsChecked Then + 'Just fillers for Crowbar + Me.theMdlFileData.theNameCopy = "" - Me.theMdlFileData.nameCopyOffset = Me.theInputFileReader.ReadInt32() - If Me.theMdlFileData.nameCopyOffset > 0 Then - inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Me.theInputFileReader.BaseStream.Seek(fileOffsetStart + Me.theMdlFileData.nameCopyOffset, SeekOrigin.Begin) - fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position + Me.theMdlFileData.boneFlexDriverCount = 0 + Me.theMdlFileData.boneFlexDriverOffset = 0 - Me.theMdlFileData.theNameCopy = FileManager.ReadNullTerminatedString(Me.theInputFileReader) - Me.theMdlFileData.theModelName = Me.theMdlFileData.theNameCopy + Me.theMdlFileData.unknownValue = 0 - fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 - Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart2, fileOffsetEnd2, "theMdlFileData.theNameCopy = " + Me.theMdlFileData.theNameCopy) - Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) + Me.theMdlFileData.bodygroupPresetCount = 0 + Me.theMdlFileData.bodygroupPresetOffset = 0 + + 'Actual Postal III data here + If Me.theMdlFileData.isBigEndian Then + Me.theMdlFileData.numBoltons = ReadInt32BE() + Me.theMdlFileData.boltonIndex = ReadInt32BE() + Me.theMdlFileData.numPrefabs = ReadInt32BE() + Me.theMdlFileData.prefabIndex = ReadInt32BE() + Else + Me.theMdlFileData.numBoltons = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.boltonIndex = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.numPrefabs = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.prefabIndex = Me.theInputFileReader.ReadInt32() + End If Else - Me.theMdlFileData.theNameCopy = "" - End If + If Me.theMdlFileData.isBigEndian Then + Me.theMdlFileData.nameCopyOffset = ReadInt32BE() + Else + Me.theMdlFileData.nameCopyOffset = Me.theInputFileReader.ReadInt32() + End If + If Me.theMdlFileData.nameCopyOffset > 0 Then + inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + Me.theInputFileReader.BaseStream.Seek(fileOffsetStart + Me.theMdlFileData.nameCopyOffset, SeekOrigin.Begin) + fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position + + Me.theMdlFileData.theNameCopy = FileManager.ReadNullTerminatedString(Me.theInputFileReader) + Me.theMdlFileData.theModelName = Me.theMdlFileData.theNameCopy + + fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart2, fileOffsetEnd2, "theMdlFileData.theNameCopy = " + Me.theMdlFileData.theNameCopy) + Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) + Else + Me.theMdlFileData.theNameCopy = "" + End If + + If Me.theMdlFileData.isBigEndian Then + Me.theMdlFileData.boneFlexDriverCount = ReadInt32BE() + Me.theMdlFileData.boneFlexDriverOffset = ReadInt32BE() - Me.theMdlFileData.boneFlexDriverCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.boneFlexDriverOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.unknownValue = ReadInt32BE() - Me.theMdlFileData.unknownValue = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.bodygroupPresetCount = ReadInt32BE() + Me.theMdlFileData.bodygroupPresetOffset = fileOffsetStart + ReadInt32BE() + Else + Me.theMdlFileData.boneFlexDriverCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.boneFlexDriverOffset = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.unknownValue = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.bodygroupPresetCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.bodygroupPresetOffset = fileOffsetStart + Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.bodygroupPresetCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.bodygroupPresetOffset = fileOffsetStart + Me.theInputFileReader.ReadInt32() + End If + End If For x As Integer = 0 To Me.theMdlFileData.reserved.Length - 1 - Me.theMdlFileData.reserved(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + Me.theMdlFileData.reserved(x) = ReadInt32BE() + Else + Me.theMdlFileData.reserved(x) = Me.theInputFileReader.ReadInt32() + End If Next fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 @@ -350,69 +632,146 @@ Public Class SourceMdlFile49 boneInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aBone As New SourceMdlBone() - aBone.nameOffset = Me.theInputFileReader.ReadInt32() - aBone.parentBoneIndex = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBone.nameOffset = ReadInt32BE() + aBone.parentBoneIndex = ReadInt32BE() + Else + aBone.nameOffset = Me.theInputFileReader.ReadInt32() + aBone.parentBoneIndex = Me.theInputFileReader.ReadInt32() + End If For j As Integer = 0 To aBone.boneControllerIndex.Length - 1 - aBone.boneControllerIndex(j) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBone.boneControllerIndex(j) = ReadInt32BE() + Else + aBone.boneControllerIndex(j) = Me.theInputFileReader.ReadInt32() + End If Next aBone.position = New SourceVector() - aBone.position.x = Me.theInputFileReader.ReadSingle() - aBone.position.y = Me.theInputFileReader.ReadSingle() - aBone.position.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.position.x = ReadSingleBE() + aBone.position.y = ReadSingleBE() + aBone.position.z = ReadSingleBE() + Else + aBone.position.x = Me.theInputFileReader.ReadSingle() + aBone.position.y = Me.theInputFileReader.ReadSingle() + aBone.position.z = Me.theInputFileReader.ReadSingle() + End If aBone.quat = New SourceQuaternion() - aBone.quat.x = Me.theInputFileReader.ReadSingle() - aBone.quat.y = Me.theInputFileReader.ReadSingle() - aBone.quat.z = Me.theInputFileReader.ReadSingle() - aBone.quat.w = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.quat.x = ReadSingleBE() + aBone.quat.y = ReadSingleBE() + aBone.quat.z = ReadSingleBE() + aBone.quat.w = ReadSingleBE() + Else + aBone.quat.x = Me.theInputFileReader.ReadSingle() + aBone.quat.y = Me.theInputFileReader.ReadSingle() + aBone.quat.z = Me.theInputFileReader.ReadSingle() + aBone.quat.w = Me.theInputFileReader.ReadSingle() + End If aBone.rotation = New SourceVector() - aBone.rotation.x = Me.theInputFileReader.ReadSingle() - aBone.rotation.y = Me.theInputFileReader.ReadSingle() - aBone.rotation.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.rotation.x = ReadSingleBE() + aBone.rotation.y = ReadSingleBE() + aBone.rotation.z = ReadSingleBE() + Else + aBone.rotation.x = Me.theInputFileReader.ReadSingle() + aBone.rotation.y = Me.theInputFileReader.ReadSingle() + aBone.rotation.z = Me.theInputFileReader.ReadSingle() + End If + aBone.positionScale = New SourceVector() - aBone.positionScale.x = Me.theInputFileReader.ReadSingle() - aBone.positionScale.y = Me.theInputFileReader.ReadSingle() - aBone.positionScale.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.positionScale.x = ReadSingleBE() + aBone.positionScale.y = ReadSingleBE() + aBone.positionScale.z = ReadSingleBE() + Else + aBone.positionScale.x = Me.theInputFileReader.ReadSingle() + aBone.positionScale.y = Me.theInputFileReader.ReadSingle() + aBone.positionScale.z = Me.theInputFileReader.ReadSingle() + End If + aBone.rotationScale = New SourceVector() - aBone.rotationScale.x = Me.theInputFileReader.ReadSingle() - aBone.rotationScale.y = Me.theInputFileReader.ReadSingle() - aBone.rotationScale.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.rotationScale.x = ReadSingleBE() + aBone.rotationScale.y = ReadSingleBE() + aBone.rotationScale.z = ReadSingleBE() + Else + aBone.rotationScale.x = Me.theInputFileReader.ReadSingle() + aBone.rotationScale.y = Me.theInputFileReader.ReadSingle() + aBone.rotationScale.z = Me.theInputFileReader.ReadSingle() + End If aBone.poseToBoneColumn0 = New SourceVector() aBone.poseToBoneColumn1 = New SourceVector() aBone.poseToBoneColumn2 = New SourceVector() aBone.poseToBoneColumn3 = New SourceVector() - aBone.poseToBoneColumn0.x = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn1.x = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn2.x = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn3.x = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn0.y = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn1.y = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn2.y = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn3.y = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn0.z = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn1.z = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn2.z = Me.theInputFileReader.ReadSingle() - aBone.poseToBoneColumn3.z = Me.theInputFileReader.ReadSingle() - - aBone.qAlignment = New SourceQuaternion() - aBone.qAlignment.x = Me.theInputFileReader.ReadSingle() - aBone.qAlignment.y = Me.theInputFileReader.ReadSingle() - aBone.qAlignment.z = Me.theInputFileReader.ReadSingle() - aBone.qAlignment.w = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.poseToBoneColumn0.x = ReadSingleBE() + aBone.poseToBoneColumn1.x = ReadSingleBE() + aBone.poseToBoneColumn2.x = ReadSingleBE() + aBone.poseToBoneColumn3.x = ReadSingleBE() + aBone.poseToBoneColumn0.y = ReadSingleBE() + aBone.poseToBoneColumn1.y = ReadSingleBE() + aBone.poseToBoneColumn2.y = ReadSingleBE() + aBone.poseToBoneColumn3.y = ReadSingleBE() + aBone.poseToBoneColumn0.z = ReadSingleBE() + aBone.poseToBoneColumn1.z = ReadSingleBE() + aBone.poseToBoneColumn2.z = ReadSingleBE() + aBone.poseToBoneColumn3.z = ReadSingleBE() + Else + aBone.poseToBoneColumn0.x = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn1.x = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn2.x = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn3.x = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn0.y = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn1.y = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn2.y = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn3.y = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn0.z = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn1.z = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn2.z = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn3.z = Me.theInputFileReader.ReadSingle() + End If - aBone.flags = Me.theInputFileReader.ReadInt32() - aBone.proceduralRuleType = Me.theInputFileReader.ReadInt32() - aBone.proceduralRuleOffset = Me.theInputFileReader.ReadInt32() - aBone.physicsBoneIndex = Me.theInputFileReader.ReadInt32() - aBone.surfacePropNameOffset = Me.theInputFileReader.ReadInt32() - aBone.contents = Me.theInputFileReader.ReadInt32() + aBone.qAlignment = New SourceQuaternion() + If Me.theMdlFileData.isBigEndian Then + aBone.qAlignment.x = ReadSingleBE() + aBone.qAlignment.y = ReadSingleBE() + aBone.qAlignment.z = ReadSingleBE() + aBone.qAlignment.w = ReadSingleBE() + + aBone.flags = ReadInt32BE() + + aBone.proceduralRuleType = ReadInt32BE() + aBone.proceduralRuleOffset = ReadInt32BE() + aBone.physicsBoneIndex = ReadInt32BE() + aBone.surfacePropNameOffset = ReadInt32BE() + aBone.contents = ReadInt32BE() + Else + aBone.qAlignment.x = Me.theInputFileReader.ReadSingle() + aBone.qAlignment.y = Me.theInputFileReader.ReadSingle() + aBone.qAlignment.z = Me.theInputFileReader.ReadSingle() + aBone.qAlignment.w = Me.theInputFileReader.ReadSingle() + + aBone.flags = Me.theInputFileReader.ReadInt32() + + aBone.proceduralRuleType = Me.theInputFileReader.ReadInt32() + aBone.proceduralRuleOffset = Me.theInputFileReader.ReadInt32() + aBone.physicsBoneIndex = Me.theInputFileReader.ReadInt32() + aBone.surfacePropNameOffset = Me.theInputFileReader.ReadInt32() + aBone.contents = Me.theInputFileReader.ReadInt32() + End If For k As Integer = 0 To 7 - aBone.unused(k) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBone.unused(k) = ReadInt32BE() + Else + aBone.unused(k) = Me.theInputFileReader.ReadInt32() + End If Next Me.theMdlFileData.theBones.Add(aBone) @@ -493,17 +852,35 @@ Public Class SourceMdlFile49 axisInterpBoneInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position aBone.theAxisInterpBone = New SourceMdlAxisInterpBone() - aBone.theAxisInterpBone.control = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBone.theAxisInterpBone.control = ReadInt32BE() + Else + aBone.theAxisInterpBone.control = Me.theInputFileReader.ReadInt32() + End If + For x As Integer = 0 To aBone.theAxisInterpBone.pos.Length - 1 - aBone.theAxisInterpBone.pos(x).x = Me.theInputFileReader.ReadSingle() - aBone.theAxisInterpBone.pos(x).y = Me.theInputFileReader.ReadSingle() - aBone.theAxisInterpBone.pos(x).z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.theAxisInterpBone.pos(x).x = ReadSingleBE() + aBone.theAxisInterpBone.pos(x).y = ReadSingleBE() + aBone.theAxisInterpBone.pos(x).z = ReadSingleBE() + Else + aBone.theAxisInterpBone.pos(x).x = Me.theInputFileReader.ReadSingle() + aBone.theAxisInterpBone.pos(x).y = Me.theInputFileReader.ReadSingle() + aBone.theAxisInterpBone.pos(x).z = Me.theInputFileReader.ReadSingle() + End If Next For x As Integer = 0 To aBone.theAxisInterpBone.quat.Length - 1 - aBone.theAxisInterpBone.quat(x).x = Me.theInputFileReader.ReadSingle() - aBone.theAxisInterpBone.quat(x).y = Me.theInputFileReader.ReadSingle() - aBone.theAxisInterpBone.quat(x).z = Me.theInputFileReader.ReadSingle() - aBone.theAxisInterpBone.quat(x).z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.theAxisInterpBone.quat(x).x = ReadSingleBE() + aBone.theAxisInterpBone.quat(x).y = ReadSingleBE() + aBone.theAxisInterpBone.quat(x).z = ReadSingleBE() + aBone.theAxisInterpBone.quat(x).z = ReadSingleBE() + Else + aBone.theAxisInterpBone.quat(x).x = Me.theInputFileReader.ReadSingle() + aBone.theAxisInterpBone.quat(x).y = Me.theInputFileReader.ReadSingle() + aBone.theAxisInterpBone.quat(x).z = Me.theInputFileReader.ReadSingle() + aBone.theAxisInterpBone.quat(x).z = Me.theInputFileReader.ReadSingle() + End If Next inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -532,9 +909,15 @@ Public Class SourceMdlFile49 quatInterpBoneInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position aBone.theQuatInterpBone = New SourceMdlQuatInterpBone() - aBone.theQuatInterpBone.controlBoneIndex = Me.theInputFileReader.ReadInt32() - aBone.theQuatInterpBone.triggerCount = Me.theInputFileReader.ReadInt32() - aBone.theQuatInterpBone.triggerOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBone.theQuatInterpBone.controlBoneIndex = ReadInt32BE() + aBone.theQuatInterpBone.triggerCount = ReadInt32BE() + aBone.theQuatInterpBone.triggerOffset = ReadInt32BE() + Else + aBone.theQuatInterpBone.controlBoneIndex = Me.theInputFileReader.ReadInt32() + aBone.theQuatInterpBone.triggerCount = Me.theInputFileReader.ReadInt32() + aBone.theQuatInterpBone.triggerOffset = Me.theInputFileReader.ReadInt32() + End If inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -561,23 +944,46 @@ Public Class SourceMdlFile49 aimAtBoneInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position aBone.theAimAtBone = New SourceMdlAimAtBone() - aBone.theAimAtBone.parentBoneIndex = Me.theInputFileReader.ReadInt32() - aBone.theAimAtBone.aimBoneOrAttachmentIndex = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBone.theAimAtBone.parentBoneIndex = ReadInt32BE() + aBone.theAimAtBone.aimBoneOrAttachmentIndex = ReadInt32BE() + Else + aBone.theAimAtBone.parentBoneIndex = Me.theInputFileReader.ReadInt32() + aBone.theAimAtBone.aimBoneOrAttachmentIndex = Me.theInputFileReader.ReadInt32() + End If aBone.theAimAtBone.aim = New SourceVector() - aBone.theAimAtBone.aim.x = Me.theInputFileReader.ReadSingle() - aBone.theAimAtBone.aim.y = Me.theInputFileReader.ReadSingle() - aBone.theAimAtBone.aim.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.theAimAtBone.aim.x = ReadSingleBE() + aBone.theAimAtBone.aim.y = ReadSingleBE() + aBone.theAimAtBone.aim.z = ReadSingleBE() + Else + aBone.theAimAtBone.aim.x = Me.theInputFileReader.ReadSingle() + aBone.theAimAtBone.aim.y = Me.theInputFileReader.ReadSingle() + aBone.theAimAtBone.aim.z = Me.theInputFileReader.ReadSingle() + End If aBone.theAimAtBone.up = New SourceVector() - aBone.theAimAtBone.up.x = Me.theInputFileReader.ReadSingle() - aBone.theAimAtBone.up.y = Me.theInputFileReader.ReadSingle() - aBone.theAimAtBone.up.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.theAimAtBone.up.x = ReadSingleBE() + aBone.theAimAtBone.up.y = ReadSingleBE() + aBone.theAimAtBone.up.z = ReadSingleBE() + Else + aBone.theAimAtBone.up.x = Me.theInputFileReader.ReadSingle() + aBone.theAimAtBone.up.y = Me.theInputFileReader.ReadSingle() + aBone.theAimAtBone.up.z = Me.theInputFileReader.ReadSingle() + End If aBone.theAimAtBone.basePos = New SourceVector() - aBone.theAimAtBone.basePos.x = Me.theInputFileReader.ReadSingle() - aBone.theAimAtBone.basePos.y = Me.theInputFileReader.ReadSingle() - aBone.theAimAtBone.basePos.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.theAimAtBone.basePos.x = ReadSingleBE() + aBone.theAimAtBone.basePos.y = ReadSingleBE() + aBone.theAimAtBone.basePos.z = ReadSingleBE() + Else + aBone.theAimAtBone.basePos.x = Me.theInputFileReader.ReadSingle() + aBone.theAimAtBone.basePos.y = Me.theInputFileReader.ReadSingle() + aBone.theAimAtBone.basePos.z = Me.theInputFileReader.ReadSingle() + End If fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "aBone.theAimAtBone") @@ -598,24 +1004,48 @@ Public Class SourceMdlFile49 For j As Integer = 0 To aQuatInterpBone.triggerCount - 1 Dim aTrigger As New SourceMdlQuatInterpBoneInfo() - aTrigger.inverseToleranceAngle = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aTrigger.inverseToleranceAngle = ReadSingleBE() + Else + aTrigger.inverseToleranceAngle = Me.theInputFileReader.ReadSingle() + End If aTrigger.trigger = New SourceQuaternion() - aTrigger.trigger.x = Me.theInputFileReader.ReadSingle() - aTrigger.trigger.y = Me.theInputFileReader.ReadSingle() - aTrigger.trigger.z = Me.theInputFileReader.ReadSingle() - aTrigger.trigger.w = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aTrigger.trigger.x = ReadSingleBE() + aTrigger.trigger.y = ReadSingleBE() + aTrigger.trigger.z = ReadSingleBE() + aTrigger.trigger.w = ReadSingleBE() + Else + aTrigger.trigger.x = Me.theInputFileReader.ReadSingle() + aTrigger.trigger.y = Me.theInputFileReader.ReadSingle() + aTrigger.trigger.z = Me.theInputFileReader.ReadSingle() + aTrigger.trigger.w = Me.theInputFileReader.ReadSingle() + End If aTrigger.pos = New SourceVector() - aTrigger.pos.x = Me.theInputFileReader.ReadSingle() - aTrigger.pos.y = Me.theInputFileReader.ReadSingle() - aTrigger.pos.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aTrigger.pos.x = ReadSingleBE() + aTrigger.pos.y = ReadSingleBE() + aTrigger.pos.z = ReadSingleBE() + Else + aTrigger.pos.x = Me.theInputFileReader.ReadSingle() + aTrigger.pos.y = Me.theInputFileReader.ReadSingle() + aTrigger.pos.z = Me.theInputFileReader.ReadSingle() + End If aTrigger.quat = New SourceQuaternion() - aTrigger.quat.x = Me.theInputFileReader.ReadSingle() - aTrigger.quat.y = Me.theInputFileReader.ReadSingle() - aTrigger.quat.z = Me.theInputFileReader.ReadSingle() - aTrigger.quat.w = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aTrigger.quat.x = ReadSingleBE() + aTrigger.quat.y = ReadSingleBE() + aTrigger.quat.z = ReadSingleBE() + aTrigger.quat.w = ReadSingleBE() + Else + aTrigger.quat.x = Me.theInputFileReader.ReadSingle() + aTrigger.quat.y = Me.theInputFileReader.ReadSingle() + aTrigger.quat.z = Me.theInputFileReader.ReadSingle() + aTrigger.quat.w = Me.theInputFileReader.ReadSingle() + End If aQuatInterpBone.theTriggers.Add(aTrigger) Next @@ -634,52 +1064,98 @@ Public Class SourceMdlFile49 fileOffsetStart = Me.theInputFileReader.BaseStream.Position aBone.theJiggleBone = New SourceMdlJiggleBone() - aBone.theJiggleBone.flags = Me.theInputFileReader.ReadInt32() - aBone.theJiggleBone.length = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.tipMass = Me.theInputFileReader.ReadSingle() - - aBone.theJiggleBone.yawStiffness = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.yawDamping = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.pitchStiffness = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.pitchDamping = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.alongStiffness = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.alongDamping = Me.theInputFileReader.ReadSingle() - - aBone.theJiggleBone.angleLimit = Me.theInputFileReader.ReadSingle() - - aBone.theJiggleBone.minYaw = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.maxYaw = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.yawFriction = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.yawBounce = Me.theInputFileReader.ReadSingle() - - aBone.theJiggleBone.minPitch = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.maxPitch = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.pitchFriction = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.pitchBounce = Me.theInputFileReader.ReadSingle() - - aBone.theJiggleBone.baseMass = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseStiffness = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseDamping = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseMinLeft = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseMaxLeft = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseLeftFriction = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseMinUp = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseMaxUp = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseUpFriction = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseMinForward = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseMaxForward = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.baseForwardFriction = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.theJiggleBone.flags = ReadInt32BE() + aBone.theJiggleBone.length = ReadSingleBE() + aBone.theJiggleBone.tipMass = ReadSingleBE() + + aBone.theJiggleBone.yawStiffness = ReadSingleBE() + aBone.theJiggleBone.yawDamping = ReadSingleBE() + aBone.theJiggleBone.pitchStiffness = ReadSingleBE() + aBone.theJiggleBone.pitchDamping = ReadSingleBE() + aBone.theJiggleBone.alongStiffness = ReadSingleBE() + aBone.theJiggleBone.alongDamping = ReadSingleBE() + + aBone.theJiggleBone.angleLimit = ReadSingleBE() + + aBone.theJiggleBone.minYaw = ReadSingleBE() + aBone.theJiggleBone.maxYaw = ReadSingleBE() + aBone.theJiggleBone.yawFriction = ReadSingleBE() + aBone.theJiggleBone.yawBounce = ReadSingleBE() + + aBone.theJiggleBone.minPitch = ReadSingleBE() + aBone.theJiggleBone.maxPitch = ReadSingleBE() + aBone.theJiggleBone.pitchFriction = ReadSingleBE() + aBone.theJiggleBone.pitchBounce = ReadSingleBE() + + aBone.theJiggleBone.baseMass = ReadSingleBE() + aBone.theJiggleBone.baseStiffness = ReadSingleBE() + aBone.theJiggleBone.baseDamping = ReadSingleBE() + aBone.theJiggleBone.baseMinLeft = ReadSingleBE() + aBone.theJiggleBone.baseMaxLeft = ReadSingleBE() + aBone.theJiggleBone.baseLeftFriction = ReadSingleBE() + aBone.theJiggleBone.baseMinUp = ReadSingleBE() + aBone.theJiggleBone.baseMaxUp = ReadSingleBE() + aBone.theJiggleBone.baseUpFriction = ReadSingleBE() + aBone.theJiggleBone.baseMinForward = ReadSingleBE() + aBone.theJiggleBone.baseMaxForward = ReadSingleBE() + aBone.theJiggleBone.baseForwardFriction = ReadSingleBE() + Else + aBone.theJiggleBone.flags = Me.theInputFileReader.ReadInt32() + aBone.theJiggleBone.length = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.tipMass = Me.theInputFileReader.ReadSingle() + + aBone.theJiggleBone.yawStiffness = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.yawDamping = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.pitchStiffness = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.pitchDamping = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.alongStiffness = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.alongDamping = Me.theInputFileReader.ReadSingle() + + aBone.theJiggleBone.angleLimit = Me.theInputFileReader.ReadSingle() + + aBone.theJiggleBone.minYaw = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.maxYaw = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.yawFriction = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.yawBounce = Me.theInputFileReader.ReadSingle() + + aBone.theJiggleBone.minPitch = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.maxPitch = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.pitchFriction = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.pitchBounce = Me.theInputFileReader.ReadSingle() + + aBone.theJiggleBone.baseMass = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseStiffness = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseDamping = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseMinLeft = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseMaxLeft = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseLeftFriction = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseMinUp = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseMaxUp = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseUpFriction = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseMinForward = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseMaxForward = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.baseForwardFriction = Me.theInputFileReader.ReadSingle() + End If 'NOTE: How to determine when to read in these bytes that probably are only compiled with Source SDK Base 2013 MP and SP? ' Only read these bytes if aBone.theJiggleBone.flags has "is_boing" set. ' The only disadvantage is decompile-MDL log will show "unread bytes" when the flag is not set for models that have these bytes, ' but "unread bytes" often show up for alignment bytes anyway. If (aBone.theJiggleBone.flags And SourceMdlJiggleBone.JIGGLE_IS_BOING) > 0 AndAlso (Me.theMdlFileData.version = 48 OrElse Me.theMdlFileData.version = 49) Then - aBone.theJiggleBone.boingImpactSpeed = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.boingImpactAngle = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.boingDampingRate = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.boingFrequency = Me.theInputFileReader.ReadSingle() - aBone.theJiggleBone.boingAmplitude = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBone.theJiggleBone.boingImpactSpeed = ReadSingleBE() + aBone.theJiggleBone.boingImpactAngle = ReadSingleBE() + aBone.theJiggleBone.boingDampingRate = ReadSingleBE() + aBone.theJiggleBone.boingFrequency = ReadSingleBE() + aBone.theJiggleBone.boingAmplitude = ReadSingleBE() + Else + aBone.theJiggleBone.boingImpactSpeed = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.boingImpactAngle = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.boingDampingRate = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.boingFrequency = Me.theInputFileReader.ReadSingle() + aBone.theJiggleBone.boingAmplitude = Me.theInputFileReader.ReadSingle() + End If End If fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 @@ -703,15 +1179,29 @@ Public Class SourceMdlFile49 boneControllerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aBoneController As New SourceMdlBoneController() - aBoneController.boneIndex = Me.theInputFileReader.ReadInt32() - aBoneController.type = Me.theInputFileReader.ReadInt32() - aBoneController.startBlah = Me.theInputFileReader.ReadSingle() - aBoneController.endBlah = Me.theInputFileReader.ReadSingle() - aBoneController.restIndex = Me.theInputFileReader.ReadInt32() - aBoneController.inputField = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBoneController.boneIndex = ReadInt32BE() + aBoneController.type = ReadInt32BE() + aBoneController.startBlah = ReadSingleBE() + aBoneController.endBlah = ReadSingleBE() + aBoneController.restIndex = ReadInt32BE() + aBoneController.inputField = ReadInt32BE() + Else + aBoneController.boneIndex = Me.theInputFileReader.ReadInt32() + aBoneController.type = Me.theInputFileReader.ReadInt32() + aBoneController.startBlah = Me.theInputFileReader.ReadSingle() + aBoneController.endBlah = Me.theInputFileReader.ReadSingle() + aBoneController.restIndex = Me.theInputFileReader.ReadInt32() + aBoneController.inputField = Me.theInputFileReader.ReadInt32() + End If + If Me.theMdlFileData.version > 10 Then For x As Integer = 0 To aBoneController.unused.Length - 1 - aBoneController.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBoneController.unused(x) = ReadInt32BE() + Else + aBoneController.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next End If @@ -764,37 +1254,78 @@ Public Class SourceMdlFile49 anAttachment.name = Me.theInputFileReader.ReadChars(32) anAttachment.theName = anAttachment.name anAttachment.theName = StringClass.ConvertFromNullTerminatedOrFullLengthString(anAttachment.theName) - anAttachment.type = Me.theInputFileReader.ReadInt32() - anAttachment.bone = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anAttachment.type = ReadInt32BE() + anAttachment.bone = ReadInt32BE() + Else + anAttachment.type = Me.theInputFileReader.ReadInt32() + anAttachment.bone = Me.theInputFileReader.ReadInt32() + End If anAttachment.attachmentPoint = New SourceVector() - anAttachment.attachmentPoint.x = Me.theInputFileReader.ReadSingle() - anAttachment.attachmentPoint.y = Me.theInputFileReader.ReadSingle() - anAttachment.attachmentPoint.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + anAttachment.attachmentPoint.x = ReadSingleBE() + anAttachment.attachmentPoint.y = ReadSingleBE() + anAttachment.attachmentPoint.z = ReadSingleBE() + Else + anAttachment.attachmentPoint.x = Me.theInputFileReader.ReadSingle() + anAttachment.attachmentPoint.y = Me.theInputFileReader.ReadSingle() + anAttachment.attachmentPoint.z = Me.theInputFileReader.ReadSingle() + End If + For x As Integer = 0 To 2 anAttachment.vectors(x) = New SourceVector() - anAttachment.vectors(x).x = Me.theInputFileReader.ReadSingle() - anAttachment.vectors(x).y = Me.theInputFileReader.ReadSingle() - anAttachment.vectors(x).z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + anAttachment.vectors(x).x = ReadSingleBE() + anAttachment.vectors(x).y = ReadSingleBE() + anAttachment.vectors(x).z = ReadSingleBE() + Else + anAttachment.vectors(x).x = Me.theInputFileReader.ReadSingle() + anAttachment.vectors(x).y = Me.theInputFileReader.ReadSingle() + anAttachment.vectors(x).z = Me.theInputFileReader.ReadSingle() + End If Next Else - anAttachment.nameOffset = Me.theInputFileReader.ReadInt32() - anAttachment.flags = Me.theInputFileReader.ReadInt32() - anAttachment.localBoneIndex = Me.theInputFileReader.ReadInt32() - anAttachment.localM11 = Me.theInputFileReader.ReadSingle() - anAttachment.localM12 = Me.theInputFileReader.ReadSingle() - anAttachment.localM13 = Me.theInputFileReader.ReadSingle() - anAttachment.localM14 = Me.theInputFileReader.ReadSingle() - anAttachment.localM21 = Me.theInputFileReader.ReadSingle() - anAttachment.localM22 = Me.theInputFileReader.ReadSingle() - anAttachment.localM23 = Me.theInputFileReader.ReadSingle() - anAttachment.localM24 = Me.theInputFileReader.ReadSingle() - anAttachment.localM31 = Me.theInputFileReader.ReadSingle() - anAttachment.localM32 = Me.theInputFileReader.ReadSingle() - anAttachment.localM33 = Me.theInputFileReader.ReadSingle() - anAttachment.localM34 = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + anAttachment.nameOffset = ReadInt32BE() + anAttachment.flags = ReadInt32BE() + anAttachment.localBoneIndex = ReadInt32BE() + anAttachment.localM11 = ReadSingleBE() + anAttachment.localM12 = ReadSingleBE() + anAttachment.localM13 = ReadSingleBE() + anAttachment.localM14 = ReadSingleBE() + anAttachment.localM21 = ReadSingleBE() + anAttachment.localM22 = ReadSingleBE() + anAttachment.localM23 = ReadSingleBE() + anAttachment.localM24 = ReadSingleBE() + anAttachment.localM31 = ReadSingleBE() + anAttachment.localM32 = ReadSingleBE() + anAttachment.localM33 = ReadSingleBE() + anAttachment.localM34 = ReadSingleBE() + Else + anAttachment.nameOffset = Me.theInputFileReader.ReadInt32() + anAttachment.flags = Me.theInputFileReader.ReadInt32() + anAttachment.localBoneIndex = Me.theInputFileReader.ReadInt32() + anAttachment.localM11 = Me.theInputFileReader.ReadSingle() + anAttachment.localM12 = Me.theInputFileReader.ReadSingle() + anAttachment.localM13 = Me.theInputFileReader.ReadSingle() + anAttachment.localM14 = Me.theInputFileReader.ReadSingle() + anAttachment.localM21 = Me.theInputFileReader.ReadSingle() + anAttachment.localM22 = Me.theInputFileReader.ReadSingle() + anAttachment.localM23 = Me.theInputFileReader.ReadSingle() + anAttachment.localM24 = Me.theInputFileReader.ReadSingle() + anAttachment.localM31 = Me.theInputFileReader.ReadSingle() + anAttachment.localM32 = Me.theInputFileReader.ReadSingle() + anAttachment.localM33 = Me.theInputFileReader.ReadSingle() + anAttachment.localM34 = Me.theInputFileReader.ReadSingle() + End If + For x As Integer = 0 To 7 - anAttachment.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anAttachment.unused(x) = ReadInt32BE() + Else + anAttachment.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next End If @@ -843,9 +1374,16 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.hitboxSetCount - 1 hitboxSetInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aHitboxSet As New SourceMdlHitboxSet() - aHitboxSet.nameOffset = Me.theInputFileReader.ReadInt32() - aHitboxSet.hitboxCount = Me.theInputFileReader.ReadInt32() - aHitboxSet.hitboxOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aHitboxSet.nameOffset = ReadInt32BE() + aHitboxSet.hitboxCount = ReadInt32BE() + aHitboxSet.hitboxOffset = ReadInt32BE() + Else + aHitboxSet.nameOffset = Me.theInputFileReader.ReadInt32() + aHitboxSet.hitboxCount = Me.theInputFileReader.ReadInt32() + aHitboxSet.hitboxOffset = Me.theInputFileReader.ReadInt32() + End If + Me.theMdlFileData.theHitboxSets.Add(aHitboxSet) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -898,22 +1436,44 @@ Public Class SourceMdlFile49 hitboxInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aHitbox As New SourceMdlHitbox() - aHitbox.boneIndex = Me.theInputFileReader.ReadInt32() - aHitbox.groupIndex = Me.theInputFileReader.ReadInt32() - aHitbox.boundingBoxMin.x = Me.theInputFileReader.ReadSingle() - aHitbox.boundingBoxMin.y = Me.theInputFileReader.ReadSingle() - aHitbox.boundingBoxMin.z = Me.theInputFileReader.ReadSingle() - aHitbox.boundingBoxMax.x = Me.theInputFileReader.ReadSingle() - aHitbox.boundingBoxMax.y = Me.theInputFileReader.ReadSingle() - aHitbox.boundingBoxMax.z = Me.theInputFileReader.ReadSingle() - aHitbox.nameOffset = Me.theInputFileReader.ReadInt32() - 'NOTE: Roll (z) is first. - aHitbox.boundingBoxPitchYawRoll.z = Me.theInputFileReader.ReadSingle() - aHitbox.boundingBoxPitchYawRoll.x = Me.theInputFileReader.ReadSingle() - aHitbox.boundingBoxPitchYawRoll.y = Me.theInputFileReader.ReadSingle() - aHitbox.unknown = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aHitbox.boneIndex = ReadInt32BE() + aHitbox.groupIndex = ReadInt32BE() + aHitbox.boundingBoxMin.x = ReadSingleBE() + aHitbox.boundingBoxMin.y = ReadSingleBE() + aHitbox.boundingBoxMin.z = ReadSingleBE() + aHitbox.boundingBoxMax.x = ReadSingleBE() + aHitbox.boundingBoxMax.y = ReadSingleBE() + aHitbox.boundingBoxMax.z = ReadSingleBE() + aHitbox.nameOffset = ReadInt32BE() + 'NOTE: Roll (z) is first. + aHitbox.boundingBoxPitchYawRoll.z = ReadSingleBE() + aHitbox.boundingBoxPitchYawRoll.x = ReadSingleBE() + aHitbox.boundingBoxPitchYawRoll.y = ReadSingleBE() + aHitbox.unknown = ReadSingleBE() + Else + aHitbox.boneIndex = Me.theInputFileReader.ReadInt32() + aHitbox.groupIndex = Me.theInputFileReader.ReadInt32() + aHitbox.boundingBoxMin.x = Me.theInputFileReader.ReadSingle() + aHitbox.boundingBoxMin.y = Me.theInputFileReader.ReadSingle() + aHitbox.boundingBoxMin.z = Me.theInputFileReader.ReadSingle() + aHitbox.boundingBoxMax.x = Me.theInputFileReader.ReadSingle() + aHitbox.boundingBoxMax.y = Me.theInputFileReader.ReadSingle() + aHitbox.boundingBoxMax.z = Me.theInputFileReader.ReadSingle() + aHitbox.nameOffset = Me.theInputFileReader.ReadInt32() + 'NOTE: Roll (z) is first. + aHitbox.boundingBoxPitchYawRoll.z = Me.theInputFileReader.ReadSingle() + aHitbox.boundingBoxPitchYawRoll.x = Me.theInputFileReader.ReadSingle() + aHitbox.boundingBoxPitchYawRoll.y = Me.theInputFileReader.ReadSingle() + aHitbox.unknown = Me.theInputFileReader.ReadSingle() + End If + For x As Integer = 0 To aHitbox.unused_VERSION49.Length - 1 - aHitbox.unused_VERSION49(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aHitbox.unused_VERSION49(x) = ReadInt32BE() + Else + aHitbox.unused_VERSION49(x) = Me.theInputFileReader.ReadInt32() + End If Next aHitboxSet.theHitboxes.Add(aHitbox) @@ -992,34 +1552,68 @@ Public Class SourceMdlFile49 anAnimationDesc.theOffsetStart = Me.theInputFileReader.BaseStream.Position - anAnimationDesc.baseHeaderOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.nameOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.fps = Me.theInputFileReader.ReadSingle() - anAnimationDesc.flags = Me.theInputFileReader.ReadInt32() - anAnimationDesc.frameCount = Me.theInputFileReader.ReadInt32() - anAnimationDesc.movementCount = Me.theInputFileReader.ReadInt32() - anAnimationDesc.movementOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anAnimationDesc.baseHeaderOffset = ReadInt32BE() + anAnimationDesc.nameOffset = ReadInt32BE() + anAnimationDesc.fps = ReadSingleBE() + anAnimationDesc.flags = ReadInt32BE() + anAnimationDesc.frameCount = ReadInt32BE() + anAnimationDesc.movementCount = ReadInt32BE() + anAnimationDesc.movementOffset = ReadInt32BE() - anAnimationDesc.ikRuleZeroFrameOffset_VERSION49 = Me.theInputFileReader.ReadInt32() + anAnimationDesc.ikRuleZeroFrameOffset_VERSION49 = ReadInt32BE() + Else + anAnimationDesc.baseHeaderOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.nameOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.fps = Me.theInputFileReader.ReadSingle() + anAnimationDesc.flags = Me.theInputFileReader.ReadInt32() + anAnimationDesc.frameCount = Me.theInputFileReader.ReadInt32() + anAnimationDesc.movementCount = Me.theInputFileReader.ReadInt32() + anAnimationDesc.movementOffset = Me.theInputFileReader.ReadInt32() + + anAnimationDesc.ikRuleZeroFrameOffset_VERSION49 = Me.theInputFileReader.ReadInt32() + End If For x As Integer = 0 To anAnimationDesc.unused1.Length - 1 - anAnimationDesc.unused1(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anAnimationDesc.unused1(x) = ReadInt32BE() + Else + anAnimationDesc.unused1(x) = Me.theInputFileReader.ReadInt32() + End If Next - anAnimationDesc.animBlock = Me.theInputFileReader.ReadInt32() - anAnimationDesc.animOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.ikRuleCount = Me.theInputFileReader.ReadInt32() - anAnimationDesc.ikRuleOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.animblockIkRuleOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.localHierarchyCount = Me.theInputFileReader.ReadInt32() - anAnimationDesc.localHierarchyOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.sectionOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.sectionFrameCount = Me.theInputFileReader.ReadInt32() - - anAnimationDesc.spanFrameCount = Me.theInputFileReader.ReadInt16() - anAnimationDesc.spanCount = Me.theInputFileReader.ReadInt16() - anAnimationDesc.spanOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.spanStallTime = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + anAnimationDesc.animBlock = ReadInt32BE() + anAnimationDesc.animOffset = ReadInt32BE() + anAnimationDesc.ikRuleCount = ReadInt32BE() + anAnimationDesc.ikRuleOffset = ReadInt32BE() + anAnimationDesc.animblockIkRuleOffset = ReadInt32BE() + anAnimationDesc.localHierarchyCount = ReadInt32BE() + anAnimationDesc.localHierarchyOffset = ReadInt32BE() + anAnimationDesc.sectionOffset = ReadInt32BE() + anAnimationDesc.sectionFrameCount = ReadInt32BE() + + anAnimationDesc.spanFrameCount = ReadInt16BE() + anAnimationDesc.spanCount = ReadInt16BE() + anAnimationDesc.spanOffset = ReadInt32BE() + anAnimationDesc.spanStallTime = ReadSingleBE() + Else + anAnimationDesc.animBlock = Me.theInputFileReader.ReadInt32() + anAnimationDesc.animOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.ikRuleCount = Me.theInputFileReader.ReadInt32() + anAnimationDesc.ikRuleOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.animblockIkRuleOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.localHierarchyCount = Me.theInputFileReader.ReadInt32() + anAnimationDesc.localHierarchyOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.sectionOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.sectionFrameCount = Me.theInputFileReader.ReadInt32() + + anAnimationDesc.spanFrameCount = Me.theInputFileReader.ReadInt16() + anAnimationDesc.spanCount = Me.theInputFileReader.ReadInt16() + anAnimationDesc.spanOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.spanStallTime = Me.theInputFileReader.ReadSingle() + End If + Me.theMdlFileData.theAnimationDescs.Add(anAnimationDesc) @@ -1266,11 +1860,22 @@ Public Class SourceMdlFile49 fileOffsetStart = Me.theInputFileReader.BaseStream.Position - aSectionOfAnimation.constantsOffset = Me.theInputFileReader.ReadInt32() - aSectionOfAnimation.frameOffset = Me.theInputFileReader.ReadInt32() - aSectionOfAnimation.frameLength = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aSectionOfAnimation.constantsOffset = ReadInt32BE() + aSectionOfAnimation.frameOffset = ReadInt32BE() + aSectionOfAnimation.frameLength = ReadInt32BE() + Else + aSectionOfAnimation.constantsOffset = Me.theInputFileReader.ReadInt32() + aSectionOfAnimation.frameOffset = Me.theInputFileReader.ReadInt32() + aSectionOfAnimation.frameLength = Me.theInputFileReader.ReadInt32() + End If + For x As Integer = 0 To aSectionOfAnimation.unused.Length - 1 - aSectionOfAnimation.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aSectionOfAnimation.unused(x) = ReadInt32BE() + Else + aSectionOfAnimation.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 @@ -1306,24 +1911,46 @@ Public Class SourceMdlFile49 If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_ROT2) > 0 Then aBoneConstantInfo.theConstantRotation2 = New SourceQuaternion48bitsViaBytes() aBoneConstantInfo.theConstantRotation2.theBytes = Me.theInputFileReader.ReadBytes(6) + + If Me.theMdlFileData.isBigEndian Then + Array.Reverse(aBoneConstantInfo.theConstantRotation2.theBytes) + End If End If If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_POS2) > 0 Then aBoneConstantInfo.theConstantPosition2 = New SourceVector() - aBoneConstantInfo.theConstantPosition2.x = Me.theInputFileReader.ReadSingle() - aBoneConstantInfo.theConstantPosition2.y = Me.theInputFileReader.ReadSingle() - aBoneConstantInfo.theConstantPosition2.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBoneConstantInfo.theConstantPosition2.x = ReadSingleBE() + aBoneConstantInfo.theConstantPosition2.y = ReadSingleBE() + aBoneConstantInfo.theConstantPosition2.z = ReadSingleBE() + Else + aBoneConstantInfo.theConstantPosition2.x = Me.theInputFileReader.ReadSingle() + aBoneConstantInfo.theConstantPosition2.y = Me.theInputFileReader.ReadSingle() + aBoneConstantInfo.theConstantPosition2.z = Me.theInputFileReader.ReadSingle() + End If End If If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_RAWROT) > 0 Then aBoneConstantInfo.theConstantRawRot = New SourceQuaternion48bits() - aBoneConstantInfo.theConstantRawRot.theXInput = Me.theInputFileReader.ReadUInt16() - aBoneConstantInfo.theConstantRawRot.theYInput = Me.theInputFileReader.ReadUInt16() - aBoneConstantInfo.theConstantRawRot.theZWInput = Me.theInputFileReader.ReadUInt16() + If Me.theMdlFileData.isBigEndian Then + aBoneConstantInfo.theConstantRawRot.theXInput = ReadUInt16BE() + aBoneConstantInfo.theConstantRawRot.theYInput = ReadUInt16BE() + aBoneConstantInfo.theConstantRawRot.theZWInput = ReadUInt16BE() + Else + aBoneConstantInfo.theConstantRawRot.theXInput = Me.theInputFileReader.ReadUInt16() + aBoneConstantInfo.theConstantRawRot.theYInput = Me.theInputFileReader.ReadUInt16() + aBoneConstantInfo.theConstantRawRot.theZWInput = Me.theInputFileReader.ReadUInt16() + End If End If If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_RAWPOS) > 0 Then aBoneConstantInfo.theConstantRawPos = New SourceVector48bits() - aBoneConstantInfo.theConstantRawPos.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - aBoneConstantInfo.theConstantRawPos.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - aBoneConstantInfo.theConstantRawPos.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + If Me.theMdlFileData.isBigEndian Then + aBoneConstantInfo.theConstantRawPos.theXInput.the16BitValue = ReadUInt16BE() + aBoneConstantInfo.theConstantRawPos.theYInput.the16BitValue = ReadUInt16BE() + aBoneConstantInfo.theConstantRawPos.theZInput.the16BitValue = ReadUInt16BE() + Else + aBoneConstantInfo.theConstantRawPos.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + aBoneConstantInfo.theConstantRawPos.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + aBoneConstantInfo.theConstantRawPos.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + End If End If Next @@ -1365,24 +1992,46 @@ Public Class SourceMdlFile49 If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_ANIM_ROT2) > 0 Then aBoneFrameDataInfo.theAnimRotationUnknown = New SourceQuaternion48bitsViaBytes() aBoneFrameDataInfo.theAnimRotationUnknown.theBytes = Me.theInputFileReader.ReadBytes(6) + + If Me.theMdlFileData.isBigEndian Then + Array.Reverse(aBoneFrameDataInfo.theAnimRotationUnknown.theBytes) + End If End If If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_ANIMROT) > 0 Then aBoneFrameDataInfo.theAnimRotation = New SourceQuaternion48bits() - aBoneFrameDataInfo.theAnimRotation.theXInput = Me.theInputFileReader.ReadUInt16() - aBoneFrameDataInfo.theAnimRotation.theYInput = Me.theInputFileReader.ReadUInt16() - aBoneFrameDataInfo.theAnimRotation.theZWInput = Me.theInputFileReader.ReadUInt16() + If Me.theMdlFileData.isBigEndian Then + aBoneFrameDataInfo.theAnimRotation.theXInput = ReadUInt16BE() + aBoneFrameDataInfo.theAnimRotation.theYInput = ReadUInt16BE() + aBoneFrameDataInfo.theAnimRotation.theZWInput = ReadUInt16BE() + Else + aBoneFrameDataInfo.theAnimRotation.theXInput = Me.theInputFileReader.ReadUInt16() + aBoneFrameDataInfo.theAnimRotation.theYInput = Me.theInputFileReader.ReadUInt16() + aBoneFrameDataInfo.theAnimRotation.theZWInput = Me.theInputFileReader.ReadUInt16() + End If End If If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_ANIMPOS) > 0 Then aBoneFrameDataInfo.theAnimPosition = New SourceVector48bits() - aBoneFrameDataInfo.theAnimPosition.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - aBoneFrameDataInfo.theAnimPosition.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - aBoneFrameDataInfo.theAnimPosition.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + If Me.theMdlFileData.isBigEndian Then + aBoneFrameDataInfo.theAnimPosition.theXInput.the16BitValue = ReadUInt16BE() + aBoneFrameDataInfo.theAnimPosition.theYInput.the16BitValue = ReadUInt16BE() + aBoneFrameDataInfo.theAnimPosition.theZInput.the16BitValue = ReadUInt16BE() + Else + aBoneFrameDataInfo.theAnimPosition.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + aBoneFrameDataInfo.theAnimPosition.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + aBoneFrameDataInfo.theAnimPosition.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + End If End If If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_FULLANIMPOS) > 0 Then aBoneFrameDataInfo.theFullAnimPosition = New SourceVector() - aBoneFrameDataInfo.theFullAnimPosition.x = Me.theInputFileReader.ReadSingle() - aBoneFrameDataInfo.theFullAnimPosition.y = Me.theInputFileReader.ReadSingle() - aBoneFrameDataInfo.theFullAnimPosition.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBoneFrameDataInfo.theFullAnimPosition.x = ReadSingleBE() + aBoneFrameDataInfo.theFullAnimPosition.y = ReadSingleBE() + aBoneFrameDataInfo.theFullAnimPosition.z = ReadSingleBE() + Else + aBoneFrameDataInfo.theFullAnimPosition.x = Me.theInputFileReader.ReadSingle() + aBoneFrameDataInfo.theFullAnimPosition.y = Me.theInputFileReader.ReadSingle() + aBoneFrameDataInfo.theFullAnimPosition.z = Me.theInputFileReader.ReadSingle() + End If End If 'If (boneFlag And SourceAniFrameAnim.STUDIO_FRAME_ANIM_ROT2) > 0 Then ' aBoneFrameDataInfo.theAnimRotationUnknown = New SourceQuaternion48bitsViaBytes() @@ -1457,7 +2106,12 @@ Public Class SourceMdlFile49 anAnimation.boneIndex = boneIndex anAnimation.flags = Me.theInputFileReader.ReadByte() - anAnimation.nextSourceMdlAnimationOffset = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + anAnimation.nextSourceMdlAnimationOffset = ReadInt16BE() + Else + anAnimation.nextSourceMdlAnimationOffset = Me.theInputFileReader.ReadInt16() + End If + 'DEBUG: If (anAnimation.flags And &H40) > 0 Then @@ -1473,19 +2127,35 @@ Public Class SourceMdlFile49 anAnimation.theRot64bits = New SourceQuaternion64bits() anAnimation.theRot64bits.theBytes = Me.theInputFileReader.ReadBytes(8) + If Me.theMdlFileData.isBigEndian Then + Array.Reverse(anAnimation.theRot64bits.theBytes) + End If + 'Me.DebugQuaternion(anAnimation.theRot64) End If If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT) > 0 Then anAnimation.theRot48bits = New SourceQuaternion48bits() - anAnimation.theRot48bits.theXInput = Me.theInputFileReader.ReadUInt16() - anAnimation.theRot48bits.theYInput = Me.theInputFileReader.ReadUInt16() - anAnimation.theRot48bits.theZWInput = Me.theInputFileReader.ReadUInt16() + If Me.theMdlFileData.isBigEndian Then + anAnimation.theRot48bits.theXInput = ReadUInt16BE() + anAnimation.theRot48bits.theYInput = ReadUInt16BE() + anAnimation.theRot48bits.theZWInput = ReadUInt16BE() + Else + anAnimation.theRot48bits.theXInput = Me.theInputFileReader.ReadUInt16() + anAnimation.theRot48bits.theYInput = Me.theInputFileReader.ReadUInt16() + anAnimation.theRot48bits.theZWInput = Me.theInputFileReader.ReadUInt16() + End If End If If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS) > 0 Then anAnimation.thePos = New SourceVector48bits() - anAnimation.thePos.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - anAnimation.thePos.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - anAnimation.thePos.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + If Me.theMdlFileData.isBigEndian Then + anAnimation.thePos.theXInput.the16BitValue = ReadUInt16BE() + anAnimation.thePos.theYInput.the16BitValue = ReadUInt16BE() + anAnimation.thePos.theZInput.the16BitValue = ReadUInt16BE() + Else + anAnimation.thePos.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.thePos.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.thePos.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + End If End If animValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -1495,17 +2165,32 @@ Public Class SourceMdlFile49 rotValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position anAnimation.theRotV = New SourceMdlAnimationValuePointer() - anAnimation.theRotV.animXValueOffset = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + anAnimation.theRotV.animXValueOffset = ReadInt16BE() + Else + anAnimation.theRotV.animXValueOffset = Me.theInputFileReader.ReadInt16() + End If + If anAnimation.theRotV.theAnimXValues Is Nothing Then anAnimation.theRotV.theAnimXValues = New List(Of SourceMdlAnimationValue)() End If - anAnimation.theRotV.animYValueOffset = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + anAnimation.theRotV.animYValueOffset = ReadInt16BE() + Else + anAnimation.theRotV.animYValueOffset = Me.theInputFileReader.ReadInt16() + End If + If anAnimation.theRotV.theAnimYValues Is Nothing Then anAnimation.theRotV.theAnimYValues = New List(Of SourceMdlAnimationValue)() End If - anAnimation.theRotV.animZValueOffset = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + anAnimation.theRotV.animZValueOffset = ReadInt16BE() + Else + anAnimation.theRotV.animZValueOffset = Me.theInputFileReader.ReadInt16() + End If + If anAnimation.theRotV.theAnimZValues Is Nothing Then anAnimation.theRotV.theAnimZValues = New List(Of SourceMdlAnimationValue)() End If @@ -1514,17 +2199,32 @@ Public Class SourceMdlFile49 posValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position anAnimation.thePosV = New SourceMdlAnimationValuePointer() - anAnimation.thePosV.animXValueOffset = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + anAnimation.thePosV.animXValueOffset = ReadInt16BE() + Else + anAnimation.thePosV.animXValueOffset = Me.theInputFileReader.ReadInt16() + End If + If anAnimation.thePosV.theAnimXValues Is Nothing Then anAnimation.thePosV.theAnimXValues = New List(Of SourceMdlAnimationValue)() End If - anAnimation.thePosV.animYValueOffset = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + anAnimation.thePosV.animYValueOffset = ReadInt16BE() + Else + anAnimation.thePosV.animYValueOffset = Me.theInputFileReader.ReadInt16() + End If + If anAnimation.thePosV.theAnimYValues Is Nothing Then anAnimation.thePosV.theAnimYValues = New List(Of SourceMdlAnimationValue)() End If - anAnimation.thePosV.animZValueOffset = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + anAnimation.thePosV.animZValueOffset = ReadInt16BE() + Else + anAnimation.thePosV.animZValueOffset = Me.theInputFileReader.ReadInt16() + End If + If anAnimation.thePosV.theAnimZValues Is Nothing Then anAnimation.thePosV.theAnimZValues = New List(Of SourceMdlAnimationValue)() End If @@ -1769,7 +2469,9 @@ Public Class SourceMdlFile49 frameCountRemainingToBeChecked = frameCount accumulatedTotal = 0 While (frameCountRemainingToBeChecked > 0) + ' This value is also little endian on Xbox 360 models animValue.value = Me.theInputFileReader.ReadInt16() + currentTotal = animValue.total accumulatedTotal += currentTotal If currentTotal = 0 Then @@ -1781,7 +2483,11 @@ Public Class SourceMdlFile49 validCount = animValue.valid For i As Integer = 1 To validCount - animValue.value = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + animValue.value = ReadInt16BE() + Else + animValue.value = Me.theInputFileReader.ReadInt16() + End If theAnimValues.Add(animValue) Next End While @@ -1833,49 +2539,100 @@ Public Class SourceMdlFile49 ikRuleInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anIkRule As New SourceMdlIkRule() - anIkRule.index = Me.theInputFileReader.ReadInt32() - anIkRule.type = Me.theInputFileReader.ReadInt32() - anIkRule.chain = Me.theInputFileReader.ReadInt32() - anIkRule.bone = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anIkRule.index = ReadInt32BE() + anIkRule.type = ReadInt32BE() + anIkRule.chain = ReadInt32BE() + anIkRule.bone = ReadInt32BE() - anIkRule.slot = Me.theInputFileReader.ReadInt32() - anIkRule.height = Me.theInputFileReader.ReadSingle() - anIkRule.radius = Me.theInputFileReader.ReadSingle() - anIkRule.floor = Me.theInputFileReader.ReadSingle() + anIkRule.slot = ReadInt32BE() + anIkRule.height = ReadSingleBE() + anIkRule.radius = ReadSingleBE() + anIkRule.floor = ReadSingleBE() + Else + anIkRule.index = Me.theInputFileReader.ReadInt32() + anIkRule.type = Me.theInputFileReader.ReadInt32() + anIkRule.chain = Me.theInputFileReader.ReadInt32() + anIkRule.bone = Me.theInputFileReader.ReadInt32() + + anIkRule.slot = Me.theInputFileReader.ReadInt32() + anIkRule.height = Me.theInputFileReader.ReadSingle() + anIkRule.radius = Me.theInputFileReader.ReadSingle() + anIkRule.floor = Me.theInputFileReader.ReadSingle() + End If anIkRule.pos = New SourceVector() - anIkRule.pos.x = Me.theInputFileReader.ReadSingle() - anIkRule.pos.y = Me.theInputFileReader.ReadSingle() - anIkRule.pos.z = Me.theInputFileReader.ReadSingle() - anIkRule.q = New SourceQuaternion() - anIkRule.q.x = Me.theInputFileReader.ReadSingle() - anIkRule.q.y = Me.theInputFileReader.ReadSingle() - anIkRule.q.z = Me.theInputFileReader.ReadSingle() - anIkRule.q.w = Me.theInputFileReader.ReadSingle() - - anIkRule.compressedIkErrorOffset = Me.theInputFileReader.ReadInt32() - anIkRule.unused2 = Me.theInputFileReader.ReadInt32() - anIkRule.ikErrorIndexStart = Me.theInputFileReader.ReadInt32() - anIkRule.ikErrorOffset = Me.theInputFileReader.ReadInt32() - - anIkRule.influenceStart = Me.theInputFileReader.ReadSingle() - anIkRule.influencePeak = Me.theInputFileReader.ReadSingle() - anIkRule.influenceTail = Me.theInputFileReader.ReadSingle() - anIkRule.influenceEnd = Me.theInputFileReader.ReadSingle() - - anIkRule.unused3 = Me.theInputFileReader.ReadSingle() - anIkRule.contact = Me.theInputFileReader.ReadSingle() - anIkRule.drop = Me.theInputFileReader.ReadSingle() - anIkRule.top = Me.theInputFileReader.ReadSingle() - - anIkRule.unused6 = Me.theInputFileReader.ReadInt32() - anIkRule.unused7 = Me.theInputFileReader.ReadInt32() - anIkRule.unused8 = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anIkRule.pos.x = ReadSingleBE() + anIkRule.pos.y = ReadSingleBE() + anIkRule.pos.z = ReadSingleBE() + Else + anIkRule.pos.x = Me.theInputFileReader.ReadSingle() + anIkRule.pos.y = Me.theInputFileReader.ReadSingle() + anIkRule.pos.z = Me.theInputFileReader.ReadSingle() + End If - anIkRule.attachmentNameOffset = Me.theInputFileReader.ReadInt32() + anIkRule.q = New SourceQuaternion() + If Me.theMdlFileData.isBigEndian Then + anIkRule.q.x = ReadSingleBE() + anIkRule.q.y = ReadSingleBE() + anIkRule.q.z = ReadSingleBE() + anIkRule.q.w = ReadSingleBE() + + anIkRule.compressedIkErrorOffset = ReadInt32BE() + anIkRule.unused2 = ReadInt32BE() + anIkRule.ikErrorIndexStart = ReadInt32BE() + anIkRule.ikErrorOffset = ReadInt32BE() + + anIkRule.influenceStart = ReadSingleBE() + anIkRule.influencePeak = ReadSingleBE() + anIkRule.influenceTail = ReadSingleBE() + anIkRule.influenceEnd = ReadSingleBE() + + anIkRule.unused3 = ReadSingleBE() + anIkRule.contact = ReadSingleBE() + anIkRule.drop = ReadSingleBE() + anIkRule.top = ReadSingleBE() + + anIkRule.unused6 = ReadInt32BE() + anIkRule.unused7 = ReadInt32BE() + anIkRule.unused8 = ReadInt32BE() + + anIkRule.attachmentNameOffset = ReadInt32BE() + Else + anIkRule.q.x = Me.theInputFileReader.ReadSingle() + anIkRule.q.y = Me.theInputFileReader.ReadSingle() + anIkRule.q.z = Me.theInputFileReader.ReadSingle() + anIkRule.q.w = Me.theInputFileReader.ReadSingle() + + anIkRule.compressedIkErrorOffset = Me.theInputFileReader.ReadInt32() + anIkRule.unused2 = Me.theInputFileReader.ReadInt32() + anIkRule.ikErrorIndexStart = Me.theInputFileReader.ReadInt32() + anIkRule.ikErrorOffset = Me.theInputFileReader.ReadInt32() + + anIkRule.influenceStart = Me.theInputFileReader.ReadSingle() + anIkRule.influencePeak = Me.theInputFileReader.ReadSingle() + anIkRule.influenceTail = Me.theInputFileReader.ReadSingle() + anIkRule.influenceEnd = Me.theInputFileReader.ReadSingle() + + anIkRule.unused3 = Me.theInputFileReader.ReadSingle() + anIkRule.contact = Me.theInputFileReader.ReadSingle() + anIkRule.drop = Me.theInputFileReader.ReadSingle() + anIkRule.top = Me.theInputFileReader.ReadSingle() + + anIkRule.unused6 = Me.theInputFileReader.ReadInt32() + anIkRule.unused7 = Me.theInputFileReader.ReadInt32() + anIkRule.unused8 = Me.theInputFileReader.ReadInt32() + + anIkRule.attachmentNameOffset = Me.theInputFileReader.ReadInt32() + End If For x As Integer = 0 To anIkRule.unused.Length - 1 - anIkRule.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anIkRule.unused(x) = ReadInt32BE() + Else + anIkRule.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next anAnimationDesc.theIkRules.Add(anIkRule) @@ -1948,7 +2705,11 @@ Public Class SourceMdlFile49 ' First, read the scale data. For k As Integer = 0 To anIkRule.theCompressedIkError.scale.Length - 1 kInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - anIkRule.theCompressedIkError.scale(k) = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + anIkRule.theCompressedIkError.scale(k) = ReadSingleBE() + Else + anIkRule.theCompressedIkError.scale(k) = Me.theInputFileReader.ReadSingle() + End If fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(kInputFileStreamPosition, fileOffsetEnd, "anIkRule.theCompressedIkError [ikRuleIndex = " + ikRuleIndex.ToString() + "] [scale = " + anIkRule.theCompressedIkError.scale(k).ToString() + "]") @@ -1957,7 +2718,11 @@ Public Class SourceMdlFile49 ' Second, read the offset data. For k As Integer = 0 To anIkRule.theCompressedIkError.offset.Length - 1 kInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - anIkRule.theCompressedIkError.offset(k) = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + anIkRule.theCompressedIkError.offset(k) = ReadInt16BE() + Else + anIkRule.theCompressedIkError.offset(k) = Me.theInputFileReader.ReadInt16() + End If fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(kInputFileStreamPosition, fileOffsetEnd, "anIkRule.theCompressedIkError [ikRuleIndex = " + ikRuleIndex.ToString() + "] [offset = " + anIkRule.theCompressedIkError.offset(k).ToString() + "]") @@ -2006,8 +2771,14 @@ Public Class SourceMdlFile49 'animSectionInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anAnimSection As New SourceMdlAnimationSection() - anAnimSection.animBlock = Me.theInputFileReader.ReadInt32() - anAnimSection.animOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anAnimSection.animBlock = ReadInt32BE() + anAnimSection.animOffset = ReadInt32BE() + Else + anAnimSection.animBlock = Me.theInputFileReader.ReadInt32() + anAnimSection.animOffset = Me.theInputFileReader.ReadInt32() + End If + anAnimationDesc.theSections.Add(anAnimSection) 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -2048,20 +2819,41 @@ Public Class SourceMdlFile49 movementInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aMovement As New SourceMdlMovement() - aMovement.endframeIndex = Me.theInputFileReader.ReadInt32() - aMovement.motionFlags = Me.theInputFileReader.ReadInt32() - aMovement.v0 = Me.theInputFileReader.ReadSingle() - aMovement.v1 = Me.theInputFileReader.ReadSingle() - aMovement.angle = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aMovement.endframeIndex = ReadInt32BE() + aMovement.motionFlags = ReadInt32BE() + aMovement.v0 = ReadSingleBE() + aMovement.v1 = ReadSingleBE() + aMovement.angle = ReadSingleBE() + Else + aMovement.endframeIndex = Me.theInputFileReader.ReadInt32() + aMovement.motionFlags = Me.theInputFileReader.ReadInt32() + aMovement.v0 = Me.theInputFileReader.ReadSingle() + aMovement.v1 = Me.theInputFileReader.ReadSingle() + aMovement.angle = Me.theInputFileReader.ReadSingle() + End If aMovement.vector = New SourceVector() - aMovement.vector.x = Me.theInputFileReader.ReadSingle() - aMovement.vector.y = Me.theInputFileReader.ReadSingle() - aMovement.vector.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aMovement.vector.x = ReadSingleBE() + aMovement.vector.y = ReadSingleBE() + aMovement.vector.z = ReadSingleBE() + Else + aMovement.vector.x = Me.theInputFileReader.ReadSingle() + aMovement.vector.y = Me.theInputFileReader.ReadSingle() + aMovement.vector.z = Me.theInputFileReader.ReadSingle() + End If + aMovement.position = New SourceVector() - aMovement.position.x = Me.theInputFileReader.ReadSingle() - aMovement.position.y = Me.theInputFileReader.ReadSingle() - aMovement.position.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aMovement.position.x = ReadSingleBE() + aMovement.position.y = ReadSingleBE() + aMovement.position.z = ReadSingleBE() + Else + aMovement.position.x = Me.theInputFileReader.ReadSingle() + aMovement.position.y = Me.theInputFileReader.ReadSingle() + aMovement.position.z = Me.theInputFileReader.ReadSingle() + End If anAnimationDesc.theMovements.Add(aMovement) Next @@ -2085,16 +2877,32 @@ Public Class SourceMdlFile49 localHieararchyInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aLocalHierarchy As New SourceMdlLocalHierarchy() - aLocalHierarchy.boneIndex = Me.theInputFileReader.ReadInt32() - aLocalHierarchy.boneNewParentIndex = Me.theInputFileReader.ReadInt32() - aLocalHierarchy.startInfluence = Me.theInputFileReader.ReadSingle() - aLocalHierarchy.peakInfluence = Me.theInputFileReader.ReadSingle() - aLocalHierarchy.tailInfluence = Me.theInputFileReader.ReadSingle() - aLocalHierarchy.endInfluence = Me.theInputFileReader.ReadSingle() - aLocalHierarchy.startFrameIndex = Me.theInputFileReader.ReadInt32() - aLocalHierarchy.localAnimOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aLocalHierarchy.boneIndex = ReadInt32BE() + aLocalHierarchy.boneNewParentIndex = ReadInt32BE() + aLocalHierarchy.startInfluence = ReadSingleBE() + aLocalHierarchy.peakInfluence = ReadSingleBE() + aLocalHierarchy.tailInfluence = ReadSingleBE() + aLocalHierarchy.endInfluence = ReadSingleBE() + aLocalHierarchy.startFrameIndex = ReadInt32BE() + aLocalHierarchy.localAnimOffset = ReadInt32BE() + Else + aLocalHierarchy.boneIndex = Me.theInputFileReader.ReadInt32() + aLocalHierarchy.boneNewParentIndex = Me.theInputFileReader.ReadInt32() + aLocalHierarchy.startInfluence = Me.theInputFileReader.ReadSingle() + aLocalHierarchy.peakInfluence = Me.theInputFileReader.ReadSingle() + aLocalHierarchy.tailInfluence = Me.theInputFileReader.ReadSingle() + aLocalHierarchy.endInfluence = Me.theInputFileReader.ReadSingle() + aLocalHierarchy.startFrameIndex = Me.theInputFileReader.ReadInt32() + aLocalHierarchy.localAnimOffset = Me.theInputFileReader.ReadInt32() + End If + For x As Integer = 0 To aLocalHierarchy.unused.Length - 1 - aLocalHierarchy.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aLocalHierarchy.unused(x) = ReadInt32BE() + Else + aLocalHierarchy.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next anAnimationDesc.theLocalHierarchies.Add(aLocalHierarchy) @@ -2127,76 +2935,151 @@ Public Class SourceMdlFile49 seqInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aSeqDesc As New SourceMdlSequenceDesc() - aSeqDesc.baseHeaderOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.nameOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.activityNameOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.flags = Me.theInputFileReader.ReadInt32() - aSeqDesc.activity = Me.theInputFileReader.ReadInt32() - aSeqDesc.activityWeight = Me.theInputFileReader.ReadInt32() - aSeqDesc.eventCount = Me.theInputFileReader.ReadInt32() - aSeqDesc.eventOffset = Me.theInputFileReader.ReadInt32() - - aSeqDesc.bbMin.x = Me.theInputFileReader.ReadSingle() - aSeqDesc.bbMin.y = Me.theInputFileReader.ReadSingle() - aSeqDesc.bbMin.z = Me.theInputFileReader.ReadSingle() - aSeqDesc.bbMax.x = Me.theInputFileReader.ReadSingle() - aSeqDesc.bbMax.y = Me.theInputFileReader.ReadSingle() - aSeqDesc.bbMax.z = Me.theInputFileReader.ReadSingle() - - aSeqDesc.blendCount = Me.theInputFileReader.ReadInt32() - aSeqDesc.animIndexOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.movementIndex = Me.theInputFileReader.ReadInt32() - aSeqDesc.groupSize(0) = Me.theInputFileReader.ReadInt32() - aSeqDesc.groupSize(1) = Me.theInputFileReader.ReadInt32() - - aSeqDesc.paramIndex(0) = Me.theInputFileReader.ReadInt32() - aSeqDesc.paramIndex(1) = Me.theInputFileReader.ReadInt32() - aSeqDesc.paramStart(0) = Me.theInputFileReader.ReadSingle() - aSeqDesc.paramStart(1) = Me.theInputFileReader.ReadSingle() - aSeqDesc.paramEnd(0) = Me.theInputFileReader.ReadSingle() - aSeqDesc.paramEnd(1) = Me.theInputFileReader.ReadSingle() - aSeqDesc.paramParent = Me.theInputFileReader.ReadInt32() - - aSeqDesc.fadeInTime = Me.theInputFileReader.ReadSingle() - aSeqDesc.fadeOutTime = Me.theInputFileReader.ReadSingle() - - aSeqDesc.localEntryNodeIndex = Me.theInputFileReader.ReadInt32() - aSeqDesc.localExitNodeIndex = Me.theInputFileReader.ReadInt32() - aSeqDesc.nodeFlags = Me.theInputFileReader.ReadInt32() - - aSeqDesc.entryPhase = Me.theInputFileReader.ReadSingle() - aSeqDesc.exitPhase = Me.theInputFileReader.ReadSingle() - aSeqDesc.lastFrame = Me.theInputFileReader.ReadSingle() - - aSeqDesc.nextSeq = Me.theInputFileReader.ReadInt32() - aSeqDesc.pose = Me.theInputFileReader.ReadInt32() - - aSeqDesc.ikRuleCount = Me.theInputFileReader.ReadInt32() - aSeqDesc.autoLayerCount = Me.theInputFileReader.ReadInt32() - aSeqDesc.autoLayerOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.weightOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.poseKeyOffset = Me.theInputFileReader.ReadInt32() - - aSeqDesc.ikLockCount = Me.theInputFileReader.ReadInt32() - aSeqDesc.ikLockOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.keyValueOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.keyValueSize = Me.theInputFileReader.ReadInt32() - aSeqDesc.cyclePoseIndex = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aSeqDesc.baseHeaderOffset = ReadInt32BE() + aSeqDesc.nameOffset = ReadInt32BE() + aSeqDesc.activityNameOffset = ReadInt32BE() + aSeqDesc.flags = ReadInt32BE() + aSeqDesc.activity = ReadInt32BE() + aSeqDesc.activityWeight = ReadInt32BE() + aSeqDesc.eventCount = ReadInt32BE() + aSeqDesc.eventOffset = ReadInt32BE() + + aSeqDesc.bbMin.x = ReadSingleBE() + aSeqDesc.bbMin.y = ReadSingleBE() + aSeqDesc.bbMin.z = ReadSingleBE() + aSeqDesc.bbMax.x = ReadSingleBE() + aSeqDesc.bbMax.y = ReadSingleBE() + aSeqDesc.bbMax.z = ReadSingleBE() + + aSeqDesc.blendCount = ReadInt32BE() + aSeqDesc.animIndexOffset = ReadInt32BE() + aSeqDesc.movementIndex = ReadInt32BE() + aSeqDesc.groupSize(0) = ReadInt32BE() + aSeqDesc.groupSize(1) = ReadInt32BE() + + aSeqDesc.paramIndex(0) = ReadInt32BE() + aSeqDesc.paramIndex(1) = ReadInt32BE() + aSeqDesc.paramStart(0) = ReadSingleBE() + aSeqDesc.paramStart(1) = ReadSingleBE() + aSeqDesc.paramEnd(0) = ReadSingleBE() + aSeqDesc.paramEnd(1) = ReadSingleBE() + aSeqDesc.paramParent = ReadInt32BE() + + aSeqDesc.fadeInTime = ReadSingleBE() + aSeqDesc.fadeOutTime = ReadSingleBE() + + aSeqDesc.localEntryNodeIndex = ReadInt32BE() + aSeqDesc.localExitNodeIndex = ReadInt32BE() + aSeqDesc.nodeFlags = ReadInt32BE() + + aSeqDesc.entryPhase = ReadSingleBE() + aSeqDesc.exitPhase = ReadSingleBE() + aSeqDesc.lastFrame = ReadSingleBE() + + aSeqDesc.nextSeq = ReadInt32BE() + aSeqDesc.pose = ReadInt32BE() + + aSeqDesc.ikRuleCount = ReadInt32BE() + aSeqDesc.autoLayerCount = ReadInt32BE() + aSeqDesc.autoLayerOffset = ReadInt32BE() + aSeqDesc.weightOffset = ReadInt32BE() + aSeqDesc.poseKeyOffset = ReadInt32BE() + + aSeqDesc.ikLockCount = ReadInt32BE() + aSeqDesc.ikLockOffset = ReadInt32BE() + aSeqDesc.keyValueOffset = ReadInt32BE() + aSeqDesc.keyValueSize = ReadInt32BE() + aSeqDesc.cyclePoseIndex = ReadInt32BE() + Else + aSeqDesc.baseHeaderOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.nameOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.activityNameOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.flags = Me.theInputFileReader.ReadInt32() + aSeqDesc.activity = Me.theInputFileReader.ReadInt32() + aSeqDesc.activityWeight = Me.theInputFileReader.ReadInt32() + aSeqDesc.eventCount = Me.theInputFileReader.ReadInt32() + aSeqDesc.eventOffset = Me.theInputFileReader.ReadInt32() + + aSeqDesc.bbMin.x = Me.theInputFileReader.ReadSingle() + aSeqDesc.bbMin.y = Me.theInputFileReader.ReadSingle() + aSeqDesc.bbMin.z = Me.theInputFileReader.ReadSingle() + aSeqDesc.bbMax.x = Me.theInputFileReader.ReadSingle() + aSeqDesc.bbMax.y = Me.theInputFileReader.ReadSingle() + aSeqDesc.bbMax.z = Me.theInputFileReader.ReadSingle() + + aSeqDesc.blendCount = Me.theInputFileReader.ReadInt32() + aSeqDesc.animIndexOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.movementIndex = Me.theInputFileReader.ReadInt32() + aSeqDesc.groupSize(0) = Me.theInputFileReader.ReadInt32() + aSeqDesc.groupSize(1) = Me.theInputFileReader.ReadInt32() + + aSeqDesc.paramIndex(0) = Me.theInputFileReader.ReadInt32() + aSeqDesc.paramIndex(1) = Me.theInputFileReader.ReadInt32() + aSeqDesc.paramStart(0) = Me.theInputFileReader.ReadSingle() + aSeqDesc.paramStart(1) = Me.theInputFileReader.ReadSingle() + aSeqDesc.paramEnd(0) = Me.theInputFileReader.ReadSingle() + aSeqDesc.paramEnd(1) = Me.theInputFileReader.ReadSingle() + aSeqDesc.paramParent = Me.theInputFileReader.ReadInt32() + + aSeqDesc.fadeInTime = Me.theInputFileReader.ReadSingle() + aSeqDesc.fadeOutTime = Me.theInputFileReader.ReadSingle() + + aSeqDesc.localEntryNodeIndex = Me.theInputFileReader.ReadInt32() + aSeqDesc.localExitNodeIndex = Me.theInputFileReader.ReadInt32() + aSeqDesc.nodeFlags = Me.theInputFileReader.ReadInt32() + + aSeqDesc.entryPhase = Me.theInputFileReader.ReadSingle() + aSeqDesc.exitPhase = Me.theInputFileReader.ReadSingle() + aSeqDesc.lastFrame = Me.theInputFileReader.ReadSingle() + + aSeqDesc.nextSeq = Me.theInputFileReader.ReadInt32() + aSeqDesc.pose = Me.theInputFileReader.ReadInt32() + + aSeqDesc.ikRuleCount = Me.theInputFileReader.ReadInt32() + aSeqDesc.autoLayerCount = Me.theInputFileReader.ReadInt32() + aSeqDesc.autoLayerOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.weightOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.poseKeyOffset = Me.theInputFileReader.ReadInt32() + + aSeqDesc.ikLockCount = Me.theInputFileReader.ReadInt32() + aSeqDesc.ikLockOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.keyValueOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.keyValueSize = Me.theInputFileReader.ReadInt32() + aSeqDesc.cyclePoseIndex = Me.theInputFileReader.ReadInt32() + End If aSeqDesc.activityModifierOffset = 0 aSeqDesc.activityModifierCount = 0 If Me.theMdlFileData.version = 48 OrElse Me.theMdlFileData.version = 49 Then - aSeqDesc.activityModifierOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.activityModifierCount = Me.theInputFileReader.ReadInt32() - aSeqDesc.animTagOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.animTagCount = Me.theInputFileReader.ReadInt32() - aSeqDesc.rootDriverBoneIndex = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aSeqDesc.activityModifierOffset = ReadInt32BE() + aSeqDesc.activityModifierCount = ReadInt32BE() + aSeqDesc.animTagOffset = ReadInt32BE() + aSeqDesc.animTagCount = ReadInt32BE() + aSeqDesc.rootDriverBoneIndex = ReadInt32BE() + Else + aSeqDesc.activityModifierOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.activityModifierCount = Me.theInputFileReader.ReadInt32() + aSeqDesc.animTagOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.animTagCount = Me.theInputFileReader.ReadInt32() + aSeqDesc.rootDriverBoneIndex = Me.theInputFileReader.ReadInt32() + End If + For x As Integer = 0 To 1 - aSeqDesc.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aSeqDesc.unused(x) = ReadInt32BE() + Else + aSeqDesc.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next Else For x As Integer = 0 To 6 - aSeqDesc.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aSeqDesc.unused(x) = ReadInt32BE() + Else + aSeqDesc.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next End If @@ -2282,7 +3165,11 @@ Public Class SourceMdlFile49 For j As Integer = 0 To poseKeyCount - 1 poseKeyInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aPoseKey As Double - aPoseKey = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aPoseKey = ReadSingleBE() + Else + aPoseKey = Me.theInputFileReader.ReadSingle() + End If aSeqDesc.thePoseKeys.Add(aPoseKey) 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -2311,13 +3198,25 @@ Public Class SourceMdlFile49 For j As Integer = 0 To eventCount - 1 eventInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anEvent As New SourceMdlEvent() - anEvent.cycle = Me.theInputFileReader.ReadSingle() - anEvent.eventIndex = Me.theInputFileReader.ReadInt32() - anEvent.eventType = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anEvent.cycle = ReadSingleBE() + anEvent.eventIndex = ReadInt32BE() + anEvent.eventType = ReadInt32BE() + Else + anEvent.cycle = Me.theInputFileReader.ReadSingle() + anEvent.eventIndex = Me.theInputFileReader.ReadInt32() + anEvent.eventType = Me.theInputFileReader.ReadInt32() + End If + For x As Integer = 0 To anEvent.options.Length - 1 anEvent.options(x) = Me.theInputFileReader.ReadChar() Next - anEvent.nameOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anEvent.nameOffset = ReadInt32BE() + Else + anEvent.nameOffset = Me.theInputFileReader.ReadInt32() + End If + aSeqDesc.theEvents.Add(anEvent) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -2370,13 +3269,24 @@ Public Class SourceMdlFile49 For j As Integer = 0 To autoLayerCount - 1 autoLayerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anAutoLayer As New SourceMdlAutoLayer() - anAutoLayer.sequenceIndex = Me.theInputFileReader.ReadInt16() - anAutoLayer.poseIndex = Me.theInputFileReader.ReadInt16() - anAutoLayer.flags = Me.theInputFileReader.ReadInt32() - anAutoLayer.influenceStart = Me.theInputFileReader.ReadSingle() - anAutoLayer.influencePeak = Me.theInputFileReader.ReadSingle() - anAutoLayer.influenceTail = Me.theInputFileReader.ReadSingle() - anAutoLayer.influenceEnd = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + anAutoLayer.sequenceIndex = ReadInt16BE() + anAutoLayer.poseIndex = ReadInt16BE() + anAutoLayer.flags = ReadInt32BE() + anAutoLayer.influenceStart = ReadSingleBE() + anAutoLayer.influencePeak = ReadSingleBE() + anAutoLayer.influenceTail = ReadSingleBE() + anAutoLayer.influenceEnd = ReadSingleBE() + Else + anAutoLayer.sequenceIndex = Me.theInputFileReader.ReadInt16() + anAutoLayer.poseIndex = Me.theInputFileReader.ReadInt16() + anAutoLayer.flags = Me.theInputFileReader.ReadInt32() + anAutoLayer.influenceStart = Me.theInputFileReader.ReadSingle() + anAutoLayer.influencePeak = Me.theInputFileReader.ReadSingle() + anAutoLayer.influenceTail = Me.theInputFileReader.ReadSingle() + anAutoLayer.influenceEnd = Me.theInputFileReader.ReadSingle() + End If + aSeqDesc.theAutoLayers.Add(anAutoLayer) 'NOTE: Change NaN to 0. This is needed for HL2DM\HL2\hl2_misc_dir.vpk\models\combine_soldier_anims.mdl for its "Man_Gun" $sequence. @@ -2418,7 +3328,12 @@ Public Class SourceMdlFile49 For j As Integer = 0 To Me.theMdlFileData.boneCount - 1 weightListInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anAnimBoneWeight As Double - anAnimBoneWeight = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + anAnimBoneWeight = ReadSingleBE() + Else + anAnimBoneWeight = Me.theInputFileReader.ReadSingle() + End If + aSeqDesc.theBoneWeights.Add(anAnimBoneWeight) If anAnimBoneWeight <> 1 Then @@ -2452,12 +3367,24 @@ Public Class SourceMdlFile49 For j As Integer = 0 To lockCount - 1 lockInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anIkLock As New SourceMdlIkLock() - anIkLock.chainIndex = Me.theInputFileReader.ReadInt32() - anIkLock.posWeight = Me.theInputFileReader.ReadSingle() - anIkLock.localQWeight = Me.theInputFileReader.ReadSingle() - anIkLock.flags = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anIkLock.chainIndex = ReadInt32BE() + anIkLock.posWeight = ReadSingleBE() + anIkLock.localQWeight = ReadSingleBE() + anIkLock.flags = ReadInt32BE() + Else + anIkLock.chainIndex = Me.theInputFileReader.ReadInt32() + anIkLock.posWeight = Me.theInputFileReader.ReadSingle() + anIkLock.localQWeight = Me.theInputFileReader.ReadSingle() + anIkLock.flags = Me.theInputFileReader.ReadInt32() + End If + For x As Integer = 0 To anIkLock.unused.Length - 1 - anIkLock.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anIkLock.unused(x) = ReadInt32BE() + Else + anIkLock.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next aSeqDesc.theIkLocks.Add(anIkLock) @@ -2485,7 +3412,12 @@ Public Class SourceMdlFile49 For j As Integer = 0 To animIndexCount - 1 animIndexInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anAnimIndex As Short - anAnimIndex = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + anAnimIndex = ReadInt16BE() + Else + anAnimIndex = Me.theInputFileReader.ReadInt16() + End If + aSeqDesc.theAnimDescIndexes.Add(anAnimIndex) If Me.theMdlFileData.theAnimationDescs IsNot Nothing AndAlso Me.theMdlFileData.theAnimationDescs.Count > anAnimIndex Then @@ -2536,7 +3468,12 @@ Public Class SourceMdlFile49 For j As Integer = 0 To activityModifierCount - 1 activityModifierInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anActivityModifier As New SourceMdlActivityModifier() - anActivityModifier.nameOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anActivityModifier.nameOffset = ReadInt32BE() + Else + anActivityModifier.nameOffset = Me.theInputFileReader.ReadInt32() + End If + aSeqDesc.theActivityModifiers.Add(anActivityModifier) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -2580,9 +3517,16 @@ Public Class SourceMdlFile49 animTagInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anAnimTag As New SourceMdlAnimTag() - anAnimTag.tagIndex = Me.theInputFileReader.ReadInt32() - anAnimTag.cycle = Me.theInputFileReader.ReadSingle() - anAnimTag.nameOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anAnimTag.tagIndex = ReadInt32BE() + anAnimTag.cycle = ReadSingleBE() + anAnimTag.nameOffset = ReadInt32BE() + Else + anAnimTag.tagIndex = Me.theInputFileReader.ReadInt32() + anAnimTag.cycle = Me.theInputFileReader.ReadSingle() + anAnimTag.nameOffset = Me.theInputFileReader.ReadInt32() + End If + aSeqDesc.theAnimTags.Add(anAnimTag) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -2637,7 +3581,11 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.localNodeCount - 1 localNodeNameInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aLocalNodeName As String - localNodeNameOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + localNodeNameOffset = ReadInt32BE() + Else + localNodeNameOffset = Me.theInputFileReader.ReadInt32() + End If inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -2739,10 +3687,18 @@ Public Class SourceMdlFile49 For bodyPartIndex As Integer = 0 To Me.theMdlFileData.bodyPartCount - 1 bodyPartInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aBodyPart As New SourceMdlBodyPart() - aBodyPart.nameOffset = Me.theInputFileReader.ReadInt32() - aBodyPart.modelCount = Me.theInputFileReader.ReadInt32() - aBodyPart.base = Me.theInputFileReader.ReadInt32() - aBodyPart.modelOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBodyPart.nameOffset = ReadInt32BE() + aBodyPart.modelCount = ReadInt32BE() + aBodyPart.base = ReadInt32BE() + aBodyPart.modelOffset = ReadInt32BE() + Else + aBodyPart.nameOffset = Me.theInputFileReader.ReadInt32() + aBodyPart.modelCount = Me.theInputFileReader.ReadInt32() + aBodyPart.base = Me.theInputFileReader.ReadInt32() + aBodyPart.modelOffset = Me.theInputFileReader.ReadInt32() + End If + Me.theMdlFileData.theBodyParts.Add(aBodyPart) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -2796,23 +3752,49 @@ Public Class SourceMdlFile49 Dim aModel As New SourceMdlModel() aModel.name = Me.theInputFileReader.ReadChars(64) - aModel.type = Me.theInputFileReader.ReadInt32() - aModel.boundingRadius = Me.theInputFileReader.ReadSingle() - aModel.meshCount = Me.theInputFileReader.ReadInt32() - aModel.meshOffset = Me.theInputFileReader.ReadInt32() - aModel.vertexCount = Me.theInputFileReader.ReadInt32() - aModel.vertexOffset = Me.theInputFileReader.ReadInt32() - aModel.tangentOffset = Me.theInputFileReader.ReadInt32() - aModel.attachmentCount = Me.theInputFileReader.ReadInt32() - aModel.attachmentOffset = Me.theInputFileReader.ReadInt32() - aModel.eyeballCount = Me.theInputFileReader.ReadInt32() - aModel.eyeballOffset = Me.theInputFileReader.ReadInt32() + + If Me.theMdlFileData.isBigEndian Then + aModel.type = ReadInt32BE() + aModel.boundingRadius = ReadSingleBE() + aModel.meshCount = ReadInt32BE() + aModel.meshOffset = ReadInt32BE() + aModel.vertexCount = ReadInt32BE() + aModel.vertexOffset = ReadInt32BE() + aModel.tangentOffset = ReadInt32BE() + aModel.attachmentCount = ReadInt32BE() + aModel.attachmentOffset = ReadInt32BE() + aModel.eyeballCount = ReadInt32BE() + aModel.eyeballOffset = ReadInt32BE() + Else + aModel.type = Me.theInputFileReader.ReadInt32() + aModel.boundingRadius = Me.theInputFileReader.ReadSingle() + aModel.meshCount = Me.theInputFileReader.ReadInt32() + aModel.meshOffset = Me.theInputFileReader.ReadInt32() + aModel.vertexCount = Me.theInputFileReader.ReadInt32() + aModel.vertexOffset = Me.theInputFileReader.ReadInt32() + aModel.tangentOffset = Me.theInputFileReader.ReadInt32() + aModel.attachmentCount = Me.theInputFileReader.ReadInt32() + aModel.attachmentOffset = Me.theInputFileReader.ReadInt32() + aModel.eyeballCount = Me.theInputFileReader.ReadInt32() + aModel.eyeballOffset = Me.theInputFileReader.ReadInt32() + End If + Dim modelVertexData As New SourceMdlModelVertexData() - modelVertexData.vertexDataP = Me.theInputFileReader.ReadInt32() - modelVertexData.tangentDataP = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + modelVertexData.vertexDataP = ReadInt32BE() + modelVertexData.tangentDataP = ReadInt32BE() + Else + modelVertexData.vertexDataP = Me.theInputFileReader.ReadInt32() + modelVertexData.tangentDataP = Me.theInputFileReader.ReadInt32() + End If + aModel.vertexData = modelVertexData For x As Integer = 0 To 7 - aModel.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aModel.unused(x) = ReadInt32BE() + Else + aModel.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next aBodyPart.theModels.Add(aModel) @@ -2852,26 +3834,55 @@ Public Class SourceMdlFile49 meshInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aMesh As New SourceMdlMesh() - aMesh.materialIndex = Me.theInputFileReader.ReadInt32() - aMesh.modelOffset = Me.theInputFileReader.ReadInt32() - aMesh.vertexCount = Me.theInputFileReader.ReadInt32() - aMesh.vertexIndexStart = Me.theInputFileReader.ReadInt32() - aMesh.flexCount = Me.theInputFileReader.ReadInt32() - aMesh.flexOffset = Me.theInputFileReader.ReadInt32() - aMesh.materialType = Me.theInputFileReader.ReadInt32() - aMesh.materialParam = Me.theInputFileReader.ReadInt32() - aMesh.id = Me.theInputFileReader.ReadInt32() - aMesh.centerX = Me.theInputFileReader.ReadSingle() - aMesh.centerY = Me.theInputFileReader.ReadSingle() - aMesh.centerZ = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aMesh.materialIndex = ReadInt32BE() + aMesh.modelOffset = ReadInt32BE() + aMesh.vertexCount = ReadInt32BE() + aMesh.vertexIndexStart = ReadInt32BE() + aMesh.flexCount = ReadInt32BE() + aMesh.flexOffset = ReadInt32BE() + aMesh.materialType = ReadInt32BE() + aMesh.materialParam = ReadInt32BE() + aMesh.id = ReadInt32BE() + aMesh.centerX = ReadSingleBE() + aMesh.centerY = ReadSingleBE() + aMesh.centerZ = ReadSingleBE() + Else + aMesh.materialIndex = Me.theInputFileReader.ReadInt32() + aMesh.modelOffset = Me.theInputFileReader.ReadInt32() + aMesh.vertexCount = Me.theInputFileReader.ReadInt32() + aMesh.vertexIndexStart = Me.theInputFileReader.ReadInt32() + aMesh.flexCount = Me.theInputFileReader.ReadInt32() + aMesh.flexOffset = Me.theInputFileReader.ReadInt32() + aMesh.materialType = Me.theInputFileReader.ReadInt32() + aMesh.materialParam = Me.theInputFileReader.ReadInt32() + aMesh.id = Me.theInputFileReader.ReadInt32() + aMesh.centerX = Me.theInputFileReader.ReadSingle() + aMesh.centerY = Me.theInputFileReader.ReadSingle() + aMesh.centerZ = Me.theInputFileReader.ReadSingle() + End If + Dim meshVertexData As New SourceMdlMeshVertexData() - meshVertexData.modelVertexDataP = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + meshVertexData.modelVertexDataP = ReadInt32BE() + Else + meshVertexData.modelVertexDataP = Me.theInputFileReader.ReadInt32() + End If + For x As Integer = 0 To MAX_NUM_LODS - 1 - meshVertexData.lodVertexCount(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + meshVertexData.lodVertexCount(x) = ReadInt32BE() + Else + meshVertexData.lodVertexCount(x) = Me.theInputFileReader.ReadInt32() + End If Next aMesh.vertexData = meshVertexData For x As Integer = 0 To 7 - aMesh.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aMesh.unused(x) = ReadInt32BE() + Else + aMesh.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next aModel.theMeshes.Add(aMesh) @@ -2914,46 +3925,99 @@ Public Class SourceMdlFile49 eyeballInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anEyeball As New SourceMdlEyeball() - anEyeball.nameOffset = Me.theInputFileReader.ReadInt32() - anEyeball.boneIndex = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anEyeball.nameOffset = ReadInt32BE() + anEyeball.boneIndex = ReadInt32BE() + Else + anEyeball.nameOffset = Me.theInputFileReader.ReadInt32() + anEyeball.boneIndex = Me.theInputFileReader.ReadInt32() + End If + anEyeball.org = New SourceVector() - anEyeball.org.x = Me.theInputFileReader.ReadSingle() - anEyeball.org.y = Me.theInputFileReader.ReadSingle() - anEyeball.org.z = Me.theInputFileReader.ReadSingle() - anEyeball.zOffset = Me.theInputFileReader.ReadSingle() - anEyeball.radius = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + anEyeball.org.x = ReadSingleBE() + anEyeball.org.y = ReadSingleBE() + anEyeball.org.z = ReadSingleBE() + anEyeball.zOffset = ReadSingleBE() + anEyeball.radius = ReadSingleBE() + Else + anEyeball.org.x = Me.theInputFileReader.ReadSingle() + anEyeball.org.y = Me.theInputFileReader.ReadSingle() + anEyeball.org.z = Me.theInputFileReader.ReadSingle() + anEyeball.zOffset = Me.theInputFileReader.ReadSingle() + anEyeball.radius = Me.theInputFileReader.ReadSingle() + End If + anEyeball.up = New SourceVector() - anEyeball.up.x = Me.theInputFileReader.ReadSingle() - anEyeball.up.y = Me.theInputFileReader.ReadSingle() - anEyeball.up.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + anEyeball.up.x = ReadSingleBE() + anEyeball.up.y = ReadSingleBE() + anEyeball.up.z = ReadSingleBE() + Else + anEyeball.up.x = Me.theInputFileReader.ReadSingle() + anEyeball.up.y = Me.theInputFileReader.ReadSingle() + anEyeball.up.z = Me.theInputFileReader.ReadSingle() + End If + anEyeball.forward = New SourceVector() - anEyeball.forward.x = Me.theInputFileReader.ReadSingle() - anEyeball.forward.y = Me.theInputFileReader.ReadSingle() - anEyeball.forward.z = Me.theInputFileReader.ReadSingle() - anEyeball.texture = Me.theInputFileReader.ReadInt32() - - anEyeball.unused1 = Me.theInputFileReader.ReadInt32() - anEyeball.irisScale = Me.theInputFileReader.ReadSingle() - anEyeball.unused2 = Me.theInputFileReader.ReadInt32() - - anEyeball.upperFlexDesc(0) = Me.theInputFileReader.ReadInt32() - anEyeball.upperFlexDesc(1) = Me.theInputFileReader.ReadInt32() - anEyeball.upperFlexDesc(2) = Me.theInputFileReader.ReadInt32() - anEyeball.lowerFlexDesc(0) = Me.theInputFileReader.ReadInt32() - anEyeball.lowerFlexDesc(1) = Me.theInputFileReader.ReadInt32() - anEyeball.lowerFlexDesc(2) = Me.theInputFileReader.ReadInt32() - anEyeball.upperTarget(0) = Me.theInputFileReader.ReadSingle() - anEyeball.upperTarget(1) = Me.theInputFileReader.ReadSingle() - anEyeball.upperTarget(2) = Me.theInputFileReader.ReadSingle() - anEyeball.lowerTarget(0) = Me.theInputFileReader.ReadSingle() - anEyeball.lowerTarget(1) = Me.theInputFileReader.ReadSingle() - anEyeball.lowerTarget(2) = Me.theInputFileReader.ReadSingle() - - anEyeball.upperLidFlexDesc = Me.theInputFileReader.ReadInt32() - anEyeball.lowerLidFlexDesc = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anEyeball.forward.x = ReadSingleBE() + anEyeball.forward.y = ReadSingleBE() + anEyeball.forward.z = ReadSingleBE() + anEyeball.texture = ReadInt32BE() + + anEyeball.unused1 = ReadInt32BE() + anEyeball.irisScale = ReadSingleBE() + anEyeball.unused2 = ReadInt32BE() + + anEyeball.upperFlexDesc(0) = ReadInt32BE() + anEyeball.upperFlexDesc(1) = ReadInt32BE() + anEyeball.upperFlexDesc(2) = ReadInt32BE() + anEyeball.lowerFlexDesc(0) = ReadInt32BE() + anEyeball.lowerFlexDesc(1) = ReadInt32BE() + anEyeball.lowerFlexDesc(2) = ReadInt32BE() + anEyeball.upperTarget(0) = ReadSingleBE() + anEyeball.upperTarget(1) = ReadSingleBE() + anEyeball.upperTarget(2) = ReadSingleBE() + anEyeball.lowerTarget(0) = ReadSingleBE() + anEyeball.lowerTarget(1) = ReadSingleBE() + anEyeball.lowerTarget(2) = ReadSingleBE() + + anEyeball.upperLidFlexDesc = ReadInt32BE() + anEyeball.lowerLidFlexDesc = ReadInt32BE() + Else + anEyeball.forward.x = Me.theInputFileReader.ReadSingle() + anEyeball.forward.y = Me.theInputFileReader.ReadSingle() + anEyeball.forward.z = Me.theInputFileReader.ReadSingle() + anEyeball.texture = Me.theInputFileReader.ReadInt32() + + anEyeball.unused1 = Me.theInputFileReader.ReadInt32() + anEyeball.irisScale = Me.theInputFileReader.ReadSingle() + anEyeball.unused2 = Me.theInputFileReader.ReadInt32() + + anEyeball.upperFlexDesc(0) = Me.theInputFileReader.ReadInt32() + anEyeball.upperFlexDesc(1) = Me.theInputFileReader.ReadInt32() + anEyeball.upperFlexDesc(2) = Me.theInputFileReader.ReadInt32() + anEyeball.lowerFlexDesc(0) = Me.theInputFileReader.ReadInt32() + anEyeball.lowerFlexDesc(1) = Me.theInputFileReader.ReadInt32() + anEyeball.lowerFlexDesc(2) = Me.theInputFileReader.ReadInt32() + anEyeball.upperTarget(0) = Me.theInputFileReader.ReadSingle() + anEyeball.upperTarget(1) = Me.theInputFileReader.ReadSingle() + anEyeball.upperTarget(2) = Me.theInputFileReader.ReadSingle() + anEyeball.lowerTarget(0) = Me.theInputFileReader.ReadSingle() + anEyeball.lowerTarget(1) = Me.theInputFileReader.ReadSingle() + anEyeball.lowerTarget(2) = Me.theInputFileReader.ReadSingle() + + anEyeball.upperLidFlexDesc = Me.theInputFileReader.ReadInt32() + anEyeball.lowerLidFlexDesc = Me.theInputFileReader.ReadInt32() + End If For x As Integer = 0 To anEyeball.unused.Length - 1 - anEyeball.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anEyeball.unused(x) = ReadInt32BE() + Else + anEyeball.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next anEyeball.eyeballIsNonFacs = Me.theInputFileReader.ReadByte() @@ -2962,7 +4026,11 @@ Public Class SourceMdlFile49 anEyeball.unused3(x) = Me.theInputFileReader.ReadChar() Next For x As Integer = 0 To anEyeball.unused4.Length - 1 - anEyeball.unused4(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anEyeball.unused4(x) = ReadInt32BE() + Else + anEyeball.unused4(x) = Me.theInputFileReader.ReadInt32() + End If Next aModel.theEyeballs.Add(anEyeball) @@ -3032,23 +4100,43 @@ Public Class SourceMdlFile49 flexInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aFlex As New SourceMdlFlex() - aFlex.flexDescIndex = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aFlex.flexDescIndex = ReadInt32BE() + + aFlex.target0 = ReadSingleBE() + aFlex.target1 = ReadSingleBE() + aFlex.target2 = ReadSingleBE() + aFlex.target3 = ReadSingleBE() + + aFlex.vertCount = ReadInt32BE() + aFlex.vertOffset = ReadInt32BE() - aFlex.target0 = Me.theInputFileReader.ReadSingle() - aFlex.target1 = Me.theInputFileReader.ReadSingle() - aFlex.target2 = Me.theInputFileReader.ReadSingle() - aFlex.target3 = Me.theInputFileReader.ReadSingle() + aFlex.flexDescPartnerIndex = ReadInt32BE() + Else + aFlex.flexDescIndex = Me.theInputFileReader.ReadInt32() + + aFlex.target0 = Me.theInputFileReader.ReadSingle() + aFlex.target1 = Me.theInputFileReader.ReadSingle() + aFlex.target2 = Me.theInputFileReader.ReadSingle() + aFlex.target3 = Me.theInputFileReader.ReadSingle() - aFlex.vertCount = Me.theInputFileReader.ReadInt32() - aFlex.vertOffset = Me.theInputFileReader.ReadInt32() + aFlex.vertCount = Me.theInputFileReader.ReadInt32() + aFlex.vertOffset = Me.theInputFileReader.ReadInt32() + + aFlex.flexDescPartnerIndex = Me.theInputFileReader.ReadInt32() + End If - aFlex.flexDescPartnerIndex = Me.theInputFileReader.ReadInt32() aFlex.vertAnimType = Me.theInputFileReader.ReadByte() + For x As Integer = 0 To aFlex.unusedChar.Length - 1 aFlex.unusedChar(x) = Me.theInputFileReader.ReadChar() Next For x As Integer = 0 To aFlex.unused.Length - 1 - aFlex.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aFlex.unused(x) = ReadInt32BE() + Else + aFlex.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next aMesh.theFlexes.Add(aFlex) @@ -3093,19 +4181,36 @@ Public Class SourceMdlFile49 aVertAnim = New SourceMdlVertAnim() End If - aVertAnim.index = Me.theInputFileReader.ReadUInt16() + If Me.theMdlFileData.isBigEndian Then + aVertAnim.index = ReadUInt16BE() + Else + aVertAnim.index = Me.theInputFileReader.ReadUInt16() + End If + aVertAnim.speed = Me.theInputFileReader.ReadByte() aVertAnim.side = Me.theInputFileReader.ReadByte() For x As Integer = 0 To 2 - aVertAnim.deltaUShort(x) = Me.theInputFileReader.ReadUInt16() + If Me.theMdlFileData.isBigEndian Then + aVertAnim.deltaUShort(x) = ReadUInt16BE() + Else + aVertAnim.deltaUShort(x) = Me.theInputFileReader.ReadUInt16() + End If Next For x As Integer = 0 To 2 - aVertAnim.nDeltaUShort(x) = Me.theInputFileReader.ReadUInt16() + If Me.theMdlFileData.isBigEndian Then + aVertAnim.nDeltaUShort(x) = ReadUInt16BE() + Else + aVertAnim.nDeltaUShort(x) = Me.theInputFileReader.ReadUInt16() + End If Next If aFlex.vertAnimType = aFlex.STUDIO_VERT_ANIM_WRINKLE Then - CType(aVertAnim, SourceMdlVertAnimWrinkle).wrinkleDelta = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + CType(aVertAnim, SourceMdlVertAnimWrinkle).wrinkleDelta = ReadInt16BE() + Else + CType(aVertAnim, SourceMdlVertAnimWrinkle).wrinkleDelta = Me.theInputFileReader.ReadInt16() + End If End If aFlex.theVertAnims.Add(aVertAnim) @@ -3143,7 +4248,12 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.flexDescCount - 1 flexDescInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aFlexDesc As New SourceMdlFlexDesc() - aFlexDesc.nameOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aFlexDesc.nameOffset = ReadInt32BE() + Else + aFlexDesc.nameOffset = Me.theInputFileReader.ReadInt32() + End If + Me.theMdlFileData.theFlexDescs.Add(aFlexDesc) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -3186,11 +4296,20 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.flexControllerCount - 1 flexControllerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aFlexController As New SourceMdlFlexController() - aFlexController.typeOffset = Me.theInputFileReader.ReadInt32() - aFlexController.nameOffset = Me.theInputFileReader.ReadInt32() - aFlexController.localToGlobal = Me.theInputFileReader.ReadInt32() - aFlexController.min = Me.theInputFileReader.ReadSingle() - aFlexController.max = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aFlexController.typeOffset = ReadInt32BE() + aFlexController.nameOffset = ReadInt32BE() + aFlexController.localToGlobal = ReadInt32BE() + aFlexController.min = ReadSingleBE() + aFlexController.max = ReadSingleBE() + Else + aFlexController.typeOffset = Me.theInputFileReader.ReadInt32() + aFlexController.nameOffset = Me.theInputFileReader.ReadInt32() + aFlexController.localToGlobal = Me.theInputFileReader.ReadInt32() + aFlexController.min = Me.theInputFileReader.ReadSingle() + aFlexController.max = Me.theInputFileReader.ReadSingle() + End If + Me.theMdlFileData.theFlexControllers.Add(aFlexController) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -3270,9 +4389,16 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.flexRuleCount - 1 flexRuleInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aFlexRule As New SourceMdlFlexRule() - aFlexRule.flexIndex = Me.theInputFileReader.ReadInt32() - aFlexRule.opCount = Me.theInputFileReader.ReadInt32() - aFlexRule.opOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aFlexRule.flexIndex = ReadInt32BE() + aFlexRule.opCount = ReadInt32BE() + aFlexRule.opOffset = ReadInt32BE() + Else + aFlexRule.flexIndex = Me.theInputFileReader.ReadInt32() + aFlexRule.opCount = Me.theInputFileReader.ReadInt32() + aFlexRule.opOffset = Me.theInputFileReader.ReadInt32() + End If + Me.theMdlFileData.theFlexRules.Add(aFlexRule) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -3310,11 +4436,25 @@ Public Class SourceMdlFile49 For i As Integer = 0 To aFlexRule.opCount - 1 'flexRuleInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aFlexOp As New SourceMdlFlexOp() - aFlexOp.op = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aFlexOp.op = ReadInt32BE() + Else + aFlexOp.op = Me.theInputFileReader.ReadInt32() + End If + If aFlexOp.op = SourceMdlFlexOp.STUDIO_CONST Then - aFlexOp.value = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aFlexOp.value = ReadSingleBE() + Else + aFlexOp.value = Me.theInputFileReader.ReadSingle() + End If Else - aFlexOp.index = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aFlexOp.index = ReadInt32BE() + Else + aFlexOp.index = Me.theInputFileReader.ReadInt32() + End If + If aFlexOp.op = SourceMdlFlexOp.STUDIO_FETCH2 Then Me.theMdlFileData.theFlexDescs(aFlexOp.index).theDescIsUsedByFlexRule = True End If @@ -3346,10 +4486,18 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.ikChainCount - 1 ikChainInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anIkChain As New SourceMdlIkChain() - anIkChain.nameOffset = Me.theInputFileReader.ReadInt32() - anIkChain.linkType = Me.theInputFileReader.ReadInt32() - anIkChain.linkCount = Me.theInputFileReader.ReadInt32() - anIkChain.linkOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anIkChain.nameOffset = ReadInt32BE() + anIkChain.linkType = ReadInt32BE() + anIkChain.linkCount = ReadInt32BE() + anIkChain.linkOffset = ReadInt32BE() + Else + anIkChain.nameOffset = Me.theInputFileReader.ReadInt32() + anIkChain.linkType = Me.theInputFileReader.ReadInt32() + anIkChain.linkCount = Me.theInputFileReader.ReadInt32() + anIkChain.linkOffset = Me.theInputFileReader.ReadInt32() + End If + Me.theMdlFileData.theIkChains.Add(anIkChain) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -3393,13 +4541,24 @@ Public Class SourceMdlFile49 For j As Integer = 0 To anIkChain.linkCount - 1 'ikLinkInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anIkLink As New SourceMdlIkLink() - anIkLink.boneIndex = Me.theInputFileReader.ReadInt32() - anIkLink.idealBendingDirection.x = Me.theInputFileReader.ReadSingle() - anIkLink.idealBendingDirection.y = Me.theInputFileReader.ReadSingle() - anIkLink.idealBendingDirection.z = Me.theInputFileReader.ReadSingle() - anIkLink.unused0.x = Me.theInputFileReader.ReadSingle() - anIkLink.unused0.y = Me.theInputFileReader.ReadSingle() - anIkLink.unused0.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + anIkLink.boneIndex = ReadInt32BE() + anIkLink.idealBendingDirection.x = ReadSingleBE() + anIkLink.idealBendingDirection.y = ReadSingleBE() + anIkLink.idealBendingDirection.z = ReadSingleBE() + anIkLink.unused0.x = ReadSingleBE() + anIkLink.unused0.y = ReadSingleBE() + anIkLink.unused0.z = ReadSingleBE() + Else + anIkLink.boneIndex = Me.theInputFileReader.ReadInt32() + anIkLink.idealBendingDirection.x = Me.theInputFileReader.ReadSingle() + anIkLink.idealBendingDirection.y = Me.theInputFileReader.ReadSingle() + anIkLink.idealBendingDirection.z = Me.theInputFileReader.ReadSingle() + anIkLink.unused0.x = Me.theInputFileReader.ReadSingle() + anIkLink.unused0.y = Me.theInputFileReader.ReadSingle() + anIkLink.unused0.z = Me.theInputFileReader.ReadSingle() + End If + anIkChain.theLinks.Add(anIkLink) 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -3428,12 +4587,24 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.localIkAutoPlayLockCount - 1 'ikChainInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anIkLock As New SourceMdlIkLock() - anIkLock.chainIndex = Me.theInputFileReader.ReadInt32() - anIkLock.posWeight = Me.theInputFileReader.ReadSingle() - anIkLock.localQWeight = Me.theInputFileReader.ReadSingle() - anIkLock.flags = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anIkLock.chainIndex = ReadInt32BE() + anIkLock.posWeight = ReadSingleBE() + anIkLock.localQWeight = ReadSingleBE() + anIkLock.flags = ReadInt32BE() + Else + anIkLock.chainIndex = Me.theInputFileReader.ReadInt32() + anIkLock.posWeight = Me.theInputFileReader.ReadSingle() + anIkLock.localQWeight = Me.theInputFileReader.ReadSingle() + anIkLock.flags = Me.theInputFileReader.ReadInt32() + End If + For x As Integer = 0 To anIkLock.unused.Length - 1 - anIkLock.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + anIkLock.unused(x) = ReadInt32BE() + Else + anIkLock.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next Me.theMdlFileData.theIkLocks.Add(anIkLock) @@ -3464,11 +4635,19 @@ Public Class SourceMdlFile49 'mouthInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aMouth As New SourceMdlMouth() - aMouth.boneIndex = Me.theInputFileReader.ReadInt32() - aMouth.forward.x = Me.theInputFileReader.ReadSingle() - aMouth.forward.y = Me.theInputFileReader.ReadSingle() - aMouth.forward.z = Me.theInputFileReader.ReadSingle() - aMouth.flexDescIndex = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aMouth.boneIndex = ReadInt32BE() + aMouth.forward.x = ReadSingleBE() + aMouth.forward.y = ReadSingleBE() + aMouth.forward.z = ReadSingleBE() + aMouth.flexDescIndex = ReadInt32BE() + Else + aMouth.boneIndex = Me.theInputFileReader.ReadInt32() + aMouth.forward.x = Me.theInputFileReader.ReadSingle() + aMouth.forward.y = Me.theInputFileReader.ReadSingle() + aMouth.forward.z = Me.theInputFileReader.ReadSingle() + aMouth.flexDescIndex = Me.theInputFileReader.ReadInt32() + End If Me.theMdlFileData.theMouths.Add(aMouth) @@ -3504,11 +4683,20 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.localPoseParamaterCount - 1 poseInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aPoseParamDesc As New SourceMdlPoseParamDesc() - aPoseParamDesc.nameOffset = Me.theInputFileReader.ReadInt32() - aPoseParamDesc.flags = Me.theInputFileReader.ReadInt32() - aPoseParamDesc.startingValue = Me.theInputFileReader.ReadSingle() - aPoseParamDesc.endingValue = Me.theInputFileReader.ReadSingle() - aPoseParamDesc.loopingRange = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aPoseParamDesc.nameOffset = ReadInt32BE() + aPoseParamDesc.flags = ReadInt32BE() + aPoseParamDesc.startingValue = ReadSingleBE() + aPoseParamDesc.endingValue = ReadSingleBE() + aPoseParamDesc.loopingRange = ReadSingleBE() + Else + aPoseParamDesc.nameOffset = Me.theInputFileReader.ReadInt32() + aPoseParamDesc.flags = Me.theInputFileReader.ReadInt32() + aPoseParamDesc.startingValue = Me.theInputFileReader.ReadSingle() + aPoseParamDesc.endingValue = Me.theInputFileReader.ReadSingle() + aPoseParamDesc.loopingRange = Me.theInputFileReader.ReadSingle() + End If + Me.theMdlFileData.thePoseParamDescs.Add(aPoseParamDesc) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -3552,14 +4740,28 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.textureCount - 1 textureInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aTexture As New SourceMdlTexture() - aTexture.nameOffset = Me.theInputFileReader.ReadInt32() - aTexture.flags = Me.theInputFileReader.ReadInt32() - aTexture.used = Me.theInputFileReader.ReadInt32() - aTexture.unused1 = Me.theInputFileReader.ReadInt32() - aTexture.materialP = Me.theInputFileReader.ReadInt32() - aTexture.clientMaterialP = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aTexture.nameOffset = ReadInt32BE() + aTexture.flags = ReadInt32BE() + aTexture.used = ReadInt32BE() + aTexture.unused1 = ReadInt32BE() + aTexture.materialP = ReadInt32BE() + aTexture.clientMaterialP = ReadInt32BE() + Else + aTexture.nameOffset = Me.theInputFileReader.ReadInt32() + aTexture.flags = Me.theInputFileReader.ReadInt32() + aTexture.used = Me.theInputFileReader.ReadInt32() + aTexture.unused1 = Me.theInputFileReader.ReadInt32() + aTexture.materialP = Me.theInputFileReader.ReadInt32() + aTexture.clientMaterialP = Me.theInputFileReader.ReadInt32() + End If + For x As Integer = 0 To 9 - aTexture.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aTexture.unused(x) = ReadInt32BE() + Else + aTexture.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next Me.theMdlFileData.theTextures.Add(aTexture) @@ -3610,7 +4812,11 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.texturePathCount - 1 texturePathInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aTexturePath As String - texturePathOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + texturePathOffset = ReadInt32BE() + Else + texturePathOffset = Me.theInputFileReader.ReadInt32() + End If inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -3664,7 +4870,11 @@ Public Class SourceMdlFile49 For j As Integer = 0 To Me.theMdlFileData.skinReferenceCount - 1 Dim aSkinRef As Short - aSkinRef = Me.theInputFileReader.ReadInt16() + If Me.theMdlFileData.isBigEndian Then + aSkinRef = ReadInt16BE() + Else + aSkinRef = Me.theInputFileReader.ReadInt16() + End If aSkinFamily.Add(aSkinRef) Next @@ -3725,8 +4935,14 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.includeModelCount - 1 includeModelInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aModelGroup As New SourceMdlModelGroup() - aModelGroup.labelOffset = Me.theInputFileReader.ReadInt32() - aModelGroup.fileNameOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aModelGroup.labelOffset = ReadInt32BE() + aModelGroup.fileNameOffset = ReadInt32BE() + Else + aModelGroup.labelOffset = Me.theInputFileReader.ReadInt32() + aModelGroup.fileNameOffset = Me.theInputFileReader.ReadInt32() + End If + Me.theMdlFileData.theModelGroups.Add(aModelGroup) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -3782,10 +4998,18 @@ Public Class SourceMdlFile49 For i As Integer = 0 To Me.theMdlFileData.flexControllerUiCount - 1 flexControllerUiInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aFlexControllerUi As New SourceMdlFlexControllerUi() - aFlexControllerUi.nameOffset = Me.theInputFileReader.ReadInt32() - aFlexControllerUi.config0 = Me.theInputFileReader.ReadInt32() - aFlexControllerUi.config1 = Me.theInputFileReader.ReadInt32() - aFlexControllerUi.config2 = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aFlexControllerUi.nameOffset = ReadInt32BE() + aFlexControllerUi.config0 = ReadInt32BE() + aFlexControllerUi.config1 = ReadInt32BE() + aFlexControllerUi.config2 = ReadInt32BE() + Else + aFlexControllerUi.nameOffset = Me.theInputFileReader.ReadInt32() + aFlexControllerUi.config0 = Me.theInputFileReader.ReadInt32() + aFlexControllerUi.config1 = Me.theInputFileReader.ReadInt32() + aFlexControllerUi.config2 = Me.theInputFileReader.ReadInt32() + End If + aFlexControllerUi.remapType = Me.theInputFileReader.ReadByte() aFlexControllerUi.controlIsStereo = Me.theInputFileReader.ReadByte() For x As Integer = 0 To aFlexControllerUi.unused.Length - 1 @@ -3914,41 +5138,75 @@ Public Class SourceMdlFile49 boneInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aBoneTransform As New SourceMdlBoneTransform() - aBoneTransform.nameOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBoneTransform.nameOffset = ReadInt32BE() + Else + aBoneTransform.nameOffset = Me.theInputFileReader.ReadInt32() + End If aBoneTransform.preTransformColumn0 = New SourceVector() aBoneTransform.preTransformColumn1 = New SourceVector() aBoneTransform.preTransformColumn2 = New SourceVector() aBoneTransform.preTransformColumn3 = New SourceVector() - aBoneTransform.preTransformColumn0.x = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn1.x = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn2.x = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn3.x = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn0.y = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn1.y = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn2.y = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn3.y = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn0.z = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn1.z = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn2.z = Me.theInputFileReader.ReadSingle() - aBoneTransform.preTransformColumn3.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBoneTransform.preTransformColumn0.x = ReadSingleBE() + aBoneTransform.preTransformColumn1.x = ReadSingleBE() + aBoneTransform.preTransformColumn2.x = ReadSingleBE() + aBoneTransform.preTransformColumn3.x = ReadSingleBE() + aBoneTransform.preTransformColumn0.y = ReadSingleBE() + aBoneTransform.preTransformColumn1.y = ReadSingleBE() + aBoneTransform.preTransformColumn2.y = ReadSingleBE() + aBoneTransform.preTransformColumn3.y = ReadSingleBE() + aBoneTransform.preTransformColumn0.z = ReadSingleBE() + aBoneTransform.preTransformColumn1.z = ReadSingleBE() + aBoneTransform.preTransformColumn2.z = ReadSingleBE() + aBoneTransform.preTransformColumn3.z = ReadSingleBE() + Else + aBoneTransform.preTransformColumn0.x = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn1.x = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn2.x = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn3.x = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn0.y = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn1.y = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn2.y = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn3.y = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn0.z = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn1.z = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn2.z = Me.theInputFileReader.ReadSingle() + aBoneTransform.preTransformColumn3.z = Me.theInputFileReader.ReadSingle() + End If aBoneTransform.postTransformColumn0 = New SourceVector() aBoneTransform.postTransformColumn1 = New SourceVector() aBoneTransform.postTransformColumn2 = New SourceVector() aBoneTransform.postTransformColumn3 = New SourceVector() - aBoneTransform.postTransformColumn0.x = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn1.x = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn2.x = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn3.x = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn0.y = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn1.y = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn2.y = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn3.y = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn0.z = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn1.z = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn2.z = Me.theInputFileReader.ReadSingle() - aBoneTransform.postTransformColumn3.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + aBoneTransform.postTransformColumn0.x = ReadSingleBE() + aBoneTransform.postTransformColumn1.x = ReadSingleBE() + aBoneTransform.postTransformColumn2.x = ReadSingleBE() + aBoneTransform.postTransformColumn3.x = ReadSingleBE() + aBoneTransform.postTransformColumn0.y = ReadSingleBE() + aBoneTransform.postTransformColumn1.y = ReadSingleBE() + aBoneTransform.postTransformColumn2.y = ReadSingleBE() + aBoneTransform.postTransformColumn3.y = ReadSingleBE() + aBoneTransform.postTransformColumn0.z = ReadSingleBE() + aBoneTransform.postTransformColumn1.z = ReadSingleBE() + aBoneTransform.postTransformColumn2.z = ReadSingleBE() + aBoneTransform.postTransformColumn3.z = ReadSingleBE() + Else + aBoneTransform.postTransformColumn0.x = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn1.x = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn2.x = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn3.x = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn0.y = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn1.y = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn2.y = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn3.y = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn0.z = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn1.z = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn2.z = Me.theInputFileReader.ReadSingle() + aBoneTransform.postTransformColumn3.z = Me.theInputFileReader.ReadSingle() + End If Me.theMdlFileData.theBoneTransforms.Add(aBoneTransform) @@ -4026,18 +5284,36 @@ Public Class SourceMdlFile49 Dim linearBoneTable As SourceMdlLinearBone Me.theMdlFileData.theLinearBoneTable = New SourceMdlLinearBone() linearBoneTable = Me.theMdlFileData.theLinearBoneTable - linearBoneTable.boneCount = Me.theInputFileReader.ReadInt32() - linearBoneTable.flagsOffset = Me.theInputFileReader.ReadInt32() - linearBoneTable.parentOffset = Me.theInputFileReader.ReadInt32() - linearBoneTable.posOffset = Me.theInputFileReader.ReadInt32() - linearBoneTable.quatOffset = Me.theInputFileReader.ReadInt32() - linearBoneTable.rotOffset = Me.theInputFileReader.ReadInt32() - linearBoneTable.poseToBoneOffset = Me.theInputFileReader.ReadInt32() - linearBoneTable.posScaleOffset = Me.theInputFileReader.ReadInt32() - linearBoneTable.rotScaleOffset = Me.theInputFileReader.ReadInt32() - linearBoneTable.qAlignmentOffset = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + linearBoneTable.boneCount = ReadInt32BE() + linearBoneTable.flagsOffset = ReadInt32BE() + linearBoneTable.parentOffset = ReadInt32BE() + linearBoneTable.posOffset = ReadInt32BE() + linearBoneTable.quatOffset = ReadInt32BE() + linearBoneTable.rotOffset = ReadInt32BE() + linearBoneTable.poseToBoneOffset = ReadInt32BE() + linearBoneTable.posScaleOffset = ReadInt32BE() + linearBoneTable.rotScaleOffset = ReadInt32BE() + linearBoneTable.qAlignmentOffset = ReadInt32BE() + Else + linearBoneTable.boneCount = Me.theInputFileReader.ReadInt32() + linearBoneTable.flagsOffset = Me.theInputFileReader.ReadInt32() + linearBoneTable.parentOffset = Me.theInputFileReader.ReadInt32() + linearBoneTable.posOffset = Me.theInputFileReader.ReadInt32() + linearBoneTable.quatOffset = Me.theInputFileReader.ReadInt32() + linearBoneTable.rotOffset = Me.theInputFileReader.ReadInt32() + linearBoneTable.poseToBoneOffset = Me.theInputFileReader.ReadInt32() + linearBoneTable.posScaleOffset = Me.theInputFileReader.ReadInt32() + linearBoneTable.rotScaleOffset = Me.theInputFileReader.ReadInt32() + linearBoneTable.qAlignmentOffset = Me.theInputFileReader.ReadInt32() + End If + For x As Integer = 0 To linearBoneTable.unused.Length - 1 - linearBoneTable.unused(x) = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + linearBoneTable.unused(x) = ReadInt32BE() + Else + linearBoneTable.unused(x) = Me.theInputFileReader.ReadInt32() + End If Next fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 @@ -4047,7 +5323,11 @@ Public Class SourceMdlFile49 fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position For i As Integer = 0 To linearBoneTable.boneCount - 1 Dim flags As Integer - flags = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + flags = ReadInt32BE() + Else + flags = Me.theInputFileReader.ReadInt32() + End If linearBoneTable.theFlags.Add(flags) Next fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 @@ -4064,7 +5344,11 @@ Public Class SourceMdlFile49 fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position For i As Integer = 0 To linearBoneTable.boneCount - 1 Dim parent As Integer - parent = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + parent = ReadInt32BE() + Else + parent = Me.theInputFileReader.ReadInt32() + End If linearBoneTable.theParents.Add(parent) Next fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 @@ -4081,9 +5365,15 @@ Public Class SourceMdlFile49 fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position For i As Integer = 0 To linearBoneTable.boneCount - 1 Dim position As New SourceVector - position.x = Me.theInputFileReader.ReadSingle() - position.y = Me.theInputFileReader.ReadSingle() - position.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + position.x = ReadSingleBE() + position.y = ReadSingleBE() + position.z = ReadSingleBE() + Else + position.x = Me.theInputFileReader.ReadSingle() + position.y = Me.theInputFileReader.ReadSingle() + position.z = Me.theInputFileReader.ReadSingle() + End If linearBoneTable.thePositions.Add(position) Next fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 @@ -4100,10 +5390,17 @@ Public Class SourceMdlFile49 fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position For i As Integer = 0 To linearBoneTable.boneCount - 1 Dim quaternion As New SourceQuaternion - quaternion.x = Me.theInputFileReader.ReadSingle() - quaternion.y = Me.theInputFileReader.ReadSingle() - quaternion.z = Me.theInputFileReader.ReadSingle() - quaternion.w = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + quaternion.x = ReadSingleBE() + quaternion.y = ReadSingleBE() + quaternion.z = ReadSingleBE() + quaternion.w = ReadSingleBE() + Else + quaternion.x = Me.theInputFileReader.ReadSingle() + quaternion.y = Me.theInputFileReader.ReadSingle() + quaternion.z = Me.theInputFileReader.ReadSingle() + quaternion.w = Me.theInputFileReader.ReadSingle() + End If linearBoneTable.theQuaternions.Add(quaternion) Next fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 @@ -4120,9 +5417,15 @@ Public Class SourceMdlFile49 fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position For i As Integer = 0 To linearBoneTable.boneCount - 1 Dim rotation As New SourceVector - rotation.x = Me.theInputFileReader.ReadSingle() - rotation.y = Me.theInputFileReader.ReadSingle() - rotation.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + rotation.x = ReadSingleBE() + rotation.y = ReadSingleBE() + rotation.z = ReadSingleBE() + Else + rotation.x = Me.theInputFileReader.ReadSingle() + rotation.y = Me.theInputFileReader.ReadSingle() + rotation.z = Me.theInputFileReader.ReadSingle() + End If linearBoneTable.theRotations.Add(rotation) Next fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 @@ -4142,18 +5445,34 @@ Public Class SourceMdlFile49 Dim poseToBoneDataColumn1 As New SourceVector() Dim poseToBoneDataColumn2 As New SourceVector() Dim poseToBoneDataColumn3 As New SourceVector() - poseToBoneDataColumn0.x = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn1.x = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn2.x = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn3.x = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn0.y = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn1.y = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn2.y = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn3.y = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn0.z = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn1.z = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn2.z = Me.theInputFileReader.ReadSingle() - poseToBoneDataColumn3.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + poseToBoneDataColumn0.x = ReadSingleBE() + poseToBoneDataColumn1.x = ReadSingleBE() + poseToBoneDataColumn2.x = ReadSingleBE() + poseToBoneDataColumn3.x = ReadSingleBE() + poseToBoneDataColumn0.y = ReadSingleBE() + poseToBoneDataColumn1.y = ReadSingleBE() + poseToBoneDataColumn2.y = ReadSingleBE() + poseToBoneDataColumn3.y = ReadSingleBE() + poseToBoneDataColumn0.z = ReadSingleBE() + poseToBoneDataColumn1.z = ReadSingleBE() + poseToBoneDataColumn2.z = ReadSingleBE() + poseToBoneDataColumn3.z = ReadSingleBE() + Else + poseToBoneDataColumn0.x = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn1.x = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn2.x = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn3.x = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn0.y = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn1.y = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn2.y = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn3.y = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn0.z = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn1.z = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn2.z = Me.theInputFileReader.ReadSingle() + poseToBoneDataColumn3.z = Me.theInputFileReader.ReadSingle() + End If + linearBoneTable.thePoseToBoneDataColumn0s.Add(poseToBoneDataColumn0) linearBoneTable.thePoseToBoneDataColumn1s.Add(poseToBoneDataColumn1) linearBoneTable.thePoseToBoneDataColumn2s.Add(poseToBoneDataColumn2) @@ -4173,9 +5492,15 @@ Public Class SourceMdlFile49 fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position For i As Integer = 0 To linearBoneTable.boneCount - 1 Dim positionScale As New SourceVector - positionScale.x = Me.theInputFileReader.ReadSingle() - positionScale.y = Me.theInputFileReader.ReadSingle() - positionScale.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + positionScale.x = ReadSingleBE() + positionScale.y = ReadSingleBE() + positionScale.z = ReadSingleBE() + Else + positionScale.x = Me.theInputFileReader.ReadSingle() + positionScale.y = Me.theInputFileReader.ReadSingle() + positionScale.z = Me.theInputFileReader.ReadSingle() + End If linearBoneTable.thePositionScales.Add(positionScale) Next fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 @@ -4192,9 +5517,15 @@ Public Class SourceMdlFile49 fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position For i As Integer = 0 To linearBoneTable.boneCount - 1 Dim rotationScale As New SourceVector - rotationScale.x = Me.theInputFileReader.ReadSingle() - rotationScale.y = Me.theInputFileReader.ReadSingle() - rotationScale.z = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + rotationScale.x = ReadSingleBE() + rotationScale.y = ReadSingleBE() + rotationScale.z = ReadSingleBE() + Else + rotationScale.x = Me.theInputFileReader.ReadSingle() + rotationScale.y = Me.theInputFileReader.ReadSingle() + rotationScale.z = Me.theInputFileReader.ReadSingle() + End If linearBoneTable.theRotationScales.Add(rotationScale) Next fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 @@ -4211,10 +5542,17 @@ Public Class SourceMdlFile49 fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position For i As Integer = 0 To linearBoneTable.boneCount - 1 Dim qAlignment As New SourceQuaternion - qAlignment.x = Me.theInputFileReader.ReadSingle() - qAlignment.y = Me.theInputFileReader.ReadSingle() - qAlignment.z = Me.theInputFileReader.ReadSingle() - qAlignment.w = Me.theInputFileReader.ReadSingle() + If Me.theMdlFileData.isBigEndian Then + qAlignment.x = ReadSingleBE() + qAlignment.y = ReadSingleBE() + qAlignment.z = ReadSingleBE() + qAlignment.w = ReadSingleBE() + Else + qAlignment.x = Me.theInputFileReader.ReadSingle() + qAlignment.y = Me.theInputFileReader.ReadSingle() + qAlignment.z = Me.theInputFileReader.ReadSingle() + qAlignment.w = Me.theInputFileReader.ReadSingle() + End If linearBoneTable.theQAlignments.Add(qAlignment) Next fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 @@ -4246,9 +5584,15 @@ Public Class SourceMdlFile49 bodygroupPresetInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim aBodygroupPreset As New SourceMdlBodygroupPreset() - aBodygroupPreset.nameOffset = Me.theInputFileReader.ReadInt32() - aBodygroupPreset.value = Me.theInputFileReader.ReadInt32() - aBodygroupPreset.mask = Me.theInputFileReader.ReadInt32() + If Me.theMdlFileData.isBigEndian Then + aBodygroupPreset.nameOffset = ReadInt32BE() + aBodygroupPreset.value = ReadInt32BE() + aBodygroupPreset.mask = ReadInt32BE() + Else + aBodygroupPreset.nameOffset = Me.theInputFileReader.ReadInt32() + aBodygroupPreset.value = Me.theInputFileReader.ReadInt32() + aBodygroupPreset.mask = Me.theInputFileReader.ReadInt32() + End If Me.theMdlFileData.theBodygroupPresets.Add(aBodygroupPreset) @@ -4281,6 +5625,94 @@ Public Class SourceMdlFile49 End If End Sub + Public Sub ReadBoltons() + If Me.theMdlFileData.numBoltons > 0 Then + Dim boltonInputFileStreamPosition As Long + Dim inputFileStreamPosition As Long + + Try + Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.boltonIndex, SeekOrigin.Begin) + + Me.theMdlFileData.theBoltons = New List(Of SourceMdlBolton)(Me.theMdlFileData.numBoltons) + For i As Integer = 0 To Me.theMdlFileData.numBoltons - 1 + boltonInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + Dim aBolton As New SourceMdlBolton() + + If Me.theMdlFileData.isBigEndian Then + aBolton.type = ReadInt32BE() + aBolton.szmodelnameindex = ReadInt32BE() + Else + aBolton.type = Me.theInputFileReader.ReadInt32() + aBolton.szmodelnameindex = Me.theInputFileReader.ReadInt32() + End If + + Me.theMdlFileData.theBoltons.Add(aBolton) + + inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + + Me.theInputFileReader.BaseStream.Seek(boltonInputFileStreamPosition + aBolton.szmodelnameindex, SeekOrigin.Begin) + + aBolton.theModelName = FileManager.ReadNullTerminatedString(Me.theInputFileReader) + + Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) + Next + Catch ex As Exception + + End Try + End If + End Sub + + Public Sub ReadPrefabs() + If Me.theMdlFileData.numPrefabs > 0 Then + Dim prefabInputFileStreamPosition As Long + Dim inputFileStreamPosition As Long + + Try + Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.prefabIndex, SeekOrigin.Begin) + + Me.theMdlFileData.thePrefabs = New List(Of SourceMdlPrefab)(Me.theMdlFileData.numPrefabs) + For i As Integer = 0 To Me.theMdlFileData.numPrefabs - 1 + prefabInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + Dim aPrefab As New SourceMdlPrefab() + + If Me.theMdlFileData.isBigEndian Then + aPrefab.sznameindex = ReadInt32BE() + aPrefab.skin = ReadInt32BE() + aPrefab.boltonsmask = ReadInt32BE() + aPrefab.bodypartsindex = ReadInt32BE() + Else + aPrefab.sznameindex = Me.theInputFileReader.ReadInt32() + aPrefab.skin = Me.theInputFileReader.ReadInt32() + aPrefab.boltonsmask = Me.theInputFileReader.ReadInt32() + aPrefab.bodypartsindex = Me.theInputFileReader.ReadInt32() + End If + + inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + + Me.theInputFileReader.BaseStream.Seek(prefabInputFileStreamPosition + aPrefab.bodypartsindex, SeekOrigin.Begin) + + aPrefab.theBodyParts = New List(Of Byte)(Me.theMdlFileData.bodyPartCount) + + For j As Integer = 0 To Me.theMdlFileData.bodyPartCount - 1 + aPrefab.theBodyParts.Add(Me.theInputFileReader.ReadByte()) + Next + + Me.theMdlFileData.thePrefabs.Add(aPrefab) + + 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + + Me.theInputFileReader.BaseStream.Seek(prefabInputFileStreamPosition + aPrefab.sznameindex, SeekOrigin.Begin) + + aPrefab.theName = FileManager.ReadNullTerminatedString(Me.theInputFileReader) + + Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) + Next + Catch ex As Exception + + End Try + End If + End Sub + 'Public Sub ReadFinalBytesAlignment() ' Me.theMdlFileData.theFileSeekLog.LogAndAlignFromFileSeekLogEnd(Me.theInputFileReader, 4, "Final bytes alignment") 'End Sub diff --git a/Crowbar/Core/GameModel/SourceModel49/SourceMdlFileData/SourceMdlFileData49.vb b/Crowbar/Core/GameModel/SourceModel49/SourceMdlFileData/SourceMdlFileData49.vb index 49f21989..f54b382c 100644 --- a/Crowbar/Core/GameModel/SourceModel49/SourceMdlFileData/SourceMdlFileData49.vb +++ b/Crowbar/Core/GameModel/SourceModel49/SourceMdlFileData/SourceMdlFileData49.vb @@ -494,6 +494,10 @@ Public illumPositionAttachmentNumber As Integer Public maxEyeDeflection As Single Public linearBoneOffset As Integer + Public numBoltons As Integer + Public boltonIndex As Integer + Public numPrefabs As Integer + Public prefabIndex As Integer Public nameCopyOffset As Integer Public boneFlexDriverCount As Integer Public boneFlexDriverOffset As Integer @@ -541,6 +545,8 @@ Public theTexturePaths As List(Of String) Public theTextures As List(Of SourceMdlTexture) Public theWeightLists As List(Of SourceMdlWeightList) + Public theBoltons As List(Of SourceMdlBolton) + Public thePrefabs As List(Of SourceMdlPrefab) Public theAnimBlockSizeNoStallOptionIsUsed As Boolean Public theBoneNameToBoneIndexMap As New SortedList(Of String, Integer)() @@ -549,5 +555,6 @@ Public theProceduralBonesCommandIsUsed As Boolean Public theSectionFrameCount As Integer Public theSectionFrameMinFrameCount As Integer + Public isBigEndian As Boolean End Class diff --git a/Crowbar/Core/GameModel/SourceModel49/SourceModel49.vb b/Crowbar/Core/GameModel/SourceModel49/SourceModel49.vb index 437a0791..2e30be86 100644 --- a/Crowbar/Core/GameModel/SourceModel49/SourceModel49.vb +++ b/Crowbar/Core/GameModel/SourceModel49/SourceModel49.vb @@ -472,6 +472,7 @@ Public Class SourceModel49 'Me.theMdlFileData.theModelCommandIsUsed = False Me.theMdlFileData.theProceduralBonesCommandIsUsed = False Me.theMdlFileData.theAnimBlockSizeNoStallOptionIsUsed = False + Me.theMdlFileData.isBigEndian = False mdlFile.ReadMdlHeader00("MDL File Header 00") mdlFile.ReadMdlHeader01("MDL File Header 01") @@ -538,6 +539,12 @@ Public Class SourceModel49 mdlFile.ReadBodygroupPresets() + 'Postal III stuffs + If TheApp.Settings.IsPostal3IsChecked Then + mdlFile.ReadBoltons() + mdlFile.ReadPrefabs() + End If + 'mdlFile.ReadFinalBytesAlignment() 'mdlFile.ReadUnknownValues(Me.theMdlFileData.theFileSeekLog) mdlFile.ReadUnreadBytes() @@ -590,6 +597,8 @@ Public Class SourceModel49 Me.theVtxFileData = New SourceVtxFileData07() End If + Me.theVtxFileData.isBigEndian = False + 'TEST: When a model has a nameCopy, it seems to also use the VTF file strip group topology fields. Dim vtxFile As New SourceVtxFile07(Me.theInputFileReader, Me.theVtxFileData) @@ -684,6 +693,12 @@ Public Class SourceModel49 command = "$keyvalues" End If qcFile.WriteKeyValues(Me.theMdlFileData.theKeyValuesText, command) + + 'Postal III stuffs + If TheApp.Settings.IsPostal3IsChecked Then + qcFile.WriteBoltons() + qcFile.WritePrefabs() + End If Catch ex As Exception Dim debug As Integer = 4242 Finally diff --git a/Crowbar/Core/GameModel/SourceModel49/SourceQcFile49.vb b/Crowbar/Core/GameModel/SourceModel49/SourceQcFile49.vb index fb03d60c..995d05df 100644 --- a/Crowbar/Core/GameModel/SourceModel49/SourceQcFile49.vb +++ b/Crowbar/Core/GameModel/SourceModel49/SourceQcFile49.vb @@ -77,6 +77,10 @@ Public Class SourceQcFile49 Try If File.Exists(qciPathFileName) Then Dim qciFileInfo As New FileInfo(qciPathFileName) + Dim bodyPartIndex As Integer + bodyPartIndex = Me.theMdlFileData.theBodyParts.IndexOf(Me.theBodyPartForFlexWriting) + Dim aBodyPart As SourceMdlBodyPart + aBodyPart = Me.theMdlFileData.theBodyParts(bodyPartIndex) If qciFileInfo.Length > 0 Then Dim line As String = "" @@ -87,6 +91,9 @@ Public Class SourceQcFile49 End If If includeLineIsIndented Then line += vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If End If If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then line += "$Include " @@ -230,7 +237,9 @@ Public Class SourceQcFile49 'Dim aBodyPart As SourceMdlBodyPart Dim bodyPartIndex As Integer Dim aBodyModel As SourceMdlModel + Dim aVtxBodyPart As SourceVtxBodyPart07 Dim eyeballNames As List(Of String) + Dim aVtxModel As SourceVtxModel07 '$model "producer" "producer_model_merged.dmx.smd" { '//-doesn't work eyeball righteye ValveBiped.Bip01_Head1 -1.260 -0.086 64.594 eyeball_r 1.050 3.000 producer_head 0.530 @@ -246,30 +255,101 @@ Public Class SourceQcFile49 bodyPartIndex = Me.theMdlFileData.theBodyParts.IndexOf(aBodyPart) aBodyModel.theSmdFileNames(0) = SourceFileNamesModule.CreateBodyGroupSmdFileName(aBodyModel.theSmdFileNames(0), bodyPartIndex, 0, 0, Me.theModelName, aBodyPart.theModels(0).name) - If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then - line = "$Model " + 'Because Postal III supports multiple bodypart meshes with $model features for each studio mesh + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then + line = "$BodyGroup " + Else + line = "$bodygroup " + End If Else - line = "$model " + If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then + line = "$Model " + Else + line = "$model " + End If End If line += """" line += aBodyPart.theName - line += """ """ - line += aBodyModel.theSmdFileNames(0) - line += """" + 'line += """ """ + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += """" + Me.theOutputFileStreamWriter.WriteLine(line) + line = "{" + Else + line += """ """ + line += aBodyModel.theSmdFileNames(0) + line += """" + + If TheApp.Settings.IsPostal3IsChecked Then + line += " ""#" + line += aBodyModel.theSmdFileNames(0).Substring(0, aBodyModel.theSmdFileNames(0).Length - 4) + line += """" + End If + + line += " {" + End If - line += " {" Me.theOutputFileStreamWriter.WriteLine(line) - 'NOTE: Must call WriteEyeballLines() before WriteEyelidLines(), because eyeballNames are created in first and sent to other. - Me.WriteEyeballLines(aBodyPart, eyeballNames) - Me.WriteEyelidLines(aBodyPart, eyeballNames) + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + If Me.theVtxFileData IsNot Nothing AndAlso Me.theVtxFileData.theVtxBodyParts IsNot Nothing AndAlso Me.theVtxFileData.theVtxBodyParts.Count > 0 Then + aVtxBodyPart = Me.theVtxFileData.theVtxBodyParts(bodyPartIndex) + Else + aVtxBodyPart = Nothing + End If - If bodyPartIndex = 0 Then - Me.WriteMouthLines() - End If + If aBodyPart.theModels IsNot Nothing AndAlso aBodyPart.theModels.Count > 0 Then + For modelIndex As Integer = 0 To aBodyPart.theModels.Count - 1 + aBodyModel = aBodyPart.theModels(modelIndex) + + If aVtxBodyPart IsNot Nothing AndAlso aVtxBodyPart.theVtxModels IsNot Nothing AndAlso aVtxBodyPart.theVtxModels.Count > 0 Then + aVtxModel = aVtxBodyPart.theVtxModels(modelIndex) + Else + aVtxModel = Nothing + End If + + line = vbTab + If aBodyModel.name(0) = ChrW(0) AndAlso (aVtxModel IsNot Nothing AndAlso aVtxModel.theVtxModelLods(0).theVtxMeshes Is Nothing) Then + line += "blank" + Else + aBodyModel.theSmdFileNames(0) = SourceFileNamesModule.CreateBodyGroupSmdFileName(aBodyModel.theSmdFileNames(0), bodyPartIndex, modelIndex, 0, Me.theModelName, aBodyModel.name) + line += "studio " + line += """" + line += aBodyModel.theSmdFileNames(0) + line += """ ""#" + line += aBodyModel.theSmdFileNames(0).Substring(0, aBodyModel.theSmdFileNames(0).Length - 4) + line += """ {" + Me.theOutputFileStreamWriter.WriteLine(line) + + 'NOTE: Must call WriteEyeballLines() before WriteEyelidLines(), because eyeballNames are created in first and sent to other. + Me.WriteEyeballLines(aBodyPart, eyeballNames) + Me.WriteEyelidLines(aBodyPart, eyeballNames) + + If bodyPartIndex = 0 Then + Me.WriteMouthLines(aBodyPart) + End If + + Me.theBodyPartForFlexWriting = aBodyPart + Me.WriteGroup("flex", AddressOf WriteGroupFlex, False, True) + line = vbTab + line += "}" + End If + Me.theOutputFileStreamWriter.WriteLine(line) + Next + End If + Else + 'NOTE: Must call WriteEyeballLines() before WriteEyelidLines(), because eyeballNames are created in first and sent to other. + Me.WriteEyeballLines(aBodyPart, eyeballNames) + Me.WriteEyelidLines(aBodyPart, eyeballNames) - Me.theBodyPartForFlexWriting = aBodyPart - Me.WriteGroup("flex", AddressOf WriteGroupFlex, False, True) + If bodyPartIndex = 0 Then + Me.WriteMouthLines(aBodyPart) + End If + + Me.theBodyPartForFlexWriting = aBodyPart + Me.WriteGroup("flex", AddressOf WriteGroupFlex, False, True) + End If line = "}" Me.theOutputFileStreamWriter.WriteLine(line) @@ -304,8 +384,10 @@ Public Class SourceQcFile49 If aBodyPart.theModels IsNot Nothing AndAlso aBodyPart.theModels.Count > 0 Then aModel = aBodyPart.theModels(0) If aModel.theEyeballs IsNot Nothing AndAlso aModel.theEyeballs.Count > 0 Then - line = "" - Me.theOutputFileStreamWriter.WriteLine(line) + If Not TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line = "" + Me.theOutputFileStreamWriter.WriteLine(line) + End If For eyeballIndex As Integer = 0 To aModel.theEyeballs.Count - 1 anEyeball = aModel.theEyeballs(eyeballIndex) @@ -372,6 +454,9 @@ Public Class SourceQcFile49 End If line = vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += "eyeball """ line += eyeballNames(eyeballIndex) line += """ """ @@ -445,8 +530,10 @@ Public Class SourceQcFile49 If aBodyPart.theModels IsNot Nothing AndAlso aBodyPart.theModels.Count > 0 Then aModel = aBodyPart.theModels(0) If aModel.theEyeballs IsNot Nothing AndAlso aModel.theEyeballs.Count > 0 Then - line = "" - Me.theOutputFileStreamWriter.WriteLine(line) + If Not TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line = "" + Me.theOutputFileStreamWriter.WriteLine(line) + End If 'frameIndex = 0 For eyeballIndex As Integer = 0 To aModel.theEyeballs.Count - 1 @@ -467,6 +554,9 @@ Public Class SourceQcFile49 eyelidName = Me.theMdlFileData.theFlexDescs(anEyeball.upperLidFlexDesc).theName line = vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += "eyelid " line += eyelidName 'line += " """ @@ -545,6 +635,9 @@ Public Class SourceQcFile49 eyelidName = Me.theMdlFileData.theFlexDescs(anEyeball.lowerLidFlexDesc).theName line = vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += "eyelid " line += eyelidName 'line += " """ @@ -636,7 +729,7 @@ Public Class SourceQcFile49 End If End Function - Private Sub WriteMouthLines() + Private Sub WriteMouthLines(ByVal aBodyPart As SourceMdlBodyPart) Dim line As String = "" Dim offsetX As Double Dim offsetY As Double @@ -644,8 +737,10 @@ Public Class SourceQcFile49 'NOTE: Writes out mouth line correctly for teenangst zoey. If Me.theMdlFileData.theMouths IsNot Nothing AndAlso Me.theMdlFileData.theMouths.Count > 0 Then - line = "" - Me.theOutputFileStreamWriter.WriteLine(line) + If Not TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line = "" + Me.theOutputFileStreamWriter.WriteLine(line) + End If For i As Integer = 0 To Me.theMdlFileData.theMouths.Count - 1 Dim aMouth As SourceMdlMouth @@ -655,6 +750,9 @@ Public Class SourceQcFile49 offsetZ = Math.Round(aMouth.forward.z, 3) line = vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += "mouth " line += i.ToString(TheApp.InternalNumberFormat) line += " """ @@ -691,11 +789,16 @@ Public Class SourceQcFile49 'If Me.theBodyPartForFlexWriting.theFlexFrames IsNot Nothing AndAlso Me.theBodyPartForFlexWriting.theFlexFrames.Count > 1 Then Dim bodyPartIndex As Integer bodyPartIndex = Me.theMdlFileData.theBodyParts.IndexOf(Me.theBodyPartForFlexWriting) + Dim aBodyPart As SourceMdlBodyPart + aBodyPart = Me.theMdlFileData.theBodyParts(bodyPartIndex) line = "" Me.theOutputFileStreamWriter.WriteLine(line) line = vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += "flexfile" 'line += Path.GetFileNameWithoutExtension(CStr(Me.theSourceEngineModel.theMdlFileHeader.theBodyParts(0).theModels(0).name).Trim(Chr(0))) 'line += ".vta""" @@ -705,12 +808,18 @@ Public Class SourceQcFile49 Me.theOutputFileStreamWriter.WriteLine(line) line = vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += "{" Me.theOutputFileStreamWriter.WriteLine(line) '====== line = vbTab line += vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += "defaultflex frame 0" Me.theOutputFileStreamWriter.WriteLine(line) @@ -722,6 +831,9 @@ Public Class SourceQcFile49 aFlexFrame = Me.theBodyPartForFlexWriting.theFlexFrames(frameIndex) line = vbTab line += vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If If Me.theMdlFileData.theFlexDescs(aFlexFrame.flexes(0).flexDescIndex).theDescIsUsedByEyelid Then line += "// Already in eyelid lines: " End If @@ -821,6 +933,9 @@ Public Class SourceQcFile49 'Next line = vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += "}" Me.theOutputFileStreamWriter.WriteLine(line) 'End If @@ -833,6 +948,10 @@ Public Class SourceQcFile49 Dim aFlexController As SourceMdlFlexController Dim flexControllerNames As New List(Of String)() Dim commentOperatorText As String + Dim bodyPartIndex As Integer + bodyPartIndex = Me.theMdlFileData.theBodyParts.IndexOf(Me.theBodyPartForFlexWriting) + Dim aBodyPart As SourceMdlBodyPart + aBodyPart = Me.theMdlFileData.theBodyParts(bodyPartIndex) line = "" Me.theOutputFileStreamWriter.WriteLine(line) @@ -842,6 +961,9 @@ Public Class SourceQcFile49 If flexControllerNames.Contains(aFlexController.theName) Then line = vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += "// Although in the original model, the line below is a duplicate of a line above and is commented-out to avoid problems in Source Filmmaker (and possibly other tools)." Me.theOutputFileStreamWriter.WriteLine(line) commentOperatorText = "//" @@ -857,6 +979,9 @@ Public Class SourceQcFile49 End If line = vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += commentOperatorText line += "flexcontroller " line += aFlexController.theType @@ -878,6 +1003,10 @@ Public Class SourceQcFile49 If Me.theMdlFileData.theFlexRules IsNot Nothing AndAlso Me.theMdlFileData.theFlexRules.Count > 0 Then Dim aFlexRule As SourceMdlFlexRule + Dim bodyPartIndex As Integer + bodyPartIndex = Me.theMdlFileData.theBodyParts.IndexOf(Me.theBodyPartForFlexWriting) + Dim aBodyPart As SourceMdlBodyPart + aBodyPart = Me.theMdlFileData.theBodyParts(bodyPartIndex) line = "" Me.theOutputFileStreamWriter.WriteLine(line) @@ -888,6 +1017,9 @@ Public Class SourceQcFile49 If Not flexDesc.theDescIsUsedByFlex AndAlso flexDesc.theDescIsUsedByFlexRule Then line = vbTab + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line += vbTab + End If line += "localvar " line += flexDesc.theName Me.theOutputFileStreamWriter.WriteLine(line) @@ -897,7 +1029,13 @@ Public Class SourceQcFile49 For i As Integer = 0 To Me.theMdlFileData.theFlexRules.Count - 1 aFlexRule = Me.theMdlFileData.theFlexRules(i) 'line = Me.GetFlexRule(aFlexRule) - line = Common.GetFlexRule(Me.theMdlFileData.theFlexDescs, Me.theMdlFileData.theFlexControllers, aFlexRule) + If TheApp.Settings.IsPostal3IsChecked AndAlso aBodyPart.modelCount > 1 Then + line = vbTab + line += Common.GetFlexRule(Me.theMdlFileData.theFlexDescs, Me.theMdlFileData.theFlexControllers, aFlexRule) + Else + line = Common.GetFlexRule(Me.theMdlFileData.theFlexDescs, Me.theMdlFileData.theFlexControllers, aFlexRule) + End If + Me.theOutputFileStreamWriter.WriteLine(line) Next End If @@ -4828,11 +4966,21 @@ Public Class SourceQcFile49 If aBodyModel.name(0) = ChrW(0) AndAlso (aVtxModel IsNot Nothing AndAlso aVtxModel.theVtxModelLods(0).theVtxMeshes Is Nothing) Then line += "blank" Else - aBodyModel.theSmdFileNames(0) = SourceFileNamesModule.CreateBodyGroupSmdFileName(aBodyModel.theSmdFileNames(0), bodyPartIndex, modelIndex, 0, Me.theModelName, aBodyModel.name) - line += "studio " - line += """" - line += aBodyModel.theSmdFileNames(0) - line += """" + If TheApp.Settings.IsPostal3IsChecked Then + aBodyModel.theSmdFileNames(0) = SourceFileNamesModule.CreateBodyGroupSmdFileName(aBodyModel.theSmdFileNames(0), bodyPartIndex, modelIndex, 0, Me.theModelName, aBodyModel.name) + line += "studio " + line += """" + line += aBodyModel.theSmdFileNames(0) + line += """ ""#" + line += aBodyModel.theSmdFileNames(0).Substring(0, aBodyModel.theSmdFileNames(0).Length - 4) + line += """" + Else + aBodyModel.theSmdFileNames(0) = SourceFileNamesModule.CreateBodyGroupSmdFileName(aBodyModel.theSmdFileNames(0), bodyPartIndex, modelIndex, 0, Me.theModelName, aBodyModel.name) + line += "studio " + line += """" + line += aBodyModel.theSmdFileNames(0) + line += """" + End If End If Me.theOutputFileStreamWriter.WriteLine(line) Next @@ -5051,6 +5199,81 @@ Public Class SourceQcFile49 End Try End Sub + Public Sub WriteBoltons() + Dim line As String = "" + + Try + If Me.theMdlFileData.numBoltons > 0 Then + Dim aBolton As SourceMdlBolton + Dim m_BoltonType As BoltonType + + For i As Integer = 0 To Me.theMdlFileData.numBoltons - 1 + aBolton = Me.theMdlFileData.theBoltons(i) + + line = "$bolton ""Bolton" + i.ToString() + line += """ """ + + m_BoltonType = CType(aBolton.type, BoltonType) + line += m_BoltonType.ToString() + line += """ """ + line += aBolton.theModelName + line += """" + + Me.theOutputFileStreamWriter.WriteLine(line) + Next + End If + Catch ex As Exception + + End Try + End Sub + + Public Sub WritePrefabs() + Dim line As String = "" + + Try + If Me.theMdlFileData.numPrefabs > 0 Then + Dim aPrefab As SourceMdlPrefab + + For i As Integer = 0 To Me.theMdlFileData.numPrefabs - 1 + aPrefab = Me.theMdlFileData.thePrefabs(i) + + line = "$prefab """ + line += aPrefab.theName + line += """ """ + line += "#Skin" + aPrefab.skin.ToString() + line += """" + + For j As Integer = 0 To Me.theMdlFileData.numBoltons - 1 + Dim bits As Integer + bits = 1 << j + + If (bits And aPrefab.boltonsmask) = bits Then + line += " ""Bolton" + j.ToString() + line += """" + End If + Next + + For j As Integer = 0 To Me.theMdlFileData.bodyPartCount - 1 + Dim aBodyPart As SourceMdlBodyPart + aBodyPart = Me.theMdlFileData.theBodyParts(j) + Dim aModel As SourceMdlModel + aModel = aBodyPart.theModels(aPrefab.theBodyParts(j)) + Dim bodyPartName As String + If Not aModel.theSmdFileNames(0) = "" Then + bodyPartName = aModel.theSmdFileNames(0).Substring(0, aModel.theSmdFileNames(0).Length - 4) + line += " ""#" + bodyPartName + line += """" + End If + Next + + Me.theOutputFileStreamWriter.WriteLine(line) + Next + End If + Catch ex As Exception + + End Try + End Sub + Private Sub WriteTextLines(ByVal text As String, ByVal indentCount As Integer) Dim line As String = "" Dim textChar As Char diff --git a/Crowbar/Core/GameModel/SourceModel49/SourceSmdFile49.vb b/Crowbar/Core/GameModel/SourceModel49/SourceSmdFile49.vb index 0395f2e4..04942430 100644 --- a/Crowbar/Core/GameModel/SourceModel49/SourceSmdFile49.vb +++ b/Crowbar/Core/GameModel/SourceModel49/SourceSmdFile49.vb @@ -290,93 +290,95 @@ Public Class SourceSmdFile49 Try If Me.thePhyFileData.theSourcePhyCollisionDatas IsNot Nothing Then - Me.ProcessTransformsForPhysics() + If Me.theMdlFileData.localAnimationCount > 0 Then + Me.ProcessTransformsForPhysics() + End If For collisionDataIndex As Integer = 0 To Me.thePhyFileData.theSourcePhyCollisionDatas.Count - 1 - collisionData = Me.thePhyFileData.theSourcePhyCollisionDatas(collisionDataIndex) + collisionData = Me.thePhyFileData.theSourcePhyCollisionDatas(collisionDataIndex) - If collisionDataIndex < Me.thePhyFileData.theSourcePhyPhysCollisionModels.Count Then - aSourcePhysCollisionModel = Me.thePhyFileData.theSourcePhyPhysCollisionModels(collisionDataIndex) - Else - aSourcePhysCollisionModel = Nothing - End If + If collisionDataIndex < Me.thePhyFileData.theSourcePhyPhysCollisionModels.Count Then + aSourcePhysCollisionModel = Me.thePhyFileData.theSourcePhyPhysCollisionModels(collisionDataIndex) + Else + aSourcePhysCollisionModel = Nothing + End If - For convexMeshIndex As Integer = 0 To collisionData.theConvexMeshes.Count - 1 - convexMesh = collisionData.theConvexMeshes(convexMeshIndex) + For convexMeshIndex As Integer = 0 To collisionData.theConvexMeshes.Count - 1 + convexMesh = collisionData.theConvexMeshes(convexMeshIndex) ' [12-Apr-2022] From RED_EYE. (He is using someone else's set of data strutures for PHY file.) ' flags: has_children: (self.flags >> 0) & 3 ' 0 = false; > 0 true ' This seems to be correct way rather than checking Me.thePhyFileData.theSourcePhyIsCollisionModel. ' Example where checking Me.thePhyFileData.theSourcePhyIsCollisionModel is incorrect (because the gib meshes are compiled in): ' "SourceFilmmaker\game\hl2\models\combine_strider.mdl" - If (convexMesh.flags And 3) > 0 Then + If Not Me.thePhyFileData.isBigEndian AndAlso (convexMesh.flags And 3) > 0 Then Continue For End If If Me.theMdlFileData.theBones.Count = 1 Then - boneIndex = 0 - Else - boneIndex = convexMesh.theBoneIndex - ' MDL36 and MDL37 need this because their PHY does not store bone index. - ' Model versions above MDL37 can have multiple bones with same name, so this check needs to be last. - If boneIndex < 0 Then - If aSourcePhysCollisionModel IsNot Nothing AndAlso Me.theMdlFileData.theBoneNameToBoneIndexMap.ContainsKey(aSourcePhysCollisionModel.theName) Then - boneIndex = Me.theMdlFileData.theBoneNameToBoneIndexMap(aSourcePhysCollisionModel.theName) - Else - ' Not expected to reach here, but just in case, write a mesh connected to first bone instead of writing an empty mesh. - boneIndex = 0 + boneIndex = 0 + Else + boneIndex = convexMesh.theBoneIndex + ' MDL36 and MDL37 need this because their PHY does not store bone index. + ' Model versions above MDL37 can have multiple bones with same name, so this check needs to be last. + If boneIndex < 0 Then + If aSourcePhysCollisionModel IsNot Nothing AndAlso Me.theMdlFileData.theBoneNameToBoneIndexMap.ContainsKey(aSourcePhysCollisionModel.theName) Then + boneIndex = Me.theMdlFileData.theBoneNameToBoneIndexMap(aSourcePhysCollisionModel.theName) + Else + ' Not expected to reach here, but just in case, write a mesh connected to first bone instead of writing an empty mesh. + boneIndex = 0 + End If End If End If - End If - aBone = Me.theMdlFileData.theBones(boneIndex) + aBone = Me.theMdlFileData.theBones(boneIndex) - For triangleIndex As Integer = 0 To convexMesh.theFaces.Count - 1 - aTriangle = convexMesh.theFaces(triangleIndex) - - line = " phy" - Me.theOutputFileStreamWriter.WriteLine(line) - - ' 19 -0.000009 0.000001 0.999953 0.0 0.0 0.0 1 0 - ' 19 -0.000005 1.000002 -0.000043 0.0 0.0 0.0 1 0 - ' 19 -0.008333 0.997005 1.003710 0.0 0.0 0.0 1 0 - For vertexIndex As Integer = 0 To aTriangle.vertexIndex.Length - 1 - 'phyVertex = collisionData.theVertices(aTriangle.vertexIndex(vertexIndex)) - phyVertex = convexMesh.theVertices(aTriangle.vertexIndex(vertexIndex)) - - aVectorTransformed = Me.TransformPhyVertex(aBone, phyVertex.vertex, aSourcePhysCollisionModel) - - ''DEBUG: Move different face sections away from each other. - 'aVectorTransformed.x += faceSectionIndex * 20 - 'aVectorTransformed.y += faceSectionIndex * 20 - - line = " " - line += boneIndex.ToString(TheApp.InternalNumberFormat) - line += " " - line += aVectorTransformed.x.ToString("0.000000", TheApp.InternalNumberFormat) - line += " " - line += aVectorTransformed.y.ToString("0.000000", TheApp.InternalNumberFormat) - line += " " - line += aVectorTransformed.z.ToString("0.000000", TheApp.InternalNumberFormat) - - 'line += " 0 0 0" - '------ - line += " " - line += phyVertex.Normal.x.ToString("0.000000", TheApp.InternalNumberFormat) - line += " " - line += phyVertex.Normal.y.ToString("0.000000", TheApp.InternalNumberFormat) - line += " " - line += phyVertex.Normal.z.ToString("0.000000", TheApp.InternalNumberFormat) - - line += " 0 0" - 'NOTE: The studiomdl.exe doesn't need the integer values at end. - 'line += " 1 0" + For triangleIndex As Integer = 0 To convexMesh.theFaces.Count - 1 + aTriangle = convexMesh.theFaces(triangleIndex) + + line = " phy" Me.theOutputFileStreamWriter.WriteLine(line) + + ' 19 -0.000009 0.000001 0.999953 0.0 0.0 0.0 1 0 + ' 19 -0.000005 1.000002 -0.000043 0.0 0.0 0.0 1 0 + ' 19 -0.008333 0.997005 1.003710 0.0 0.0 0.0 1 0 + For vertexIndex As Integer = 0 To aTriangle.vertexIndex.Length - 1 + 'phyVertex = collisionData.theVertices(aTriangle.vertexIndex(vertexIndex)) + phyVertex = convexMesh.theVertices(aTriangle.vertexIndex(vertexIndex)) + + aVectorTransformed = Me.TransformPhyVertex(aBone, phyVertex.vertex, aSourcePhysCollisionModel) + + ''DEBUG: Move different face sections away from each other. + 'aVectorTransformed.x += faceSectionIndex * 20 + 'aVectorTransformed.y += faceSectionIndex * 20 + + line = " " + line += boneIndex.ToString(TheApp.InternalNumberFormat) + line += " " + line += aVectorTransformed.x.ToString("0.000000", TheApp.InternalNumberFormat) + line += " " + line += aVectorTransformed.y.ToString("0.000000", TheApp.InternalNumberFormat) + line += " " + line += aVectorTransformed.z.ToString("0.000000", TheApp.InternalNumberFormat) + + 'line += " 0 0 0" + '------ + line += " " + line += phyVertex.Normal.x.ToString("0.000000", TheApp.InternalNumberFormat) + line += " " + line += phyVertex.Normal.y.ToString("0.000000", TheApp.InternalNumberFormat) + line += " " + line += phyVertex.Normal.z.ToString("0.000000", TheApp.InternalNumberFormat) + + line += " 0 0" + 'NOTE: The studiomdl.exe doesn't need the integer values at end. + 'line += " 1 0" + Me.theOutputFileStreamWriter.WriteLine(line) + Next Next Next Next - Next - End If - Catch ex As Exception + End If + Catch ex As Exception Dim debug As Integer = 4242 End Try diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index 49ab8387..85d73535 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -20,6 +20,21 @@ 2.0 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true true @@ -127,6 +142,8 @@ + + @@ -1010,6 +1027,13 @@ + + + False + .NET Framework 3.5 SP1 + false + +