예제 #1
0
        public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
        {
            TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
            try
            {
                var world      = GameManager.Instance.World ?? throw new FriendlyMessageException(Resources.ErrorWorldNotReady);
                var chunkCache = world.ChunkCache ?? throw new FriendlyMessageException(Resources.ErrorChunkCacheNotReady);

                (var pos1, var pos2) = ParseParams(parameters, senderInfo);
                WorldTools.OrderAreaBounds(ref pos1, ref pos2);

                // Check if all needed chunks are in cache
                foreach (var chunkKey in GetChunksForArea(pos1, pos2, +1))
                {
                    if (!chunkCache.ContainsChunkSync(chunkKey))
                    {
                        throw new FriendlyMessageException(Resources.ErrorAreaTooFarAway);
                    }
                }

                ThreadManager.AddSingleTask(info => RegenerateChunks(pos1, pos2, senderInfo));
            }
            catch (Exception ex)
            {
                CommandTools.HandleCommandException(ex);
            }
        }
예제 #2
0
        public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
        {
            TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
            try
            {
                if (parameters.Count == 0)
                {
                    SdtdConsole.Instance.Output($"Patch for {CorpseDupe.PatchName} is {(PersistentData.Instance.PatchCorpseItemDupeExploit ? "ENABLED" : "DISABLED")}.");
                    return;
                }

                if (parameters.Count == 1 || parameters.Count > 2)
                {
                    throw new FriendlyMessageException(Resources.ErrorParameerCountNotValid);
                }

                var    patchName = parameters[0];
                string mode      = parameters[1];

                if (mode != "/on" && mode != "/off")
                {
                    throw new FriendlyMessageException($"Wrong second parameter \"{parameters[1]}\". See help.");
                }

                switch (patchName)
                {
                case "corpse-dupe":
                    if (mode == "/on")
                    {
                        if (PersistentData.Instance.PatchCorpseItemDupeExploit)
                        {
                            throw new FriendlyMessageException($"Patch for {CorpseDupe.PatchName} is already enabled.");
                        }
                        PersistentData.Instance.PatchCorpseItemDupeExploit = true;
                        PatchTools.ApplyPatches();
                        PersistentData.Instance.Save();     // save after patching in case something crashes
                        SdtdConsole.Instance.Output($"Patch for {CorpseDupe.PatchName} enabled.");
                    }
                    else if (mode == "/off")
                    {
                        if (!PersistentData.Instance.PatchCorpseItemDupeExploit)
                        {
                            throw new FriendlyMessageException($"Patch for {CorpseDupe.PatchName} is already disabled.");
                        }
                        PersistentData.Instance.PatchCorpseItemDupeExploit = false;
                        PersistentData.Instance.Save();
                        SdtdConsole.Instance.Output($"Patch for {CorpseDupe.PatchName} disabled.");
                    }
                    break;

                default:
                    throw new FriendlyMessageException($"Unknown patch name \"{patchName}\". See help.");
                }
            }
            catch (Exception ex)
            {
                CommandTools.HandleCommandException(ex);
            }
        }
 public override void Execute(List <string> _params, CommandSenderInfo _senderInfo)
 {
     TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
     try
     {
         _action(_params, _senderInfo);
     }
     catch (Exception ex)
     {
         CommandTools.HandleCommandException(ex);
     }
 }
