11using System . IO ;
2+ using InventorySystem . Items ;
23using PlayerRoles ;
34
45namespace Causality0 . Core ;
@@ -16,7 +17,7 @@ public static void Save(string path)
1617 using FileStream fs = new FileStream ( path , FileMode . Create , FileAccess . Write , FileShare . None ) ;
1718 using BinaryWriter w = new BinaryWriter ( fs ) ;
1819 w . Write ( "CAUS" ) ;
19- w . Write ( ( byte ) 9 ) ;
20+ w . Write ( ( byte ) 13 ) ;
2021 w . Write ( Timeline . MapSeed ) ;
2122 w . Write ( Timeline . CurrentFps ) ;
2223 w . Write ( Timeline . Tracks . Count ) ;
@@ -25,6 +26,7 @@ public static void Save(string path)
2526 w . Write ( t . PlayerId ) ;
2627 w . Write ( t . ActorName ?? string . Empty ) ;
2728 w . Write ( t . Role ) ;
29+ w . Write ( t . StartFrame ) ;
2830 w . Write ( t . Frames . Count ) ;
2931 for ( int i = 0 ; i < t . Frames . Count ; i ++ )
3032 {
@@ -102,6 +104,116 @@ public static void Save(string path)
102104 w . Write ( x . Act ) ;
103105 w . Write ( x . CanOpen ) ;
104106 }
107+
108+ w . Write ( Timeline . HasWorldState ) ;
109+ if ( Timeline . HasWorldState )
110+ {
111+ w . Write ( Timeline . WorldPickups . Count ) ;
112+ for ( int i = 0 ; i < Timeline . WorldPickups . Count ; i ++ )
113+ {
114+ PickupData x = Timeline . WorldPickups [ i ] ;
115+ w . Write ( x . Id ) ;
116+ w . Write ( x . T ) ;
117+ w . Write ( x . Pos . x ) ;
118+ w . Write ( x . Pos . y ) ;
119+ w . Write ( x . Pos . z ) ;
120+ w . Write ( x . Rot . x ) ;
121+ w . Write ( x . Rot . y ) ;
122+ w . Write ( x . Rot . z ) ;
123+ w . Write ( x . Rot . w ) ;
124+ w . Write ( x . At ) ;
125+ w . Write ( x . Am ) ;
126+ w . Write ( x . Locked ) ;
127+ }
128+
129+ w . Write ( Timeline . PickupOps . Count ) ;
130+ for ( int i = 0 ; i < Timeline . PickupOps . Count ; i ++ )
131+ {
132+ PickupOp x = Timeline . PickupOps [ i ] ;
133+ w . Write ( x . Ts ) ;
134+ w . Write ( ( byte ) x . Act ) ;
135+ w . Write ( x . Id ) ;
136+ if ( x . Act != PickupAct . Remove )
137+ {
138+ PickupData pd = x . Data ;
139+ w . Write ( pd . Id ) ;
140+ w . Write ( pd . T ) ;
141+ w . Write ( pd . Pos . x ) ;
142+ w . Write ( pd . Pos . y ) ;
143+ w . Write ( pd . Pos . z ) ;
144+ w . Write ( pd . Rot . x ) ;
145+ w . Write ( pd . Rot . y ) ;
146+ w . Write ( pd . Rot . z ) ;
147+ w . Write ( pd . Rot . w ) ;
148+ w . Write ( pd . At ) ;
149+ w . Write ( pd . Am ) ;
150+ w . Write ( pd . Locked ) ;
151+ }
152+ }
153+
154+ w . Write ( Timeline . LockerStates . Count ) ;
155+ for ( int i = 0 ; i < Timeline . LockerStates . Count ; i ++ )
156+ {
157+ LockerData x = Timeline . LockerStates [ i ] ;
158+ w . Write ( x . Pos . x ) ;
159+ w . Write ( x . Pos . y ) ;
160+ w . Write ( x . Pos . z ) ;
161+ w . Write ( x . Id ) ;
162+ w . Write ( x . Open ) ;
163+ w . Write ( x . WasOpen ) ;
164+ w . Write ( x . Items . Count ) ;
165+ for ( int j = 0 ; j < x . Items . Count ; j ++ )
166+ {
167+ PickupData pd = x . Items [ j ] ;
168+ w . Write ( pd . Id ) ;
169+ w . Write ( pd . T ) ;
170+ w . Write ( pd . Pos . x ) ;
171+ w . Write ( pd . Pos . y ) ;
172+ w . Write ( pd . Pos . z ) ;
173+ w . Write ( pd . Rot . x ) ;
174+ w . Write ( pd . Rot . y ) ;
175+ w . Write ( pd . Rot . z ) ;
176+ w . Write ( pd . Rot . w ) ;
177+ w . Write ( pd . At ) ;
178+ w . Write ( pd . Am ) ;
179+ w . Write ( pd . Locked ) ;
180+ }
181+ }
182+
183+ w . Write ( Timeline . LockerOps . Count ) ;
184+ for ( int i = 0 ; i < Timeline . LockerOps . Count ; i ++ )
185+ {
186+ LockerOp x = Timeline . LockerOps [ i ] ;
187+ w . Write ( x . Ts ) ;
188+ w . Write ( x . Pos . x ) ;
189+ w . Write ( x . Pos . y ) ;
190+ w . Write ( x . Pos . z ) ;
191+ w . Write ( x . Id ) ;
192+ w . Write ( x . Open ) ;
193+ w . Write ( x . CanOpen ) ;
194+ }
195+ }
196+
197+ w . Write ( Timeline . ProjTracks . Count ) ;
198+ for ( int i = 0 ; i < Timeline . ProjTracks . Count ; i ++ )
199+ {
200+ ProjectileTrack x = Timeline . ProjTracks [ i ] ;
201+ w . Write ( ( ushort ) x . ProjectileType ) ;
202+ w . Write ( x . StartFrame ) ;
203+ w . Write ( x . OwnerId ) ;
204+ w . Write ( x . Frames . Count ) ;
205+ for ( int j = 0 ; j < x . Frames . Count ; j ++ )
206+ {
207+ ProjectileFrame f = x . Frames [ j ] ;
208+ w . Write ( f . Pos . x ) ;
209+ w . Write ( f . Pos . y ) ;
210+ w . Write ( f . Pos . z ) ;
211+ w . Write ( f . Rot . x ) ;
212+ w . Write ( f . Rot . y ) ;
213+ w . Write ( f . Rot . z ) ;
214+ w . Write ( f . Rot . w ) ;
215+ }
216+ }
105217 }
106218
107219 public static bool Load ( string path )
@@ -138,7 +250,8 @@ public static bool Load(string path)
138250 {
139251 PlayerId = r . ReadInt32 ( ) ,
140252 ActorName = r . ReadString ( ) ,
141- Role = r . ReadSByte ( )
253+ Role = r . ReadSByte ( ) ,
254+ StartFrame = v >= 10 ? r . ReadInt32 ( ) : 0
142255 } ;
143256 int m = r . ReadInt32 ( ) ;
144257 for ( int j = 0 ; j < m ; j ++ )
@@ -224,6 +337,82 @@ public static bool Load(string path)
224337 }
225338 }
226339
340+ if ( v >= 11 )
341+ {
342+ Timeline . HasWorldState = r . ReadBoolean ( ) ;
343+ if ( Timeline . HasWorldState )
344+ {
345+ int c = r . ReadInt32 ( ) ;
346+ for ( int i = 0 ; i < c ; i ++ )
347+ {
348+ Timeline . WorldPickups . Add ( new PickupData ( r . ReadInt32 ( ) , ( ItemType ) r . ReadUInt16 ( ) , new UnityEngine . Vector3 ( r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) ) , new UnityEngine . Quaternion ( r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) ) , r . ReadUInt32 ( ) , r . ReadUInt16 ( ) , r . ReadBoolean ( ) ) ) ;
349+ }
350+
351+ c = r . ReadInt32 ( ) ;
352+ for ( int i = 0 ; i < c ; i ++ )
353+ {
354+ float ts = r . ReadSingle ( ) ;
355+ PickupAct a = ( PickupAct ) r . ReadByte ( ) ;
356+ int id = r . ReadInt32 ( ) ;
357+ if ( a != PickupAct . Remove )
358+ {
359+ PickupData d = new PickupData ( r . ReadInt32 ( ) , ( ItemType ) r . ReadUInt16 ( ) , new UnityEngine . Vector3 ( r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) ) , new UnityEngine . Quaternion ( r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) ) , r . ReadUInt32 ( ) , r . ReadUInt16 ( ) , r . ReadBoolean ( ) ) ;
360+ Timeline . PickupOps . Add ( new PickupOp ( ts , a , id , d ) ) ;
361+ }
362+ else
363+ {
364+ Timeline . PickupOps . Add ( PickupOp . NewRemove ( ts , id ) ) ;
365+ }
366+ }
367+
368+ c = r . ReadInt32 ( ) ;
369+ for ( int i = 0 ; i < c ; i ++ )
370+ {
371+ LockerData x = new LockerData
372+ {
373+ Pos = new UnityEngine . Vector3 ( r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) ) ,
374+ Id = r . ReadByte ( ) ,
375+ Open = r . ReadBoolean ( ) ,
376+ WasOpen = r . ReadBoolean ( )
377+ } ;
378+ int n2 = r . ReadInt32 ( ) ;
379+ for ( int j = 0 ; j < n2 ; j ++ )
380+ {
381+ x . Items . Add ( new PickupData ( r . ReadInt32 ( ) , ( ItemType ) r . ReadUInt16 ( ) , new UnityEngine . Vector3 ( r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) ) , new UnityEngine . Quaternion ( r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) ) , r . ReadUInt32 ( ) , r . ReadUInt16 ( ) , r . ReadBoolean ( ) ) ) ;
382+ }
383+
384+ Timeline . LockerStates . Add ( x ) ;
385+ }
386+
387+ c = r . ReadInt32 ( ) ;
388+ for ( int i = 0 ; i < c ; i ++ )
389+ {
390+ Timeline . LockerOps . Add ( new LockerOp ( r . ReadSingle ( ) , new UnityEngine . Vector3 ( r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) ) , r . ReadByte ( ) , r . ReadBoolean ( ) , r . ReadBoolean ( ) ) ) ;
391+ }
392+ }
393+ }
394+
395+ if ( v >= 12 )
396+ {
397+ int c = r . ReadInt32 ( ) ;
398+ for ( int i = 0 ; i < c ; i ++ )
399+ {
400+ ProjectileTrack x = new ProjectileTrack
401+ {
402+ ProjectileType = ( ItemType ) r . ReadUInt16 ( ) ,
403+ StartFrame = r . ReadInt32 ( ) ,
404+ OwnerId = r . ReadInt32 ( )
405+ } ;
406+ int n2 = r . ReadInt32 ( ) ;
407+ for ( int j = 0 ; j < n2 ; j ++ )
408+ {
409+ x . Frames . Add ( new ProjectileFrame ( new UnityEngine . Vector3 ( r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) ) , new UnityEngine . Quaternion ( r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) , r . ReadSingle ( ) ) ) ) ;
410+ }
411+
412+ Timeline . ProjTracks . Add ( x ) ;
413+ }
414+ }
415+
227416 return true ;
228417 }
229418}
0 commit comments