Decompiled source of MissingAnimations v1.0.1

plugins\MissingAnimations.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using MagicaCloth2;
using Microsoft.CodeAnalysis;
using MissingAnimations.Data.Dive;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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;
		}
	}
}
namespace MissingAnimations
{
	[BepInPlugin("com.razaotium.missinganimations", "Missing Animations", "1.0.1")]
	[BepInProcess("valheim.exe")]
	public sealed class MissingAnimationsPlugin : BaseUnityPlugin
	{
		private Harmony harmony;

		private bool ready;

		private ConfigEntry<bool> Bind(string section, string name, bool value, string description)
		{
			return ((BaseUnityPlugin)this).Config.Bind<bool>(section, name, value, description);
		}

		private void Awake()
		{
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Expected O, but got Unknown
			MotionSettings.All = Bind("General", "AllAnimations", value: true, "Turns all of this mod's animations on or off for your character. Off: your character behaves like the normal game, but you still see the animations of other players who have the mod.");
			MotionSettings.Chairs = Bind("Seats", "Chairs", value: true, "Sit down on and stand up from chairs, stools, benches, logs and the bear rug.");
			MotionSettings.Thrones = Bind("Seats", "Thrones", value: true, "Sit down on and stand up from thrones.");
			MotionSettings.ShipBenches = Bind("Seats", "ShipBenches", value: true, "Sit down on and stand up from the benches of the raft, karve and longships.");
			MotionSettings.Bathtub = Bind("Seats", "Bathtub", value: true, "Vault into and out of the bathtub.");
			MotionSettings.BathUndress = Bind("Seats", "BathtubUndress", value: true, "Look undressed while in the bathtub (nothing is unequipped).");
			MotionSettings.Divan = Bind("Seats", "Divan", value: true, "Throw yourself onto Hildir's divan and get up from it.");
			MotionSettings.BedEnabled = Bind("Beds", "Beds", value: true, "Lie down on beds and get up from them.");
			MotionSettings.ClimbEnabled = Bind("Mounts", "Climb", value: true, "Climb into the saddle of the lox, askvin and moose.");
			MotionSettings.DismountEnabled = Bind("Mounts", "Dismount", value: true, "Climb down from the lox, askvin and moose.");
			MotionSettings.HandsOnReins = Bind("Mounts", "HandsOnReins", value: true, "Hold the saddle reins while riding.");
			MotionSettings.DiveEnabled = Bind("Water", "Dive", value: true, "Dive headfirst when a jump will land in deep water.");
			MotionSettings.HelmEnabled = Bind("Ships", "Helm", value: true, "Sit down at the helm, hold the tiller and stand up from it.");
			MotionSettings.ShipBoardingEnabled = Bind("Ships", "BoardingFromWater", value: false, "Experimental: climb the ladder when boarding a ship from the water.");
			MotionSettings.CartEnabled = Bind("Carts", "Harness", value: true, "Wear a harness while pulling a cart, catapult or battering ram.");
			MotionSettings.CartTie = Bind("Carts", "TieKnot", value: true, "Tie the traces to the belt when hitching.");
			harmony = new Harmony("com.razaotium.missinganimations");
			try
			{
				MotionModule.Init(harmony);
				ready = true;
			}
			catch (Exception ex)
			{
				harmony.UnpatchSelf();
				((BaseUnityPlugin)this).Logger.LogError((object)("Missing Animations disabled for this session; vanilla fallback. " + ex.GetType().Name + ": " + ex.Message));
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Missing Animations 1.0.1: animations=" + ready));
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			if (ready)
			{
				MotionModule.Shutdown();
			}
		}
	}
	internal static class AnimFiles
	{
		internal static Stream Open(string name)
		{
			return typeof(AnimFiles).Assembly.GetManifestResourceStream(name);
		}
	}
	internal static class BathUndress
	{
		internal static readonly int KBath = StringExtensionMethods.GetStableHashCode("razaotium.missinganimations.bath");

		private static readonly FieldRef<VisEquipment, Player> fPlayer = AccessTools.FieldRefAccess<VisEquipment, Player>("m_playerComponent");

		private static bool IsTub(Transform ap)
		{
			Chair val = SeatClips.ChairFor(ap);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			Piece componentInParent = ((Component)val).GetComponentInParent<Piece>();
			return (Object.op_Implicit((Object)(object)componentInParent) ? ((Object)((Component)componentInParent).gameObject).name : ((Object)((Component)val).transform.root).name).ToLowerInvariant().Contains("bathtub");
		}

		internal static bool InBath(VisEquipment v)
		{
			try
			{
				Player val = (Object.op_Implicit((Object)(object)v) ? fPlayer.Invoke(v) : null);
				if (!Object.op_Implicit((Object)(object)val) || !MotionSettings.BathUndress.Value)
				{
					return false;
				}
				if (Net.IsLocal(val))
				{
					if (!MotionSettings.Mine(MotionSettings.BathUndress))
					{
						ZDO val2 = Net.Own(val);
						if (val2 != null && val2.GetBool(KBath, false))
						{
							val2.Set(KBath, false);
						}
						return false;
					}
					Sitter component = ((Component)val).GetComponent<Sitter>();
					bool flag = (((Character)val).IsAttached() && IsTub(val.GetAttachPoint())) || (Object.op_Implicit((Object)(object)component) && component.LeavingBath);
					ZDO val3 = Net.Own(val);
					if (val3 != null && val3.GetBool(KBath, false) != flag)
					{
						val3.Set(KBath, flag);
					}
					return flag;
				}
				ZDO val4 = Net.Zdo(val);
				return val4 != null && val4.GetBool(KBath, false);
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[MissingAnimations] Bath undress check failed: " + ex.Message));
				return false;
			}
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "SetChestEquipped")]
	internal static class BathChestPatch
	{
		private static void Prefix(VisEquipment __instance, ref int __0)
		{
			if (__0 != 0 && BathUndress.InBath(__instance))
			{
				__0 = 0;
			}
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "SetLegEquipped")]
	internal static class BathLegPatch
	{
		private static void Prefix(VisEquipment __instance, ref int __0)
		{
			if (__0 != 0 && BathUndress.InBath(__instance))
			{
				__0 = 0;
			}
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "SetHelmetEquipped")]
	internal static class BathHelmetPatch
	{
		private static void Prefix(VisEquipment __instance, ref int __0)
		{
			if (__0 != 0 && BathUndress.InBath(__instance))
			{
				__0 = 0;
			}
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "SetShoulderEquipped")]
	internal static class BathShoulderPatch
	{
		private static void Prefix(VisEquipment __instance, ref int __0)
		{
			if (__0 != 0 && BathUndress.InBath(__instance))
			{
				__0 = 0;
			}
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "SetUtilityEquipped")]
	internal static class BathUtilityPatch
	{
		private static void Prefix(VisEquipment __instance, ref int __0)
		{
			if (__0 != 0 && BathUndress.InBath(__instance))
			{
				__0 = 0;
			}
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "SetTrinketEquipped")]
	internal static class BathTrinketPatch
	{
		private static void Prefix(VisEquipment __instance, ref int __0)
		{
			if (__0 != 0 && BathUndress.InBath(__instance))
			{
				__0 = 0;
			}
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "SetBackEquipped")]
	internal static class BathBackPatch
	{
		private static void Prefix(VisEquipment __instance, ref int __0, ref int __1)
		{
			if ((__0 != 0 || __1 != 0) && BathUndress.InBath(__instance))
			{
				__0 = 0;
				__1 = 0;
			}
		}
	}
	internal static class BedClips
	{
		internal struct Hit
		{
			public float time;

			public Vector3 pos;
		}

		internal const float AlertRadius = 12f;

