Skip to content

Commit 5a16591

Browse files
committed
Use the new Patcher API so that the mod can be fully disabled
1 parent 5703a98 commit 5a16591

3 files changed

Lines changed: 9 additions & 20 deletions

File tree

src/PatchManager.PreloadPatcher/Directory.Build.props

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/PatchManager.PreloadPatcher/PatchManager.PreloadPatcher.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
<PackageReference Include="BepInEx.BaseLib" Version="5.4.21"/>
66
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" PrivateAssets="All"/>
77
<PackageReference Include="Mono.Cecil" Version="0.11.4"/>
8+
<PackageReference Include="SpaceWarp" Version="1.8.0"/>
89
</ItemGroup>
910
</Project>

src/PatchManager.PreloadPatcher/Patcher.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
using BepInEx;
2-
using BepInEx.Logging;
32
using JetBrains.Annotations;
43
using Mono.Cecil;
54
using Mono.Cecil.Cil;
5+
using SpaceWarp.Preload.API;
66

77
namespace PatchManager.PreloadPatcher;
88

99
/// <summary>
1010
/// Preload patcher for the game's AssetProvider.
1111
/// </summary>
12-
public static class Patcher
12+
[UsedImplicitly]
13+
internal class Patcher : BasePatcher
1314
{
14-
[UsedImplicitly]
15-
public static IEnumerable<string> TargetDLLs { get; } = new[]
15+
public override IEnumerable<string> DLLsToPatch { get; } = new[]
1616
{
1717
"Assembly-CSharp.dll"
1818
};
1919

20-
private static MethodReference MakeGeneric(this MethodReference method, params GenericParameter[] args)
20+
private static MethodReference MakeGeneric(MethodReference method, params GenericParameter[] args)
2121
{
2222
if (args.Length == 0)
2323
{
@@ -43,8 +43,7 @@ private static MethodReference MakeGeneric(this MethodReference method, params G
4343
/// </summary>
4444
/// <param name="assemblyDefinition">Game assembly containing the AssetProvider class.</param>
4545
/// <exception cref="Exception">Thrown if the assembly with the replacement method cannot be found.</exception>
46-
[UsedImplicitly]
47-
public static void Patch(ref AssemblyDefinition assemblyDefinition)
46+
public override void ApplyPatch(ref AssemblyDefinition assemblyDefinition)
4847
{
4948
// Now we need to get the assembly with the replacement method
5049
AssemblyDefinition coreAssembly = null;
@@ -67,14 +66,14 @@ public static void Patch(ref AssemblyDefinition assemblyDefinition)
6766
// Remove every single instruction from the body of the methods
6867
// Emit call to our extracted method
6968
var methodInModule = targetMethod.Module.ImportReference(extractedMethod);
70-
var generic = methodInModule.MakeGeneric(targetMethod.GenericParameters.ToArray());
69+
var generic = MakeGeneric(methodInModule, targetMethod.GenericParameters.ToArray());
7170
targetMethod.Body.Instructions.Clear();
7271
targetMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_1));
7372
targetMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_2));
7473
targetMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_3));
7574
targetMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Call, generic));
7675
targetMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
7776

78-
Logger.CreateLogSource("Patch Manager Preload").LogInfo("Pre-patching complete!");
77+
Logger.LogInfo("Pre-patching complete!");
7978
}
8079
}

0 commit comments

Comments
 (0)