diff --git a/Torch/TorchBase.cs b/Torch/TorchBase.cs index c5f3c7d..882fd65 100644 --- a/Torch/TorchBase.cs +++ b/Torch/TorchBase.cs @@ -47,7 +47,8 @@ namespace Torch { static TorchBase() { - RuntimeHelpers.RunClassConstructor(typeof(ReflectedManager).TypeHandle); + ReflectedManager.Process(typeof(TorchBase).Assembly); + ReflectedManager.Process(typeof(ITorchBase).Assembly); PatchManager.AddPatchShim(typeof(GameStatePatchShim)); PatchManager.CommitInternal(); RegisterCoreAssembly(typeof(ITorchBase).Assembly); @@ -419,9 +420,9 @@ namespace Torch lock (_registeredCoreAssemblies) if (_registeredCoreAssemblies.Add(asm)) { + ReflectedManager.Process(asm); EventManager.AddDispatchShims(asm); PatchManager.AddPatchShims(asm); - ReflectedManager.Process(asm); } } diff --git a/Torch/Utils/ReflectedManager.cs b/Torch/Utils/ReflectedManager.cs index 60c1ea6..c9a9fce 100644 --- a/Torch/Utils/ReflectedManager.cs +++ b/Torch/Utils/ReflectedManager.cs @@ -401,25 +401,16 @@ namespace Torch.Utils public static class ReflectedManager { private static readonly Logger _log = LogManager.GetCurrentClassLogger(); - private static readonly string[] _namespaceBlacklist = new[] { - "System", "VRage", "Sandbox", "SpaceEngineers", "Microsoft" - }; - private static readonly HashSet _processedTypes = new HashSet(); /// /// Ensures all reflected fields and methods contained in the given type are initialized /// /// Type to process - internal static void Process(Type t) + public static void Process(Type t) { if (_processedTypes.Add(t)) { - if (string.IsNullOrWhiteSpace(t.Namespace)) - return; - foreach (string ns in _namespaceBlacklist) - if (t.FullName.StartsWith(ns)) - return; foreach (FieldInfo field in t.GetFields(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { @@ -444,7 +435,7 @@ namespace Torch.Utils /// Ensures all types in the given assembly are initialized using /// /// Assembly to process - internal static void Process(Assembly asm) + public static void Process(Assembly asm) { foreach (Type type in asm.GetTypes()) Process(type); @@ -613,6 +604,7 @@ namespace Torch.Utils field.SetValue(null, Expression.Lambda(Expression.Call(paramExp[0], methodInstance, argExp), paramExp) .Compile()); + _log.Trace($"Reflecting field {field.DeclaringType?.FullName}#{field.Name} with {methodInstance.DeclaringType?.FullName}#{methodInstance.Name}"); } } @@ -698,6 +690,7 @@ namespace Torch.Utils } field.SetValue(null, Expression.Lambda(impl, paramExp).Compile()); + _log.Trace($"Reflecting field {field.DeclaringType?.FullName}#{field.Name} with {field.DeclaringType?.FullName}#{field.Name}"); } } }