Fix introspection of dynamic assemblies
All checks were successful
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 7m22s
Build / Build Nuget package (NuGet) (push) Successful in 6m52s
Build / Build Nuget package (CringePlugins) (push) Successful in 7m59s
Build / Build Nuget package (SharedCringe) (push) Successful in 6m17s
Build / Build Launcher (push) Successful in 9m57s
All checks were successful
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 7m22s
Build / Build Nuget package (NuGet) (push) Successful in 6m52s
Build / Build Nuget package (CringePlugins) (push) Successful in 7m59s
Build / Build Nuget package (SharedCringe) (push) Successful in 6m17s
Build / Build Launcher (push) Successful in 9m57s
Log incorrect config method instead of throwing exception
This commit is contained in:
@@ -34,6 +34,12 @@ public static class IntrospectionPatches
|
|||||||
if (AssemblyLoadContext.GetLoadContext(__instance) is ICoreLoadContext || __instance.FullName?.StartsWith("System.") == true)
|
if (AssemblyLoadContext.GetLoadContext(__instance) is ICoreLoadContext || __instance.FullName?.StartsWith("System.") == true)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (__instance.IsDynamic)
|
||||||
|
{
|
||||||
|
__result = [];
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (AssemblyLoadContext.GetLoadContext(__instance) is ModAssemblyLoadContext or DerivedAssemblyLoadContext)
|
if (AssemblyLoadContext.GetLoadContext(__instance) is ModAssemblyLoadContext or DerivedAssemblyLoadContext)
|
||||||
{
|
{
|
||||||
//mods need to look for specific derived types
|
//mods need to look for specific derived types
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
using CringeBootstrap.Abstractions;
|
using CringeBootstrap.Abstractions;
|
||||||
using CringePlugins.Utils;
|
using CringePlugins.Utils;
|
||||||
|
using dnlib.DotNet;
|
||||||
|
using NLog;
|
||||||
using SharedCringe.Loader;
|
using SharedCringe.Loader;
|
||||||
using VRage.Plugins;
|
using VRage.Plugins;
|
||||||
|
|
||||||
@@ -16,6 +18,8 @@ internal sealed class PluginInstance
|
|||||||
private IPlugin? _instance;
|
private IPlugin? _instance;
|
||||||
private Action? _openConfigAction;
|
private Action? _openConfigAction;
|
||||||
private IHandleInputPlugin? _handleInputInstance;
|
private IHandleInputPlugin? _handleInputInstance;
|
||||||
|
|
||||||
|
private static readonly NLog.ILogger Log = LogManager.GetCurrentClassLogger();
|
||||||
public PluginMetadata Metadata { get; }
|
public PluginMetadata Metadata { get; }
|
||||||
|
|
||||||
public PluginInstance(PluginMetadata metadata, string entrypointPath)
|
public PluginInstance(PluginMetadata metadata, string entrypointPath)
|
||||||
@@ -51,12 +55,16 @@ internal sealed class PluginInstance
|
|||||||
|
|
||||||
if (openConfigMethod is not null)
|
if (openConfigMethod is not null)
|
||||||
{
|
{
|
||||||
//todo: log this and continue without action instead of throwing exception
|
|
||||||
if (openConfigMethod.ReturnType != typeof(void) || openConfigMethod.IsStatic || openConfigMethod.GetParameters().Length > 0)
|
if (openConfigMethod.ReturnType != typeof(void) || openConfigMethod.IsStatic || openConfigMethod.GetParameters().Length > 0)
|
||||||
throw new InvalidOperationException("OpenConfigDialog method has an incorrect signature");
|
{
|
||||||
|
Log.Error("Plugin has OpenConfigDialog method with incorrect signature: {Name}, v{Version} - {Source}",
|
||||||
|
Metadata.Name, Metadata.Version, Metadata.Source);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
_openConfigAction = openConfigMethod.CreateDelegate<Action>(_instance);
|
_openConfigAction = openConfigMethod.CreateDelegate<Action>(_instance);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_handleInputInstance = _instance as IHandleInputPlugin;
|
_handleInputInstance = _instance as IHandleInputPlugin;
|
||||||
}
|
}
|
||||||
@@ -76,6 +84,13 @@ internal sealed class PluginInstance
|
|||||||
if (_openConfigAction is null)
|
if (_openConfigAction is null)
|
||||||
throw new InvalidOperationException("Plugin does not have OpenConfigDialog method");
|
throw new InvalidOperationException("Plugin does not have OpenConfigDialog method");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
_openConfigAction();
|
_openConfigAction();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Error opening config: {Exception}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user