- add: script abilities
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
||||||
<PackageReference Include="libsodium" Version="1.0.20"/>
|
<PackageReference Include="libsodium" Version="1.0.20"/>
|
||||||
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
||||||
|
<PackageReference Include="NLua" Version="1.7.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Lib.Harmony" Version="2.3.6" />
|
<PackageReference Include="Lib.Harmony" Version="2.3.6" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
||||||
|
<PackageReference Include="NLua" Version="1.7.5" />
|
||||||
<PackageReference Include="SharpZstd.Interop" Version="1.5.6"/>
|
<PackageReference Include="SharpZstd.Interop" Version="1.5.6"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
using System.Data;
|
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Nebula.Shared;
|
using Nebula.Shared;
|
||||||
|
|
||||||
namespace Nebula.Runner.Services;
|
namespace Nebula.Runner.Services;
|
||||||
|
|
||||||
[ServiceRegister]
|
[ServiceRegister]
|
||||||
public class HarmonyService(ReflectionService reflectionService)
|
public class HarmonyService
|
||||||
{
|
{
|
||||||
private HarmonyInstance? _instance;
|
private HarmonyInstance? _instance;
|
||||||
|
|
||||||
@@ -25,21 +24,6 @@ public class HarmonyService(ReflectionService reflectionService)
|
|||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
|
||||||
_instance = new HarmonyInstance();
|
_instance = new HarmonyInstance();
|
||||||
UnShittyWizard();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Я помню пенис большой,Я помню пенис большой, Я помню пенис большой, я помню....
|
|
||||||
/// </summary>
|
|
||||||
private void UnShittyWizard()
|
|
||||||
{
|
|
||||||
var method = reflectionService.GetType("Robust.Client.GameController").TypeInitializer;
|
|
||||||
_instance!.Harmony.Patch(method, new HarmonyMethod(Prefix));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool Prefix()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,29 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Nebula.Shared;
|
using Nebula.Shared;
|
||||||
using Nebula.Shared.FileApis;
|
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
|
||||||
namespace Nebula.Runner.Services;
|
namespace Nebula.Runner.Services;
|
||||||
|
|
||||||
[ServiceRegister]
|
[ServiceRegister]
|
||||||
public class ReflectionService(AssemblyService assemblyService)
|
public class ReflectionService
|
||||||
{
|
{
|
||||||
private Dictionary<string, Assembly> _typeCache = new();
|
private readonly Dictionary<string, Assembly> _typeCache = new();
|
||||||
|
|
||||||
|
public ReflectionService(AssemblyService assemblyService)
|
||||||
|
{
|
||||||
|
assemblyService.OnAssemblyLoaded += OnAssemblyLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAssemblyLoaded(Assembly obj)
|
||||||
|
{
|
||||||
|
RegisterAssembly(obj);
|
||||||
|
}
|
||||||
|
|
||||||
public void RegisterAssembly(Assembly robustAssembly)
|
public void RegisterAssembly(Assembly robustAssembly)
|
||||||
{
|
{
|
||||||
_typeCache.Add(robustAssembly.GetName().Name!, robustAssembly);
|
_typeCache.Add(robustAssembly.GetName().Name!, robustAssembly);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterRobustAssemblies(AssemblyApi engine)
|
|
||||||
{
|
|
||||||
RegisterAssembly(GetRobustAssembly("Robust.Shared", engine));
|
|
||||||
RegisterAssembly(GetRobustAssembly("Robust.Client", engine));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Assembly GetRobustAssembly(string assemblyName, AssemblyApi engine)
|
|
||||||
{
|
|
||||||
if(!assemblyService.TryOpenAssembly(assemblyName, engine, out var assembly))
|
|
||||||
throw new Exception($"Unable to locate {assemblyName}.dll in engine build!");
|
|
||||||
return assembly;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type? GetTypeImp(string name)
|
public Type? GetTypeImp(string name)
|
||||||
{
|
{
|
||||||
foreach (var (prefix,assembly) in _typeCache)
|
foreach (var (prefix,assembly) in _typeCache)
|
||||||
@@ -51,7 +47,7 @@ public class ReflectionService(AssemblyService assemblyService)
|
|||||||
: assembly.GetType(name)!;
|
: assembly.GetType(name)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ExtrackPrefix(string path)
|
public string ExtrackPrefix(string path)
|
||||||
{
|
{
|
||||||
var sp = path.Split(".");
|
var sp = path.Split(".");
|
||||||
return sp[0] + "." + sp[1];
|
return sp[0] + "." + sp[1];
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Reflection.Emit;
|
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Nebula.Shared;
|
using Nebula.Shared;
|
||||||
using Nebula.Shared.Models;
|
using Nebula.Shared.Models;
|
||||||
@@ -18,9 +17,10 @@ public sealed class RunnerService(
|
|||||||
EngineService engineService,
|
EngineService engineService,
|
||||||
AssemblyService assemblyService,
|
AssemblyService assemblyService,
|
||||||
ReflectionService reflectionService,
|
ReflectionService reflectionService,
|
||||||
HarmonyService harmonyService)
|
HarmonyService harmonyService,
|
||||||
|
ScriptService scriptService)
|
||||||
{
|
{
|
||||||
private ILogger _logger = debugService.GetLogger("RunnerService");
|
private readonly ILogger _logger = debugService.GetLogger("RunnerService");
|
||||||
private bool MetricEnabled = false; //TODO: ADD METRIC THINKS LATER
|
private bool MetricEnabled = false; //TODO: ADD METRIC THINKS LATER
|
||||||
|
|
||||||
public async Task Run(string[] runArgs, RobustBuildInfo buildInfo, IRedialApi redialApi,
|
public async Task Run(string[] runArgs, RobustBuildInfo buildInfo, IRedialApi redialApi,
|
||||||
@@ -58,6 +58,24 @@ public sealed class RunnerService(
|
|||||||
|
|
||||||
var args = new MainArgs(runArgs, engine, redialApi, extraMounts);
|
var args = new MainArgs(runArgs, engine, redialApi, extraMounts);
|
||||||
|
|
||||||
|
|
||||||
|
var assemblyManifest = hashApi.Manifest.Where(p =>
|
||||||
|
p.Key.StartsWith("Assemblies/"))
|
||||||
|
.Select(p =>
|
||||||
|
{
|
||||||
|
return p.Value with { Path = Path.GetFileNameWithoutExtension(p.Key) };
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var assembliesHash = contentService.CreateHashApi(assemblyManifest);
|
||||||
|
|
||||||
|
var contentAssemblyApi = assemblyService.Mount(assembliesHash);
|
||||||
|
|
||||||
|
foreach (var file in contentAssemblyApi.AllFiles.Where(p => Path.GetExtension(p) == ".dll"))
|
||||||
|
{
|
||||||
|
var newExt = Path.GetFileNameWithoutExtension(file);
|
||||||
|
if(!assemblyService.TryOpenAssembly(newExt, contentAssemblyApi, out _)) throw new Exception("Assembly not found: " + newExt);
|
||||||
|
}
|
||||||
|
|
||||||
if (!assemblyService.TryOpenAssembly(varService.GetConfigValue(CurrentConVar.RobustAssemblyName)!, engine,
|
if (!assemblyService.TryOpenAssembly(varService.GetConfigValue(CurrentConVar.RobustAssemblyName)!, engine,
|
||||||
out var clientAssembly))
|
out var clientAssembly))
|
||||||
throw new Exception("Unable to locate Robust.Client.dll in engine build!");
|
throw new Exception("Unable to locate Robust.Client.dll in engine build!");
|
||||||
@@ -68,7 +86,6 @@ public sealed class RunnerService(
|
|||||||
if(!assemblyService.TryOpenAssembly("Prometheus.NetStandard", engine, out var prometheusAssembly))
|
if(!assemblyService.TryOpenAssembly("Prometheus.NetStandard", engine, out var prometheusAssembly))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
reflectionService.RegisterRobustAssemblies(engine);
|
|
||||||
harmonyService.CreateInstance();
|
harmonyService.CreateInstance();
|
||||||
|
|
||||||
IDisposable? metricServer = null;
|
IDisposable? metricServer = null;
|
||||||
@@ -78,12 +95,18 @@ public sealed class RunnerService(
|
|||||||
MetricsEnabledPatcher.ApplyPatch(reflectionService, harmonyService);
|
MetricsEnabledPatcher.ApplyPatch(reflectionService, harmonyService);
|
||||||
metricServer = RunHelper.RunMetric(prometheusAssembly);
|
metricServer = RunHelper.RunMetric(prometheusAssembly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scriptService.LoadScripts();
|
||||||
|
|
||||||
await Task.Run(() => loader.Main(args), cancellationToken);
|
await Task.Run(() => loader.Main(args), cancellationToken);
|
||||||
|
|
||||||
metricServer?.Dispose();
|
metricServer?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CacheAssembly()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MetricsEnabledPatcher
|
public static class MetricsEnabledPatcher
|
||||||
|
|||||||
181
Nebula.Runner/Services/ScriptService.cs
Normal file
181
Nebula.Runner/Services/ScriptService.cs
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using HarmonyLib;
|
||||||
|
using Nebula.Shared;
|
||||||
|
using Nebula.Shared.FileApis;
|
||||||
|
using Nebula.Shared.Services;
|
||||||
|
using NLua;
|
||||||
|
|
||||||
|
namespace Nebula.Runner.Services;
|
||||||
|
|
||||||
|
[ServiceRegister]
|
||||||
|
public class ScriptService
|
||||||
|
{
|
||||||
|
private readonly HarmonyService _harmonyService;
|
||||||
|
private readonly ReflectionService _reflectionService;
|
||||||
|
private readonly AssemblyService _assemblyService;
|
||||||
|
|
||||||
|
private readonly FileApi _scriptFileApi;
|
||||||
|
|
||||||
|
private static Dictionary<MethodBase, ScriptManifestDict> _scriptCache = [];
|
||||||
|
private static Dictionary<string, Action> _assemblyLoadingQuery = [];
|
||||||
|
|
||||||
|
public ScriptService(HarmonyService harmonyService, ReflectionService reflectionService, FileService fileService, AssemblyService assemblyService)
|
||||||
|
{
|
||||||
|
_harmonyService = harmonyService;
|
||||||
|
_reflectionService = reflectionService;
|
||||||
|
_assemblyService = assemblyService;
|
||||||
|
|
||||||
|
_scriptFileApi = fileService.CreateFileApi("scripts");
|
||||||
|
_assemblyService.OnAssemblyLoaded += OnAssemblyLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAssemblyLoaded(Assembly obj)
|
||||||
|
{
|
||||||
|
var objName = obj.GetName().Name ?? string.Empty;
|
||||||
|
if (!_assemblyLoadingQuery.TryGetValue(objName, out var a)) return;
|
||||||
|
Console.WriteLine("Inject assembly: " + objName);
|
||||||
|
a();
|
||||||
|
_assemblyLoadingQuery.Remove(objName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadScripts()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Loading scripts... " + _scriptFileApi.EnumerateDirectories("").Count());
|
||||||
|
foreach (var dir in _scriptFileApi.EnumerateDirectories(""))
|
||||||
|
{
|
||||||
|
LoadScript(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadScript(string name)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Reading script {name}");
|
||||||
|
var manifests = ReadManifest(name);
|
||||||
|
|
||||||
|
foreach (var entry in manifests)
|
||||||
|
{
|
||||||
|
if (entry.TypeInitializer.HasValue) LoadTypeInitializer(entry.TypeInitializer.Value, name);
|
||||||
|
if (entry.Method.HasValue) LoadMethod(entry.Method.Value, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadTypeInitializer(ScriptMethodInjectItem item, string name)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Loading Initializer injection {name}...");
|
||||||
|
var assemblyName = _reflectionService.ExtrackPrefix(item.Method.Class);
|
||||||
|
|
||||||
|
if (!_assemblyService.Assemblies.Select(a => a.GetName().Name).Contains(assemblyName))
|
||||||
|
{
|
||||||
|
_assemblyLoadingQuery.Add(assemblyName, () => LoadTypeInitializer(item, name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetType = _reflectionService.GetType(item.Method.Class);
|
||||||
|
var method = targetType.TypeInitializer;
|
||||||
|
InitialiseShared(method!, name, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadMethod(ScriptMethodInjectItem item, string name)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Loading method injection {name}...");
|
||||||
|
var assemblyName = _reflectionService.ExtrackPrefix(item.Method.Class);
|
||||||
|
|
||||||
|
if (!_assemblyService.Assemblies.Select(a => a.GetName().Name).Contains(assemblyName))
|
||||||
|
{
|
||||||
|
_assemblyLoadingQuery.Add(assemblyName, () => LoadMethod(item, name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetType = _reflectionService.GetType(item.Method.Class);
|
||||||
|
var method = targetType.GetMethod(item.Method.Method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||||
|
InitialiseShared(method!, name, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitialiseShared(MethodBase method, string scriptName, ScriptMethodInjectItem item)
|
||||||
|
{
|
||||||
|
var scriptCode = File.ReadAllText(Path.Combine(_scriptFileApi.RootPath, scriptName, item.Script.LuaFile));
|
||||||
|
|
||||||
|
var methodInfo = method as MethodInfo;
|
||||||
|
HarmonyMethod dynamicPatch;
|
||||||
|
|
||||||
|
if (methodInfo == null || methodInfo.ReturnType == typeof(void))
|
||||||
|
dynamicPatch = new HarmonyMethod(typeof(ScriptService).GetMethod(nameof(LuaPrefix), BindingFlags.Static | BindingFlags.NonPublic));
|
||||||
|
else
|
||||||
|
dynamicPatch = new HarmonyMethod(typeof(ScriptService).GetMethod(nameof(LuaPrefixResult), BindingFlags.Static | BindingFlags.NonPublic));
|
||||||
|
|
||||||
|
_scriptCache[method] = new ScriptManifestDict(scriptCode, item);
|
||||||
|
|
||||||
|
_harmonyService.Instance.Harmony.Patch(method, prefix: dynamicPatch);
|
||||||
|
Console.WriteLine($"Injected {scriptName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScriptEntry[] ReadManifest(string scriptName)
|
||||||
|
{
|
||||||
|
if(!_scriptFileApi.TryOpen(Path.Join(scriptName, "MANIFEST.json"), out var stream))
|
||||||
|
throw new FileNotFoundException(Path.Join(scriptName, "MANIFEST.json") + " not found manifest!");
|
||||||
|
|
||||||
|
return JsonSerializer.Deserialize<ScriptEntry[]>(stream) ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool LuaPrefix(MethodBase __originalMethod, object __instance)
|
||||||
|
{
|
||||||
|
if (!_scriptCache.TryGetValue(__originalMethod, out var luaCode))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
using var lua = new Lua();
|
||||||
|
|
||||||
|
lua["this"] = __instance;
|
||||||
|
|
||||||
|
var results = lua.DoString(luaCode.Code);
|
||||||
|
|
||||||
|
if (results is { Length: > 0 } && results[0] is bool b)
|
||||||
|
return b;
|
||||||
|
|
||||||
|
return luaCode.ScriptMethodInjectItem.ContinueAfterInject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool LuaPrefixResult(MethodBase __originalMethod, object __instance, ref object __result)
|
||||||
|
{
|
||||||
|
if (!_scriptCache.TryGetValue(__originalMethod, out var luaCode))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
using var lua = new Lua();
|
||||||
|
|
||||||
|
lua["this"] = __instance;
|
||||||
|
lua["result"] = __result;
|
||||||
|
|
||||||
|
var results = lua.DoString(luaCode.Code);
|
||||||
|
|
||||||
|
if (lua["result"] != null)
|
||||||
|
__result = lua["result"];
|
||||||
|
|
||||||
|
if (results is { Length: > 0 } && results[0] is bool b)
|
||||||
|
return b;
|
||||||
|
|
||||||
|
return luaCode.ScriptMethodInjectItem.ContinueAfterInject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record struct ScriptManifestDict(string Code, ScriptMethodInjectItem ScriptMethodInjectItem);
|
||||||
|
|
||||||
|
public record struct ScriptEntry(
|
||||||
|
[property: JsonPropertyName("method")] ScriptMethodInjectItem? Method,
|
||||||
|
[property: JsonPropertyName("type_initializer")] ScriptMethodInjectItem? TypeInitializer
|
||||||
|
);
|
||||||
|
|
||||||
|
public record struct ScriptMethodInjectItem(
|
||||||
|
[property: JsonPropertyName("method")] ScriptMethodInfo Method,
|
||||||
|
[property: JsonPropertyName("continue")] bool ContinueAfterInject,
|
||||||
|
[property: JsonPropertyName("script")] LuaMethodEntry Script
|
||||||
|
);
|
||||||
|
|
||||||
|
public record struct ScriptMethodInfo(
|
||||||
|
[property: JsonPropertyName("class")] string Class,
|
||||||
|
[property: JsonPropertyName("method")] string Method
|
||||||
|
);
|
||||||
|
|
||||||
|
public record struct LuaMethodEntry(
|
||||||
|
[property: JsonPropertyName("lua_file")] string LuaFile
|
||||||
|
);
|
||||||
@@ -75,6 +75,11 @@ public sealed class FileApi : IReadWriteFileApi
|
|||||||
return File.Exists(fullPath);
|
return File.Exists(fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> EnumerateDirectories(string path)
|
||||||
|
{
|
||||||
|
return Directory.GetDirectories(Path.Join(RootPath, path)).Select(p=>p.Replace(RootPath,"").Substring(1));
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerable<string> GetAllFiles(){
|
private IEnumerable<string> GetAllFiles(){
|
||||||
|
|
||||||
if(!Directory.Exists(RootPath)) return [];
|
if(!Directory.Exists(RootPath)) return [];
|
||||||
|
|||||||
@@ -12,15 +12,23 @@ namespace Nebula.Shared.Services;
|
|||||||
[ServiceRegister]
|
[ServiceRegister]
|
||||||
public class AssemblyService
|
public class AssemblyService
|
||||||
{
|
{
|
||||||
private readonly List<Assembly> _assemblies = new();
|
private readonly Dictionary<string, Assembly> _assemblyCache = new();
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly HashSet<string> _resolvingAssemblies = new();
|
private readonly HashSet<string> _resolvingAssemblies = new();
|
||||||
|
|
||||||
|
private List<AssemblyApi> _mountedApis = [];
|
||||||
|
|
||||||
|
public Action<Assembly>? OnAssemblyLoaded;
|
||||||
|
public IReadOnlyList<Assembly> Assemblies => _assemblyCache.Values.ToList().AsReadOnly();
|
||||||
|
|
||||||
public AssemblyService(DebugService debugService)
|
public AssemblyService(DebugService debugService)
|
||||||
{
|
{
|
||||||
_logger = debugService.GetLogger(this);
|
_logger = debugService.GetLogger(this);
|
||||||
|
|
||||||
|
AssemblyLoadContext.Default.ResolvingUnmanagedDll += LoadContextOnResolvingUnmanaged;
|
||||||
|
AssemblyLoadContext.Default.Resolving += (context, name) => OnAssemblyResolving(context, name);
|
||||||
|
|
||||||
ZstdImportResolver.ResolveLibrary += (name, assembly1, path) =>
|
ZstdImportResolver.ResolveLibrary += (name, assembly1, path) =>
|
||||||
{
|
{
|
||||||
if (name.Equals("SharpZstd.Native"))
|
if (name.Equals("SharpZstd.Native"))
|
||||||
@@ -36,21 +44,41 @@ public class AssemblyService
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<Assembly> Assemblies => _assemblies;
|
private Assembly? OnAssemblyResolving(AssemblyLoadContext context, AssemblyName name)
|
||||||
|
{
|
||||||
|
if (_resolvingAssemblies.Contains(name.FullName))
|
||||||
|
{
|
||||||
|
_logger.Debug($"Already resolving {name.Name}, skipping.");
|
||||||
|
return null; // Prevent recursive resolution
|
||||||
|
}
|
||||||
|
|
||||||
|
Assembly? assembly;
|
||||||
|
|
||||||
|
if (_assemblyCache.TryGetValue(name.Name ?? "", out assembly))
|
||||||
|
{
|
||||||
|
return assembly;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var api in _mountedApis)
|
||||||
|
{
|
||||||
|
if((assembly = OnAssemblyResolving(context, name, api)) != null)
|
||||||
|
return assembly;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public AssemblyApi Mount(IFileApi fileApi)
|
public AssemblyApi Mount(IFileApi fileApi)
|
||||||
{
|
{
|
||||||
var asmApi = new AssemblyApi(fileApi);
|
var asmApi = new AssemblyApi(fileApi);
|
||||||
AssemblyLoadContext.Default.Resolving += (context, name) => OnAssemblyResolving(context, name, asmApi);
|
_mountedApis.Add(asmApi);
|
||||||
AssemblyLoadContext.Default.ResolvingUnmanagedDll += LoadContextOnResolvingUnmanaged;
|
|
||||||
|
|
||||||
return asmApi;
|
return asmApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGetLoader(Assembly clientAssembly, [NotNullWhen(true)] out ILoaderEntryPoint? loader)
|
public bool TryGetLoader(Assembly clientAssembly, [NotNullWhen(true)] out ILoaderEntryPoint? loader)
|
||||||
{
|
{
|
||||||
loader = null;
|
loader = null;
|
||||||
// Find ILoaderEntryPoint with the LoaderEntryPointAttribute
|
|
||||||
var attrib = clientAssembly.GetCustomAttribute<LoaderEntryPointAttribute>();
|
var attrib = clientAssembly.GetCustomAttribute<LoaderEntryPointAttribute>();
|
||||||
if (attrib == null)
|
if (attrib == null)
|
||||||
{
|
{
|
||||||
@@ -79,9 +107,11 @@ public class AssemblyService
|
|||||||
|
|
||||||
assembly = AssemblyLoadContext.Default.LoadFromStream(asm, pdb);
|
assembly = AssemblyLoadContext.Default.LoadFromStream(asm, pdb);
|
||||||
_logger.Log("LOADED ASSEMBLY " + name);
|
_logger.Log("LOADED ASSEMBLY " + name);
|
||||||
|
|
||||||
|
if (_assemblyCache.TryAdd(name, assembly))
|
||||||
if (!_assemblies.Contains(assembly)) _assemblies.Add(assembly);
|
{
|
||||||
|
OnAssemblyLoaded?.Invoke(assembly);
|
||||||
|
}
|
||||||
|
|
||||||
asm.Dispose();
|
asm.Dispose();
|
||||||
pdb?.Dispose();
|
pdb?.Dispose();
|
||||||
@@ -103,21 +133,18 @@ public class AssemblyService
|
|||||||
|
|
||||||
private Assembly? OnAssemblyResolving(AssemblyLoadContext context, AssemblyName name, AssemblyApi assemblyApi)
|
private Assembly? OnAssemblyResolving(AssemblyLoadContext context, AssemblyName name, AssemblyApi assemblyApi)
|
||||||
{
|
{
|
||||||
if (_resolvingAssemblies.Contains(name.FullName))
|
lock (_resolvingAssemblies)
|
||||||
{
|
{
|
||||||
_logger.Debug($"Already resolving {name.Name}, skipping.");
|
try
|
||||||
return null; // Prevent recursive resolution
|
{
|
||||||
}
|
_resolvingAssemblies.Add(name.FullName);
|
||||||
|
_logger.Debug($"Resolving assembly from FileAPI: {name.Name}");
|
||||||
try
|
return TryOpenAssembly(name.Name!, assemblyApi, out var assembly) ? assembly : null;
|
||||||
{
|
}
|
||||||
_resolvingAssemblies.Add(name.FullName);
|
finally
|
||||||
_logger.Debug($"Resolving assembly from FileAPI: {name.Name}");
|
{
|
||||||
return TryOpenAssembly(name.Name!, assemblyApi, out var assembly) ? assembly : null;
|
_resolvingAssemblies.Remove(name.FullName);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
_resolvingAssemblies.Remove(name.FullName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class FileService
|
|||||||
Directory.CreateDirectory(RootPath);
|
Directory.CreateDirectory(RootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadWriteFileApi CreateFileApi(string path)
|
public FileApi CreateFileApi(string path)
|
||||||
{
|
{
|
||||||
_logger.Debug($"Creating file api for {path}");
|
_logger.Debug($"Creating file api for {path}");
|
||||||
return new FileApi(Path.Join(RootPath, path));
|
return new FileApi(Path.Join(RootPath, path));
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArchiving_002EUtils_002EWindows_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F27e9f12ad1e4318b9b02849ec3e6a502fa3ee761c4f0522ba756ab30cde1c_003FArchiving_002EUtils_002EWindows_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArchiving_002EUtils_002EWindows_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F27e9f12ad1e4318b9b02849ec3e6a502fa3ee761c4f0522ba756ab30cde1c_003FArchiving_002EUtils_002EWindows_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAssemblyLoadContext_002ECoreCLR_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F99b58e5049c4c1b08628baf3843f62e765df3a131566566b5bcf4a2c47fb4bd_003FAssemblyLoadContext_002ECoreCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAssemblyLoadContext_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa6b7f037ba7b44df80b8d3aa7e58eeb2e8e938_003F9f_003F247e98fb_003FAssemblyLoadContext_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAssemblyLoadContext_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F47e646b7b981834f2b1298e9ba8543fc4994cc50e15f81d515ec883b6e3797b_003FAssemblyLoadContext_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAssemblyName_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fe151f62e5a2bc2dcf247d43eb37d7ba6ae4177aabc3e46e7aa6563b35a374536_003FAssemblyName_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAssembly_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F501151723a8d43558c75acbd334f26322066fa4b1c82b1297291314bf92ff_003FAssembly_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAssembly_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F501151723a8d43558c75acbd334f26322066fa4b1c82b1297291314bf92ff_003FAssembly_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAuthenticationHeaderValue_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F88b338246f59cffdb6f3dc3d8dbcfc169599dc71d6f44a8f2732983db7f73a_003FAuthenticationHeaderValue_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAuthenticationHeaderValue_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F88b338246f59cffdb6f3dc3d8dbcfc169599dc71d6f44a8f2732983db7f73a_003FAuthenticationHeaderValue_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAvaloniaXamlLoader_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F80462644bd1cc7e0b229dc4f5752b48c01cb67b46ae563b1b5078cc2556b98_003FAvaloniaXamlLoader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAvaloniaXamlLoader_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F80462644bd1cc7e0b229dc4f5752b48c01cb67b46ae563b1b5078cc2556b98_003FAvaloniaXamlLoader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
@@ -38,6 +42,7 @@
|
|||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AJsonSerializer_002ERead_002EString_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F27c4858128168eda568c1334d70d5241efb9461e2a3209258a04deee5d9c367_003FJsonSerializer_002ERead_002EString_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AJsonSerializer_002ERead_002EString_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F27c4858128168eda568c1334d70d5241efb9461e2a3209258a04deee5d9c367_003FJsonSerializer_002ERead_002EString_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKnownHeader_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F1079f3c57a31ec97cba3b6ebb3d45c5a4afcdf6fa483a4db57c3d58ea59d7a9_003FKnownHeader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKnownHeader_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F1079f3c57a31ec97cba3b6ebb3d45c5a4afcdf6fa483a4db57c3d58ea59d7a9_003FKnownHeader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AListBox_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F3a6cdc26ff4d30986a9a16b6bbc9bb6a7f2657431c82cde5c66dd377cf51e2b_003FListBox_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AListBox_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F3a6cdc26ff4d30986a9a16b6bbc9bb6a7f2657431c82cde5c66dd377cf51e2b_003FListBox_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMethodInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6bd3b909e3250b8181899b1a1238cd417918c6c816fbeba173df45af2ec41e_003FMethodInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMetricServer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb07ddb833489431aae882d295a4e94797e00_003Fcf_003F23af7cad_003FMetricServer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMetricServer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb07ddb833489431aae882d295a4e94797e00_003Fcf_003F23af7cad_003FMetricServer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMetricServer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F66d3496ea2e7f3cbfb5f2ba1362869af0588ac72e87912659693443b5b7c3a_003FMetricServer_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMetricServer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F66d3496ea2e7f3cbfb5f2ba1362869af0588ac72e87912659693443b5b7c3a_003FMetricServer_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMetrics_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb07ddb833489431aae882d295a4e94797e00_003F0f_003Fc9e3d448_003FMetrics_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMetrics_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb07ddb833489431aae882d295a4e94797e00_003F0f_003Fc9e3d448_003FMetrics_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
|||||||
Reference in New Issue
Block a user