11using BepInEx ;
2- using BepInEx . Logging ;
32using JetBrains . Annotations ;
43using Mono . Cecil ;
54using Mono . Cecil . Cil ;
5+ using SpaceWarp . Preload . API ;
66
77namespace 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