/// <inheritdoc /> /// <summary> /// Writes this class as json using <code>generator</code>. /// This method is valid only in an array context or in no context (see <see cref="M:Newtonsoft.Json.JsonTextWriter.WriteStartObject" />. /// Requires the current objects list to be correctly sorted, otherwise the written /// <see cref="T:SavegameToolkit.Types.ObjectReference" /> might be broken. /// </summary> /// <param name="writer"><see cref="T:Newtonsoft.Json.JsonTextWriter" /> to write with</param> /// <param name="writingOptions"></param> public void WriteJson(JsonTextWriter writer, WritingOptions writingOptions) { writer.WriteStartObject(); writer.WriteField("saveVersion", SaveVersion); writer.WriteField("gameTime", GameTime); writer.WriteField("saveCount", SaveCount); if (!writingOptions.Compact && OldNameList != null && OldNameList.Any()) { writer.WriteArrayFieldStart("preservedNames"); foreach (string oldName in OldNameList) { writer.WriteValue(oldName); } writer.WriteEndArray(); } if (!writingOptions.Compact && DataFiles.Any()) { writer.WriteArrayFieldStart("dataFiles"); foreach (string dataFile in DataFiles) { writer.WriteValue(dataFile); } writer.WriteEndArray(); } if (!writingOptions.Compact && EmbeddedData.Any()) { writer.WriteArrayFieldStart("embeddedData"); foreach (EmbeddedData data in EmbeddedData) { data.WriteJson(writer); } writer.WriteEndArray(); } if (DataFilesObjectMap.Any()) { writer.WriteObjectFieldStart("dataFilesObjectMap"); foreach (KeyValuePair <int, List <string[]> > entry in DataFilesObjectMap) { writer.WriteArrayFieldStart(entry.Key.ToString()); foreach (string[] namesList in entry.Value) { writer.WriteStartArray(); foreach (string name in namesList) { writer.WriteValue(name); } writer.WriteEndArray(); } writer.WriteEndArray(); } writer.WriteEndObject(); } if (Objects.Any()) { writer.WriteArrayFieldStart("objects"); foreach (GameObject gameObject in Objects) { gameObject.WriteJson(writer, writingOptions); } writer.WriteEndArray(); } writer.WriteObjectFieldStart("hibernation"); if (!writingOptions.Compact) { writer.WriteField("v8Unknown1", hibernationV8Unknown1); writer.WriteField("v8Unknown2", hibernationV8Unknown2); writer.WriteField("v8Unknown3", hibernationV8Unknown3); writer.WriteField("v8Unknown4", hibernationV8Unknown4); writer.WriteField("unknown1", hibernationUnknown1); writer.WriteField("unknown2", hibernationUnknown2); } if (!writingOptions.Compact && hibernationClasses.Any()) { writer.WriteArrayFieldStart("classes"); foreach (string hibernationClass in hibernationClasses) { writer.WriteValue(hibernationClass); } writer.WriteEndArray(); } if (!writingOptions.Compact && hibernationIndices.Any()) { writer.WriteArrayFieldStart("indices"); foreach (int hibernationIndex in hibernationIndices) { writer.WriteValue(hibernationIndex); } writer.WriteEndArray(); } if (HibernationEntries.Any()) { writer.WriteArrayFieldStart("entries"); foreach (HibernationEntry hibernationEntry in HibernationEntries) { hibernationEntry.WriteJson(writer, writingOptions); } writer.WriteEndArray(); } writer.WriteEndObject(); writer.WriteEndObject(); }