diff --git a/1.3/Assemblies/Rimworld-Animations.dll b/1.3/Assemblies/Rimworld-Animations.dll index 8b6064b..bf20574 100644 Binary files a/1.3/Assemblies/Rimworld-Animations.dll and b/1.3/Assemblies/Rimworld-Animations.dll differ diff --git a/Rimworld-Animations.csproj b/Rimworld-Animations.csproj index e183076..492ca30 100644 --- a/Rimworld-Animations.csproj +++ b/Rimworld-Animations.csproj @@ -36,7 +36,7 @@ False - ..\..\..\..\workshop\content\294100\839005762\1.2\Assemblies\AlienRace.dll + ..\..\..\..\workshop\content\294100\839005762\1.3\Assemblies\AlienRace.dll False @@ -55,13 +55,11 @@ - - False + ..\..\RimWorldWin64_Data\Managed\UnityEngine.dll False - - False + ..\..\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll False @@ -94,6 +92,7 @@ + diff --git a/Source/AnimationUtility.cs b/Source/AnimationUtility.cs index 6a4f76d..ef089f1 100644 --- a/Source/AnimationUtility.cs +++ b/Source/AnimationUtility.cs @@ -161,12 +161,15 @@ namespace Rimworld_Animations { } } - public static void AdjustHead(ref Quaternion quat, ref Rot4 bodyFacing, ref Vector3 pos, Pawn pawn) + public static void AdjustHead(ref Quaternion quat, ref Rot4 bodyFacing, ref Vector3 pos, ref float angle, Pawn pawn, PawnRenderFlags flags) { + if (flags.FlagSet(PawnRenderFlags.Portrait)) return; + CompBodyAnimator anim = pawn.TryGetComp(); if (anim.isAnimating) { bodyFacing = anim.headFacing; + angle = anim.headAngle; quat = Quaternion.AngleAxis(anim.headAngle, Vector3.up); pos = anim.getPawnHeadOffset(); } diff --git a/Source/Patches/HarmonyPatch_AlienRace.cs b/Source/Patches/HarmonyPatch_AlienRace.cs index 0391195..c6c6156 100644 --- a/Source/Patches/HarmonyPatch_AlienRace.cs +++ b/Source/Patches/HarmonyPatch_AlienRace.cs @@ -22,6 +22,7 @@ namespace Rimworld_Animations { prefix: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_AlienRace), "Prefix_StopResolveAllGraphicsWhileSex"))); (new Harmony("rjw")).Patch(AccessTools.Method(AccessTools.TypeByName("AlienRace.HarmonyPatches"), "DrawAddons"), + //transpiler: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_AlienRace), "Transpiler_HeadRotation")), prefix: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_AlienRace), "Prefix_AnimateHeadAddons"))); } }))(); @@ -39,8 +40,32 @@ namespace Rimworld_Animations { return true; } - public static bool Prefix_AnimateHeadAddons(bool portrait, Vector3 vector, Vector3 headOffset, Pawn pawn, Quaternion quat, Rot4 rotation, bool invisible) { + public static float RotateHeadAddon(float initialRotation, Pawn pawn) + { + return pawn.TryGetComp().headAngle + initialRotation; + } + public static IEnumerable Transpiler_HeadRotation(IEnumerable instructions) + { + List ins = instructions.ToList(); + for (int i = 0; i < ins.Count; i++) + { + + yield return ins[i]; + + if(ins[i].opcode == OpCodes.Stloc_S && ins[i].OperandIs((object)6)) + { + yield return new CodeInstruction(OpCodes.Ldloc_S, (object)6); + yield return new CodeInstruction(OpCodes.Ldarg_S, (object)4); + yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(HarmonyPatch_AlienRace), "RotateHeadAddon")); + yield return new CodeInstruction(OpCodes.Stloc_S, (object)6); + + } + } + } + + public static bool Prefix_AnimateHeadAddons(PawnRenderFlags renderFlags, ref Vector3 vector, ref Vector3 headOffset, Pawn pawn, ref Quaternion quat, ref Rot4 rotation) { + /* old patch for 1.2 if (portrait || pawn.TryGetComp() == null || !pawn.TryGetComp().isAnimating) return true; if (!(pawn.def is ThingDef_AlienRace alienProps) || invisible) return false; @@ -52,29 +77,9 @@ namespace Rimworld_Animations { AlienPartGenerator.BodyAddon ba = addons[index: i]; if (!ba.CanDrawAddon(pawn: pawn)) continue; - AlienPartGenerator.RotationOffset offset; - if (ba.drawnInBed || ba.alignWithHead) { - offset = pawnAnimator.headFacing == Rot4.South ? - ba.offsets.south : - pawnAnimator.headFacing == Rot4.North ? - ba.offsets.north : - pawnAnimator.headFacing == Rot4.East ? - ba.offsets.east : - ba.offsets.west; + AlienPartGenerator.RotationOffset offset = ba.defaultOffsets.GetOffset((ba.drawnInBed || ba.alignWithHead) ? pawnAnimator.headFacing : rotation); + Vector3 a = (offset != null) ? offset.GetOffset(renderFlags.FlagSet(PawnRenderFlags.Portrait), pawn.story.bodyType, comp.crownType) : Vector3.zero; - } else { - - offset = rotation == Rot4.South ? - ba.offsets.south : - rotation == Rot4.North ? - ba.offsets.north : - rotation == Rot4.East ? - ba.offsets.east : - ba.offsets.west; - - } - - Vector2 bodyOffset = (portrait ? offset?.portraitBodyTypes ?? offset?.bodyTypes : offset?.bodyTypes)?.FirstOrDefault(predicate: to => to.bodyType == pawn.story.bodyType) ?.offset ?? Vector2.zero; @@ -145,8 +150,59 @@ namespace Rimworld_Animations { } + + + CompBodyAnimator pawnAnimator = pawn.TryGetComp(); + + ThingDef_AlienRace thingDef_AlienRace = pawn.def as ThingDef_AlienRace; + if (thingDef_AlienRace == null || renderFlags.FlagSet(PawnRenderFlags.Invisible)) + { + return false; + } + List bodyAddons = thingDef_AlienRace.alienRace.generalSettings.alienPartGenerator.bodyAddons; + AlienPartGenerator.AlienComp comp = pawn.GetComp(); + for (int i = 0; i < bodyAddons.Count; i++) + { + AlienPartGenerator.BodyAddon bodyAddon = bodyAddons[i]; + if (bodyAddon.CanDrawAddon(pawn)) + { + AlienPartGenerator.RotationOffset offset = bodyAddon.defaultOffsets.GetOffset((bodyAddon.drawnInBed || bodyAddon.alignWithHead) ? pawnAnimator.headFacing : rotation); + Vector3 a = (offset != null) ? offset.GetOffset(renderFlags.FlagSet(PawnRenderFlags.Portrait), pawn.story.bodyType, comp.crownType) : Vector3.zero; + AlienPartGenerator.RotationOffset offset2 = bodyAddon.offsets.GetOffset((bodyAddon.drawnInBed || bodyAddon.alignWithHead) ? pawnAnimator.headFacing : rotation); + Vector3 vector2 = a + ((offset2 != null) ? offset2.GetOffset(renderFlags.FlagSet(PawnRenderFlags.Portrait), pawn.story.bodyType, comp.crownType) : Vector3.zero); + vector2.y = (bodyAddon.inFrontOfBody ? (0.3f + vector2.y) : (-0.3f - vector2.y)); + float num = bodyAddon.angle; + if (rotation == Rot4.North) + { + if (bodyAddon.layerInvert) + { + vector2.y = -vector2.y; + } + num = 0f; + } + if (rotation == Rot4.East) + { + num = -num; + vector2.x = -vector2.x; + } + Graphic graphic = comp.addonGraphics[i]; + graphic.drawSize = ((renderFlags.FlagSet(PawnRenderFlags.Portrait) && bodyAddon.drawSizePortrait != Vector2.zero) ? bodyAddon.drawSizePortrait : bodyAddon.drawSize) * (bodyAddon.scaleWithPawnDrawsize ? (bodyAddon.alignWithHead ? (renderFlags.FlagSet(PawnRenderFlags.Portrait) ? comp.customPortraitHeadDrawSize : comp.customHeadDrawSize) : (renderFlags.FlagSet(PawnRenderFlags.Portrait) ? comp.customPortraitDrawSize : comp.customDrawSize)) : Vector2.one) * 1.5f; + GenDraw.DrawMeshNowOrLater(graphic.MeshAt(rotation), vector + (bodyAddon.alignWithHead ? headOffset : Vector3.zero) + vector2.RotatedBy(Mathf.Acos(Quaternion.Dot(Quaternion.identity, quat)) * 2f * 57.29578f), Quaternion.AngleAxis(num, Vector3.up) * quat, graphic.MatAt(rotation, null), renderFlags.FlagSet(PawnRenderFlags.DrawNow)); + } + } + + */ + CompBodyAnimator anim = pawn.TryGetComp(); + if (anim.isAnimating) + { + headOffset = anim.getPawnHeadOffset(); + quat = Quaternion.AngleAxis(anim.headAngle * 5, Vector3.up); + rotation = anim.headFacing; + } + + return true; + - return false; } } } \ No newline at end of file diff --git a/Source/Patches/HarmonyPatch_HeadHair.cs b/Source/Patches/HarmonyPatch_HeadHair.cs new file mode 100644 index 0000000..37ba6ce --- /dev/null +++ b/Source/Patches/HarmonyPatch_HeadHair.cs @@ -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) + { + + } + + } +} diff --git a/Source/Patches/HarmonyPatch_PawnRenderer.cs b/Source/Patches/HarmonyPatch_PawnRenderer.cs index d21af92..7514963 100644 --- a/Source/Patches/HarmonyPatch_PawnRenderer.cs +++ b/Source/Patches/HarmonyPatch_PawnRenderer.cs @@ -28,6 +28,9 @@ namespace Rimworld_Animations { [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(); @@ -54,8 +57,10 @@ namespace Rimworld_Animations { 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 diff --git a/Source/Patches/HarmonyPatch_SetPawnAnimatable.cs b/Source/Patches/HarmonyPatch_SetPawnAnimatable.cs index 4ddff2c..2c0f29c 100644 --- a/Source/Patches/HarmonyPatch_SetPawnAnimatable.cs +++ b/Source/Patches/HarmonyPatch_SetPawnAnimatable.cs @@ -16,7 +16,7 @@ namespace Rimworld_Animations { static bool ClearCache(Pawn pawn) { - return pawn.IsInvisible() || pawn.TryGetComp().isAnimating; + return pawn.IsInvisible() || pawn.TryGetComp().isAnimating; } public static IEnumerable Transpiler(IEnumerable instructions) @@ -27,6 +27,7 @@ namespace Rimworld_Animations { if (i.OperandIs(AccessTools.Method(typeof(PawnUtility), "IsInvisible"))) { + yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(PawnRenderer_RenderPawnAt_Patch), "ClearCache")); } else