From ad204c6ecb0882ded0e59dfae375ede7b4e1bb60 Mon Sep 17 00:00:00 2001 From: pas2704 Date: Sat, 2 Nov 2024 15:19:05 -0400 Subject: [PATCH] Fix mod components loading --- .gitignore | 1 + .../Patches/IntrospectionPatches.cs | 28 ++++++++++++++++++- CringePlugins/Utils/IntrospectionContext.cs | 4 +-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 12ae23d..43301a5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ riderModule.iml /CringeLauncher/Bin64 /CringeLauncher/pub *.user +pub/ diff --git a/CringeLauncher/Patches/IntrospectionPatches.cs b/CringeLauncher/Patches/IntrospectionPatches.cs index fdf553d..3e64826 100644 --- a/CringeLauncher/Patches/IntrospectionPatches.cs +++ b/CringeLauncher/Patches/IntrospectionPatches.cs @@ -3,9 +3,13 @@ using System.Reflection; using System.Runtime.Loader; using System.Xml.Serialization; using CringeBootstrap.Abstractions; +using CringeLauncher.Loader; using CringePlugins.Utils; using HarmonyLib; +using Sandbox.Game.GameSystems.TextSurfaceScripts; +using Sandbox.Game; using Sandbox.Game.World; +using SharedCringe.Loader; using VRage; using VRage.FileSystem; using VRage.Game; @@ -13,6 +17,7 @@ using VRage.Game.Common; using VRage.Game.Components; using VRage.Game.Definitions; using VRage.Game.Entity.UseObject; +using VRage.ModAPI; using VRage.ObjectBuilders; using VRage.ObjectBuilders.Private; using VRage.Plugins; @@ -27,7 +32,28 @@ public static class IntrospectionPatches { if (AssemblyLoadContext.GetLoadContext(__instance) is ICoreLoadContext || __instance.FullName?.StartsWith("System.") == true) return true; - + + if (AssemblyLoadContext.GetLoadContext(__instance) is ModAssemblyLoadContext or DerivedAssemblyLoadContext) + { + //mods need to look for specific derived types + Debug.WriteLine($"Getting special types for {__instance.FullName}"); + var module = __instance.GetMainModule(); + __result = IntrospectionContext.Global.CollectDerivedTypes(module) + .Concat(IntrospectionContext.Global.CollectDerivedTypes(module)) + .Concat(IntrospectionContext.Global.CollectDerivedTypes(module)) + .Concat(IntrospectionContext.Global.CollectAttributedTypes(module)) + .Concat(IntrospectionContext.Global.CollectDerivedTypes(module)) + .Concat(IntrospectionContext.Global.CollectAttributedTypes(module)) + .Concat(IntrospectionContext.Global.CollectDerivedTypes(module)) + .Concat(IntrospectionContext.Global.CollectDerivedTypes(module)) + .Concat(IntrospectionContext.Global.CollectDerivedTypes(module)) + .Concat(IntrospectionContext.Global.CollectAttributedTypes(module)) + .ToArray(); + + + return false; + } + Debug.WriteLine($"Blocking GetTypes for {__instance.FullName}"); __result = []; diff --git a/CringePlugins/Utils/IntrospectionContext.cs b/CringePlugins/Utils/IntrospectionContext.cs index 44de507..4ebdf2f 100644 --- a/CringePlugins/Utils/IntrospectionContext.cs +++ b/CringePlugins/Utils/IntrospectionContext.cs @@ -15,7 +15,7 @@ public class IntrospectionContext return moduleDef.GetTypes() .Where(b => b.CustomAttributes.IsDefined(typeof(TAttribute).FullName) && (allowAbstract || !b.IsAbstract)) - .Select(b => module.GetType(b.FullName, true, false)!); + .Select(b => module.GetType(b.FullName.Replace('/', '+'), true, false)!); } public IEnumerable CollectDerivedTypes(Module module, bool allowAbstract = false) @@ -28,7 +28,7 @@ public class IntrospectionContext .Where(b => (typeof(T).IsInterface ? b.Interfaces.Any(i => i.Interface.FullName == token.FullName) : MatchBaseType(b, token)) && (allowAbstract || !b.IsAbstract)) - .Select(b => module.GetType(b.FullName, true, false)!); + .Select(b => module.GetType(b.FullName.Replace('/', '+'), true, false)!); } private static bool MatchBaseType(ITypeDefOrRef? defOrRef, TypeSig token)