@@ -19,9 +19,25 @@ public class Frame
1919
2020 private struct FrameBoneRotation
2121 {
22- public FrameBoneRotation ( int x , int y , int z , int w )
22+ public FrameBoneRotation ( GameType game , int x , int y , int z , int w )
2323 {
24- this . rotation = new Quaternion ( x / 32767f , y / 32767f , z / 32767f , w / 32767f ) ;
24+ if ( game . num == 4 )
25+ {
26+ this . rotation = new Quaternion ( ParseDlFloat ( x ) , ParseDlFloat ( y ) , ParseDlFloat ( z ) , - ParseDlFloat ( w ) ) ;
27+ }
28+ else
29+ {
30+ this . rotation = new Quaternion ( x / 32767f , y / 32767f , z / 32767f , - w / 32767f ) ;
31+ }
32+ }
33+
34+ private float ParseDlFloat ( int v )
35+ {
36+ int vpos = v & 0x7fff ;
37+ if ( v < 0 )
38+ return vpos / - 32767f ;
39+
40+ return vpos / 32767f ;
2541 }
2642
2743 public Quaternion rotation ;
@@ -115,7 +131,9 @@ public bool GetScalingUnk(int bone)
115131
116132 if ( exists )
117133 {
118- return translations . First ( t => t . bone == bone ) . translation ;
134+ // dl can have multiple translations per bone
135+ // doesn't seem to break the other rac games
136+ return translations . Where ( t => t . bone == bone ) . Select ( x => x . translation ) . Aggregate ( ( a , b ) => a + b ) ;
119137 }
120138
121139 return null ;
@@ -210,7 +228,7 @@ public Frame(FileStream fs, GameType game, int offset, int boneCount)
210228 int y = ReadShort ( frameBlock , i * 8 + 0x02 ) ;
211229 int z = ReadShort ( frameBlock , i * 8 + 0x04 ) ;
212230 int w = ReadShort ( frameBlock , i * 8 + 0x06 ) ;
213- rotations . Add ( new FrameBoneRotation ( x , y , z , - w ) ) ;
231+ rotations . Add ( new FrameBoneRotation ( game , x , y , z , w ) ) ;
214232 }
215233
216234 scalings = new List < FrameBoneScaling > ( ) ;
@@ -249,13 +267,6 @@ public Frame(FileStream fs, GameType game, int offset, int boneCount)
249267 // Constructor for Deadlocked
250268 public Frame ( byte [ ] frameBlock , int offset , int numRotations , int numScalings , int numTranslations )
251269 {
252- // This code is not correct and is causing crashes.
253- // TODO: (Milch) Implement support for Deadlocked animations.
254- #if true
255- rotations = new List < FrameBoneRotation > ( ) ;
256- scalings = new List < FrameBoneScaling > ( ) ;
257- translations = new List < FrameBoneTranslation > ( ) ;
258- #else
259270 int rotationOffset = 0 ;
260271 rotations = new List < FrameBoneRotation > ( ) ;
261272 for ( int i = 0 ; i < numRotations ; i ++ )
@@ -265,16 +276,16 @@ public Frame(byte[] frameBlock, int offset, int numRotations, int numScalings, i
265276 int y = ReadShort ( frameBlock , offset + i * 8 + 0x02 ) ;
266277 int z = ReadShort ( frameBlock , offset + i * 8 + 0x04 ) ;
267278 int w = ReadShort ( frameBlock , offset + i * 8 + 0x06 ) ;
268- rotations . Add ( new FrameBoneRotation ( x , y , z , - w ) ) ;
279+ rotations . Add ( new FrameBoneRotation ( GameType . DL , x , y , z , w ) ) ;
269280 }
270281
271282 int scalingOffset = rotationOffset + numRotations * 0x08 ;
272283 scalings = new List < FrameBoneScaling > ( ) ;
273284 for ( int i = 0 ; i < numScalings ; i ++ )
274285 {
275- float x = ReadShort ( frameBlock , offset + scalingOffset + i * 8 + 0x00 ) / 32767 .0f;
276- float y = ReadShort ( frameBlock , offset + scalingOffset + i * 8 + 0x02 ) / 32767 .0f;
277- float z = ReadShort ( frameBlock , offset + scalingOffset + i * 8 + 0x04 ) / 32767 .0f;
286+ float x = ReadShort ( frameBlock , offset + scalingOffset + i * 8 + 0x00 ) / 4096 .0f;
287+ float y = ReadShort ( frameBlock , offset + scalingOffset + i * 8 + 0x02 ) / 4096 .0f;
288+ float z = ReadShort ( frameBlock , offset + scalingOffset + i * 8 + 0x04 ) / 4096 .0f;
278289 byte unk = frameBlock [ offset + scalingOffset + i * 8 + 0x06 ] ;
279290 byte bone = frameBlock [ offset + scalingOffset + i * 8 + 0x07 ] ;
280291 scalings . Add ( new FrameBoneScaling ( x , y , z , bone , unk ) ) ;
@@ -284,14 +295,13 @@ public Frame(byte[] frameBlock, int offset, int numRotations, int numScalings, i
284295 translations = new List < FrameBoneTranslation > ( ) ;
285296 for ( int i = 0 ; i < numTranslations ; i ++ )
286297 {
287- float x = ReadShort ( frameBlock , offset + translationOffset + i * 8 + 0x00 ) / 32767 .0f;
288- float y = ReadShort ( frameBlock , offset + translationOffset + i * 8 + 0x02 ) / 32767 .0f;
289- float z = ReadShort ( frameBlock , offset + translationOffset + i * 8 + 0x04 ) / 32767 .0f;
298+ float x = ReadShort ( frameBlock , offset + translationOffset + i * 8 + 0x00 ) / 1024 .0f;
299+ float y = ReadShort ( frameBlock , offset + translationOffset + i * 8 + 0x02 ) / 1024 .0f;
300+ float z = ReadShort ( frameBlock , offset + translationOffset + i * 8 + 0x04 ) / 1024 .0f;
290301 byte unk = frameBlock [ offset + translationOffset + i * 8 + 0x06 ] ;
291302 byte bone = frameBlock [ offset + translationOffset + i * 8 + 0x07 ] ;
292303 translations . Add ( new FrameBoneTranslation ( x , y , z , bone , unk ) ) ;
293304 }
294- #endif
295305 }
296306
297307 public byte [ ] Serialize ( )
0 commit comments