public static void OnDismantle(BuildTool_Dismantle __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }
            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            List <int> objectIds = __instance.DetermineDismantle().ToList();

            if (objectIds.Count <= 0)
            {
                return;
            }

            BlueprintData blueprint = UndoUtils.GenerateBlueprint(objectIds, out Vector3 position);

            if (blueprint.buildings.Length > 0 && !position.Equals(Vector3.zero))
            {
                PlayerUndo data = UndoManager.GetCurrentPlayerData();
                data.AddUndoItem(new UndoDismantle(data, objectIds, blueprint, new[] { position }, 0));
            }
        }
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            CodeMatcher matcher = new CodeMatcher(instructions)
                                  .End().MatchBack(false,
                                                   new CodeMatch(OpCodes.Ldarg_0),
                                                   new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(BuildTool), nameof(BuildTool.buildPreviews))),
                                                   new CodeMatch(OpCodes.Callvirt))
                                  .Advance(1)
                                  .InsertAndAdvance(Transpilers.EmitDelegate <Action <BuildTool_Inserter> >(tool =>
            {
                if (UndoManager.IgnoreAllEvents.Value)
                {
                    return;
                }
                if (NebulaModAPI.IsMultiplayerActive)
                {
                    if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                    {
                        return;
                    }
                }

                IEnumerable <int> objectIds = tool.buildPreviews.Select(preview => preview.objId);

                PlayerUndo data = UndoManager.GetCurrentPlayerData();
                data.AddUndoItem(new UndoBuild(data, objectIds));
            }))
                                  .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0));

            return(matcher.InstructionEnumeration());
        }
        public static void OnPaste(BuildTool_BlueprintPaste __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }
            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            List <int> objectIds = new List <int>(__instance.bpCursor);

            for (int l = 0; l < __instance.bpCursor; l++)
            {
                BuildPreview preview = __instance.bpPool[l];
                objectIds.Add(preview.objId);
            }

            Vector3[] dots = new Vector3[__instance.dotsCursor];
            Array.Copy(__instance.dotsSnapped, dots, __instance.dotsCursor);

            PlayerUndo    data = UndoManager.GetCurrentPlayerData();
            UndoBlueprint undo = new UndoBlueprint(data, objectIds, __instance.blueprint, dots, __instance.yaw);

            data.AddUndoItem(undo);
        }
        public static void OnPathAddonBuilt(BuildTool_PathAddon __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }
            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            PlayerUndo data = UndoManager.GetCurrentPlayerData();

            data.AddUndoItem(new UndoPathAddon(data, __instance.handbp.objId));
        }
        public static void OnClickBuilt(BuildTool_Click __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }
            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            IEnumerable <int> objectIds = __instance.buildPreviews.Select(preview => preview.objId);

            PlayerUndo data = UndoManager.GetCurrentPlayerData();

            data.AddUndoItem(new UndoBuild(data, objectIds));
        }
Exemple #6
0
        public static void OnUpgradePost(BuildTool_Upgrade __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }

            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            RecordUpgrades = false;

            if (upgradeList.Count > 0)
            {
                PlayerUndo data = UndoManager.GetCurrentPlayerData();
                data.AddUndoItem(new UndoUpgrade(data, upgradeList));
            }
        }