head rot fix

This commit is contained in:
c0ffee 2021-07-21 22:59:18 -07:00
parent 7a82ddaf13
commit f8d3f3c63b
4 changed files with 39 additions and 26 deletions

View file

@ -143,21 +143,32 @@ namespace Rimworld_Animations {
return null; return null;
} }
public static void RenderPawnHeadMeshInAnimation(Mesh mesh, Vector3 loc, Quaternion quaternion, Material material, bool portrait, Pawn pawn) { public static void RenderPawnHeadMeshInAnimation1(Mesh mesh, Vector3 loc, Quaternion quaternion, Material material, bool drawNow, Pawn pawn) {
if(pawn == null || pawn.Map != Find.CurrentMap) { if (pawn == null || pawn.Map != Find.CurrentMap) {
GenDraw.DrawMeshNowOrLater(mesh, loc, quaternion, material, portrait); GenDraw.DrawMeshNowOrLater(mesh, loc, quaternion, material, drawNow);
return; return;
} }
CompBodyAnimator pawnAnimator = pawn.TryGetComp<CompBodyAnimator>(); CompBodyAnimator pawnAnimator = pawn.TryGetComp<CompBodyAnimator>();
if (pawnAnimator == null || !pawnAnimator.isAnimating || portrait) { if (pawnAnimator == null || !pawnAnimator.isAnimating) {
GenDraw.DrawMeshNowOrLater(mesh, loc, quaternion, material, portrait); GenDraw.DrawMeshNowOrLater(mesh, loc, quaternion, material, drawNow);
} else { } else {
Vector3 pawnHeadPosition = pawnAnimator.getPawnHeadPosition(); Vector3 pawnHeadPosition = pawnAnimator.getPawnHeadPosition();
pawnHeadPosition.y = loc.y; pawnHeadPosition.y = loc.y;
GenDraw.DrawMeshNowOrLater(mesh, pawnHeadPosition, Quaternion.AngleAxis(pawnAnimator.headAngle, Vector3.up), material, portrait); GenDraw.DrawMeshNowOrLater(MeshPool.humanlikeHeadSet.MeshAt(pawnAnimator.headFacing), pawnHeadPosition, Quaternion.AngleAxis(pawnAnimator.headAngle, Vector3.up), material, true);
}
}
public static void AdjustHead(ref Quaternion quat, ref Rot4 bodyFacing, ref Vector3 pos, Pawn pawn)
{
CompBodyAnimator anim = pawn.TryGetComp<CompBodyAnimator>();
if (anim.isAnimating)
{
bodyFacing = anim.headFacing;
quat = Quaternion.AngleAxis(anim.headAngle, Vector3.up);
pos = anim.getPawnHeadOffset();
} }
} }

View file

@ -411,6 +411,12 @@ namespace Rimworld_Animations {
} }
public Vector3 getPawnHeadOffset()
{
return Quaternion.AngleAxis(bodyAngle, Vector3.up) * (pawn.Drawer.renderer.BaseHeadOffsetAt(headFacing) + headBob);
}
public AnimationDef CurrentAnimation { public AnimationDef CurrentAnimation {
get { get {
return anim; return anim;

View file

@ -38,35 +38,32 @@ namespace Rimworld_Animations {
bodyAnim.animatePawnBody(ref rootLoc, ref angle, ref bodyFacing); bodyAnim.animatePawnBody(ref rootLoc, ref angle, ref bodyFacing);
} }
} }
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{ {
bool forHead = false; List<CodeInstruction> ins = instructions.ToList();
foreach (CodeInstruction i in instructions) for(int i = 0; i < instructions.Count(); i++)
{ {
if (i.opcode == OpCodes.Ldfld && i.OperandIs(AccessTools.Field(typeof(PawnGraphicSet), "headGraphic"))) if (i - 3 >= 0 && ins[i - 3].opcode == OpCodes.Call && ins[i - 3].operand != null && ins[i - 3].OperandIs(AccessTools.DeclaredMethod(typeof(PawnRenderer), "BaseHeadOffsetAt")))
{ {
forHead = true;
yield return i;
}
else if (forHead && i.opcode == OpCodes.Ldarg_S && i.operand == (object)4)
{
yield return new CodeInstruction(OpCodes.Ldloca, (object)0);
yield return new CodeInstruction(OpCodes.Ldloca, (object)7);
yield return new CodeInstruction(OpCodes.Ldloca, (object)6);
yield return new CodeInstruction(OpCodes.Ldarg_0); yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PawnRenderer), "pawn")); yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.DeclaredField(typeof(PawnRenderer), "pawn"));
yield return new CodeInstruction(OpCodes.Ldloc_S, operand: 4); yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(AnimationUtility), "AdjustHead"));
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(AnimationUtility), "PawnHeadRotInAnimation")); yield return ins[i];
//headFacing equals true
} }
else else
{ {
yield return i; yield return ins[i];
} }
@ -78,5 +75,4 @@ namespace Rimworld_Animations {
} }