Changed from rerouting the job to another for joininbed to simply patching joininbed, code tidying

This commit is contained in:
c0ffee 2021-07-24 13:52:33 -07:00
parent 8177b95bc8
commit 702964a8c2
24 changed files with 143 additions and 774 deletions

View file

@ -1,92 +0,0 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
using AlienRace;
namespace Rimworld_Animations {
[HarmonyPatch(typeof(AlienRace.HarmonyPatches), "DrawAddons")]
public static class HarmonyPatch_AlienRace {
public static void RenderHeadAddonInAnimation(Mesh mesh, Vector3 loc, Quaternion quat, Material mat, bool drawNow, Graphic graphic, AlienPartGenerator.BodyAddon bodyAddon, Vector3 v, float num, Vector3 headOffset, Pawn pawn, PawnRenderFlags renderFlags)
{
CompBodyAnimator pawnAnimator = pawn.TryGetComp<CompBodyAnimator>();
if (!renderFlags.FlagSet(PawnRenderFlags.Portrait) && pawnAnimator.isAnimating && (bodyAddon.drawnInBed || bodyAddon.alignWithHead))
{
Quaternion headQuatInAnimation = Quaternion.AngleAxis(pawnAnimator.headAngle, Vector3.up);
Rot4 headRotInAnimation = pawnAnimator.headFacing;
Vector3 headPositionInAnimation = pawnAnimator.getPawnHeadPosition() - pawn.Drawer.renderer.BaseHeadOffsetAt(pawnAnimator.headFacing).RotatedBy(angle: Mathf.Acos(f: Quaternion.Dot(a: Quaternion.identity, b: headQuatInAnimation)) * 2f * 57.29578f);
Log.Message(bodyAddon.path + " " + bodyAddon.inFrontOfBody.ToStringSafe());
headPositionInAnimation.y += bodyAddon.inFrontOfBody ? 1f : -1f;
GenDraw.DrawMeshNowOrLater(mesh: graphic.MeshAt(rot: headRotInAnimation), loc: headPositionInAnimation + (bodyAddon.alignWithHead ? headOffset : Vector3.zero) + v.RotatedBy(angle: Mathf.Acos(f: Quaternion.Dot(a: Quaternion.identity, b: headQuatInAnimation)) * 2f * 57.29578f),
quat: Quaternion.AngleAxis(angle: num, axis: Vector3.up) * headQuatInAnimation, mat: graphic.MatAt(rot: pawnAnimator.headFacing), drawNow: drawNow);
}
else
{
GenDraw.DrawMeshNowOrLater(mesh, loc, quat, mat, drawNow);
}
}
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> ins = instructions.ToList();
for (int i = 0; i < ins.Count; i++)
{
Type[] type = new Type[] { typeof(Mesh), typeof(Vector3), typeof(Quaternion), typeof(Material), typeof(bool) };
if (ins[i].OperandIs(AccessTools.Method(typeof(GenDraw), "DrawMeshNowOrLater", type)))
{
yield return new CodeInstruction(OpCodes.Ldloc, (object)7); //graphic
yield return new CodeInstruction(OpCodes.Ldloc, (object)4); //bodyAddon
yield return new CodeInstruction(OpCodes.Ldloc, (object)5); //offsetVector/AddonOffset (v)
yield return new CodeInstruction(OpCodes.Ldloc, (object)6); //num
yield return new CodeInstruction(OpCodes.Ldarg, (object)2); //headOffset
yield return new CodeInstruction(OpCodes.Ldarg, (object)3); //pawn
yield return new CodeInstruction(OpCodes.Ldarg, (object)0); //renderflags
yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(HarmonyPatch_AlienRace), "RenderHeadAddonInAnimation"));
}
else
{
yield return ins[i];
}
}
}
}
[HarmonyPatch(typeof(PawnGraphicSet), "ResolveApparelGraphics")]
public static class HarmonyPatch_ResolveApparelGraphics
{
public static bool Prefix(ref Pawn ___pawn)
{
if (___pawn.TryGetComp<CompBodyAnimator>() != null && ___pawn.TryGetComp<CompBodyAnimator>().isAnimating)
{
return false;
}
return true;
}
}
}

View file

@ -1,87 +0,0 @@
/*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using rjw;
using Verse;
using RimWorld;
using System.Reflection.Emit;
using System.Reflection;
using UnityEngine;
namespace Rimworld_Animations {
[StaticConstructorOnStartup]
public static class HarmonyPatch_CSL {
static HarmonyPatch_CSL() {
try {
((Action)(() => {
if (LoadedModManager.RunningModsListForReading.Any(x => x.Name == "Children, school and learning")) {
(new Harmony("rjw")).Patch(AccessTools.Method(AccessTools.TypeByName("Children.PawnRenderer_RenderPawnInternal_Patch"), "RenderPawnInternalScaled"),
prefix: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_CSL), "Prefix_CSL")),
transpiler: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_CSL), "Transpiler_CSL")));
}
}))();
}
catch (TypeLoadException ex) {
}
}
public static void Prefix_CSL(PawnRenderer __instance, Pawn pawn, ref Vector3 rootLoc, ref float angle, bool renderBody, ref Rot4 bodyFacing, ref Rot4 headFacing, RotDrawMode bodyDrawType, bool portrait, bool headStump, bool invisible) {
PawnGraphicSet graphics = __instance.graphics;
CompBodyAnimator bodyAnim = pawn.TryGetComp<CompBodyAnimator>();
if (!graphics.AllResolved) {
graphics.ResolveAllGraphics();
}
if (bodyAnim != null && bodyAnim.isAnimating && !portrait) {
bodyAnim.tickGraphics(graphics);
pawn.TryGetComp<CompBodyAnimator>().animatePawn(ref rootLoc, ref angle, ref bodyFacing, ref headFacing);
}
}
public static IEnumerable<CodeInstruction> Transpiler_CSL(IEnumerable<CodeInstruction> instructions) {
MethodInfo drawMeshNowOrLater = AccessTools.Method(typeof(GenDraw), "DrawMeshNowOrLater");
FieldInfo headGraphic = AccessTools.Field(typeof(PawnGraphicSet), "headGraphic");
List<CodeInstruction> codes = instructions.ToList();
bool forHead = true;
for (int i = 0; i < codes.Count(); i++) {
//Instead of calling drawmeshnoworlater, add pawn to the stack and call my special static method
if (codes[i].OperandIs(drawMeshNowOrLater) && forHead) {
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.DeclaredField(typeof(PawnRenderer), "pawn"));
yield return new CodeInstruction(OpCodes.Ldarg_2);
yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(AnimationUtility), nameof(AnimationUtility.RenderPawnHeadMeshInAnimation), new Type[] { typeof(Mesh), typeof(Vector3), typeof(Quaternion), typeof(Material), typeof(bool), typeof(Pawn), typeof(float) }));
}
//checking for if(graphics.headGraphic != null)
else if (codes[i].opcode == OpCodes.Ldfld && codes[i].OperandIs(headGraphic)) {
forHead = true;
yield return codes[i];
}
//checking for if(renderbody)
else if (codes[i].opcode == OpCodes.Ldarg_3) {
forHead = false;
yield return codes[i];
}
else {
yield return codes[i];
}
}
}
}
}*/

View file

@ -1,29 +0,0 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace Rimworld_Animations {
class HarmonyPatch_DontShaveYourHead {
[StaticConstructorOnStartup]
public static class Patch_DontShaveYourHead {
static Patch_DontShaveYourHead() {
try {
((Action)(() =>
{
if (LoadedModManager.RunningModsListForReading.Any(x => x.Name == "Don't Shave Your Head 1.0")) {
(new Harmony("rjw")).Patch(AccessTools.Method(AccessTools.TypeByName("DontShaveYourHead.Harmony_PawnRenderer"), "DrawHairReroute"), //typeof(ShowHair.Patch_PawnRenderer_RenderPawnInternal), nameof(ShowHair.Patch_PawnRenderer_RenderPawnInternal.Postfix)),
transpiler: new HarmonyMethod(AccessTools.Method(typeof(Patch_ShowHairWithHats), "Transpiler")));
}
}))();
}
catch (TypeLoadException ex) { }
}
}
}
}

View file

@ -1,104 +0,0 @@
using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
namespace Rimworld_Animations {
[StaticConstructorOnStartup]
public static class Patch_FacialAnimation {
static Patch_FacialAnimation() {
try {
((Action)(() => {
if (LoadedModManager.RunningModsListForReading.Any(x => x.Name == "[NL] Facial Animation - WIP")) {
(new Harmony("rjw")).Patch(AccessTools.Method(AccessTools.TypeByName("FacialAnimation.DrawFaceGraphicsComp"), "DrawGraphics"),
prefix: new HarmonyMethod(AccessTools.Method(typeof(Patch_FacialAnimation), "Prefix")));
}
}))();
}
catch (TypeLoadException ex) {
}
}
public static bool Prefix(ref Pawn ___pawn, ref Rot4 headFacing, ref Vector3 headOrigin, ref Quaternion quaternion, ref bool portrait) {
CompBodyAnimator bodyAnim = ___pawn.TryGetComp<CompBodyAnimator>();
if (bodyAnim != null && bodyAnim.isAnimating && !portrait) {
headFacing = bodyAnim.headFacing;
headOrigin = new Vector3(bodyAnim.getPawnHeadPosition().x, headOrigin.y, bodyAnim.getPawnHeadPosition().z);
quaternion = Quaternion.AngleAxis(bodyAnim.headAngle, Vector3.up);
}
return true;
}
/*
public static List<string> rjwLovinDefNames = new List<string>{
"Lovin",
"Quickie",
"GettingQuickie",
"JoinInBed",
"JoinInBedAnimation",
"GettinLovedAnimation",
"GettinLoved",
"GettinLicked",
"GettinSucked",
"GettinRaped",
"ViolateCorpse",
"RJW_Masturbate",
"GettinBred",
"Breed",
"RJW_Mate",
"Bestiality",
"BestialityForFemale",
"StruggleInBondageGear",
"WhoreIsServingVisitors",
"UseFM"
};
public static List<string> rjwRapeDefNames = new List<string> {
"RapeComfortPawn",
"RandomRape",
"RapeEnemy"
};
public static bool Prefix_IsSameA(JobDef job, string ___jobDef, ref bool __result) {
if(___jobDef != null && ___jobDef == "Lovin" && job?.defName != null && rjwLovinDefNames.Contains(job?.defName)) {
__result = true;
return false;
}
else if (___jobDef != null && ___jobDef == "Wait_Combat" && job?.defName != null && rjwRapeDefNames.Contains(job?.defName)) {
__result = true;
return false;
}
return true;
}
public static bool Prefix_IsSameB(string jobName, string ___jobDef, ref bool __result) {
if (___jobDef != null && ___jobDef == "Lovin" && jobName != null && rjwLovinDefNames.Contains(jobName)) {
__result = true;
return false;
}
if (___jobDef != null && ___jobDef == "Wait_Combat" && jobName != null && rjwRapeDefNames.Contains(jobName)) {
__result = true;
return false;
}
return true;
}
*/
}
}

View file

@ -1,28 +0,0 @@
using HarmonyLib;
using Verse;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rimworld_Animations
{
[HarmonyPatch(typeof(PawnUtility), "GetPosture")]
public static class HarmonyPatch_SetPawnLaying
{
public static bool Prefix(Pawn p, ref PawnPosture __result)
{
if(p.TryGetComp<CompBodyAnimator>().isAnimating)
{
__result = PawnPosture.LayingOnGroundNormal;
return false;
}
return true;
}
}
}

View file

@ -1,51 +0,0 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
namespace Rimworld_Animations {
[StaticConstructorOnStartup]
public static class Patch_ShowHairWithHats {
static Patch_ShowHairWithHats() {
try {
((Action)(() =>
{
if (LoadedModManager.RunningModsListForReading.Any(x => x.Name == "[KV] Show Hair With Hats or Hide All Hats - 1.1")) {
(new Harmony("rjw")).Patch(AccessTools.Method(AccessTools.TypeByName("ShowHair.Patch_PawnRenderer_RenderPawnInternal"), "Postfix"), //typeof(ShowHair.Patch_PawnRenderer_RenderPawnInternal), nameof(ShowHair.Patch_PawnRenderer_RenderPawnInternal.Postfix)),
transpiler: new HarmonyMethod(AccessTools.Method(typeof(Patch_ShowHairWithHats), "Transpiler")));
}
}))();
}
catch (TypeLoadException ex) { }
}
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) {
MethodInfo drawMeshNowOrLater = AccessTools.Method(typeof(GenDraw), "DrawMeshNowOrLater");
List<CodeInstruction> codes = instructions.ToList();
for (int i = 0; i < codes.Count(); i++) {
//Instead of calling drawmeshnoworlater, add pawn to the stack and call my special static method
if (codes[i].OperandIs(drawMeshNowOrLater)) {
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.DeclaredField(typeof(PawnRenderer), "pawn"));
yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(AnimationUtility), nameof(AnimationUtility.RenderPawnHeadMeshInAnimation), new Type[] { typeof(Mesh), typeof(Vector3), typeof(Quaternion), typeof(Material), typeof(bool), typeof(Pawn) }));
}
else {
yield return codes[i];
}
}
}
}
}

