diff --git a/SavegameToolkit/ArkSavegame.cs b/SavegameToolkit/ArkSavegame.cs index 4468545..073192c 100644 --- a/SavegameToolkit/ArkSavegame.cs +++ b/SavegameToolkit/ArkSavegame.cs @@ -1,15 +1,19 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using SavegameToolkit.Arrays; using SavegameToolkit.Propertys; +using SavegameToolkit.Structs; using SavegameToolkit.Types; -namespace SavegameToolkit { +namespace SavegameToolkit +{ - public class ArkSavegame : GameObjectContainerMixin, IConversionSupport { + public class ArkSavegame : GameObjectContainerMixin, IConversionSupport + { [JsonProperty(Order = 0)] public short SaveVersion { get; private set; } @@ -72,10 +76,12 @@ public class ArkSavegame : GameObjectContainerMixin, IConversionSupport { #region readBinary - public void ReadBinary(ArkArchive archive, ReadingOptions options) { + public void ReadBinary(ArkArchive archive, ReadingOptions options) + { readBinaryHeader(archive); - if (SaveVersion > 5) { + if (SaveVersion > 5) + { // Name table is located after the objects block, but will be needed to read the objects block readBinaryNameTable(archive); } @@ -86,20 +92,22 @@ public void ReadBinary(ArkArchive archive, ReadingOptions options) { readBinaryObjects(archive, options); readBinaryObjectProperties(archive, options); - if (SaveVersion > 6) { + if (SaveVersion > 6) + { readBinaryHibernation(archive, options); } - - - //Now parse out cryo creature data + // Now parse cryo creature data foreach (var cryo in this.Objects.Where(x => x.ClassName.ToString().Contains("Cryop")).ToList()) { - - var contents = ((((((((Structs.StructPropertyList)((cryo.Properties[4] as Propertys.PropertyArray).Value as Arrays.ArkArrayStruct)[0]).Properties[6] as Propertys.PropertyStruct) - .Value as Structs.StructPropertyList).Properties[0] as Propertys.PropertyArray).Value as Arrays.ArkArrayStruct)[0] as Structs.StructPropertyList).Properties[0] as Propertys.PropertyArray).Value as Arrays.ArkArrayUInt8; + StructPropertyList customData = cryo.GetPropertyValue("CustomItemDatas")?.FirstOrDefault() as StructPropertyList; + PropertyStruct customDataBytes = customData?.Properties.FirstOrDefault(p => p.NameString == "CustomDataBytes") as PropertyStruct; + PropertyArray byteArrays = (customDataBytes?.Value as StructPropertyList)?.Properties.FirstOrDefault(property => property.NameString == "ByteArrays") as PropertyArray; + ArkArrayStruct byteArraysValue = byteArrays?.Value as ArkArrayStruct; + ArkArrayUInt8 creatureBytes = ((byteArraysValue?[0] as StructPropertyList)?.Properties.FirstOrDefault(p => p.NameString == "Bytes") as PropertyArray)?.Value as ArkArrayUInt8; + if (creatureBytes == null) continue; - var cryoStream = new System.IO.MemoryStream(contents.ToArray()); + var cryoStream = new System.IO.MemoryStream(creatureBytes.ToArray()); using (ArkArchive cryoArchive = new ArkArchive(cryoStream)) { @@ -116,37 +124,43 @@ public void ReadBinary(ArkArchive archive, ReadingOptions options) { //hack the id's so that the dino points to the appropriate dinostatuscomponent var statusComponentRef = dino.GetTypedProperty("MyCharacterStatusComponent"); statusComponentRef.Value.ObjectId = statusobject.Id; - } - } - - OldNameList = archive.HasUnknownNames? archive.NameTable: null; + OldNameList = archive.HasUnknownNames ? archive.NameTable : null; HasUnknownData = archive.HasUnknownData; } - private void readBinaryHeader(ArkArchive archive) { + private void readBinaryHeader(ArkArchive archive) + { SaveVersion = archive.ReadShort(); - if (SaveVersion < 5 || SaveVersion > 9) { + if (SaveVersion < 5 || SaveVersion > 9) + { throw new NotSupportedException("Found unknown Version " + SaveVersion); } - if (SaveVersion > 6) { + if (SaveVersion > 6) + { hibernationOffset = archive.ReadInt(); int shouldBeZero = archive.ReadInt(); - if (shouldBeZero != 0) { - throw new NotSupportedException("The stuff at this position should be zero: " + (archive.Position- 4).ToString("X4")); + if (shouldBeZero != 0) + { + throw new NotSupportedException("The stuff at this position should be zero: " + (archive.Position - 4).ToString("X4")); } - } else { + } + else + { hibernationOffset = 0; } - if (SaveVersion > 5) { + if (SaveVersion > 5) + { nameTableOffset = archive.ReadInt(); propertiesBlockOffset = archive.ReadInt(); - } else { + } + else + { nameTableOffset = 0; propertiesBlockOffset = 0; } @@ -156,14 +170,16 @@ private void readBinaryHeader(ArkArchive archive) { SaveCount = SaveVersion > 8 ? archive.ReadInt() : 0; } - private void readBinaryNameTable(ArkArchive archive) { + private void readBinaryNameTable(ArkArchive archive) + { long position = archive.Position; archive.Position = nameTableOffset; int nameCount = archive.ReadInt(); List nameTable = new List(nameCount); - for (int n = 0; n < nameCount; n++) { + for (int n = 0; n < nameCount; n++) + { nameTable.Add(archive.ReadString()); } @@ -172,85 +188,113 @@ private void readBinaryNameTable(ArkArchive archive) { archive.Position = position; } - private void readBinaryDataFiles(ArkArchive archive, ReadingOptions options) { + private void readBinaryDataFiles(ArkArchive archive, ReadingOptions options) + { int count = archive.ReadInt(); DataFiles.Clear(); - if (options.DataFiles) { - for (int n = 0; n < count; n++) { + if (options.DataFiles) + { + for (int n = 0; n < count; n++) + { DataFiles.Add(archive.ReadString()); } - } else { + } + else + { archive.HasUnknownData = true; - for (int n = 0; n < count; n++) { + for (int n = 0; n < count; n++) + { archive.SkipString(); } } } - private void readBinaryEmbeddedData(ArkArchive archive, ReadingOptions options) { + private void readBinaryEmbeddedData(ArkArchive archive, ReadingOptions options) + { int count = archive.ReadInt(); EmbeddedData.Clear(); - if (options.EmbeddedData) { - for (int n = 0; n < count; n++) { + if (options.EmbeddedData) + { + for (int n = 0; n < count; n++) + { EmbeddedData.Add(new EmbeddedData(archive)); } - } else { + } + else + { archive.HasUnknownData = true; - for (int n = 0; n < count; n++) { + for (int n = 0; n < count; n++) + { Types.EmbeddedData.Skip(archive); } } } - private void readBinaryDataFilesObjectMap(ArkArchive archive, ReadingOptions options) { + private void readBinaryDataFilesObjectMap(ArkArchive archive, ReadingOptions options) + { DataFilesObjectMap.Clear(); - if (options.DataFilesObjectMap) { + if (options.DataFilesObjectMap) + { int dataFilesCount = archive.ReadInt(); - for (int n = 0; n < dataFilesCount; n++) { + for (int n = 0; n < dataFilesCount; n++) + { int level = archive.ReadInt(); int count = archive.ReadInt(); string[] names = new string[count]; - for (int index = 0; index < count; index++) { + for (int index = 0; index < count; index++) + { names[index] = archive.ReadString(); } - if (!DataFilesObjectMap.ContainsKey(level) || DataFilesObjectMap[level] == null) { + if (!DataFilesObjectMap.ContainsKey(level) || DataFilesObjectMap[level] == null) + { DataFilesObjectMap.Add(level, new List { names }); } } - } else { + } + else + { archive.HasUnknownData = true; int count = archive.ReadInt(); - for (int entry = 0; entry < count; entry++) { + for (int entry = 0; entry < count; entry++) + { archive.SkipBytes(4); int stringCount = archive.ReadInt(); - for (int stringIndex = 0; stringIndex < stringCount; stringIndex++) { + for (int stringIndex = 0; stringIndex < stringCount; stringIndex++) + { archive.SkipString(); } } } } - private void readBinaryObjects(ArkArchive archive, ReadingOptions options) { - if (options.GameObjects) { + private void readBinaryObjects(ArkArchive archive, ReadingOptions options) + { + if (options.GameObjects) + { int count = archive.ReadInt(); - + Objects.Clear(); ObjectMap.Clear(); - while (count-- > 0) { + while (count-- > 0) + { addObject(new GameObject(archive), options.BuildComponentTree); } - } else { + } + else + { archive.HasUnknownData = true; archive.HasUnknownNames = true; } } - private void readBinaryObjectProperties(ArkArchive archive, ReadingOptions options) { - if (options.GameObjects && options.GameObjectProperties) { + private void readBinaryObjectProperties(ArkArchive archive, ReadingOptions options) + { + if (options.GameObjects && options.GameObjectProperties) + { //if (options.isParallel()) { // ParallelQuery parallelQuery = Enumerable.Range(0, Objects.Count).AsParallel(); @@ -261,32 +305,39 @@ private void readBinaryObjectProperties(ArkArchive archive, ReadingOptions optio // parallelQuery.ForAll(n => readBinaryObjectPropertiesImpl(n, archive.Clone())); //} else { - IEnumerable stream = Enumerable.Range(0, Objects.Count); + IEnumerable stream = Enumerable.Range(0, Objects.Count); - if (options.ObjectFilter != null) { - stream = stream.Where(n => options.ObjectFilter(Objects[n])); - } + if (options.ObjectFilter != null) + { + stream = stream.Where(n => options.ObjectFilter(Objects[n])); + } - foreach (int n in stream) - readBinaryObjectPropertiesImpl(n, archive); + foreach (int n in stream) + readBinaryObjectPropertiesImpl(n, archive); //} - if (options.ObjectFilter != null) { + if (options.ObjectFilter != null) + { archive.HasUnknownData = true; archive.HasUnknownNames = true; } - } else { + } + else + { archive.HasUnknownData = true; archive.HasUnknownNames = true; } } - private void readBinaryObjectPropertiesImpl(int n, ArkArchive archive) { + private void readBinaryObjectPropertiesImpl(int n, ArkArchive archive) + { Objects[n].LoadProperties(archive, (n < Objects.Count - 1) ? Objects[n + 1] : null, propertiesBlockOffset); } - private void readBinaryHibernation(ArkArchive archive, ReadingOptions options) { - if (!options.Hibernation) { + private void readBinaryHibernation(ArkArchive archive, ReadingOptions options) + { + if (!options.Hibernation) + { hibernationV8Unknown1 = 0; hibernationV8Unknown2 = 0; hibernationV8Unknown3 = 0; @@ -302,7 +353,8 @@ private void readBinaryHibernation(ArkArchive archive, ReadingOptions options) { archive.Position = hibernationOffset; - if (SaveVersion > 7) { + if (SaveVersion > 7) + { hibernationV8Unknown1 = archive.ReadInt(); hibernationV8Unknown2 = archive.ReadInt(); hibernationV8Unknown3 = archive.ReadInt(); @@ -310,7 +362,8 @@ private void readBinaryHibernation(ArkArchive archive, ReadingOptions options) { } // No hibernate section if we reached the nameTable - if (archive.Position== nameTableOffset) { + if (archive.Position == nameTableOffset) + { return; } @@ -321,20 +374,23 @@ private void readBinaryHibernation(ArkArchive archive, ReadingOptions options) { hibernationClasses.Clear(); hibernationClasses.Capacity = hibernatedClassesCount; - for (int index = 0; index < hibernatedClassesCount; index++) { + for (int index = 0; index < hibernatedClassesCount; index++) + { hibernationClasses.Add(archive.ReadString()); } int hibernatedIndicesCount = archive.ReadInt(); - if (hibernatedIndicesCount != hibernatedClassesCount) { + if (hibernatedIndicesCount != hibernatedClassesCount) + { archive.DebugMessage("hibernatedClassesCount does not match hibernatedIndicesCount"); throw new NotSupportedException(); } hibernationIndices.Clear(); hibernationIndices.Capacity = hibernatedIndicesCount; - for (int index = 0; index < hibernatedIndicesCount; index++) { + for (int index = 0; index < hibernatedIndicesCount; index++) + { hibernationIndices.Add(archive.ReadInt()); } @@ -342,7 +398,8 @@ private void readBinaryHibernation(ArkArchive archive, ReadingOptions options) { HibernationEntries.Clear(); HibernationEntries.Capacity = hibernatedObjectsCount; - for (int index = 0; index < hibernatedObjectsCount; index++) { + for (int index = 0; index < hibernatedObjectsCount; index++) + { HibernationEntries.Add(new HibernationEntry(archive, options)); } } @@ -351,9 +408,11 @@ private void readBinaryHibernation(ArkArchive archive, ReadingOptions options) { #region writeBinary - public void WriteBinary(ArkArchive archive, WritingOptions options) { - if (nameTableForWriteBinary != null) { - archive.SetNameTable(OldNameList != null ? ((ListAppendingSet)nameTableForWriteBinary).List : new List(nameTableForWriteBinary)); + public void WriteBinary(ArkArchive archive, WritingOptions options) + { + if (nameTableForWriteBinary != null) + { + archive.SetNameTable(OldNameList != null ? ((ListAppendingSet)nameTableForWriteBinary).List : new List(nameTableForWriteBinary)); } writeBinaryHeader(archive); @@ -362,18 +421,21 @@ public void WriteBinary(ArkArchive archive, WritingOptions options) { writeBinaryDataFilesObjectMap(archive); writeBinaryObjects(archive); - if (SaveVersion > 6) { + if (SaveVersion > 6) + { writeBinaryHibernation(archive); } - if (SaveVersion > 5) { + if (SaveVersion > 5) + { writeNameTable(archive); } writeBinaryProperties(archive, options); } - public int CalculateSize() { + public int CalculateSize() + { // calculateHeaderSize checks for valid known versions NameSizeCalculator calculator = ArkArchive.GetNameSizer(SaveVersion > 5); @@ -383,24 +445,31 @@ public int CalculateSize() { size += calculateDataFilesObjectMapSize(); size += calculateObjectsSize(calculator); - if (SaveVersion > 6) { + if (SaveVersion > 6) + { hibernationOffset = size; size += calculateHibernationSize(); } - if (SaveVersion > 5) { + if (SaveVersion > 5) + { nameTableOffset = size; nameTableForWriteBinary = OldNameList != null ? new ListAppendingSet(OldNameList) : new HashSet(); Objects.ForEach(o => o.CollectNames(arkName => nameTableForWriteBinary.Add(arkName.Name))); - if (OldNameList != null) { + if (OldNameList != null) + { size += 4 + ((ListAppendingSet)nameTableForWriteBinary).List.Sum(ArkArchive.GetStringLength); - } else { + } + else + { size += 4 + nameTableForWriteBinary.Sum(ArkArchive.GetStringLength); } - } else { + } + else + { nameTableForWriteBinary = null; } @@ -410,71 +479,86 @@ public int CalculateSize() { return size; } - private void writeBinaryHeader(ArkArchive archive) { + private void writeBinaryHeader(ArkArchive archive) + { archive.WriteShort(SaveVersion); - if (SaveVersion > 6) { + if (SaveVersion > 6) + { archive.WriteInt(hibernationOffset); archive.WriteInt(0); } - if (SaveVersion > 5) { + if (SaveVersion > 5) + { archive.WriteInt(nameTableOffset); archive.WriteInt(propertiesBlockOffset); } archive.WriteFloat(GameTime); - if (SaveVersion > 8) { + if (SaveVersion > 8) + { archive.WriteInt(SaveCount); } } - private void writeBinaryDataFiles(ArkArchive archive) { + private void writeBinaryDataFiles(ArkArchive archive) + { archive.WriteInt(DataFiles.Count); DataFiles.ForEach(archive.WriteString); } - private void writeBinaryEmbeddedData(ArkArchive archive) { + private void writeBinaryEmbeddedData(ArkArchive archive) + { archive.WriteInt(EmbeddedData.Count); EmbeddedData.ForEach(ed => ed.WriteBinary(archive)); } - private void writeBinaryDataFilesObjectMap(ArkArchive archive) { + private void writeBinaryDataFilesObjectMap(ArkArchive archive) + { archive.WriteInt(DataFilesObjectMap.Count); - foreach (int key in DataFilesObjectMap.Keys) { - foreach (string[] namesList in DataFilesObjectMap[key]) { + foreach (int key in DataFilesObjectMap.Keys) + { + foreach (string[] namesList in DataFilesObjectMap[key]) + { archive.WriteInt(key); archive.WriteInt(namesList.Length); - foreach (string name in namesList) { + foreach (string name in namesList) + { archive.WriteString(name); } } } } - private void writeBinaryObjects(ArkArchive archive) { + private void writeBinaryObjects(ArkArchive archive) + { archive.WriteInt(Objects.Count); // Position of properties data is absolute // or Position of properties data is relative to propertiesBlockOffset int currentOffset = SaveVersion == 5 ? propertiesBlockOffset : 0; - foreach (GameObject gameObject in Objects) { + foreach (GameObject gameObject in Objects) + { currentOffset = gameObject.WriteBinary(archive, currentOffset); } } - private void writeBinaryHibernation(ArkArchive archive) { + private void writeBinaryHibernation(ArkArchive archive) + { archive.Position = hibernationOffset; - if (SaveVersion > 7) { + if (SaveVersion > 7) + { archive.WriteInt(hibernationV8Unknown1); archive.WriteInt(hibernationV8Unknown2); archive.WriteInt(hibernationV8Unknown3); archive.WriteInt(hibernationV8Unknown4); } - if (!HibernationEntries.Any()) { + if (!HibernationEntries.Any()) + { return; } @@ -488,12 +572,14 @@ private void writeBinaryHibernation(ArkArchive archive) { hibernationIndices.ForEach(archive.WriteInt); archive.WriteInt(HibernationEntries.Count); - foreach (HibernationEntry hibernationEntry in HibernationEntries) { + foreach (HibernationEntry hibernationEntry in HibernationEntries) + { hibernationEntry.WriteBinary(archive); } } - private void writeNameTable(ArkArchive archive) { + private void writeNameTable(ArkArchive archive) + { archive.Position = nameTableOffset; List nameTable = archive.NameTable; @@ -501,7 +587,8 @@ private void writeNameTable(ArkArchive archive) { nameTable.ForEach(archive.WriteString); } - private void writeBinaryProperties(ArkArchive archive, WritingOptions writingOptions) { + private void writeBinaryProperties(ArkArchive archive, WritingOptions writingOptions) + { // Position of properties data is absolute // or Position of properties data is relative to propertiesBlockOffset int offset = SaveVersion == 5 ? 0 : propertiesBlockOffset; @@ -511,8 +598,8 @@ private void writeBinaryProperties(ArkArchive archive, WritingOptions writingOpt // gameObject.writeProperties(archive.Clone(), offset); // } //} else { - foreach (GameObject gameObject in Objects) - gameObject.WriteProperties(archive, offset); + foreach (GameObject gameObject in Objects) + gameObject.WriteProperties(archive, offset); //} } @@ -520,25 +607,30 @@ private void writeBinaryProperties(ArkArchive archive, WritingOptions writingOpt #region calculate sizes - private int calculateHeaderSize() { - if (SaveVersion < 5 || SaveVersion > 9) { + private int calculateHeaderSize() + { + if (SaveVersion < 5 || SaveVersion > 9) + { throw new NotSupportedException("Version " + SaveVersion + " is unknown and cannot be written in binary form"); } // saveVersion + gameTime int size = sizeof(short) + sizeof(float); - if (SaveVersion > 5) { + if (SaveVersion > 5) + { // nameTableOffset + propertiesBlockOffset size += sizeof(int) * 2; } - if (SaveVersion > 6) { + if (SaveVersion > 6) + { // hibernationOffset + shouldBeZero size += sizeof(int) * 2; } - if (SaveVersion > 8) { + if (SaveVersion > 8) + { // saveCount size += sizeof(int); } @@ -546,19 +638,24 @@ private int calculateHeaderSize() { return size; } - private int calculateDataFilesSize() { + private int calculateDataFilesSize() + { return 4 + DataFiles.Sum(ArkArchive.GetStringLength); } - private int calculateEmbeddedDataSize() { + private int calculateEmbeddedDataSize() + { return 4 + EmbeddedData.Sum(data => data.Size); } - private int calculateDataFilesObjectMapSize() { + private int calculateDataFilesObjectMapSize() + { int size = 4; - foreach (List namesListList in DataFilesObjectMap.Values) { + foreach (List namesListList in DataFilesObjectMap.Values) + { size += namesListList.Count * 8; - foreach (string[] namesList in namesListList) { + foreach (string[] namesList in namesListList) + { size += namesList.Sum(ArkArchive.GetStringLength); } } @@ -566,15 +663,18 @@ private int calculateDataFilesObjectMapSize() { return size; } - private int calculateObjectsSize(NameSizeCalculator nameSizer) { + private int calculateObjectsSize(NameSizeCalculator nameSizer) + { return 4 + Objects.AsParallel().Sum(o => o.Size(nameSizer)); } - private int calculateObjectPropertiesSize(NameSizeCalculator nameSizer) { + private int calculateObjectPropertiesSize(NameSizeCalculator nameSizer) + { return Objects.AsParallel().Sum(o => o.PropertiesSize(nameSizer)); } - private int calculateHibernationSize() { + private int calculateHibernationSize() + { int size = SaveVersion > 7 ? sizeof(int) * 4 : 0; if (HibernationEntries.Count <= 0) @@ -590,7 +690,8 @@ private int calculateHibernationSize() { #region readJson - public void ReadJson(JToken node, ReadingOptions options) { + public void ReadJson(JToken node, ReadingOptions options) + { readJsonHeader(node); readJsonDataFiles(node, options); readJsonEmbeddedData(node, options); @@ -599,7 +700,8 @@ public void ReadJson(JToken node, ReadingOptions options) { readJsonHibernatedObjects(node, options); } - private void readJsonHeader(JToken node) { + private void readJsonHeader(JToken node) + { SaveVersion = node.Value("saveVersion"); GameTime = node.Value("gameTime"); SaveCount = node.Value("saveCount"); @@ -608,7 +710,8 @@ private void readJsonHeader(JToken node) { OldNameList = preservedNames?.Any() == true ? preservedNames.Values().ToList() : null; } - private void readJsonDataFiles(JToken node, ReadingOptions options) { + private void readJsonDataFiles(JToken node, ReadingOptions options) + { DataFiles.Clear(); if (!options.DataFiles) return; @@ -619,7 +722,8 @@ private void readJsonDataFiles(JToken node, ReadingOptions options) { DataFiles.AddRange(dataFilesArray.Values()); } - private void readJsonEmbeddedData(JToken node, ReadingOptions options) { + private void readJsonEmbeddedData(JToken node, ReadingOptions options) + { EmbeddedData.Clear(); if (!options.EmbeddedData) return; @@ -630,7 +734,8 @@ private void readJsonEmbeddedData(JToken node, ReadingOptions options) { EmbeddedData.AddRange(embeddedDataArray.Values().Select(data => new EmbeddedData(data))); } - private void readJsonDataFilesObjectMap(JToken node, ReadingOptions options) { + private void readJsonDataFilesObjectMap(JToken node, ReadingOptions options) + { DataFilesObjectMap.Clear(); if (!options.DataFilesObjectMap) return; @@ -638,7 +743,8 @@ private void readJsonDataFilesObjectMap(JToken node, ReadingOptions options) { if (dataFilesObjectMapObject == null) return; - foreach (KeyValuePair entry in dataFilesObjectMapObject) { + foreach (KeyValuePair entry in dataFilesObjectMapObject) + { List objectNameList = ((JArray)entry.Value).Values() .Select(namesArray => namesArray.Values().ToArray()) .ToList(); @@ -646,7 +752,8 @@ private void readJsonDataFilesObjectMap(JToken node, ReadingOptions options) { } } - private void readJsonObjects(JToken node, ReadingOptions options) { + private void readJsonObjects(JToken node, ReadingOptions options) + { Objects.Clear(); ObjectMap.Clear(); if (!options.GameObjects) @@ -655,17 +762,20 @@ private void readJsonObjects(JToken node, ReadingOptions options) { if (objectsArray == null) return; Objects.Capacity = objectsArray.Count; - foreach (JObject jObject in objectsArray.Values()) { + foreach (JObject jObject in objectsArray.Values()) + { addObject(new GameObject(jObject, options.GameObjectProperties), options.BuildComponentTree); } } - private void readJsonHibernatedObjects(JToken node, ReadingOptions options) { + private void readJsonHibernatedObjects(JToken node, ReadingOptions options) + { hibernationClasses.Clear(); hibernationIndices.Clear(); HibernationEntries.Clear(); JObject hibernation = node.Value("hibernation"); - if (options.Hibernation && hibernation != null && hibernation.Type != JTokenType.Null) { + if (options.Hibernation && hibernation != null && hibernation.Type != JTokenType.Null) + { hibernationV8Unknown1 = hibernation.Value("v8Unknown1"); hibernationV8Unknown2 = hibernation.Value("v8Unknown2"); hibernationV8Unknown3 = hibernation.Value("v8Unknown3"); @@ -674,26 +784,34 @@ private void readJsonHibernatedObjects(JToken node, ReadingOptions options) { hibernationUnknown2 = hibernation.Value("unknown2"); JArray classesArray = hibernation.Value("classes"); - if (classesArray != null) { - foreach (JToken clazz in classesArray) { + if (classesArray != null) + { + foreach (JToken clazz in classesArray) + { hibernationClasses.Add(clazz.Value()); } } JArray indicesArray = hibernation.Value("indices"); - if (indicesArray != null) { - foreach (JToken index in indicesArray) { + if (indicesArray != null) + { + foreach (JToken index in indicesArray) + { hibernationIndices.Add(index.Value()); } } JArray entriesArray = hibernation.Value("entries"); - if (entriesArray != null) { - foreach (JToken hibernatedObject in entriesArray) { + if (entriesArray != null) + { + foreach (JToken hibernatedObject in entriesArray) + { HibernationEntries.Add(new HibernationEntry(hibernatedObject, options)); } } - } else { + } + else + { hibernationV8Unknown1 = 0; hibernationV8Unknown2 = 0; hibernationV8Unknown3 = 0; @@ -716,7 +834,8 @@ private void readJsonHibernatedObjects(JToken node, ReadingOptions options) { /// /// to write with /// - public void WriteJson(JsonTextWriter writer, WritingOptions writingOptions) { + public void WriteJson(JsonTextWriter writer, WritingOptions writingOptions) + { writer.WriteStartObject(); writer.WriteField("saveVersion", SaveVersion); @@ -724,44 +843,54 @@ public void WriteJson(JsonTextWriter writer, WritingOptions writingOptions) { writer.WriteField("saveCount", SaveCount); - if (!writingOptions.Compact && OldNameList != null && OldNameList.Any()) { + if (!writingOptions.Compact && OldNameList != null && OldNameList.Any()) + { writer.WriteArrayFieldStart("preservedNames"); - foreach (string oldName in OldNameList) { + foreach (string oldName in OldNameList) + { writer.WriteValue(oldName); } writer.WriteEndArray(); } - if (!writingOptions.Compact && DataFiles.Any()) { + if (!writingOptions.Compact && DataFiles.Any()) + { writer.WriteArrayFieldStart("dataFiles"); - foreach (string dataFile in DataFiles) { + foreach (string dataFile in DataFiles) + { writer.WriteValue(dataFile); } writer.WriteEndArray(); } - if (!writingOptions.Compact && EmbeddedData.Any()) { + if (!writingOptions.Compact && EmbeddedData.Any()) + { writer.WriteArrayFieldStart("embeddedData"); - foreach (EmbeddedData data in EmbeddedData) { + foreach (EmbeddedData data in EmbeddedData) + { data.WriteJson(writer); } writer.WriteEndArray(); } - if (DataFilesObjectMap.Any()) { + if (DataFilesObjectMap.Any()) + { writer.WriteObjectFieldStart("dataFilesObjectMap"); - foreach (KeyValuePair> entry in DataFilesObjectMap) { + foreach (KeyValuePair> entry in DataFilesObjectMap) + { writer.WriteArrayFieldStart(entry.Key.ToString()); - foreach (string[] namesList in entry.Value) { + foreach (string[] namesList in entry.Value) + { writer.WriteStartArray(); - foreach (string name in namesList) { + foreach (string name in namesList) + { writer.WriteValue(name); } @@ -774,10 +903,12 @@ public void WriteJson(JsonTextWriter writer, WritingOptions writingOptions) { writer.WriteEndObject(); } - if (Objects.Any()) { + if (Objects.Any()) + { writer.WriteArrayFieldStart("objects"); - foreach (GameObject gameObject in Objects) { + foreach (GameObject gameObject in Objects) + { gameObject.WriteJson(writer, writingOptions); } @@ -786,7 +917,8 @@ public void WriteJson(JsonTextWriter writer, WritingOptions writingOptions) { writer.WriteObjectFieldStart("hibernation"); - if (!writingOptions.Compact) { + if (!writingOptions.Compact) + { writer.WriteField("v8Unknown1", hibernationV8Unknown1); writer.WriteField("v8Unknown2", hibernationV8Unknown2); writer.WriteField("v8Unknown3", hibernationV8Unknown3); @@ -796,30 +928,36 @@ public void WriteJson(JsonTextWriter writer, WritingOptions writingOptions) { writer.WriteField("unknown2", hibernationUnknown2); } - if (!writingOptions.Compact && hibernationClasses.Any()) { + if (!writingOptions.Compact && hibernationClasses.Any()) + { writer.WriteArrayFieldStart("classes"); - foreach (string hibernationClass in hibernationClasses) { + foreach (string hibernationClass in hibernationClasses) + { writer.WriteValue(hibernationClass); } writer.WriteEndArray(); } - if (!writingOptions.Compact && hibernationIndices.Any()) { + if (!writingOptions.Compact && hibernationIndices.Any()) + { writer.WriteArrayFieldStart("indices"); - foreach (int hibernationIndex in hibernationIndices) { + foreach (int hibernationIndex in hibernationIndices) + { writer.WriteValue(hibernationIndex); } writer.WriteEndArray(); } - if (HibernationEntries.Any()) { + if (HibernationEntries.Any()) + { writer.WriteArrayFieldStart("entries"); - foreach (HibernationEntry hibernationEntry in HibernationEntries) { + foreach (HibernationEntry hibernationEntry in HibernationEntries) + { hibernationEntry.WriteJson(writer, writingOptions); }