This commit is contained in:
vis2k 2021-08-22 20:46:38 +08:00
parent 852ef64034
commit 08fdffd6ab

View File

@ -155,17 +155,24 @@ static bool WeaveFromFile(string assemblyPath, string[] dependencies)
// open the file as stream // open the file as stream
using (FileStream stream = new FileStream(assemblyPath, FileMode.Open, FileAccess.ReadWrite)) using (FileStream stream = new FileStream(assemblyPath, FileMode.Open, FileAccess.ReadWrite))
{ {
// resolver for this assembly
using (DefaultAssemblyResolver asmResolver = new DefaultAssemblyResolver()) using (DefaultAssemblyResolver asmResolver = new DefaultAssemblyResolver())
{ {
// read assembly with the following parameters
ReaderParameters readerParameters = new ReaderParameters { ReaderParameters readerParameters = new ReaderParameters {
ReadWrite = true, ReadWrite = true,
ReadSymbols = true, ReadSymbols = true,
AssemblyResolver = asmResolver AssemblyResolver = asmResolver
}; };
// read assembly from stream with parameters
using (AssemblyDefinition asmDef = AssemblyDefinition.ReadAssembly(stream, readerParameters)) using (AssemblyDefinition asmDef = AssemblyDefinition.ReadAssembly(stream, readerParameters))
{ {
// add this assembly's path and unity's assembly path
asmResolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath)); asmResolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath));
asmResolver.AddSearchDirectory(Helpers.UnityEngineDllDirectoryName()); asmResolver.AddSearchDirectory(Helpers.UnityEngineDllDirectoryName());
// add dependencies
if (dependencies != null) if (dependencies != null)
{ {
foreach (string path in dependencies) foreach (string path in dependencies)