fix harmony patches in plugins
All checks were successful
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m53s
Build / Build Nuget package (NuGet) (push) Successful in 2m2s
Build / Build Nuget package (CringePlugins) (push) Successful in 2m49s
Build / Build Launcher (push) Successful in 3m28s
Build / Build Nuget package (SharedCringe) (push) Successful in 4m55s
All checks were successful
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m53s
Build / Build Nuget package (NuGet) (push) Successful in 2m2s
Build / Build Nuget package (CringePlugins) (push) Successful in 2m49s
Build / Build Launcher (push) Successful in 3m28s
Build / Build Nuget package (SharedCringe) (push) Successful in 4m55s
This commit is contained in:
@@ -66,7 +66,8 @@ public static class IntrospectionPatches
|
|||||||
if (AssemblyLoadContext.GetLoadContext(assembly) is ICoreLoadContext)
|
if (AssemblyLoadContext.GetLoadContext(assembly) is ICoreLoadContext)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
__result = IntrospectionContext.Global.CollectAttributedTypes<HarmonyAttribute>(assembly.GetMainModule())
|
// static classes are abstract
|
||||||
|
__result = IntrospectionContext.Global.CollectAttributedTypes<HarmonyAttribute>(assembly.GetMainModule(), true)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
using VRage.FileSystem;
|
||||||
|
|
||||||
namespace CringePlugins.Utils;
|
namespace CringePlugins.Utils;
|
||||||
|
|
||||||
@@ -7,14 +8,28 @@ public class IntrospectionContext
|
|||||||
{
|
{
|
||||||
public static IntrospectionContext Global { get; } = new();
|
public static IntrospectionContext Global { get; } = new();
|
||||||
|
|
||||||
internal readonly ModuleContext Context = ModuleDef.CreateModuleContext();
|
internal readonly ModuleContext Context;
|
||||||
|
|
||||||
|
public IntrospectionContext()
|
||||||
|
{
|
||||||
|
var assemblyResolver = new AssemblyResolver();
|
||||||
|
|
||||||
|
assemblyResolver.PreSearchPaths.Add(AppContext.BaseDirectory);
|
||||||
|
assemblyResolver.PreSearchPaths.Add(MyFileSystem.ExePath);
|
||||||
|
|
||||||
|
Context = new(assemblyResolver);
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<Type> CollectAttributedTypes<TAttribute>(Module module, bool allowAbstract = false) where TAttribute : Attribute
|
public IEnumerable<Type> CollectAttributedTypes<TAttribute>(Module module, bool allowAbstract = false) where TAttribute : Attribute
|
||||||
{
|
{
|
||||||
var moduleDef = ModuleDefMD.Load(module, Context);
|
var moduleDef = ModuleDefMD.Load(module, Context);
|
||||||
|
|
||||||
|
var token = moduleDef.ImportAsTypeSig(typeof(TAttribute));
|
||||||
|
|
||||||
return moduleDef.GetTypes()
|
return moduleDef.GetTypes()
|
||||||
.Where(b => b.CustomAttributes.IsDefined(typeof(TAttribute).FullName) && (allowAbstract || !b.IsAbstract))
|
.Where(b => b.CustomAttributes.Any(a =>
|
||||||
|
a.AttributeType.FullName == token.FullName || MatchBaseType(a.AttributeType, token)) &&
|
||||||
|
(allowAbstract || !b.IsAbstract))
|
||||||
.Select(b => module.GetType(b.FullName.Replace('/', '+'), true, false)!);
|
.Select(b => module.GetType(b.FullName.Replace('/', '+'), true, false)!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user