2020-04-09 00:43:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using RimWorld;
|
|
|
|
|
using Verse;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
|
|
|
|
|
|
namespace Rimworld_Animations {
|
2021-07-21 19:24:23 +00:00
|
|
|
|
|
2020-04-09 00:43:01 +00:00
|
|
|
|
[HarmonyPatch(typeof(PawnRenderer), "RenderPawnInternal", new Type[]
|
2020-12-21 23:00:45 +00:00
|
|
|
|
{
|
2021-07-21 19:24:23 +00:00
|
|
|
|
typeof(Vector3),
|
|
|
|
|
typeof(float),
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(Rot4),
|
|
|
|
|
typeof(RotDrawMode),
|
|
|
|
|
typeof(PawnRenderFlags)
|
2020-12-21 23:00:45 +00:00
|
|
|
|
}
|
|
|
|
|
)]
|
2021-07-21 19:24:23 +00:00
|
|
|
|
public static class HarmonyPatch_PawnRenderer
|
|
|
|
|
{
|
2020-04-09 00:43:01 +00:00
|
|
|
|
|
|
|
|
|
[HarmonyBefore(new string[] { "showhair.kv.rw", "erdelf.HumanoidAlienRaces", "Nals.FacialAnimation" })]
|
2021-07-21 19:24:23 +00:00
|
|
|
|
public static void Prefix(PawnRenderer __instance, ref Vector3 rootLoc, ref float angle, bool renderBody, ref Rot4 bodyFacing, RotDrawMode bodyDrawType, PawnRenderFlags flags)
|
|
|
|
|
{
|
2021-07-22 23:04:21 +00:00
|
|
|
|
|
|
|
|
|
if (flags.FlagSet(PawnRenderFlags.Portrait)) return;
|
|
|
|
|
|
2020-04-09 00:43:01 +00:00
|
|
|
|
PawnGraphicSet graphics = __instance.graphics;
|
|
|
|
|
Pawn pawn = graphics.pawn;
|
|
|
|
|
CompBodyAnimator bodyAnim = pawn.TryGetComp<CompBodyAnimator>();
|
|
|
|
|
|
|
|
|
|
|
2021-07-21 19:24:23 +00:00
|
|
|
|
if (bodyAnim != null && bodyAnim.isAnimating && pawn.Map == Find.CurrentMap)
|
|
|
|
|
{
|
|
|
|
|
bodyAnim.animatePawnBody(ref rootLoc, ref angle, ref bodyFacing);
|
2020-05-30 06:10:31 +00:00
|
|
|
|
|
2020-04-09 00:43:01 +00:00
|
|
|
|
}
|
2020-12-21 23:00:45 +00:00
|
|
|
|
|
2021-07-22 05:59:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 19:24:23 +00:00
|
|
|
|
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
|
|
|
|
{
|
2021-07-22 05:59:18 +00:00
|
|
|
|
List<CodeInstruction> ins = instructions.ToList();
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < instructions.Count(); i++)
|
2021-07-21 19:24:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
2021-07-22 05:59:18 +00:00
|
|
|
|
if (i - 3 >= 0 && ins[i - 3].opcode == OpCodes.Call && ins[i - 3].operand != null && ins[i - 3].OperandIs(AccessTools.DeclaredMethod(typeof(PawnRenderer), "BaseHeadOffsetAt")))
|
|
|
|
|
{
|
2020-04-09 00:43:01 +00:00
|
|
|
|
|
2021-07-22 05:59:18 +00:00
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldloca, (object)0);
|
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldloca, (object)7);
|
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldloca, (object)6);
|
2021-07-22 23:04:21 +00:00
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldarga, (object)2);
|
2021-07-21 19:24:23 +00:00
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldarg_0);
|
2021-07-22 05:59:18 +00:00
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.DeclaredField(typeof(PawnRenderer), "pawn"));
|
2021-07-22 23:04:21 +00:00
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldarg, (object)6);
|
2021-07-22 05:59:18 +00:00
|
|
|
|
yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(AnimationUtility), "AdjustHead"));
|
|
|
|
|
yield return ins[i];
|
|
|
|
|
//headFacing equals true
|
|
|
|
|
}
|
2020-04-09 00:43:01 +00:00
|
|
|
|
|
2021-07-21 19:24:23 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2021-07-22 05:59:18 +00:00
|
|
|
|
yield return ins[i];
|
2021-07-21 19:24:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2020-04-09 00:43:01 +00:00
|
|
|
|
|
2021-07-21 19:24:23 +00:00
|
|
|
|
}
|
2020-04-09 00:43:01 +00:00
|
|
|
|
|
2021-07-21 19:24:23 +00:00
|
|
|
|
}
|
2020-04-09 00:43:01 +00:00
|
|
|
|
|
2021-07-21 19:24:23 +00:00
|
|
|
|
|
2020-04-09 00:43:01 +00:00
|
|
|
|
|
|
|
|
|
}
|