2021-07-26 05:35:50 +00:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Verse;
|
|
|
|
|
using AlienRace;
|
|
|
|
|
|
|
|
|
|
namespace Rimworld_Animations {
|
2021-07-26 05:56:01 +00:00
|
|
|
|
|
2021-07-26 05:35:50 +00:00
|
|
|
|
[HarmonyPatch(typeof(AlienRace.HarmonyPatches), "DrawAddons")]
|
|
|
|
|
public static class HarmonyPatch_AlienRace {
|
|
|
|
|
|
|
|
|
|
public static void RenderHeadAddonInAnimation(Mesh mesh, Vector3 loc, Quaternion quat, Material mat, bool drawNow, Graphic graphic, AlienPartGenerator.BodyAddon bodyAddon, Vector3 v, float num, Vector3 headOffset, Pawn pawn, PawnRenderFlags renderFlags)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
CompBodyAnimator pawnAnimator = pawn.TryGetComp<CompBodyAnimator>();
|
2021-07-27 02:11:34 +00:00
|
|
|
|
if (pawnAnimator != null && !renderFlags.FlagSet(PawnRenderFlags.Portrait) && pawnAnimator.isAnimating && (bodyAddon.drawnInBed || bodyAddon.alignWithHead))
|
2021-07-26 05:35:50 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Quaternion headQuatInAnimation = Quaternion.AngleAxis(pawnAnimator.headAngle, Vector3.up);
|
|
|
|
|
Rot4 headRotInAnimation = pawnAnimator.headFacing;
|
2021-08-03 13:00:55 +00:00
|
|
|
|
Vector3 headPositionInAnimation = pawnAnimator.getPawnHeadPosition();
|
2021-07-26 05:35:50 +00:00
|
|
|
|
|
2021-08-03 12:11:22 +00:00
|
|
|
|
headPositionInAnimation.y = loc.y;
|
2021-07-26 05:35:50 +00:00
|
|
|
|
|
2021-08-05 01:29:38 +00:00
|
|
|
|
|
|
|
|
|
Vector3 orassanv = Vector3.zero;
|
|
|
|
|
bool orassan = false;
|
2021-08-19 18:14:56 +00:00
|
|
|
|
/*
|
2021-08-05 01:29:38 +00:00
|
|
|
|
if ((pawn.def as ThingDef_AlienRace).defName == "Alien_Orassan")
|
|
|
|
|
{
|
|
|
|
|
orassan = true;
|
|
|
|
|
|
2021-08-05 01:32:20 +00:00
|
|
|
|
if(bodyAddon.path.Contains("closed"))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 01:29:38 +00:00
|
|
|
|
if (bodyAddon.bodyPart.Contains("ear"))
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
orassan = true;
|
|
|
|
|
|
|
|
|
|
orassanv = new Vector3(0, 0, 0.23f);
|
2021-08-12 22:54:33 +00:00
|
|
|
|
if (pawnAnimator.headFacing == Rot4.North)
|
2021-08-05 01:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
orassanv.z -= 0.1f;
|
2021-08-05 02:34:08 +00:00
|
|
|
|
orassanv.y += 1f;
|
|
|
|
|
|
|
|
|
|
if(bodyAddon.bodyPart.Contains("left"))
|
|
|
|
|
{
|
|
|
|
|
orassanv.x += 0.03f;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
orassanv.x -= 0.03f;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 01:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
else if (pawnAnimator.headFacing == Rot4.East)
|
|
|
|
|
{
|
2021-08-12 23:26:10 +00:00
|
|
|
|
orassanv.x -= 0.1f;
|
2021-08-05 01:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
else if (pawnAnimator.headFacing == Rot4.West)
|
|
|
|
|
{
|
2021-08-12 23:26:10 +00:00
|
|
|
|
orassanv.x = 0.1f;
|
2021-08-05 01:29:38 +00:00
|
|
|
|
}
|
2021-08-12 22:54:33 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
orassanv.z -= 0.1f;
|
|
|
|
|
orassanv.y += 1f;
|
|
|
|
|
|
|
|
|
|
if (bodyAddon.bodyPart.Contains("right"))
|
|
|
|
|
{
|
2021-08-12 23:03:26 +00:00
|
|
|
|
orassanv.x += 0.05f;
|
2021-08-12 22:54:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-08-12 23:03:26 +00:00
|
|
|
|
orassanv.x -= 0.05f;
|
2021-08-12 22:54:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-05 01:29:38 +00:00
|
|
|
|
orassanv = orassanv.RotatedBy(pawnAnimator.headAngle);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-19 18:14:56 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
float quatDot = Quaternion.Dot(Quaternion.identity, quat);
|
|
|
|
|
if (quat.eulerAngles.y > 180f) quatDot = -quatDot;
|
2021-08-05 01:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
2021-08-19 19:23:37 +00:00
|
|
|
|
GenDraw.DrawMeshNowOrLater(mesh: graphic.MeshAt(rot: headRotInAnimation), loc: headPositionInAnimation + orassanv + (bodyAddon.alignWithHead && !orassan ? headOffset : Vector3.zero) + v.RotatedBy(Mathf.Acos(quatDot) * 2f * 57.29578f),
|
2021-08-05 00:22:49 +00:00
|
|
|
|
quat: Quaternion.AngleAxis(angle: num, axis: Vector3.up) * headQuatInAnimation, mat: graphic.MatAt(rot: pawnAnimator.headFacing), drawNow: drawNow);;
|
2021-07-26 05:35:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GenDraw.DrawMeshNowOrLater(mesh, loc, quat, mat, drawNow);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-05 00:22:03 +00:00
|
|
|
|
|
2021-07-26 05:35:50 +00:00
|
|
|
|
|
|
|
|
|
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
|
|
|
|
{
|
|
|
|
|
List<CodeInstruction> ins = instructions.ToList();
|
|
|
|
|
for (int i = 0; i < ins.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
|
2021-08-05 00:22:03 +00:00
|
|
|
|
Type[] type = new Type[] { typeof(Mesh), typeof(Vector3), typeof(Quaternion), typeof(Material), typeof(bool) };
|
|
|
|
|
|
|
|
|
|
|
2021-07-26 05:35:50 +00:00
|
|
|
|
if (ins[i].OperandIs(AccessTools.Method(typeof(GenDraw), "DrawMeshNowOrLater", type)))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldloc, (object)7); //graphic
|
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldloc, (object)4); //bodyAddon
|
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldloc, (object)5); //offsetVector/AddonOffset (v)
|
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldloc, (object)6); //num
|
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldarg, (object)2); //headOffset
|
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldarg, (object)3); //pawn
|
|
|
|
|
yield return new CodeInstruction(OpCodes.Ldarg, (object)0); //renderflags
|
|
|
|
|
|
|
|
|
|
yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(HarmonyPatch_AlienRace), "RenderHeadAddonInAnimation"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
yield return ins[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 05:56:01 +00:00
|
|
|
|
public static bool Prefix(PawnRenderFlags renderFlags, ref Vector3 vector, ref Vector3 headOffset, Pawn pawn, ref Quaternion quat, ref Rot4 rotation)
|
|
|
|
|
{
|
2021-07-27 02:11:34 +00:00
|
|
|
|
if(pawn == null)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 05:56:01 +00:00
|
|
|
|
CompBodyAnimator anim = pawn.TryGetComp<CompBodyAnimator>();
|
2021-07-27 02:11:34 +00:00
|
|
|
|
|
|
|
|
|
if(anim == null)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (anim != null && !renderFlags.FlagSet(PawnRenderFlags.Portrait) && anim.isAnimating)
|
2021-07-26 05:56:01 +00:00
|
|
|
|
{
|
|
|
|
|
quat = Quaternion.AngleAxis(anim.bodyAngle, Vector3.up);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
2021-07-26 05:35:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(PawnGraphicSet), "ResolveApparelGraphics")]
|
|
|
|
|
public static class HarmonyPatch_ResolveApparelGraphics
|
2021-07-26 05:56:01 +00:00
|
|
|
|
{
|
2021-07-26 05:35:50 +00:00
|
|
|
|
public static bool Prefix(ref Pawn ___pawn)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (___pawn.TryGetComp<CompBodyAnimator>() != null && ___pawn.TryGetComp<CompBodyAnimator>().isAnimating)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-26 05:56:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|