7502018d20
There is an asset in the store I grabbed. the coding is WAY above my head, I got about half of it and integrated and adapted what I can to it. im going as far as I can with it and ill come back in a few month when I understand t better.
66 lines
1.3 KiB
C#
66 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Mono.Cecil;
|
|
|
|
namespace ModTool.Shared
|
|
{
|
|
|
|
public class AssemblyResolver : DefaultAssemblyResolver
|
|
{
|
|
private Dictionary<string, AssemblyDefinition> cache;
|
|
|
|
private ReaderParameters parameters;
|
|
|
|
public AssemblyResolver()
|
|
{
|
|
cache = new Dictionary<string, AssemblyDefinition>();
|
|
|
|
parameters = new ReaderParameters()
|
|
{
|
|
AssemblyResolver = this,
|
|
InMemory = true
|
|
};
|
|
}
|
|
|
|
public override AssemblyDefinition Resolve(AssemblyNameReference name)
|
|
{
|
|
AssemblyDefinition assemblyDefinition;
|
|
|
|
if (cache.TryGetValue(name.Name, out assemblyDefinition))
|
|
return assemblyDefinition;
|
|
|
|
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
|
{
|
|
if(assembly.GetName().Name == name.Name)
|
|
{
|
|
string location = assembly.Location;
|
|
|
|
assemblyDefinition = GetAssembly(location, parameters);
|
|
|
|
cache.Add(name.Name, assemblyDefinition);
|
|
|
|
return assemblyDefinition;
|
|
}
|
|
}
|
|
|
|
return base.Resolve(name);
|
|
}
|
|
|
|
protected virtual AssemblyDefinition GetAssembly(string location, ReaderParameters parameters)
|
|
{
|
|
return ModuleDefinition.ReadModule(location, parameters).Assembly;
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
foreach (var assembly in cache.Values)
|
|
assembly.Dispose();
|
|
|
|
cache.Clear();
|
|
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
|
|
}
|