From 045239a35ed148a11f93d519410043b795c7048c Mon Sep 17 00:00:00 2001 From: Austin Vandersluis Date: Fri, 8 Sep 2023 06:46:42 -0700 Subject: [PATCH] Fix base hooks being unsubscribed from Some plugins will unsubscribe from hooks that are required for core functionality. This fixes that by adding a check to make sure the hook doesn't contain a call to a base method. --- src/Oxide.Core.csproj | 2 +- src/Plugins/CSPlugin.cs | 11 +++++++++++ src/Plugins/Plugin.cs | 2 ++ src/Plugins/PluginManager.cs | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Oxide.Core.csproj b/src/Oxide.Core.csproj index 28c3efccd..c2bd5c69e 100644 --- a/src/Oxide.Core.csproj +++ b/src/Oxide.Core.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Plugins/CSPlugin.cs b/src/Plugins/CSPlugin.cs index ee2b02ab2..709da639c 100644 --- a/src/Plugins/CSPlugin.cs +++ b/src/Plugins/CSPlugin.cs @@ -1,6 +1,7 @@ using Oxide.Core.Libraries; using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; namespace Oxide.Core.Plugins @@ -115,6 +116,16 @@ protected void AddHookMethod(string name, MethodInfo method) hookMethods.Add(new HookMethod(method)); } + internal override bool IsBaseHook(string name) + { + if (string.IsNullOrEmpty(name)) + { + return false; + } + + return Hooks.TryGetValue(name, out List hooks) && hooks.Any(h => h.IsBaseHook); + } + /// /// Calls the specified hook on this plugin /// diff --git a/src/Plugins/Plugin.cs b/src/Plugins/Plugin.cs index 6f6ba6e60..75c540708 100644 --- a/src/Plugins/Plugin.cs +++ b/src/Plugins/Plugin.cs @@ -327,6 +327,8 @@ public object CallHook(string hook, params object[] args) /// protected abstract object OnCallHook(string hook, object[] args); + internal virtual bool IsBaseHook(string name) => false; + /// /// Raises an error on this plugin /// diff --git a/src/Plugins/PluginManager.cs b/src/Plugins/PluginManager.cs index 9bf1f80df..faf406391 100644 --- a/src/Plugins/PluginManager.cs +++ b/src/Plugins/PluginManager.cs @@ -144,7 +144,7 @@ internal void SubscribeToHook(string hook, Plugin plugin) /// internal void UnsubscribeToHook(string hook, Plugin plugin) { - if (!loadedPlugins.ContainsKey(plugin.Name) || !plugin.IsCorePlugin && (hook.StartsWith("IOn") || hook.StartsWith("ICan"))) + if (!loadedPlugins.ContainsKey(plugin.Name) || !plugin.IsCorePlugin && (hook.StartsWith("IOn") || hook.StartsWith("ICan")) || plugin.IsBaseHook(hook)) { return; }