public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (value is null) { writer.WriteNull(); return; } (value as IExtraData)?.WriteJson(writer as JsonTextWriter, WritingOptions.Create()); }
public static (GameObjectContainer, float) ReadSavegameFile(string fileName, string jsonFileName) { if (new FileInfo(fileName).Length > int.MaxValue) { throw new Exception("Input file is too large."); } Stream stream = new MemoryStream(File.ReadAllBytes(fileName)); ArkSavegame arkSavegame = new ArkSavegame(); // We're actually converting to json so we don't want to eliminate everything besides dinos. //bool PredicateCreatures(GameObject o) => !o.IsItem && (o.Parent != null || o.Components.Any()); //bool PredicateCreaturesAndCryopods(GameObject o) => (!o.IsItem && (o.Parent != null || o.Components.Any())) || o.ClassString.Contains("Cryopod") || o.ClassString.Contains("SoulTrap_"); using (ArkArchive archive = new ArkArchive(stream)) { arkSavegame.ReadBinary(archive, ReadingOptions.Create() .WithDataFiles(false) .WithEmbeddedData(false) .WithDataFilesObjectMap(false) //.WithObjectFilter(new Predicate<GameObject>(PredicateCreaturesAndCryopods)) .WithBuildComponentTree(true)); } // Jenny's addition - immediately write the json format for any binary file we read in. using (StreamWriter file = File.CreateText(jsonFileName)) using (JsonTextWriter writer = new JsonTextWriter(file)) { writer.Formatting = Formatting.Indented; arkSavegame.WriteJson(writer, WritingOptions.Create()); } // End of Jenny's addition. if (!arkSavegame.HibernationEntries.Any()) { return(arkSavegame, arkSavegame.GameTime); } List <GameObject> combinedObjects = arkSavegame.Objects; foreach (HibernationEntry entry in arkSavegame.HibernationEntries) { ObjectCollector collector = new ObjectCollector(entry, 1); combinedObjects.AddRange(collector.Remap(combinedObjects.Count)); } return(new GameObjectContainer(combinedObjects), arkSavegame.GameTime); }