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; } if (BasicSettings.autoscaleDeltaPos) { __instance.deltaPos.x *= __instance.pawn.RaceProps.baseBodySize; __instance.deltaPos.z *= __instance.pawn.RaceProps.baseBodySize; } 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); } } } }