RJW-Sexperience/Source/RJWSexperience/Patches/GetGizmos.cs

53 lines
1.4 KiB
C#
Raw Normal View History

2022-05-10 06:47:51 +00:00
using HarmonyLib;
2022-06-07 03:46:19 +00:00
using RJWSexperience.Logs;
2022-06-13 05:51:09 +00:00
using RJWSexperience.SexHistory;
2022-05-10 06:47:51 +00:00
using System.Collections.Generic;
2022-06-07 03:46:19 +00:00
using System.Reflection;
2022-05-10 06:47:51 +00:00
using Verse;
namespace RJWSexperience
{
public static class Pawn_GetGizmos
{
2022-06-11 12:32:15 +00:00
private static Settings.SettingsTabHistory Settings => SexperienceMod.Settings.History;
2022-06-07 03:46:19 +00:00
public static void DoConditionalPatch(Harmony harmony)
{
2022-06-11 12:32:15 +00:00
if (!Settings.EnableSexHistory)
2022-06-07 03:46:19 +00:00
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()");
}
2022-05-10 06:47:51 +00:00
public static void Postfix(ref IEnumerable<Gizmo> __result, Pawn __instance)
{
2022-06-11 12:32:15 +00:00
if (Settings.HideGizmoWhenDrafted && __instance.Drafted)
return;
2022-05-10 06:47:51 +00:00
if (Find.Selector.NumSelected > 1)
return;
2022-06-11 12:32:15 +00:00
if (Settings.HideGizmoWithRJW && !rjw.RJWSettings.show_RJW_designation_box)
return;
2022-06-04 08:40:40 +00:00
SexHistoryComp history = __instance.TryGetComp<SexHistoryComp>();
if (history == null)
return;
2022-06-11 12:32:15 +00:00
__result = AddHistoryGizmo(history.Gizmo, __result);
2022-05-10 06:47:51 +00:00
}
2022-06-11 12:32:15 +00:00
private static IEnumerable<Gizmo> AddHistoryGizmo(Gizmo historyGizmo, IEnumerable<Gizmo> gizmos)
2022-05-10 06:47:51 +00:00
{
foreach (Gizmo gizmo in gizmos)
yield return gizmo;
2022-06-11 12:32:15 +00:00
yield return historyGizmo;
2022-05-10 06:47:51 +00:00
}
}
}