private void Save(BinaryWriter writer) { writer.WriteKleiString("world"); SaveFileRoot obj = PrepSaveFile(); Serializer.Serialize(obj, writer); Game.SaveSettings(writer); saveManager.Save(writer); Game.Instance.Save(writer); }
private SaveFileRoot PrepSaveFile() { SaveFileRoot saveFileRoot = new SaveFileRoot(); saveFileRoot.WidthInCells = Grid.WidthInCells; saveFileRoot.HeightInCells = Grid.HeightInCells; using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(memoryStream)) { Sim.Save(writer); } if (zipStreams) { saveFileRoot.streamed["SimBZ"] = CompressContents(memoryStream.ToArray()); } else { saveFileRoot.streamed["Sim"] = memoryStream.ToArray(); } } if (zipStreams) { saveFileRoot.streamed["GridVisibleBZ"] = CompressContents(Grid.Visible); saveFileRoot.streamed["GridSpawnableBZ"] = CompressContents(Grid.Spawnable); saveFileRoot.streamed["GridDamageBZ"] = CompressContents(FloatToBytes(Grid.Damage)); } else { saveFileRoot.streamed["GridVisible"] = Grid.Visible; saveFileRoot.streamed["GridSpawnable"] = Grid.Spawnable; saveFileRoot.streamed["GridDamage"] = FloatToBytes(Grid.Damage); } Global.Instance.modManager.SendMetricsEvent(); saveFileRoot.active_mods = new List <Label>(); foreach (Mod mod in Global.Instance.modManager.mods) { if (mod.enabled) { saveFileRoot.active_mods.Add(mod.label); } } string text = saveFileRoot.worldID = ((Game.worldID == null) ? CustomGameSettings.Instance.GetCurrentQualitySetting(CustomGameSettingConfigs.World).id : Game.worldID); using (MemoryStream memoryStream2 = new MemoryStream()) { using (BinaryWriter writer2 = new BinaryWriter(memoryStream2)) { Camera.main.transform.parent.GetComponent <CameraController>().Save(writer2); } saveFileRoot.streamed["Camera"] = memoryStream2.ToArray(); return(saveFileRoot); } }
private bool Load(IReader reader) { string a = reader.ReadKleiString(); Debug.Assert(a == "world"); Deserializer deserializer = new Deserializer(reader); SaveFileRoot saveFileRoot = new SaveFileRoot(); deserializer.Deserialize(saveFileRoot); SaveGame.GameInfo gameInfo = GameInfo; if (gameInfo.saveMajorVersion != 7) { SaveGame.GameInfo gameInfo2 = GameInfo; if (gameInfo2.saveMinorVersion >= 8) { goto IL_00f7; } } if (saveFileRoot.requiredMods != null) { saveFileRoot.active_mods = new List <Label>(); foreach (ModInfo requiredMod in saveFileRoot.requiredMods) { ModInfo current = requiredMod; saveFileRoot.active_mods.Add(new Label { id = current.assetID, version = current.lastModifiedTime, distribution_platform = Label.DistributionPlatform.Steam, title = current.description }); } saveFileRoot.requiredMods.Clear(); } goto IL_00f7; IL_00f7: KMod.Manager modManager = Global.Instance.modManager; modManager.Load(Content.LayerableFiles); if (!modManager.MatchFootprint(saveFileRoot.active_mods, Content.LayerableFiles | Content.Strings | Content.DLL | Content.Translation | Content.Animation)) { DebugUtil.LogWarningArgs("Mod footprint of save file doesn't match current mod configuration"); } Global.Instance.modManager.SendMetricsEvent(); string text = saveFileRoot.worldID; if (text == null) { try { text = CustomGameSettings.Instance.GetCurrentQualitySetting(CustomGameSettingConfigs.World).id; } catch { text = "worlds/SandstoneDefault"; } } Game.worldID = text; worldGen = new WorldGen(text, null); Game.LoadSettings(deserializer); GridSettings.Reset(saveFileRoot.WidthInCells, saveFileRoot.HeightInCells); Singleton <KBatchedAnimUpdater> .Instance.InitializeGrid(); Sim.SIM_Initialize(Sim.DLL_MessageHandler); SimMessages.CreateSimElementsTable(ElementLoader.elements); SimMessages.CreateDiseaseTable(); byte[] bytes = saveFileRoot.streamed["Sim"]; FastReader reader2 = new FastReader(bytes); if (Sim.Load(reader2) != 0) { DebugUtil.LogWarningArgs("\n--- Error loading save ---\nSimDLL found bad data\n"); Sim.Shutdown(); return(false); } SceneInitializer.Instance.PostLoadPrefabs(); mustRestartOnFail = true; if (!saveManager.Load(reader)) { Sim.Shutdown(); DebugUtil.LogWarningArgs("\n--- Error loading save ---\n"); SetActiveSaveFilePath(null); return(false); } Grid.Visible = saveFileRoot.streamed["GridVisible"]; if (saveFileRoot.streamed.ContainsKey("GridSpawnable")) { Grid.Spawnable = saveFileRoot.streamed["GridSpawnable"]; } Grid.Damage = BytesToFloat(saveFileRoot.streamed["GridDamage"]); Game.Instance.Load(deserializer); FastReader reader3 = new FastReader(saveFileRoot.streamed["Camera"]); CameraSaveData.Load(reader3); return(true); }