Skip to content

Commit 045239a

Browse files
committed
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.
1 parent c5d86c8 commit 045239a

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/Oxide.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
33
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
44
<Import Project="..\netfx.props" />

src/Plugins/CSPlugin.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Oxide.Core.Libraries;
22
using System;
33
using System.Collections.Generic;
4+
using System.Linq;
45
using System.Reflection;
56

67
namespace Oxide.Core.Plugins
@@ -115,6 +116,16 @@ protected void AddHookMethod(string name, MethodInfo method)
115116
hookMethods.Add(new HookMethod(method));
116117
}
117118

119+
internal override bool IsBaseHook(string name)
120+
{
121+
if (string.IsNullOrEmpty(name))
122+
{
123+
return false;
124+
}
125+
126+
return Hooks.TryGetValue(name, out List<HookMethod> hooks) && hooks.Any(h => h.IsBaseHook);
127+
}
128+
118129
/// <summary>
119130
/// Calls the specified hook on this plugin
120131
/// </summary>

src/Plugins/Plugin.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ public object CallHook(string hook, params object[] args)
327327
/// <returns></returns>
328328
protected abstract object OnCallHook(string hook, object[] args);
329329

330+
internal virtual bool IsBaseHook(string name) => false;
331+
330332
/// <summary>
331333
/// Raises an error on this plugin
332334
/// </summary>

src/Plugins/PluginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ internal void SubscribeToHook(string hook, Plugin plugin)
144144
/// <param name="plugin"></param>
145145
internal void UnsubscribeToHook(string hook, Plugin plugin)
146146
{
147-
if (!loadedPlugins.ContainsKey(plugin.Name) || !plugin.IsCorePlugin && (hook.StartsWith("IOn") || hook.StartsWith("ICan")))
147+
if (!loadedPlugins.ContainsKey(plugin.Name) || !plugin.IsCorePlugin && (hook.StartsWith("IOn") || hook.StartsWith("ICan")) || plugin.IsBaseHook(hook))
148148
{
149149
return;
150150
}

0 commit comments

Comments
 (0)