Jump to content

[Help] Last Update Mod Bug


Recommended Posts

Salve a tutti Modders,

sI'm here to ask for help. I have developed a simple Mod to make an Airlock. The operation was basic: I rewrote the "SetSimState" method of the door to duplicate the "push back" of the elements (simulating the closing effect) that tried to cross it when it was open.

Code in spoiler:

Spoiler

 [HarmonyPatch(typeof(Door), "SetSimState")]
    internal class AirlockDoor_SetSimState
    {
        private static bool Prefix(Door __instance, bool is_door_open, IList<int> cells)
        {
            if (__instance.gameObject == null)
                return true;

            if (!__instance.gameObject.ToString().Contains("AirlockMechanizedDoorComplete"))
                return true;

            Door.ControlState controlState = Traverse.Create(__instance).Field("controlState").GetValue<Door.ControlState>();
            Door.DoorType doorType = __instance.doorType;

            Debug.Log($"Door Control State: {controlState} - DoorType : {doorType}");

            if (doorType == Door.DoorType.Internal || controlState == Door.ControlState.Opened)
            { return true; }


            PrimaryElement element = __instance.GetComponent<PrimaryElement>();
            float mass_per_cell = element.Mass / cells.Count;

            for (int i = 0; i < cells.Count; i++)
            {
                int cell = cells[i];
                // On opening
                if (is_door_open)
                {
                    Debug.Log("Opening");
                    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
                {
                    Debug.Log("Closing");
                    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);
                }
                SimMessages.SetCellProperties(cell, 4);
            }

            return false;
        }
    }

 

With this update however I believe that this "push back" somehow also applies when the door is open by pushing my duplicant away. 

Because if with a duplicator I try to stop in the middle of the door it is pushed back immediately, and this also happens when it tries to build / demolish something and stops at the door. (construction / demolition goes on but animation cancels ... bad bad thing)

Do you have any ideas?

P.S. this only happens in the DLC, in Vanilla it continues to function normally

Link to comment
https://forums.kleientertainment.com/forums/topic/126608-help-last-update-mod-bug/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...