Decompiled source of UniversalCartAttachments v1.0.0

UniversalCartAttachments.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using Photon.Voice.Unity;
using REPOLib.Modules;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.UI;
using UniversalCartHitch.Belt;
using UniversalCartHitch.CartCam;
using UniversalCartHitch.Configuration;
using UniversalCartHitch.Debugging;
using UniversalCartHitch.Detection;
using UniversalCartHitch.Hanging;
using UniversalCartHitch.Hitching;
using UniversalCartHitch.Interaction;
using UniversalCartHitch.Networking;
using UniversalCartHitch.Stacking;
using UniversalCartHitch.Visuals;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("Zee")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Universal Cart Attachments")]
[assembly: AssemblyTitle("UniversalCartAttachments")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace UniversalCartHitch
{
	internal sealed class ModLog
	{
		private readonly ManualLogSource _source;

		internal static bool Verbose
		{
			get
			{
				if (PluginConfig.VerboseLogging != null && !PluginConfig.VerboseLogging.Value)
				{
					return PluginConfig.Dev;
				}
				return true;
			}
		}

		internal ModLog(ManualLogSource source)
		{
			_source = source;
		}

		internal void LogInfo(object message)
		{
			if (Verbose)
			{
				_source.LogInfo(message);
			}
		}

		internal void LogDebug(object message)
		{
			if (Verbose)
			{
				_source.LogDebug(message);
			}
		}

		internal void LogWarning(object message)
		{
			_source.LogWarning(message);
		}

		internal void LogError(object message)
		{
			_source.LogError(message);
		}

		internal void LogImportant(object message)
		{
			_source.LogInfo(message);
		}
	}
	[BepInPlugin("Zee.UniversalCartHitch", "Universal Cart Attachments", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class UniversalCartHitch : BaseUnityPlugin
	{
		private ModLog? _log;

		internal static UniversalCartHitch Instance { get; private set; }

		internal static ModLog Logger
		{
			get
			{
				UniversalCartHitch instance = Instance;
				return instance._log ?? (instance._log = new ModLog(Instance.BaseLogger));
			}
		}

		private ManualLogSource BaseLogger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			PluginConfig.Bind(((BaseUnityPlugin)this).Config);
			HitchManager.Initialize();
			HitchVisualManager.Initialize();
			HitchNetwork.Initialize();
			StackerManager.Initialize();
			StackerVisuals.Initialize();
			StackNetwork.Initialize();
			BeltNetwork.Initialize();
			HangNetwork.Initialize();
			BeltRope.Initialize();
			Patch();
			Logger.LogImportant($"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded! Build id {typeof(UniversalCartHitch).Assembly.ManifestModule.ModuleVersionId.ToString().Substring(0, 8)} (both players must show the same id).");
			CartCamVoiceMonitor.LogPatchStatus();
		}

		internal void Patch()
		{
			//IL_0019: 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_0020: Expected O, but got Unknown
			//IL_0025: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
			if (PluginConfig.Dev)
			{
				DevKeys();
			}
			CartCamPrototype.Update();
			HitchNetwork.Tick();
			TickSystems();
		}

		private static void DevKeys()
		{
			//IL_0005: 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_0011: 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_0033: 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_00c4: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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_0116: 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_00ae: 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)
			if ((int)PluginConfig.DebugLogKey.Value != 0 && Input.GetKeyDown(PluginConfig.DebugLogKey.Value))
			{
				DetectionDebugLogger.LogAll();
			}
			if ((int)PluginConfig.StackerTestSpawnKey.Value != 0 && Input.GetKeyDown(PluginConfig.StackerTestSpawnKey.Value) && SemiFunc.NoTextInputsActive())
			{
				StackerItemRegistration.DebugSpawn();
			}
			if ((int)PluginConfig.TestCubeSpawnKey.Value != 0 && Input.GetKeyDown(PluginConfig.TestCubeSpawnKey.Value) && SemiFunc.NoTextInputsActive())
			{
				TestCube.Spawn();
			}
			if (SemiFunc.NoTextInputsActive())
			{
				if ((int)PluginConfig.TestLargeCartSpawnKey.Value != 0 && Input.GetKeyDown(PluginConfig.TestLargeCartSpawnKey.Value))
				{
					TestCartSpawner.SpawnLarge();
				}
				if ((int)PluginConfig.TestPocketCartSpawnKey.Value != 0 && Input.GetKeyDown(PluginConfig.TestPocketCartSpawnKey.Value))
				{
					TestCartSpawner.SpawnPocket();
				}
			}
			if ((int)PluginConfig.BeltTestSpawnKey.Value != 0 && Input.GetKeyDown(PluginConfig.BeltTestSpawnKey.Value) && SemiFunc.NoTextInputsActive())
			{
				BeltItemRegistration.DebugSpawn();
			}
			if ((int)PluginConfig.KitSpawnKey.Value != 0 && Input.GetKeyDown(PluginConfig.KitSpawnKey.Value) && SemiFunc.NoTextInputsActive())
			{
				CartCamItemRegistration.DebugSpawnKit();
			}
			if ((int)PluginConfig.TestHuntsmanSpawnKey.Value != 0 && Input.GetKeyDown(PluginConfig.TestHuntsmanSpawnKey.Value) && SemiFunc.NoTextInputsActive())
			{
				TestHuntsmanSpawner.Spawn();
			}
		}

		private void TickSystems()
		{
			StackNetwork.Tick();
			BeltNetwork.Tick();
			HangNetwork.Tick();
			CartCamNetwork.Tick();
			HeadHanging.Update();
			InteractionPrompt.Tick();
			StackerManager.Update();
			BeltManager.Update();
			BeltRope.UpdateResistance();
			CartCamInteraction.TickBodyCam();
			CartCamInteraction.TickPower();
			CartCamAudioMonitor.TickIsolationKey();
			if (StackerInteraction.Update())
			{
				HitchInteraction.Yield();
				BeltInteraction.Yield();
				CartCamInteraction.Yield();
			}
			else if (BeltInteraction.Update())
			{
				HitchInteraction.Yield();
				CartCamInteraction.Yield();
			}
			else if (CartCamInteraction.Update())
			{
				HitchInteraction.Yield();
				BeltInteraction.Yield();
			}
			else
			{
				BeltInteraction.BeforeHitch();
				HitchInteraction.Update();
				StackerInteraction.LateHint(HitchInteraction.HasSelection);
				BeltInteraction.AfterHitch(HitchInteraction.HasTarget || HitchInteraction.HasSelection);
			}
			CartCamInteraction.TickViewer();
			CartCamVanMonitor.Ensure();
			CartCamVanMonitor.TickPlaceKey();
			CartCamVanMonitor.Tick();
			CartCamVanView.Tick();
			InteractionPrompt.LateTick();
			HoldProgressRing.LateTick();
		}

		private void FixedUpdate()
		{
			HitchManager.FixedTick();
			StackerManager.FixedTick();
			BeltRope.FixedTick();
			HeadHanging.FixedTick();
		}
	}
}
namespace UniversalCartHitch.Visuals
{
	internal static class CouplingGeometry
	{
		private const int Round = 24;

		internal const float BallCenterZ = 0.085f;

		private const float BallRadius = 0.04f;

		private static readonly Vector3 PlateSize = new Vector3(0.2f, 0.14f, 0.014f);

		private const float TubeRadius = 0.022f;

		internal static MeshBuilder HookBracket()
		{
			//IL_0021: 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_0044: 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_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_0069: 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)
			MeshBuilder meshBuilder = new MeshBuilder();
			meshBuilder.Box(new Vector3(0f, 0f, PlateSize.z * 0.5f), PlateSize);
			meshBuilder.Lathe((IReadOnlyList<Vector2>)(object)new Vector2[2]
			{
				new Vector2(0.014f, 0.045f),
				new Vector2(0.04f, 0.026f)
			}, 24, smooth: false);
			return meshBuilder;
		}

		internal static MeshBuilder HookSteel()
		{
			//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_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_0044: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_015c: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			MeshBuilder meshBuilder = new MeshBuilder();
			Vector2[] outline = (Vector2[])(object)new Vector2[3]
			{
				new Vector2(0.014f, 0.012f),
				new Vector2(0.023f, 0.012f),
				new Vector2(0.023f, 0f)
			};
			float[] array = new float[2] { -0.075f, 0.075f };
			foreach (float num in array)
			{
				float[] array2 = new float[2] { -0.045f, 0.045f };
				foreach (float num2 in array2)
				{
					meshBuilder.Lathe(outline, 6, smooth: false, new Vector3(num, num2, 0f));
				}
			}
			meshBuilder.Lathe((IReadOnlyList<Vector2>)(object)new Vector2[5]
			{
				new Vector2(0.04f, 0.026f),
				new Vector2(0.04f, 0.033f),
				new Vector2(0.048f, 0.033f),
				new Vector2(0.048f, 0.018f),
				new Vector2(0.062f, 0.018f)
			}, 24, smooth: false);
			meshBuilder.Sphere(0.085f, 0.04f, 24, 14);
			return meshBuilder;
		}

		internal static MeshBuilder CouplerHead()
		{
			//IL_0019: 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_002f: 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_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_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_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_0087: 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_0096: 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)
			MeshBuilder meshBuilder = new MeshBuilder();
			meshBuilder.Lathe((IReadOnlyList<Vector2>)(object)new Vector2[6]
			{
				new Vector2(-0.012f, 0.036f),
				new Vector2(-0.012f, 0.046f),
				new Vector2(0f, 0.052f),
				new Vector2(0.035f, 0.052f),
				new Vector2(0.06f, 0.028f),
				new Vector2(0.06f, 0.022f)
			}, 24, smooth: false);
			return meshBuilder;
		}

		internal static MeshBuilder CouplerAccent()
		{
			//IL_0016: 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_0045: 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_0077: 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_008d: 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_00a3: 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_00b9: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			MeshBuilder meshBuilder = new MeshBuilder();
			meshBuilder.Box(new Vector3(0f, 0.056f, 0.016f), new Vector3(0.032f, 0.014f, 0.046f));
			meshBuilder.Box(new Vector3(0f, 0.071f, 0.03f), new Vector3(0.02f, 0.016f, 0.066f));
			meshBuilder.Lathe((IReadOnlyList<Vector2>)(object)new Vector2[4]
			{
				new Vector2(0.06f, 0.022f),
				new Vector2(0.06f, 0.033f),
				new Vector2(0.072f, 0.033f),
				new Vector2(0.072f, 0.022f)
			}, 24, smooth: false);
			return meshBuilder;
		}

		internal static MeshBuilder Tube()
		{
			//IL_0019: 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_002f: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			MeshBuilder meshBuilder = new MeshBuilder();
			meshBuilder.Lathe((IReadOnlyList<Vector2>)(object)new Vector2[2]
			{
				new Vector2(0f, 0.022f),
				new Vector2(1f, 0.022f)
			}, 24, smooth: false);
			return meshBuilder;
		}
	}
	internal sealed class CouplingVisualProvider : IHitchVisualProvider
	{
		private static readonly Color DarkColor = new Color(0.1f, 0.1f, 0.12f);

		private static readonly Color SteelColor = new Color(0.72f, 0.74f, 0.78f);

		private static readonly Color AccentColor = new Color(1f, 0.45f, 0.04f);

		private static Mesh? _hookBracket;

		private static Mesh? _hookSteel;

		private static Mesh? _couplerHead;

		private static Mesh? _couplerAccent;

		private static Mesh? _tube;

		private static Material? _dark;

		private static Material? _steel;

		private static Material? _accent;

		public float MinimumBarLength => 0.16f;

		public GameObject CreateHook(HitchableObject owner)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			EnsureAssets(owner, owner);
			GameObject val = new GameObject("Hook");
			AddPart(val.transform, "Bracket", _hookBracket, _dark);
			AddPart(val.transform, "Tow Ball", _hookSteel, _steel);
			GameObject val2 = new GameObject("BarAttach");
			val2.transform.SetParent(val.transform, false);
			val2.transform.localPosition = new Vector3(0f, 0f, 0.085f);
			return val;
		}

		public GameObject CreateBar(HitchableObject a, HitchableObject b)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			EnsureAssets(a, b);
			GameObject val = new GameObject("Bar");
			AddCouplerHead(val.transform, "StartCap");
			AddCouplerHead(val.transform, "EndCap");
			AddPart(val.transform, "Middle", _tube, _dark);
			return val;
		}

		private static void AddCouplerHead(Transform parent, string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			AddPart(val.transform, "Head", _couplerHead, _dark);
			AddPart(val.transform, "Latch", _couplerAccent, _accent);
		}

		private static void AddPart(Transform parent, string name, Mesh? mesh, Material? material)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer val2 = val.AddComponent<MeshRenderer>();
			if ((Object)(object)material != (Object)null)
			{
				((Renderer)val2).sharedMaterial = material;
			}
		}

		private static void EnsureAssets(HitchableObject a, HitchableObject b)
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_hookBracket == (Object)null)
			{
				_hookBracket = CouplingGeometry.HookBracket().ToMesh("UCH Hook Bracket");
			}
			if ((Object)(object)_hookSteel == (Object)null)
			{
				_hookSteel = CouplingGeometry.HookSteel().ToMesh("UCH Hook Steel");
			}
			if ((Object)(object)_couplerHead == (Object)null)
			{
				_couplerHead = CouplingGeometry.CouplerHead().ToMesh("UCH Coupler Head");
			}
			if ((Object)(object)_couplerAccent == (Object)null)
			{
				_couplerAccent = CouplingGeometry.CouplerAccent().ToMesh("UCH Coupler Accent");
			}
			if ((Object)(object)_tube == (Object)null)
			{
				_tube = CouplingGeometry.Tube().ToMesh("UCH Tube");
			}
			if ((Object)(object)_dark == (Object)null)
			{
				_dark = CreateMaterial(a, b, "UCH Dark Paint", DarkColor, 0.3f, 0.45f);
			}
			if ((Object)(object)_steel == (Object)null)
			{
				_steel = CreateMaterial(a, b, "UCH Steel", SteelColor, 0.9f, 0.75f);
			}
			if ((Object)(object)_accent == (Object)null)
			{
				_accent = CreateMaterial(a, b, "UCH Accent", AccentColor, 0f, 0.5f);
			}
		}

		private static Material? CreateMaterial(HitchableObject a, HitchableObject b, string name, Color color, float metallic, float smoothness)
		{
			//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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			Shader val = FindShader(a) ?? FindShader(b) ?? Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val)
			{
				name = name,
				hideFlags = (HideFlags)61
			};
			if (val2.HasProperty("_Color"))
			{
				val2.SetColor("_Color", color);
			}
			if (val2.HasProperty("_Metallic"))
			{
				val2.SetFloat("_Metallic", metallic);
			}
			if (val2.HasProperty("_Glossiness"))
			{
				val2.SetFloat("_Glossiness", smoothness);
			}
			if (val2.HasProperty("_EmissionColor"))
			{
				val2.SetColor("_EmissionColor", Color.black);
			}
			return val2;
		}

		private static Shader? FindShader(HitchableObject obj)
		{
			MeshRenderer val = null;
			PhysGrabCart cart = obj.Cart;
			if ((Object)(object)cart != (Object)null)
			{
				val = cart.cartMesh;
			}
			if ((Object)(object)val == (Object)null)
			{
				val = obj.Source.GetComponentInChildren<MeshRenderer>();
			}
			if ((Object)(object)val == (Object)null || (Object)(object)((Renderer)val).sharedMaterial == (Object)null)
			{
				return null;
			}
			return ((Renderer)val).sharedMaterial.shader;
		}
	}
	internal sealed class HitchPreview : MonoBehaviour
	{
		private static HitchPreview? _instance;

		private static bool _unavailable;

		private HitchRig? _rig;

		private Renderer[] _renderers = Array.Empty<Renderer>();

		private Material[] _originals = Array.Empty<Material>();

		private HitchableObject? _a;

		private HitchableObject? _b;

		private HitchEnd _endA;

		private HitchEnd _endB;

		private HookMount _mountA;

		private HookMount _mountB;

		private bool _invalid;

		private int _materialsVersion = -1;

		internal static bool IsShowing
		{
			get
			{
				if ((Object)(object)_instance != (Object)null)
				{
					return ((Component)_instance).gameObject.activeSelf;
				}
				return false;
			}
		}

		internal static void Show(HitchableObject a, HitchEnd endA, HitchableObject b, HitchEnd endB, bool invalid)
		{
			if (_unavailable)
			{
				return;
			}
			if ((Object)(object)_instance == (Object)null)
			{
				if ((Object)(object)PreviewMaterials.TransparentShader == (Object)null)
				{
					_unavailable = true;
					return;
				}
				HitchRig hitchRig = HitchRig.Create("UniversalCartHitch Hitch Preview", HitchVisualManager.Provider, a, b);
				hitchRig.Root.SetActive(false);
				_instance = hitchRig.Root.AddComponent<HitchPreview>();
				_instance.Adopt(hitchRig);
			}
			_instance.Present(a, endA, b, endB, invalid);
		}

		internal static void Hide()
		{
			if ((Object)(object)_instance != (Object)null && ((Component)_instance).gameObject.activeSelf)
			{
				((Component)_instance).gameObject.SetActive(false);
			}
		}

		private void Adopt(HitchRig rig)
		{
			_rig = rig;
			_renderers = rig.Root.GetComponentsInChildren<Renderer>(true);
			_originals = (Material[])(object)new Material[_renderers.Length];
			for (int i = 0; i < _renderers.Length; i++)
			{
				_originals[i] = _renderers[i].sharedMaterial;
				_renderers[i].shadowCastingMode = (ShadowCastingMode)0;
				_renderers[i].receiveShadows = false;
			}
		}

		private void Present(HitchableObject a, HitchEnd endA, HitchableObject b, HitchEnd endB, bool invalid)
		{
			if (a != _a || b != _b || endA != _endA || endB != _endB)
			{
				_a = a;
				_b = b;
				_endA = endA;
				_endB = endB;
				_mountA = HookMountFinder.Find(a, endA, log: false);
				_mountB = HookMountFinder.Find(b, endB, log: false);
			}
			Material val = ((_originals.Length != 0 && (Object)(object)_originals[0] != (Object)null) ? PreviewMaterials.Get(_originals[0], invalid) : null);
			if (_materialsVersion != PreviewMaterials.Version || invalid != _invalid || (Object)(object)val == (Object)null)
			{
				_invalid = invalid;
				for (int i = 0; i < _renderers.Length; i++)
				{
					Material val2 = (((Object)(object)_originals[i] != (Object)null) ? PreviewMaterials.Get(_originals[i], invalid) : null);
					if ((Object)(object)val2 != (Object)null)
					{
						_renderers[i].sharedMaterial = val2;
					}
				}
				_materialsVersion = PreviewMaterials.Version;
			}
			if (Place() && !((Component)this).gameObject.activeSelf)
			{
				((Component)this).gameObject.SetActive(true);
			}
		}

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

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

		private void LateUpdate()
		{
			Refresh();
		}

		private void Refresh()
		{
			if (!((Object)(object)this == (Object)null) && !Place() && ((Component)this).gameObject.activeSelf)
			{
				((Component)this).gameObject.SetActive(false);
			}
		}

		private bool Place()
		{
			if (_rig == null || _a == null || _b == null || !_a.IsAlive || !_b.IsAlive)
			{
				return false;
			}
			return _rig.Place(_mountA, _endA, _mountB, _endB);
		}
	}
	internal sealed class HitchRig
	{
		private readonly Transform _bar;

		private readonly Transform _hookA;

		private readonly Transform _hookB;

		private readonly Transform? _attachA;

		private readonly Transform? _attachB;

		private readonly Transform? _barMiddle;

		private readonly Transform? _barEndCap;

		private readonly Transform? _barStartCap;

		private readonly float _naturalLength;

		private const float MinimumSize = 0.2f;

		internal GameObject Root { get; }

		internal Vector3 BarStart { get; private set; }

		internal Vector3 BarEnd { get; private set; }

		private HitchRig(GameObject root, Transform bar, Transform hookA, Transform hookB, float minimumBarLength)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Root = root;
			_bar = bar;
			_hookA = hookA;
			_hookB = hookB;
			_attachA = hookA.Find("BarAttach");
			_attachB = hookB.Find("BarAttach");
			_barMiddle = bar.Find("Middle");
			_barEndCap = bar.Find("EndCap");
			_barStartCap = bar.Find("StartCap");
			float num;
			Vector3 localPosition;
			if (!((Object)(object)_attachA != (Object)null))
			{
				num = 0f;
			}
			else
			{
				localPosition = _attachA.localPosition;
				num = ((Vector3)(ref localPosition)).magnitude;
			}
			float num2 = num;
			float num3;
			if (!((Object)(object)_attachB != (Object)null))
			{
				num3 = 0f;
			}
			else
			{
				localPosition = _attachB.localPosition;
				num3 = ((Vector3)(ref localPosition)).magnitude;
			}
			float num4 = num3;
			_naturalLength = num2 + num4 + Mathf.Max(0.01f, minimumBarLength);
		}

		internal static HitchRig Create(string name, IHitchVisualProvider provider, HitchableObject a, HitchableObject b)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			Object.DontDestroyOnLoad((Object)(object)val);
			Transform bar = Adopt(provider.CreateBar(a, b), val.transform);
			Transform hookA = Adopt(provider.CreateHook(a), val.transform);
			Transform hookB = Adopt(provider.CreateHook(b), val.transform);
			return new HitchRig(val, bar, hookA, hookB, provider.MinimumBarLength);
		}

		internal bool Place(HookMount mountA, HitchEnd endA, HookMount mountB, HitchEnd endB)
		{
			//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_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_0055: 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_0057: 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_007a: 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_0086: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_00eb: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_010d: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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_01b6: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Root == (Object)null || (Object)(object)mountA.Space == (Object)null || (Object)(object)mountB.Space == (Object)null)
			{
				return false;
			}
			Vector3 val = mountA.Space.TransformPoint(mountA.Local);
			Vector3 val2 = mountB.Space.TransformPoint(mountB.Local);
			float num = Mathf.Clamp(Vector3.Distance(val, val2) / _naturalLength, 0.2f, 1f);
			Vector3 localScale = Vector3.one * num;
			_hookA.localScale = localScale;
			_hookB.localScale = localScale;
			_hookA.SetPositionAndRotation(val, HookRotation(mountA, endA));
			_hookB.SetPositionAndRotation(val2, HookRotation(mountB, endB));
			Vector3 val3 = (((Object)(object)_attachA != (Object)null) ? _attachA.position : val);
			Vector3 val4 = (((Object)(object)_attachB != (Object)null) ? _attachB.position : val2);
			BarStart = val3;
			BarEnd = val4;
			Vector3 val5 = val4 - val3;
			float magnitude = ((Vector3)(ref val5)).magnitude;
			_bar.position = val3;
			if (magnitude > 0.001f)
			{
				_bar.rotation = Quaternion.LookRotation(val5 / magnitude, Vector3.up);
			}
			if ((Object)(object)_barMiddle != (Object)null)
			{
				_bar.localScale = Vector3.one;
				_barMiddle.localScale = new Vector3(num, num, magnitude);
				if ((Object)(object)_barStartCap != (Object)null)
				{
					_barStartCap.localScale = localScale;
				}
				if ((Object)(object)_barEndCap != (Object)null)
				{
					_barEndCap.localScale = localScale;
					_barEndCap.localPosition = new Vector3(0f, 0f, magnitude);
					_barEndCap.localRotation = Quaternion.Euler(0f, 180f, 0f);
				}
			}
			else
			{
				_bar.localScale = new Vector3(num, num, magnitude);
			}
			return true;
		}

		private static Quaternion HookRotation(HookMount mount, HitchEnd end)
		{
			//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_002b: 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_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)
			Quaternion rotation = mount.Space.rotation;
			if (end != HitchEnd.Front)
			{
				return rotation * Quaternion.Euler(0f, 180f, 0f);
			}
			return rotation;
		}

		private static Transform Adopt(GameObject part, Transform parent)
		{
			StripPhysics(part);
			part.transform.SetParent(parent, false);
			return part.transform;
		}

		private static void StripPhysics(GameObject part)
		{
			Joint[] componentsInChildren = part.GetComponentsInChildren<Joint>(true);
			foreach (Joint val in componentsInChildren)
			{
				Object.DestroyImmediate((Object)(object)val);
			}
			Rigidbody[] componentsInChildren2 = part.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody val2 in componentsInChildren2)
			{
				Object.DestroyImmediate((Object)(object)val2);
			}
			Collider[] componentsInChildren3 = part.GetComponentsInChildren<Collider>(true);
			foreach (Collider val3 in componentsInChildren3)
			{
				Object.DestroyImmediate((Object)(object)val3);
			}
		}
	}
	internal sealed class HitchVisual : MonoBehaviour
	{
		private HitchLink? _link;

		private HitchRig? _rig;

		private HookMount _mountA;

		private HookMount _mountB;

		internal Vector3 BarStart
		{
			get
			{
				//IL_0014: 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)
				if (_rig == null)
				{
					return Vector3.zero;
				}
				return _rig.BarStart;
			}
		}

		internal Vector3 BarEnd
		{
			get
			{
				//IL_0014: 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)
				if (_rig == null)
				{
					return Vector3.zero;
				}
				return _rig.BarEnd;
			}
		}

		internal static HitchVisual Create(HitchLink link, IHitchVisualProvider provider)
		{
			HitchRig hitchRig = HitchRig.Create("UniversalCartHitch Hitch Visual", provider, link.A, link.B);
			HitchVisual hitchVisual = hitchRig.Root.AddComponent<HitchVisual>();
			hitchVisual._link = link;
			hitchVisual._rig = hitchRig;
			hitchVisual._mountA = HookMountFinder.Find(link.A, link.EndA);
			hitchVisual._mountB = HookMountFinder.Find(link.B, link.EndB);
			hitchVisual.Refresh();
			return hitchVisual;
		}

		internal void Remove()
		{
			_link = null;
			((Component)this).gameObject.SetActive(false);
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}

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

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

		private void LateUpdate()
		{
			Refresh();
		}

		private void Refresh()
		{
			HitchLink link = _link;
			if ((link == null || _rig == null || !link.A.IsAlive || !link.B.IsAlive || !_rig.Place(_mountA, link.EndA, _mountB, link.EndB)) && (Object)(object)this != (Object)null && ((Component)this).gameObject.activeSelf)
			{
				Remove();
			}
		}
	}
	internal static class HitchVisualManager
	{
		private static readonly Dictionary<HitchLink, HitchVisual> Visuals = new Dictionary<HitchLink, HitchVisual>();

		private static bool _initialized;

		internal static IHitchVisualProvider Provider { get; set; } = new CouplingVisualProvider();

		internal static void Initialize()
		{
			if (!_initialized)
			{
				_initialized = true;
				HitchManager.LinkAdded += OnLinkAdded;
				HitchManager.LinkRemoved += OnLinkRemoved;
			}
		}

		internal static void GetSegment(HitchLink link, out Vector3 start, out Vector3 end)
		{
			//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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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)
			if (Visuals.TryGetValue(link, out HitchVisual value) && (Object)(object)value != (Object)null)
			{
				start = value.BarStart;
				end = value.BarEnd;
			}
			else
			{
				start = link.WorldTipA;
				end = link.WorldTipB;
			}
		}

		private static void OnLinkAdded(HitchLink link)
		{
			if (!PluginConfig.ShowHitchVisuals.Value)
			{
				return;
			}
			try
			{
				Visuals[link] = HitchVisual.Create(link, Provider);
			}
			catch (Exception arg)
			{
				UniversalCartHitch.Logger.LogError($"Could not create the hitch visual (the hitch itself still works): {arg}");
			}
		}

		private static void OnLinkRemoved(HitchLink link)
		{
			if (Visuals.TryGetValue(link, out HitchVisual value))
			{
				Visuals.Remove(link);
				if ((Object)(object)value != (Object)null)
				{
					value.Remove();
				}
			}
		}
	}
	internal static class HitchVisualNames
	{
		internal const string BarAttach = "BarAttach";

		internal const string StartCap = "StartCap";

		internal const string Middle = "Middle";

		internal const string EndCap = "EndCap";
	}
	internal readonly struct HookMount
	{
		internal Transform Space { get; }

		internal Vector3 Local { get; }

		internal HookMount(Transform space, Vector3 local)
		{
			//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)
			Space = space;
			Local = local;
		}
	}
	internal static class HookMountFinder
	{
		private const float PocketCenterX = 0.02f;

		private const float PocketHeight = -0.08f;

		private const float PocketFrontZ = 0.39f;

		private const float PocketRearZ = -0.401f;

		private const float ScoutRearHeight = 0.25f;

		private const float ScoutRearZ = -0.89f;

		private const float ScoutFrontHeight = 0.22f;

		private const float ScoutFrontZ = 0.935f;

		private const float HaulerRearHeight = 0.25f;

		private const float HaulerRearZ = -1.299f;

		private const float HaulerFrontHeight = 0.22f;

		private const float HaulerFrontZ = 0.935f;

		private const float StartOutside = 0.5f;

		private static readonly float[] HeightSearch = new float[11]
		{
			0f, -0.05f, 0.05f, -0.1f, 0.1f, -0.15f, 0.15f, -0.2f, 0.2f, -0.3f,
			0.3f
		};

		internal static HookMount Find(HitchableObject obj, HitchEnd end, bool log = true)
		{
			//IL_018b: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_016e: Unknown result type (might be due to invalid IL or missing references)
			Transform val = HitchGeometry.RootOf(obj);
			bool flag = end == HitchEnd.Front;
			float num = (flag ? 1f : (-1f));
			HookMount result = obj.Kind switch
			{
				HitchableKind.LargeCart => new HookMount(val, FindOnBodySurface(obj, end, PluginConfig.LargeCartMountHeight.Value, flag ? PluginConfig.LargeCartFrontDepth.Value : PluginConfig.LargeCartRearDepth.Value)), 
				HitchableKind.PocketCart => new HookMount(val, new Vector3(0.02f, -0.08f + PluginConfig.PocketCartHeightAdjust.Value, (flag ? 0.39f : (-0.401f)) + num * (flag ? PluginConfig.PocketCartFrontAdjust.Value : PluginConfig.PocketCartRearAdjust.Value))), 
				HitchableKind.Scout => OnVisibleModel(obj, val, new Vector3(0f, (flag ? 0.22f : 0.25f) + PluginConfig.ScoutHeightAdjust.Value, (flag ? 0.935f : (-0.89f)) + num * (flag ? PluginConfig.ScoutFrontAdjust.Value : PluginConfig.ScoutRearAdjust.Value))), 
				HitchableKind.Hauler => OnVisibleModel(obj, val, new Vector3(0f, (flag ? 0.22f : 0.25f) + PluginConfig.HaulerHeightAdjust.Value, (flag ? 0.935f : (-1.299f)) + num * (flag ? PluginConfig.HaulerFrontAdjust.Value : PluginConfig.HaulerRearAdjust.Value))), 
				_ => new HookMount(val, FindOnBodySurface(obj, end, HitchGeometry.HitchHeight(obj), 0f)), 
			};
			if (log)
			{
				ModLog logger = UniversalCartHitch.Logger;
				object[] obj2 = new object[5] { obj.Kind, obj.ObjectName, end, null, null };
				Vector3 local = result.Local;
				obj2[3] = ((Vector3)(ref local)).ToString("F3");
				obj2[4] = ((Object)result.Space).name;
				logger.LogDebug(string.Format("Hook mount: {0} '{1}' [{2}] at local {3} of '{4}'.", obj2));
			}
			return result;
		}

		private static HookMount OnVisibleModel(HitchableObject obj, Transform root, Vector3 local)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			Transform space = (Transform)(((Object)(object)obj.Vehicle != (Object)null && (Object)(object)obj.Vehicle.meshTransform != (Object)null) ? ((object)obj.Vehicle.meshTransform) : ((object)root));
			return new HookMount(space, local);
		}

		private static Vector3 FindOnBodySurface(HitchableObject obj, HitchEnd end, float height, float depth)
		{
			//IL_002c: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			Transform val = HitchGeometry.RootOf(obj);
			float num = ((end == HitchEnd.Front) ? 1f : (-1f));
			if (!HitchGeometry.TryGetExtents(obj, out var extents))
			{
				return new Vector3(0f, height, 0f);
			}
			float num2 = ((end == HitchEnd.Front) ? extents.FrontZ : extents.RearZ);
			float num3 = Mathf.Min(0.8f, extents.Length * 0.45f);
			Vector3 val2 = val.TransformDirection(new Vector3(0f, 0f, 0f - num));
			Collider[] componentsInChildren = ((Component)val).GetComponentsInChildren<Collider>();
			Vector3 result = default(Vector3);
			((Vector3)(ref result))..ctor(extents.CenterX, height, num2);
			float[] heightSearch = HeightSearch;
			Vector3 val3 = default(Vector3);
			Ray val4 = default(Ray);
			RaycastHit val7 = default(RaycastHit);
			foreach (float num4 in heightSearch)
			{
				((Vector3)(ref val3))..ctor(extents.CenterX, height + num4, num2 + num * 0.5f);
				((Ray)(ref val4))..ctor(val.TransformPoint(val3), val2);
				float num5 = float.MaxValue;
				Vector3 val5 = Vector3.zero;
				Collider[] array = componentsInChildren;
				foreach (Collider val6 in array)
				{
					if (!((Object)(object)val6 == (Object)null) && !val6.isTrigger && val6.enabled && !HitchGeometry.IsRollingCollider(val6, obj) && val6.Raycast(val4, ref val7, 0.5f + num3) && ((RaycastHit)(ref val7)).distance < num5)
					{
						num5 = ((RaycastHit)(ref val7)).distance;
						val5 = ((RaycastHit)(ref val7)).point;
					}
				}
				if (num5 < float.MaxValue)
				{
					result = val.InverseTransformPoint(val5);
					break;
				}
			}
			result.z += num * depth;
			return result;
		}
	}
	internal interface IHitchVisualProvider
	{
		float MinimumBarLength { get; }

		GameObject CreateBar(HitchableObject a, HitchableObject b);

		GameObject CreateHook(HitchableObject owner);
	}
	internal sealed class MeshBuilder
	{
		internal readonly List<Vector3> Vertices = new List<Vector3>();

		internal readonly List<Vector3> Normals = new List<Vector3>();

		internal readonly List<int> Triangles = new List<int>();

		internal MeshBuilder Lathe(IReadOnlyList<Vector2> outline, int segments, bool smooth, Vector3 offset = default(Vector3))
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//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_0029: 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_0033: 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_003e: 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_0061: 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_0073: 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_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_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_00f9: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			int num = outline.Count - 1;
			Vector2[] array = (Vector2[])(object)new Vector2[num];
			Vector2 val2;
			for (int i = 0; i < num; i++)
			{
				Vector2 val = outline[i + 1] - outline[i];
				int num2 = i;
				val2 = new Vector2(0f - val.y, val.x);
				array[num2] = ((Vector2)(ref val2)).normalized;
			}
			for (int j = 0; j < num; j++)
			{
				val2 = outline[j + 1] - outline[j];
				if (((Vector2)(ref val2)).sqrMagnitude < 1E-10f)
				{
					continue;
				}
				Vector2 normal = array[j];
				Vector2 normal2 = array[j];
				if (smooth)
				{
					if (j > 0)
					{
						val2 = array[j - 1] + array[j];
						normal = ((Vector2)(ref val2)).normalized;
					}
					if (j < num - 1)
					{
						val2 = array[j] + array[j + 1];
						normal2 = ((Vector2)(ref val2)).normalized;
					}
				}
				int num3 = AddRing(outline[j], normal, segments, offset);
				int num4 = AddRing(outline[j + 1], normal2, segments, offset);
				for (int k = 0; k < segments; k++)
				{
					AddTriangle(num3 + k, num3 + k + 1, num4 + k + 1);
					AddTriangle(num3 + k, num4 + k + 1, num4 + k);
				}
			}
			return this;
		}

		internal MeshBuilder Sphere(float centerZ, float radius, int segments, int rings, Vector3 offset = default(Vector3))
		{
			//IL_002e: 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)
			List<Vector2> list = new List<Vector2>(rings + 1);
			for (int i = 0; i <= rings; i++)
			{
				float num = MathF.PI * (float)i / (float)rings;
				list.Add(new Vector2(centerZ - radius * Mathf.Cos(num), radius * Mathf.Sin(num)));
			}
			return Lathe(list, segments, smooth: true, offset);
		}

		internal MeshBuilder Box(Vector3 center, Vector3 size)
		{
			//IL_0000: 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_000e: 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_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_0029: 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_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_0045: 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_0051: 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_0063: 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_006d: 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_0079: 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_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)
			//IL_0095: 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_00a1: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_00eb: 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)
			Vector3 val = size * 0.5f;
			AddFace(center, Vector3.right, Vector3.up, Vector3.forward, val.x, val.y, val.z);
			AddFace(center, Vector3.left, Vector3.up, Vector3.back, val.x, val.y, val.z);
			AddFace(center, Vector3.up, Vector3.forward, Vector3.right, val.y, val.z, val.x);
			AddFace(center, Vector3.down, Vector3.forward, Vector3.left, val.y, val.z, val.x);
			AddFace(center, Vector3.forward, Vector3.up, Vector3.left, val.z, val.y, val.x);
			AddFace(center, Vector3.back, Vector3.up, Vector3.right, val.z, val.y, val.x);
			return this;
		}

		internal Mesh ToMesh(string name)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			Mesh val = new Mesh
			{
				name = name,
				hideFlags = (HideFlags)61
			};
			val.SetVertices(Vertices);
			val.SetNormals(Normals);
			val.SetTriangles(Triangles, 0);
			val.RecalculateBounds();
			return val;
		}

		private int AddRing(Vector2 point, Vector2 normal, int segments, Vector3 offset)
		{
			//IL_0031: 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_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_004f: 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_0067: 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)
			int count = Vertices.Count;
			for (int i = 0; i <= segments; i++)
			{
				float num = MathF.PI * 2f * (float)i / (float)segments;
				float num2 = Mathf.Cos(num);
				float num3 = Mathf.Sin(num);
				Vertices.Add(new Vector3(point.y * num2, point.y * num3, point.x) + offset);
				Normals.Add(new Vector3(normal.y * num2, normal.y * num3, normal.x));
			}
			return count;
		}

		private void AddFace(Vector3 center, Vector3 normal, Vector3 up, Vector3 right, float depth, float halfUp, float halfRight)
		{
			//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_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_001a: 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_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_002f: 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_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_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_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_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_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_007d: 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_0096: 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_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)
			//IL_00a4: 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_00ad: 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)
			int count = Vertices.Count;
			Vector3 val = center + normal * depth;
			Vertices.Add(val - up * halfUp - right * halfRight);
			Vertices.Add(val + up * halfUp - right * halfRight);
			Vertices.Add(val + up * halfUp + right * halfRight);
			Vertices.Add(val - up * halfUp + right * halfRight);
			for (int i = 0; i < 4; i++)
			{
				Normals.Add(normal);
			}
			AddTriangle(count, count + 1, count + 2);
			AddTriangle(count, count + 2, count + 3);
		}

		private void AddTriangle(int a, int b, int c)
		{
			//IL_0007: 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_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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0057: 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_0068: 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)
			Vector3 val = Vector3.Cross(Vertices[b] - Vertices[a], Vertices[c] - Vertices[a]);
			if (!(((Vector3)(ref val)).sqrMagnitude < 1E-14f))
			{
				if (Vector3.Dot(val, Normals[a] + Normals[b] + Normals[c]) < 0f)
				{
					int num = c;
					c = b;
					b = num;
				}
				Triangles.Add(a);
				Triangles.Add(b);
				Triangles.Add(c);
			}
		}
	}
	internal static class PreviewMaterials
	{
		private static readonly Color InvalidTint = new Color(1f, 0.22f, 0.18f);

		private static readonly Color FallbackColor = new Color(0.6f, 0.6f, 0.6f);

		private static readonly Dictionary<Material, Material> Valid = new Dictionary<Material, Material>();

		private static readonly Dictionary<Material, Material> Invalid = new Dictionary<Material, Material>();

		private static Shader? _shader;

		private static bool _searched;

		private static float _opacity = -1f;

		internal static int Version { get; private set; }

		internal static Shader? TransparentShader
		{
			get
			{
				if (_searched)
				{
					return _shader;
				}
				_searched = true;
				_shader = Shader.Find("Sprites/Default");
				if ((Object)(object)_shader == (Object)null)
				{
					_shader = Shader.Find("UI/Default");
				}
				if ((Object)(object)_shader == (Object)null)
				{
					_shader = Shader.Find("Legacy Shaders/Transparent/Diffuse");
				}
				if ((Object)(object)_shader == (Object)null)
				{
					UniversalCartHitch.Logger.LogWarning("No see-through shader was found in the game; hitch previews and the selection marker will not be shown.");
				}
				else
				{
					UniversalCartHitch.Logger.LogDebug("Preview visuals use the '" + ((Object)_shader).name + "' shader.");
				}
				return _shader;
			}
		}

		internal static Material? Get(Material original, bool invalid)
		{
			//IL_0074: 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_0079: 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_0093: 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_007e: 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_008a: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			Shader transparentShader = TransparentShader;
			if ((Object)(object)transparentShader == (Object)null)
			{
				return null;
			}
			float value = PluginConfig.PreviewOpacity.Value;
			if (!Mathf.Approximately(value, _opacity))
			{
				Clear();
				_opacity = value;
			}
			Dictionary<Material, Material> dictionary = (invalid ? Invalid : Valid);
			if (dictionary.TryGetValue(original, out var value2) && (Object)(object)value2 != (Object)null)
			{
				return value2;
			}
			Color val = (original.HasProperty("_Color") ? original.GetColor("_Color") : FallbackColor);
			Color color = (invalid ? Color.Lerp(val, InvalidTint, 0.75f) : Color.Lerp(val, Color.white, 0.3f));
			return dictionary[original] = Create(transparentShader, color, value, invalid ? "UCH Preview (invalid)" : "UCH Preview");
		}

		internal static Material? CreatePlain(Color color, float opacity, string name)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Shader transparentShader = TransparentShader;
			if (!((Object)(object)transparentShader == (Object)null))
			{
				return Create(transparentShader, color, opacity, name);
			}
			return null;
		}

		private static Material Create(Shader shader, Color color, float opacity, string name)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0029: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			color.a = opacity;
			Material val = new Material(shader)
			{
				name = name,
				hideFlags = (HideFlags)61,
				renderQueue = 3000
			};
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", color);
			}
			return val;
		}

		private static void Clear()
		{
			foreach (Material value in Valid.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)value);
				}
			}
			foreach (Material value2 in Invalid.Values)
			{
				if ((Object)(object)value2 != (Object)null)
				{
					Object.Destroy((Object)(object)value2);
				}
			}
			Valid.Clear();
			Invalid.Clear();
			Version++;
		}
	}
	internal static class SelectionHighlight
	{
		private static readonly Color MarkerColor = new Color(0.35f, 1f, 0.3f);

		private static readonly int ColorId = Shader.PropertyToID("_Color");

		private static readonly List<Renderer> Tinted = new List<Renderer>();

		private static readonly MaterialPropertyBlock Block = new MaterialPropertyBlock();

		private static HitchableObject? _current;

		private static SelectionMarker? _marker;

		internal static void Set(HitchableObject? obj)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: 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_0190: Unknown result type (might be due to invalid IL or missing references)
			if (obj == _current)
			{
				if (_current != null && !_current.IsAlive)
				{
					Clear();
				}
				return;
			}
			Clear();
			if (obj == null || !obj.IsAlive)
			{
				return;
			}
			float value = PluginConfig.SelectionHighlightStrength.Value;
			if (value <= 0f)
			{
				return;
			}
			_current = obj;
			Transform space = ModelSpace(obj);
			bool flag = false;
			Bounds bounds = default(Bounds);
			Color val = default(Color);
			foreach (Renderer item in CollectRenderers(obj, space))
			{
				if ((Object)(object)item == (Object)null || !item.enabled || (!(item is MeshRenderer) && !(item is SkinnedMeshRenderer)))
				{
					continue;
				}
				Material sharedMaterial = item.sharedMaterial;
				if (!((Object)(object)sharedMaterial == (Object)null) && sharedMaterial.HasProperty(ColorId) && !item.HasPropertyBlock())
				{
					Color color = sharedMaterial.GetColor(ColorId);
					((Color)(ref val))..ctor(color.r * Mathf.Lerp(1f, 0.75f, value) + 0.02f * value, color.g * Mathf.Lerp(1f, 1.7f, value) + 0.1f * value, color.b * Mathf.Lerp(1f, 0.75f, value) + 0.02f * value, color.a);
					Block.Clear();
					Block.SetColor(ColorId, val);
					item.SetPropertyBlock(Block);
					Tinted.Add(item);
					if (flag)
					{
						((Bounds)(ref bounds)).Encapsulate(item.bounds);
						continue;
					}
					bounds = item.bounds;
					flag = true;
				}
			}
			if (flag)
			{
				ShowMarker(space, bounds, value);
			}
		}

		internal static void Clear()
		{
			foreach (Renderer item in Tinted)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.SetPropertyBlock((MaterialPropertyBlock)null);
				}
			}
			Tinted.Clear();
			_current = null;
			if ((Object)(object)_marker != (Object)null)
			{
				_marker.Hide();
			}
		}

		private static Transform ModelSpace(HitchableObject obj)
		{
			if ((Object)(object)obj.Vehicle != (Object)null && (Object)(object)obj.Vehicle.meshTransform != (Object)null)
			{
				return obj.Vehicle.meshTransform;
			}
			return HitchGeometry.RootOf(obj);
		}

		private static IEnumerable<Renderer> CollectRenderers(HitchableObject obj, Transform space)
		{
			Renderer[] componentsInChildren = obj.Source.GetComponentsInChildren<Renderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				yield return componentsInChildren[i];
			}
			if (!space.IsChildOf(obj.Source.transform))
			{
				componentsInChildren = ((Component)space).GetComponentsInChildren<Renderer>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					yield return componentsInChildren[i];
				}
			}
		}

		private static void ShowMarker(Transform space, Bounds bounds, float strength)
		{
			//IL_0117: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_005e: 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_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_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_00a0: 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_00b6: 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_00c4: 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)(object)_marker == (Object)null)
			{
				Material val = PreviewMaterials.CreatePlain(MarkerColor, 0.7f, "UCH Selection Marker");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				GameObject val2 = new GameObject("UniversalCartHitch Selection Marker");
				Object.DontDestroyOnLoad((Object)(object)val2);
				val2.SetActive(false);
				MeshBuilder meshBuilder = new MeshBuilder().Lathe((IReadOnlyList<Vector2>)(object)new Vector2[5]
				{
					new Vector2(-0.008f, 0.15f),
					new Vector2(-0.008f, 0.185f),
					new Vector2(0.008f, 0.185f),
					new Vector2(0.008f, 0.15f),
					new Vector2(-0.008f, 0.15f)
				}, 4, smooth: false);
				val2.AddComponent<MeshFilter>().sharedMesh = meshBuilder.ToMesh("UCH Selection Ring");
				MeshRenderer val3 = val2.AddComponent<MeshRenderer>();
				((Renderer)val3).sharedMaterial = val;
				((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)val3).receiveShadows = false;
				_marker = val2.AddComponent<SelectionMarker>();
			}
			float num = Mathf.Min(((Bounds)(ref bounds)).max.y, space.position.y + 1.8f);
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(((Bounds)(ref bounds)).center.x, num + 0.22f, ((Bounds)(ref bounds)).center.z);
			_marker.Follow(space, space.InverseTransformPoint(val4), Mathf.Lerp(0.7f, 1.15f, strength));
		}
	}
	internal sealed class SelectionMarker : MonoBehaviour
	{
		private Transform? _space;

		private Vector3 _local;

		private float _angle;

		internal void Follow(Transform space, Vector3 local, float scale)
		{
			//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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			_space = space;
			_local = local;
			((Component)this).transform.localScale = Vector3.one * scale;
			((Component)this).gameObject.SetActive(true);
			Place();
		}

		internal void Hide()
		{
			_space = null;
			if (((Component)this).gameObject.activeSelf)
			{
				((Component)this).gameObject.SetActive(false);
			}
		}

		private void LateUpdate()
		{
			_angle = Mathf.Repeat(_angle + 40f * Time.deltaTime, 360f);
			Place();
		}

		private void Place()
		{
			//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_004f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_space == (Object)null)
			{
				if (((Component)this).gameObject.activeSelf)
				{
					((Component)this).gameObject.SetActive(false);
				}
			}
			else
			{
				((Component)this).transform.SetPositionAndRotation(_space.TransformPoint(_local), Quaternion.Euler(90f, _angle, 0f));
			}
		}
	}
}
namespace UniversalCartHitch.Stacking
{
	public sealed class CartStackerItem : MonoBehaviour
	{
		private void Start()
		{
			//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_0058: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			string text = (SemiFunc.RunIsShop() ? "on sale in the shop" : "as an owned item");
			string text2 = ((!SemiFunc.IsMultiplayer()) ? "singleplayer" : (SemiFunc.IsMasterClient() ? "host" : "non-host"));
			UniversalCartHitch.Logger.LogInfo($"Cart Stacker persistence: item APPEARED {text} at ({position.x:F1}, {position.y:F1}, {position.z:F1}) on this game ({text2}).");
		}

