private static void CheckGlobalInit() { if (!globalInitDone) { UnityDataInitializer.CopyUnityData(); SteamManager.InitIfNeeded(); string[] commandLineArgs = Environment.GetCommandLineArgs(); if (commandLineArgs != null && commandLineArgs.Length > 1) { Log.Message("Command line arguments: " + GenText.ToSpaceList(commandLineArgs.Skip(1))); } VersionControl.LogVersionNumber(); Application.targetFrameRate = 60; Prefs.Init(); if (Prefs.DevMode) { StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes(); } LongEventHandler.QueueLongEvent(StaticConstructorOnStartupUtility.CallAll, null, doAsynchronously: false, null); globalInitDone = true; } }
private static void <UpdateCurrentAsynchronousEvent> m__1() { LongEventHandler.RunEventFromAnotherThread(LongEventHandler.currentEvent.eventAction); }
public void LoadGame() { if (this.maps.Any <Map>()) { Log.Error("Called LoadGame() but there already is a map. There should be 0 maps...", false); return; } MemoryUtility.UnloadUnusedUnityAssets(); Current.ProgramState = ProgramState.MapInitializing; this.ExposeSmallComponents(); LongEventHandler.SetCurrentEventText("LoadingWorld".Translate()); if (Scribe.EnterNode("world")) { try { this.World = new World(); this.World.ExposeData(); } finally { Scribe.ExitNode(); } this.World.FinalizeInit(); LongEventHandler.SetCurrentEventText("LoadingMap".Translate()); Scribe_Collections.Look <Map>(ref this.maps, "maps", LookMode.Deep, new object[0]); if (this.maps.RemoveAll((Map x) => x == null) != 0) { Log.Warning("Some maps were null after loading.", false); } int num = -1; Scribe_Values.Look <int>(ref num, "currentMapIndex", -1, false); if (num < 0 && this.maps.Any <Map>()) { Log.Error("Current map is null after loading but there are maps available. Setting current map to [0].", false); num = 0; } if (num >= this.maps.Count) { Log.Error("Current map index out of bounds after loading.", false); if (this.maps.Any <Map>()) { num = 0; } else { num = -1; } } this.currentMapIndex = -128; this.CurrentMap = ((num < 0) ? null : this.maps[num]); LongEventHandler.SetCurrentEventText("InitializingGame".Translate()); Find.CameraDriver.Expose(); DeepProfiler.Start("FinalizeLoading"); Scribe.loader.FinalizeLoading(); DeepProfiler.End(); LongEventHandler.SetCurrentEventText("SpawningAllThings".Translate()); for (int i = 0; i < this.maps.Count; i++) { try { this.maps[i].FinalizeLoading(); } catch (Exception arg) { Log.Error("Error in Map.FinalizeLoading(): " + arg, false); } try { this.maps[i].Parent.FinalizeLoading(); } catch (Exception arg2) { Log.Error("Error in MapParent.FinalizeLoading(): " + arg2, false); } } this.FinalizeInit(); if (Prefs.PauseOnLoad) { LongEventHandler.ExecuteWhenFinished(delegate { Find.TickManager.DoSingleTick(); Find.TickManager.CurTimeSpeed = TimeSpeed.Paused; }); } GameComponentUtility.LoadedGame(); return; } Log.Error("Could not find world XML node.", false); }
public void ReloadContent() { LongEventHandler.ExecuteWhenFinished(ReloadContentInt); assemblies.ReloadAll(); }
public void InitNewGame() { string str = (from mod in LoadedModManager.RunningMods select mod.ToString()).ToCommaList(false); Log.Message("Initializing new game with mods " + str, false); if (this.maps.Any <Map>()) { Log.Error("Called InitNewGame() but there already is a map. There should be 0 maps...", false); return; } if (this.initData == null) { Log.Error("Called InitNewGame() but init data is null. Create it first.", false); return; } MemoryUtility.UnloadUnusedUnityAssets(); DeepProfiler.Start("InitNewGame"); try { Current.ProgramState = ProgramState.MapInitializing; IntVec3 intVec = new IntVec3(this.initData.mapSize, 1, this.initData.mapSize); Settlement settlement = null; List <Settlement> settlements = Find.WorldObjects.Settlements; for (int i = 0; i < settlements.Count; i++) { if (settlements[i].Faction == Faction.OfPlayer) { settlement = settlements[i]; break; } } if (settlement == null) { Log.Error("Could not generate starting map because there is no any player faction base.", false); } this.tickManager.gameStartAbsTick = GenTicks.ConfiguredTicksAbsAtGameStart; Map currentMap = MapGenerator.GenerateMap(intVec, settlement, settlement.MapGeneratorDef, settlement.ExtraGenStepDefs, null); this.worldInt.info.initialMapSize = intVec; if (this.initData.permadeath) { this.info.permadeathMode = true; this.info.permadeathModeUniqueName = PermadeathModeUtility.GeneratePermadeathSaveName(); } PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism); this.FinalizeInit(); Current.Game.CurrentMap = currentMap; Find.CameraDriver.JumpToCurrentMapLoc(MapGenerator.PlayerStartSpot); Find.CameraDriver.ResetSize(); if (Prefs.PauseOnLoad && this.initData.startedFromEntry) { LongEventHandler.ExecuteWhenFinished(delegate { this.tickManager.DoSingleTick(); this.tickManager.CurTimeSpeed = TimeSpeed.Paused; }); } Find.Scenario.PostGameStart(); if (Faction.OfPlayer.def.startingResearchTags != null) { foreach (ResearchProjectTagDef current in Faction.OfPlayer.def.startingResearchTags) { foreach (ResearchProjectDef current2 in DefDatabase <ResearchProjectDef> .AllDefs) { if (current2.HasTag(current)) { this.researchManager.FinishProject(current2, false, null); } } } } GameComponentUtility.StartedNewGame(); this.initData = null; } finally { DeepProfiler.End(); } }
public void LoadGame() { if (maps.Any()) { Log.Error("Called LoadGame() but there already is a map. There should be 0 maps..."); } else { MemoryUtility.UnloadUnusedUnityAssets(); Current.ProgramState = ProgramState.MapInitializing; ExposeSmallComponents(); LongEventHandler.SetCurrentEventText("LoadingWorld".Translate()); if (!Scribe.EnterNode("world")) { Log.Error("Could not find world XML node."); } else { try { World = new World(); World.ExposeData(); } finally { Scribe.ExitNode(); } World.FinalizeInit(); LongEventHandler.SetCurrentEventText("LoadingMap".Translate()); Scribe_Collections.Look(ref maps, "maps", LookMode.Deep); if (maps.RemoveAll((Map x) => x == null) != 0) { Log.Warning("Some maps were null after loading."); } int value = -1; Scribe_Values.Look(ref value, "currentMapIndex", -1); if (value < 0 && maps.Any()) { Log.Error("Current map is null after loading but there are maps available. Setting current map to [0]."); value = 0; } if (value >= maps.Count) { Log.Error("Current map index out of bounds after loading."); value = ((!maps.Any()) ? (-1) : 0); } currentMapIndex = sbyte.MinValue; CurrentMap = ((value < 0) ? null : maps[value]); LongEventHandler.SetCurrentEventText("InitializingGame".Translate()); Find.CameraDriver.Expose(); DeepProfiler.Start("FinalizeLoading"); Scribe.loader.FinalizeLoading(); DeepProfiler.End(); LongEventHandler.SetCurrentEventText("SpawningAllThings".Translate()); for (int i = 0; i < maps.Count; i++) { try { maps[i].FinalizeLoading(); } catch (Exception arg) { Log.Error("Error in Map.FinalizeLoading(): " + arg); } try { maps[i].Parent.FinalizeLoading(); } catch (Exception arg2) { Log.Error("Error in MapParent.FinalizeLoading(): " + arg2); } } FinalizeInit(); if (Prefs.PauseOnLoad) { LongEventHandler.ExecuteWhenFinished(delegate { Find.TickManager.DoSingleTick(); Find.TickManager.CurTimeSpeed = TimeSpeed.Paused; }); } GameComponentUtility.LoadedGame(); } } }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { //Before base.SpawnSetup() so when regions are rebuilt this building can be accessed via edificeGrid if (def.IsEdifice()) { map.edificeGrid.Register(this); } base.SpawnSetup(map, respawningAfterLoad); Map.listerBuildings.Add(this); //Remake terrain meshes with new underwall under me if (def.coversFloor) { Map.mapDrawer.MapMeshDirty(Position, MapMeshFlag.Terrain, true, false); } var occRect = this.OccupiedRect(); for (int z = occRect.minZ; z <= occRect.maxZ; z++) { for (int x = occRect.minX; x <= occRect.maxX; x++) { var c = new IntVec3(x, 0, z); Map.mapDrawer.MapMeshDirty(c, MapMeshFlag.Buildings); Map.glowGrid.MarkGlowGridDirty(c); if (!SnowGrid.CanCoexistWithSnow(def)) { Map.snowGrid.SetDepth(c, 0); } } } if (Faction == Faction.OfPlayer) { if (def.building != null && def.building.spawnedConceptLearnOpportunity != null) { LessonAutoActivator.TeachOpportunity(def.building.spawnedConceptLearnOpportunity, OpportunityType.GoodToKnow); } } AutoHomeAreaMaker.Notify_BuildingSpawned(this); if (def.building != null && !def.building.soundAmbient.NullOrUndefined()) { LongEventHandler.ExecuteWhenFinished(() => { SoundInfo info = SoundInfo.InMap(this, MaintenanceType.None); sustainerAmbient = SoundStarter.TrySpawnSustainer(def.building.soundAmbient, info); }); } Map.listerBuildingsRepairable.Notify_BuildingSpawned(this); if (!this.CanBeSeenOver()) { Map.exitMapGrid.Notify_LOSBlockerSpawned(); } SmoothSurfaceDesignatorUtility.Notify_BuildingSpawned(this); //Must go after adding to buildings list map.avoidGrid.Notify_BuildingSpawned(this); }
public override void Start() { Log.ResetMessageCount(); base.Start(); try { this.musicManagerPlay = new MusicManagerPlay(); FileInfo autostart = (!Root.checkedAutostartSaveFile) ? SaveGameFilesUtility.GetAutostartSaveFile() : null; Root.checkedAutostartSaveFile = true; if (autostart != null) { Action action = delegate() { SavedGameLoaderNow.LoadGameFromSaveFileNow(Path.GetFileNameWithoutExtension(autostart.Name)); }; string textKey = "LoadingLongEvent"; bool doAsynchronously = true; if (Root_Play.< > f__mg$cache0 == null) { Root_Play.< > f__mg$cache0 = new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileLoadingGame); } LongEventHandler.QueueLongEvent(action, textKey, doAsynchronously, Root_Play.< > f__mg$cache0); } else if (Find.GameInitData != null && !Find.GameInitData.gameToLoad.NullOrEmpty()) { Action action2 = delegate() { SavedGameLoaderNow.LoadGameFromSaveFileNow(Find.GameInitData.gameToLoad); }; string textKey2 = "LoadingLongEvent"; bool doAsynchronously2 = true; if (Root_Play.< > f__mg$cache1 == null) { Root_Play.< > f__mg$cache1 = new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileLoadingGame); } LongEventHandler.QueueLongEvent(action2, textKey2, doAsynchronously2, Root_Play.< > f__mg$cache1); } else { Action action3 = delegate() { if (Current.Game == null) { Root_Play.SetupForQuickTestPlay(); } Current.Game.InitNewGame(); }; string textKey3 = "GeneratingMap"; bool doAsynchronously3 = true; if (Root_Play.< > f__mg$cache2 == null) { Root_Play.< > f__mg$cache2 = new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap); } LongEventHandler.QueueLongEvent(action3, textKey3, doAsynchronously3, Root_Play.< > f__mg$cache2); } LongEventHandler.QueueLongEvent(delegate() { ScreenFader.SetColor(Color.black); ScreenFader.StartFade(Color.clear, 0.5f); }, null, false, null); } catch (Exception arg) { Log.Error("Critical error in root Start(): " + arg, false); } }
public void InitNewGame() { string str = LoadedModManager.RunningMods.Select((ModContentPack mod) => mod.PackageIdPlayerFacing).ToLineList(" - "); Log.Message("Initializing new game with mods:\n" + str); if (maps.Any()) { Log.Error("Called InitNewGame() but there already is a map. There should be 0 maps..."); return; } if (initData == null) { Log.Error("Called InitNewGame() but init data is null. Create it first."); return; } MemoryUtility.UnloadUnusedUnityAssets(); DeepProfiler.Start("InitNewGame"); try { //InitMap Current.ProgramState = ProgramState.MapInitializing; IntVec3 intVec = new IntVec3(initData.mapSize, 1, initData.mapSize); Settlement settlement = null; List <Settlement> settlements = Find.WorldObjects.Settlements; for (int i = 0; i < settlements.Count; i++) { if (settlements[i].Faction == Faction.OfPlayer) { settlement = settlements[i]; break; } } if (settlement == null) { Log.Error("Could not generate starting map because there is no any player faction base."); } tickManager.gameStartAbsTick = GenTicks.ConfiguredTicksAbsAtGameStart; //-------------- //Map currentMap=Map //Map currentMap = MapGenerator.GenerateMap(intVec, settlement, settlement.MapGeneratorDef, settlement.ExtraGenStepDefs); //Map currentMap=MapGenerator.GenerateMap(intVec,settlement,settlement.MapGeneratorDef,settlement.ExtraGenStepDefs) Map currentMap = MapGenerator.GenerateMap(intVec, settlement, settlement.MapGeneratorDef, settlement.ExtraGenStepDefs); worldInt.info.initialMapSize = intVec; if (initData.permadeath) { info.permadeathMode = true; info.permadeathModeUniqueName = PermadeathModeUtility.GeneratePermadeathSaveName(); } PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism); FinalizeInit(); Current.Game.CurrentMap = currentMap; Find.CameraDriver.JumpToCurrentMapLoc(MapGenerator.PlayerStartSpot); Find.CameraDriver.ResetSize(); if (Prefs.PauseOnLoad && initData.startedFromEntry) { LongEventHandler.ExecuteWhenFinished(delegate { tickManager.DoSingleTick(); tickManager.CurTimeSpeed = TimeSpeed.Paused; }); } //--------------end Find.Scenario.PostGameStart(); if (Faction.OfPlayer.def.startingResearchTags != null) { foreach (ResearchProjectTagDef startingResearchTag in Faction.OfPlayer.def.startingResearchTags) { foreach (ResearchProjectDef allDef in DefDatabase <ResearchProjectDef> .AllDefs) { if (allDef.HasTag(startingResearchTag)) { researchManager.FinishProject(allDef); } } } } if (Faction.OfPlayer.def.startingTechprintsResearchTags != null) { foreach (ResearchProjectTagDef startingTechprintsResearchTag in Faction.OfPlayer.def.startingTechprintsResearchTags) { foreach (ResearchProjectDef allDef2 in DefDatabase <ResearchProjectDef> .AllDefs) { if (allDef2.HasTag(startingTechprintsResearchTag)) { int techprints = researchManager.GetTechprints(allDef2); if (techprints < allDef2.techprintCount) { researchManager.AddTechprints(allDef2, allDef2.techprintCount - techprints); } } } } } GameComponentUtility.StartedNewGame(); initData = null; } finally { DeepProfiler.End(); } }
public void LoadData() { if (this.dataIsLoaded) { return; } this.dataIsLoaded = true; DeepProfiler.Start("Loading language data: " + this.folderName); foreach (string text in this.FolderPaths) { string localFolderPath = text; LongEventHandler.ExecuteWhenFinished(delegate { if (this.icon == BaseContent.BadTex) { FileInfo fileInfo = new FileInfo(Path.Combine(localFolderPath.ToString(), "LangIcon.png")); if (fileInfo.Exists) { this.icon = ModContentLoader <Texture2D> .LoadItem(fileInfo.FullName, null).contentItem; } } }); DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(text.ToString(), "CodeLinked")); if (directoryInfo.Exists) { this.loadErrors.Add("Translations aren't called CodeLinked any more. Please rename to Keyed: " + directoryInfo); } else { directoryInfo = new DirectoryInfo(Path.Combine(text.ToString(), "Keyed")); } if (directoryInfo.Exists) { foreach (FileInfo file in directoryInfo.GetFiles("*.xml", SearchOption.AllDirectories)) { this.LoadFromFile_Keyed(file); } } DirectoryInfo directoryInfo2 = new DirectoryInfo(Path.Combine(text.ToString(), "DefLinked")); if (directoryInfo2.Exists) { this.loadErrors.Add("Translations aren't called DefLinked any more. Please rename to DefInjected: " + directoryInfo2); } else { directoryInfo2 = new DirectoryInfo(Path.Combine(text.ToString(), "DefInjected")); } if (directoryInfo2.Exists) { foreach (DirectoryInfo directoryInfo3 in directoryInfo2.GetDirectories("*", SearchOption.TopDirectoryOnly)) { string name = directoryInfo3.Name; Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name); if (typeInAnyAssembly == null && name.Length > 3) { typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name.Substring(0, name.Length - 1)); } if (typeInAnyAssembly == null) { this.loadErrors.Add(string.Concat(new string[] { "Error loading language from ", text, ": dir ", directoryInfo3.Name, " doesn't correspond to any def type. Skipping..." })); } else { foreach (FileInfo file2 in directoryInfo3.GetFiles("*.xml", SearchOption.AllDirectories)) { this.LoadFromFile_DefInject(file2, typeInAnyAssembly); } } } } this.EnsureAllDefTypesHaveDefInjectionPackage(); DirectoryInfo directoryInfo4 = new DirectoryInfo(Path.Combine(text.ToString(), "Strings")); if (directoryInfo4.Exists) { foreach (DirectoryInfo directoryInfo5 in directoryInfo4.GetDirectories("*", SearchOption.TopDirectoryOnly)) { foreach (FileInfo file3 in directoryInfo5.GetFiles("*.txt", SearchOption.AllDirectories)) { this.LoadFromFile_Strings(file3, directoryInfo4); } } } } DeepProfiler.End(); }
public void LoadGame() { if (this.maps.Any()) { Log.Error("Called LoadGame() but there already is a map. There should be 0 maps..."); } else { MemoryUtility.UnloadUnusedUnityAssets(); Current.ProgramState = ProgramState.MapInitializing; this.ExposeSmallComponents(); BackCompatibility.AfterLoadingSmallGameClassComponents(this); LongEventHandler.SetCurrentEventText("LoadingWorld".Translate()); if (Scribe.EnterNode("world")) { try { this.World = new World(); this.World.ExposeData(); } finally { Scribe.ExitNode(); } this.World.FinalizeInit(); LongEventHandler.SetCurrentEventText("LoadingMap".Translate()); Scribe_Collections.Look <Map>(ref this.maps, "maps", LookMode.Deep, new object[0]); int num = -1; Scribe_Values.Look(ref num, "visibleMapIndex", -1, false); if (num < 0 && this.maps.Any()) { Log.Error("Visible map is null after loading but there are maps available. Setting visible map to [0]."); num = 0; } if (num >= this.maps.Count) { Log.Error("Visible map index out of bounds after loading."); num = ((!this.maps.Any()) ? (-1) : 0); } this.visibleMapIndex = -128; this.VisibleMap = ((num < 0) ? null : this.maps[num]); LongEventHandler.SetCurrentEventText("InitializingGame".Translate()); Find.CameraDriver.Expose(); DeepProfiler.Start("FinalizeLoading"); Scribe.loader.FinalizeLoading(); DeepProfiler.End(); LongEventHandler.SetCurrentEventText("SpawningAllThings".Translate()); for (int i = 0; i < this.maps.Count; i++) { this.maps[i].FinalizeLoading(); } this.FinalizeInit(); if (Prefs.PauseOnLoad) { LongEventHandler.ExecuteWhenFinished(delegate { Find.TickManager.DoSingleTick(); Find.TickManager.CurTimeSpeed = TimeSpeed.Paused; }); } GameComponentUtility.LoadedGame(); } else { Log.Error("Could not find world XML node."); } } }
public void InitNewGame() { string str = GenText.ToCommaList(from mod in LoadedModManager.RunningMods select mod.ToString(), true); Log.Message("Initializing new game with mods " + str); if (this.maps.Any()) { Log.Error("Called InitNewGame() but there already is a map. There should be 0 maps..."); } else if (this.initData == null) { Log.Error("Called InitNewGame() but init data is null. Create it first."); } else { MemoryUtility.UnloadUnusedUnityAssets(); DeepProfiler.Start("InitNewGame"); try { Current.ProgramState = ProgramState.MapInitializing; IntVec3 intVec = new IntVec3(this.initData.mapSize, 1, this.initData.mapSize); FactionBase factionBase = null; List <FactionBase> factionBases = Find.WorldObjects.FactionBases; int num = 0; while (num < factionBases.Count) { if (factionBases[num].Faction != Faction.OfPlayer) { num++; continue; } factionBase = factionBases[num]; break; } if (factionBase == null) { Log.Error("Could not generate starting map because there is no any player faction base."); } this.tickManager.gameStartAbsTick = GenTicks.ConfiguredTicksAbsAtGameStart; Map visibleMap = MapGenerator.GenerateMap(intVec, factionBase, factionBase.MapGeneratorDef, factionBase.ExtraGenStepDefs, null); this.worldInt.info.initialMapSize = intVec; if (this.initData.permadeath) { this.info.permadeathMode = true; this.info.permadeathModeUniqueName = PermadeathModeUtility.GeneratePermadeathSaveName(); } PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism); this.FinalizeInit(); Current.Game.VisibleMap = visibleMap; Find.CameraDriver.JumpToVisibleMapLoc(MapGenerator.PlayerStartSpot); Find.CameraDriver.ResetSize(); if (Prefs.PauseOnLoad && this.initData.startedFromEntry) { LongEventHandler.ExecuteWhenFinished(delegate { this.tickManager.DoSingleTick(); this.tickManager.CurTimeSpeed = TimeSpeed.Paused; }); } Find.Scenario.PostGameStart(); if (Faction.OfPlayer.def.startingResearchTags != null) { foreach (string startingResearchTag in Faction.OfPlayer.def.startingResearchTags) { foreach (ResearchProjectDef allDef in DefDatabase <ResearchProjectDef> .AllDefs) { if (allDef.HasTag(startingResearchTag)) { this.researchManager.InstantFinish(allDef, false); } } } } GameComponentUtility.StartedNewGame(); this.initData = null; } finally { DeepProfiler.End(); } } }