Beispiel #1
0
        public void UnloadPlugin(string name, bool removeFromDict = true)
        {
            Logger.LogDebug("[IPModule] Unloading " + name + " plugin.");

            if (plugins.ContainsKey(name))
            {
                IPPlugin plugin = plugins[name];
                if (plugin.Globals.Contains("On_PluginShutdown"))
                {
                    plugin.Engine.Operations.InvokeMember(plugin.Class, "On_PluginShutdown", new object[0]);
                }
                plugin.OnPluginShutdown();
                plugin.KillTimers();
                RemoveHooks(plugin);
                if (removeFromDict)
                {
                    plugins.Remove(name);
                }

                Logger.LogDebug("[IPModule] " + name + " plugin was unloaded successfuly.");
            }
            else
            {
                Logger.LogError("[IPModule] Can't unload " + name + ". Plugin is not loaded.");
                throw new InvalidOperationException("[IPModule] Can't unload " + name + ". Plugin is not loaded.");
            }
        }
Beispiel #2
0
        public void UnloadPlugin(string name, bool removeFromDict = true)
        {
            Logger.LogDebug("[IPModule] Unloading " + name + " plugin.");

            if (plugins.ContainsKey(name))
            {
                IPPlugin plugin = plugins[name];
                plugin.OnPluginShutdown();
                plugin.KillTimers();
                RemoveHooks(plugin);
                if (removeFromDict)
                {
                    plugins.Remove(name);
                }
                GlobalPluginCollector.GetPluginCollector().RemovePlugin(name);
                Logger.Log("[IPModule] " + name + " plugin was unloaded successfully.");
            }
            else
            {
                Logger.LogError("[IPModule] Can't unload " + name + ". Plugin is not loaded.");
                //throw new InvalidOperationException("[IPModule] Can't unload " + name + ". Plugin is not loaded.");
            }
        }
