mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-25 05:40:21 -04:00
If the AssemblyLoader attempted to load a non-csil dll while iterating through the file list, it would catch the exception OUTSIDE the loop, and wouldn't load the rest. This fix makes it catch inside the loop so it will continue iterating.
66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using Mono.Cecil;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace AssetStudio
|
|
{
|
|
public class AssemblyLoader
|
|
{
|
|
public bool Loaded;
|
|
private Dictionary<string, ModuleDefinition> moduleDic = new Dictionary<string, ModuleDefinition>();
|
|
|
|
public void Load(string path)
|
|
{
|
|
var files = Directory.GetFiles(path, "*.dll");
|
|
var resolver = new MyAssemblyResolver();
|
|
var readerParameters = new ReaderParameters();
|
|
readerParameters.AssemblyResolver = resolver;
|
|
foreach (var file in files)
|
|
{
|
|
try
|
|
{
|
|
var assembly = AssemblyDefinition.ReadAssembly(file, readerParameters);
|
|
resolver.Register(assembly);
|
|
moduleDic.Add(assembly.MainModule.Name, assembly.MainModule);
|
|
}
|
|
catch
|
|
{
|
|
// ignored
|
|
}
|
|
}
|
|
Loaded = true;
|
|
}
|
|
|
|
public TypeDefinition GetTypeDefinition(string assemblyName, string fullName)
|
|
{
|
|
if (moduleDic.TryGetValue(assemblyName, out var module))
|
|
{
|
|
var typeDef = module.GetType(fullName);
|
|
if (typeDef == null && assemblyName == "UnityEngine.dll")
|
|
{
|
|
foreach (var pair in moduleDic)
|
|
{
|
|
typeDef = pair.Value.GetType(fullName);
|
|
if (typeDef != null)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return typeDef;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
foreach (var pair in moduleDic)
|
|
{
|
|
pair.Value.Dispose();
|
|
}
|
|
moduleDic.Clear();
|
|
Loaded = false;
|
|
}
|
|
}
|
|
}
|