		private void OnDestroy()
		{
			UniversalCartHitch.Logger.LogDebug("Cart Stacker persistence: an item object was removed from the scene.");
		}
	}
	internal sealed class CartProfile
	{
		internal Bounds Body;

		internal Bounds Full;

		internal float Rim;

		internal float Top;

		internal float VisibleBottom;

		internal bool HasProtrusion;

		internal float ProtrusionZMin;

		internal float ProtrusionZMax;

		internal float BasketZMin;

		internal float BasketZMax;
	}
	internal static class StackerGeometry
	{
		internal const float UnloadGap = 0.3f;

		private const float MaxSlideFraction = 0.3f;

		private static readonly Dictionary<HitchableObject, CartProfile> Profiles = new Dictionary<HitchableObject, CartProfile>();

		internal static bool IsStackableKind(HitchableKind kind)
		{
			if (kind != HitchableKind.LargeCart)
			{
				return kind == HitchableKind.PocketCart;
			}
			return true;
		}

		internal static void Forget(HitchableObject cart)
		{
			Profiles.Remove(cart);
		}

		internal static bool TryGetBody(HitchableObject cart, out Bounds body)
		{
			//IL_0001: 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)
			body = default(Bounds);
			if (!TryGetProfile(cart, out CartProfile profile) || profile == null)
			{
				return false;
			}
			body = profile.Body;
			return true;
		}