Beispiel #3
0
        private void RemoveHooks(IPPlugin plugin)
        {
            foreach (string method in plugin.Globals)
            {
                if (!method.StartsWith("On_") && !method.EndsWith("Callback"))
                {
                    continue;
                }

                Logger.LogDebug("Removing function: " + method);
                switch (method)
                {
                case "On_ServerInit": Hooks.OnServerInit -= new Hooks.ServerInitDelegate(plugin.OnServerInit); break;

                case "On_ServerShutdown": Hooks.OnServerShutdown -= new Hooks.ServerShutdownDelegate(plugin.OnServerShutdown); break;

                case "On_ItemsLoaded": Hooks.OnItemsLoaded -= new Hooks.ItemsDatablocksLoaded(plugin.OnItemsLoaded); break;

                case "On_TablesLoaded": Hooks.OnTablesLoaded -= new Hooks.LootTablesLoaded(plugin.OnTablesLoaded); break;

                case "On_Chat": Hooks.OnChat -= new Hooks.ChatHandlerDelegate(plugin.OnChat); break;

                case "On_Console": Hooks.OnConsoleReceived -= new Hooks.ConsoleHandlerDelegate(plugin.OnConsole); break;

                case "On_Command": Hooks.OnCommand -= new Hooks.CommandHandlerDelegate(plugin.OnCommand); break;

                case "On_PlayerConnected": Hooks.OnPlayerConnected -= new Hooks.ConnectionHandlerDelegate(plugin.OnPlayerConnected); break;

                case "On_PlayerDisconnected": Hooks.OnPlayerDisconnected -= new Hooks.DisconnectionHandlerDelegate(plugin.OnPlayerDisconnected); break;

                case "On_PlayerKilled": Hooks.OnPlayerKilled -= new Hooks.KillHandlerDelegate(plugin.OnPlayerKilled); break;

                case "On_PlayerHurt": Hooks.OnPlayerHurt -= new Hooks.HurtHandlerDelegate(plugin.OnPlayerHurt); break;

                case "On_PlayerSpawn": Hooks.OnPlayerSpawning -= new Hooks.PlayerSpawnHandlerDelegate(plugin.OnPlayerSpawn); break;

                case "On_PlayerSpawned": Hooks.OnPlayerSpawned -= new Hooks.PlayerSpawnHandlerDelegate(plugin.OnPlayerSpawned); break;

                case "On_PlayerGathering": Hooks.OnPlayerGathering -= new Hooks.PlayerGatheringHandlerDelegate(plugin.OnPlayerGathering); break;

                case "On_EntityHurt": Hooks.OnEntityHurt -= new Hooks.EntityHurtDelegate(plugin.OnEntityHurt); break;

                case "On_EntityDecay": Hooks.OnEntityDecay -= new Hooks.EntityDecayDelegate(plugin.OnEntityDecay); break;

                case "On_EntityDestroyed": Hooks.OnEntityDestroyed -= new Hooks.EntityDestroyedDelegate(plugin.OnEntityDestroyed); break;

                case "On_EntityDeployed": Hooks.OnEntityDeployedWithPlacer -= new Hooks.EntityDeployedWithPlacerDelegate(plugin.OnEntityDeployed); break;

                case "On_NPCHurt": Hooks.OnNPCHurt -= new Hooks.HurtHandlerDelegate(plugin.OnNPCHurt); break;

                case "On_NPCKilled": Hooks.OnNPCKilled -= new Hooks.KillHandlerDelegate(plugin.OnNPCKilled); break;

                case "On_BlueprintUse": Hooks.OnBlueprintUse -= new Hooks.BlueprintUseHandlerDelegate(plugin.OnBlueprintUse); break;

                case "On_DoorUse": Hooks.OnDoorUse -= new Hooks.DoorOpenHandlerDelegate(plugin.OnDoorUse); break;

                case "On_PlayerTeleport": Hooks.OnPlayerTeleport -= new Hooks.TeleportDelegate(plugin.OnPlayerTeleport); break;

                case "On_AllPluginsLoaded": IPModule.OnAllLoaded -= new IPModule.AllLoadedDelegate(plugin.OnAllPluginsLoaded); break;

                case "On_Crafting": Hooks.OnCrafting -= new Hooks.CraftingDelegate(plugin.OnCrafting); break;

                case "On_ResourceSpawn": Hooks.OnResourceSpawned -= new Hooks.ResourceSpawnDelegate(plugin.OnResourceSpawned); break;

                case "On_ItemAdded": Hooks.OnItemAdded -= new Hooks.ItemAddedDelegate(plugin.OnItemAdded); break;

                case "On_ItemRemoved": Hooks.OnItemRemoved -= new Hooks.ItemRemovedDelegate(plugin.OnItemRemoved); break;

                case "On_Airdrop": Hooks.OnAirdropCalled -= new Hooks.AirdropDelegate(plugin.OnAirdrop); break;

                //case "On_AirdropCrateDropped": Hooks.OnAirdropCrateDropped -= new Hooks.AirdropCrateDroppedDelegate(plugin.OnAirdropCrateDropped); break;
                case "On_SteamDeny": Hooks.OnSteamDeny -= new Hooks.SteamDenyDelegate(plugin.OnSteamDeny); break;

                case "On_PlayerApproval": Hooks.OnPlayerApproval -= new Hooks.PlayerApprovalDelegate(plugin.OnPlayerApproval); break;

                case "On_Research": Hooks.OnResearch -= new Hooks.ResearchDelegate(plugin.OnResearch); break;

                case "On_ServerSaved": Hooks.OnServerSaved -= new Hooks.ServerSavedDelegate(plugin.OnServerSaved); break;

                case "On_VoiceChat": Hooks.OnShowTalker -= new Hooks.ShowTalkerDelegate(plugin.OnShowTalker); break;

                case "On_ItemPickup": Hooks.OnItemPickup -= new Hooks.ItemPickupDelegate(plugin.OnItemPickup); break;

                case "On_FallDamage": Hooks.OnFallDamage -= new Hooks.FallDamageDelegate(plugin.OnFallDamage); break;

                case "On_LootUse": Hooks.OnLootUse -= new Hooks.LootEnterDelegate(plugin.OnLootUse); break;

                case "On_PlayerBan": Hooks.OnPlayerBan -= new Hooks.BanEventDelegate(plugin.OnBanEvent); break;

                case "On_RepairBench": Hooks.OnRepairBench -= new Hooks.RepairBenchEventDelegate(plugin.OnRepairBench); break;

                case "On_ItemMove": Hooks.OnItemMove -= new Hooks.ItemMoveEventDelegate(plugin.OnItemMove); break;

                case "On_GenericSpawnLoad": Hooks.OnGenericSpawnerLoad -= new Hooks.GenericSpawnerLoadDelegate(plugin.OnGenericSpawnLoad); break;

                case "On_ServerLoaded": Hooks.OnServerLoaded -= new Hooks.ServerLoadedDelegate(plugin.OnServerLoaded); break;

                case "On_SupplySignalExploded": Hooks.OnSupplySignalExpode -= new Hooks.SupplySignalDelegate(plugin.OnSupplySignalExploded); break;
                }
            }
        }
