public bool LoadFromWorldGen() { DebugUtil.LogArgs("Attempting to start a new game with current world gen"); WorldGen.LoadSettings(); string worldName; try { worldName = CustomGameSettings.Instance.GetCurrentQualitySetting(CustomGameSettingConfigs.World).id; } catch { worldName = "worlds/SandstoneDefault"; } worldGen = new WorldGen(worldName, null); SimSaveFileStructure simSaveFileStructure = worldGen.LoadWorldGenSim(); if (simSaveFileStructure == null) { Debug.LogError("Attempt failed"); return(false); } worldDetailSave = simSaveFileStructure.worldDetail; if (worldDetailSave == null) { Debug.LogError("Detail is null"); } GridSettings.Reset(simSaveFileStructure.WidthInCells, simSaveFileStructure.HeightInCells); Singleton <KBatchedAnimUpdater> .Instance.InitializeGrid(); Sim.SIM_Initialize(Sim.DLL_MessageHandler); SimMessages.CreateSimElementsTable(ElementLoader.elements); SimMessages.CreateDiseaseTable(); try { FastReader reader = new FastReader(simSaveFileStructure.Sim); if (Sim.Load(reader) != 0) { DebugUtil.LogWarningArgs("\n--- Error loading save ---\nSimDLL found bad data\n"); Sim.Shutdown(); return(false); } } catch (Exception ex) { Debug.LogWarning("--- Error loading Sim FROM NEW WORLDGEN ---" + ex.Message + "\n" + ex.StackTrace); Sim.Shutdown(); return(false); } Debug.Log("Attempt success"); SceneInitializer.Instance.PostLoadPrefabs(); SceneInitializer.Instance.NewSaveGamePrefab(); worldGen.ReplayGenerate(Reset); OnWorldGenComplete.Signal(); ThreadedHttps <KleiMetrics> .Instance.StartNewGame(); return(true); }
private void DoWorldGenInitialize() { SettingLevel currentQualitySetting = CustomGameSettings.Instance.GetCurrentQualitySetting(CustomGameSettingConfigs.World); SettingLevel currentQualitySetting2 = CustomGameSettings.Instance.GetCurrentQualitySetting(CustomGameSettingConfigs.WorldgenSeed); seed = int.Parse(currentQualitySetting2.id); List <string> randomTraits = SettingsCache.GetRandomTraits(seed); worldGen = new WorldGen(currentQualitySetting.id, randomTraits); Vector2I worldsize = worldGen.Settings.world.worldsize; GridSettings.Reset(worldsize.x, worldsize.y); worldGen.Initialise(UpdateProgress, OnError, seed, seed, seed, seed); firstPassGeneration = true; worldGen.GenerateOfflineThreaded(); }
private static void ResetGridSettingsChunks(int width, int height) { GridSettings.Reset(width * 32, height * 32); }
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); }