@@ -21,20 +21,23 @@ namespace NitroxServer.Serialization
2121 * This class consolidates the gameObject, entitySlot, and cellHeader data to
2222 * create EntitySpawnPoint objects.
2323 */
24- class BatchCellsParser
24+ public class BatchCellsParser
2525 {
2626 private readonly EntitySpawnPointFactory entitySpawnPointFactory ;
2727 private readonly ServerProtoBufSerializer serializer ;
28- private readonly Dictionary < string , Type > surrogateTypes = new Dictionary < string , Type > ( ) ;
28+ private readonly Dictionary < string , Type > surrogateTypes ;
2929
3030 public BatchCellsParser ( EntitySpawnPointFactory entitySpawnPointFactory , ServerProtoBufSerializer serializer )
3131 {
3232 this . entitySpawnPointFactory = entitySpawnPointFactory ;
3333 this . serializer = serializer ;
3434
35- surrogateTypes . Add ( "UnityEngine.Transform" , typeof ( NitroxTransform ) ) ;
36- surrogateTypes . Add ( "UnityEngine.Vector3" , typeof ( NitroxVector3 ) ) ;
37- surrogateTypes . Add ( "UnityEngine.Quaternion" , typeof ( NitroxQuaternion ) ) ;
35+ surrogateTypes = new Dictionary < string , Type >
36+ {
37+ { "UnityEngine.Transform" , typeof ( NitroxTransform ) } ,
38+ { "UnityEngine.Vector3" , typeof ( NitroxVector3 ) } ,
39+ { "UnityEngine.Quaternion" , typeof ( NitroxQuaternion ) }
40+ } ;
3841 }
3942
4043 public List < EntitySpawnPoint > ParseBatchData ( Int3 batchId )
@@ -53,12 +56,12 @@ public void ParseFile(Int3 batchId, string pathPrefix, string prefix, string suf
5356
5457 if ( subnauticaPath == null )
5558 {
56- Log . Info ( $ "Could not locate Subnautica installation directory: { Environment . NewLine } { string . Join ( Environment . NewLine , errors ) } ") ;
59+ Log . Error ( $ "Could not locate Subnautica installation directory: { Environment . NewLine } { string . Join ( Environment . NewLine , errors ) } ") ;
5760 return ;
5861 }
5962
60- string path = Path . Combine ( subnauticaPath , "SNUnmanagedData" , "Build18" ) ;
61- string fileName = Path . Combine ( path , pathPrefix , prefix + " batch-cells-" + batchId . X + "-" + batchId . Y + "-" + batchId . Z + suffix + " .bin") ;
63+ string path = Path . Combine ( subnauticaPath , "Subnautica_Data" , "StreamingAssets" , " SNUnmanagedData", "Build18" ) ;
64+ string fileName = Path . Combine ( path , pathPrefix , $ " { prefix } batch-cells-{ batchId . X } - { batchId . Y } - { batchId . Z } { suffix } .bin") ;
6265
6366 if ( ! File . Exists ( fileName ) )
6467 {
@@ -79,25 +82,25 @@ private void ParseCacheCells(Int3 batchId, string fileName, List<EntitySpawnPoin
7982 {
8083 CellsFileHeader cellsFileHeader = serializer . Deserialize < CellsFileHeader > ( stream ) ;
8184
82- for ( int cellCounter = 0 ; cellCounter < cellsFileHeader . numCells ; cellCounter ++ )
85+ for ( int cellCounter = 0 ; cellCounter < cellsFileHeader . NumCells ; cellCounter ++ )
8386 {
8487 CellHeaderEx cellHeader = serializer . Deserialize < CellHeaderEx > ( stream ) ;
8588
8689 bool wasLegacy ;
8790
88- byte [ ] serialData = new byte [ cellHeader . dataLength ] ;
89- stream . Read ( serialData , 0 , cellHeader . dataLength ) ;
90- ParseGameObjectsWithHeader ( serialData , batchId , cellHeader . cellId , cellHeader . level , spawnPoints , out wasLegacy ) ;
91+ byte [ ] serialData = new byte [ cellHeader . DataLength ] ;
92+ stream . Read ( serialData , 0 , cellHeader . DataLength ) ;
93+ ParseGameObjectsWithHeader ( serialData , batchId , cellHeader . CellId , cellHeader . Level , spawnPoints , out wasLegacy ) ;
9194
9295 if ( ! wasLegacy )
9396 {
94- byte [ ] legacyData = new byte [ cellHeader . legacyDataLength ] ;
95- stream . Read ( legacyData , 0 , cellHeader . legacyDataLength ) ;
96- ParseGameObjectsWithHeader ( legacyData , batchId , cellHeader . cellId , cellHeader . level , spawnPoints , out wasLegacy ) ;
97+ byte [ ] legacyData = new byte [ cellHeader . LegacyDataLength ] ;
98+ stream . Read ( legacyData , 0 , cellHeader . LegacyDataLength ) ;
99+ ParseGameObjectsWithHeader ( legacyData , batchId , cellHeader . CellId , cellHeader . Level , spawnPoints , out wasLegacy ) ;
97100
98- byte [ ] waiterData = new byte [ cellHeader . waiterDataLength ] ;
99- stream . Read ( waiterData , 0 , cellHeader . waiterDataLength ) ;
100- ParseGameObjectsFromStream ( new MemoryStream ( waiterData ) , batchId , cellHeader . cellId , cellHeader . level , spawnPoints ) ;
101+ byte [ ] waiterData = new byte [ cellHeader . WaiterDataLength ] ;
102+ stream . Read ( waiterData , 0 , cellHeader . WaiterDataLength ) ;
103+ ParseGameObjectsFromStream ( new MemoryStream ( waiterData ) , batchId , cellHeader . CellId , cellHeader . Level , spawnPoints ) ;
101104 }
102105 }
103106 }
@@ -164,9 +167,7 @@ private void DeserializeComponents(Stream stream, GameObject gameObject)
164167 {
165168 ComponentHeader componentHeader = serializer . Deserialize < ComponentHeader > ( stream ) ;
166169
167- Type type = null ;
168-
169- if ( ! surrogateTypes . TryGetValue ( componentHeader . TypeName , out type ) )
170+ if ( ! surrogateTypes . TryGetValue ( componentHeader . TypeName , out Type type ) )
170171 {
171172 type = AppDomain . CurrentDomain . GetAssemblies ( )
172173 . Select ( a => a . GetType ( componentHeader . TypeName ) )
@@ -188,29 +189,29 @@ public class CellsFileHeader
188189 {
189190 public override string ToString ( )
190191 {
191- return string . Format ( "(version={0}, numCells={1})" , version , numCells ) ;
192+ return string . Format ( "(version={0}, numCells={1})" , Version , NumCells ) ;
192193 }
193194
194195 [ ProtoMember ( 1 ) ]
195- public int version ;
196+ public int Version ;
196197
197198 [ ProtoMember ( 2 ) ]
198- public int numCells ;
199+ public int NumCells ;
199200 }
200201
201202 [ ProtoContract ]
202203 public class CellHeader
203204 {
204205 public override string ToString ( )
205206 {
206- return $ "(cellId={ cellId } , level={ level } )";
207+ return $ "(cellId={ CellId } , level={ Level } )";
207208 }
208209
209210 [ ProtoMember ( 1 ) ]
210- public Int3 cellId ;
211+ public Int3 CellId ;
211212
212213 [ ProtoMember ( 2 ) ]
213- public int level ;
214+ public int Level ;
214215 }
215216
216217 [ ProtoContract ]
@@ -220,28 +221,28 @@ public override string ToString()
220221 {
221222 return string . Format ( "(cellId={0}, level={1}, dataLength={2}, legacyDataLength={3}, waiterDataLength={4})" , new object [ ]
222223 {
223- cellId ,
224- level ,
225- dataLength ,
226- legacyDataLength ,
227- waiterDataLength
224+ CellId ,
225+ Level ,
226+ DataLength ,
227+ LegacyDataLength ,
228+ WaiterDataLength
228229 } ) ;
229230 }
230231
231232 [ ProtoMember ( 1 ) ]
232- public Int3 cellId ;
233+ public Int3 CellId ;
233234
234235 [ ProtoMember ( 2 ) ]
235- public int level ;
236+ public int Level ;
236237
237238 [ ProtoMember ( 3 ) ]
238- public int dataLength ;
239+ public int DataLength ;
239240
240241 [ ProtoMember ( 4 ) ]
241- public int legacyDataLength ;
242+ public int LegacyDataLength ;
242243
243244 [ ProtoMember ( 5 ) ]
244- public int waiterDataLength ;
245+ public int WaiterDataLength ;
245246 }
246247
247248 [ ProtoContract ]
0 commit comments