Skip to content

Commit 0aceade

Browse files
authored
Fix BatchParsing path (SubnauticaNitrox#1196)
* Fix GameObject FullName & Batch location * Updated AssetTools * review changes
1 parent f8cecaf commit 0aceade

8 files changed

Lines changed: 74 additions & 49 deletions

File tree

Nitrox.Bootloader/Main.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class Main
1212
{
1313
// Get path from command args.
1414
string[] args = Environment.GetCommandLineArgs();
15-
for (var i = 0; i < args.Length - 1; i++)
15+
for (int i = 0; i < args.Length - 1; i++)
1616
{
1717
if (args[i].Equals("-nitrox", StringComparison.OrdinalIgnoreCase) && Directory.Exists(args[i + 1]))
1818
{
@@ -116,4 +116,4 @@ private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEve
116116
return Assembly.LoadFile(dllPath);
117117
}
118118
}
119-
}
119+
}

NitroxClient/Communication/Packets/Processors/PingRenamedProcessor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NitroxClient.Communication.Abstract;
33
using NitroxClient.Communication.Packets.Processors.Abstract;
44
using NitroxClient.MonoBehaviours;
5+
using NitroxClient.Unity.Helper;
56
using NitroxModel.DataStructures.Util;
67
using NitroxModel.Logger;
78
using NitroxModel.Packets;

NitroxClient/GameLogic/Helper/VehicleChildObjectIdentifierHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using NitroxClient.MonoBehaviours;
4+
using NitroxClient.Unity.Helper;
45
using NitroxModel.DataStructures;
56
using NitroxModel.DataStructures.GameLogic;
67
using NitroxModel.Logger;

NitroxClient/Unity/Helper/GameObjectHelper.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Text;
34
using NitroxModel.Helper;
45
using UnityEngine;
@@ -36,7 +37,7 @@ public static Transform RequireTransform(this Transform tf, string name)
3637
{
3738
Transform child = tf.Find(name);
3839

39-
if (child == null)
40+
if (!child)
4041
{
4142
throw new ArgumentNullException(tf + " does not contain \"" + name + "\"");
4243
}
@@ -104,13 +105,36 @@ public static string GetHierarchyPath(this Component component)
104105
private static string GetHierarchyPathBuilder(this GameObject obj, StringBuilder builder)
105106
{
106107
Transform parent = obj.transform;
108+
107109
while (parent)
108110
{
109111
builder.Insert(0, parent.name);
110112
builder.Insert(0, "/");
111113
parent = parent.transform.parent;
112114
}
115+
113116
return builder.ToString();
114117
}
118+
119+
public static string GetFullName(this GameObject obj)
120+
{
121+
Stack<string> stack = new Stack<string>();
122+
Transform transform = obj.transform;
123+
124+
while (transform)
125+
{
126+
stack.Push(transform.name);
127+
transform = transform.parent;
128+
}
129+
130+
StringBuilder stringBuilder = new StringBuilder();
131+
132+
while (stack.Count > 0)
133+
{
134+
stringBuilder.AppendFormat("/{0}", stack.Pop());
135+
}
136+
137+
return stringBuilder.ToString();
138+
}
115139
}
116140
}

NitroxServer-Subnautica/NitroxServer-Subnautica.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</PropertyGroup>
3333
<ItemGroup>
3434
<Reference Include="AssetsTools.NET, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
35-
<HintPath>..\packages\AssetsTools.NET.2.0.2\lib\net35\AssetsTools.NET.dll</HintPath>
35+
<HintPath>..\packages\AssetsTools.NET.2.0.4\lib\net35\AssetsTools.NET.dll</HintPath>
3636
</Reference>
3737
<Reference Include="Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
3838
<SpecificVersion>False</SpecificVersion>

NitroxServer-Subnautica/Serialization/Resources/ResourceAssetsParser.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using AssetsTools.NET;
5-
using NitroxModel.DataStructures.Util;
65
using NitroxModel.Discovery;
7-
using NitroxModel.Logger;
86
using NitroxServer_Subnautica.Serialization.Resources.Parsers;
97
using NitroxServer_Subnautica.Serialization.Resources.Processing;
108
using NitroxServer.Serialization.Resources.Datastructures;
@@ -13,15 +11,15 @@ namespace NitroxServer_Subnautica.Serialization.Resources
1311
{
1412
public static class ResourceAssetsParser
1513
{
16-
private static Dictionary<AssetIdentifier, uint> assetIdentifierToClassId = new Dictionary<AssetIdentifier, uint>();
14+
private static readonly Dictionary<AssetIdentifier, uint> assetIdentifierToClassId = new Dictionary<AssetIdentifier, uint>();
1715

18-
private static Dictionary<string, int> fileIdByResourcePath = new Dictionary<string, int>();
19-
private static HashSet<string> parsedManifests = new HashSet<string>();
16+
private static readonly Dictionary<string, int> fileIdByResourcePath = new Dictionary<string, int>();
17+
private static readonly HashSet<string> parsedManifests = new HashSet<string>();
2018

21-
private static PrefabPlaceholderExtractor prefabPlaceholderExtractor = new PrefabPlaceholderExtractor();
19+
private static readonly PrefabPlaceholderExtractor prefabPlaceholderExtractor = new PrefabPlaceholderExtractor();
2220

2321
// https://docs.huihoo.com/unity/4.3/Documentation/Manual/ClassIDReference.html
24-
private static Dictionary<uint, AssetParser> assetParsersByClassId = new Dictionary<uint, AssetParser>()
22+
private static readonly Dictionary<uint, AssetParser> assetParsersByClassId = new Dictionary<uint, AssetParser>()
2523
{
2624
{ 1, new GameObjectAssetParser()},
2725
{ 4, new TransformAssetParser()},

NitroxServer-Subnautica/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="AssetsTools.NET" version="2.0.2" targetFramework="net40" />
3+
<package id="AssetsTools.NET" version="2.0.4" targetFramework="net40" />
44
<package id="Autofac" version="3.5.2" targetFramework="net40" />
55
<package id="Autofac.Configuration" version="3.3.0" targetFramework="net40" />
66
<package id="Mono.Cecil" version="0.11.2" targetFramework="net40" />

NitroxServer/Serialization/BatchCellsParser.cs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)