mirror of
https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
synced 2024-08-15 00:43:45 +00:00
Patch for Hats Display Selection
This commit is contained in:
parent
38374a97e2
commit
7e54290548
4 changed files with 95 additions and 18 deletions
Binary file not shown.
|
@ -45,7 +45,7 @@
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="RJW">
|
<Reference Include="RJW">
|
||||||
<HintPath>..\rjw-master\1.1\Assemblies\RJW.dll</HintPath>
|
<HintPath>..\RJW\1.1\Assemblies\RJW.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
@ -94,6 +94,7 @@
|
||||||
<Compile Include="Source\Patches\HarmonyPatch_CSL.cs" />
|
<Compile Include="Source\Patches\HarmonyPatch_CSL.cs" />
|
||||||
<Compile Include="Source\Patches\HarmonyPatch_DontShaveYourHead.cs" />
|
<Compile Include="Source\Patches\HarmonyPatch_DontShaveYourHead.cs" />
|
||||||
<Compile Include="Source\Patches\HarmonyPatch_FacialAnimation.cs" />
|
<Compile Include="Source\Patches\HarmonyPatch_FacialAnimation.cs" />
|
||||||
|
<Compile Include="Source\Patches\HarmonyPatch_HatsDisplaySelection.cs" />
|
||||||
<Compile Include="Source\Patches\HarmonyPatch_PawnRenderer.cs" />
|
<Compile Include="Source\Patches\HarmonyPatch_PawnRenderer.cs" />
|
||||||
<Compile Include="Source\Patches\HarmonyPatch_PawnRotation.cs" />
|
<Compile Include="Source\Patches\HarmonyPatch_PawnRotation.cs" />
|
||||||
<Compile Include="Source\Patches\HarmonyPatch_Pawn_DrawTracker.cs" />
|
<Compile Include="Source\Patches\HarmonyPatch_Pawn_DrawTracker.cs" />
|
||||||
|
|
47
Source/Patches/HarmonyPatch_HatsDisplaySelection.cs
Normal file
47
Source/Patches/HarmonyPatch_HatsDisplaySelection.cs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
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 {
|
||||||
|
public static class HarmonyPatch_HatsDisplaySelection {
|
||||||
|
|
||||||
|
public static void PatchHatsDisplaySelectionArgs() {
|
||||||
|
(new Harmony("rjw")).Patch(AccessTools.Method(AccessTools.TypeByName("HatDisplaySelection.Patch"), "DrawHatCEWithHair"),
|
||||||
|
transpiler: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_HatsDisplaySelection), "ReplaceDrawMeshOrLaterWithAnimate")));
|
||||||
|
|
||||||
|
(new Harmony("rjw")).Patch(AccessTools.Method(AccessTools.TypeByName("HatDisplaySelection.Patch"), "DrawHatWithHair"),
|
||||||
|
transpiler: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_HatsDisplaySelection), "ReplaceDrawMeshOrLaterWithAnimate")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<CodeInstruction> ReplaceDrawMeshOrLaterWithAnimate(IEnumerable<CodeInstruction> instructions) {
|
||||||
|
|
||||||
|
MethodInfo drawMeshNowOrLater = AccessTools.Method(typeof(GenDraw), "DrawMeshNowOrLater");
|
||||||
|
List<CodeInstruction> codes = instructions.ToList();
|
||||||
|
for (int i = 0; i < instructions.Count(); i++) {
|
||||||
|
|
||||||
|
|
||||||
|
if (codes[i].OperandIs(drawMeshNowOrLater)) {
|
||||||
|
|
||||||
|
yield return new CodeInstruction(OpCodes.Ldarg_0);
|
||||||
|
yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.DeclaredField(AccessTools.TypeByName("HatDisplaySelection.Patch"), "pawn"));
|
||||||
|
yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(AnimationUtility), nameof(AnimationUtility.RenderPawnHeadMeshInAnimation), new Type[] { typeof(Mesh), typeof(Vector3), typeof(Quaternion), typeof(Material), typeof(bool), typeof(Pawn) }));
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
yield return codes[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,14 +23,12 @@ namespace Rimworld_Animations {
|
||||||
typeof(bool),
|
typeof(bool),
|
||||||
typeof(bool),
|
typeof(bool),
|
||||||
typeof(bool)
|
typeof(bool)
|
||||||
})]
|
}
|
||||||
|
)]
|
||||||
public static class HarmonyPatch_PawnRenderer
|
public static class HarmonyPatch_PawnRenderer {
|
||||||
{
|
|
||||||
|
|
||||||
[HarmonyBefore(new string[] { "showhair.kv.rw", "erdelf.HumanoidAlienRaces", "Nals.FacialAnimation" })]
|
[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, ref Rot4 headFacing, RotDrawMode bodyDrawType, bool portrait, bool headStump, bool invisible)
|
public static void Prefix(PawnRenderer __instance, ref Vector3 rootLoc, ref float angle, bool renderBody, ref Rot4 bodyFacing, ref Rot4 headFacing, RotDrawMode bodyDrawType, bool portrait, bool headStump, bool invisible) {
|
||||||
{
|
|
||||||
PawnGraphicSet graphics = __instance.graphics;
|
PawnGraphicSet graphics = __instance.graphics;
|
||||||
Pawn pawn = graphics.pawn;
|
Pawn pawn = graphics.pawn;
|
||||||
CompBodyAnimator bodyAnim = pawn.TryGetComp<CompBodyAnimator>();
|
CompBodyAnimator bodyAnim = pawn.TryGetComp<CompBodyAnimator>();
|
||||||
|
@ -46,6 +44,37 @@ namespace Rimworld_Animations {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[StaticConstructorOnStartup]
|
||||||
|
public static class HarmonyPatch_Animate
|
||||||
|
{
|
||||||
|
|
||||||
|
static HarmonyPatch_Animate() {
|
||||||
|
|
||||||
|
if (LoadedModManager.RunningModsListForReading.Any(x => x.Name == "Hats Display Selection")) {
|
||||||
|
HarmonyPatch_HatsDisplaySelection.PatchHatsDisplaySelectionArgs();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PatchRimworldFunctionsNormally();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void PatchRimworldFunctionsNormally() {
|
||||||
|
(new Harmony("rjw")).Patch(AccessTools.Method(typeof(PawnRenderer), "RenderPawnInternal", parameters: new Type[]
|
||||||
|
{
|
||||||
|
typeof(Vector3),
|
||||||
|
typeof(float),
|
||||||
|
typeof(bool),
|
||||||
|
typeof(Rot4),
|
||||||
|
typeof(Rot4),
|
||||||
|
typeof(RotDrawMode),
|
||||||
|
typeof(bool),
|
||||||
|
typeof(bool),
|
||||||
|
typeof(bool)
|
||||||
|
}),
|
||||||
|
transpiler: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_Animate), "Transpiler")));
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyAfter(new string[] { "showhair.kv.rw", "erdelf.HumanoidAlienRaces", "Nals.FacialAnimation" })]
|
[HarmonyAfter(new string[] { "showhair.kv.rw", "erdelf.HumanoidAlienRaces", "Nals.FacialAnimation" })]
|
||||||
[HarmonyReversePatch(HarmonyReversePatchType.Snapshot)]
|
[HarmonyReversePatch(HarmonyReversePatchType.Snapshot)]
|
||||||
|
|
Loading…
Reference in a new issue