		internal static bool TryGetFull(HitchableObject cart, out Bounds full)
		{
			//IL_0001: 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)
			full = default(Bounds);
			if (!TryGetProfile(cart, out CartProfile profile) || profile == null)
			{
				return false;
			}
			full = profile.Full;
			return true;
		}

		internal static bool TryGetProfile(HitchableObject cart, out CartProfile? profile)
		{
			//IL_00a3: 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_00ac: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_0129: 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_0130: 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_0154: 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_01a5: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: 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_01f4: 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_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			if (Profiles.TryGetValue(cart, out profile))
			{
				return true;
			}
			profile = null;
			if (!HitchGeometry.TryGetLocalBounds(cart, includeRolling: false, out var bounds))
			{
				return false;
			}
			if (!HitchGeometry.TryGetLocalBounds(cart, includeRolling: true, out var bounds2))
			{
				return false;
			}
			Transform val = HitchGeometry.RootOf(cart);
			List<Bounds> list = new List<Bounds>();
			Collider[] componentsInChildren = ((Component)val).GetComponentsInChildren<Collider>();
			foreach (Collider val2 in componentsInChildren)
			{
				if (!((Object)(object)val2 == (Object)null) && !val2.isTrigger && val2.enabled && !HitchGeometry.IsRollingCollider(val2, cart))
				{
					list.Add(HitchGeometry.ColliderLocalBounds(val2, val));
				}
			}
			float num = float.MinValue;
			foreach (Bounds item in list)
			{
				Bounds current = item;
				if (((Bounds)(ref current)).size.z >= ((Bounds)(ref bounds)).size.z * 0.5f && ((Bounds)(ref current)).size.y >= 0.2f)
				{
					num = Mathf.Max(num, ((Bounds)(ref current)).max.y);
				}
			}
			if (num == float.MinValue)
			{
				num = ((Bounds)(ref bounds)).max.y;
			}
			CartProfile cartProfile = new CartProfile
			{
				Body = bounds,
				Full = bounds2,
				Rim = num,
				Top = ((Bounds)(ref bounds)).max.y,
				VisibleBottom = MeasureVisibleBottom(cart, val, ((Bounds)(ref bounds)).min.y),
				BasketZMin = float.MaxValue,
				BasketZMax = float.MinValue,
				ProtrusionZMin = float.MaxValue,
				ProtrusionZMax = float.MinValue
			};
			foreach (Bounds item2 in list)
			{
				Bounds current2 = item2;
				if (((Bounds)(ref current2)).max.y > num + 0.03f)
				{
					cartProfile.HasProtrusion = true;
					cartProfile.ProtrusionZMin = Mathf.Min(cartProfile.ProtrusionZMin, ((Bounds)(ref current2)).min.z);
					cartProfile.ProtrusionZMax = Mathf.Max(cartProfile.ProtrusionZMax, ((Bounds)(ref current2)).max.z);
				}
				else
				{
					cartProfile.BasketZMin = Mathf.Min(cartProfile.BasketZMin, ((Bounds)(ref current2)).min.z);
					cartProfile.BasketZMax = Mathf.Max(cartProfile.BasketZMax, ((Bounds)(ref current2)).max.z);
				}
			}
			if (cartProfile.BasketZMin > cartProfile.BasketZMax)
			{
				cartProfile.BasketZMin = ((Bounds)(ref bounds)).min.z;
				cartProfile.BasketZMax = ((Bounds)(ref bounds)).max.z;
			}
			Profiles[cart] = cartProfile;
			profile = cartProfile;
			UniversalCartHitch.Logger.LogInfo($"Stacker geometry: '{cart.ObjectName}' rim at y={cartProfile.Rim:F2}, highest point y={cartProfile.Top:F2}, visible underside y={cartProfile.VisibleBottom:F2} (rolling colliders reach y={((Bounds)(ref bounds2)).min.y:F2})" + $" | basket z={cartProfile.BasketZMin:F2} to {cartProfile.BasketZMax:F2}" + (cartProfile.HasProtrusion ? $" | handle above the rim at z={cartProfile.ProtrusionZMin:F2} to {cartProfile.ProtrusionZMax:F2}" : " | nothing above the rim"));
			return true;
		}

