rimworld-animations/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderTree.cs

37 lines
1.4 KiB
C#
Raw Normal View History

using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace Rimworld_Animations
{
[HarmonyPatch(typeof(PawnRenderTree), "TryGetMatrix")]
public class HarmonyPatch_PawnRenderTree
{
public static void Prefix(PawnRenderTree __instance, PawnRenderNode node, ref PawnDrawParms parms)
{
//Note: Maybe need to change this to check all ancestors if it's the head node
//in case of deeper nodes in the PawnRenderTree
//This code only checks for node and parent, if either are head
// Change facing for all head and apparelhead nodes
// So that the offset is based on body rotation, not head rotation
//fixes misaligned hairs and headaddons
if ((node.Props.tagDef == PawnRenderNodeTagDefOf.Head || node.Props.tagDef == PawnRenderNodeTagDefOf.ApparelHead
|| node?.parent?.Props?.tagDef == PawnRenderNodeTagDefOf.Head || node?.parent?.Props?.tagDef == PawnRenderNodeTagDefOf.ApparelHead)
&& node.tree.rootNode.AnimationWorker is AnimationWorker_KeyframesExtended rootNodeAnimationWorker)
{
// this is only for the Vector3 position to work right
parms.facing = rootNodeAnimationWorker.facingAtTick(node.tree.AnimationTick);
}
}
}
}