mirror of
				https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
				synced 2024-08-15 00:43:45 +00:00 
			
		
		
		
	head rot fix
This commit is contained in:
		
							parent
							
								
									7a82ddaf13
								
							
						
					
					
						commit
						f8d3f3c63b
					
				
					 4 changed files with 39 additions and 26 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| 
						 | 
				
			
			@ -143,21 +143,32 @@ namespace Rimworld_Animations {
 | 
			
		|||
                return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void RenderPawnHeadMeshInAnimation(Mesh mesh, Vector3 loc, Quaternion quaternion, Material material, bool portrait, Pawn pawn) {
 | 
			
		||||
        public static void RenderPawnHeadMeshInAnimation1(Mesh mesh, Vector3 loc, Quaternion quaternion, Material material, bool drawNow, Pawn pawn) {
 | 
			
		||||
 | 
			
		||||
            if(pawn == null || pawn.Map != Find.CurrentMap) {
 | 
			
		||||
                GenDraw.DrawMeshNowOrLater(mesh, loc, quaternion, material, portrait);
 | 
			
		||||
            if (pawn == null || pawn.Map != Find.CurrentMap) {
 | 
			
		||||
                GenDraw.DrawMeshNowOrLater(mesh, loc, quaternion, material, drawNow);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            CompBodyAnimator pawnAnimator = pawn.TryGetComp<CompBodyAnimator>();
 | 
			
		||||
 | 
			
		||||
            if (pawnAnimator == null || !pawnAnimator.isAnimating || portrait) {
 | 
			
		||||
                GenDraw.DrawMeshNowOrLater(mesh, loc, quaternion, material, portrait);
 | 
			
		||||
            if (pawnAnimator == null || !pawnAnimator.isAnimating) {
 | 
			
		||||
                GenDraw.DrawMeshNowOrLater(mesh, loc, quaternion, material, drawNow);
 | 
			
		||||
            } else {
 | 
			
		||||
                Vector3 pawnHeadPosition = pawnAnimator.getPawnHeadPosition();
 | 
			
		||||
                pawnHeadPosition.y = loc.y;
 | 
			
		||||
                GenDraw.DrawMeshNowOrLater(mesh, pawnHeadPosition, Quaternion.AngleAxis(pawnAnimator.headAngle, Vector3.up), material, portrait);
 | 
			
		||||
                GenDraw.DrawMeshNowOrLater(MeshPool.humanlikeHeadSet.MeshAt(pawnAnimator.headFacing), pawnHeadPosition, Quaternion.AngleAxis(pawnAnimator.headAngle, Vector3.up), material, true);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void AdjustHead(ref Quaternion quat, ref Rot4 bodyFacing, ref Vector3 pos, Pawn pawn)
 | 
			
		||||
        {
 | 
			
		||||
            CompBodyAnimator anim = pawn.TryGetComp<CompBodyAnimator>();
 | 
			
		||||
            if (anim.isAnimating)
 | 
			
		||||
            {
 | 
			
		||||
                bodyFacing = anim.headFacing;
 | 
			
		||||
                quat = Quaternion.AngleAxis(anim.headAngle, Vector3.up);
 | 
			
		||||
                pos = anim.getPawnHeadOffset();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -411,6 +411,12 @@ namespace Rimworld_Animations {
 | 
			
		|||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Vector3 getPawnHeadOffset()
 | 
			
		||||
        {
 | 
			
		||||
            return Quaternion.AngleAxis(bodyAngle, Vector3.up) * (pawn.Drawer.renderer.BaseHeadOffsetAt(headFacing) + headBob);
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public AnimationDef CurrentAnimation {
 | 
			
		||||
            get {
 | 
			
		||||
                return anim;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,35 +38,32 @@ namespace Rimworld_Animations {
 | 
			
		|||
				bodyAnim.animatePawnBody(ref rootLoc, ref angle, ref bodyFacing);
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
 | 
			
		||||
		{
 | 
			
		||||
			bool forHead = false;
 | 
			
		||||
 | 
			
		||||
			foreach (CodeInstruction i in instructions)
 | 
			
		||||
			List<CodeInstruction> ins = instructions.ToList();
 | 
			
		||||
			
 | 
			
		||||
			for(int i = 0; i < instructions.Count(); i++)
 | 
			
		||||
			{
 | 
			
		||||
				
 | 
			
		||||
				if (i.opcode == OpCodes.Ldfld && i.OperandIs(AccessTools.Field(typeof(PawnGraphicSet), "headGraphic")))
 | 
			
		||||
				{
 | 
			
		||||
 | 
			
		||||
					forHead = true;
 | 
			
		||||
					yield return i;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				else if (forHead && i.opcode == OpCodes.Ldarg_S && i.operand == (object)4)
 | 
			
		||||
				{
 | 
			
		||||
				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.Ldarg_0);
 | 
			
		||||
					yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PawnRenderer), "pawn"));
 | 
			
		||||
					yield return new CodeInstruction(OpCodes.Ldloc_S, operand: 4);
 | 
			
		||||
					yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(AnimationUtility), "PawnHeadRotInAnimation"));
 | 
			
		||||
				
 | 
			
		||||
				}
 | 
			
		||||
					yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.DeclaredField(typeof(PawnRenderer), "pawn"));
 | 
			
		||||
					yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(AnimationUtility), "AdjustHead"));
 | 
			
		||||
					yield return ins[i];
 | 
			
		||||
					//headFacing equals true
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
				else
 | 
			
		||||
                {
 | 
			
		||||
					yield return i;
 | 
			
		||||
					yield return ins[i];
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +73,6 @@ namespace Rimworld_Animations {
 | 
			
		|||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue