private static bool Prefix(Door __instance, bool is_door_open, IList <int> cells) { PrimaryElement component = __instance.GetComponent <PrimaryElement>(); float mass = component.Mass / (float)cells.Count; for (int i = 0; i < cells.Count; i++) { int offsetCell = cells[i]; Door.DoorType doorType = __instance.doorType; if (doorType <= Door.DoorType.ManualPressure || doorType == Door.DoorType.Sealed) { World.Instance.groundRenderer.MarkDirty(offsetCell); if (is_door_open) { MethodInfo method_opened = AccessTools.Method(typeof(Door), "OnSimDoorOpened"); System.Action cb_opened = (System.Action)Delegate.CreateDelegate(typeof(System.Action), __instance, method_opened); HandleVector <Game.CallbackInfo> .Handle handle = Game.Instance.callbackManager.Add(new Game.CallbackInfo(cb_opened)); SimMessages.Dig(offsetCell, handle.index, true); SimMessages.ClearCellProperties(offsetCell, 1); SimMessages.ClearCellProperties(offsetCell, 2); SimMessages.ClearCellProperties(offsetCell, 4); SimMessages.SetCellProperties(offsetCell, (byte)(__instance.CurrentState == Door.ControlState.Auto ? 7 : 4)); if (__instance.ShouldBlockFallingSand) { SimMessages.ClearCellProperties(offsetCell, 4); } } else { MethodInfo method_closed = AccessTools.Method(typeof(Door), "OnSimDoorClosed"); System.Action cb_closed = (System.Action)Delegate.CreateDelegate(typeof(System.Action), __instance, method_closed); HandleVector <Game.CallbackInfo> .Handle handle = Game.Instance.callbackManager.Add(new Game.CallbackInfo(cb_closed)); float temperature = component.Temperature; if (temperature <= 0f) { temperature = component.Temperature; } SimMessages.ReplaceAndDisplaceElement(offsetCell, component.ElementID, CellEventLogger.Instance.DoorClose, mass, temperature, byte.MaxValue, 0, handle.index); SimMessages.ClearCellProperties(offsetCell, 1); SimMessages.ClearCellProperties(offsetCell, 2); SimMessages.SetCellProperties(offsetCell, 4); } } } return(false); }
private void SetSimState(bool is_door_open, IList <int> cells) { PrimaryElement component = GetComponent <PrimaryElement>(); float num = component.Mass / (float)cells.Count; for (int i = 0; i < cells.Count; i++) { int num2 = cells[i]; DoorType doorType = this.doorType; if (doorType == DoorType.Pressure || doorType == DoorType.Sealed || doorType == DoorType.ManualPressure) { World.Instance.groundRenderer.MarkDirty(num2); if (is_door_open) { SimMessages.Dig(num2, Game.Instance.callbackManager.Add(new Game.CallbackInfo(OnSimDoorOpened, false)).index); if (ShouldBlockFallingSand) { SimMessages.ClearCellProperties(num2, 4); } else { SimMessages.SetCellProperties(num2, 4); } } else { HandleVector <Game.CallbackInfo> .Handle handle = Game.Instance.callbackManager.Add(new Game.CallbackInfo(OnSimDoorClosed, false)); float temperature = component.Temperature; if (temperature <= 0f) { temperature = component.Temperature; } int gameCell = num2; SimHashes elementID = component.ElementID; CellElementEvent doorClose = CellEventLogger.Instance.DoorClose; float mass = num; float temperature2 = temperature; int index = handle.index; SimMessages.ReplaceAndDisplaceElement(gameCell, elementID, doorClose, mass, temperature2, byte.MaxValue, 0, index); SimMessages.SetCellProperties(num2, 4); } } } }
/// <summary> /// Applied before InstantlyFinish runs. /// </summary> internal static bool Prefix(Diggable __instance, Worker worker, ref bool __result) { bool cont = true; if (__instance != null) { int cell = Grid.PosToCell(__instance); Element element; // Complete by removing the cell instantaneously if (Grid.IsValidCell(cell) && (element = Grid.Element[cell]) != null && element.hardness > 254) { if (worker != null) { // Give some experience worker.Work(1.0f); } SimMessages.Dig(cell); __result = true; cont = false; } } return(cont); }
public void OnKeyDown(KButtonEvent e) { if (!enabled) { return; } if (e.TryConsume(Action.DebugSpawnMinion)) { SpawnMinion(); } else if (e.TryConsume(Action.DebugSpawnStressTest)) { for (int i = 0; i < 60; i++) { SpawnMinion(); } } else if (e.TryConsume(Action.DebugSuperTestMode)) { if (!superTestMode) { Time.timeScale = 15f; superTestMode = true; } else { Time.timeScale = 1f; superTestMode = false; } } else if (e.TryConsume(Action.DebugUltraTestMode)) { if (!ultraTestMode) { Time.timeScale = 30f; ultraTestMode = true; } else { Time.timeScale = 1f; ultraTestMode = false; } } else if (e.TryConsume(Action.DebugSlowTestMode)) { if (!slowTestMode) { Time.timeScale = 0.06f; slowTestMode = true; } else { Time.timeScale = 1f; slowTestMode = false; } } else if (e.TryConsume(Action.DebugDig)) { int mouseCell = GetMouseCell(); SimMessages.Dig(mouseCell, -1); } else if (e.TryConsume(Action.DebugInstantBuildMode)) { InstantBuildMode = !InstantBuildMode; if ((UnityEngine.Object)Game.Instance == (UnityEngine.Object)null) { return; } if ((UnityEngine.Object)PlanScreen.Instance != (UnityEngine.Object)null) { PlanScreen.Instance.Refresh(); } if ((UnityEngine.Object)BuildMenu.Instance != (UnityEngine.Object)null) { BuildMenu.Instance.Refresh(); } if ((UnityEngine.Object)OverlayMenu.Instance != (UnityEngine.Object)null) { OverlayMenu.Instance.Refresh(); } if ((UnityEngine.Object)ConsumerManager.instance != (UnityEngine.Object)null) { ConsumerManager.instance.RefreshDiscovered(null); } if ((UnityEngine.Object)ManagementMenu.Instance != (UnityEngine.Object)null) { ManagementMenu.Instance.CheckResearch(null); ManagementMenu.Instance.CheckSkills(null); ManagementMenu.Instance.CheckStarmap(null); } Game.Instance.Trigger(1594320620, "all_the_things"); } else if (e.TryConsume(Action.DebugExplosion)) { Vector3 mousePos = KInputManager.GetMousePos(); Vector3 position = Camera.main.transform.GetPosition(); mousePos.z = 0f - position.z - Grid.CellSizeInMeters; Vector3 explosion_pos = Camera.main.ScreenToWorldPoint(mousePos); GameUtil.CreateExplosion(explosion_pos); } else if (e.TryConsume(Action.DebugLockCursor)) { if (GenericGameSettings.instance.developerDebugEnable) { KInputManager.isMousePosLocked = !KInputManager.isMousePosLocked; KInputManager.lockedMousePos = KInputManager.GetMousePos(); } } else if (e.TryConsume(Action.DebugDiscoverAllElements)) { if ((UnityEngine.Object)WorldInventory.Instance != (UnityEngine.Object)null) { foreach (Element element in ElementLoader.elements) { WorldInventory.Instance.Discover(element.tag, element.GetMaterialCategoryTag()); } } } else if (e.TryConsume(Action.DebugToggleUI)) { ToggleScreenshotMode(); } else if (e.TryConsume(Action.SreenShot1x)) { string filename = Path.ChangeExtension(SaveLoader.GetActiveSaveFilePath(), ".png"); ScreenCapture.CaptureScreenshot(filename, 1); } else if (e.TryConsume(Action.SreenShot2x)) { string filename2 = Path.ChangeExtension(SaveLoader.GetActiveSaveFilePath(), ".png"); ScreenCapture.CaptureScreenshot(filename2, 2); } else if (e.TryConsume(Action.SreenShot8x)) { string filename3 = Path.ChangeExtension(SaveLoader.GetActiveSaveFilePath(), ".png"); ScreenCapture.CaptureScreenshot(filename3, 8); } else if (e.TryConsume(Action.SreenShot32x)) { string filename4 = Path.ChangeExtension(SaveLoader.GetActiveSaveFilePath(), ".png"); ScreenCapture.CaptureScreenshot(filename4, 32); } else if (e.TryConsume(Action.DebugCellInfo)) { DebugCellInfo = !DebugCellInfo; } else if (e.TryConsume(Action.DebugToggle)) { if ((UnityEngine.Object)Game.Instance != (UnityEngine.Object)null) { Game.Instance.UpdateGameActiveRegion(0, 0, Grid.WidthInCells, Grid.HeightInCells); SaveGame.Instance.worldGenSpawner.SpawnEverything(); } if ((UnityEngine.Object)DebugPaintElementScreen.Instance != (UnityEngine.Object)null) { bool activeSelf = DebugPaintElementScreen.Instance.gameObject.activeSelf; DebugPaintElementScreen.Instance.gameObject.SetActive(!activeSelf); if ((bool)DebugElementMenu.Instance && DebugElementMenu.Instance.root.activeSelf) { DebugElementMenu.Instance.root.SetActive(false); } DebugBaseTemplateButton.Instance.gameObject.SetActive(!activeSelf); PropertyTextures.FogOfWarScale = (float)((!activeSelf) ? 1 : 0); if ((UnityEngine.Object)CameraController.Instance != (UnityEngine.Object)null) { CameraController.Instance.EnableFreeCamera(!activeSelf); } } } else if (e.TryConsume(Action.DebugCollectGarbage)) { GC.Collect(); } else if (e.TryConsume(Action.DebugInvincible)) { InvincibleMode = !InvincibleMode; } else if (e.TryConsume(Action.DebugVisualTest)) { Scenario.Instance.SetupVisualTest(); } else if (e.TryConsume(Action.DebugGameplayTest)) { Scenario.Instance.SetupGameplayTest(); } else if (e.TryConsume(Action.DebugElementTest)) { Scenario.Instance.SetupElementTest(); } else if (e.TryConsume(Action.ToggleProfiler)) { Sim.SIM_HandleMessage(-409964931, 0, null); } else if (e.TryConsume(Action.DebugRefreshNavCell)) { Pathfinding.Instance.RefreshNavCell(GetMouseCell()); } else if (e.TryConsume(Action.DebugToggleSelectInEditor)) { SetSelectInEditor(!SelectInEditor); } else if (e.TryConsume(Action.DebugGotoTarget)) { Debug.Log("Debug GoTo"); Game.Instance.Trigger(775300118, null); foreach (Brain item in Components.Brains.Items) { item.GetSMI <DebugGoToMonitor.Instance>()?.GoToCursor(); item.GetSMI <CreatureDebugGoToMonitor.Instance>()?.GoToCursor(); } } else if (e.TryConsume(Action.DebugTeleport)) { if ((UnityEngine.Object)SelectTool.Instance == (UnityEngine.Object)null) { return; } KSelectable selected = SelectTool.Instance.selected; if ((UnityEngine.Object)selected != (UnityEngine.Object)null) { int mouseCell2 = GetMouseCell(); if (!Grid.IsValidBuildingCell(mouseCell2)) { PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Negative, UI.DEBUG_TOOLS.INVALID_LOCATION, null, GetMousePos(), 1.5f, false, true); return; } selected.transform.SetPosition(Grid.CellToPosCBC(mouseCell2, Grid.SceneLayer.Move)); } } else if (!e.TryConsume(Action.DebugPlace) && !e.TryConsume(Action.DebugSelectMaterial)) { if (e.TryConsume(Action.DebugNotification)) { if (GenericGameSettings.instance.developerDebugEnable) { Tutorial.Instance.DebugNotification(); } } else if (e.TryConsume(Action.DebugNotificationMessage)) { if (GenericGameSettings.instance.developerDebugEnable) { Tutorial.Instance.DebugNotificationMessage(); } } else if (e.TryConsume(Action.DebugSuperSpeed)) { if ((UnityEngine.Object)SpeedControlScreen.Instance != (UnityEngine.Object)null) { SpeedControlScreen.Instance.ToggleRidiculousSpeed(); } } else if (e.TryConsume(Action.DebugGameStep)) { if ((UnityEngine.Object)SpeedControlScreen.Instance != (UnityEngine.Object)null) { SpeedControlScreen.Instance.DebugStepFrame(); } } else if (e.TryConsume(Action.DebugSimStep)) { Game.Instance.ForceSimStep(); } else if (e.TryConsume(Action.DebugToggleMusic)) { AudioDebug.Get().ToggleMusic(); } else if (e.TryConsume(Action.DebugRiverTest)) { Scenario.Instance.SetupRiverTest(); } else if (e.TryConsume(Action.DebugTileTest)) { Scenario.Instance.SetupTileTest(); } else if (e.TryConsume(Action.DebugForceLightEverywhere)) { PropertyTextures.instance.ForceLightEverywhere = !PropertyTextures.instance.ForceLightEverywhere; } else if (e.TryConsume(Action.DebugPathFinding)) { DebugPathFinding = !DebugPathFinding; Debug.Log("DebugPathFinding=" + DebugPathFinding); } else if (!e.TryConsume(Action.DebugFocus)) { if (e.TryConsume(Action.DebugReportBug)) { if (GenericGameSettings.instance.developerDebugEnable) { int num = 0; string validSaveFilename; while (true) { validSaveFilename = SaveScreen.GetValidSaveFilename("bug_report_savefile_" + num.ToString()); if (!File.Exists(validSaveFilename)) { break; } num++; } string save_file = "No save file (front end)"; if ((UnityEngine.Object)SaveLoader.Instance != (UnityEngine.Object)null) { save_file = SaveLoader.Instance.Save(validSaveFilename, false, false); } KCrashReporter.ReportBug("Bug Report", save_file); } else { Debug.Log("Debug crash keys are not enabled."); } } else if (e.TryConsume(Action.DebugTriggerException)) { if (GenericGameSettings.instance.developerDebugEnable) { string str = Guid.NewGuid().ToString(); StackTrace stackTrace = new StackTrace(1, true); str = str + "\n" + stackTrace.ToString(); KCrashReporter.ReportError("Debug crash with random stack", str, null, ScreenPrefabs.Instance.ConfirmDialogScreen, string.Empty); } } else if (e.TryConsume(Action.DebugTriggerError)) { if (GenericGameSettings.instance.developerDebugEnable) { Debug.LogError("Oooops! Testing error!"); } } else if (e.TryConsume(Action.DebugDumpGCRoots)) { GarbageProfiler.DebugDumpRootItems(); } else if (e.TryConsume(Action.DebugDumpGarbageReferences)) { GarbageProfiler.DebugDumpGarbageStats(); } else if (e.TryConsume(Action.DebugDumpEventData)) { if (GenericGameSettings.instance.developerDebugEnable) { KObjectManager.Instance.DumpEventData(); } } else if (e.TryConsume(Action.DebugDumpSceneParitionerLeakData)) { if (!GenericGameSettings.instance.developerDebugEnable) { goto IL_0b5e; } } else if (e.TryConsume(Action.DebugCrashSim)) { if (GenericGameSettings.instance.developerDebugEnable) { Sim.SIM_DebugCrash(); } } else if (e.TryConsume(Action.DebugNextCall)) { DebugNextCall = true; } else if (e.TryConsume(Action.DebugTogglePersonalPriorityComparison)) { Chore.ENABLE_PERSONAL_PRIORITIES = !Chore.ENABLE_PERSONAL_PRIORITIES; } } } goto IL_0b5e; IL_0b5e: if (e.Consumed && (UnityEngine.Object)Game.Instance != (UnityEngine.Object)null) { Game.Instance.debugWasUsed = true; KCrashReporter.debugWasUsed = true; } }
private static bool Prefix(Door __instance, bool is_door_open, IList <int> cells) { Door.ControlState controlState = Traverse.Create(__instance).Field("controlState").GetValue <Door.ControlState>(); PrimaryElement component = __instance.GetComponent <PrimaryElement>(); float num = component.Mass / (float)cells.Count; MethodInfo method_closed = AccessTools.Method(typeof(Door), "OnSimDoorClosed", null, null); System.Action cb_closed = (System.Action)Delegate.CreateDelegate(typeof(System.Action), __instance, method_closed); MethodInfo method_opened = AccessTools.Method(typeof(Door), "OnSimDoorOpened", null, null); System.Action cb_opened = (System.Action)Delegate.CreateDelegate(typeof(System.Action), __instance, method_opened); for (int i = 0; i < cells.Count; i++) { int num2 = cells[i]; Door.DoorType doorType = __instance.doorType; if (doorType == Door.DoorType.Pressure || doorType == Door.DoorType.Sealed || doorType == Door.DoorType.ManualPressure) { World.Instance.groundRenderer.MarkDirty(num2); if (is_door_open) { SimMessages.Dig(num2, Game.Instance.callbackManager.Add(new Game.CallbackInfo(cb_opened, false)).index); if (controlState == Door.ControlState.Auto) { HandleVector <Game.CallbackInfo> .Handle handle = Game.Instance.callbackManager.Add(new Game.CallbackInfo(cb_opened, false)); float temperature = component.Temperature; if (temperature <= 0f) { temperature = component.Temperature; } int gameCell = num2; SimHashes elementID = component.ElementID; CellElementEvent doorOpen = CellEventLogger.Instance.DoorOpen; float mass = num; float temperature2 = temperature; int index = handle.index; SimMessages.ReplaceAndDisplaceElement(gameCell, elementID, doorOpen, mass, temperature2, byte.MaxValue, 0, index); SimMessages.SetCellProperties(num2, 4); } else if (__instance.ShouldBlockFallingSand) { SimMessages.ClearCellProperties(num2, 4); } else { SimMessages.SetCellProperties(num2, 4); } } else { HandleVector <Game.CallbackInfo> .Handle handle = Game.Instance.callbackManager.Add(new Game.CallbackInfo(cb_closed, false)); float temperature = component.Temperature; if (temperature <= 0f) { temperature = component.Temperature; } int gameCell = num2; SimHashes elementID = component.ElementID; CellElementEvent doorClose = CellEventLogger.Instance.DoorClose; float mass = num; float temperature2 = temperature; int index = handle.index; SimMessages.ReplaceAndDisplaceElement(gameCell, elementID, doorClose, mass, temperature2, byte.MaxValue, 0, index); SimMessages.SetCellProperties(num2, 4); } } } return(false); }
protected override void OnDragTool(int cell, int distFromOrigin) { if (Grid.IsValidCell(cell)) { switch (type) { case Type.PaintPlant: break; case Type.Dig: SimMessages.Dig(cell, -1); break; case Type.Heat: SimMessages.ModifyEnergy(cell, 10000f, 10000f, SimMessages.EnergySourceID.DebugHeat); break; case Type.Cool: SimMessages.ModifyEnergy(cell, -10000f, 10000f, SimMessages.EnergySourceID.DebugCool); break; case Type.AddPressure: SimMessages.ModifyMass(cell, 10000f, byte.MaxValue, 0, CellEventLogger.Instance.DebugToolModifyMass, 293f, SimHashes.Oxygen); break; case Type.RemovePressure: SimMessages.ModifyMass(cell, -10000f, byte.MaxValue, 0, CellEventLogger.Instance.DebugToolModifyMass, 0f, SimHashes.Oxygen); break; case Type.ReplaceSubstance: DoReplaceSubstance(cell); break; case Type.FillReplaceSubstance: { GameUtil.FloodFillNext.Clear(); GameUtil.FloodFillVisited.Clear(); SimHashes elem_hash = Grid.Element[cell].id; GameUtil.FloodFillConditional(cell, delegate(int check_cell) { bool result = false; if (Grid.Element[check_cell].id == elem_hash) { result = true; DoReplaceSubstance(check_cell); } return(result); }, GameUtil.FloodFillVisited, null); break; } case Type.Clear: ClearCell(cell); break; case Type.AddSelection: DebugBaseTemplateButton.Instance.AddToSelection(cell); break; case Type.RemoveSelection: DebugBaseTemplateButton.Instance.RemoveFromSelection(cell); break; case Type.Destroy: DestroyCell(cell); break; case Type.Deconstruct: DeconstructCell(cell); break; case Type.Sample: DebugPaintElementScreen.Instance.SampleCell(cell); break; } } }