Decompiled source of SagTag Inverse Kinematics v0.0.1

InverseKinematics.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("InverseKinematics")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Lethal Company Inverse Kinematics for employees, les gooo")]
[assembly: AssemblyFileVersion("0.1.3.0")]
[assembly: AssemblyInformationalVersion("0.1.3")]
[assembly: AssemblyProduct("InverseKinematics")]
[assembly: AssemblyTitle("InverseKinematics")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[BepInPlugin("com.sagtags.lethalcompany.IKFootsteps", "SagTags Inverse Kinematics Footsteps", "0.0.1")]
public class FootIKPlugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private readonly Harmony harmony = new Harmony("com.sagtags.lethalcompany.IKFootsteps");

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		harmony.PatchAll();
		Log.LogInfo((object)"SagTags IK Footsteps initialized properly");
	}
}
[HarmonyPatch(typeof(PlayerControllerB), "Awake")]
public class PlayerControllerB_AwakePatch
{
	private static void Postfix(PlayerControllerB __instance)
	{
		Animator playerBodyAnimator = __instance.playerBodyAnimator;
		if (!((Object)(object)playerBodyAnimator == (Object)null) && (Object)(object)((Component)playerBodyAnimator).GetComponent<FootIKController>() == (Object)null)
		{
			((Component)playerBodyAnimator).gameObject.AddComponent<FootIKController>();
		}
	}
}
[DefaultExecutionOrder(10000)]
public class FootIKController : MonoBehaviour
{
	private struct FootSample
	{
		public float delta;

		public float plant;

		public Quaternion tilt;

		public bool hit;

		public Vector3 hitPoint;

		public string hitInfo;
	}

	[Header("Floor")]
	public float maxStepUp = 0.35f;

	public float maxStepDown = 0.45f;

	[Header("Calibration")]
	public float planeOffset = 0f;

	[Header("Foot  Adjusting (adjust at own risk)")]
	public float plantStart = 0.15f;

	public float plantEnd = 0.4f;

	[Header("Smoothing")]
	public float footSmoothSpeed = 20f;

	public float hipSmoothSpeed = 12f;

	public float weightFadeSpeed = 6f;

	public float maxFootTilt = 35f;

	public float maxHipDrop = 0.3f;

	[Header("Debug")]
	public bool debugLog = false;

	public bool debugMarkers = false;

	private bool initialized;

	private int initAttempts;

	private int lastFrame = -1;

	private float logTimer;

	private LayerMask groundMask;

	private Animator animator;

	private PlayerControllerB controller;

	private Transform bodyT;

	private Transform hips;

	private Transform lUpper;

	private Transform lLower;

	private Transform lFoot;

	private Transform rUpper;

	private Transform rLower;

	private Transform rFoot;

	private string boneSource = "?";

	private float weight;

	private float lDelta;

	private float rDelta;

	private float hipOffset;

	private float hover;

	private Quaternion lTilt = Quaternion.identity;

	private Quaternion rTilt = Quaternion.identity;

	private Transform mPlane;

	private Transform mLHit;

	private Transform mLTarget;

	private Transform mRHit;

	private Transform mRTarget;

	private void Awake()
	{
		if (FootIKPlugin.Log != null)
		{
			FootIKPlugin.Log.LogInfo((object)"[FootIK] IK Script attached");
		}
	}