Beispiel #4
0
 public void ReloadPlugin(IPPlugin plugin)
 {
     UnloadPlugin(plugin.Name);
     LoadPlugin(plugin.Name);
 }
Beispiel #5
0
        public void LoadPlugin(string name)
        {
            Logger.LogDebug("[IPModule] Loading plugin " + name + ".");

            if (plugins.ContainsKey(name))
            {
                Logger.LogError("[IPModule] " + name + " plugin is already loaded.");
                return;
                //throw new InvalidOperationException("[IPModule] " + name + " plugin is already loaded.");
            }

            try
            {
                string        code   = GetPluginScriptText(name);
                string[]      lines  = code.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                DirectoryInfo path   = new DirectoryInfo(Path.Combine(pluginDirectory.FullName, name));
                IPPlugin      plugin = new IPPlugin(name, code, path);
                InstallHooks(plugin);
                string cmdname = null;
                bool   d = false, f = false;
                foreach (string line in lines)
                {
                    if (line.Contains("On_Command"))
                    {
                        string[] spl = line.Split(Convert.ToChar(","));
                        cmdname = spl[2].Trim();
                        if (plugin.CommandList.Count == 0)
                        {
                            f = true;
                        }
                        continue;
                    }
                    if (cmdname != null)
                    {
                        string n = line.Trim();
                        string l = n.ToLower();
                        if (n.Contains(cmdname) && n.Contains("=="))
                        {
                            if ((l.Contains("getsetting") || l.Contains("datastore")) && !d)
                            {
                                if (!d && f)
                                {
                                    Logger.LogDebug("I detected the usage of custom commands in: " + plugin.Name);
                                    Logger.LogDebug("Make sure you add the commands manually to: Plugin.CommandList");
                                    Logger.LogDebug("Example: Plugin.CommandList.Add(ini.GetSetting(...))");
                                    Logger.LogDebug("If you have questions go to www.fougerite.com !");
                                    d = true;
                                }
                                continue;
                            }
                            IEnumerable <string> s  = null;
                            IEnumerable <string> s2 = null;
                            if (n.Contains("'"))
                            {
                                s = getBetween(l, "'", "'");
                            }
                            else if (n.Contains('"'.ToString()))
                            {
                                s2 = getBetween(l, '"'.ToString(), '"'.ToString());
                            }
                            else
                            {
                                if (!d && f)
                                {
                                    Logger.LogDebug("I detected the usage of custom commands in " + plugin.Name);
                                    Logger.LogDebug("Make sure you add the commands manually to: Plugin.CommandList");
                                    Logger.LogDebug("Example: Plugin.CommandList.Add(ini.GetSetting(...))");
                                    Logger.LogDebug("If you have questions go to www.fougerite.com !");
                                    d = true;
                                }
                                continue;
                            }
                            if (s != null)
                            {
                                foreach (var cmd in s)
                                {
                                    plugin.CommandList.Add(cmd);
                                }
                            }
                            if (s2 != null)
                            {
                                foreach (var cmd in s2)
                                {
                                    plugin.CommandList.Add(cmd);
                                }
                            }
                        }
                    }
                }
                if (d)
                {
                    plugin.CommandList.Clear();
                }
                plugins.Add(name, plugin);
                GlobalPluginCollector.GetPluginCollector().AddPlugin(name, plugin, "Python");

                Logger.Log("[IPModule] " + name + " plugin by " + plugin.Author + " V" + plugin.Version + " was loaded successfully.");
                if (!string.IsNullOrEmpty(plugin.About))
                {
                    Logger.Log("[IPModule] Description: " + plugin.About);
                }
            } catch (Exception ex) {
                Logger.LogError("[IPModule] " + name + " plugin could not be loaded.");
                Logger.LogException(ex);
            }
        }
