@@ -39,22 +39,82 @@ public Collision(FileStream fs, int collisionPointer)
3939 // RaC 1 title screen has no collision
4040 if ( collisionPointer == 0 ) return ;
4141
42- float div = 1024f ;
42+ byte [ ] headBlock = ReadBlock ( fs , collisionPointer , 0x08 ) ;
43+ int standardCollisionStart = ReadInt ( headBlock , 0x00 ) ;
44+ int heroCollisionStart = ReadInt ( headBlock , 0x04 ) ;
4345
46+ var vertexList = new List < float > ( ) ;
47+ var indexList = new List < uint > ( ) ;
48+ var colorList = new List < uint > ( ) ;
4449 uint totalVertexCount = 0 ;
4550
46- byte [ ] headBlock = ReadBlock ( fs , collisionPointer , 0x08 ) ;
47- int collisionStart = collisionPointer + ReadInt ( headBlock , 0x00 ) ;
48- int collisionLength = ReadInt ( headBlock , 0x04 ) ;
49- if ( collisionLength == 0 )
51+ if ( standardCollisionStart > 0 )
5052 {
51- collisionLength = ( int ) fs . Length - collisionStart ;
53+ int start = collisionPointer + standardCollisionStart ;
54+ int length ;
55+
56+ if ( heroCollisionStart > 0 )
57+ length = heroCollisionStart - standardCollisionStart ;
58+ else
59+ length = ( int ) fs . Length - start ;
60+
61+ byte [ ] data = ReadBlock ( fs , start , length ) ;
62+ ParseStandardCollision ( data , vertexList , indexList , ref totalVertexCount ) ;
5263 }
53- byte [ ] collision = ReadBlock ( fs , collisionStart , collisionLength ) ;
5464
55- var vertexList = new List < float > ( ) ;
56- var indexList = new List < uint > ( ) ;
57- var colorList = new List < uint > ( ) ;
65+ if ( heroCollisionStart > 0 )
66+ {
67+ int start = collisionPointer + heroCollisionStart ;
68+ int length = ( int ) fs . Length - start ;
69+
70+ byte [ ] data = ReadBlock ( fs , start , length ) ;
71+ ParseHeroCollision ( data , vertexList , indexList , ref totalVertexCount ) ;
72+ }
73+
74+ vertexBuffer = vertexList . ToArray ( ) ;
75+ indBuff = indexList . ToArray ( ) ;
76+ }
77+
78+ private void ParseHeroCollision ( byte [ ] hero , List < float > vertexList , List < uint > indexList , ref uint totalVertexCount )
79+ {
80+ int groupCount = ReadInt ( hero , 0x00 ) ;
81+
82+ for ( int i = 0 ; i < groupCount ; i ++ )
83+ {
84+ int entryOffset = 0x10 + ( i * 16 ) ;
85+
86+ ushort triCount = ReadUshort ( hero , entryOffset + 8 ) ;
87+ ushort vertCount = ReadUshort ( hero , entryOffset + 10 ) ;
88+ int dataOffset = ( int ) ReadUint ( hero , entryOffset + 12 ) ;
89+
90+ // Wrench has hero collision as blue, so I figured I'll just... use that color as well...
91+ FloatColor fc = new FloatColor { r = 0 , g = 0 , b = 255 , a = 255 } ;
92+
93+ for ( int v = 0 ; v < vertCount ; v ++ )
94+ {
95+ int vOff = dataOffset + ( v * 8 ) ;
96+ vertexList . Add ( ReadUshort ( hero , vOff + 0 ) / 64.0f ) ;
97+ vertexList . Add ( ReadUshort ( hero , vOff + 2 ) / 64.0f ) ;
98+ vertexList . Add ( ReadUshort ( hero , vOff + 4 ) / 64.0f ) ;
99+ vertexList . Add ( fc . value ) ;
100+ }
101+
102+ int triBase = dataOffset + ( vertCount * 8 ) ;
103+ for ( int t = 0 ; t < triCount ; t ++ )
104+ {
105+ int tOff = triBase + ( t * 4 ) ;
106+ indexList . Add ( totalVertexCount + hero [ tOff + 1 ] ) ;
107+ indexList . Add ( totalVertexCount + hero [ tOff + 0 ] ) ;
108+ indexList . Add ( totalVertexCount + hero [ tOff + 2 ] ) ;
109+ }
110+
111+ totalVertexCount += vertCount ;
112+ }
113+ }
114+
115+ private void ParseStandardCollision ( byte [ ] collision , List < float > vertexList , List < uint > indexList , ref uint totalVertexCount )
116+ {
117+ float div = 1024f ;
58118
59119 ushort zShift = ReadUshort ( collision , 0 ) ;
60120 ushort zCount = ReadUshort ( collision , 2 ) ;
@@ -152,8 +212,6 @@ public Collision(FileStream fs, int collisionPointer)
152212 }
153213 }
154214 }
155- vertexBuffer = vertexList . ToArray ( ) ;
156- indBuff = indexList . ToArray ( ) ;
157215 }
158216 }
159217}
0 commit comments