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 static bool Prefix(Door __instance, bool is_door_open, IList <int> cells) { // If the attached gameobject doesn't exist, exit here if (__instance.gameObject == null) { return(true); } // Get the door control state Door.ControlState controlState = Traverse.Create(__instance).Field("controlState").GetValue <Door.ControlState>(); // Get the door type Door.DoorType doorType = __instance.doorType; // Exit here if the door type is 'Internal', or the door state is set to 'Opened' if (doorType == Door.DoorType.Internal || controlState == Door.ControlState.Opened) { return(true); } // Get the mass of the door (per cell) PrimaryElement element = __instance.GetComponent <PrimaryElement>(); float mass_per_cell = element.Mass / cells.Count; // Loop over each cell making up the door for (int i = 0; i < cells.Count; i++) { int cell = cells[i]; SimMessages.SetCellProperties(cell, 4); // On opening if (is_door_open) { MethodInfo method_opened = AccessTools.Method(typeof(Door), "OnSimDoorOpened", null, null); 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, false)); SimMessages.ReplaceAndDisplaceElement(cell, element.ElementID, CellEventLogger.Instance.DoorOpen, mass_per_cell, element.Temperature, byte.MaxValue, 0, handle.index); } // On closing else { MethodInfo method_closed = AccessTools.Method(typeof(Door), "OnSimDoorClosed", null, null); 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, false)); SimMessages.ReplaceAndDisplaceElement(cell, element.ElementID, CellEventLogger.Instance.DoorClose, mass_per_cell, element.Temperature, byte.MaxValue, 0, handle.index); } } // Exit, do not run the orginal method return(false); }
/// <summary> /// Get the opposite door /// </summary> /// <param name="type">world side</param> /// <returns></returns> public Door GetOpposite(Door.DoorType type) { switch (type) { case Door.DoorType.North: return(SouthDoor); case Door.DoorType.South: return(NorthDoor); case Door.DoorType.East: return(WestDoor); case Door.DoorType.West: return(EastDoor); default: return(null); } }
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); }