|
@@ -16,13 +16,6 @@ namespace BepInEx.Bootstrap
|
|
|
/// </summary>
|
|
|
public static class TypeLoader
|
|
|
{
|
|
|
- private static bool Is(this TypeDefinition self, Type td)
|
|
|
- {
|
|
|
- if (self.FullName == td.FullName)
|
|
|
- return true;
|
|
|
- return self.FullName != "System.Object" && (self.BaseType?.Resolve().Is(td) ?? false);
|
|
|
- }
|
|
|
-
|
|
|
private static DefaultAssemblyResolver resolver;
|
|
|
private static ReaderParameters readerParameters;
|
|
|
|
|
@@ -35,7 +28,9 @@ namespace BepInEx.Bootstrap
|
|
|
{
|
|
|
var name = new AssemblyName(reference.FullName);
|
|
|
|
|
|
- if (Utility.TryResolveDllAssembly(name, Paths.BepInExAssemblyDirectory, readerParameters, out AssemblyDefinition assembly) || Utility.TryResolveDllAssembly(name, Paths.PluginPath, readerParameters, out assembly) || Utility.TryResolveDllAssembly(name, Paths.ManagedPath, readerParameters, out assembly))
|
|
|
+ if (Utility.TryResolveDllAssembly(name, Paths.BepInExAssemblyDirectory, readerParameters, out AssemblyDefinition assembly) ||
|
|
|
+ Utility.TryResolveDllAssembly(name, Paths.PluginPath, readerParameters, out assembly) ||
|
|
|
+ Utility.TryResolveDllAssembly(name, Paths.ManagedPath, readerParameters, out assembly))
|
|
|
return assembly;
|
|
|
|
|
|
return null;
|
|
@@ -48,11 +43,9 @@ namespace BepInEx.Bootstrap
|
|
|
/// <typeparam name="T">The specific base type to search for.</typeparam>
|
|
|
/// <param name="directory">The directory to search for assemblies.</param>
|
|
|
/// <returns>Returns a list of found derivative types.</returns>
|
|
|
- public static Dictionary<AssemblyDefinition, IEnumerable<PluginInfo>> FindPluginTypes(string directory)
|
|
|
+ public static Dictionary<AssemblyDefinition, IEnumerable<T>> FindPluginTypes<T>(string directory, Func<TypeDefinition, T> typeSelector) where T : class
|
|
|
{
|
|
|
- var result = new Dictionary<AssemblyDefinition, IEnumerable<PluginInfo>>();
|
|
|
- var pluginType = typeof(BaseUnityPlugin);
|
|
|
- string currentProcess = Process.GetCurrentProcess().ProcessName.ToLower();
|
|
|
+ var result = new Dictionary<AssemblyDefinition, IEnumerable<T>>();
|
|
|
|
|
|
foreach (string dll in Directory.GetFiles(Path.GetFullPath(directory), "*.dll", SearchOption.AllDirectories))
|
|
|
{
|
|
@@ -60,47 +53,15 @@ namespace BepInEx.Bootstrap
|
|
|
{
|
|
|
var ass = AssemblyDefinition.ReadAssembly(dll, readerParameters);
|
|
|
|
|
|
- var matchingTypes = ass.MainModule.Types.Where(t => !t.IsInterface && !t.IsAbstract && t.Is(pluginType)).ToList();
|
|
|
+ var matches = ass.MainModule.Types.Select(typeSelector).Where(t => t != null).ToList();
|
|
|
|
|
|
- if (matchingTypes.Count == 0)
|
|
|
- continue;
|
|
|
-
|
|
|
- var pluginInfos = new List<PluginInfo>();
|
|
|
-
|
|
|
- foreach (var pluginTypeDefinition in matchingTypes)
|
|
|
+ if (matches.Count == 0)
|
|
|
{
|
|
|
- var metadata = BepInPlugin.FromCecilType(pluginTypeDefinition);
|
|
|
-
|
|
|
- if (metadata == null)
|
|
|
- {
|
|
|
- Logger.LogWarning($"Skipping over type [{pluginTypeDefinition.Name}] as no metadata attribute is specified");
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //Perform a filter for currently running process
|
|
|
- var filters = BepInProcess.FromCecilType(pluginTypeDefinition);
|
|
|
-
|
|
|
- bool invalidProcessName = filters.Any(x => x.ProcessName.ToLower().Replace(".exe", "") == currentProcess);
|
|
|
-
|
|
|
- if (invalidProcessName)
|
|
|
- {
|
|
|
- Logger.LogInfo($"Skipping over plugin [{metadata.GUID}] due to process filter");
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- var dependencies = BepInDependency.FromCecilType(pluginTypeDefinition);
|
|
|
-
|
|
|
- pluginInfos.Add(new PluginInfo
|
|
|
- {
|
|
|
- Metadata = metadata,
|
|
|
- Processes = filters,
|
|
|
- Dependencies = dependencies,
|
|
|
- CecilType = pluginTypeDefinition,
|
|
|
- Location = dll
|
|
|
- });
|
|
|
+ ass.Dispose();
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- result[ass] = pluginInfos;
|
|
|
+ result[ass] = matches;
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|