Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit 572d764

Browse files
committed
Fix(core): Reflection attribute scanner
1 parent 4ef2366 commit 572d764

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Core/Models/CKeyHook.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ internal ParamsHook(CPlugin plugin, TInfo info, MethodInfo method) : base(plugin
4848
/// <param name="register">注册机</param>
4949
public void ScanPlugin(CPlugin plugin, Func<TAttribute, TInfo> convertInfo, Action<TKey>? register)
5050
{
51-
var hooks = plugin.Instance.GetType().GetMethods()
52-
.Where(m => Attribute.GetCustomAttributes(m, typeof(TAttribute)).Any())
51+
var hooks = plugin.Instance.GetType()
52+
.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy)
53+
.Where(m => m.GetCustomAttributes(typeof(TAttribute), false).Any())
5354
.ToList();
5455

5556
if (!hooks.Any())

Core/PluginManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public PluginManager(ISourceSharpBase sourceSharp, IShareSystemBase shareSystem)
3030
_listeners = new();
3131
}
3232

33-
public void Initialize()
3433
public void Initialize(IServiceProvider services)
3534
{
3635
var listeners = services.GetAllServices<IListenerBase>();
@@ -78,8 +77,9 @@ public void Initialize(IServiceProvider services)
7877
tPlugin.SetProtectedReadOnlyField("_sourceSharp", instance, _sourceSharp);
7978
tPlugin.SetProtectedReadOnlyField("_shareSystem", instance, _shareSystem);
8079

81-
var frameHooks = tPlugin.GetMethods()
82-
.Where(m => Attribute.GetCustomAttributes(m, typeof(GameFrameAttribute)).Any())
80+
var frameHooks = tPlugin
81+
.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy)
82+
.Where(m => m.GetCustomAttributes(typeof(GameFrameAttribute), false).Any())
8383
.ToList();
8484

8585
if (frameHooks.Any())
@@ -115,7 +115,7 @@ public void Signal()
115115
{
116116
try
117117
{
118-
if (plugin.Instance.QueryRunning())
118+
if (!plugin.Instance.QueryRunning())
119119
{
120120
throw new InvalidOperationException();
121121
}

0 commit comments

Comments
 (0)