예제 #1
0
        static void Postfix(Dialog_DebugOptionLister __instance, string label, Action toolAction, Container <DebugTool>?__state)
        {
            // New tool chosen
            if (__state != null && DebugTools.curTool != __state?.Inner)
            {
                var originalAction = (toolAction.Target as DebugListerContext)?.originalAction ?? toolAction;
                int hash           = Gen.HashCombineInt(GenText.StableStringHash(originalAction.Method.MethodDesc()), GenText.StableStringHash(label));

                if (__instance is Dialog_DebugActionsMenu)
                {
                    var source = MpDebugTools.ListingSource();
                    if (source == DebugSource.None)
                    {
                        return;
                    }

                    Map map = source == DebugSource.ListingMap ? Find.CurrentMap : null;

                    MpDebugTools.SendCmd(source, hash, map);
                    DebugTools.curTool = null;
                }

                if (__instance is Dialog_DebugOptionListLister lister)
                {
                    var context = (DebugListerContext)toolAction.Target;
                    MpDebugTools.SendCmd(DebugSource.Lister, hash, context.map);
                    DebugTools.curTool = null;
                }
            }
        }
예제 #2
0
        static void Postfix(Dialog_DebugOptionLister __instance, string label, Action toolAction, Container <DebugTool>?__state)
        {
            // New tool chosen
            if (!__state.HasValue || DebugTools.curTool == __state?.Inner)
            {
                return;
            }

            int hash = Gen.HashCombineInt(GenText.StableStringHash(toolAction.Method.MethodDesc()), GenText.StableStringHash(label));

            if (__instance is Dialog_DebugActionsMenu)
            {
                var source = MpDebugTools.ListingSource();
                if (source == DebugSource.None)
                {
                    return;
                }

                Map map = source == DebugSource.ListingMap ? Find.CurrentMap : null;

                MpDebugTools.SendCmd(source, hash, map);
                DebugTools.curTool = null;
            }

            else if (__instance is Dialog_DebugOptionListLister lister)
            {
                Map map = MpDebugTools.CurrentPlayerState.Map;
                if (ListingMapMarker.drawing)
                {
                    map = Find.CurrentMap;
                }
                MpDebugTools.SendCmd(DebugSource.Lister, hash, map);
                DebugTools.curTool = null;
            }
        }
예제 #3
0
        static bool Prefix(Dialog_DebugOptionLister __instance, string label, ref Action action)
        {
            if (Multiplayer.Client == null)
            {
                return(true);
            }
            if (Current.ProgramState == ProgramState.Playing && !Multiplayer.WorldComp.debugMode)
            {
                return(true);
            }

            var originalAction = (action.Target as DebugListerContext)?.originalAction ?? action;

            int hash = Gen.HashCombineInt(
                GenText.StableStringHash(originalAction.Method.MethodDesc()),
                GenText.StableStringHash(label)
                );

            if (Multiplayer.ExecutingCmds)
            {
                if (hash == MpDebugTools.currentHash)
                {
                    action();
                }

                return(false);
            }

            if (__instance is Dialog_DebugActionsMenu)
            {
                var source = MpDebugTools.ListingSource();
                if (source == DebugSource.None)
                {
                    return(true);
                }

                Map map = source == DebugSource.ListingMap ? Find.CurrentMap : null;

                if (ListingIncidentMarker.target != null)
                {
                    map = ListingIncidentMarker.target as Map;
                }

                action = () => MpDebugTools.SendCmd(source, hash, map);
            }

            if (__instance is Dialog_DebugOptionListLister)
            {
                var context = (DebugListerContext)action.Target;
                action = () => MpDebugTools.SendCmd(DebugSource.Lister, hash, context.map);
            }

            return(true);
        }
예제 #4
0
        static bool Prefix(Window window)
        {
            if (Multiplayer.Client == null)
            {
                return(true);
            }
            if (!Multiplayer.ExecutingCmds)
            {
                return(true);
            }
            if (!Multiplayer.GameComp.debugMode)
            {
                return(true);
            }

            bool keepOpen = TickPatch.currentExecutingCmdIssuedBySelf;
            var  map      = Multiplayer.MapContext;

            if (window is Dialog_DebugOptionListLister lister)
            {
                MpDebugTools.CurrentPlayerState.window = lister.options;
                MpDebugTools.CurrentPlayerState.mapId  = map?.uniqueID ?? -1;

                return(keepOpen);
            }

            if (window is FloatMenu menu)
            {
                var options = menu.options;

                if (keepOpen)
                {
                    menu.options = new List <FloatMenuOption>();

                    foreach (var option in options)
                    {
                        var copy = new FloatMenuOption(option.labelInt, option.action);
                        int hash = copy.Hash();
                        copy.action = () => MpDebugTools.SendCmd(DebugSource.FloatMenu, hash, map);
                        menu.options.Add(copy);
                    }
                }

                MpDebugTools.CurrentPlayerState.window = options;
                return(keepOpen);
            }

            return(true);
        }
예제 #5
0
        static bool Prefix(Window window)
        {
            if (Multiplayer.Client == null)
            {
                return(true);
            }
            if (!Multiplayer.ExecutingCmds)
            {
                return(true);
            }
            if (!Multiplayer.WorldComp.debugMode)
            {
                return(true);
            }

            bool keepOpen = TickPatch.currentExecutingCmdIssuedBySelf;
            var  map      = Multiplayer.MapContext;

            if (window is Dialog_DebugOptionListLister lister)
            {
                var options = lister.options;

                if (keepOpen)
                {
                    lister.options = new List <DebugMenuOption>();

                    foreach (var option in options)
                    {
                        var copy = option;
                        copy.method = new DebugListerContext()
                        {
                            map = map, originalAction = copy.method
                        }.Do;
                        lister.options.Add(copy);
                    }
                }

                Multiplayer.game.playerDebugState.GetOrAddNew(MpDebugTools.currentPlayer).window = options;
                return(keepOpen);
            }

            if (window is FloatMenu menu)
            {
                var options = menu.options;

                if (keepOpen)
                {
                    menu.options = new List <FloatMenuOption>();

                    foreach (var option in options)
                    {
                        var copy = new FloatMenuOption(option.labelInt, option.action);
                        int hash = copy.Hash();
                        copy.action = () => MpDebugTools.SendCmd(DebugSource.FloatMenu, hash, map);
                        menu.options.Add(copy);
                    }
                }

                Multiplayer.game.playerDebugState.GetOrAddNew(MpDebugTools.currentPlayer).window = options;
                return(keepOpen);
            }

            return(true);
        }