Plugins: Catch TargetInvocationException -> MissingFieldException on instantiation
This commit is contained in:
@@ -146,6 +146,13 @@ namespace Il2CppInspector
|
|||||||
//typeof(PluginAPI.V101.IPlugin)
|
//typeof(PluginAPI.V101.IPlugin)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Construct disabled plugin as a placeholder if loading fails (mainly for the GUI)
|
||||||
|
var disabledPlugin = new ManagedPlugin {
|
||||||
|
Plugin = null,
|
||||||
|
Available = false,
|
||||||
|
Enabled = false
|
||||||
|
};
|
||||||
|
|
||||||
// Load plugin
|
// Load plugin
|
||||||
try {
|
try {
|
||||||
var asm = loader.LoadDefaultAssembly();
|
var asm = loader.LoadDefaultAssembly();
|
||||||
@@ -173,13 +180,7 @@ namespace Il2CppInspector
|
|||||||
catch (ReflectionTypeLoadException ex) {
|
catch (ReflectionTypeLoadException ex) {
|
||||||
var name = Path.GetFileName(dll);
|
var name = Path.GetFileName(dll);
|
||||||
|
|
||||||
// Construct disabled plugin
|
AsInstance.ManagedPlugins.Add(disabledPlugin);
|
||||||
var plugin = new ManagedPlugin {
|
|
||||||
Plugin = null,
|
|
||||||
Available = false,
|
|
||||||
Enabled = false
|
|
||||||
};
|
|
||||||
AsInstance.ManagedPlugins.Add(plugin);
|
|
||||||
|
|
||||||
// Determine error
|
// Determine error
|
||||||
switch (ex.LoaderExceptions[0]) {
|
switch (ex.LoaderExceptions[0]) {
|
||||||
@@ -189,20 +190,20 @@ namespace Il2CppInspector
|
|||||||
if (failedType.TypeName.StartsWith("Il2CppInspector.PluginAPI.")) {
|
if (failedType.TypeName.StartsWith("Il2CppInspector.PluginAPI.")) {
|
||||||
|
|
||||||
// Requires newer plugin API version
|
// Requires newer plugin API version
|
||||||
plugin.Plugin = new InvalidPlugin { Name = name, Description = "This plugin requires a newer version of Il2CppInspector" };
|
disabledPlugin.Plugin = new InvalidPlugin { Name = name, Description = "This plugin requires a newer version of Il2CppInspector" };
|
||||||
Console.Error.WriteLine($"Error loading plugin {plugin.Plugin.Name}: {plugin.Plugin.Description}");
|
Console.Error.WriteLine($"Error loading plugin {disabledPlugin.Plugin.Name}: {disabledPlugin.Plugin.Description}");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Missing dependencies
|
// Missing dependencies or some inherited interfaces not implemented
|
||||||
plugin.Plugin = new InvalidPlugin { Name = name, Description = "This plugin has dependencies that could not be found. Check that all required DLLs are present in the plugins folder." };
|
disabledPlugin.Plugin = new InvalidPlugin { Name = name, Description = "This plugin has dependencies that could not be found or may require a newer version of Il2CppInspector. Check that all required DLLs are present in the plugins folder." };
|
||||||
Console.Error.WriteLine($"Error loading plugin {plugin.Plugin.Name}: {plugin.Plugin.Description}");
|
Console.Error.WriteLine($"Error loading plugin {disabledPlugin.Plugin.Name}: {disabledPlugin.Plugin.Description}");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Assembly could not be found
|
// Assembly could not be found
|
||||||
case FileNotFoundException failedFile:
|
case FileNotFoundException failedFile:
|
||||||
plugin.Plugin = new InvalidPlugin { Name = name, Description = $"This plugin needs {failedFile.FileName} but the file could not be found" };
|
disabledPlugin.Plugin = new InvalidPlugin { Name = name, Description = $"This plugin needs {failedFile.FileName} but the file could not be found" };
|
||||||
Console.Error.WriteLine($"Error loading plugin {plugin.Plugin.Name}: {plugin.Plugin.Description}");
|
Console.Error.WriteLine($"Error loading plugin {disabledPlugin.Plugin.Name}: {disabledPlugin.Plugin.Description}");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Some other type loading error
|
// Some other type loading error
|
||||||
@@ -211,6 +212,14 @@ namespace Il2CppInspector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some field not implemented in class
|
||||||
|
catch (TargetInvocationException ex) when (ex.InnerException is MissingFieldException fEx) {
|
||||||
|
var name = Path.GetFileName(dll);
|
||||||
|
|
||||||
|
disabledPlugin.Plugin = new InvalidPlugin { Name = name, Description = fEx.Message };
|
||||||
|
Console.Error.WriteLine($"Error loading plugin {disabledPlugin.Plugin.Name}: {disabledPlugin.Plugin.Description} - this plugin may require a newer version of Il2CppInspector");
|
||||||
|
}
|
||||||
|
|
||||||
// Ignore unmanaged DLLs
|
// Ignore unmanaged DLLs
|
||||||
catch (BadImageFormatException) { }
|
catch (BadImageFormatException) { }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user