rjw-quirks/RJW-Quirks/HarmonyPatches/Patch_SexUtility.cs

147 lines
5.2 KiB
C#

using HarmonyLib;
using RimWorld;
using rjw;
using rjwquirks.Modules.Quirks;
using rjwquirks.Modules.Shared.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace rjwquirks.HarmonyPatches
{
[HarmonyPatch(typeof(SexUtility))]
public class Patch_SexUtility
{
// Increases cum filth generated by pawn
[HarmonyPostfix]
[HarmonyPatch(nameof(SexUtility.CumOutputModifier))]
public static void FilthAdder(Pawn pawn, ref float __result)
{
if(pawn.GetQuirks() != null)
pawn.GetQuirks().ApplyValueModifiers("cumFilthAmount", ref __result);
}
// Change how much the pawn wants to clean post sex
[HarmonyTranspiler]
[HarmonyPatch(nameof(SexUtility.ConsiderCleaning))]
static IEnumerable<CodeInstruction> ConsiderCleanup(IEnumerable<CodeInstruction> instructions)
{
FieldInfo PawnNeeds = AccessTools.Field(typeof(Pawn), nameof(Pawn.needs));
MethodInfo Cleanup = AccessTools.Method(typeof(Patch_SexUtility), nameof(CleanupChanceAdjuster));
bool found = false;
foreach (CodeInstruction i in instructions)
{
if (found)
{
yield return i;
yield return new CodeInstruction(OpCodes.Ldloc_0);
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Call, Cleanup);
found = false;
continue;
}
if (i.opcode == OpCodes.Ldfld && i.operand as FieldInfo == PawnNeeds)
found = true;
yield return i;
}
}
public static void CleanupChanceAdjuster(float chance, Pawn pawn)
{
pawn.GetQuirks().ApplyValueModifiers("cleanAfterFapChance", ref chance);
}
// Change satisfaction from sex
[HarmonyPostfix]
[HarmonyPatch(nameof(SexUtility.GetExtraSatisfaction))]
public static void Satisfaction(SexProps props, ref float __result)
{
var quirkCount = props.pawn.GetQuirks().GetSatisfiedBySex(props).Count();
if (quirkCount > 0)
{
__result += props.pawn.GetQuirks().GetSatisfiedBySex(props).Count() * 0.20f;
RjwEventManager.NotifyEvent(new RjwEvent(RjwEventDefOf.Orgasm, props.Named(RjwEventArgNames.SexProps), __result.Named(RjwEventArgNames.Satisfaction)));
}
}
// Change ticks to next lovin
[HarmonyTranspiler]
[HarmonyPatch(nameof(SexUtility.GenerateMinTicksToNextLovin))]
public static IEnumerable<CodeInstruction> ChangeTicksToNextLovin(IEnumerable<CodeInstruction> instructions)
{
MethodInfo SexDrive = AccessTools.Method(typeof(xxx), nameof(xxx.get_sex_drive));
MethodInfo AdjustTicks = AccessTools.Method(typeof(Patch_SexUtility), nameof(AdjustTicksToNextLovin));
bool found = false;
foreach (var i in instructions)
{
if (found)
{
yield return i;
yield return new CodeInstruction(OpCodes.Ldloc_0);
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Call, AdjustTicks);
found = false;
continue;
}
if (i.opcode == OpCodes.Call && i.operand as MethodInfo == SexDrive)
found = true;
yield return i;
}
}
public static void AdjustTicksToNextLovin(float ticks, Pawn pawn)
{
if (pawn.GetQuirks() != null)
{
pawn.GetQuirks().ApplyValueModifiers("ticksToNextLovin", ref ticks);
}
}
// Rest adjustments
[HarmonyTranspiler]
[HarmonyPatch(nameof(SexUtility.reduce_rest))]
public static IEnumerable<CodeInstruction> AdjustRest(IEnumerable<CodeInstruction> instructions)
{
MethodInfo Adjustment = AccessTools.Method(typeof(Patch_SexUtility), nameof(AdjustRestFromQuirk));
bool found = false;
bool completed = false;
foreach (CodeInstruction i in instructions)
{
if (found && !completed)
{
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldarg_1);
yield return new CodeInstruction(OpCodes.Call, Adjustment);
completed = true;
found = false;
}
if (i.opcode == OpCodes.Dup)
found = true;
yield return i;
}
}
public static void AdjustRestFromQuirk(Pawn pawn, float x)
{
if(pawn.GetQuirks() != null)
pawn.GetQuirks().ApplyValueModifiers("reduceRest", ref x);
}
}
}