		internal const float AlertMemory = 6f;

		private static readonly List<Hit> attacks = new List<Hit>();

		internal static string ForBed(Bed b)
		{
			if (!Object.op_Implicit((Object)(object)b))
			{
				return null;
			}
			Piece componentInParent = ((Component)b).GetComponentInParent<Piece>();
			string text = (Object.op_Implicit((Object)(object)componentInParent) ? ((Object)((Component)componentInParent).gameObject).name : ((Object)((Component)b).transform.root).name).ToLowerInvariant();
			if (text.StartsWith("piece_bed02"))
			{
				return "piece_bed02";
			}
			if (text.StartsWith("ashwood_bed"))
			{
				return "ashwood_bed";
			}
			if (text.StartsWith("bed"))
			{
				return "bed";
			}
			return null;
		}

		internal static Bed BedFor(Transform attach)
		{
			if (!Object.op_Implicit((Object)(object)attach))
			{
				return null;
			}
			Bed[] componentsInParent = ((Component)attach).GetComponentsInParent<Bed>(true);
			foreach (Bed val in componentsInParent)
			{
				if (Object.op_Implicit((Object)(object)val) && (Object)(object)val.m_spawnPoint == (Object)(object)attach)
				{
					return val;
				}
			}
			return null;
		}

		internal static void NoteAttack(Vector3 pos)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			float now = Time.time;
			attacks.RemoveAll((Hit a) => now - a.time > 6f);
			if (attacks.Count < 64)
			{
				attacks.Add(new Hit
				{
					time = now,
					pos = pos
				});
			}
		}

		internal static bool Alert(Player p)
		{
			//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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)p))
			{
				return false;
			}
			Vector3 position = ((Component)p).transform.position;
			float time = Time.time;
			float num = 144f;
			Vector3 val;
			foreach (Hit attack in attacks)
			{
				if (time - attack.time <= 6f)
				{
					val = attack.pos - position;
					if (((Vector3)(ref val)).sqrMagnitude <= num)
					{
						return true;
					}
				}
			}
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (!Object.op_Implicit((Object)(object)allCharacter) || allCharacter.IsPlayer() || allCharacter.IsTamed() || allCharacter.IsDead())
				{
					continue;
				}
				val = ((Component)allCharacter).transform.position - position;
				if (!(((Vector3)(ref val)).sqrMagnitude > num))
				{
					BaseAI baseAI = allCharacter.GetBaseAI();
					if (Object.op_Implicit((Object)(object)baseAI) && BaseAI.IsEnemy(allCharacter, (Character)(object)p) && baseAI.IsAlerted())
					{
						return true;
					}
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Humanoid), "StartAttack")]
	internal static class BedAttackWatchPatch
	{
		private static void Postfix(Humanoid __instance, Character target, bool __result)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (__result && Object.op_Implicit((Object)(object)__instance) && !((Character)__instance).IsPlayer() && !((Character)__instance).IsTamed())
				{
					Player localPlayer = Player.m_localPlayer;
					if (Object.op_Implicit((Object)(object)localPlayer) && (((Character)localPlayer).InBed() || ((Character)localPlayer).IsAttached()) && BaseAI.IsEnemy((Character)(object)__instance, (Character)(object)localPlayer))
					{
						BedClips.NoteAttack(((Component)__instance).transform.position);
					}
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(Bed), "Interact")]
	internal static class BedLiePatch
	{
		private static Quaternion preRot;

