Reformat project; apply code style

This commit is contained in:
ghorsington committed 2021-12-21 18:55:05 +02:00
1 parent 81141fcfc4
commit 4bb48c502e
30 files changed
+213 -172

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ public static class EnvVars
public static string DOORSTOP_PROCESS_PATH { get; private set; }
/// <summary>
/// Array of paths where Mono searches DLLs from before assembly resolvers are invoked.
/// Array of paths where Mono searches DLLs from before assembly resolvers are invoked.
/// </summary>
public static string[] DOORSTOP_DLL_SEARCH_DIRS { get; private set; }
@@ -23,10 +23,7 @@ public class PreloaderConsoleListener : ILogListener
public LogLevel LogLevelFilter => ConfigConsoleDisplayedLevel.Value;
/// <inheritdoc />
public void LogEvent(object sender, LogEventArgs eventArgs)
{
LogEvents.Add(eventArgs);
}
public void LogEvent(object sender, LogEventArgs eventArgs) => LogEvents.Add(eventArgs);
/// <inheritdoc />
public void Dispose() { }
@@ -23,7 +23,7 @@ public class AssemblyPatcher : IDisposable
private static readonly string CurrentAssemblyName = Assembly.GetExecutingAssembly().GetName().Name;
/// <summary>
/// The context of this assembly patcher instance that is passed to all patcher plugins.
/// The context of this assembly patcher instance that is passed to all patcher plugins.
/// </summary>
public PatcherContext PatcherContext { get; } = new()
{
@@ -81,7 +81,8 @@ public class AssemblyPatcher : IDisposable
if (string.IsNullOrEmpty(metadata.GUID) || !allowedGuidRegex.IsMatch(metadata.GUID))
{
Logger.Log(LogLevel.Warning, $"Skipping type [{type.FullName}] because its GUID [{metadata.GUID}] is of an illegal format");
Logger.Log(LogLevel.Warning,
$"Skipping type [{type.FullName}] because its GUID [{metadata.GUID}] is of an illegal format");
return null;
}
@@ -180,7 +181,8 @@ public class AssemblyPatcher : IDisposable
)
{
Logger
.Log(LogLevel.Warning, $"Skipping method [{method.FullDescription()}] as it is not a valid patcher method");
.Log(LogLevel.Warning,
$"Skipping method [{method.FullDescription()}] as it is not a valid patcher method");
continue;
}
@@ -211,7 +213,8 @@ public class AssemblyPatcher : IDisposable
/// <summary>
/// Adds all .dll assemblies in given directories to be patched and loaded by this patcher instance. Non-managed assemblies
/// Adds all .dll assemblies in given directories to be patched and loaded by this patcher instance. Non-managed
/// assemblies
/// are skipped.
/// </summary>
/// <param name="directories">The directories to search.</param>
@@ -219,7 +222,8 @@ public class AssemblyPatcher : IDisposable
LoadAssemblyDirectories(directories, new[] { "dll" });
/// <summary>
/// Adds all assemblies in given directories to be patched and loaded by this patcher instance. Non-managed assemblies are
/// Adds all assemblies in given directories to be patched and loaded by this patcher instance. Non-managed assemblies
/// are
/// skipped.
/// </summary>
/// <param name="directories">The directory to search.</param>
@@ -386,7 +390,8 @@ public class AssemblyPatcher : IDisposable
}
catch (Exception e)
{
Logger.Log(LogLevel.Error, $"Failed to run [{patchDefinition.FullName}] when patching [{assembly.Name.Name}]. This assembly will not be patched. Error: {e}");
Logger.Log(LogLevel.Error,
$"Failed to run [{patchDefinition.FullName}] when patching [{assembly.Name.Name}]. This assembly will not be patched. Error: {e}");
patchedAssemblies.Remove(targetDll);
invalidAssemblies.Add(targetDll);
return false;
@@ -416,14 +421,14 @@ public class AssemblyPatcher : IDisposable
if (earlyLoadAssemblies.Count != 0)
Logger.Log(LogLevel.Warning, new StringBuilder()
.AppendLine("The following assemblies have been loaded too early and will not be patched by preloader:")
.AppendLine(string.Join(Environment.NewLine,
earlyLoadAssemblies
.Select(kv =>
$"* [{kv.Key}] (first loaded by [{kv.Value}])")
.ToArray()))
.AppendLine("Expect unexpected behavior and issues with plugins and patchers not being loaded.")
.ToString());
.AppendLine("The following assemblies have been loaded too early and will not be patched by preloader:")
.AppendLine(string.Join(Environment.NewLine,
earlyLoadAssemblies
.Select(kv =>
$"* [{kv.Key}] (first loaded by [{kv.Value}])")
.ToArray()))
.AppendLine("Expect unexpected behavior and issues with plugins and patchers not being loaded.")
.ToString());
var dumpedAssemblyPaths = new Dictionary<string, string>();
// Finally, load patched assemblies into memory
@@ -457,7 +462,8 @@ public class AssemblyPatcher : IDisposable
if (ConfigBreakBeforeLoadAssemblies.Value)
{
Logger.Log(LogLevel.Info, $"BepInEx is about load the following assemblies:\n{string.Join("\n", patchedAssemblies.ToArray())}");
Logger.Log(LogLevel.Info,
$"BepInEx is about load the following assemblies:\n{string.Join("\n", patchedAssemblies.ToArray())}");
Logger.Log(LogLevel.Info, $"The assemblies were dumped into {PatcherContext.DumpedAssembliesPath}");
Logger.Log(LogLevel.Info, "Load any assemblies into the debugger, set breakpoints and continue execution.");
Debugger.Break();
+11 -8
View File
@@ -80,35 +80,38 @@ public class PatcherPluginInfoAttribute : Attribute
}
/// <summary>
/// Defines an assembly that a patch method will target.
/// Defines an assembly that a patch method will target.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class TargetAssemblyAttribute : Attribute
{
/// <summary>
/// Marker used to indicate all possible assemblies to be targeted by a patch method.
/// Marker used to indicate all possible assemblies to be targeted by a patch method.
/// </summary>
public const string AllAssemblies = "_all";
/// <param name="targetAssembly">The short filename of the assembly. Use <see cref="AllAssemblies"/> to mark all possible assemblies as targets.</param>
/// <param name="targetAssembly">
/// The short filename of the assembly. Use <see cref="AllAssemblies" /> to mark all possible
/// assemblies as targets.
/// </param>
public TargetAssemblyAttribute(string targetAssembly)
{
TargetAssembly = targetAssembly;
}
/// <summary>
/// The short filename of the assembly to target.
/// The short filename of the assembly to target.
/// </summary>
public string TargetAssembly { get; }
}
/// <summary>
/// Defines a type that a patch method will target.
/// Defines a type that a patch method will target.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class TargetTypeAttribute : Attribute
{
/// <param name="targetAssembly">The short filename of the assembly of which <paramref name="targetType"/> belongs to.</param>
/// <param name="targetAssembly">The short filename of the assembly of which <paramref name="targetType" /> belongs to.</param>
/// <param name="targetType">The full name of the type to target for patching.</param>
public TargetTypeAttribute(string targetAssembly, string targetType)
{
@@ -117,12 +120,12 @@ public class TargetTypeAttribute : Attribute
}
/// <summary>
/// The short filename of the assembly to target.
/// The short filename of the assembly to target.
/// </summary>
public string TargetAssembly { get; }
/// <summary>
/// The full name of the type to target for patching.
/// The full name of the type to target for patching.
/// </summary>
public string TargetType { get; }
}
+21 -20
View File
@@ -8,26 +8,6 @@ namespace BepInEx.Preloader.Core.Patching;
/// </summary>
public abstract class BasePatcher
{
/// <summary>
/// A <see cref="ILogSource"/> instance created for use by this patcher plugin.
/// </summary>
public ManualLogSource Log { get; }
/// <summary>
/// A configuration file binding created with the <see cref="PatcherPluginInfoAttribute.GUID"/> of this plugin as the filename.
/// </summary>
public ConfigFile Config { get; }
/// <summary>
/// Metadata associated with this patcher plugin.
/// </summary>
public PatcherPluginInfoAttribute Info { get; }
/// <summary>
/// The context of the <see cref="AssemblyPatcher"/> this BasePatcher is associated with.
/// </summary>
public PatcherContext Context { get; set; }
protected BasePatcher()
{
Info = PatcherPluginInfoAttribute.FromType(GetType());
@@ -38,6 +18,27 @@ public abstract class BasePatcher
new BepInPlugin(Info.GUID, Info.Name, Info.Version.ToString()));
}
/// <summary>
/// A <see cref="ILogSource" /> instance created for use by this patcher plugin.
/// </summary>
public ManualLogSource Log { get; }
/// <summary>
/// A configuration file binding created with the <see cref="PatcherPluginInfoAttribute.GUID" /> of this plugin as the
/// filename.
/// </summary>
public ConfigFile Config { get; }
/// <summary>
/// Metadata associated with this patcher plugin.
/// </summary>
public PatcherPluginInfoAttribute Info { get; }
/// <summary>
/// The context of the <see cref="AssemblyPatcher" /> this BasePatcher is associated with.
/// </summary>
public PatcherContext Context { get; set; }
/// <summary>
/// Executed before any patches from any plugin are applied.
/// </summary>
@@ -5,7 +5,7 @@ using Mono.Cecil;
namespace BepInEx.Preloader.Core.Patching;
/// <summary>
/// A definition of an individual patch for use by <see cref="AssemblyPatcher"/>.
/// A definition of an individual patch for use by <see cref="AssemblyPatcher" />.
/// </summary>
public class PatchDefinition
{
@@ -31,20 +31,20 @@ public class PatchDefinition
/// <summary>
/// The assembly / assemblies this patch will target, if there any.
/// </summary>
public TargetAssemblyAttribute TargetAssembly { get; } = null;
public TargetAssemblyAttribute TargetAssembly { get; }
/// <summary>
/// The type / types this patch will target, if there are any.
/// </summary>
public TargetTypeAttribute TargetType { get; } = null;
public TargetTypeAttribute TargetType { get; }
/// <summary>
/// The instance of the <see cref="BasePatcher"/> this <see cref="PatchDefinition"/> originates from.
/// The instance of the <see cref="BasePatcher" /> this <see cref="PatchDefinition" /> originates from.
/// </summary>
public BasePatcher Instance { get; }
/// <summary>
/// The method that will perform the patching logic defined by this <see cref="PatchDefinition"/> instance.
/// The method that will perform the patching logic defined by this <see cref="PatchDefinition" /> instance.
/// </summary>
public MethodInfo MethodInfo { get; }
@@ -55,7 +55,7 @@ public class PatchDefinition
}
/// <summary>
/// Context provided to patcher plugins from the associated patcher engine.
/// Context provided to patcher plugins from the associated patcher engine.
/// </summary>
public class PatcherContext
{
@@ -85,7 +85,8 @@ public class PatcherContext
public List<BasePatcher> PatcherPlugins { get; } = new();
/// <summary>
/// A list of individual patches that <see cref="AssemblyPatcher"/> will execute, generated by parsing <see cref="PatcherPlugins"/>.
/// A list of individual patches that <see cref="AssemblyPatcher" /> will execute, generated by parsing
/// <see cref="PatcherPlugins" />.
/// </summary>
public List<PatchDefinition> PatchDefinitions { get; } = new();