Beispiel #6
0
        private void RemoveHooks(IPPlugin plugin)
        {
            foreach (string method in plugin.Globals)
            {
                if (!method.StartsWith("On_") && !method.EndsWith("Callback"))
                {
                    continue;
                }

                Logger.LogDebug("Removing function: " + method);
                switch (method)
                {
                case "On_ServerInit": Hooks.OnServerInit -= new Hooks.ServerInitDelegate(plugin.OnServerInit); break;

                case "On_ServerShutdown": Hooks.OnServerShutdown -= new Hooks.ServerShutdownDelegate(plugin.OnServerShutdown); break;

                case "On_ItemsLoaded": Hooks.OnItemsLoaded -= new Hooks.ItemsDatablocksLoaded(plugin.OnItemsLoaded); break;

                case "On_TablesLoaded": Hooks.OnTablesLoaded -= new Hooks.LootTablesLoaded(plugin.OnTablesLoaded); break;

                case "On_Chat": Hooks.OnChat -= new Hooks.ChatHandlerDelegate(plugin.OnChat); break;

                case "On_Console": Hooks.OnConsoleReceived -= new Hooks.ConsoleHandlerDelegate(plugin.OnConsole); break;

                case "On_Command": Hooks.OnCommand -= new Hooks.CommandHandlerDelegate(plugin.OnCommand); break;

                case "On_PlayerConnected": Hooks.OnPlayerConnected -= new Hooks.ConnectionHandlerDelegate(plugin.OnPlayerConnected); break;

                case "On_PlayerDisconnected": Hooks.OnPlayerDisconnected -= new Hooks.DisconnectionHandlerDelegate(plugin.OnPlayerDisconnected); break;

                case "On_PlayerKilled": Hooks.OnPlayerKilled -= new Hooks.KillHandlerDelegate(plugin.OnPlayerKilled); break;

                case "On_PlayerHurt": Hooks.OnPlayerHurt -= new Hooks.HurtHandlerDelegate(plugin.OnPlayerHurt); break;

                case "On_PlayerSpawn": Hooks.OnPlayerSpawning -= new Hooks.PlayerSpawnHandlerDelegate(plugin.OnPlayerSpawn); break;

                case "On_PlayerSpawned": Hooks.OnPlayerSpawned -= new Hooks.PlayerSpawnHandlerDelegate(plugin.OnPlayerSpawned); break;

                case "On_PlayerGathering": Hooks.OnPlayerGathering -= new Hooks.PlayerGatheringHandlerDelegate(plugin.OnPlayerGathering); break;

                case "On_EntityHurt": Hooks.OnEntityHurt -= new Hooks.EntityHurtDelegate(plugin.OnEntityHurt); break;

                case "On_EntityDecay": Hooks.OnEntityDecay -= new Hooks.EntityDecayDelegate(plugin.OnEntityDecay); break;

                case "On_EntityDestroyed": Hooks.OnEntityDestroyed -= new Hooks.EntityDestroyedDelegate(plugin.OnEntityDestroyed); break;

                case "On_EntityDeployed": Hooks.OnEntityDeployed -= new Hooks.EntityDeployedDelegate(plugin.OnEntityDeployed); break;

                case "On_NPCHurt": Hooks.OnNPCHurt -= new Hooks.HurtHandlerDelegate(plugin.OnNPCHurt); break;

                case "On_NPCKilled": Hooks.OnNPCKilled -= new Hooks.KillHandlerDelegate(plugin.OnNPCKilled); break;

                case "On_BlueprintUse": Hooks.OnBlueprintUse -= new Hooks.BlueprintUseHandlerDelegate(plugin.OnBlueprintUse); break;

                case "On_DoorUse": Hooks.OnDoorUse -= new Hooks.DoorOpenHandlerDelegate(plugin.OnDoorUse); break;

                case "On_PlayerTeleport": Hooks.OnPlayerTeleport -= new Hooks.TeleportDelegate(plugin.OnPlayerTeleport); break;

                case "On_AllPluginsLoaded": IPModule.OnAllLoaded -= new IPModule.AllLoadedDelegate(plugin.OnAllPluginsLoaded); break;

                case "On_Crafting": Hooks.OnCrafting -= new Hooks.CraftingDelegate(plugin.OnCrafting); break;

                case "On_ResourceSpawn": Hooks.OnResourceSpawned -= new Hooks.ResourceSpawnDelegate(plugin.OnResourceSpawned); break;

                case "On_ItemAdded": Hooks.OnItemAdded -= new Hooks.ItemAddedDelegate(plugin.OnItemAdded); break;

                case "On_ItemRemoved": Hooks.OnItemRemoved -= new Hooks.ItemRemovedDelegate(plugin.OnItemRemoved); break;

                case "On_Airdrop": Hooks.OnAirdropCalled -= new Hooks.AirdropDelegate(plugin.OnAirdrop); break;

                case "On_SteamDeny": Hooks.OnSteamDeny -= new Hooks.SteamDenyDelegate(plugin.OnSteamDeny); break;

                case "On_PlayerApproval": Hooks.OnPlayerApproval -= new Hooks.PlayerApprovalDelegate(plugin.OnPlayerApproval); break;

                case "On_Research": Hooks.OnResearch -= new Hooks.ResearchDelegate(plugin.OnResearch); break;
                }
            }
        }