mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-04-25 08:27:28 +00:00
Theres documentation at https://sylvessa.zip/fourkit/ now. And a bunch of other changes. Check the discord server for a more comprehensive list
47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using Minecraft.Server.FourKit.Plugin;
|
|
using System.Reflection;
|
|
using System.Runtime.Loader;
|
|
|
|
namespace Minecraft.Server.FourKit;
|
|
|
|
internal sealed class PluginLoadContext : AssemblyLoadContext
|
|
{
|
|
private readonly AssemblyDependencyResolver _resolver;
|
|
private readonly string _pluginDirectory;
|
|
|
|
public PluginLoadContext(string pluginPath)
|
|
: base(isCollectible: false)
|
|
{
|
|
_pluginDirectory = Path.GetDirectoryName(Path.GetFullPath(pluginPath))!;
|
|
_resolver = new AssemblyDependencyResolver(pluginPath);
|
|
}
|
|
|
|
protected override Assembly? Load(AssemblyName assemblyName)
|
|
{
|
|
if (assemblyName.Name == typeof(ServerPlugin).Assembly.GetName().Name)
|
|
return typeof(ServerPlugin).Assembly;
|
|
|
|
string? path = _resolver.ResolveAssemblyToPath(assemblyName);
|
|
if (path != null)
|
|
return LoadFromAssemblyPath(path);
|
|
|
|
if (assemblyName.Name != null)
|
|
{
|
|
string fallback = Path.Combine(_pluginDirectory, assemblyName.Name + ".dll");
|
|
if (File.Exists(fallback))
|
|
return LoadFromAssemblyPath(fallback);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
|
|
{
|
|
string? path = _resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
|
|
if (path != null)
|
|
return LoadUnmanagedDllFromPath(path);
|
|
|
|
return IntPtr.Zero;
|
|
}
|
|
}
|