Skip to content

Commit

Permalink
Merge pull request #11 from IJARika/pre-merger
Browse files Browse the repository at this point in the history
Pre merger
  • Loading branch information
IJARika authored Sep 13, 2022
2 parents 506766d + 713e2b8 commit b43a044
Show file tree
Hide file tree
Showing 19 changed files with 1,174 additions and 1,345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Public Class SourceMdlAnimation
Public Const STUDIO_ANIM_DELTA As Integer = &H10
Public Const STUDIO_ANIM_RAWROT2 As Integer = &H20

'MDL 53 values for flags:
Public Const STUDIO_ANIM_RAWPOS_53 As Integer = &H2
Public Const STUDIO_ANIM_RAWROT_53 As Integer = &H4
Public Const STUDIO_ANIM_RAWSCALE_53 As Integer = &H8
Public Const STUDIO_ANIM_UNKFLAG_53 As Integer = &H10


' Do not use union, because it will have to rely on size of a .NET Framework data type.
'<StructLayout(LayoutKind.Explicit)> _
Expand Down
18 changes: 18 additions & 0 deletions Crowbar/Core/GameModel/SourceGlobal/SourceQuaternion64bits.vb
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,22 @@ Public Class SourceQuaternion64bits
<FieldOffset(0)> Public s As Single
End Structure

Public ReadOnly Property XOffset() As UInt16
Get
Return BitConverter.ToUInt16(Me.theBytes, 0)
End Get
End Property

Public ReadOnly Property YOffset() As UInt16
Get
Return BitConverter.ToUInt16(Me.theBytes, 2)
End Get
End Property

Public ReadOnly Property ZOffset() As UInt16
Get
Return BitConverter.ToUInt16(Me.theBytes, 4)
End Get
End Property

End Class
69 changes: 59 additions & 10 deletions Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb
Original file line number Diff line number Diff line change
Expand Up @@ -319,22 +319,39 @@ Public Class SourceMdlFile52
Me.theMdlFileData.boneFlexDriverCount = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.boneFlexDriverOffset = Me.theInputFileReader.ReadInt32()

Me.theMdlFileData.unknownOffset01 = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.unknown01 = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.unknown02 = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.unknown03 = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.unknownOffset02 = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.perTriCollisionOffset = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.perTriCount1 = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.perTriCount2 = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.perTriCount3 = Me.theInputFileReader.ReadInt32()

Me.theMdlFileData.unkStringOffset = Me.theInputFileReader.ReadInt32()

'NOTE: In V52 the subheader is 208 bytes instead of 256.

'For x As Integer = 0 To Me.theMdlFileData.reserved.Length - 1
' Me.theMdlFileData.reserved(x) = Me.theInputFileReader.ReadInt32()
'Next
For x As Integer = 0 To Me.theMdlFileData.reserved.Length - 1
Me.theMdlFileData.reserved(x) = Me.theInputFileReader.ReadInt32()
Next

fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1
Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, logDescription)
End Sub

' TODO: write to .txt (maybe), get log formatting better, remove null characters when present.
Public Sub ReadMayaStrings()
If Me.theMdlFileData.mayaOffset > 0 And Me.theMdlFileData.mayaOffset < Me.theMdlFileData.boneOffset Then
Dim fileOffsetStart As Long
Dim fileOffsetEnd As Long

Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.mayaOffset, SeekOrigin.Begin)
fileOffsetStart = Me.theInputFileReader.BaseStream.Position

theMdlFileData.theMayaStrings = Me.theInputFileReader.ReadChars(Me.theMdlFileData.boneOffset - Me.theMdlFileData.mayaOffset)

fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1
Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "theMdlFileData.theMayaStrings " + theMdlFileData.theMayaStrings)
End If
End Sub

Public Sub ReadBones()
If Me.theMdlFileData.boneCount > 0 Then
Dim boneInputFileStreamPosition As Long
Expand Down Expand Up @@ -394,10 +411,12 @@ Public Class SourceMdlFile52
aBone.rotation.x = Me.theInputFileReader.ReadSingle()
aBone.rotation.y = Me.theInputFileReader.ReadSingle()
aBone.rotation.z = Me.theInputFileReader.ReadSingle()

aBone.positionScale = New SourceVector()
aBone.positionScale.x = Me.theInputFileReader.ReadSingle()
aBone.positionScale.y = Me.theInputFileReader.ReadSingle()
aBone.positionScale.z = Me.theInputFileReader.ReadSingle()

aBone.rotationScale = New SourceVector()
aBone.rotationScale.x = Me.theInputFileReader.ReadSingle()
aBone.rotationScale.y = Me.theInputFileReader.ReadSingle()
Expand Down Expand Up @@ -459,8 +478,6 @@ Public Class SourceMdlFile52
aBone.contents = Me.theInputFileReader.ReadInt32()
aBone.surfacepropLookup = Me.theInputFileReader.ReadInt32()

'If Me.theMdlFileData.version <> 2531 Then

aBone.unkVector = New SourceVector()
aBone.unkVector.x = Me.theInputFileReader.ReadSingle()
aBone.unkVector.y = Me.theInputFileReader.ReadSingle()
Expand Down Expand Up @@ -995,6 +1012,8 @@ Public Class SourceMdlFile52

anAnimationDesc.ikRuleZeroFrameOffset = Me.theInputFileReader.ReadInt32()

anAnimationDesc.compressedIkErrorOffset = Me.theInputFileReader.ReadInt32()

For x As Integer = 0 To anAnimationDesc.unused1.Length - 1
anAnimationDesc.unused1(x) = Me.theInputFileReader.ReadInt32()
Next
Expand Down Expand Up @@ -4217,6 +4236,36 @@ Public Class SourceMdlFile52
End If
End Sub

' This just reads the bytes for now, will implement reading the mesh at a later date once it's understood.
Public Sub ReadPerTriCollisionHeader()
Dim fileOffsetStart As Long
Dim fileOffsetEnd As Long

Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.studioHeader2Offset + Me.theMdlFileData.perTriCollisionOffset, SeekOrigin.Begin)
fileOffsetStart = Me.theInputFileReader.BaseStream.Position

Dim theDetailedCollision As New RSourcePerTriCollisionHeader52

theDetailedCollision.version = Me.theInputFileReader.ReadInt32()

theDetailedCollision.bbMin = New SourceVector()
theDetailedCollision.bbMin.x = Me.theInputFileReader.ReadSingle()
theDetailedCollision.bbMin.y = Me.theInputFileReader.ReadSingle()
theDetailedCollision.bbMin.z = Me.theInputFileReader.ReadSingle()

theDetailedCollision.bbMax = New SourceVector()
theDetailedCollision.bbMax.x = Me.theInputFileReader.ReadSingle()
theDetailedCollision.bbMax.y = Me.theInputFileReader.ReadSingle()
theDetailedCollision.bbMax.z = Me.theInputFileReader.ReadSingle()

For k As Integer = 0 To 7
theDetailedCollision.unused(k) = Me.theInputFileReader.ReadInt32()
Next

fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1
Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "theMdlFileData.theDetailedCollision")
End Sub

'Public Sub ReadFinalBytesAlignment()
' Me.theMdlFileData.theFileSeekLog.LogAndAlignFromFileSeekLogEnd(Me.theInputFileReader, 4, "Final bytes alignment")
'End Sub
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Public Class RSourcePerTriCollisionHeader52

'struct pertriheader_t
'{
' int version; // unsure If this Is an actual version Or type
' // set to '2' for static prop.
'
' // aabb sizes, same as hulls
' Vector3 bbmin;
' Vector3 bbmax;
'
' int unused[8]; // hopefully, checks out With other mdl structs
'};

' 2 for static props, 0 for everything else, unknown if 1 is used.
Public version As Integer

' Size of AABB
Public bbMin As SourceVector
Public bbMax As SourceVector

Public unused(7) As Integer

End Class
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ Public Class SourceMdlAnimationDesc52
' mstudioikrulezeroframe_t *pIKRuleZeroFrame( int i ) const { if (ikrulezeroframeindex) return (mstudioikrulezeroframe_t *)(((byte *)this) + ikrulezeroframeindex) + i; else return NULL; };
Public ikRuleZeroFrameOffset As Integer

Public compressedIkErrorOffset As Integer

' int unused1[5]; // remove as appropriate (and zero if loading older versions)
Public unused1(4) As Integer
Public unused1(3) As Integer

' int animblock;
Public animBlock As Integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,21 +547,16 @@
Public boneFlexDriverCount As Integer
Public boneFlexDriverOffset As Integer

' Both V52 and V53 have this section.
' Related to some block that appears when linear bone data is not present.
Public unknownOffset01 As Integer
Public unknown01 As Integer
Public unknown02 As Integer
Public unknown03 As Integer
' Points to byte just before string table.
Public unknownOffset02 As Integer
' High detail collision mesh for static props.
Public perTriCollisionOffset As Integer
Public perTriCount1 As Integer
Public perTriCount2 As Integer
Public perTriCount3 As Integer

'NOTE: Just skip reading these bytes, because it unknown if any are used.
'NOTE: These are unused in V52 as far as I can tell.
'Public reserved(56) As Integer
'======
'Public studiohdr2(63) As Integer
' When used the string is normally "Titan", only observed on models for animation.
Public unkStringOffset As Integer

Public reserved(38) As Integer


'Public theID As String
Expand Down Expand Up @@ -594,6 +589,8 @@
Public theSurfacePropName As String
Public theTexturePaths As List(Of String)
Public theTextures As List(Of SourceMdlTexture)
Public theMayaStrings As String
Public theDetailedCollision As RSourcePerTriCollisionHeader52

Public theSectionFrameCount As Integer
Public theSectionFrameMinFrameCount As Integer
Expand Down
4 changes: 4 additions & 0 deletions Crowbar/Core/GameModel/SourceModel52/SourceModel52.vb
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ Public Class SourceModel52
mdlFile.ReadMdlHeader02("MDL File Header 02")
End If

mdlFile.ReadMayaStrings()

mdlFile.ReadBones()
mdlFile.ReadBoneControllers()
mdlFile.ReadAttachments()
Expand Down Expand Up @@ -395,6 +397,8 @@ Public Class SourceModel52
mdlFile.ReadBoneTransforms()
mdlFile.ReadLinearBoneTable()

mdlFile.ReadPerTriCollisionHeader()

'TODO: ReadLocalIkAutoPlayLocks()
mdlFile.ReadFlexControllerUis()

Expand Down
Loading

0 comments on commit b43a044

Please sign in to comment.