Use Prepare instead DoConditionalPatch

This commit is contained in:
amevarashi 2023-03-24 20:56:21 +05:00
parent 8d49addd63
commit 9e0a461db3
2 changed files with 2 additions and 14 deletions

View file

@ -16,7 +16,6 @@ namespace RJWSexperience
{ {
var har = new Harmony("RJW_Sexperience"); var har = new Harmony("RJW_Sexperience");
har.PatchAll(Assembly.GetExecutingAssembly()); har.PatchAll(Assembly.GetExecutingAssembly());
Pawn_GetGizmos.DoConditionalPatch(har);
InjectIntoRjwInteractionServices(); InjectIntoRjwInteractionServices();
} }

View file

@ -1,27 +1,16 @@
using HarmonyLib; using HarmonyLib;
using RJWSexperience.Logs;
using RJWSexperience.SexHistory; using RJWSexperience.SexHistory;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using Verse; using Verse;
namespace RJWSexperience namespace RJWSexperience
{ {
[HarmonyPatch(typeof(Pawn), nameof(Pawn.GetGizmos))]
public static class Pawn_GetGizmos public static class Pawn_GetGizmos
{ {
private static Configurations Settings => SexperienceMod.Settings; private static Configurations Settings => SexperienceMod.Settings;
public static void DoConditionalPatch(Harmony harmony) public static bool Prepare() => Settings.EnableSexHistory;
{
if (!Settings.EnableSexHistory)
return;
MethodInfo original = typeof(Pawn).GetMethod(nameof(Pawn.GetGizmos));
MethodInfo postfix = typeof(Pawn_GetGizmos).GetMethod(nameof(Pawn_GetGizmos.Postfix));
harmony.Patch(original, postfix: new HarmonyMethod(postfix));
LogManager.GetLogger<DebugLogProvider>(nameof(Pawn_GetGizmos)).Message("Applied conditional patch to Pawn.GetGizmos()");
}
public static void Postfix(ref IEnumerable<Gizmo> __result, Pawn __instance) public static void Postfix(ref IEnumerable<Gizmo> __result, Pawn __instance)
{ {