Skip to content

Commit

Permalink
Fix base hooks being unsubscribed from
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
austinv900 committed Sep 8, 2023
1 parent c5d86c8 commit 045239a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Oxide.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<Import Project="..\netfx.props" />
Expand Down
11 changes: 11 additions & 0 deletions src/Plugins/CSPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Oxide.Core.Libraries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Oxide.Core.Plugins
Expand Down Expand Up @@ -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<HookMethod> hooks) && hooks.Any(h => h.IsBaseHook);
}

/// <summary>
/// Calls the specified hook on this plugin
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Plugins/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ public object CallHook(string hook, params object[] args)
/// <returns></returns>
protected abstract object OnCallHook(string hook, object[] args);

internal virtual bool IsBaseHook(string name) => false;

/// <summary>
/// Raises an error on this plugin
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal void SubscribeToHook(string hook, Plugin plugin)
/// <param name="plugin"></param>
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;
}
Expand Down

0 comments on commit 045239a

Please sign in to comment.