		private static bool Prefix(Bed __instance, Humanoid human, bool repeat, out Vector3 __state)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_004e: 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_00b5: 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)
			Player localPlayer = Player.m_localPlayer;
			bool flag = Object.op_Implicit((Object)(object)localPlayer) && !((Character)localPlayer).IsAttached() && (Object)(object)human == (Object)(object)localPlayer;
			__state = (Vector3)(flag ? ((Component)localPlayer).transform.position : new Vector3(float.NaN, 0f, 0f));
			preRot = (flag ? ((Component)localPlayer).transform.rotation : Quaternion.identity);
			try
			{
				if (flag && !repeat && !Sleeper.Bypass && MotionSettings.Mine(MotionSettings.BedEnabled) && BedClips.ForBed(__instance) != null)
				{
					Sleeper component = ((Component)localPlayer).GetComponent<Sleeper>();
					if (Object.op_Implicit((Object)(object)component) && component.NeedsApproach(__instance))
					{
						component.Approach(__instance);
						__state = new Vector3(float.NaN, 0f, 0f);
						return false;
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[MissingAnimations] Bed approach failed: " + ex));
			}
			return true;
		}

		private static void Postfix(Bed __instance, Vector3 __state)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Player localPlayer = Player.m_localPlayer;
				if (Object.op_Implicit((Object)(object)localPlayer) && !float.IsNaN(__state.x) && MotionSettings.Mine(MotionSettings.BedEnabled) && ((Character)localPlayer).IsAttached() && Object.op_Implicit((Object)(object)__instance.m_spawnPoint) && !((Object)(object)localPlayer.GetAttachPoint() != (Object)(object)__instance.m_spawnPoint))
				{
					Sleeper component = ((Component)localPlayer).GetComponent<Sleeper>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.Lie(__instance, __state, preRot);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[MissingAnimations] Bed animation failed, using the game's: " + ex));
			}
		}
	}
	[HarmonyPatch(typeof(Player), "AttachStop")]
	internal static class BedRisePatch
	{
		private static void Prefix(Player __instance, out Transform __state)
		{
			__state = null;
			try
			{
				if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && ((Character)__instance).IsAttached() && MotionSettings.Mine(MotionSettings.BedEnabled))
				{
					Transform attachPoint = __instance.GetAttachPoint();
					if (BedClips.ForBed(BedClips.BedFor(attachPoint)) != null)
					{
						__state = attachPoint;
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[MissingAnimations] Bed get-up check failed: " + ex));
				__state = null;
			}
		}

		private static void Postfix(Player __instance, Transform __state)
		{
			try
			{
				if (Object.op_Implicit((Object)(object)__state) && !((Character)__instance).IsAttached())
				{
					Sleeper component = ((Component)__instance).GetComponent<Sleeper>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.Rise(__state);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[MissingAnimations] Bed get-up animation failed: " + ex));
			}
		}
	}
	[HarmonyPatch(typeof(Player), "SetControls")]
	internal static class BedApproachControlsPatch
	{
		private static void Postfix(Player __instance, Vector3 movedir, bool attack, bool secondaryAttack, bool block, bool jump, bool crouch, bool dodge)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			Sleeper component = ((Component)__instance).GetComponent<Sleeper>();
			if (Object.op_Implicit((Object)(object)component) && component.Approaching)
			{
				if (((Vector3)(ref movedir)).sqrMagnitude > 0.01f || attack || secondaryAttack || block || jump || crouch || dodge)
				{
					component.CancelApproach();
				}
				else
				{
					((Character)__instance).SetMoveDir(component.ApproachDir());
				}
			}
		}
	}
	internal sealed class Sleeper : MonoBehaviour, IPreCloth
	{
		internal static bool Bypass;

		private static readonly MethodInfo mIsMine = AccessTools.Method(typeof(Bed), "IsMine", (Type[])null, (Type[])null);

		private Bed approachBed;

		private readonly List<Vector3> path = new List<Vector3>();

		private int wp;

		private float approachT;

		private float bestDist;

		private float bestT;

		private Vector3 moveDir;

		private const float BlendOut = 0.3f;

		private const float MaxStart = 6f;

		private const float StartYaw = -90f;

		private static readonly int Floor = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle" });

		private static readonly FieldRef<Character, Rigidbody> fBody = AccessTools.FieldRefAccess<Character, Rigidbody>("m_body");

		private static readonly FieldRef<Character, float> fMaxAir = AccessTools.FieldRefAccess<Character, float>("m_maxAirAltitude");

		private Player player;

		private Body body;

		private Transform attach;

		private MountClip clip;

		private Transform[] bones;

		private PoseBase clipBase;

		private Quaternion[] snapshot;

		private Quaternion snapshotHips;

		private int hipsIndex = -1;

		private bool capeHold;

		private float t = -1f;

		private bool lying;

		private float side = -1f;

		private Vector3 p0;

		private Vector3 offset;

		private Vector3 pivot;

		private Vector3 endLocal;

		private float dyaw;

		private float fade;

		private float lift;

		internal bool Approaching => Object.op_Implicit((Object)(object)approachBed);

		internal bool Playing => t >= 0f;

		private float Duration => clip.End + 0.3f;

		public Body ClothBody => body;

		internal Vector3 ApproachDir()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return moveDir;
		}

		private static Vector3 L(Transform ap, Vector3 w)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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)
			return Quaternion.Inverse(ap.rotation) * (w - ap.position);
		}

		private static Vector3 Wd(Transform ap, Vector3 l)
		{
			//IL_0001: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return ap.position + ap.rotation * l;
		}

		private static void BedBox(Bed b, out Vector2 min, out Vector2 max)
		{
			//IL_001f: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_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_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			Transform spawnPoint = b.m_spawnPoint;
			Transform root = ((Component)b).transform.root;
			bool flag = false;
			min = new Vector2(-0.7f, -1.2f);
			max = new Vector2(0.7f, 1.2f);
			Collider[] componentsInChildren = ((Component)root).GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val) || val.isTrigger || !val.enabled)
				{
					continue;
				}
				Bounds bounds = val.bounds;
				for (int j = 0; j < 4; j++)
				{
					Vector3 val2 = L(spawnPoint, new Vector3(((j & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((Bounds)(ref bounds)).center.y, ((j & 2) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z));
					if (!flag)
					{
						min = (max = new Vector2(val2.x, val2.z));
						flag = true;
					}
					min = Vector2.Min(min, new Vector2(val2.x, val2.z));
					max = Vector2.Max(max, new Vector2(val2.x, val2.z));
				}
			}
		}

		private bool Free(Vector3 feet, Transform own)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//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_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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapCapsule(feet + Vector3.up * 0.5f, feet + Vector3.up * 1.6f, 0.28f, Floor, (QueryTriggerInteraction)1);
			foreach (Collider val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && (!Object.op_Implicit((Object)(object)own) || !((Component)val).transform.IsChildOf(own)) && !((Component)val).transform.IsChildOf(((Component)this).transform))
				{
					return false;
				}
			}
			return true;
		}

		private bool RouteFree(List<Vector3> r, Transform own)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 1; i < r.Count; i++)
			{
				float num = Vector3.Distance(r[i - 1], r[i]);
				int num2 = Mathf.Max(1, Mathf.CeilToInt(num / 0.25f));
				for (int j = 1; j <= num2; j++)
				{
					if (!Free(Vector3.Lerp(r[i - 1], r[i], (float)j / (float)num2), own))
					{
						return false;
					}
				}
			}
			return true;
		}

		private bool StartOf(Bed b, string kind, float sd, out Vector3 w)
		{
			//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_002a: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			w = Vector3.zero;
			MountClip mountClip = MountClip.For(sd, "BedLie_" + kind);
			if (mountClip == null)
			{
				return false;
			}
			Vector3 val = mountClip.Hips[0];
			Transform spawnPoint = b.m_spawnPoint;
			w = Wd(spawnPoint, new Vector3(val.x, mountClip.Ground, val.z));
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(w + Vector3.up * 0.5f, Vector3.down, ref val2, 1.2f, Floor, (QueryTriggerInteraction)1))
			{
				w.y = ((RaycastHit)(ref val2)).point.y;
			}
			return true;
		}

		private bool WillSleep(Bed b)
		{
			if (!Object.op_Implicit((Object)(object)b) || !Object.op_Implicit((Object)(object)b.m_spawnPoint) || ((Character)player).IsEncumbered())
			{
				return false;
			}
			if (mIsMine != null && (bool)mIsMine.Invoke(b, null) && b.IsCurrent())
			{
				return EnvMan.CanSleep();
			}
			return false;
		}

		internal bool NeedsApproach(Bed b)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			if (Playing || Approaching || !WillSleep(b))
			{
				return false;
			}
			string kind = BedClips.ForBed(b);
			float num = ((L(b.m_spawnPoint, ((Component)this).transform.position).x >= 0f) ? (-1f) : 1f);
			float[] array = new float[2]
			{
				num,
				0f - num
			};
			foreach (float sd in array)
			{
				if (StartOf(b, kind, sd, out var w) && Free(w, ((Component)b).transform.root))
				{
					Vector3 val = w - ((Component)this).transform.position;
					val.y = 0f;
					return ((Vector3)(ref val)).magnitude > 0.35f;
				}
			}
			return false;
		}

		internal void Approach(Bed b)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_01c0: 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_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_015b: Unknown result type (might be due to invalid IL or missing references)
			string kind = BedClips.ForBed(b);
			Transform spawnPoint = b.m_spawnPoint;
			Transform root = ((Component)b).transform.root;
			Vector3 position = ((Component)this).transform.position;
			Vector3 val = L(spawnPoint, position);
			BedBox(b, out var min, out var max);
			float num = ((val.x >= 0f) ? (-1f) : 1f);
			List<Vector3> list = null;
			float[] array = new float[2]
			{
				num,
				0f - num
			};
			foreach (float num2 in array)
			{
				if (!StartOf(b, kind, num2, out var w) || !Free(w, root))
				{
					continue;
				}
				List<Vector3> list2 = new List<Vector3>();
				if ((Object)(object)Pathfinding.instance != (Object)null && Pathfinding.instance.GetPath(position, w, list2, (AgentType)1, false, true, false) && list2.Count >= 2)
				{
					bool flag = false;
					for (int j = 1; j < list2.Count; j++)
					{
						if (flag)
						{
							break;
						}
						for (int k = 0; k <= 10; k++)
						{
							Vector3 val2 = L(spawnPoint, Vector3.Lerp(list2[j - 1], list2[j], (float)k / 10f));
							if (val2.x > min.x - 0.2f && val2.x < max.x + 0.2f && val2.z > min.y - 0.2f && val2.z < max.y + 0.2f)
							{
								flag = true;
								break;
							}
						}
					}
					if (!flag)
					{
						list2.Add(w);
						if (RouteFree(list2, root))
						{
							list = list2;
							break;
						}
					}
				}
				float num3 = ((num2 < 0f) ? (max.x + 0.55f) : (min.x - 0.55f));
				float num4 = ((val.z >= 0f) ? (max.y + 0.55f) : (min.y - 0.55f));
				List<Vector3> list3 = new List<Vector3> { position };
				if (!((num2 < 0f) ? (val.x > max.x) : (val.x < min.x)))
				{
					if (val.z < max.y + 0.3f && val.z > min.y - 0.3f)
					{
						list3.Add(Wd(spawnPoint, new Vector3(val.x, 0f, num4)));
					}
					list3.Add(Wd(spawnPoint, new Vector3(num3, 0f, num4)));
				}
				list3.Add(w);
				for (int l = 0; l < list3.Count; l++)
				{
					Vector3 value = list3[l];
					value.y = position.y;
					list3[l] = value;
				}
				if (RouteFree(list3, root))
				{
					list = list3;
					break;
				}
			}
			if (list == null)
			{
				Bypass = true;
				try
				{
					b.Interact((Humanoid)(object)player, false, false);
					return;
				}
				finally
				{
					Bypass = false;
				}
			}
			path.Clear();
			path.AddRange(list);
			wp = 1;
			approachBed = b;
			approachT = 0f;
			bestDist = float.MaxValue;
			bestT = 0f;
		}

		internal void CancelApproach()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)approachBed))
			{
				approachBed = null;
				moveDir = Vector3.zero;
				((Character)player).SetMoveDir(Vector3.zero);
			}
		}

		private void Steer(float dt)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			Bed val = approachBed;
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.m_spawnPoint) || ((Character)player).IsDead() || ((Character)player).IsAttached())
			{
				CancelApproach();
				return;
			}
			approachT += dt;
			Vector3 position = ((Component)this).transform.position;
			Vector3 val2 = path[path.Count - 1];
			Vector2 val3 = new Vector2(val2.x - position.x, val2.z - position.z);
			float magnitude = ((Vector2)(ref val3)).magnitude;
			if (magnitude < bestDist - 0.05f)
			{
				bestDist = magnitude;
				bestT = approachT;
			}
			if (magnitude < 0.15f || approachT > 6f || approachT - bestT > 0.5f)
			{
				approachBed = null;
				moveDir = Vector3.zero;
				((Character)player).SetMoveDir(Vector3.zero);
				Bypass = true;
				try
				{
					val.Interact((Humanoid)(object)player, false, false);
					return;
				}
				finally
				{
					Bypass = false;
				}
			}
			while (wp < path.Count - 1)
			{
				val3 = new Vector2(path[wp].x - position.x, path[wp].z - position.z);
				if (!(((Vector2)(ref val3)).magnitude < 0.3f))
				{
					break;
				}
				wp++;
			}
			Vector3 val4 = path[wp] - position;
			val4.y = 0f;
			moveDir = ((((Vector3)(ref val4)).sqrMagnitude > 1E-06f) ? ((Vector3)(ref val4)).normalized : Vector3.zero);
			if (wp == path.Count - 1 && magnitude < 0.5f)
			{
				moveDir *= Mathf.Clamp(magnitude / 0.5f, 0.5f, 1f);
			}
		}

		private void Awake()
		{
			player = ((Component)this).GetComponent<Player>();
			body = new Body(player);
		}

		private bool Load(string name, Transform ap, float s)
		{
			clip = MountClip.For(s, name);
			if (clip == null && s > 0f)
			{
				s = -1f;
				clip = MountClip.For(s, name);
			}
			side = s;
			bones = ((clip != null && body.Ready && Object.op_Implicit((Object)(object)body.hips)) ? clip.Bind(body.hips) : null);
			clipBase = ((bones != null) ? new PoseBase(bones) : null);
			if (bones == null || !body.Claim(this))
			{
				clip = null;
				return false;
			}
			attach = ap;
			return true;
		}

		private void Snapshot(Quaternion priorRot)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			snapshot = (Quaternion[])(object)new Quaternion[bones.Length];
			hipsIndex = -1;
			for (int i = 0; i < bones.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)bones[i]))
				{
					snapshot[i] = bones[i].localRotation;
					if ((Object)(object)bones[i] == (Object)(object)body.hips)
					{
						hipsIndex = i;
						snapshotHips = priorRot * Quaternion.Inverse(((Component)this).transform.rotation) * bones[i].rotation;
					}
				}
			}
		}

		internal void Lie(Bed bed, Vector3 pre, Quaternion preRot)
		{
			//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_0033: 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)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_0114: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			if (Playing)
			{
				Finish();
			}
			string text = BedClips.ForBed(bed);
			Transform spawnPoint = bed.m_spawnPoint;
			if (text != null && Object.op_Implicit((Object)(object)spawnPoint))
			{
				Quaternion val = Quaternion.Inverse(spawnPoint.rotation);
				p0 = val * (pre - spawnPoint.position);
				Vector2 val2 = new Vector2(p0.x, p0.z);
				if (!(((Vector2)(ref val2)).magnitude > 6f) && Load("BedLie_" + text, spawnPoint, (p0.x >= 0f) ? (-1f) : 1f))
				{
					Vector3 val3 = clip.Hips[0];
					pivot = new Vector3(val3.x, 0f, val3.z);
					offset = new Vector3(p0.x - val3.x, 0f, p0.z - val3.z);
					Vector3 val4 = val * (preRot * Vector3.forward);
					dyaw = Mathf.DeltaAngle(-90f * (0f - side), Mathf.Atan2(val4.x, val4.z) * 57.29578f);
					fade = Mathf.Clamp(0.35f + 0.4f * ((Vector3)(ref offset)).magnitude + Mathf.Abs(dyaw) / 600f, 0.35f, 0.9f);
					lying = true;
					t = 0f;
					Snapshot(preRot);
					Pose();
				}
			}
		}

		internal void Rise(Transform ap)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_0137: 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_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_0168: 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_0172: Unknown result type (might be due to invalid IL or missing references)
			if (Playing)
			{
				Finish();
			}
			Bed val = BedClips.BedFor(ap);
			string text = BedClips.ForBed(val);
			if (text == null || !Object.op_Implicit((Object)(object)ap))
			{
				return;
			}
			float num = -1f;
			GameCamera instance = GameCamera.instance;
			if (Object.op_Implicit((Object)(object)instance))
			{
				num = (((Quaternion.Inverse(ap.rotation) * (((Component)instance).transform.position - ap.position)).x >= 0f) ? (-1f) : 1f);
			}
			string name = ((BedClips.Alert(player) && MountClip.For(-1f, "BedJump_" + text) != null) ? "BedJump_" : "BedRise_") + text;
			if (!SideFree(ap, val, name, num) && SideFree(ap, val, name, 0f - num))
			{
				num = 0f - num;
			}
			if (Load(name, ap, num))
			{
				Vector3 val2 = clip.Hips[clip.Hips.Length - 1];
				float num2 = clip.Ground;
				RaycastHit val3 = default(RaycastHit);
				if (Physics.Raycast(W(new Vector3(val2.x, clip.Ground + 1.2f, val2.z)), -ap.up, ref val3, 2f, Floor, (QueryTriggerInteraction)1))
				{
					num2 = Mathf.Clamp((Quaternion.Inverse(ap.rotation) * (((RaycastHit)(ref val3)).point - ap.position)).y, clip.Ground - 0.3f, clip.Ground + 0.3f);
				}
				lift = num2 - clip.Ground;
				endLocal = new Vector3(val2.x, num2, val2.z);
				lying = false;
				t = 0f;
				Snapshot(((Component)this).transform.rotation);
				Hold();
				Pose();
				capeHold = true;
			}
		}

		private Vector3 W(Vector3 local)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			return attach.position + attach.rotation * local;
		}

		private bool SideFree(Transform ap, Bed bed, string name, float s)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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)
			MountClip mountClip = MountClip.For(s, name);
			if (mountClip == null)
			{
				return false;
			}
			Vector3 val = mountClip.Hips[mountClip.Hips.Length - 1];
			Vector3 val2 = ap.position + ap.rotation * new Vector3(val.x, mountClip.Ground, val.z);
			Transform val3 = (Object.op_Implicit((Object)(object)bed) ? ((Component)bed).transform.root : null);
			Collider[] array = Physics.OverlapCapsule(val2 + Vector3.up * 0.5f, val2 + Vector3.up * 1.6f, 0.28f, Floor, (QueryTriggerInteraction)1);
			foreach (Collider val4 in array)
			{
				if (Object.op_Implicit((Object)(object)val4) && (!Object.op_Implicit((Object)(object)val3) || !((Component)val4).transform.IsChildOf(val3)) && !((Component)val4).transform.IsChildOf(((Component)this).transform))
				{
					return false;
				}
			}
			return true;
		}

		private void Hold()
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0024: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = W(endLocal);
			Vector3 val2 = attach.rotation * (Vector3.right * (0f - side));
			val2.y = 0f;
			((Component)this).transform.position = val;
			if (((Vector3)(ref val2)).sqrMagnitude > 1E-06f)
			{
				((Component)this).transform.rotation = Quaternion.LookRotation(((Vector3)(ref val2)).normalized, Vector3.up);
			}
			Rigidbody val3 = fBody.Invoke((Character)(object)player);
			if (Object.op_Implicit((Object)(object)val3))
			{
				val3.position = val;
				val3.linearVelocity = Vector3.zero;
			}
			fMaxAir.Invoke((Character)(object)player) = val.y;
		}

		private void Update()
		{
			if (Approaching)
			{
				Steer(Time.deltaTime);
			}
			if (!Playing)
			{
				return;
			}
			float deltaTime = Time.deltaTime;
			if (deltaTime > 0f)
			{
				t += deltaTime;
			}
			bool flag = !Object.op_Implicit((Object)(object)attach) || ((Character)player).IsDead() || ((!lying) ? ((Character)player).IsAttached() : (!((Character)player).IsAttached() || (Object)(object)player.GetAttachPoint() != (Object)(object)attach));
			if (t >= Duration || flag)
			{
				Finish();
				return;
			}
			if (!lying)
			{
				Hold();
			}
			if (body.PoseInUpdate)
			{
				Pose();
			}
		}

		private void LateUpdate()
		{
			if (Playing && !body.PoseInUpdate)
			{
				Pose();
			}
		}

		public void PreCloth()
		{
			LateUpdate();
		}

		internal void Stop()
		{
			Finish();
		}

		private void Finish()
		{
			capeHold = false;
			if (Playing)
			{
				t = -1f;
				body.GiveBack();
				body.Unclaim(this);
			}
		}

		private void OnDisable()
		{
			Finish();
		}

		private void Pose()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: 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)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: 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_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: 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_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: 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_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: 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_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			if (!body.Ready || !Object.op_Implicit((Object)(object)attach))
			{
				return;
			}
			Transform visual = body.visual;
			visual.localRotation = Quaternion.identity;
			visual.localPosition = Vector3.zero;
			body.RestoreBase();
			if (clipBase != null)
			{
				clipBase.Restore();
			}
			if (snapshot != null && t < 0.15f)
			{
				for (int i = 0; i < bones.Length; i++)
				{
					if (Object.op_Implicit((Object)(object)bones[i]))
					{
						bones[i].localRotation = snapshot[i];
					}
				}
				if (hipsIndex >= 0)
				{
					bones[hipsIndex].rotation = snapshotHips;
				}
			}
			float num = clip.Frame(t);
			int num2 = (int)num;
			int num3 = Mathf.Min(num2 + 1, clip.Times.Length - 1);
			float num4 = num - (float)num2;
			float num5 = 1f - Body.Smooth(clip.End, clip.End + 0.3f, t);
			float num6 = Body.Smooth(0f, 0.15f, t) * num5;
			Vector3 val = Vector3.Lerp(clip.Hips[num2], clip.Hips[num3], num4);
			Quaternion val2 = Quaternion.identity;
			if (lying)
			{
				float num7 = Body.Smooth(0f, fade, t);
				val2 = Quaternion.AngleAxis(dyaw * (1f - num7), Vector3.up);
				val = pivot + val2 * (val - pivot) + offset * (1f - num7);
				val.y += (p0.y - clip.Ground) * (1f - Body.Smooth(0f, 1.2f, t));
			}
			else
			{
				val.y += lift * Body.Smooth(clip.End * 0.5f, clip.End, t);
			}
			Quaternion val3 = attach.rotation * val2;
			for (int j = 0; j < bones.Length; j++)
			{
				Transform val4 = bones[j];
				if (Object.op_Implicit((Object)(object)val4))
				{
					Quaternion val5 = val3 * Quaternion.Slerp(clip.Rotations[num2, j], clip.Rotations[num3, j], num4);
					val4.rotation = Quaternion.Slerp(val4.rotation, val5, num6);
				}
			}
			if (Object.op_Implicit((Object)(object)body.hips))
			{
				visual.position += (W(val) - body.hips.position) * num5;
			}
			body.RecordWritten();
			if (capeHold)
			{
				capeHold = Cape.Hold((Component)(object)this, body);
			}
			if (clipBase != null)
			{
				clipBase.Record();
			}
		}
	}
	internal sealed class Body
	{
		private static readonly FieldRef<Character, GameObject> fVisual = AccessTools.FieldRefAccess<Character, GameObject>("m_visual");

		private static readonly Dictionary<int, object> owners = new Dictionary<int, object>();

		public readonly Player player;

		public Transform visual;

		public Transform hips;

		public Transform spine;

		public Transform neck;

		public Transform head;

		public Animator anim;

		public readonly Transform[] seg = (Transform[])(object)new Transform[11];

		public readonly Transform[] segChild = (Transform[])(object)new Transform[11];

		public readonly Transform[] finger = (Transform[])(object)new Transform[2];

		public readonly Transform[] indexFinger = (Transform[])(object)new Transform[2];

		public readonly Transform[] pinky = (Transform[])(object)new Transform[2];

		private readonly List<Transform> touched = new List<Transform>();

		private Quaternion[] baseRot;

		private Quaternion[] wroteRot;

		private bool wrote;

		private bool ok;

		private float lastRecord = -1f;

		private const float ElbowMax = 150f;

		private const float KneeMax = 155f;

		private const float WristMax = 75f;

		private const float AnkleMin = 10f;

		private const float AnkleMax = 93f;

		private const float LimbSpeed = 900f;

		private const float SpineSpeed = 350f;

		private const float NeckSpeed = 450f;

		private static readonly FieldRef<Character, Rigidbody> fMountBody = AccessTools.FieldRefAccess<Character, Rigidbody>("m_body");

		public bool Ready
		{
			get
			{
				if (!ok)
				{
					Find();
				}
				if (Object.op_Implicit((Object)(object)visual))
				{
					return touched.Count > 0;
				}
				return false;
			}
		}

		public bool PoseInUpdate
		{
			get
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Invalid comparison between Unknown and I4
				if (Object.op_Implicit((Object)(object)anim))
				{
					return (int)anim.updateMode == 1;
				}
				return true;
			}
		}

		public Body(Player p)
		{
			player = p;
		}

		public bool Claim(object who)
		{
			int instanceID = ((Object)player).GetInstanceID();
			if (owners.TryGetValue(instanceID, out var value) && value != null && value != who)
			{
				return false;
			}
			owners[instanceID] = who;
			return true;
		}

		public void Unclaim(object who)
		{
			int instanceID = ((Object)player).GetInstanceID();
			if (owners.TryGetValue(instanceID, out var value) && value == who)
			{
				owners.Remove(instanceID);
			}
		}

		public static void UnclaimAll()
		{
			owners.Clear();
		}

		internal static void CopyOwners(List<object> into)
		{
			foreach (object value in owners.Values)
			{
				if (value != null)
				{
					into.Add(value);
				}
			}
		}

		private void Find()
		{
			ok = true;
			GameObject val = fVisual.Invoke((Character)(object)player);
			visual = (Object.op_Implicit((Object)(object)val) ? val.transform : null);
			if ((Object)(object)visual == (Object)(object)((Component)player).transform)
			{
				visual = null;
			}
			anim = ((Component)player).GetComponentInChildren<Animator>();
			hips = B((HumanBodyBones)0, "Hips");
			spine = B((HumanBodyBones)7, "Spine");
			neck = B((HumanBodyBones)9, "Neck");
			head = B((HumanBodyBones)10, "Head");
			seg[0] = B((HumanBodyBones)14, "RightArm");
			segChild[0] = B((HumanBodyBones)16, "RightForeArm");
			seg[1] = B((HumanBodyBones)13, "LeftArm");
			segChild[1] = B((HumanBodyBones)15, "LeftForeArm");
			seg[2] = segChild[0];
			segChild[2] = B((HumanBodyBones)18, "RightHand");
			seg[3] = segChild[1];
			segChild[3] = B((HumanBodyBones)17, "LeftHand");
			seg[4] = B((HumanBodyBones)2, "RightUpLeg");
			segChild[4] = B((HumanBodyBones)4, "RightLeg");
			seg[5] = B((HumanBodyBones)1, "LeftUpLeg");
			segChild[5] = B((HumanBodyBones)3, "LeftLeg");
			seg[6] = segChild[4];
			segChild[6] = B((HumanBodyBones)6, "RightFoot");
			seg[7] = segChild[5];
			segChild[7] = B((HumanBodyBones)5, "LeftFoot");
			seg[8] = segChild[6];
			segChild[8] = B((HumanBodyBones)20, "RightToeBase");
			seg[9] = segChild[7];
			segChild[9] = B((HumanBodyBones)19, "LeftToeBase");
			seg[10] = neck;
			segChild[10] = head;
			finger[0] = B((HumanBodyBones)45, "RightHandMiddle1");
			indexFinger[0] = B((HumanBodyBones)42, "RightHandIndex1");
			pinky[0] = B((HumanBodyBones)51, "RightHandPinky1");
			finger[1] = B((HumanBodyBones)30, "LeftHandMiddle1");
			indexFinger[1] = B((HumanBodyBones)27, "LeftHandIndex1");
			pinky[1] = B((HumanBodyBones)36, "LeftHandPinky1");
			touched.Clear();
			if (Object.op_Implicit((Object)(object)spine))
			{
				touched.Add(spine);
			}
			for (int i = 0; i < 11; i++)
			{
				if (Object.op_Implicit((Object)(object)seg[i]) && !touched.Contains(seg[i]))
				{
					touched.Add(seg[i]);
				}
			}
			baseRot = (Quaternion[])(object)new Quaternion[touched.Count];
			wroteRot = (Quaternion[])(object)new Quaternion[touched.Count];
			wrote = false;
		}

		private Transform B(HumanBodyBones hb, string name)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			Transform val = null;
			if (Object.op_Implicit((Object)(object)anim) && anim.isHuman)
			{
				val = anim.GetBoneTransform(hb);
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				Transform[] componentsInChildren = ((Component)player).GetComponentsInChildren<Transform>(true);
				foreach (Transform val2 in componentsInChildren)
				{
					if (((Object)val2).name == name)
					{
						val = val2;
						break;
					}
				}
			}
			return val;
		}

		public void RestoreBase()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < touched.Count; i++)
			{
				Transform val = touched[i];
				if (Object.op_Implicit((Object)(object)val))
				{
					if (!wrote || val.localRotation != wroteRot[i])
					{
						baseRot[i] = val.localRotation;
					}
					else
					{
						val.localRotation = baseRot[i];
					}
				}
			}
		}

		public void RecordWritten()
		{
			//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)
			ApplyLimits();
			for (int i = 0; i < touched.Count; i++)
			{
				if (Object.op_Implicit((Object)(object)touched[i]))
				{
					wroteRot[i] = touched[i].localRotation;
				}
			}
			wrote = true;
			lastRecord = Time.time;
		}

		private void ApplyLimits()
		{
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_0163: 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)
			if (!Object.op_Implicit((Object)(object)visual))
			{
				return;
			}
			for (int i = 0; i < 2; i++)
			{
				HingeCap(seg[i], seg[i + 2], segChild[i + 2], 150f);
				Knee(seg[i + 4], seg[i + 6], segChild[i + 6]);
				HingeCap(seg[i + 2], segChild[i + 2], finger[i], 75f);
				Ankle(seg[i + 6], segChild[i + 6], segChild[i + 8]);
			}
			if (!wrote || lastRecord < 0f)
			{
				return;
			}
			float num = Time.time - lastRecord;
			if (num <= 0f || num > 0.1f)
			{
				return;
			}
			for (int j = 0; j < touched.Count; j++)
			{
				Transform val = touched[j];
				if (Object.op_Implicit((Object)(object)val))
				{
					float num2 = (((Object)(object)val == (Object)(object)spine) ? 350f : (((Object)(object)val == (Object)(object)neck) ? 450f : 900f));
					float num3 = Quaternion.Angle(wroteRot[j], val.localRotation);
					float num4 = num2 * num;
					if (num3 > num4)
					{
						val.localRotation = Quaternion.Slerp(wroteRot[j], val.localRotation, num4 / num3);
					}
				}
			}
		}

		private static void HingeCap(Transform a, Transform b, Transform c, float max)
		{
			//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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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)
			if (!Object.op_Implicit((Object)(object)a) || !Object.op_Implicit((Object)(object)b) || !Object.op_Implicit((Object)(object)c))
			{
				return;
			}
			Vector3 val = b.position - a.position;
			Vector3 val2 = c.position - b.position;
			if (((Vector3)(ref val)).sqrMagnitude < 1E-08f || ((Vector3)(ref val2)).sqrMagnitude < 1E-08f)
			{
				return;
			}
			float num = Vector3.Angle(val, val2);
			if (!(num <= max))
			{
				Vector3 val3 = Vector3.Cross(val2, val);
				if (!(((Vector3)(ref val3)).sqrMagnitude < 1E-10f))
				{
					b.rotation = Quaternion.AngleAxis(num - max, val3) * b.rotation;
				}
			}
		}

		private void Knee(Transform thigh, Transform shin, Transform foot)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)thigh) || !Object.op_Implicit((Object)(object)shin) || !Object.op_Implicit((Object)(object)foot))
			{
				return;
			}
			HingeCap(thigh, shin, foot, 155f);
			Vector3 val = shin.position - thigh.position;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3 val2 = foot.position - shin.position;
			Vector3 val3 = ((Object.op_Implicit((Object)(object)seg[4]) && Object.op_Implicit((Object)(object)seg[5])) ? (seg[4].position - seg[5].position) : visual.right);
			if (((Vector3)(ref val3)).sqrMagnitude < 1E-06f)
			{
				val3 = visual.right;
			}
			Vector3 val4 = -Vector3.Cross(normalized, ((Vector3)(ref val3)).normalized);
			if (!(((Vector3)(ref val4)).sqrMagnitude < 0.25f) && !(((Vector3)(ref val2)).sqrMagnitude < 1E-08f))
			{
				((Vector3)(ref val4)).Normalize();
				Vector3 val5 = val2 - normalized * Vector3.Dot(val2, normalized);
				if (!(((Vector3)(ref val5)).magnitude < ((Vector3)(ref val2)).magnitude * 0.17f) && !(Vector3.Dot(((Vector3)(ref val5)).normalized, val4) > -0.5f))
				{
					Vector3 dir = val2 - 2f * Vector3.Dot(val5, val4) * val4;
					Aim(shin, foot, dir, 1f);
				}
			}
		}

		private static void Ankle(Transform shin, Transform foot, Transform toe)
		{
			//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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)shin) || !Object.op_Implicit((Object)(object)foot) || !Object.op_Implicit((Object)(object)toe))
			{
				return;
			}
			Vector3 val = foot.position - shin.position;
			Vector3 val2 = toe.position - foot.position;
			if (((Vector3)(ref val)).sqrMagnitude < 1E-08f || ((Vector3)(ref val2)).sqrMagnitude < 1E-08f)
			{
				return;
			}
			float num = Vector3.Angle(val, val2);
			float num2 = ((num > 93f) ? 93f : ((num < 10f) ? 10f : num));
			if (num2 != num)
			{
				Vector3 val3 = Vector3.Cross(val2, val);
				if (!(((Vector3)(ref val3)).sqrMagnitude < 1E-10f))
				{
					foot.rotation = Quaternion.AngleAxis(num - num2, val3) * foot.rotation;
				}
			}
		}

		public void GiveBack()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)visual))
			{
				visual.localRotation = Quaternion.identity;
				visual.localPosition = Vector3.zero;
			}
			if (wrote)
			{
				RestoreBase();
				wrote = false;
			}
		}

		public void Write(Vector3[] dirs, float f, float backbone)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			Vector3 up = visual.up;
			Vector3 forward = visual.forward;
			Vector3 right = visual.right;
			Aim(spine, neck, up, f * backbone);
			for (int i = 0; i < 11; i++)
			{
				Vector3 val = dirs[i];
				float num = ((i == 10) ? 0f : ((i % 2 == 0) ? 1f : (-1f)));
				Vector3 dir = right * (val.x * num) + up * val.y + forward * val.z;
				Aim(seg[i], segChild[i], dir, (i == 10) ? (f * 0.7f) : f);
			}
		}

		public static void Aim(Transform bone, Transform child, Vector3 dir, float w)
		{
			//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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)bone) && Object.op_Implicit((Object)(object)child) && !(w <= 0f))
			{
				Vector3 val = child.position - bone.position;
				if (!(((Vector3)(ref val)).sqrMagnitude < 1E-08f) && !(((Vector3)(ref dir)).sqrMagnitude < 1E-08f))
				{
					Vector3 val2 = Vector3.Slerp(((Vector3)(ref val)).normalized, ((Vector3)(ref dir)).normalized, Mathf.Clamp01(w));
					bone.rotation = Quaternion.FromToRotation(val, val2) * bone.rotation;
				}
			}
		}

		public static float Smooth(float a, float b, float x)
		{
			return Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((x - a) / (b - a)));
		}
	}
	internal sealed class Frozen
	{
		private sealed class Original
		{
			public int uses;

			public readonly List<Animator> anims = new List<Animator>();

			public readonly List<float> vel = new List<float>();

			public Rigidbody body;

			public bool wasKinematic;

			public RigidbodyConstraints savedConstraints;

			public MonsterAI ai;

			public bool aiWasOn;
		}

		private static readonly Dictionary<Character, Original> originals = new Dictionary<Character, Original>();

		private static readonly FieldRef<Character, Rigidbody> fRigid = AccessTools.FieldRefAccess<Character, Rigidbody>("m_body");

		private readonly Character mount;

		private Original o;

		private bool returned;

		private static float Slow => Mathf.Clamp01(MotionSettings.MountSlow.Value);

		public static bool Active(Character b)
		{
			if (Object.op_Implicit((Object)(object)b) && originals.TryGetValue(b, out var value))
			{
				return value.uses > 0;
			}
			return false;
		}

		public Frozen(Character b)
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
			mount = b;
			if (!Object.op_Implicit((Object)(object)b))
			{
				return;
			}
			if (!originals.TryGetValue(b, out o))
			{
				o = new Original();
				Animator[] componentsInChildren = ((Component)b).GetComponentsInChildren<Animator>();
				foreach (Animator val in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						o.anims.Add(val);
						o.vel.Add(val.speed);
					}
				}
				o.body = fRigid.Invoke(b);
				if (Object.op_Implicit((Object)(object)o.body))
				{
					o.wasKinematic = o.body.isKinematic;
					o.savedConstraints = o.body.constraints;
				}
				o.ai = ((Component)b).GetComponent<MonsterAI>();
				if (Object.op_Implicit((Object)(object)o.ai))
				{
					o.aiWasOn = ((Behaviour)o.ai).enabled;
				}
				originals[b] = o;
			}
			o.uses++;
			for (int j = 0; j < o.anims.Count; j++)
			{
				if (Object.op_Implicit((Object)(object)o.anims[j]))
				{
					o.anims[j].speed = o.vel[j] * Slow;
				}
			}
			if (Object.op_Implicit((Object)(object)o.body))
			{
				if (!o.body.isKinematic)
				{
					o.body.linearVelocity = Vector3.zero;
					o.body.angularVelocity = Vector3.zero;
				}
				o.body.constraints = (RigidbodyConstraints)126;
			}
			if (Object.op_Implicit((Object)(object)o.ai))
			{
				((BaseAI)o.ai).StopMoving();
				((Behaviour)o.ai).enabled = false;
			}
		}

		public void Keep()
		{
			//IL_00b5: 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)
			if (!Object.op_Implicit((Object)(object)mount) || o == null || returned)
			{
				return;
			}
			for (int i = 0; i < o.anims.Count; i++)
			{
				Animator val = o.anims[i];
				float num = o.vel[i] * Slow;
				if (Object.op_Implicit((Object)(object)val) && Mathf.Abs(val.speed - num) > 0.0001f)
				{
					val.speed = num;
				}
			}
			if (Object.op_Implicit((Object)(object)o.body) && !o.body.isKinematic)
			{
				o.body.linearVelocity = Vector3.zero;
				o.body.angularVelocity = Vector3.zero;
			}
		}

		public void GiveBack()
		{
			if (o == null || returned)
			{
				return;
			}
			returned = true;
			if (--o.uses <= 0)
			{
				Restore(o);
				if (Object.op_Implicit((Object)(object)mount))
				{
					originals.Remove(mount);
				}
			}
		}

		private static void Restore(Original o)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < o.anims.Count; i++)
			{
				if (Object.op_Implicit((Object)(object)o.anims[i]))
				{
					o.anims[i].speed = o.vel[i];
				}
			}
			if (Object.op_Implicit((Object)(object)o.body))
			{
				o.body.constraints = o.savedConstraints;
				o.body.isKinematic = o.wasKinematic;
			}
			if (Object.op_Implicit((Object)(object)o.ai))
			{
				((Behaviour)o.ai).enabled = o.aiWasOn;
			}
		}
	}
	internal static class Cape
	{
		private const float UprightAngle = 35f;

		internal static void Reset(Component who)
		{
			if (!Object.op_Implicit((Object)(object)who))
			{
				return;
			}
			try
			{
				MagicaCloth[] componentsInChildren = who.GetComponentsInChildren<MagicaCloth>();
				foreach (MagicaCloth val in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)val) && ((Behaviour)val).isActiveAndEnabled)
					{
						val.ResetCloth(false);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[MissingAnimations] cape reset: " + ex.Message));
			}
		}

		internal static bool Hold(Component who, Body body)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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)
			if (!Object.op_Implicit((Object)(object)who) || body == null || !Object.op_Implicit((Object)(object)body.hips) || !Object.op_Implicit((Object)(object)body.head))
			{
				return false;
			}
			Vector3 val = body.head.position - body.hips.position;
			if (((Vector3)(ref val)).sqrMagnitude > 0.0001f && Vector3.Angle(val, Vector3.up) < 35f)
			{
				Reset(who);
				return false;
			}
			Reset(who);
			return true;
		}
	}
	internal interface IPreCloth
	{
		Body ClothBody { get; }

		void PreCloth();
	}
	[HarmonyPatch(typeof(ClothManager), "OnBeforeLateUpdate")]
	internal static class ClothPrePosePatch
	{
		private const float MaxArmFromHanging = 50f;

		private static readonly List<object> now = new List<object>();

		internal static readonly List<Transform> held = new List<Transform>();

		internal static readonly List<Quaternion> real = new List<Quaternion>();

		internal static readonly List<Quaternion> given = new List<Quaternion>();

		internal static readonly List<bool> always = new List<bool>();

		private static bool poseInUpdate;

		private const float MaxClavicleLift = 10f;

		private static void Prefix()
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_0161: Unknown result type (might be due to invalid IL or missing references)
			held.Clear();
			real.Clear();
			given.Clear();
			always.Clear();
			now.Clear();
			Body.CopyOwners(now);
			foreach (object item in now)
			{
				Behaviour val = (Behaviour)((item is Behaviour) ? item : null);
				if (!(item is IPreCloth preCloth) || !Object.op_Implicit((Object)(object)val) || !val.isActiveAndEnabled)
				{
					continue;
				}
				try
				{
					preCloth.PreCloth();
					Body clothBody = preCloth.ClothBody;
					Animator val2 = clothBody?.anim;
					if (Object.op_Implicit((Object)(object)val2) && val2.isHuman)
					{
						poseInUpdate = clothBody.PoseInUpdate;
						Transform boneTransform = val2.GetBoneTransform((HumanBodyBones)9);
						Transform boneTransform2 = val2.GetBoneTransform((HumanBodyBones)0);
						if (Object.op_Implicit((Object)(object)boneTransform) && Object.op_Implicit((Object)(object)boneTransform2))
						{
							Vector3 val3 = boneTransform2.position - boneTransform.position;
							Vector3 normalized = ((Vector3)(ref val3)).normalized;
							Lift(val2.GetBoneTransform((HumanBodyBones)11), val2.GetBoneTransform((HumanBodyBones)13), normalized);
							Lift(val2.GetBoneTransform((HumanBodyBones)12), val2.GetBoneTransform((HumanBodyBones)14), normalized);
							Hold(val2.GetBoneTransform((HumanBodyBones)13), val2.GetBoneTransform((HumanBodyBones)15), normalized);
							Hold(val2.GetBoneTransform((HumanBodyBones)14), val2.GetBoneTransform((HumanBodyBones)16), normalized);
						}
					}
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("[MissingAnimations] pose before cloth: " + ex.Message));
				}
			}
		}

		private static void Lift(Transform clav, Transform arm, Vector3 down)
		{
			//IL_0012: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)clav) || !Object.op_Implicit((Object)(object)arm))
			{
				return;
			}
			Vector3 val = arm.position - clav.position;
			if (!(((Vector3)(ref val)).sqrMagnitude < 1E-06f))
			{
				((Vector3)(ref val)).Normalize();
				if (!(Vector3.Angle(val, down) - 90f <= 10f))
				{
					Vector3 val2 = Vector3.ProjectOnPlane(val, down);
					Vector3 val3 = Vector3.RotateTowards(((Vector3)(ref val2)).normalized, -down, 0.17453292f, 0f);
					Quaternion localRotation = clav.localRotation;
					clav.rotation = Quaternion.FromToRotation(val, val3) * clav.rotation;
					held.Add(clav);
					real.Add(localRotation);
					given.Add(clav.localRotation);
					always.Add(poseInUpdate);
				}
			}
		}

		private static void Hold(Transform arm, Transform fore, Vector3 down)
		{
			//IL_0012: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)arm) || !Object.op_Implicit((Object)(object)fore))
			{
				return;
			}
			Vector3 val = fore.position - arm.position;
			if (!(((Vector3)(ref val)).sqrMagnitude < 1E-06f))
			{
				((Vector3)(ref val)).Normalize();
				if (!(Vector3.Angle(val, down) <= 50f))
				{
					Vector3 val2 = Vector3.RotateTowards(down, val, 0.87266463f, 0f);
					Quaternion localRotation = arm.localRotation;
					arm.rotation = Quaternion.FromToRotation(val, val2) * arm.rotation;
					held.Add(arm);
					real.Add(localRotation);
					given.Add(arm.localRotation);
					always.Add(poseInUpdate);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ClothManager), "OnAfterLateUpdate")]
	internal static class ClothPostReadPatch
	{
		private static void Postfix()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			List<Transform> held = ClothPrePosePatch.held;
			for (int i = 0; i < held.Count; i++)
			{
				if (Object.op_Implicit((Object)(object)held[i]) && (ClothPrePosePatch.always[i] || held[i].localRotation == ClothPrePosePatch.given[i]))
				{
					held[i].localRotation = ClothPrePosePatch.real[i];
				}
			}
			held.Clear();
		}
	}
	internal static class CartGeometry
	{
		internal static bool IsCart(Vagon v)
		{
			if (!Object.op_Implicit((Object)(object)v))
			{
				return false;
			}
			string name = ((Object)((Component)v).gameObject).name;
			if (!name.StartsWith("Cart") && !name.StartsWith("Catapult"))
			{
				return name.StartsWith("BatteringRam");
			}
			return true;
		}

		internal static bool Mine(Vagon v)
		{
			if (MotionSettings.Mine(MotionSettings.CartEnabled) && IsCart(v) && Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return v.IsAttached((Character)(object)Player.m_localPlayer);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Vagon), "LateUpdate")]
	internal static class CartHarnessPatch
	{
		private static readonly FieldRef<Vagon, LineRenderer> fLine = AccessTools.FieldRefAccess<Vagon, LineRenderer>("m_lineRenderer");

		private static void Postfix(Vagon __instance)
		{
			try
			{
				if (CartGeometry.Mine(__instance))
				{
					CartHarness component = ((Component)Player.m_localPlayer).GetComponent<CartHarness>();
					LineRenderer val = fLine.Invoke(__instance);
					if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)val) && component.Draw(__instance, val, MotionSettings.CartTie.Value))
					{
						((Renderer)val).enabled = false;
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[MissingAnimations] Cart harness failed, keeping the game's rope: " + ex.Message));
			}
		}
	}
	internal sealed class CartHarness : MonoBehaviour
	{
		private struct Frame
		{
			public Vector3 o;

			public Vector3 r;

			public Vector3 u;

			public Vector3 f;

			public Vector3 P(Vector3 v)
			{
				//IL_0001: 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_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: 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_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: 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_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				return o + r * v.x + u * v.y + f * v.z;
			}
		}

		private static readonly Vector3 SpinePiv = new Vector3(0f, 1.078f, -0.007f);

		private static readonly Vector3 Spine1Piv = new Vector3(0f, 1.379f, -0.031f);

		private static readonly Vector3 Spine2Piv = new Vector3(0f, 1.529f, -0.046f);

		private const float BuckleU = 31f / 64f;

		private const float WaistY = 1.12f;

		private const float WaistZ = -0.01f;

		private const float BeltH = 0.1f;

		private const float Padding = 0.022f;

		private const float StrapW = 0.05f;

		private const float StrapGap = 0.03f;

		private const float StrapFront = 14f;

		private const float BeltRound = 1.19f;

		private static readonly float[] WaistAng = new float[5] { 0f, 45f, 90f, 135f, 180f };

		private static readonly float[] WaistR = new float[5] { 0.144f, 0.157f, 0.181f, 0.173f, 0.15f };

		private Player player;

		private Transform hips;

		private Transform spine;

		private Transform spine1;

		private Transform spine2;

		private Transform neck;

		private Transform upL;

		private Transform upR;

		private Transform armL;

		private Transform armR;

		private GameObject root;

		private Mesh beltMesh;

		private Mesh strapMeshL;

		private Mesh strapMeshR;

		private LineRenderer ropeL;

		private LineRenderer ropeR;

		private Material beltMat;

		private Materi