Decompiled source of Enigmas Tidy Cart v0.1.15

EnigmasTidyCart.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[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 EnigmasTidyCart
{
	internal sealed class Fixed<T>
	{
		public readonly T Value;

		public Fixed(T value)
		{
			Value = value;
		}
	}
	[BepInPlugin("EnigmaPrime.EnigmasTidyCart", "Enigma's Tidy Cart", "0.1.15")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "EnigmaPrime.EnigmasTidyCart";

		public const string PluginName = "Enigma's Tidy Cart";

		public const string PluginVersion = "0.1.15";

		internal static ManualLogSource Log;

		internal static Plugin Instance;

		internal static ConfigEntry<bool> Enabled;

		internal static Fixed<float> WallCheckDistance = new Fixed<float>(0.7f);

		internal static ConfigEntry<float> MinWallHeight;

		internal static Fixed<float> SecondRayAngle = new Fixed<float>(15f);

		internal static Fixed<bool> RequireBothRays = new Fixed<bool>(value: false);

		internal static ConfigEntry<float> StowedTiltDegrees;

		internal static Fixed<bool> LogCartLayout = new Fixed<bool>(value: false);

		internal static Fixed<bool> LogInteractions = new Fixed<bool>(value: false);

		internal static ConfigEntry<KeyCode> StowModifierKey;

		internal static Fixed<bool> LogInput = new Fixed<bool>(value: false);

		internal static Fixed<float> ClearanceTolerance = new Fixed<float>(0.1f);

		internal static ConfigEntry<float> ClearanceHeight;

		internal static Fixed<float> TurnSeconds = new Fixed<float>(1f);

		internal static ConfigEntry<float> TipSeconds;

		internal static Fixed<float> CrouchSeconds = new Fixed<float>(0.6f);

		internal static Fixed<float> EquipSeconds = new Fixed<float>(1.2f);

		internal static ConfigEntry<bool> StowThumbsUp;

		internal static Fixed<float> WalkDelaySeconds = new Fixed<float>(0.5f);

		internal static Fixed<float> UnstowTipDelaySeconds = new Fixed<float>(0f);

		internal static Fixed<float> StandDistance = new Fixed<float>(0.05f);

		internal static Fixed<bool> RealWalk = new Fixed<bool>(value: true);

		internal static ConfigEntry<bool> UnstowThumbsUp;

		internal static Fixed<float> UpperSideForgiveness = new Fixed<float>(0.15f);

		internal static Fixed<bool> LogStowCheck = new Fixed<bool>(value: false);

		private Harmony _harmony;

		private void Awake()
		{
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Turn the whole mod on or off. Use (E) unstows a stowed cart. Shift + Use stows an empty cart.");
			MinWallHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Wall check", "MinimumWallHeight", 2f, "Walls shorter than this (meters) do not count. Uses the whole piece, not where the ray lands.");
			StowedTiltDegrees = ((BaseUnityPlugin)this).Config.Bind<float>("Stowed pose", "StowedTiltDegrees", 115f, "How far the cart tips over (degrees from lying flat). 90 stands it straight up on its back end. More leans it back against the wall (the top rim of the bed at the handle end rests on the wall). Limited to 90 to 130.");
			StowModifierKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "StowModifierKey", (KeyCode)304, "Holding this key while pressing Use stows the cart. The game's own Alt Place binding (and the gamepad alt button) also work.");
			ClearanceHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Wall check", "ClearanceHeight", 3f, "Height (meters) above the standing cart's base up to which a floor or ceiling counts as clear, measured to the floor's TOP surface. A floor whose top is at this height or higher is fine, one lower blocks. The cart stands about 3.25 m tall, so its top clips into a floor at 3.0 m. The floor's thickness (0.13 m) is subtracted automatically.");
			TipSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Animation", "TipSeconds", 1.6f, "How long (seconds) the cart takes to tip up (stow) or back down (unstow).");
			StowThumbsUp = ((BaseUnityPlugin)this).Config.Bind<bool>("Animation", "StowThumbsUp", true, "Do the thumbs up emote at the end of stowing.");
			UnstowThumbsUp = ((BaseUnityPlugin)this).Config.Bind<bool>("Animation", "UnstowThumbsUp", false, "Do the thumbs up emote at the end of unstowing.");
			_harmony = new Harmony("EnigmaPrime.EnigmasTidyCart");
			_harmony.PatchAll();
			Log.LogInfo((object)"Enigma's Tidy Cart 0.1.15 loaded.");
		}

		private void OnDestroy()
		{
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
			}
		}
	}
	internal static class CartState
	{
		private const string StowedKey = "EnigmaTidyCart_Stowed";

		private const string StowLine = "\n[<color=yellow><b>Shift + $KEY_Use</b></color>] Stow";

		private const string UnstowLine = "\n[<color=yellow><b>$KEY_Use</b></color>] Unstow";

		internal static bool IsStowed(Vagon cart)
		{
			if ((Object)(object)cart == (Object)null)
			{
				return false;
			}
			ZNetView component = ((Component)cart).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid())
			{
				return component.GetZDO().GetBool("EnigmaTidyCart_Stowed", false);
			}
			return false;
		}

		internal static void SetStowedFlag(Vagon cart, bool stowed)
		{
			SetStowed(cart, stowed);
		}

		private static void SetStowed(Vagon cart, bool stowed)
		{
			ZNetView component = ((Component)cart).GetComponent<ZNetView>();
			if (!((Object)(object)component == (Object)null) && component.IsValid())
			{
				component.ClaimOwnership();
				component.GetZDO().Set("EnigmaTidyCart_Stowed", stowed);
			}
		}

		internal static bool HasContents(Vagon cart)
		{
			if ((Object)(object)cart.m_container != (Object)null)
			{
				return cart.m_container.GetInventory().NrOfItems() > 0;
			}
			return false;
		}

		internal static bool HandleInteract(Vagon cart, Humanoid user, bool hold, bool alt)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)cart == (Object)null || !Plugin.Enabled.Value)
			{
				return false;
			}
			bool key = ZInput.GetKey(Plugin.StowModifierKey.Value, true);
			alt = alt || key;
			if (Plugin.LogInteractions.Value)
			{
				Plugin.Log.LogInfo((object)("Cart interact: hold=" + hold + ", alt(after merge)=" + alt + ", modifierKey=" + key + ", stowed=" + IsStowed(cart) + ", contents=" + HasContents(cart) + ", attached=" + cart.IsAttached()));
			}
			if (CartMotion.IsBusy(cart))
			{
				return true;
			}
			if (IsStowed(cart))
			{
				if (!hold)
				{
					Player val = (Player)(object)((user is Player) ? user : null);
					if ((Object)(object)val != (Object)null)
					{
						CartMotion.BeginUnstow(cart, val);
					}
					else
					{
						SetStowed(cart, stowed: false);
					}
				}
				return true;
			}
			if (alt && !hold)
			{
				if (cart.IsAttached())
				{
					((Character)user).Message((MessageType)2, "Let go of the cart first", 0, (Sprite)null, false);
				}
				else if (HasContents(cart))
				{
					((Character)user).Message((MessageType)2, "Empty the cart first", 0, (Sprite)null, false);
				}
				else
				{
					Vector3 stowPos;
					Quaternion stowRot;
					Vector3 pivotLocalOut;
					switch (StowCheck.Evaluate(cart, out stowPos, out stowRot, out pivotLocalOut))
					{
					case StowResult.NoWall:
						((Character)user).Message((MessageType)2, "Back the cart up to a wall first", 0, (Sprite)null, false);
						break;
					case StowResult.NoRoom:
						((Character)user).Message((MessageType)2, "The cart doesn't fit here", 0, (Sprite)null, false);
						break;
					default:
					{
						Player val2 = (Player)(object)((user is Player) ? user : null);
						if ((Object)(object)val2 != (Object)null)
						{
							CartMotion.BeginStow(cart, val2, stowPos, stowRot, pivotLocalOut);
						}
						else
						{
							SetStowed(cart, stowed: true);
						}
						break;
					}
					}
				}
				return true;
			}
			return false;
		}

		internal static string HoverText(Vagon cart, string original)
		{
			if ((Object)(object)cart == (Object)null || !Plugin.Enabled.Value)
			{
				return original;
			}
			if (IsStowed(cart))
			{
				return Localization.instance.Localize(cart.m_name + "\n[<color=yellow><b>$KEY_Use</b></color>] Unstow");
			}
			return original + Localization.instance.Localize("\n[<color=yellow><b>Shift + $KEY_Use</b></color>] Stow");
		}
	}
	[HarmonyPatch(typeof(Vagon), "Interact")]
	internal static class VagonInteractPatch
	{
		private static bool Prefix(Vagon __instance, Humanoid character, bool hold, bool alt, ref bool __result)
		{
			if (!CartState.HandleInteract(__instance, character, hold, alt))
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(Vagon), "GetHoverText")]
	internal static class VagonHoverPatch
	{
		private static void Postfix(Vagon __instance, ref string __result)
		{
			__result = CartState.HoverText(__instance, __result);
		}
	}
	[HarmonyPatch(typeof(Container), "Interact")]
	internal static class ContainerInteractPatch
	{
		private static bool Prefix(Container __instance, Humanoid character, bool hold, bool alt, ref bool __result)
		{
			Vagon componentInParent = ((Component)__instance).GetComponentInParent<Vagon>();
			if ((Object)(object)componentInParent == (Object)null || !CartState.HandleInteract(componentInParent, character, hold, alt))
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(Container), "GetHoverText")]
	internal static class ContainerHoverPatch
	{
		private static void Postfix(Container __instance, ref string __result)
		{
			Vagon componentInParent = ((Component)__instance).GetComponentInParent<Vagon>();
			if (!((Object)(object)componentInParent == (Object)null))
			{
				__result = CartState.HoverText(componentInParent, __result);
			}
		}
	}
	[HarmonyPatch(typeof(Vagon), "Awake")]
	internal static class VagonLayoutLogPatch
	{
		private static void Postfix(Vagon __instance)
		{
			//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_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_005e: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_0097: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.LogCartLayout.Value || (Object)(object)__instance.m_attachPoint == (Object)null)
			{
				return;
			}
			Transform transform = ((Component)__instance).transform;
			Vector3 val = transform.InverseTransformPoint(__instance.m_attachPoint.position);
			string text = "none";
			Vector3 val2;
			if ((Object)(object)__instance.m_container != (Object)null)
			{
				val2 = transform.InverseTransformPoint(((Component)__instance.m_container).transform.position);
				text = ((Vector3)(ref val2)).ToString("F2");
			}
			string text2 = "no renderers";
			Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>();
			if (componentsInChildren.Length != 0)
			{
				Bounds bounds = componentsInChildren[0].bounds;
				for (int i = 1; i < componentsInChildren.Length; i++)
				{
					((Bounds)(ref bounds)).Encapsulate(componentsInChildren[i].bounds);
				}
				val2 = transform.InverseTransformPoint(((Bounds)(ref bounds)).center);
				string text3 = ((Vector3)(ref val2)).ToString("F2");
				val2 = ((Bounds)(ref bounds)).size;
				text2 = "center(local) " + text3 + ", world size " + ((Vector3)(ref val2)).ToString("F2");
			}
			ManualLogSource log = Plugin.Log;
			string[] obj = new string[10] { "Cart layout: forward ", null, null, null, null, null, null, null, null, null };
			val2 = transform.forward;
			obj[1] = ((Vector3)(ref val2)).ToString("F2");
			obj[2] = ", up ";
			val2 = transform.up;
			obj[3] = ((Vector3)(ref val2)).ToString("F2");
			obj[4] = ", grab point (local) ";
			obj[5] = ((Vector3)(ref val)).ToString("F2");
			obj[6] = ", storage (local) ";
			obj[7] = text;
			obj[8] = ", renderers: ";
			obj[9] = text2;
			log.LogInfo((object)string.Concat(obj));
		}
	}
	[HarmonyPatch(typeof(Vagon), "Awake")]
	internal static class VagonKeeperPatch
	{
		private static void Postfix(Vagon __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<StowedKeeper>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<StowedKeeper>();
			}
		}
	}
	[HarmonyPatch(typeof(Player), "SetControls")]
	internal static class PlayerLockPatch
	{
		private static void Prefix(Player __instance, ref Vector3 movedir, ref bool attack, ref bool attackHold, ref bool secondaryAttack, ref bool secondaryAttackHold, ref bool block, ref bool blockHold, ref bool jump, ref bool crouch, ref bool run, ref bool autoRun, ref bool dodge)
		{
			//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)
			if (CartMotion.Locked && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				movedir = Vector3.zero;
				attack = false;
				attackHold = false;
				secondaryAttack = false;
				secondaryAttackHold = false;
				block = false;
				blockHold = false;
				jump = false;
				crouch = false;
				run = false;
				autoRun = false;
				dodge = false;
			}
		}

		private static void Postfix(Player __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (CartMotion.Locked && CartMotion.WalkActive && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				Traverse.Create((object)__instance).Field("m_moveDir").SetValue((object)CartMotion.WalkDir);
			}
		}
	}
	internal enum StowResult
	{
		Ok,
		NoWall,
		NoRoom
	}
	internal static class StowCheck
	{
		private struct LocalBox
		{
			public string Name;

			public Vector3 Min;

			public Vector3 Max;

			public Vector3 Center => (Min + Max) * 0.5f;

			public Vector3 Extents => (Max - Min) * 0.5f;
		}

		private class TestBox
		{
			public string Name;

			public Vector3 Center;

			public Vector3 Half;
		}

		private const float UprightLimit = 0.35f;

		private const float WallGap = 0.03f;

		private const float MinHalfExtent = 0.05f;

		private const float FloorThickness = 0.13f;

		private const float UpperHeight = 1f;

		private const float TopMargin = 0.05f;

		private const float MaxSlide = 1.5f;

		private const float SlideStep = 0.05f;

		private static int _clearanceMask = -1;

		private static int _wallRayMask = -1;

		private static int _groundMask = -1;

		private static BoxCollider _probe;

		internal static StowResult Evaluate(Vagon cart)
		{
			Vector3 stowPos;
			Quaternion stowRot;
			Vector3 pivotLocalOut;
			return Evaluate(cart, out stowPos, out stowRot, out pivotLocalOut);
		}

		internal static StowResult Evaluate(Vagon cart, out Vector3 stowPos, out Quaternion stowRot, out Vector3 pivotLocalOut)
		{
			//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_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_0023: 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_0125: 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_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: 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_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: 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_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: 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_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0518: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0634: Unknown result type (might be due to invalid IL or missing references)
			//IL_063f: Unknown result type (might be due to invalid IL or missing references)
			//IL_064d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_056d: Unknown result type (might be due to invalid IL or missing references)
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0698: Unknown result type (might be due to invalid IL or missing references)
			//IL_0684: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_07eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0813: Unknown result type (might be due to invalid IL or missing references)
			//IL_081f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0839: Unknown result type (might be due to invalid IL or missing references)
			//IL_0847: Unknown result type (might be due to invalid IL or missing references)
			//IL_085d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0869: Unknown result type (might be due to invalid IL or missing references)
			//IL_087b: Unknown result type (might be due to invalid IL or missing references)
			//IL_089a: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a3b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a3d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a42: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a47: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a59: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a63: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a66: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a68: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_090f: Unknown result type (might be due to invalid IL or missing references)
			//IL_091e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0949: Unknown result type (might be due to invalid IL or missing references)
			//IL_094b: Unknown result type (might be due to invalid IL or missing references)
			//IL_094d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0957: Unknown result type (might be due to invalid IL or missing references)
			//IL_095c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0963: Unknown result type (might be due to invalid IL or missing references)
			//IL_0965: Unknown result type (might be due to invalid IL or missing references)
			//IL_0967: Unknown result type (might be due to invalid IL or missing references)
			//IL_0971: Unknown result type (might be due to invalid IL or missing references)
			//IL_0976: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a9e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aa0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aa4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aa9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ab1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0acb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0adb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0baa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c09: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c0e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b03: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b05: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b10: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b15: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b1a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b1f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b2c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b31: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b3f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b41: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b4c: Unknown result type (might be due to invalid IL or missing references)
			stowPos = ((Component)cart).transform.position;
			stowRot = ((Component)cart).transform.rotation;
			pivotLocalOut = Vector3.zero;
			if (_clearanceMask < 0)
			{
				_clearanceMask = LayerMask.GetMask(new string[8] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle", "character", "character_net" });
				_wallRayMask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle" });
				_groundMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "terrain" });
			}
			Transform transform = ((Component)cart).transform;
			List<LocalBox> list = new List<LocalBox>();
			if (!MeasureBox(cart, out var box, list))
			{
				Log("could not measure the cart's colliders");
				return StowResult.NoWall;
			}
			float num = box.Max.y - box.Min.y;
			string[] obj = new string[8]
			{
				"cart box (local) min ",
				((Vector3)(ref box.Min)).ToString("F2"),
				" max ",
				((Vector3)(ref box.Max)).ToString("F2"),
				" size ",
				null,
				null,
				null
			};
			Vector3 val = box.Max - box.Min;
			obj[5] = ((Vector3)(ref val)).ToString("F2");
			obj[6] = ", cart forward ";
			val = transform.forward;
			obj[7] = ((Vector3)(ref val)).ToString("F2");
			Log(string.Concat(obj));
			Vector3 val2 = -transform.forward;
			val2.y = 0f;
			if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
			{
				return StowResult.NoWall;
			}
			((Vector3)(ref val2)).Normalize();
			Vector3 val3 = transform.TransformPoint(box.Center);
			float num2 = box.Center.z - box.Min.z;
			float length = num2 + Plugin.WallCheckDistance.Value;
			float num3 = Plugin.SecondRayAngle.Value * ((float)Math.PI / 180f);
			val = val2 * Mathf.Cos(num3) + Vector3.up * Mathf.Sin(num3);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			float num4 = Mathf.Max(0f, box.Extents.x - 0.1f);
			Vector3 origin = transform.TransformPoint(new Vector3(box.Center.x - num4, box.Center.y, box.Center.z));
			Vector3 origin2 = transform.TransformPoint(new Vector3(box.Center.x + num4, box.Center.y, box.Center.z));
			RaycastHit result;
			bool flag = CastWallRay(cart, val3, val2, length, "straight back", out result);
			RaycastHit result2;
			bool flag2 = CastWallRay(cart, val3, normalized, length, "angled up", out result2);
			RaycastHit result3;
			bool flag3 = CastWallRay(cart, origin, val2, length, "left side", out result3);
			RaycastHit result4;
			bool flag4 = CastWallRay(cart, origin2, val2, length, "right side", out result4);
			bool flag5 = (Plugin.RequireBothRays.Value ? (flag && flag2) : (flag || flag2));
			if (!(flag5 || flag3 || flag4))
			{
				string[] obj2 = new string[11]
				{
					"no valid wall (straight ",
					flag.ToString(),
					", angled ",
					flag2.ToString(),
					", left ",
					flag3.ToString(),
					", right ",
					flag4.ToString(),
					", both center rays required ",
					null,
					null
				};
				bool value = Plugin.RequireBothRays.Value;
				obj2[9] = value.ToString();
				obj2[10] = ")";
				Log(string.Concat(obj2));
				return StowResult.NoWall;
			}
			float num5 = float.MaxValue;
			if (flag5 && flag)
			{
				num5 = Mathf.Min(num5, Vector3.Dot(((RaycastHit)(ref result)).point - val3, val2));
			}
			if (flag5 && flag2)
			{
				num5 = Mathf.Min(num5, Vector3.Dot(((RaycastHit)(ref result2)).point - val3, val2));
			}
			if (flag3)
			{
				num5 = Mathf.Min(num5, Vector3.Dot(((RaycastHit)(ref result3)).point - val3, val2));
			}
			if (flag4)
			{
				num5 = Mathf.Min(num5, Vector3.Dot(((RaycastHit)(ref result4)).point - val3, val2));
			}
			float value2 = Plugin.ClearanceTolerance.Value;
			float num6 = box.Max.z - box.Min.z;
			float value3 = Plugin.ClearanceHeight.Value;
			float num7 = Mathf.Clamp(Plugin.StowedTiltDegrees.Value, 90f, 130f);
			float num8 = Mathf.Sin(num7 * ((float)Math.PI / 180f));
			float num9 = Mathf.Cos(num7 * ((float)Math.PI / 180f));
			float num10 = value3 - 0.13f - 0.05f;
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(box.Center.x, box.Min.y, box.Min.z);
			pivotLocalOut = val4;
			float num11 = float.MaxValue;
			float num12 = 0f;
			float num13 = 0f;
			for (int i = 0; i < list.Count; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					float num14 = (((j & 2) == 0) ? list[i].Min.y : list[i].Max.y) - box.Min.y;
					float num15 = (((j & 4) == 0) ? list[i].Min.z : list[i].Max.z) - box.Min.z;
					float num16 = num8 * num15 + num9 * num14;
					if (num16 < num11 - 0.0001f || (Mathf.Abs(num16 - num11) <= 0.0001f && num14 < num12))
					{
						num11 = num16;
						num12 = num14;
						num13 = num15;
					}
				}
			}
			Vector3 val5 = default(Vector3);
			((Vector3)(ref val5))..ctor(box.Center.x, box.Min.y + num12, box.Min.z + num13);
			float num17 = 0f;
			for (int k = 0; k < list.Count; k++)
			{
				for (int l = 0; l < 8; l++)
				{
					float num18 = (((l & 2) == 0) ? list[k].Min.y : list[k].Max.y) - box.Min.y - num12;
					float num19 = (((l & 4) == 0) ? list[k].Min.z : list[k].Max.z) - box.Min.z - num13;
					num17 = Mathf.Max(num17, num8 * num18 - num9 * num19);
				}
			}
			if (num17 < 0.1f)
			{
				num17 = num;
			}
			Log("tilt " + num7.ToString("F0") + " degrees: rests on the corner " + num12.ToString("F2") + " m along Y and " + num13.ToString("F2") + " m along Z from the back-bottom edge; the part that reaches the wall first is " + num17.ToString("F2") + " m from it.");
			List<TestBox> list2 = new List<TestBox>();
			Vector3 val6 = default(Vector3);
			Vector3 val7 = default(Vector3);
			for (int m = 0; m < list.Count; m++)
			{
				LocalBox localBox = list[m];
				float num20 = Mathf.Min(value2, (localBox.Max.x - localBox.Min.x) * 0.4f);
				float num21 = Mathf.Min(value2, (localBox.Max.y - localBox.Min.y) * 0.4f);
				float num22 = Mathf.Min(value2, (localBox.Max.z - localBox.Min.z) * 0.4f);
				float num23 = Mathf.Max(localBox.Min.z + num22, box.Min.z + value2);
				float num24 = (localBox.Min.y + localBox.Max.y) * 0.5f - box.Min.y;
				float num25 = (num10 + num11 - num9 * num24) / num8;
				float num26 = ((localBox.Max.z - box.Min.z > num25) ? (box.Min.z + num25) : (localBox.Max.z - num22));
				if (!(num26 - num23 < 0.02f))
				{
					((Vector3)(ref val6))..ctor(localBox.Min.x + num20, localBox.Min.y + num21, num23);
					((Vector3)(ref val7))..ctor(localBox.Max.x - num20, localBox.Max.y - num21, num26);
					TestBox testBox = new TestBox();
					testBox.Name = localBox.Name;
					testBox.Center = (val6 + val7) * 0.5f;
					testBox.Half = (val7 - val6) * 0.5f;
					list2.Add(testBox);
				}
			}
			Log("test volume: " + list2.Count + " cart parts, cart length " + num6.ToString("F2") + " m, tested up to " + num10.ToString("F2") + " m above the base (ClearanceHeight " + value3.ToString("F2") + " m measured to a floor's top surface, minus " + 0.17999999f.ToString("F2") + " m for its thickness)");
			if (list2.Count == 0)
			{
				return StowResult.NoWall;
			}
			Quaternion val8 = Quaternion.LookRotation(-val2, Vector3.up) * Quaternion.Euler(0f - num7, 0f, 0f);
			float y = transform.TransformPoint(val4).y;
			float num27 = num5 - num17 - 0.03f;
			string text = "nothing";
			int num28 = 0;
			for (float num29 = 0f; num29 <= 1.501f; num29 += 0.05f)
			{
				float num30 = num27 - num29;
				Vector3 val9 = val3 + val2 * num30;
				if (!FindGround(cart, val9, y, out var groundY))
				{
					groundY = y;
				}
				Vector3 val10 = new Vector3(val9.x, groundY, val9.z) - val8 * val5;
				num28++;
				string detail = "";
				string text2 = "";
				Collider val11 = null;
				for (int n = 0; n < list2.Count; n++)
				{
					if (!((Object)(object)val11 == (Object)null))
					{
						break;
					}
					Vector3 val12 = val10 + val8 * list2[n].Center;
					val11 = FirstBlocker(Physics.OverlapBox(val12, list2[n].Half, val8, _clearanceMask, (QueryTriggerInteraction)1), transform, val12, val8, list2[n].Half, groundY, out detail);
					if ((Object)(object)val11 != (Object)null)
					{
						text2 = list2[n].Name;
					}
				}
				if ((Object)(object)val11 == (Object)null)
				{
					stowPos = val10;
					stowRot = val8;
					string[] obj3 = new string[12]
					{
						"wall at ",
						num5.ToString("F2"),
						" m along back from the cart center. Fits after sliding ",
						num29.ToString("F2"),
						" m forward from the wall contact; stowed pose position ",
						((Vector3)(ref val10)).ToString("F2"),
						", rotation (euler) ",
						null,
						null,
						null,
						null,
						null
					};
					val = ((Quaternion)(ref val8)).eulerAngles;
					obj3[7] = ((Vector3)(ref val)).ToString("F1");
					obj3[8] = ", base moves ";
					obj3[9] = (num30 - num2).ToString("F2");
					obj3[10] = " m along back, ground height ";
					obj3[11] = groundY.ToString("F2");
					Log(string.Concat(obj3));
					return StowResult.Ok;
				}
				bool flag6 = IsWallLike(val11);
				text = Describe(val11, flag6, groundY) + ((detail.Length > 0) ? (", " + detail) : "") + ", hit by cart part '" + text2 + "'";
				if (!flag6)
				{
					Log("blocked at " + num29.ToString("F2") + " m of sliding by " + text + ": not a tall wall piece, so it blocks");
					return StowResult.NoRoom;
				}
				if (num29 == 0f)
				{
					Log("first spot blocked by " + text + ", sliding forward to look for room");
				}
			}
			Log("wall at " + num5.ToString("F2") + " m, but the cart does not fit at any of " + num28 + " spots tried; last blocked by " + text);
			return StowResult.NoRoom;
		}

		private static bool IsWallLike(Collider c)
		{
			Piece componentInParent = ((Component)c).GetComponentInParent<Piece>();
			if ((Object)(object)componentInParent != (Object)null && componentInParent.IsPlacedByPlayer())
			{
				return PieceHeight(componentInParent) >= Plugin.MinWallHeight.Value;
			}
			return false;
		}

		private static string Describe(Collider c, bool wallLike, float groundY)
		{
			//IL_0008: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			Piece componentInParent = ((Component)c).GetComponentInParent<Piece>();
			Bounds bounds = c.bounds;
			string text = (((Object)(object)componentInParent != (Object)null) ? ((Object)componentInParent).name : "no piece");
			string text2 = (((Object)(object)((Component)c).transform.root != (Object)null) ? ((Object)((Component)c).transform.root).name : "?");
			string[] obj = new string[18]
			{
				"'",
				((Object)c).name,
				"' on '",
				text,
				"' (root '",
				text2,
				"', layer ",
				LayerMask.LayerToName(((Component)c).gameObject.layer),
				((Object)(object)componentInParent != (Object)null) ? (", " + (componentInParent.IsPlacedByPlayer() ? "player-built" : "not player-built")) : "",
				", ",
				wallLike ? "wall-like" : "not wall-like",
				"), size ",
				null,
				null,
				null,
				null,
				null,
				null
			};
			Vector3 size = ((Bounds)(ref bounds)).size;
			obj[12] = ((Vector3)(ref size)).ToString("F2");
			obj[13] = ", from ";
			obj[14] = (((Bounds)(ref bounds)).min.y - groundY).ToString("F2");
			obj[15] = " to ";
			obj[16] = (((Bounds)(ref bounds)).max.y - groundY).ToString("F2");
			obj[17] = " m above the ground at the base";
			return string.Concat(obj);
		}

		private static Collider FirstBlocker(Collider[] overlaps, Transform cart, Vector3 boxCenter, Quaternion q, Vector3 half, float groundY, out string detail)
		{
			//IL_0025: 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)
			//IL_0027: 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_0041: 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)
			detail = "";
			foreach (Collider val in overlaps)
			{
				if (((Component)val).transform.IsChildOf(cart))
				{
					continue;
				}
				if (Penetration(val, boxCenter, q, half, out var dir, out var depth))
				{
					Bounds bounds = val.bounds;
					bool num = ((Bounds)(ref bounds)).min.y - groundY >= 1f;
					bool flag = Mathf.Abs(dir.y) < 0.5f;
					if (num && flag && depth <= Plugin.UpperSideForgiveness.Value)
					{
						string[] obj = new string[9]
						{
							"ignored '",
							((Object)val).name,
							"' on '",
							((Object)(object)((Component)val).GetComponentInParent<Piece>() != (Object)null) ? ((Object)((Component)val).GetComponentInParent<Piece>()).name : "no piece",
							"': upper piece overlapping only ",
							depth.ToString("F3"),
							" m sideways (limit ",
							null,
							null
						};
						float value = Plugin.UpperSideForgiveness.Value;
						obj[7] = value.ToString("F2");
						obj[8] = ")";
						Log(string.Concat(obj));
						continue;
					}
					detail = "overlap " + depth.ToString("F3") + " m, push direction " + ((Vector3)(ref dir)).ToString("F2");
				}
				else
				{
					detail = "overlap depth could not be measured";
				}
				return val;
			}
			return null;
		}

		private static bool Penetration(Collider c, Vector3 boxCenter, Quaternion q, Vector3 half, out Vector3 dir, out float depth)
		{
			//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_0068: 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_007d: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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)
			//IL_002b: 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_003a: 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)
			dir = Vector3.zero;
			depth = 0f;
			try
			{
				if ((Object)(object)_probe == (Object)null)
				{
					GameObject val = new GameObject("EnigmasTidyCartProbe")
					{
						hideFlags = (HideFlags)61,
						layer = 2
					};
					val.transform.position = new Vector3(0f, -5000f, 0f);
					_probe = val.AddComponent<BoxCollider>();
				}
				_probe.size = half * 2f;
				return Physics.ComputePenetration((Collider)(object)_probe, boxCenter, q, c, ((Component)c).transform.position, ((Component)c).transform.rotation, ref dir, ref depth);
			}
			catch (Exception ex)
			{
				Log("could not measure overlap depth: " + ex.Message);
				return false;
			}
		}

		private static bool FindGround(Vagon cart, Vector3 flat, float refY, out float groundY)
		{
			//IL_0003: 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_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_0080: Unknown result type (might be due to invalid IL or missing references)
			groundY = refY;
			RaycastHit[] array = Physics.RaycastAll(new Vector3(flat.x, refY + 1.5f, flat.z), Vector3.down, 4f, _groundMask, (QueryTriggerInteraction)1);
			Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
			for (int num = 0; num < array.Length; num++)
			{
				if (!((Component)((RaycastHit)(ref array[num])).collider).transform.IsChildOf(((Component)cart).transform))
				{
					groundY = ((RaycastHit)(ref array[num])).point.y;
					return true;
				}
			}
			return false;
		}

		private static bool MeasureBox(Vagon cart, out LocalBox box, List<LocalBox> parts)
		{
			//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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: 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_005f: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: 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_0122: 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_0088: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: 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_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: 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)
			//IL_0096: 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_0154: 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_00ad: 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)
			//IL_0174: 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_00c3: 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_00d2: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)cart).transform;
			box = default(LocalBox);
			bool flag = false;
			Vector3 val = Vector3.zero;
			Vector3 val2 = Vector3.zero;
			Collider[] componentsInChildren = ((Component)cart).GetComponentsInChildren<Collider>();
			Vector3 val5 = default(Vector3);
			foreach (Collider val3 in componentsInChildren)
			{
				if (val3.isTrigger || !val3.enabled)
				{
					continue;
				}
				Vector3 center;
				Vector3 extents;
				string kind;
				bool localShape = GetLocalShape(val3, out center, out extents, out kind);
				Vector3 min = Vector3.zero;
				Vector3 max = Vector3.zero;
				bool any = false;
				if (localShape)
				{
					for (int j = 0; j < 8; j++)
					{
						Vector3 val4 = center + new Vector3(((j & 1) == 0) ? (0f - extents.x) : extents.x, ((j & 2) == 0) ? (0f - extents.y) : extents.y, ((j & 4) == 0) ? (0f - extents.z) : extents.z);
						AddPoint(transform.InverseTransformPoint(((Component)val3).transform.TransformPoint(val4)), ref min, ref max, ref any);
					}
				}
				else
				{
					Bounds bounds = val3.bounds;
					for (int k = 0; k < 8; k++)
					{
						((Vector3)(ref val5))..ctor(((k & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((k & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((k & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z);
						AddPoint(transform.InverseTransformPoint(val5), ref min, ref max, ref any);
					}
				}
				parts.Add(new LocalBox
				{
					Name = ((Object)val3).name,
					Min = min,
					Max = max
				});
				Log("collider '" + ((Object)val3).name + "' " + kind + (localShape ? "" : " (world bounds, may be oversize)") + " local min " + ((Vector3)(ref min)).ToString("F2") + " max " + ((Vector3)(ref max)).ToString("F2"));
				if (!flag)
				{
					val = min;
					val2 = max;
					flag = true;
				}
				else
				{
					val = Vector3.Min(val, min);
					val2 = Vector3.Max(val2, max);
				}
			}
			if (!flag)
			{
				return false;
			}
			box.Min = val;
			box.Max = val2;
			return true;
		}

		private static void AddPoint(Vector3 p, ref Vector3 min, ref Vector3 max, ref bool any)
		{
			//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_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_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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_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)
			if (!any)
			{
				min = p;
				max = p;
				any = true;
			}
			else
			{
				min = Vector3.Min(min, p);
				max = Vector3.Max(max, p);
			}
		}

		private static bool GetLocalShape(Collider c, out Vector3 center, out Vector3 extents, out string kind)
		{
			//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_000c: 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_0035: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_0081: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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)
			//IL_00a4: 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_0143: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			center = Vector3.zero;
			extents = Vector3.zero;
			kind = ((object)c).GetType().Name;
			BoxCollider val = (BoxCollider)(object)((c is BoxCollider) ? c : null);
			if ((Object)(object)val != (Object)null)
			{
				center = val.center;
				extents = val.size * 0.5f;
				return true;
			}
			MeshCollider val2 = (MeshCollider)(object)((c is MeshCollider) ? c : null);
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2.sharedMesh != (Object)null)
			{
				Bounds bounds = val2.sharedMesh.bounds;
				center = ((Bounds)(ref bounds)).center;
				bounds = val2.sharedMesh.bounds;
				extents = ((Bounds)(ref bounds)).extents;
				return true;
			}
			CapsuleCollider val3 = (CapsuleCollider)(object)((c is CapsuleCollider) ? c : null);
			if ((Object)(object)val3 != (Object)null)
			{
				center = val3.center;
				float num = Mathf.Max(val3.height * 0.5f, val3.radius);
				extents = new Vector3(val3.radius, val3.radius, val3.radius);
				if (val3.direction == 0)
				{
					extents.x = num;
				}
				else if (val3.direction == 1)
				{
					extents.y = num;
				}
				else
				{
					extents.z = num;
				}
				return true;
			}
			SphereCollider val4 = (SphereCollider)(object)((c is SphereCollider) ? c : null);
			if ((Object)(object)val4 != (Object)null)
			{
				center = val4.center;
				extents = new Vector3(val4.radius, val4.radius, val4.radius);
				return true;
			}
			return false;
		}

		private static bool CastWallRay(Vagon cart, Vector3 origin, Vector3 dir, float length, string label, out RaycastHit result)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			result = default(RaycastHit);
			RaycastHit[] array = Physics.RaycastAll(origin, dir, length, _wallRayMask, (QueryTriggerInteraction)1);
			Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
			for (int num = 0; num < array.Length; num++)
			{
				RaycastHit val = array[num];
				if (!((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)cart).transform))
				{
					Piece componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>();
					if ((Object)(object)componentInParent == (Object)null || !componentInParent.IsPlacedByPlayer())
					{
						Log(label + " ray: first hit '" + ((Object)((RaycastHit)(ref val)).collider).name + "' is not a player-built piece");
						return false;
					}
					if (Mathf.Abs(((RaycastHit)(ref val)).normal.y) > 0.35f)
					{
						Log(label + " ray: '" + ((Object)componentInParent).name + "' surface is not upright (normal y " + ((RaycastHit)(ref val)).normal.y.ToString("F2") + ")");
						return false;
					}
					float num2 = PieceHeight(componentInParent);
					if (num2 < Plugin.MinWallHeight.Value)
					{
						Log(label + " ray: '" + ((Object)componentInParent).name + "' is only " + num2.ToString("F2") + " m tall (minimum " + Plugin.MinWallHeight.Value.ToString("F2") + ")");
						return false;
					}
					Log(label + " ray: wall '" + ((Object)componentInParent).name + "', " + num2.ToString("F2") + " m tall, " + ((RaycastHit)(ref val)).distance.ToString("F2") + " m from the cart center");
					result = val;
					return true;
				}
			}
			Log(label + " ray: nothing within " + length.ToString("F2") + " m");
			return false;
		}

		private static float PieceHeight(Piece piece)
		{
			//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_0054: 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_0035: 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)
			Collider[] componentsInChildren = ((Component)piece).GetComponentsInChildren<Collider>();
			bool flag = false;
			float num = 0f;
			float num2 = 0f;
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (!componentsInChildren[i].isTrigger)
				{
					Bounds bounds = componentsInChildren[i].bounds;
					if (!flag)
					{
						num = ((Bounds)(ref bounds)).min.y;
						num2 = ((Bounds)(ref bounds)).max.y;
						flag = true;
					}
					else
					{
						num = Mathf.Min(num, ((Bounds)(ref bounds)).min.y);
						num2 = Mathf.Max(num2, ((Bounds)(ref bounds)).max.y);
					}
				}
			}
			if (!flag)
			{
				return 0f;
			}
			return num2 - num;
		}

		private static void Log(string text)
		{
			if (Plugin.LogStowCheck.Value)
			{
				Plugin.Log.LogInfo((object)("Stow check: " + text));
			}
		}
	}
	internal static class CartMotion
	{
		private class TipState
		{
			public bool Done;
		}

		private const string OrigPosKey = "EnigmaTidyCart_OrigPos";

		private const string OrigRotKey = "EnigmaTidyCart_OrigRot";

		private const string PivotKey = "EnigmaTidyCart_Pivot";

		private const string StowPosKey = "EnigmaTidyCart_StowPos";

		private const string StowRotKey = "EnigmaTidyCart_StowRot";

		private static readonly HashSet<Vagon> Busy = new HashSet<Vagon>();

		internal static bool Locked;

		internal static bool WalkActive;

		internal static Vector3 WalkDir;

		private static int _groundMask = -1;

		private static int GroundMask
		{
			get
			{
				if (_groundMask < 0)
				{
					_groundMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "terrain" });
				}
				return _groundMask;
			}
		}

		internal static bool IsBusy(Vagon cart)
		{
			return Busy.Contains(cart);
		}

		internal static void BeginStow(Vagon cart, Player player, Vector3 endPos, Quaternion endRot, Vector3 pivotLocal)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			((MonoBehaviour)Plugin.Instance).StartCoroutine(StowRoutine(cart, player, endPos, endRot, pivotLocal));
		}

		private static IEnumerator StowRoutine(Vagon cart, Player player, Vector3 endPos, Quaternion endRot, Vector3 pivotLocal)
		{
			//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_001c: 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_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)
			Busy.Add(cart);
			Locked = (Object)(object)player != (Object)null;
			try
			{
				Transform transform = ((Component)cart).transform;
				Vector3 startPos = transform.position;
				Quaternion startRot = transform.rotation;
				ZNetView component = ((Component)cart).GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid())
				{
					component.ClaimOwnership();
					ZDO zDO = component.GetZDO();
					zDO.Set("EnigmaTidyCart_OrigPos", startPos);
					zDO.Set("EnigmaTidyCart_OrigRot", startRot);
					zDO.Set("EnigmaTidyCart_Pivot", pivotLocal);
					zDO.Set("EnigmaTidyCart_StowPos", endPos);
					zDO.Set("EnigmaTidyCart_StowRot", endRot);
				}
				SetKinematic(cart, kinematic: true);
				Vector3 attachLocal = transform.InverseTransformPoint(((Object)(object)cart.m_attachPoint != (Object)null) ? cart.m_attachPoint.position : transform.position);
				Vector3 handles = Vector3.zero;
				Vector3 spot = Vector3.zero;
				Quaternion face = Quaternion.identity;
				if ((Object)(object)player != (Object)null)
				{
					DragSpot(cart, attachLocal, startPos, startRot, out handles, out face);
					Vector3 val = Heading(startRot);
					Vector3 val2 = endPos + endRot * pivotLocal;
					spot = GroundSnap(cart, val2 + val * Plugin.StandDistance.Value);
				}
				yield return ApproachTo(player, handles, face);
				float tip = Mathf.Max(0.1f, Plugin.TipSeconds.Value);
				TipState tipState = new TipState();
				((MonoBehaviour)Plugin.Instance).StartCoroutine(TipRoutine(cart, startPos, startRot, endPos, endRot, pivotLocal, tip, 0f, tipState));
				if ((Object)(object)player != (Object)null)
				{
					CrouchStep crouch = new CrouchStep(player, Plugin.CrouchSeconds.Value);
					crouch.Begin();
					float w = 0f;
					while (!crouch.Done && w < 8f)
					{
						w += Time.deltaTime;
						HoldPose(player, handles, face);
						crouch.Update(Time.deltaTime);
						yield return null;
					}
					yield return Pause(player, handles, face, Plugin.WalkDelaySeconds.Value);
					yield return WalkTo(player, spot, face);
					yield return ArmorAnimation(player, spot, face);
				}
				float waited = 0f;
				while (!tipState.Done && waited < 6f)
				{
					waited += Time.deltaTime;
					if ((Object)(object)player != (Object)null)
					{
						HoldPose(player, spot, face);
					}
					yield return null;
				}
				CartState.SetStowedFlag(cart, stowed: true);
				if ((Object)(object)player != (Object)null && Plugin.StowThumbsUp.Value)
				{
					yield return Emote(player, spot, face, "thumbsup");
				}
				Plugin.Log.LogInfo((object)"Cart stowed.");
			}
			finally
			{
				WalkActive = false;
				if ((Object)(object)player != (Object)null)
				{
					SetCrouch(player, crouch: false);
					SetAnimBool(player, "equipping", value: false);
				}
				Locked = false;
				Busy.Remove(cart);
			}
		}

		internal static void BeginUnstow(Vagon cart, Player player)
		{
			((MonoBehaviour)Plugin.Instance).StartCoroutine(UnstowRoutine(cart, player));
		}

		private static IEnumerator UnstowRoutine(Vagon cart, Player player)
		{
			Busy.Add(cart);
			Locked = (Object)(object)player != (Object)null;
			try
			{
				Transform transform = ((Component)cart).transform;
				Vector3 startPos = transform.position;
				Quaternion startRot = transform.rotation;
				ZNetView component = ((Component)cart).GetComponent<ZNetView>();
				Vector3 endPos = startPos;
				Quaternion endRot = Quaternion.Euler(0f, ((Quaternion)(ref startRot)).eulerAngles.y, 0f);
				Vector3 pivotLocal = Vector3.zero;
				bool flag = false;
				if ((Object)(object)component != (Object)null && component.IsValid())
				{
					component.ClaimOwnership();
					ZDO zDO = component.GetZDO();
					pivotLocal = zDO.GetVec3("EnigmaTidyCart_Pivot", Vector3.zero);
					Vector3 vec = zDO.GetVec3("EnigmaTidyCart_OrigPos", Vector3.zero);
					flag = vec != Vector3.zero;
					if (flag)
					{
						endPos = vec;
						endRot = zDO.GetQuaternion("EnigmaTidyCart_OrigRot", endRot);
					}
				}
				if (!flag)
				{
					Vector3 val = startPos + startRot * pivotLocal;
					endPos = val - endRot * pivotLocal;
				}
				SetKinematic(cart, kinematic: true);
				Vector3 attachLocal = transform.InverseTransformPoint(((Object)(object)cart.m_attachPoint != (Object)null) ? cart.m_attachPoint.position : transform.position);
				Vector3 handles = Vector3.zero;
				Vector3 spot = Vector3.zero;
				Quaternion faceHandles = Quaternion.identity;
				Quaternion faceSpot = Quaternion.identity;
				if ((Object)(object)player != (Object)null)
				{
					DragSpot(cart, attachLocal, endPos, endRot, out handles, out faceHandles);
					Vector3 val2 = Heading(endRot);
					Vector3 val3 = startPos + startRot * pivotLocal;
					spot = GroundSnap(cart, val3 + val2 * Plugin.StandDistance.Value);
					faceSpot = Quaternion.LookRotation(-val2, Vector3.up);
				}
				yield return ApproachTo(player, spot, faceSpot);
				float tip = Mathf.Max(0.1f, Plugin.TipSeconds.Value);
				TipState tipState = new TipState();
				if ((Object)(object)player != (Object)null)
				{
					yield return ArmorAnimation(player, spot, faceSpot);
				}
				((MonoBehaviour)Plugin.Instance).StartCoroutine(TipRoutine(cart, startPos, startRot, endPos, endRot, pivotLocal, tip, Mathf.Max(0f, Plugin.UnstowTipDelaySeconds.Value), tipState));
				if ((Object)(object)player != (Object)null)
				{
					yield return Pause(player, spot, faceSpot, Plugin.WalkDelaySeconds.Value);
					yield return WalkTo(player, handles, faceHandles);
					CrouchStep crouch = new CrouchStep(player, Plugin.CrouchSeconds.Value);
					crouch.Begin();
					float w = 0f;
					while (!crouch.Done && w < 8f)
					{
						w += Time.deltaTime;
						HoldPose(player, handles, faceHandles);
						crouch.Update(Time.deltaTime);
						yield return null;
					}
				}
				float waited = 0f;
				while (!tipState.Done && waited < 6f)
				{
					waited += Time.deltaTime;
					if ((Object)(object)player != (Object)null)
					{
						HoldPose(player, handles, faceHandles);
					}
					yield return null;
				}
				ApplyPose(cart, endPos, endRot);
				CartState.SetStowedFlag(cart, stowed: false);
				SetKinematic(cart, kinematic: false);
				Rigidbody[] componentsInChildren = ((Component)cart).GetComponentsInChildren<Rigidbody>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].WakeUp();
				}
				if ((Object)(object)player != (Object)null && Plugin.UnstowThumbsUp.Value)
				{
					yield return Emote(player, handles, faceHandles, "thumbsup");
				}
				Plugin.Log.LogInfo((object)"Cart unstowed.");
			}
			finally
			{
				WalkActive = false;
				if ((Object)(object)player != (Object)null)
				{
					SetCrouch(player, crouch: false);
					SetAnimBool(player, "equipping", value: false);
				}
				Locked = false;
				Busy.Remove(cart);
			}
		}

		private static IEnumerator TipRoutine(Vagon cart, Vector3 startPos, Quaternion startRot, Vector3 endPos, Quaternion endRot, Vector3 pivotLocal, float tip, float startDelay, TipState state)
		{
			//IL_000e: 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_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_001c: 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_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_002d: Unknown result type (might be due to invalid IL or missing references)
			float waitT = 0f;
			while (waitT < startDelay && (Object)(object)cart != (Object)null)
			{
				waitT += Time.deltaTime;
				yield return null;
			}
			Vector3 pivot0 = startPos + startRot * pivotLocal;
			Vector3 pivotF = endPos + endRot * pivotLocal;
			float t = 0f;
			while (t < tip && (Object)(object)cart != (Object)null)
			{
				t += Time.deltaTime;
				float num = Ease(Mathf.Clamp01(t / tip));
				Quaternion val = Quaternion.Slerp(startRot, endRot, num);
				Vector3 val2 = Vector3.Lerp(pivot0, pivotF, num);
				ApplyPose(cart, val2 - val * pivotLocal, val);
				yield return null;
			}
			if ((Object)(object)cart != (Object)null)
			{
				ApplyPose(cart, endPos, endRot);
			}
			state.Done = true;
		}

		private static void DragSpot(Vagon cart, Vector3 attachLocal, Vector3 pos, Quaternion rot, out Vector3 stand, out Quaternion face)
		{
			//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_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_0010: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0027: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = pos + rot * attachLocal;
			stand = val - cart.m_attachOffset;
			Vector3 val2 = rot * Vector3.forward;
			val2.y = 0f;
			face = ((((Vector3)(ref val2)).sqrMagnitude < 0.0001f) ? Quaternion.identity : Quaternion.LookRotation(-((Vector3)(ref val2)).normalized, Vector3.up));
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Raycast(stand + Vector3.up * 1.5f, Vector3.down, ref val3, 4f, GroundMask, (QueryTriggerInteraction)1) && !((Component)((RaycastHit)(ref val3)).collider).transform.IsChildOf(((Component)cart).transform) && stand.y < ((RaycastHit)(ref val3)).point.y)
			{
				stand.y = ((RaycastHit)(ref val3)).point.y;
			}
		}

		private static IEnumerator ApproachTo(Player player, Vector3 target, Quaternion finalFace)
		{
			//IL_000e: 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_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)
			if (!((Object)(object)player == (Object)null))
			{
				Vector3 val = target - ((Component)player).transform.position;
				val.y = 0f;
				if (((Vector3)(ref val)).magnitude > 0.25f)
				{
					Quaternion walkFace = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
					yield return TurnInPlace(player, walkFace, 0.2f);
					yield return WalkTo(player, target, walkFace);
				}
				yield return TurnInPlace(player, finalFace, Plugin.TurnSeconds.Value);
				SetBodyPose(player, target, finalFace);
			}
		}

		private static IEnumerator TurnInPlace(Player player, Quaternion to, float seconds)
		{
			//IL_000e: 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)
			Vector3 pos = ((Component)player).transform.position;
			Quaternion from = ((Component)player).transform.rotation;
			float t = 0f;
			while (t < seconds)
			{
				t += Time.deltaTime;
				SetBodyPose(player, pos, Quaternion.Slerp(from, to, Ease(Mathf.Clamp01(t / seconds))));
				yield return null;
			}
			SetBodyPose(player, pos, to);
		}

		private static Vector3 Heading(Quaternion rot)
		{
			//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_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_002e: 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)
			Vector3 val = rot * Vector3.forward;
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude < 0.0001f))
			{
				return ((Vector3)(ref val)).normalized;
			}
			return Vector3.forward;
		}

		private static Vector3 GroundSnap(Vagon cart, Vector3 p)
		{
			//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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(p + Vector3.up * 1.5f, Vector3.down, ref val, 4f, GroundMask, (QueryTriggerInteraction)1) && !((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)cart).transform))
			{
				p.y = ((RaycastHit)(ref val)).point.y;
			}
			return p;
		}

		private static IEnumerator Pause(Player player, Vector3 stand, Quaternion face, float seconds)
		{
			//IL_000e: 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_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)
			float w = 0f;
			while (w < seconds)
			{
				w += Time.deltaTime;
				HoldPose(player, stand, face);
				yield return null;
			}
		}

		private static IEnumerator WalkTo(Player player, Vector3 target, Quaternion face)
		{
			//IL_000e: 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_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)
			if ((Object)(object)player == (Object)null)
			{
				yield break;
			}
			Vector3 val = target - ((Component)player).transform.position;
			val.y = 0f;
			float dist = ((Vector3)(ref val)).magnitude;
			if (dist < 0.05f)
			{
				SetBodyPose(player, target, face);
				yield break;
			}
			if (!Plugin.RealWalk.Value)
			{
				Vector3 from = ((Component)player).transform.position;
				float dur = Mathf.Max(0.25f, dist / 1.5f);
				float t = 0f;
				while (t < dur)
				{
					t += Time.deltaTime;
					SetBodyPose(player, Vector3.Lerp(from, target, Ease(Mathf.Clamp01(t / dur))), face);
					yield return null;
				}
				SetBodyPose(player, target, face);
				yield break;
			}
			float timeout = Mathf.Max(1.2f, dist / 0.8f + 0.5f);
			float elapsed = 0f;
			bool arrived = false;
			try
			{
				WalkActive = true;
				while (elapsed < timeout)
				{
					elapsed += Time.deltaTime;
					Vector3 val2 = target - ((Component)player).transform.position;
					val2.y = 0f;
					if (((Vector3)(ref val2)).magnitude < 0.12f)
					{
						arrived = true;
						break;
					}
					WalkDir = ((Vector3)(ref val2)).normalized;
					((Component)player).transform.rotation = face;
					yield return null;
				}
			}
			finally
			{
				WalkActive = false;
				WalkDir = Vector3.zero;
			}
			Plugin.Log.LogInfo((object)("Walk: " + (arrived ? "arrived" : "timed out") + " after " + elapsed.ToString("F2") + " s, " + dist.ToString("F2") + " m to go at the start."));
			SetBodyPose(player, target, face);
		}

		private static IEnumerator ArmorAnimation(Player player, Vector3 stand, Quaternion face)
		{
			//IL_000e: 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_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)
			if ((Object)(object)player == (Object)null)
			{
				yield break;
			}
			float dur = Mathf.Max(0f, Plugin.EquipSeconds.Value);
			float t = 0f;
			bool logged = false;
			SetAnimBool(player, "equipping", value: true);
			try
			{
				while (t < dur)
				{
					t += Time.deltaTime;
					HoldPose(player, stand, face);
					if (!logged && t >= 0.4f)
					{
						logged = true;
						if (Plugin.LogInteractions.Value)
						{
							Plugin.Log.LogInfo((object)("Armor animation: clips playing: " + DescribeClips(Traverse.Create((object)player).Field("m_animator").GetValue())));
						}
					}
					yield return null;
				}
			}
			finally
			{
				SetAnimBool(player, "equipping", value: false);
			}
		}

		internal static void SetAnimBool(Player player, string name, bool value)
		{
			ZSyncAnimation value2 = Traverse.Create((object)player).Field("m_zanim").GetValue<ZSyncAnimation>();
			if ((Object)(object)value2 != (Object)null)
			{
				value2.SetBool(name, value);
			}
		}

		internal static string DescribeClips(object animator)
		{
			string text = "";
			if (animator == null)
			{
				return "no animator";
			}
			try
			{
				Type type = animator.GetType();
				int num = (int)type.GetProperty("layerCount").GetValue(animator, null);
				MethodInfo method = type.GetMethod("GetCurrentAnimatorClipInfo", new Type[1] { typeof(int) });
				for (int i = 0; i < num; i++)
				{
					if (!(method.Invoke(animator, new object[1] { i }) is Array array))
					{
						continue;
					}
					foreach (object item in array)
					{
						object? value = item.GetType().GetProperty("clip").GetValue(item, null);
						Object val = (Object)((value is Object) ? value : null);
						if (val != (Object)null)
						{
							text = text + "[" + i + ": " + val.name + "] ";
						}
					}
				}
			}
			catch (Exception ex)
			{
				text = text + "(could not read: " + ex.Message + ")";
			}
			if (text.Length <= 0)
			{
				return "none";
			}
			return text;
		}

		private static IEnumerator Emote(Player player, Vector3 stand, Quaternion face, string name)
		{
			//IL_000e: 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_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)
			if (player.StartEmote(name, true))
			{
				float w = 0f;
				while (w < 0.3f)
				{
					w += Time.deltaTime;
					HoldPose(player, stand, face);
					yield return null;
				}
				while (((Character)player).InEmote() && w < 3f)
				{
					w += Time.deltaTime;
					HoldPose(player, stand, face);
					yield return null;
				}
			}
		}

		internal static float Ease(float s)
		{
			return s * s * (3f - 2f * s);
		}

		private static void HoldPose(Player player, Vector3 stand, Quaternion face)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			SetBodyPose(player, stand, face);
		}

		private static void SetBodyPose(Player player, Vector3 position, Quaternion rotation)
		{
			//IL_0006: 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_001e: 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_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)
			((Component)player).transform.SetPositionAndRotation(position, rotation);
			Rigidbody component = ((Component)player).GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				component.position = position;
				component.rotation = rotation;
				component.linearVelocity = Vector3.zero;
				component.angularVelocity = Vector3.zero;
			}
		}

		private static void ApplyPose(Vagon cart, Vector3 pos, Quaternion rot)
		{
			//IL_0006: 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_001e: 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)
			((Component)cart).transform.SetPositionAndRotation(pos, rot);
			Rigidbody component = ((Component)cart).GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				component.position = pos;
				component.rotation = rot;
			}
		}

		internal static void SetKinematic(Vagon cart, bool kinematic)
		{
			//IL_0011: 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)
			Rigidbody[] componentsInChildren = ((Component)cart).GetComponentsInChildren<Rigidbody>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (kinematic)
				{
					componentsInChildren[i].linearVelocity = Vector3.zero;
					componentsInChildren[i].angularVelocity = Vector3.zero;
				}
				componentsInChildren[i].isKinematic = kinematic;
			}
		}

		internal static void SetCrouch(Player player, bool crouch)
		{
			Traverse.Create((object)player).Field("m_crouchToggled").SetValue((object)crouch);
		}

		internal static void PlayTrigger(Player player, string trigger)
		{
			ZSyncAnimation value = Traverse.Create((object)player).Field("m_zanim").GetValue<ZSyncAnimation>();
			if ((Object)(object)value != (Object)null)
			{
				value.SetTrigger(trigger);
			}
		}
	}
	internal class CrouchStep
	{
		private readonly Player _player;

		private readonly float _hold;

		private int _step;

		private float _timer;

		public bool Done;

		public CrouchStep(Player player, float holdSeconds)
		{
			_player = player;
			_hold = Mathf.Max(0f, holdSeconds);
			Done = (Object)(object)player == (Object)null;
		}

		public void Begin()
		{
			if (!((Object)(object)_player == (Object)null))
			{
				_step = 0;
				_timer = 0f;
				CartMotion.SetCrouch(_player, crouch: true);
			}
		}

		public void Update(float dt)
		{
			if (Done || (Object)(object)_player == (Object)null)
			{
				return;
			}
			_timer += dt;
			if (_step == 0)
			{
				if (_timer >= _hold)
				{
					CartMotion.SetCrouch(_player, crouch: false);
					_step = 1;
					_timer = 0f;
				}
			}
			else if (_timer >= 0.15f && (!((Character)_player).IsCrouching() || _timer > 1.5f))
			{
				Done = true;
				Plugin.Log.LogInfo((object)("Crouch: standing again " + _timer.ToString("F2") + " s after standing up began" + ((_timer > 1.5f) ? " (gave up waiting for the animator)." : ".")));
			}
		}
	}
	internal class StowedKeeper : MonoBehaviour
	{
		private Vagon _cart;

		private bool _forced;

		private void Awake()
		{
			_cart = ((Component)this).GetComponent<Vagon>();
		}

		private void FixedUpdate()
		{
			if ((Object)(object)_cart == (Object)null || CartMotion.IsBusy(_cart))
			{
				return;
			}
			if (CartState.IsStowed(_cart))
			{
				Rigidbody component = ((Component)_cart).GetComponent<Rigidbody>();
				if (!_forced || ((Object)(object)component != (Object)null && !component.isKinematic))
				{
					CartMotion.SetKinematic(_cart, kinematic: true);
					_forced = true;
				}
			}
			else if (_forced)
			{
				CartMotion.SetKinematic(_cart, kinematic: false);
				_forced = false;
			}
		}
	}
}