예제 #4
0
 /// <summary>
 /// Called when the game is in the process of shutting down, after connections were closed and resources were unloaded.
 /// </summary>
 public override void GameShutdown()
 {
     try
     {
         Log.Debug("Api.GameShutdown called.");
         TelemetryTools.Shutdown();
         CommandTools.InvokeScriptEvents(ScriptEvent.gameShutdown, () => new ScriptEventArgs());
     }
     catch (Exception ex)
     {
         CommandTools.HandleEventException(ex);
     }
 }
        public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
        {
            TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
            try
            {
                if (parameters.Count == 0)
                {
                    ListWhitelist();
                }
                else if (parameters.Count == 1)
                {
                    if (parameters[0] == "clear")
                    {
                        ClearWhitelist();
                    }
                    else
                    {
                        throw new FriendlyMessageException("Could not understand parameter. See help dj-eac-whitelist.");
                    }
                }
                else if (parameters.Count == 2)
                {
                    // ParseParamPartialNameOrId already sends error message when none or too many users were found
                    if (ConsoleHelper.ParseParamPartialNameOrId(parameters[1], out string steamId, out ClientInfo clientInfo, true) != 1)
                    {
                        return;
                    }

                    if (parameters[0] == "add")
                    {
                        AddToWhitelist(steamId);
                    }
                    else if (parameters[0] == "remove")
                    {
                        RemoveFromWhitelist(steamId);
                    }
                    else
                    {
                        throw new FriendlyMessageException("Could not understand first parameter. See help dj-eac-whitelist.");
                    }
                }
                else
                {
                    throw new FriendlyMessageException(Resources.ErrorParameerCountNotValid);
                }
            }
            catch (Exception ex)
            {
                CommandTools.HandleCommandException(ex);
            }
        }
예제 #6
0
        public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
        {
            TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
            string prefabName    = null;
            bool   exportStarted = false;

            try
            {
                Vector3i pos1, pos2;
                (prefabName, pos1, pos2) = ParseParams(parameters, senderInfo);
                WorldTools.OrderAreaBounds(ref pos1, ref pos2);
                // Saving tile entities first, because that also checks if chunks are loaded
                exportStarted = true;
                SaveTileEntities(prefabName, pos1, pos2);
                SavePrefab(prefabName, pos1, pos2);

                SdtdConsole.Instance.Output($"Prefab {prefabName} with block metadata exported. Area mapped from {pos1} to {pos2}.");
            }
            catch (Exception ex)
            {
                // Clean up half-writen files. All or nothing.
                if (exportStarted && !string.IsNullOrEmpty(prefabName))
                {
                    try
                    {
                        var teFilePath = Path.Combine(Constants.PrefabsFolder, prefabName + TileEntityFileExtension);
                        if (File.Exists(teFilePath))
                        {
                            File.Delete(teFilePath);
                        }
                        var ttsFilePath = Path.Combine(Constants.PrefabsFolder, prefabName + global::Constants.cExtPrefabs);
                        if (File.Exists(ttsFilePath))
                        {
                            File.Delete(ttsFilePath);
                        }
                        var xmlFilePath = Path.Combine(Constants.PrefabsFolder, prefabName + ".xml");
                        if (File.Exists(xmlFilePath))
                        {
                            File.Delete(xmlFilePath);
                        }
                    }
                    catch (Exception)
                    {
                        Log.Warning("Exception thrown while cleaning up files because of another exception: " + ex);
                    }
                }

                CommandTools.HandleCommandException(ex);
            }
        }
예제 #7
0
 public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
 {
     TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
     try
     {
         var ci     = senderInfo.RemoteClientInfo ?? throw new FriendlyMessageException(Resources.ErrorNotRemotePlayer);
         var world  = GameManager.Instance.World ?? throw new FriendlyMessageException(Resources.ErrorWorldNotReady);
         var player = senderInfo.RemoteClientInfo.GetEntityPlayer();
     }
     catch (Exception ex)
     {
         CommandTools.HandleCommandException(ex);
     }
 }
예제 #8
0
        public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
        {
            TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
            try
            {
                ParseParams(parameters, out var tasks, out bool simulate, out bool auto, out int?timerInterval);
                timerInterval = timerInterval ?? 60 * 10; // every 10 minutes by default

                if (auto)
                {
                    if (!PersistentData.Instance.RepairAuto)
                    {
                        PersistentData.Instance.RepairAuto     = true;
                        PersistentData.Instance.RepairTasks    = tasks;
                        PersistentData.Instance.RepairSimulate = simulate;
                        PersistentData.Instance.RepairInterval = timerInterval.Value; // every 10 minutes by default;
                        PersistentData.Instance.Save();
                        RepairEngine.AutoOn();
                    }
                    else
                    {
                        RepairEngine.AutoOff();
                        PersistentData.Instance.RepairAuto    = false;
                        PersistentData.Instance.RepairCounter = 0;
                        PersistentData.Instance.Save();
                    }
                }
                else
                {
                    ThreadManager.AddSingleTask(delegate
                    {
                        try
                        {
                            var repairEngine = new RepairEngine(tasks, simulate, senderInfo);
                            repairEngine.Start();
                        }
                        catch (Exception ex)
                        {
                            Log.Exception(ex);
                            SdtdConsole.Instance.OutputAsync(senderInfo, string.Format(Resources.ErrorDuringCommand, ex.Message));
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                CommandTools.HandleCommandException(ex);
            }
        }
예제 #9
0
        public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
        {
            TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
            try
            {
                var modInfo = Api.GetExecutingMod()?.ModInfo;
                if (modInfo == null)
                {
                    SdtdConsole.Instance.Output(Constants.ModName);
                    SdtdConsole.Instance.Output("Could not load mod infos.");
                }
                else
                {
                    // ReSharper disable once UnreachableCode
                    SdtdConsole.Instance.Output(modInfo.Name.Value + " - Version " + modInfo.Version.Value + (Log.IsDebug ? " DEBUG" : ""));
                    if (modInfo.Name.Value != Constants.ModName)
                    {
                        SdtdConsole.Instance.Output("Original mod name: " + Constants.ModName);
                    }
                    SdtdConsole.Instance.Output(modInfo.Description.Value);
                    if (!string.IsNullOrEmpty(modInfo.Website.Value))
                    {
                        SdtdConsole.Instance.Output("Website: " + modInfo.Website.Value);
                    }
                }

                SdtdConsole.Instance.Output("");

                SdtdConsole.Instance.Output("Operating System: " + Environment.OSVersion);
                SdtdConsole.Instance.Output("Unity version: " + Application.unityVersion);

                var displayName = Type.GetType("Mono.Runtime")?.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
                if (displayName != null)
                {
                    SdtdConsole.Instance.Output("Mono display name: " + displayName.Invoke(null, null));
                }

                var monoRuntimeVersion = Type.GetType("Mono.Runtime")?.Assembly.ImageRuntimeVersion;
                if (monoRuntimeVersion != null)
                {
                    SdtdConsole.Instance.Output("Mono runtime version: " + monoRuntimeVersion);
                }
            }
            catch (Exception ex)
            {
                CommandTools.HandleCommandException(ex);
            }
        }
예제 #10
0
        public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
        {
            TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
            try
            {
                if (parameters.Count == 0)
                {
                    ListStatus();
                    return;
                }

                bool isModeOn  = parameters.Remove("/on");
                bool isModeOff = parameters.Remove("/off");

                if (parameters.Count == 0)
                {
                    throw new FriendlyMessageException("No event names given. See help.");
                }
                if (isModeOn && isModeOff)
                {
                    throw new FriendlyMessageException("Parameters /on and /off cannot be used simultaneously.");
                }
                if (!isModeOn && !isModeOff)
                {
                    throw new FriendlyMessageException("Neither parameter /on nor /off was specified. See help.");
                }

                if (parameters.Contains("all"))
                {
                    if (parameters.Count > 1)
                    {
                        throw new FriendlyMessageException("When using the \"all\" keyword as event name you can't use other event names additionally.");
                    }
                    UpdateAllEvents(isModeOn);
                }
                else
                {
                    UpdateLogEvents(parameters, isModeOn);
                }
            }
            catch (Exception ex)
            {
                CommandTools.HandleCommandException(ex);
            }
        }
예제 #11
0
        /// <summary>
        /// Called when the game started and all objects are ready (e.g. GameManager.Instance.World)
        /// </summary>
        public override void GameStartDone()
        {
            try
            {
                Log.Debug("Api.GameStartDone called.");
                Log.Out("Initializing phase 3/3 ...");
                EacTools.Init();
                CommandTools.InitEvents();
                RepairEngine.InitAuto();
                TelemetryTools.Init();
                Log.Out($"Done initializing {Constants.ModName}.");

                CommandTools.InvokeScriptEvents(ScriptEvent.gameStartDone, () => new ScriptEventArgs());
            }
            catch (Exception ex)
            {
                CommandTools.HandleEventException(ex);
            }
        }
예제 #12
0
        public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
        {
            TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
            try
            {
                var player = senderInfo.GetRemoteClientInfo().GetEntityPlayer();
                var world  = GameManager.Instance.World;

                var worldPosExact = player.GetServerPos();
                SdtdConsole.Instance.Output($"Exact player position in world (x y z): {worldPosExact.x} {worldPosExact.y} {worldPosExact.z}");

                var worldPos = worldPosExact.ToVector3i();
                SdtdConsole.Instance.Output($"Player block position in world (x y z): {worldPos.x} {worldPos.y} {worldPos.z}");

                //string mapPos = Math.Abs(worldPos.z) + (worldPos.z >= 0 ? "N " : "S ") + Math.Abs(worldPos.x) + (worldPos.x >= 0 ? "E " : "W "); // todo: add elevation
                //SdtdConsole.Instance.Output($"Map position in world: {mapPos}"); // todo: incorrect

                var chunkPos = World.toBlock(worldPos);
                SdtdConsole.Instance.Output($"Position in chunk (x y z): {chunkPos.x} {chunkPos.y} {chunkPos.z}");

                var chunkXZ = ChunkTools.WorldPosToChunkXZ(worldPos);
                SdtdConsole.Instance.Output($"Chunk (x z): {chunkXZ.x} {chunkXZ.z}");
                //var chunk = world.GetChunkSync(chunkXZ.x, chunkXZ.z) as Chunk;
                //if (chunk != null && chunk.ChunkCustomData.dict.Count > 0)
                //    SdtdConsole.Instance.Output(DumpCustomChunkData(chunk));

                var areaMasterChunkXY = Chunk.ToAreaMasterChunkPos(worldPos);
                SdtdConsole.Instance.Output($"Area master chunk (x z): {areaMasterChunkXY.x} {areaMasterChunkXY.z}");
                //var araeMasterChunk = world.GetChunkSync(areaMasterChunkXY.x, areaMasterChunkXY.z) as Chunk;
                //if (araeMasterChunk != null && araeMasterChunk.ChunkCustomData.dict.Count > 0)
                //    SdtdConsole.Instance.Output(DumpCustomChunkData(araeMasterChunk));

                var regionXZ = ChunkTools.ChunkXZToRegionXZ(chunkXZ);
                SdtdConsole.Instance.Output($"Region file: r.{regionXZ.x}.{regionXZ.z}.7rg");
            }
            catch (Exception ex)
            {
                CommandTools.HandleCommandException(ex);
            }
        }
예제 #13
0
        public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
        {
            TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
            HashSet <Chunk> affectedChunks = null;

            try
            {
                (string prefabName, Vector3i pos1, int rotate, bool all) = ParseParams(parameters, senderInfo);

                // Will not do anything if chunks are not loaded; so no need to pre-check
                LoadPrefab(prefabName, pos1, rotate, out Vector3i pos2);
                affectedChunks = GetAffectedChunks(pos1, pos2);

                if (all)
                {
                    LoadTileEntities(prefabName, pos1, pos2, rotate);
                }

                SdtdConsole.Instance.Output($"Prefab {prefabName} placed{(all ? " with block metdata" : "")} at {pos1} with rotation {rotate}.");
            }
            catch (Exception ex)
            {
                CommandTools.HandleCommandException(ex);
            }

            // Error could have happened after prefab load, so we must reset/reload regardless
            try
            {
                if (affectedChunks != null)
                {
                    Tools.ChunkTools.ResetStability(affectedChunks);
                    Tools.ChunkTools.ReloadForClients(affectedChunks.Select(c => c.Key).ToList());
                }
            }
            catch (Exception ex)
            {
                CommandTools.HandleCommandException(ex);
            }
        }