fix dependency loading, import plugin library

This commit is contained in:
Raymond 2021-09-27 16:43:50 -04:00
parent 6ba5525812
commit 8793456a0b
10 changed files with 1328 additions and 20 deletions

View file

@ -8,8 +8,8 @@ using Dalamud.Game;
using Dalamud.IoC.Internal;
using Dalamud.Logging.Internal;
using Dalamud.Plugin.Internal.Exceptions;
using Dalamud.Plugin.Internal.Loader;
using Dalamud.Plugin.Internal.Types;
using McMaster.NETCore.Plugins;
namespace Dalamud.Plugin.Internal
{
@ -37,17 +37,18 @@ namespace Dalamud.Plugin.Internal
/// <param name="manifest">The plugin manifest.</param>
public LocalPlugin(FileInfo dllFile, LocalPluginManifest? manifest)
{
if (dllFile.Name == "FFXIVClientStructs.Generators.dll")
{
// Could this be done another way? Sure. It is an extremely common source
// of errors in the log through, and should never be loaded as a plugin.
Log.Error($"Not a plugin: {dllFile.FullName}");
throw new InvalidPluginException(dllFile);
}
this.DllFile = dllFile;
this.State = PluginState.Unloaded;
this.loader = PluginLoader.CreateFromAssemblyFile(
this.DllFile.FullName,
config =>
{
config.IsUnloadable = true;
config.LoadInMemory = true;
config.PreferSharedTypes = true;
});
this.loader = PluginLoader.CreateFromAssemblyFile(this.DllFile.FullName, this.SetupLoaderConfig);
try
{
@ -252,14 +253,7 @@ namespace Dalamud.Plugin.Internal
try
{
this.loader ??= PluginLoader.CreateFromAssemblyFile(
this.DllFile.FullName,
config =>
{
config.IsUnloadable = true;
config.LoadInMemory = true;
config.PreferSharedTypes = true;
});
this.loader ??= PluginLoader.CreateFromAssemblyFile(this.DllFile.FullName, this.SetupLoaderConfig);
if (reloading)
{
@ -437,6 +431,15 @@ namespace Dalamud.Plugin.Internal
this.SaveManifest();
}
private void SetupLoaderConfig(LoaderConfig config)
{
config.IsUnloadable = true;
config.LoadInMemory = true;
config.PreferSharedTypes = false;
config.SharedAssemblies.Add(typeof(Lumina.GameData).Assembly.GetName());
config.SharedAssemblies.Add(typeof(Lumina.Excel.ExcelSheetImpl).Assembly.GetName());
}
private void SaveManifest() => this.Manifest.Save(this.manifestFile);
}
}