using System.Collections.Generic; using System.Reflection; using Mono.Cecil; namespace BepInEx.Preloader.Core.Patching { /// /// A definition of an individual patch for use by . /// public class PatchDefinition { public PatchDefinition(TargetAssemblyAttribute targetAssembly, BasePatcher instance, MethodInfo methodInfo) { TargetAssembly = targetAssembly; Instance = instance; MethodInfo = methodInfo; FullName = $"{MethodInfo.DeclaringType.FullName}/{MethodInfo.Name} -> {TargetAssembly.TargetAssembly}"; } public PatchDefinition(TargetTypeAttribute targetType, BasePatcher instance, MethodInfo methodInfo) { TargetType = targetType; Instance = instance; MethodInfo = methodInfo; FullName = $"{MethodInfo.DeclaringType.FullName}/{MethodInfo.Name} -> {TargetType.TargetAssembly}/{TargetType.TargetType}"; } /// /// The assembly / assemblies this patch will target, if there any. /// public TargetAssemblyAttribute TargetAssembly { get; } = null; /// /// The type / types this patch will target, if there are any. /// public TargetTypeAttribute TargetType { get; } = null; /// /// The instance of the this originates from. /// public BasePatcher Instance { get; } /// /// The method that will perform the patching logic defined by this instance. /// public MethodInfo MethodInfo { get; } /// /// A friendly name for this patch definition, for use in logging and error tracking. /// public string FullName { get; } } /// /// Context provided to patcher plugins from the associated patcher engine. /// public class PatcherContext { /// /// Contains a list of assemblies that will be patched and loaded into the runtime. /// /// The dictionary has the name of the file, without any directories. These are used by the dumping /// functionality, and as such, these are also required to be unique. They do not have to be exactly the same as /// the real filename, however they have to be mapped deterministically. /// /// Order is not respected, as it will be sorted by dependencies. /// public Dictionary AvailableAssemblies { get; } = new(); /// /// Contains a dictionary of assemblies that have been loaded as part of executing this assembly patcher. /// /// The key is the same key as used in , while the value is the actual assembly /// itself. /// /// public Dictionary LoadedAssemblies { get; } = new(); /// /// A list of plugins that will be initialized and executed, in the order of the list. /// public List PatcherPlugins { get; } = new(); /// /// A list of individual patches that will execute, generated by parsing . /// public List PatchDefinitions { get; } = new(); /// /// The directory location as to where patched assemblies will be saved to and loaded from disk, for debugging /// purposes. Defaults to BepInEx/DumpedAssemblies/ /// public string DumpedAssembliesPath { get; internal set; } } }