		private static float MeasureVisibleBottom(HitchableObject cart, Transform root, float fallback)
		{
			//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_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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			PhysGrabCart cart2 = cart.Cart;
			if ((Object)(object)cart2 == (Object)null || (Object)(object)cart2.cartMesh == (Object)null)
			{
				return fallback;
			}
			bool flag = false;
			float num = float.MaxValue;
			MeshFilter[] componentsInChildren = ((Component)cart2.cartMesh).GetComponentsInChildren<MeshFilter>();
			Vector3 val2 = default(Vector3);
			foreach (MeshFilter val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || (Object)(object)val.sharedMesh == (Object)null)
				{
					continue;
				}
				MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
				if (!((Object)(object)component == (Object)null) && ((Renderer)component).enabled)
				{
					Bounds bounds = val.sharedMesh.bounds;
					Vector3 extents = ((Bounds)(ref bounds)).extents;
					for (int j = 0; j < 8; j++)
					{
						((Vector3)(ref val2))..ctor(((j & 1) == 0) ? (0f - extents.x) : extents.x, ((j & 2) == 0) ? (0f - extents.y) : extents.y, ((j & 4) == 0) ? (0f - extents.z) : extents.z);
						Vector3 val3 = root.InverseTransformPoint(((Component)val).transform.TransformPoint(((Bounds)(ref bounds)).center + val2));
						num = Mathf.Min(num, val3.y);
						flag = true;
					}
				}
			}
			if (!flag)
			{
				return fallback;
			}
			return num;
		}

