mirror of
https://gitgud.io/AbstractConcept/rimworld-animations-patch.git
synced 2024-08-15 00:43:27 +00:00
48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using HarmonyLib;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Reflection.Emit;
|
|
using UnityEngine;
|
|
using RimWorld;
|
|
using Verse;
|
|
using AlienRace;
|
|
using Rimworld_Animations;
|
|
|
|
namespace Rimworld_Animations_Patch
|
|
{
|
|
[StaticConstructorOnStartup]
|
|
[HarmonyPatch(typeof(CompBodyAnimator), "calculateDrawValues")]
|
|
public static class HarmonyPatch_CompBodyAnimator_calculateDrawValues
|
|
{
|
|
public static void Postfix(CompBodyAnimator __instance)
|
|
{
|
|
if (__instance?.pawn == null)
|
|
{ return; }
|
|
|
|
// Scale delta by body size
|
|
if (BasicSettings.autoscaleDeltaPos)
|
|
{
|
|
__instance.deltaPos.x *= __instance.pawn.RaceProps.baseBodySize;
|
|
__instance.deltaPos.z *= __instance.pawn.RaceProps.baseBodySize;
|
|
}
|
|
|
|
// In-bed specific animations cause the actors to turn to match its facing
|
|
if (__instance.pawn.IsInBed(out Building bed) &&
|
|
__instance.pawn.GetAnimationData().animationDef.actors[__instance.pawn.GetAnimationData().actorID].requiredGenitals.NullOrEmpty() == false &&
|
|
__instance.pawn.GetAnimationData().animationDef.actors[__instance.pawn.GetAnimationData().actorID].requiredGenitals.Contains("Bed"))
|
|
{
|
|
__instance.bodyAngle += ((float)bed.Rotation.AsInt - 2f) * 90;
|
|
if (__instance.bodyAngle < 0) __instance.bodyAngle = 360 - ((-1f * __instance.bodyAngle) % 360);
|
|
if (__instance.bodyAngle > 360) __instance.bodyAngle %= 360;
|
|
|
|
__instance.headAngle += ((float)bed.Rotation.AsInt - 2f) * 90;
|
|
if (__instance.headAngle < 0) __instance.headAngle = 360 - ((-1f * __instance.headAngle) % 360);
|
|
if (__instance.headAngle > 360) __instance.headAngle %= 360;
|
|
|
|
__instance.deltaPos = __instance.deltaPos.RotatedBy(-(float)bed.Rotation.AsAngle);
|
|
}
|
|
}
|
|
}
|
|
}
|