View file

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using RimWorld;
using Verse;
using rjw;
using System.Reflection.Emit;
using Verse.AI;
namespace Rimworld_Animations
{
[HarmonyPatch(typeof(xxx), "in_same_bed")]
public static class HarmonyPatch_JobDriver_InSameBedPatch
{
public static bool Prefix(Pawn partner, ref bool __result)
{
if(partner != null && partner.CurJobDef == xxx.casual_sex)
{
__result = true;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(JobDriver_JoinInBed), "MakeNewToils")]
public static class HarmonyPatch_JobDriver_JoinInBed
{
public static void Postfix(JobDriver_JoinInBed __instance, ref IEnumerable<Toil> __result)
{
var toils = __result.ToList();
Toil goToPawnInBed = Toils_Goto.GotoThing(__instance.iTarget, PathEndMode.OnCell);
goToPawnInBed.FailOn(() => !RestUtility.InBed(__instance.Partner) && __instance.Partner.CurJobDef != xxx.gettin_loved && !xxx.in_same_bed(__instance.Partner, __instance.pawn));
toils[1] = goToPawnInBed;
Toil startPartnerSex = new Toil();
startPartnerSex.initAction = delegate {
if (!(__instance.Partner.jobs.curDriver is JobDriver_SexBaseReciever)) // allows threesomes
{
Job gettinLovedJob = JobMaker.MakeJob(xxx.gettin_loved, __instance.pawn, __instance.Bed); // new gettin loved toil that wakes up the pawn goes here
__instance.Partner.jobs.jobQueue.EnqueueFirst(gettinLovedJob);
__instance.Partner.jobs.EndCurrentJob(JobCondition.InterruptForced);
}
};
toils[2] = startPartnerSex;
toils[3].AddPreTickAction(() =>
{
if (!__instance.Partner.TryGetComp<CompBodyAnimator>().isAnimating)
{
__instance.pawn.TryGetComp<CompBodyAnimator>().isAnimating = false;
}
});
__result = toils.AsEnumerable();
}
}
}

View file

@ -25,30 +25,10 @@ namespace Rimworld_Animations {
Building_Bed bed = __instance.Bed;
/*
if (__instance is JobDriver_BestialityForFemale)
bed = (__instance as JobDriver_BestialityForFemale).Bed;
else if (__instance is JobDriver_WhoreIsServingVisitors) {
bed = (__instance as JobDriver_WhoreIsServingVisitors).Bed;
}
else if (__instance is JobDriver_SexCasualForAnimation) {
bed = (__instance as JobDriver_SexCasualForAnimation).Bed;
}
else if (__instance is JobDriver_Masturbate)
bed = (__instance as JobDriver_Masturbate).Bed;
else if (__instance is JobDriver_Rape)
bed = (__instance?.Partner?.jobs?.curDriver as JobDriver_Sex)?.Bed;
*/
if ((__instance.Target as Pawn)?.jobs?.curDriver is JobDriver_SexBaseReciever) {
Pawn Target = __instance.Target as Pawn;
if (!(Target.jobs.curDriver as JobDriver_SexBaseReciever).parteners.Contains(pawn)) {
(Target.jobs.curDriver as JobDriver_SexBaseReciever).parteners.Add(pawn);
}
bool quickie = (__instance is JobDriver_SexQuick) && AnimationSettings.fastAnimForQuickie;
int preAnimDuration = __instance.duration;

View file

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using RimWorld;
using Verse;
using rjw;
using System.Reflection.Emit;
namespace Rimworld_Animations
{
[HarmonyPatch(typeof(JobDriver_SexBaseRecieverLoved), "MakeSexToil")]
public static class HarmonyPatch_JobDriver_SexBaseReceiverLoved
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codeInstructions)
{
var ins = codeInstructions.ToList();
for(int i = 0; i < ins.Count; i++)
{
if(i + 13 < ins.Count && ins[i + 13].opcode == OpCodes.Call && ins[i + 13].OperandIs(AccessTools.DeclaredMethod(typeof(Toils_LayDown), "LayDown"))) {
ins.RemoveRange(i, 14);
}
else
{
yield return ins[i];
}
}
}
}
}

View file

@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using RimWorld;
using Verse;
using rjw;
using Verse.AI;
namespace Rimworld_Animations {
[HarmonyPatch(typeof(JobGiver_DoLovin), "TryGiveJob")]
public static class HarmonyPatch_DoLovinAnimationPatch {
public static void Postfix(ref Pawn pawn, ref Job __result) {
if(__result != null) {
Pawn partnerInMyBed = LovePartnerRelationUtility.GetPartnerInMyBed(pawn);
RestUtility.WakeUp(pawn);
__result = JobMaker.MakeJob(DefDatabase<JobDef>.GetNamed("JoinInBedAnimation", true), partnerInMyBed, partnerInMyBed.CurrentBed());
}
}
}
}

View file

@ -1,22 +0,0 @@
/*
* Todo: Ask to make SemenSplatch and DrawSemen public
*
*
* using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using rjw;
using HarmonyLib;
namespace Rimworld_Animations {
[HarmonyPatch("DrawSemen")]
public static class HarmonyPatch_DrawSemen {
public static void Prefix(ref Dictionary<string, SemenSplatch>) {
}
}
}*/

View file

@ -1,68 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using rjw;
using Verse;
using Verse.AI;
using RimWorld;
using HarmonyLib;
namespace Rimworld_Animations {
[HarmonyPatch(typeof(JobGiver_JoinInBed), "TryGiveJob")]
public static class HarmonyPatch_JoinInBedGiveJob {
public static bool Prefix(ref Job __result, ref Pawn pawn) {
__result = null;
if (!RJWHookupSettings.HookupsEnabled)
return false;
if (pawn.Drafted)
return false;
if (!SexUtility.ReadyForHookup(pawn))
return false;
// We increase the time right away to prevent the fairly expensive check from happening too frequently
SexUtility.IncreaseTicksToNextHookup(pawn);
// If the pawn is a whore, or recently had sex, skip the job unless they're really horny
if (!xxx.is_frustrated(pawn) && (xxx.is_whore(pawn) || !SexUtility.ReadyForLovin(pawn)))
return false;
// This check attempts to keep groups leaving the map, like guests or traders, from turning around to hook up
if (pawn.mindState?.duty?.def == DutyDefOf.TravelOrLeave) {
// TODO: Some guest pawns keep the TravelOrLeave duty the whole time, I think the ones assigned to guard the pack animals.
// That's probably ok, though it wasn't the intention.
if (RJWSettings.DebugLogJoinInBed) ModLog.Message($"JoinInBed.TryGiveJob:({xxx.get_pawnname(pawn)}): has TravelOrLeave, no time for lovin [ANIM JOBGIVER]!");
return false;
}
if ((pawn.CurJob == null || pawn.CurJob.def == JobDefOf.LayDown) && CasualSex_Helper.CanHaveSex(pawn)) {
//--Log.Message(" finding partner");
Pawn partner = CasualSex_Helper.find_partner(pawn, pawn.Map, bedsex: true);
//--Log.Message(" checking partner");
if (partner == null)
return false;
// Can never be null, since find checks for bed.
Building_Bed bed = partner.CurrentBed();
// Interrupt current job.
if (pawn.CurJob != null && pawn.jobs.curDriver != null)
pawn.jobs.curDriver.EndJobWith(JobCondition.InterruptForced);
__result = JobMaker.MakeJob(DefDatabase<JobDef>.GetNamed("JoinInBedAnimation", true), partner, bed);
return false;
}
return false;
}
}
}

View file

@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RimWorld;
using Verse.AI;
using rjw;
using HarmonyLib;
using Verse;
namespace Rimworld_Animations {
[HarmonyPatch(typeof(Pawn_JobTracker), "TryTakeOrderedJob")]
class HarmonyPatch_PlayAnimJoinInBedRMB {
public static void Prefix(ref Job job) {
if(job.def == xxx.casual_sex) {
if (AnimationSettings.debugMode || RJWSettings.DevMode)
Log.Message("Replacing vanilla RJW JoinInBed JobDriver for animation JobDriver");
job = new Job(DefDatabase<JobDef>.GetNamed("JoinInBedAnimation", true), job.targetA, job.targetB, job.targetC);
}
}
}
}