		private static float GapFor(HitchableObject cart)
		{
			float num = ((cart.Kind == HitchableKind.PocketCart) ? PluginConfig.StackerPocketHeightAdjust.Value : PluginConfig.StackerLargeHeightAdjust.Value);
			return PluginConfig.StackerVerticalGap.Value + num;
		}

		internal static bool TryGetMountLocal(HitchableObject cart, int side, out Vector3 local, out float reach)
		{
			//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_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_0044: 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_0061: 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)
			local = Vector3.zero;
			reach = 0f;
			if (!TryGetProfile(cart, out CartProfile profile) || profile == null)
			{
				return false;
			}
			Bounds body = profile.Body;
			float num = profile.Rim - 0.1f * StackerModel.ScaleFor(cart.Kind);
			local = new Vector3(((Bounds)(ref body)).center.x + (float)side * ((Bounds)(ref body)).extents.x, num, ((Bounds)(ref body)).center.z);
			reach = RestingHeight(profile) + GapFor(cart) - num;
			return true;
		}

		private static float RestingHeight(CartProfile lower)
		{
			if (!lower.HasProtrusion || PluginConfig.StackerSlideClearOfHandle.Value)
			{
				return lower.Rim;
			}
			return lower.Top;
		}

		internal static bool TryGetSeatPose(HitchableObject lower, HitchableObject upper, out Vector3 position, out Quaternion rotation, bool? reversedOverride = null)
		{
			//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_005c: 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_0061: 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_006a: 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_007e: 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_009d: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00d3: 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_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			rotation = Quaternion.identity;
			if (!TryGetProfile(lower, out CartProfile profile) || profile == null)
			{
				return false;
			}
			if (!TryGetProfile(upper, out CartProfile profile2) || profile2 == null)
			{
				return false;
			}
			Transform val = HitchGeometry.RootOf(lower);
			bool valueOrDefault = reversedOverride == true;
			Quaternion val2 = (valueOrDefault ? Quaternion.Euler(0f, 180f, 0f) : Quaternion.identity);
			rotation = val.rotation * val2;
			Vector3 val3 = val2 * new Vector3(((Bounds)(ref profile2.Body)).center.x, 0f, ((Bounds)(ref profile2.Body)).center.z);
			float num = ((Bounds)(ref profile.Body)).center.x - val3.x;
			float num2 = ((Bounds)(ref profile.Body)).center.z - val3.z;
			float num3 = (valueOrDefault ? (0f - profile2.BasketZMax) : profile2.BasketZMin);
			float num4 = (valueOrDefault ? (0f - profile2.BasketZMin) : profile2.BasketZMax);
			num3 += num2;
			num4 += num2;
			float num5 = profile.Rim;
			if (profile.HasProtrusion)
			{
				float value = PluginConfig.StackerHandleClearance.Value;
				float num6 = profile.ProtrusionZMin - value;
				float num7 = profile.ProtrusionZMax + value;
				if (num4 > num6 && num3 < num7)
				{
					float num8 = num7 - num3;
					float num9 = num6 - num4;
					float num10 = ((Mathf.Abs(num8) <= Mathf.Abs(num9)) ? num8 : num9);
					if (PluginConfig.StackerSlideClearOfHandle.Value && Mathf.Abs(num10) <= ((Bounds)(ref profile.Body)).size.z * 0.3f)
					{
						num2 += num10;
					}
					else
					{
						num5 = profile.Top;
					}
				}
			}
			float num11 = num5 + GapFor(lower) - profile2.VisibleBottom;
			position = val.TransformPoint(new Vector3(num, num11, num2));
			return true;
		}

