Implement Patcher and plugin providers

This commit is contained in:
aldelaro5 committed 2024-08-19 19:57:52 -04:00
1 parent 53625800b8
commit 952c74f6fe
29 files changed
+864 -216

No files matched your search

@@ -0,0 +1,55 @@
using System.Collections.Generic;
using System.Reflection;
using BepInEx.Configuration;
using BepInEx.Logging;
namespace BepInEx.Preloader.Core.Patching;
/// <summary>
/// A patcher provider that can discover and load assemblies containing patcher plugins
/// </summary>
public abstract class BasePatcherProvider
{
protected BasePatcherProvider()
{
Info = PatcherPluginInfoAttribute.FromType(GetType());
Log = Logger.CreateLogSource(Info.Name);
Config = new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, Info.GUID + ".cfg"), false,
new BepInPlugin(Info.GUID, Info.Name, Info.Version.ToString()));
}
/// <summary>
/// A <see cref="ILogSource" /> instance created for use by this patcher plugin provider.
/// </summary>
public ManualLogSource Log { get; }
/// <summary>
/// A configuration file binding created with the <see cref="PatcherPluginInfoAttribute.GUID" /> of this provider as the
/// filename.
/// </summary>
public ConfigFile Config { get; }
/// <summary>
/// Metadata associated with this patcher plugin provider.
/// </summary>
public PatcherPluginInfoAttribute Info { get; }
/// <summary>
/// Obtains a list of assemblies containing patchers to load
/// </summary>
/// <returns>A list of loaders, one per assembly</returns>
public abstract IList<IPluginLoader> GetPatchers();
/// <summary>
/// A custom assembly resolver that can be used by this provider to resolve assemblies
/// that have failed to resolve
/// </summary>
/// <param name="name">The assembly's name</param>
/// <returns>The resolved assembly or null if the assembly couldn't be resolved</returns>
public virtual Assembly ResolveAssembly(string name)
{
return null;
}
}