mirror of
https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
synced 2024-08-15 00:43:45 +00:00
Changed from rerouting the job to another for joininbed to simply patching joininbed, code tidying
This commit is contained in:
parent
8177b95bc8
commit
702964a8c2
24 changed files with 143 additions and 774 deletions
22
Source/Patches/RimworldPatches/HarmonyPatch_HeadHair.cs
Normal file
22
Source/Patches/RimworldPatches/HarmonyPatch_HeadHair.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rimworld_Animations
|
||||
{
|
||||
[HarmonyPatch(typeof(PawnRenderer), "DrawHeadHair")]
|
||||
public static class HarmonyPatch_HeadHair
|
||||
{
|
||||
public static void Prefix(ref Vector3 headOffset, ref float angle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
83
Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderer.cs
Normal file
83
Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderer.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
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 {
|
||||
|
||||
[HarmonyPatch(typeof(PawnRenderer), "RenderPawnInternal", new Type[]
|
||||
{
|
||||
typeof(Vector3),
|
||||
typeof(float),
|
||||
typeof(bool),
|
||||
typeof(Rot4),
|
||||
typeof(RotDrawMode),
|
||||
typeof(PawnRenderFlags)
|
||||
}
|
||||
)]
|
||||
public static class HarmonyPatch_PawnRenderer
|
||||
{
|
||||
|
||||
[HarmonyBefore(new string[] { "showhair.kv.rw", "erdelf.HumanoidAlienRaces", "Nals.FacialAnimation" })]
|
||||
public static void Prefix(PawnRenderer __instance, ref Vector3 rootLoc, ref float angle, bool renderBody, ref Rot4 bodyFacing, RotDrawMode bodyDrawType, PawnRenderFlags flags)
|
||||
{
|
||||
|
||||
if (flags.FlagSet(PawnRenderFlags.Portrait)) return;
|
||||
|
||||
PawnGraphicSet graphics = __instance.graphics;
|
||||
Pawn pawn = graphics.pawn;
|
||||
CompBodyAnimator bodyAnim = pawn.TryGetComp<CompBodyAnimator>();
|
||||
|
||||
|
||||
if (bodyAnim != null && bodyAnim.isAnimating && pawn.Map == Find.CurrentMap)
|
||||
{
|
||||
bodyAnim.animatePawnBody(ref rootLoc, ref angle, ref bodyFacing);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
List<CodeInstruction> ins = instructions.ToList();
|
||||
|
||||
for(int i = 0; i < instructions.Count(); i++)
|
||||
{
|
||||
|
||||
if (i - 3 >= 0 && ins[i - 3].opcode == OpCodes.Call && ins[i - 3].operand != null && ins[i - 3].OperandIs(AccessTools.DeclaredMethod(typeof(PawnRenderer), "BaseHeadOffsetAt")))
|
||||
{
|
||||
|
||||
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.Ldarga, (object)2);
|
||||
yield return new CodeInstruction(OpCodes.Ldarg_0);
|
||||
yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.DeclaredField(typeof(PawnRenderer), "pawn"));
|
||||
yield return new CodeInstruction(OpCodes.Ldarg, (object)6);
|
||||
yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(AnimationUtility), "AdjustHead"));
|
||||
yield return ins[i];
|
||||
//headFacing equals true
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
yield return ins[i];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
29
Source/Patches/RimworldPatches/HarmonyPatch_PawnRotation.cs
Normal file
29
Source/Patches/RimworldPatches/HarmonyPatch_PawnRotation.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Verse;
|
||||
|
||||
namespace Rimworld_Animations {
|
||||
[HarmonyPatch(typeof(Thing), "Rotation", MethodType.Getter)]
|
||||
public static class HarmonyPatch_PawnRotation {
|
||||
|
||||
public static bool Prefix(Thing __instance, ref Rot4 __result) {
|
||||
|
||||
if(!(__instance is Pawn) || (__instance as Pawn)?.TryGetComp<CompBodyAnimator>() == null || !(__instance as Pawn).TryGetComp<CompBodyAnimator>().isAnimating) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Pawn pawn = (__instance as Pawn);
|
||||
__result = pawn.TryGetComp<CompBodyAnimator>().bodyFacing;
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
namespace Rimworld_Animations {
|
||||
|
||||
[HarmonyPatch(typeof(Pawn_DrawTracker), "DrawPos", MethodType.Getter)]
|
||||
public static class HarmonyPatch_Pawn_DrawTracker {
|
||||
public static bool Prefix(ref Pawn ___pawn, ref Vector3 __result) {
|
||||
|
||||
CompBodyAnimator bodyAnim = ___pawn.TryGetComp<CompBodyAnimator>();
|
||||
|
||||
if (bodyAnim != null && bodyAnim.isAnimating) {
|
||||
__result = ___pawn.TryGetComp<CompBodyAnimator>().anchor + ___pawn.TryGetComp<CompBodyAnimator>().deltaPos;
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
namespace Rimworld_Animations
|
||||
{
|
||||
[HarmonyPatch(typeof(PawnRenderer), "RenderPawnAt")]
|
||||
public static class PawnRenderer_RenderPawnAt_Patch
|
||||
{
|
||||
static bool ClearCache(Pawn pawn)
|
||||
{
|
||||
return pawn.IsInvisible() || pawn.TryGetComp<CompBodyAnimator>().isAnimating;
|
||||
}
|
||||
|
||||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
var list = instructions.ToList();
|
||||
|
||||
foreach (CodeInstruction i in instructions)
|
||||
{
|
||||
if (i.OperandIs(AccessTools.Method(typeof(PawnUtility), "IsInvisible")))
|
||||
{
|
||||
|
||||
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(PawnRenderer_RenderPawnAt_Patch), "ClearCache"));
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue