null ref checks for jobs

This commit is contained in:
c0ffee 2024-05-03 06:54:32 -07:00
parent 0e9419b039
commit eead6ae7ca
4 changed files with 27 additions and 26 deletions

6
.gitignore vendored
View file

@ -348,3 +348,9 @@ healthchecksdb
/Source/Patches/OtherModPatches/HarmonyPatch_AlienRace.cs
/Source/Patches/ThingAnimationPatches/HarmonyPatch_ThingDrawAt.cs
/Defs/AnimationDefs/Animations_SexToys.xml
/1.5/Defs/AnimationDefs/BasicBestiality/HumanRotatedOffset.xml
/1.5/Defs/AnimationDefs/BasicBestiality/BasicBestiality4v1.xml
/1.5/Defs/AnimationDefs/BasicBestiality/BasicBestiality3v1.xml
/1.5/Defs/AnimationDefs/BasicBestiality/BasicBestiality2v1.xml
/1.5/Defs/AnimationDefs/BasicBestiality/BasicBestiality1v1.xml
/1.5/Defs/AnimationDefs/BasicBestiality/!BasicBestiality.xml

View file

@ -11,50 +11,38 @@ namespace Rimworld_Animations {
[HarmonyPatch(typeof(JobDriver_SexBaseInitiator), "Start")]
static class HarmonyPatch_JobDriver_SexBaseInitiator_Start {
public static void Postfix(ref JobDriver_SexBaseInitiator __instance) {
/*
These particular jobs need special code
don't play anim for now
*/
if(__instance is JobDriver_Masturbate || __instance is JobDriver_ViolateCorpse) {
return;
}
if(!RJWAnimationSettings.PlayAnimForNonsexualActs && NonSexualAct(__instance))
{
return;
}
Pawn pawn = __instance.pawn;
Pawn partner = __instance.Target as Pawn;
Building_Bed bed = __instance.Bed;
if (partner?.jobs?.curDriver is JobDriver_SexBaseReciever partnerSexBaseReceiver) {
Pawn Target = __instance.Target as Pawn;
int preAnimDuration = __instance.duration;
List<Pawn> participants = partnerSexBaseReceiver.parteners.Append(partner).ToList();
GroupAnimationDef groupAnimation = AnimationUtility.FindGroupAnimation(participants, out int reorder);
if (groupAnimation != null)
{
Thing anchor;
if (bed != null) anchor = bed;
else anchor = partner;
Thing anchor = (Thing)__instance.Bed ?? partner;
AnimationUtility.StartGroupAnimation(participants, groupAnimation, reorder, anchor);
int animTicks = AnimationUtility.GetAnimationLength(pawn);
foreach(Pawn participant in participants)
{
(participant.jobs.curDriver as JobDriver_Sex).ticks_left = animTicks;
(participant.jobs.curDriver as JobDriver_Sex).sex_ticks = animTicks;
(participant.jobs.curDriver as JobDriver_Sex).orgasmStartTick = animTicks;
(participant.jobs.curDriver as JobDriver_Sex).duration = animTicks;
//null ref check for pawns that might have lost their jobs or become null for some reason
if (participant?.jobs?.curDriver is JobDriver_Sex participantJobDriver)
{
participantJobDriver.ticks_left = animTicks;
participantJobDriver.sex_ticks = animTicks;
participantJobDriver.orgasmStartTick = animTicks;
participantJobDriver.duration = animTicks;
}
}
}
}
@ -92,7 +80,8 @@ namespace Rimworld_Animations {
}
//stop partner's other partners (threesome pawns) animating
if (__instance.Partner.jobs.curDriver is JobDriver_SexBaseReciever partnerReceiverJob)
//added null ref checks for instances when pawns get nulled or lose their jobs
if (__instance.Partner?.jobs?.curDriver is JobDriver_SexBaseReciever partnerReceiverJob)
{
foreach(Pawn pawn in partnerReceiverJob.parteners)
{

View file

@ -143,6 +143,12 @@
<Content Include="1.5\Assemblies\0MultiplayerAPI.dll" />
<Content Include="1.5\Assemblies\Rimworld-Animations.dll" />
<Content Include="1.5\Assemblies\RJW.dll" />
<Content Include="1.5\Defs\AnimationDefs\BasicBestiality\!BasicBestiality.xml" />
<Content Include="1.5\Defs\AnimationDefs\BasicBestiality\BasicBestiality1v1.xml" />
<Content Include="1.5\Defs\AnimationDefs\BasicBestiality\BasicBestiality2v1.xml" />
<Content Include="1.5\Defs\AnimationDefs\BasicBestiality\BasicBestiality3v1.xml" />
<Content Include="1.5\Defs\AnimationDefs\BasicBestiality\BasicBestiality4v1.xml" />
<Content Include="1.5\Defs\AnimationDefs\BasicBestiality\HumanRotatedOffset.xml" />
<Content Include="1.5\Defs\AnimationDefs\Cowgirl\AnimationPropDef_Cowgirl_Xray.xml" />
<Content Include="1.5\Defs\AnimationDefs\Cowgirl\Cowgirl_Stage1.xml" />
<Content Include="1.5\Defs\AnimationDefs\Cowgirl\Cowgirl_Stage2_1.xml" />