		internal static bool IsReversed(HitchableObject lower, HitchableObject upper)
		{
			//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)
			return Vector3.Dot(HitchGeometry.RootOf(lower).forward, HitchGeometry.RootOf(upper).forward) < 0f;
		}

		internal static bool TryGetUnloadPose(HitchableObject lower, HitchableObject upper, int side, out Vector3 position, out Quaternion rotation)
		{
			//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_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_003c: 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_005e: 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_007b: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			rotation = HitchGeometry.RootOf(upper).rotation;
			if (!TryGetFull(lower, out var full) || !TryGetFull(upper, out var full2))
			{
				return false;
			}
			Transform val = HitchGeometry.RootOf(lower);
			float num = ((Bounds)(ref full)).extents.x + ((Bounds)(ref full2)).extents.x + 0.3f;
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(((Bounds)(ref full)).center.x + (float)side * num, ((Bounds)(ref full)).min.y - ((Bounds)(ref full2)).min.y + 0.05f, ((Bounds)(ref full)).center.z);
			position = val.TransformPoint(val2);
			return true;
		}

		internal static bool InLoadingZone(HitchableObject lower, HitchableObject candidate, float snapRange)
		{
			//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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_003b: 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_003d: 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)
			//IL_0045: 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_0068: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			if (!TryGetFull(lower, out var full) || !TryGetFull(candidate, out var full2))
			{
				return false;
			}
			Vector3 val = HitchGeometry.RootOf(lower).TransformPoint(((Bounds)(ref full)).center);
			Vector3 val2 = HitchGeometry.RootOf(candidate).TransformPoint(((Bounds)(ref full2)).center);
			Vector3 val3 = val2 - val;
			float y = val3.y;
			val3.y = 0f;
			float num = ((Bounds)(ref full)).extents.x + ((Bounds)(ref full2)).extents.x + snapRange;
			if (((Vector3)(ref val3)).magnitude > num)
			{
				return false;
			}
			if (y > -1f)
			{
				return y < ((Bounds)(ref full)).size.y + ((Bounds)(ref full2)).size.y + 1f;
			}
			return false;
		}

		internal static bool TryGetWorldBox(HitchableObject cart, Vector3 rootPosition, Quaternion rootRotation, out Vector3 centre, out Vector3 halfExtents)
		{
			//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_0009: 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_002d: 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_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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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)
			centre = rootPosition;
			halfExtents = Vector3.one * 0.5f;
			if (!TryGetProfile(cart, out CartProfile profile) || profile == null)
			{
				return false;
			}
			centre = rootPosition + rootRotation * ((Bounds)(ref profile.Body)).center;
			halfExtents = ((Bounds)(ref profile.Body)).extents;
			return true;
		}
	}
	internal static class StackerInteraction
	{
		private enum Aim
		{
			None,