mirror of
				https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
				synced 2024-08-15 00:43:45 +00:00 
			
		
		
		
	HAR Addon fix
This commit is contained in:
		
							parent
							
								
									d6ddf0e6d0
								
							
						
					
					
						commit
						4ff2ab269a
					
				
					 2 changed files with 87 additions and 40 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -11,60 +11,92 @@ using Verse;
 | 
				
			||||||
using AlienRace;
 | 
					using AlienRace;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Rimworld_Animations {
 | 
					namespace Rimworld_Animations {
 | 
				
			||||||
    [StaticConstructorOnStartup]
 | 
					    [HarmonyPatch(typeof(AlienRace.HarmonyPatches), "DrawAddons")]
 | 
				
			||||||
    public static class HarmonyPatch_AlienRace {
 | 
					    public static class HarmonyPatch_AlienRace {
 | 
				
			||||||
        static HarmonyPatch_AlienRace () {
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				((Action)(() => {
 | 
					 | 
				
			||||||
					if (LoadedModManager.RunningModsListForReading.Any(x => x.Name == "Humanoid Alien Races 2.0")) {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
						(new Harmony("rjw")).Patch(AccessTools.Method(typeof(PawnGraphicSet), "ResolveApparelGraphics"),
 | 
					 | 
				
			||||||
							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")));
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}))();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			catch (TypeLoadException ex) {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			}
 | 
							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)
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public static bool Prefix_StopResolveAllGraphicsWhileSex(ref Pawn ___pawn) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if(___pawn.TryGetComp<CompBodyAnimator>() != null && ___pawn.TryGetComp<CompBodyAnimator>().isAnimating) {
 | 
					 | 
				
			||||||
				return false;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public static float RotateHeadAddon(float initialRotation, Pawn pawn)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
			return pawn.TryGetComp<CompBodyAnimator>().headAngle + initialRotation;
 | 
					
 | 
				
			||||||
 | 
								CompBodyAnimator pawnAnimator = pawn.TryGetComp<CompBodyAnimator>();
 | 
				
			||||||
 | 
								if (pawnAnimator.isAnimating && (bodyAddon.drawnInBed || bodyAddon.alignWithHead))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									Quaternion headQuatInAnimation = Quaternion.AngleAxis(pawnAnimator.headAngle, Vector3.up);
 | 
				
			||||||
 | 
									Rot4 headRotInAnimation = pawnAnimator.headFacing;
 | 
				
			||||||
 | 
									Vector3 headPositionInAnimation = pawnAnimator.getPawnHeadPosition() - pawn.Drawer.renderer.BaseHeadOffsetAt(pawnAnimator.headFacing).RotatedBy(angle: Mathf.Acos(f: Quaternion.Dot(a: Quaternion.identity, b: headQuatInAnimation)) * 2f * 57.29578f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									Log.Message(bodyAddon.path + " " + bodyAddon.inFrontOfBody.ToStringSafe());
 | 
				
			||||||
 | 
									headPositionInAnimation.y += bodyAddon.inFrontOfBody ? 1f : -1f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									GenDraw.DrawMeshNowOrLater(mesh: graphic.MeshAt(rot: headRotInAnimation), loc: headPositionInAnimation + (bodyAddon.alignWithHead ? headOffset : Vector3.zero) + v.RotatedBy(angle: Mathf.Acos(f: Quaternion.Dot(a: Quaternion.identity, b: headQuatInAnimation)) * 2f * 57.29578f),
 | 
				
			||||||
 | 
										quat: Quaternion.AngleAxis(angle: num, axis: Vector3.up) * headQuatInAnimation, mat: graphic.MatAt(rot: pawnAnimator.headFacing), drawNow: drawNow);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public static IEnumerable<CodeInstruction> Transpiler_HeadRotation(IEnumerable<CodeInstruction> instructions)
 | 
								else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
									GenDraw.DrawMeshNowOrLater(mesh, loc, quat, mat, drawNow);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							public static Rot4 AdjustRotationValueForHeadAddon(Rot4 rotation, AlienPartGenerator.BodyAddon bodyAddon, Pawn pawn)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
								CompBodyAnimator anim = pawn.TryGetComp<CompBodyAnimator>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (anim.isAnimating && (bodyAddon.alignWithHead || bodyAddon.drawnInBed))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
									return anim.headFacing;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
									return rotation;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
			List<CodeInstruction> ins = instructions.ToList();
 | 
								List<CodeInstruction> ins = instructions.ToList();
 | 
				
			||||||
			for (int i = 0; i < ins.Count; i++)
 | 
								for (int i = 0; i < ins.Count; i++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				yield return ins[i];
 | 
									Type[] type = new Type[] { typeof(Mesh), typeof(Vector3), typeof(Quaternion), typeof(Material), typeof(bool) };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if(ins[i].opcode == OpCodes.Stloc_S && ins[i].OperandIs((object)6))
 | 
					
 | 
				
			||||||
 | 
									if (ins[i].OperandIs(AccessTools.Method(typeof(GenDraw), "DrawMeshNowOrLater", type)))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
					yield return new CodeInstruction(OpCodes.Ldloc_S, (object)6);
 | 
										
 | 
				
			||||||
					yield return new CodeInstruction(OpCodes.Ldarg_S, (object)4);
 | 
										yield return new CodeInstruction(OpCodes.Ldloc, (object)7); //graphic
 | 
				
			||||||
					yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(HarmonyPatch_AlienRace), "RotateHeadAddon"));
 | 
										yield return new CodeInstruction(OpCodes.Ldloc, (object)4); //bodyAddon
 | 
				
			||||||
					yield return new CodeInstruction(OpCodes.Stloc_S, (object)6);
 | 
										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.Call, AccessTools.DeclaredMethod(typeof(HarmonyPatch_AlienRace), "RenderHeadAddonInAnimation"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
									else if(ins[i].opcode == OpCodes.Ldarg_S && ins[i].OperandIs((object)5)) //rotation
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
										yield return ins[i];
 | 
				
			||||||
 | 
										yield return new CodeInstruction(OpCodes.Ldloc, (object)4); //bodyAddon
 | 
				
			||||||
 | 
										yield return new CodeInstruction(OpCodes.Ldarg, (object)3); //pawn
 | 
				
			||||||
 | 
										yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(HarmonyPatch_AlienRace), "AdjustRotationValueForHeadAddon"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									else
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
										yield return ins[i];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public static bool Prefix_AnimateHeadAddons(PawnRenderFlags renderFlags, ref Vector3 vector, ref Vector3 headOffset, Pawn pawn, ref Quaternion quat, ref Rot4 rotation) {
 | 
							public static bool Prefix(PawnRenderFlags renderFlags, ref Vector3 vector, ref Vector3 headOffset, Pawn pawn, ref Quaternion quat, ref Rot4 rotation) {
 | 
				
			||||||
			/* old patch for 1.2
 | 
								/* old patch for 1.2
 | 
				
			||||||
			if (portrait || pawn.TryGetComp<CompBodyAnimator>() == null || !pawn.TryGetComp<CompBodyAnimator>().isAnimating) return true;
 | 
								if (portrait || pawn.TryGetComp<CompBodyAnimator>() == null || !pawn.TryGetComp<CompBodyAnimator>().isAnimating) return true;
 | 
				
			||||||
			if (!(pawn.def is ThingDef_AlienRace alienProps) || invisible) return false;
 | 
								if (!(pawn.def is ThingDef_AlienRace alienProps) || invisible) return false;
 | 
				
			||||||
| 
						 | 
					@ -192,12 +224,13 @@ namespace Rimworld_Animations {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			*/
 | 
								*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								
 | 
				
			||||||
			CompBodyAnimator anim = pawn.TryGetComp<CompBodyAnimator>();
 | 
								CompBodyAnimator anim = pawn.TryGetComp<CompBodyAnimator>();
 | 
				
			||||||
			if (anim.isAnimating)
 | 
								if (anim.isAnimating)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
				headOffset = anim.getPawnHeadOffset();
 | 
									headOffset = anim.getPawnHeadOffset();
 | 
				
			||||||
				quat = Quaternion.AngleAxis(anim.headAngle * 5, Vector3.up);
 | 
									quat = Quaternion.AngleAxis(anim.bodyAngle, Vector3.up);
 | 
				
			||||||
				rotation = anim.headFacing;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
| 
						 | 
					@ -205,4 +238,18 @@ namespace Rimworld_Animations {
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[HarmonyPatch(typeof(PawnGraphicSet), "ResolveApparelGraphics")]
 | 
				
			||||||
 | 
						public static class HarmonyPatch_ResolveApparelGraphics
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
							public static bool Prefix(ref Pawn ___pawn)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (___pawn.TryGetComp<CompBodyAnimator>() != null && ___pawn.TryGetComp<CompBodyAnimator>().isAnimating)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									return false;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue