2020-12-24 16:33:17 -06:00
|
|
|
using System;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Runtime.Loader;
|
|
|
|
|
2020-12-28 00:43:02 -06:00
|
|
|
namespace GameServiceWarden.Core.Games.Modules
|
2020-12-24 16:33:17 -06:00
|
|
|
{
|
2020-12-28 00:43:02 -06:00
|
|
|
class GameModuleLoadContext : AssemblyLoadContext
|
2020-12-24 16:33:17 -06:00
|
|
|
{
|
2020-12-25 03:47:13 -06:00
|
|
|
private readonly AssemblyDependencyResolver dependencyResolver;
|
2020-12-24 16:33:17 -06:00
|
|
|
|
2020-12-28 00:43:02 -06:00
|
|
|
public GameModuleLoadContext(string path) {
|
2020-12-24 16:33:17 -06:00
|
|
|
dependencyResolver = new AssemblyDependencyResolver(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Assembly Load(AssemblyName assemblyName)
|
|
|
|
{
|
|
|
|
string assemblyPath = dependencyResolver.ResolveAssemblyToPath(assemblyName);
|
|
|
|
if (assemblyPath != null) {
|
|
|
|
return LoadFromAssemblyPath(assemblyPath);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
|
|
|
|
{
|
|
|
|
String libraryPath = dependencyResolver.ResolveUnmanagedDllToPath(unmanagedDllName);
|
|
|
|
if (libraryPath != null) {
|
|
|
|
return LoadUnmanagedDllFromPath(libraryPath);
|
|
|
|
}
|
|
|
|
return IntPtr.Zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|