Fix load order issues with reflected manager and patches
This commit is contained in:
@@ -47,7 +47,8 @@ namespace Torch
|
|||||||
{
|
{
|
||||||
static TorchBase()
|
static TorchBase()
|
||||||
{
|
{
|
||||||
RuntimeHelpers.RunClassConstructor(typeof(ReflectedManager).TypeHandle);
|
ReflectedManager.Process(typeof(TorchBase).Assembly);
|
||||||
|
ReflectedManager.Process(typeof(ITorchBase).Assembly);
|
||||||
PatchManager.AddPatchShim(typeof(GameStatePatchShim));
|
PatchManager.AddPatchShim(typeof(GameStatePatchShim));
|
||||||
PatchManager.CommitInternal();
|
PatchManager.CommitInternal();
|
||||||
RegisterCoreAssembly(typeof(ITorchBase).Assembly);
|
RegisterCoreAssembly(typeof(ITorchBase).Assembly);
|
||||||
@@ -419,9 +420,9 @@ namespace Torch
|
|||||||
lock (_registeredCoreAssemblies)
|
lock (_registeredCoreAssemblies)
|
||||||
if (_registeredCoreAssemblies.Add(asm))
|
if (_registeredCoreAssemblies.Add(asm))
|
||||||
{
|
{
|
||||||
|
ReflectedManager.Process(asm);
|
||||||
EventManager.AddDispatchShims(asm);
|
EventManager.AddDispatchShims(asm);
|
||||||
PatchManager.AddPatchShims(asm);
|
PatchManager.AddPatchShims(asm);
|
||||||
ReflectedManager.Process(asm);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -401,25 +401,16 @@ namespace Torch.Utils
|
|||||||
public static class ReflectedManager
|
public static class ReflectedManager
|
||||||
{
|
{
|
||||||
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
|
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
|
||||||
private static readonly string[] _namespaceBlacklist = new[] {
|
|
||||||
"System", "VRage", "Sandbox", "SpaceEngineers", "Microsoft"
|
|
||||||
};
|
|
||||||
|
|
||||||
private static readonly HashSet<Type> _processedTypes = new HashSet<Type>();
|
private static readonly HashSet<Type> _processedTypes = new HashSet<Type>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ensures all reflected fields and methods contained in the given type are initialized
|
/// Ensures all reflected fields and methods contained in the given type are initialized
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="t">Type to process</param>
|
/// <param name="t">Type to process</param>
|
||||||
internal static void Process(Type t)
|
public static void Process(Type t)
|
||||||
{
|
{
|
||||||
if (_processedTypes.Add(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 |
|
foreach (FieldInfo field in t.GetFields(BindingFlags.Static | BindingFlags.Instance |
|
||||||
BindingFlags.Public | BindingFlags.NonPublic))
|
BindingFlags.Public | BindingFlags.NonPublic))
|
||||||
{
|
{
|
||||||
@@ -444,7 +435,7 @@ namespace Torch.Utils
|
|||||||
/// Ensures all types in the given assembly are initialized using <see cref="Process(Type)"/>
|
/// Ensures all types in the given assembly are initialized using <see cref="Process(Type)"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="asm">Assembly to process</param>
|
/// <param name="asm">Assembly to process</param>
|
||||||
internal static void Process(Assembly asm)
|
public static void Process(Assembly asm)
|
||||||
{
|
{
|
||||||
foreach (Type type in asm.GetTypes())
|
foreach (Type type in asm.GetTypes())
|
||||||
Process(type);
|
Process(type);
|
||||||
@@ -613,6 +604,7 @@ namespace Torch.Utils
|
|||||||
field.SetValue(null,
|
field.SetValue(null,
|
||||||
Expression.Lambda(Expression.Call(paramExp[0], methodInstance, argExp), paramExp)
|
Expression.Lambda(Expression.Call(paramExp[0], methodInstance, argExp), paramExp)
|
||||||
.Compile());
|
.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());
|
field.SetValue(null, Expression.Lambda(impl, paramExp).Compile());
|
||||||
|
_log.Trace($"Reflecting field {field.DeclaringType?.FullName}#{field.Name} with {field.DeclaringType?.FullName}#{field.Name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user