	private void OnEnable()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		Application.onBeforeRender += new UnityAction(OnBeforeRender);
	}

	private void OnDisable()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		Application.onBeforeRender -= new UnityAction(OnBeforeRender);
		HideMarkers();
	}

	private void OnDestroy()
	{
		DestroyMarkers();
	}

	private void Update()
	{
		if (!initialized)
		{
			TryInitialize();
		}
	}

	private void TryInitialize()
	{
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Invalid comparison between Unknown and I4
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)controller == (Object)null)
		{
			controller = ((Component)this).GetComponentInParent<PlayerControllerB>();
		}
		if ((Object)(object)animator == (Object)null)
		{
			animator = ((Component)this).GetComponentInParent<Animator>();
		}
		if ((Object)(object)controller == (Object)null || (Object)(object)animator == (Object)null || (Object)(object)StartOfRound.Instance == (Object)null)
		{
			return;
		}
		initAttempts++;
		if (initAttempts > 600)
		{
			FootIKPlugin.Log.LogError((object)("[FootIK] Couldnt map out bones in " + controller.playerUsername + ", how is that player missing bones??:"));
			LogMissingBones();
			((Behaviour)this).enabled = false;
			return;
		}
		groundMask = LayerMask.op_Implicit(StartOfRound.Instance.allPlayersCollideWithMask);
		if (((LayerMask)(ref groundMask)).value != 0 && TryFindBones())
		{
			if ((int)animator.cullingMode > 0)
			{
				animator.cullingMode = (AnimatorCullingMode)0;
			}
			bodyT = (((Object)(object)controller.thisPlayerBody != (Object)null) ? controller.thisPlayerBody : ((Component)controller).transform);
			initialized = true;
			bool flag = (Object)(object)lFoot.parent == (Object)(object)lLower && (Object)(object)lLower.parent == (Object)(object)lUpper && (Object)(object)rFoot.parent == (Object)(object)rLower && (Object)(object)rLower.parent == (Object)(object)rUpper;
			float x = bodyT.InverseTransformPoint(lFoot.position).x;
			float x2 = bodyT.InverseTransformPoint(rFoot.position).x;
		}
	}

	private bool TryFindBones()
	{
		if (animator.isHuman)
		{
			hips = animator.GetBoneTransform((HumanBodyBones)0);
			lUpper = animator.GetBoneTransform((HumanBodyBones)1);
			lLower = animator.GetBoneTransform((HumanBodyBones)3);
			lFoot = animator.GetBoneTransform((HumanBodyBones)5);
			rUpper = animator.GetBoneTransform((HumanBodyBones)2);
			rLower = animator.GetBoneTransform((HumanBodyBones)4);
			rFoot = animator.GetBoneTransform((HumanBodyBones)6);
			if (HaveAllBones())
			{
				boneSource = "Humanoid";
				return true;
			}
		}
		Transform transform = ((Component)animator).transform;
		hips = FindBone(transform, "spine", "pelvis", "hips");
		lUpper = FindBone(transform, "thigh_L", "thigh.L");
		lLower = FindBone(transform, "shin_L", "shin.L");
		lFoot = FindBone(transform, "foot_L", "foot.L");
		rUpper = FindBone(transform, "thigh_R", "thigh.R");
		rLower = FindBone(transform, "shin_R", "shin.R");
		rFoot = FindBone(transform, "foot_R", "foot.R");
		if (HaveAllBones())
		{
			boneSource = "Por nombre";
			return true;
		}
		return false;
	}

	private bool HaveAllBones()
	{
		return (Object)(object)hips != (Object)null && (Object)(object)lUpper != (Object)null && (Object)(object)lLower != (Object)null && (Object)(object)lFoot != (Object)null && (Object)(object)rUpper != (Object)null && (Object)(object)rLower != (Object)null && (Object)(object)rFoot != (Object)null;
	}

	private Transform FindBone(Transform root, params string[] names)
	{
		Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
		Transform[] array = componentsInChildren;
		foreach (Transform val in array)
		{
			foreach (string value in names)
			{
				if (((Object)val).name.Equals(value, StringComparison.OrdinalIgnoreCase))
				{
					return val;
				}
			}
		}
		Transform[] array2 = componentsInChildren;
		foreach (Transform val2 in array2)
		{
			foreach (string value2 in names)
			{
				if (((Object)val2).name.EndsWith(value2, StringComparison.OrdinalIgnoreCase))
				{
					return val2;
				}
			}
		}
		return null;
	}

	private void LogMissingBones()
	{
		if ((Object)(object)hips == (Object)null)
		{
			FootIKPlugin.Log.LogError((object)" -> Missing spine");
		}
		if ((Object)(object)lUpper == (Object)null)
		{
			FootIKPlugin.Log.LogError((object)" -> Missing thigh_L");
		}
		if ((Object)(object)lLower == (Object)null)
		{
			FootIKPlugin.Log.LogError((object)" -> Missing shin_L");
		}
		if ((Object)(object)lFoot == (Object)null)
		{
			FootIKPlugin.Log.LogError((object)" -> Missing foot_L");
		}
		if ((Object)(object)rUpper == (Object)null)
		{
			FootIKPlugin.Log.LogError((object)" -> Missing thigh_R");
		}
		if ((Object)(object)rLower == (Object)null)
		{
			FootIKPlugin.Log.LogError((object)" -> Missing shin_R");
		}
		if ((Object)(object)rFoot == (Object)null)
		{
			FootIKPlugin.Log.LogError((object)" -> Missing foot_R");
		}
	}

	private static string LayerNames(int mask)
	{
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < 32; i++)
		{
			if ((mask & (1 << i)) != 0)
			{
				stringBuilder.Append(i).Append(':').Append(LayerMask.LayerToName(i))
					.Append("  ");
			}
		}
		return stringBuilder.ToString();
	}

	private void OnBeforeRender()
	{
		if (initialized && lastFrame != Time.frameCount)
		{
			lastFrame = Time.frameCount;
			UpdateLegs();
		}
	}

	private void ResetState()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		lDelta = (rDelta = (hipOffset = (hover = 0f)));
		lTilt = (rTilt = Quaternion.identity);
	}

	private void UpdateLegs()
	{
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0390: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04be: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0506: Unknown result type (might be due to invalid IL or missing references)
		//IL_050b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0510: Unknown result type (might be due to invalid IL or missing references)
		//IL_0513: Unknown result type (might be due to invalid IL or missing references)
		//IL_0531: Unknown result type (might be due to invalid IL or missing references)
		//IL_0532: Unknown result type (might be due to invalid IL or missing references)
		//IL_0544: Unknown result type (might be due to invalid IL or missing references)
		//IL_0549: Unknown result type (might be due to invalid IL or missing references)
		//IL_054e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0551: Unknown result type (might be due to invalid IL or missing references)
		bool flag = ((Behaviour)animator).enabled && (Object)(object)animator.runtimeAnimatorController != (Object)null && !controller.isPlayerDead && !controller.performingEmote && !controller.inSpecialInteractAnimation && (Object)(object)controller.inAnimationWithEnemy == (Object)null && !controller.isClimbingLadder && !controller.isUnderwater;
		weight = Mathf.MoveTowards(weight, flag ? 1f : 0f, Time.deltaTime * weightFadeSpeed);
		if (weight <= 0.001f)
		{
			ResetState();
			HideMarkers();
			return;
		}
		Transform transform = ((Component)controller).transform;
		Vector3 position = lFoot.position;
		Vector3 position2 = rFoot.position;
		Quaternion rotation = lFoot.rotation;
		Quaternion rotation2 = rFoot.rotation;
		float num = ((Component)animator).transform.position.y + planeOffset;
		RaycastHit val = default(RaycastHit);
		bool flag2 = Physics.Raycast(transform.position + Vector3.up * 0.6f, Vector3.down, ref val, 2f, LayerMask.op_Implicit(groundMask), (QueryTriggerInteraction)1);
		float num2 = (flag2 ? ((RaycastHit)(ref val)).point.y : transform.position.y);
		float num3 = num - num2;
		float num4 = ((flag2 && num3 > -0.1f && num3 < 0.15f) ? num3 : 0f);
		FootSample ls = SampleFoot(position, num, num2);
		FootSample rs = SampleFoot(position2, num, num2);
		if (!flag2)
		{
			ls.delta = (rs.delta = 0f);
			ls.tilt = (rs.tilt = Quaternion.identity);
		}
		float num5 = ((ls.delta >= 0f) ? ls.delta : (ls.delta * ls.plant)) * weight;
		float num6 = ((rs.delta >= 0f) ? rs.delta : (rs.delta * rs.plant)) * weight;
		float num7 = 1f - Mathf.Exp((0f - footSmoothSpeed) * Time.deltaTime);
		float num8 = 1f - Mathf.Exp((0f - hipSmoothSpeed) * Time.deltaTime);
		lDelta = Mathf.Lerp(lDelta, num5, num7);
		rDelta = Mathf.Lerp(rDelta, num6, num7);
		lTilt = Quaternion.Slerp(lTilt, Quaternion.Slerp(Quaternion.identity, ls.tilt, ls.plant * weight), num7);
		rTilt = Quaternion.Slerp(rTilt, Quaternion.Slerp(Quaternion.identity, rs.tilt, rs.plant * weight), num7);
		hover = Mathf.Lerp(hover, num4 * weight, num8);
		float num9 = Mathf.Clamp(Mathf.Min(0f, Mathf.Min(lDelta, rDelta)), 0f - maxHipDrop, 0f);
		hipOffset = Mathf.Lerp(hipOffset, num9, num8);
		if (debugMarkers)
		{
			UpdateMarkers(transform.position, num, ls, rs, position + Vector3.up * (lDelta - hover), position2 + Vector3.up * (rDelta - hover));
		}
		if (debugLog)
		{
			logTimer -= Time.deltaTime;
			if (logTimer <= 0f)
			{
				logTimer = 2f;
				string text = (flag2 ? (((Object)((RaycastHit)(ref val)).collider).name + "[" + LayerMask.LayerToName(((Component)((RaycastHit)(ref val)).collider).gameObject.layer) + "]") : "");
			}
		}
		if (!(Mathf.Abs(lDelta) < 0.0005f) || !(Mathf.Abs(rDelta) < 0.0005f) || !(Mathf.Abs(hipOffset) < 0.0005f) || !(Mathf.Abs(hover) < 0.0005f))
		{
			Transform obj = hips;
			obj.position += Vector3.up * (hipOffset - hover);
			SolveLeg(lUpper, lLower, lFoot, position + Vector3.up * (lDelta - hover), rotation, lTilt);
			SolveLeg(rUpper, rLower, rFoot, position2 + Vector3.up * (rDelta - hover), rotation2, rTilt);
		}
	}

	private FootSample SampleFoot(Vector3 animFootPos, float planeY, float groundRootY)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		FootSample result = new FootSample
		{
			tilt = Quaternion.identity,
			hitInfo = ""
		};
		float num = animFootPos.y - planeY;
		result.plant = 1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(plantStart, plantEnd, num));
		float num2 = maxStepUp + 0.25f;
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(animFootPos.x, groundRootY + num2, animFootPos.z);
		float num3 = num2 + maxStepDown + 0.2f;
		RaycastHit val2 = default(RaycastHit);
		if (Physics.Raycast(val, Vector3.down, ref val2, num3, LayerMask.op_Implicit(groundMask), (QueryTriggerInteraction)1))
		{
			result.hit = true;
			result.hitPoint = ((RaycastHit)(ref val2)).point;
			result.hitInfo = $"{((Object)((RaycastHit)(ref val2)).collider).name}[{LayerMask.LayerToName(((Component)((RaycastHit)(ref val2)).collider).gameObject.layer)}] y={((RaycastHit)(ref val2)).point.y:F2}";
			float num4 = ((RaycastHit)(ref val2)).point.y - groundRootY;
			if (num4 >= 0f - maxStepDown && num4 <= maxStepUp)
			{
				result.delta = num4;
				Quaternion val3 = Quaternion.FromToRotation(Vector3.up, ((RaycastHit)(ref val2)).normal);
				result.tilt = Quaternion.RotateTowards(Quaternion.identity, val3, maxFootTilt);
			}
			else
			{
				ref string hitInfo = ref result.hitInfo;
				hitInfo = hitInfo ?? "";
			}
		}
		return result;
	}

	private void SolveLeg(Transform upper, Transform lower, Transform foot, Vector3 targetPos, Quaternion animFootRot, Quaternion tilt)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = upper.position;
		Vector3 position2 = lower.position;
		Vector3 position3 = foot.position;
		Vector3 val = position2 - position;
		float magnitude = ((Vector3)(ref val)).magnitude;
		val = position3 - position2;
		float magnitude2 = ((Vector3)(ref val)).magnitude;
		if (magnitude < 0.0001f || magnitude2 < 0.0001f)
		{
			return;
		}
		Vector3 val2 = targetPos - position;
		float magnitude3 = ((Vector3)(ref val2)).magnitude;
		if (!(magnitude3 < 0.0001f))
		{
			float num = (magnitude + magnitude2) * 0.999f;
			float num2 = Mathf.Abs(magnitude - magnitude2) * 1.001f + 0.001f;
			float num3 = Mathf.Clamp(magnitude3, num2, num);
			Vector3 val3 = val2 / magnitude3;
			Vector3 val4 = position + val3 * num3;
			val = position3 - position;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3 val5 = position2 - position - normalized * Vector3.Dot(position2 - position, normalized);
			Vector3 val6 = ((((Vector3)(ref val5)).sqrMagnitude > 1E-06f) ? ((Vector3)(ref val5)).normalized : bodyT.forward);
			Vector3 val7 = val6 - val3 * Vector3.Dot(val6, val3);
			if (((Vector3)(ref val7)).sqrMagnitude < 1E-06f)
			{
				val7 = Vector3.Cross(val3, bodyT.right);
			}
			val6 = ((Vector3)(ref val7)).normalized;
			float num4 = Mathf.Clamp((magnitude * magnitude + num3 * num3 - magnitude2 * magnitude2) / (2f * magnitude * num3), -1f, 1f);
			float num5 = Mathf.Sqrt(1f - num4 * num4);
			Vector3 val8 = position + val3 * (magnitude * num4) + val6 * (magnitude * num5);
			upper.rotation = Quaternion.FromToRotation(position2 - position, val8 - position) * upper.rotation;
			Vector3 position4 = lower.position;
			lower.rotation = Quaternion.FromToRotation(foot.position - position4, val4 - position4) * lower.rotation;
			foot.rotation = tilt * animFootRot;
		}
	}

	private Transform CreateMarker(Color color, float size)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
		Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>());
		val.transform.localScale = Vector3.one * size;
		Renderer component = val.GetComponent<Renderer>();
		component.shadowCastingMode = (ShadowCastingMode)0;
		component.receiveShadows = false;
		Material val2 = (((Object)(object)controller.thisPlayerModel != (Object)null) ? ((Renderer)controller.thisPlayerModel).sharedMaterial : component.sharedMaterial);
		Material val3 = new Material(val2);
		if (val3.HasProperty("_BaseColorMap"))
		{
			val3.SetTexture("_BaseColorMap", (Texture)null);
		}
		if (val3.HasProperty("_BaseColor"))
		{
			val3.SetColor("_BaseColor", color);
		}
		else if (val3.HasProperty("_Color"))
		{
			val3.SetColor("_Color", color);
		}
		component.material = val3;
		return val.transform;
	}

	private void UpdateMarkers(Vector3 rootPos, float planeY, FootSample ls, FootSample rs, Vector3 lTarget, Vector3 rTarget)
	{
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)mPlane == (Object)null)
		{
			mPlane = CreateMarker(Color.white, 0.1f);
			mLHit = CreateMarker(new Color(0.1f, 0.3f, 1f), 0.07f);
			mLTarget = CreateMarker(Color.cyan, 0.09f);
			mRHit = CreateMarker(new Color(1f, 0.1f, 0.1f), 0.07f);
			mRTarget = CreateMarker(new Color(1f, 0.6f, 0f), 0.09f);
		}
		((Component)mPlane).gameObject.SetActive(true);
		mPlane.position = new Vector3(rootPos.x, planeY, rootPos.z);
		((Component)mLHit).gameObject.SetActive(ls.hit);
		mLHit.position = ls.hitPoint;
		((Component)mRHit).gameObject.SetActive(rs.hit);
		mRHit.position = rs.hitPoint;
		((Component)mLTarget).gameObject.SetActive(true);
		mLTarget.position = lTarget;
		((Component)mRTarget).gameObject.SetActive(true);
		mRTarget.position = rTarget;
	}

	private void HideMarkers()
	{
		if ((Object)(object)mPlane != (Object)null)
		{
			((Component)mPlane).gameObject.SetActive(false);
		}
		if ((Object)(object)mLHit != (Object)null)
		{
			((Component)mLHit).gameObject.SetActive(false);
		}
		if ((Object)(object)mLTarget != (Object)null)
		{
			((Component)mLTarget).gameObject.SetActive(false);
		}
		if ((Object)(object)mRHit != (Object)null)
		{
			((Component)mRHit).gameObject.SetActive(false);
		}
		if ((Object)(object)mRTarget != (Object)null)
		{
			((Component)mRTarget).gameObject.SetActive(false);
		}
	}

	private void DestroyMarkers()
	{
		if ((Object)(object)mPlane != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)mPlane).gameObject);
		}
		if ((Object)(object)mLHit != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)mLHit).gameObject);
		}
		if ((Object)(object)mLTarget != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)mLTarget).gameObject);
		}
		if ((Object)(object)mRHit != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)mRHit).gameObject);
		}
		if ((Object)(object)mRTarget != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)mRTarget).gameObject);
		}
	}
}