Decompiled source of HatterCartsPack v1.0.0

HatterCartsPack.dll

Decompiled an hour ago
using System;
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.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using REPOLib.Modules;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("HatterCartsPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HatterCartsPack")]
[assembly: AssemblyTitle("HatterCartsPack")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HatterCartsPack;

internal static class CartDebugExport
{
	internal static readonly bool Enabled = true;

	internal static void Export(Transform cart, string fileName)
	{
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: 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_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		if (!Enabled)
		{
			return;
		}
		try
		{
			string text = Path.Combine(Paths.BepInExRootPath, "HatterCartsPack debug");
			Directory.CreateDirectory(text);
			StringBuilder stringBuilder = new StringBuilder("# " + ((Object)cart).name + " in cart space (x width, y up, z length)\n");
			int num = 1;
			MeshFilter[] componentsInChildren = ((Component)cart).GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
				if ((Object)(object)component == (Object)null || !((Renderer)component).enabled || (Object)(object)val.sharedMesh == (Object)null || InItemVolume(((Component)val).transform, cart))
				{
					continue;
				}
				Mesh val2 = (val.sharedMesh.isReadable ? val.sharedMesh : CartStretch.ReadableCopy(val.sharedMesh));
				if (!((Object)(object)val2 == (Object)null))
				{
					Matrix4x4 val3 = cart.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
					stringBuilder.Append("o ").Append(PathOf(cart, ((Component)val).transform).Replace(' ', '_')).Append('\n');
					Vector3[] vertices = val2.vertices;
					foreach (Vector3 val4 in vertices)
					{
						Vector3 val5 = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(val4);
						stringBuilder.Append("v ").Append(F(val5.x)).Append(' ')
							.Append(F(val5.y))
							.Append(' ')
							.Append(F(val5.z))
							.Append('\n');
					}
					int[] triangles = val2.triangles;
					for (int k = 0; k + 2 < triangles.Length; k += 3)
					{
						stringBuilder.Append("f ").Append(triangles[k] + num).Append(' ')
							.Append(triangles[k + 1] + num)
							.Append(' ')
							.Append(triangles[k + 2] + num)
							.Append('\n');
					}
					num += val2.vertexCount;
				}
			}
			string text2 = Path.Combine(text, fileName + ".obj");
			File.WriteAllText(text2, stringBuilder.ToString());
			Plugin.Log.LogInfo((object)("Debug: wrote " + text2));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Debug: couldn't export " + fileName + ": " + ex.Message));
		}
	}

	internal static void ExportColliders(Transform cart, string fileName)
	{
		//IL_00c9: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: 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_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: 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_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: 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_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		if (!Enabled)
		{
			return;
		}
		try
		{
			string text = Path.Combine(Paths.BepInExRootPath, "HatterCartsPack debug");
			Directory.CreateDirectory(text);
			StringBuilder stringBuilder = new StringBuilder("# " + ((Object)cart).name + " colliders in cart space\n");
			int num = 1;
			Collider[] componentsInChildren = ((Component)cart).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if (!val.isTrigger && !InItemVolume(((Component)val).transform, cart) && CartStretch.TryLocalBounds(val, out var local))
				{
					stringBuilder.Append("o ").Append(PathOf(cart, ((Component)val).transform).Replace(' ', '_')).Append('_')
						.Append(((object)val).GetType().Name)
						.Append('\n');
					Vector3 extents = ((Bounds)(ref local)).extents;
					for (int j = 0; j < 8; j++)
					{
						Vector3 val2 = ((Bounds)(ref local)).center + new Vector3(((j & 1) == 0) ? (0f - extents.x) : extents.x, ((j & 2) == 0) ? (0f - extents.y) : extents.y, ((j & 4) == 0) ? (0f - extents.z) : extents.z);
						Vector3 val3 = cart.InverseTransformPoint(((Component)val).transform.TransformPoint(val2));
						stringBuilder.Append("v ").Append(F(val3.x)).Append(' ')
							.Append(F(val3.y))
							.Append(' ')
							.Append(F(val3.z))
							.Append('\n');
					}
					int[,] array = new int[6, 4]
					{
						{ 0, 1, 3, 2 },
						{ 4, 6, 7, 5 },
						{ 0, 4, 5, 1 },
						{ 2, 3, 7, 6 },
						{ 0, 2, 6, 4 },
						{ 1, 5, 7, 3 }
					};
					for (int k = 0; k < 6; k++)
					{
						stringBuilder.Append("f ").Append(array[k, 0] + num).Append(' ')
							.Append(array[k, 1] + num)
							.Append(' ')
							.Append(array[k, 2] + num)
							.Append(' ')
							.Append(array[k, 3] + num)
							.Append('\n');
					}
					num += 8;
				}
			}
			string text2 = Path.Combine(text, fileName + ".obj");
			File.WriteAllText(text2, stringBuilder.ToString());
			Plugin.Log.LogInfo((object)("Debug: wrote " + text2));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Debug: couldn't export " + fileName + ": " + ex.Message));
		}
	}

	private static bool InItemVolume(Transform t, Transform cart)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)cart)
		{
			if (((Object)val).name.StartsWith("Item Volume"))
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private static string PathOf(Transform root, Transform t)
	{
		string text = ((Object)t).name;
		Transform parent = t.parent;
		while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)root)
		{
			text = ((Object)parent).name + "/" + text;
			parent = parent.parent;
		}
		return text;
	}

	private static string F(float f)
	{
		return f.ToString("0.#####", CultureInfo.InvariantCulture);
	}
}
public class CartPlusButton : MonoBehaviour
{
}
public class CartPlus : MonoBehaviour
{
	private enum State
	{
		Big,
		Shrinking,
		Small,
		Growing
	}

	private const float ShrinkSeconds = 0.4f;

	private const float GrowSeconds = 0.15f;

	private const float ButtonPadding = 0.04f;

	private const float RoomMargin = 0.03f;

	private const float RoomCheckEvery = 0.1f;

	private PhysGrabObject physGrabObject;

	private PhotonView photonView;

	private BoxCollider button;

	private readonly HashSet<PhysGrabber> grabbers = new HashSet<PhysGrabber>();

	private readonly HashSet<PhysGrabber> pressing = new HashSet<PhysGrabber>();

	private readonly List<PhysGrabber> gone = new List<PhysGrabber>();

	private State state;

	private float size = 1f;

	private readonly HashSet<Mesh> ownMeshes = new HashSet<Mesh>();

	private CartPlusContents contents;

	private readonly List<Material> buttonMaterials = new List<Material>();

	private int shownVisual = -1;

	private Transform meterFill;

	private Material meterMaterial;

	private static readonly Color MeterColor = new Color(0.3f, 1f, 0.4f);

	private static bool exportedAfterRegrow;

	private readonly List<Material> stripMaterials = new List<Material>();

	private float roomTimer;

	private float leaveTimer;

	private Vector3 growShift;

	private float shiftApplied;

	private string lastBlocker;

	private void Awake()
	{
		physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
		photonView = ((Component)this).GetComponent<PhotonView>();
		contents = new CartPlusContents(((Component)this).transform, physGrabObject);
		CartPlusButton componentInChildren = ((Component)this).GetComponentInChildren<CartPlusButton>(true);
		button = (((Object)(object)componentInChildren != (Object)null) ? ((Component)componentInChildren).GetComponentInChildren<BoxCollider>(true) : null);
		if ((Object)(object)button == (Object)null)
		{
			Plugin.Log.LogWarning((object)"C.A.R.T. Plus: stasis button not found on this cart.");
		}
		meterFill = ((Component)this).transform.Find("Stasis Meter/Fill");
		if ((Object)(object)meterFill != (Object)null)
		{
			Renderer component = ((Component)meterFill).GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				meterMaterial = component.material;
			}
		}
		Transform val = ((Component)this).transform.Find("Cart Handle (Stasis Button)");
		if ((Object)(object)val != (Object)null)
		{
			Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Material[] materials = componentsInChildren[i].materials;
				foreach (Material item in materials)
				{
					buttonMaterials.Add(item);
				}
			}
		}
		string[] array = new string[2] { "Cart Handle Bar (Stasis Button)", "Cart Handle Frame (Stasis Button)" };
		foreach (string text in array)
		{
			Transform val2 = ((Component)this).transform.Find(text);
			Renderer val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<Renderer>() : null);
			if (!((Object)(object)val3 == (Object)null))
			{
				Material[] materials = val3.materials;
				foreach (Material item2 in materials)
				{
					stripMaterials.Add(item2);
				}
			}
		}
	}

	private void OnDestroy()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		contents?.Release(Vector3.zero);
		foreach (Mesh ownMesh in ownMeshes)
		{
			if ((Object)(object)ownMesh != (Object)null)
			{
				Object.Destroy((Object)(object)ownMesh);
			}
		}
		foreach (Material buttonMaterial in buttonMaterials)
		{
			if ((Object)(object)buttonMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)buttonMaterial);
			}
		}
		foreach (Material stripMaterial in stripMaterials)
		{
			if ((Object)(object)stripMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)stripMaterial);
			}
		}
		if ((Object)(object)meterMaterial != (Object)null)
		{
			Object.Destroy((Object)(object)meterMaterial);
		}
	}

	private void Update()
	{
		if (SemiFunc.IsMasterClientOrSingleplayer())
		{
			WatchButton();
		}
		Tick(Time.deltaTime);
	}

	private void FixedUpdate()
	{
		if (contents != null && contents.Active)
		{
			contents.Hold(Mathf.SmoothStep(0f, 1f, size));
		}
	}

	private void LateUpdate()
	{
		if (contents != null && contents.Active)
		{
			contents.Hold(Mathf.SmoothStep(0f, 1f, size));
		}
	}

	private void WatchButton()
	{
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)button == (Object)null || (Object)(object)physGrabObject == (Object)null)
		{
			return;
		}
		List<PhysGrabber> playerGrabbing = physGrabObject.playerGrabbing;
		gone.Clear();
		foreach (PhysGrabber grabber in grabbers)
		{
			if ((Object)(object)grabber == (Object)null || playerGrabbing == null || !playerGrabbing.Contains(grabber))
			{
				gone.Add(grabber);
			}
		}
		foreach (PhysGrabber item in gone)
		{
			grabbers.Remove(item);
			pressing.Remove(item);
		}
		if (playerGrabbing != null)
		{
			foreach (PhysGrabber item2 in playerGrabbing)
			{
				if ((Object)(object)item2 != (Object)null && grabbers.Add(item2) && (Object)(object)item2.physGrabPoint != (Object)null && OnButton(item2.physGrabPoint.position))
				{
					pressing.Add(item2);
				}
			}
		}
		WatchLeavers();
		bool flag = pressing.Count > 0;
		if (flag && (state == State.Big || state == State.Growing))
		{
			StartShrink();
		}
		else if (!flag && (state == State.Shrinking || state == State.Small))
		{
			roomTimer -= Time.deltaTime;
			if (roomTimer > 0f)
			{
				return;
			}
			roomTimer = 0.1f;
			if (FindRoom(out var shift))
			{
				lastBlocker = null;
				growShift = shift;
				shiftApplied = Mathf.SmoothStep(0f, 1f, size);
				if (shift != Vector3.zero)
				{
					Plugin.Log.LogInfo((object)string.Format("{0}: growing towards the open side (shift {1}).", "C.A.R.T. Plus", shift));
				}
				Send("CartPlusGrowRPC");
			}
		}
		else
		{
			roomTimer = 0f;
		}
	}

	private void WatchLeavers()
	{
		if (state != State.Small || !contents.Active)
		{
			return;
		}
		leaveTimer -= Time.deltaTime;
		if (leaveTimer > 0f)
		{
			return;
		}
		leaveTimer = 0.1f;
		foreach (Component item in contents.FindLeavers())
		{
			PlayerAvatar val = (PlayerAvatar)(object)((item is PlayerAvatar) ? item : null);
			PhotonView val2 = ((val != null) ? val.photonView : item.GetComponent<PhotonView>());
			if (SemiFunc.IsMultiplayer() && (Object)(object)photonView != (Object)null && (Object)(object)val2 != (Object)null)
			{
				photonView.RPC("CartPlusDropRPC", (RpcTarget)0, new object[1] { val2.ViewID });
			}
			else
			{
				contents.Drop(item);
			}
		}
	}

	private static Component Resolve(int viewId)
	{
		PhotonView val = PhotonView.Find(viewId);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		PlayerAvatar component = ((Component)val).GetComponent<PlayerAvatar>();
		if ((Object)(object)component != (Object)null)
		{
			return (Component)(object)component;
		}
		return (Component)(object)((Component)val).GetComponent<PhysGrabObject>();
	}

	[PunRPC]
	private void CartPlusDropRPC(int viewId)
	{
		Component val = Resolve(viewId);
		if ((Object)(object)val != (Object)null)
		{
			contents.Drop(val);
		}
	}

	private bool FindRoom(out Vector3 shift)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: 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_0088: 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_00e3: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		shift = Vector3.zero;
		Vector3 fullDelta = CartPlusBuilder.FullDelta;
		if (HasRoom(Vector3.zero))
		{
			return true;
		}
		List<Vector3> list = new List<Vector3>();
		float[] array = new float[5] { -1f, -0.5f, 0f, 0.5f, 1f };
		float[] array2 = array;
		foreach (float num in array2)
		{
			float[] array3 = array;
			foreach (float num2 in array3)
			{
				if (num != 0f || num2 != 0f)
				{
					list.Add(new Vector3(num * Mathf.Abs(fullDelta.x), 0f, num2 * Mathf.Abs(fullDelta.z)));
				}
			}
		}
		list.Sort((Vector3 a, Vector3 b) => ((Vector3)(ref a)).sqrMagnitude.CompareTo(((Vector3)(ref b)).sqrMagnitude));
		foreach (Vector3 item in list)
		{
			if (HasRoom(item))
			{
				shift = item;
				return true;
			}
		}
		return false;
	}

	private bool HasRoom(Vector3 localShift)
	{
		//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_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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_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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		Bounds roomFull = CartPlusBuilder.RoomFull;
		if (((Bounds)(ref roomFull)).size == Vector3.zero)
		{
			return true;
		}
		Vector3 val = Vector3.Max(((Bounds)(ref roomFull)).extents - Vector3.one * 0.03f, Vector3.one * 0.01f);
		Collider[] array = Physics.OverlapBox(((Component)this).transform.TransformPoint(((Bounds)(ref roomFull)).center + localShift), Vector3.Scale(val, ((Component)this).transform.lossyScale), ((Component)this).transform.rotation, -1, (QueryTriggerInteraction)1);
		foreach (Collider val2 in array)
		{
			if ((Object)(object)val2 == (Object)null || ((Component)val2).transform.IsChildOf(((Component)this).transform))
			{
				continue;
			}
			Rigidbody attachedRigidbody = val2.attachedRigidbody;
			if ((!((Object)(object)attachedRigidbody != (Object)null) || attachedRigidbody.isKinematic) && !((Object)(object)((Component)val2).GetComponentInParent<PhysGrabObject>() != (Object)null) && !((Object)(object)((Component)val2).GetComponentInParent<PlayerAvatar>() != (Object)null) && !((Object)(object)((Component)val2).GetComponentInParent<PlayerController>() != (Object)null) && !((Object)(object)((Component)val2).GetComponentInParent<EnemyParent>() != (Object)null))
			{
				if (((Object)val2).name != lastBlocker)
				{
					lastBlocker = ((Object)val2).name;
					Plugin.Log.LogInfo((object)("C.A.R.T. Plus: no room to grow back yet (blocked by " + ((Object)val2).name + ", layer " + LayerMask.LayerToName(((Component)val2).gameObject.layer) + ")."));
				}
				return false;
			}
		}
		return true;
	}

	private bool OnButton(Vector3 world)
	{
		//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_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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)
		Transform transform = ((Component)button).transform;
		Vector3 val = transform.InverseTransformPoint(world) - button.center;
		Vector3 lossyScale = transform.lossyScale;
		for (int i = 0; i < 3; i++)
		{
			float num = 0.04f / Mathf.Max(Mathf.Abs(((Vector3)(ref lossyScale))[i]), 0.0001f);
			float num2 = Mathf.Abs(((Vector3)(ref val))[i]);
			Vector3 val2 = button.size;
			if (num2 > Mathf.Abs(((Vector3)(ref val2))[i]) * 0.5f + num)
			{
				return false;
			}
		}
		return true;
	}

	private void StartShrink()
	{
		List<Component> list = ((state == State.Big && !contents.Active) ? contents.Gather() : new List<Component>());
		if (SemiFunc.IsMultiplayer() && (Object)(object)photonView != (Object)null)
		{
			List<int> list2 = new List<int>();
			foreach (Component item in list)
			{
				PlayerAvatar val = (PlayerAvatar)(object)((item is PlayerAvatar) ? item : null);
				PhotonView val2 = ((val != null) ? val.photonView : item.GetComponent<PhotonView>());
				if ((Object)(object)val2 != (Object)null)
				{
					list2.Add(val2.ViewID);
				}
			}
			photonView.RPC("CartPlusShrinkRPC", (RpcTarget)0, new object[1] { list2.ToArray() });
		}
		else
		{
			BeginShrink(list);
		}
	}

	private void Send(string rpc)
	{
		if (SemiFunc.IsMultiplayer() && (Object)(object)photonView != (Object)null)
		{
			photonView.RPC(rpc, (RpcTarget)0, Array.Empty<object>());
		}
		else
		{
			((Component)this).SendMessage(rpc);
		}
	}

	[PunRPC]
	private void CartPlusShrinkRPC(int[] itemViewIds)
	{
		List<Component> list = new List<Component>();
		if (itemViewIds != null)
		{
			for (int i = 0; i < itemViewIds.Length; i++)
			{
				Component val = Resolve(itemViewIds[i]);
				if ((Object)(object)val != (Object)null)
				{
					list.Add(val);
				}
			}
		}
		BeginShrink(list);
	}

	private void BeginShrink(List<Component> things)
	{
		if (state == State.Big || state == State.Growing)
		{
			if (state == State.Big && !contents.Active)
			{
				contents.Begin(things);
			}
			state = State.Shrinking;
		}
	}

	[PunRPC]
	private void CartPlusGrowRPC()
	{
		if (state == State.Shrinking || state == State.Small)
		{
			contents.Tighten();
			state = State.Growing;
		}
	}

	private void Tick(float dt)
	{
		//IL_0078: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		switch (state)
		{
		case State.Shrinking:
			SetSize(size - dt / 0.4f);
			if (size <= 0f)
			{
				state = State.Small;
				Rigidbody val2 = (((Object)(object)physGrabObject != (Object)null) ? physGrabObject.rb : ((Component)this).GetComponent<Rigidbody>());
				contents.Loosen(((Object)(object)val2 != (Object)null) ? val2.linearVelocity : Vector3.zero);
			}
			break;
		case State.Growing:
			SetSize(size + dt / 0.15f);
			ShiftWhileGrowing();
			if (size >= 1f)
			{
				Rigidbody val = (((Object)(object)physGrabObject != (Object)null) ? physGrabObject.rb : ((Component)this).GetComponent<Rigidbody>());
				contents.Release(((Object)(object)val != (Object)null) ? val.linearVelocity : Vector3.zero);
				state = State.Big;
				if (!exportedAfterRegrow)
				{
					exportedAfterRegrow = true;
					CartDebugExport.Export(((Component)this).transform, "cart_plus_after_regrow");
					CartDebugExport.ExportColliders(((Component)this).transform, "cart_plus_colliders_after_regrow");
				}
			}
			break;
		}
		TintButton();
		UpdateMeter();
	}

	private void UpdateMeter()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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)
		if (!((Object)(object)meterFill == (Object)null))
		{
			float num = 1f - size;
			float num2 = 0.6f;
			Vector3 localScale = meterFill.localScale;
			localScale.x = Mathf.Max(num2 * num, 0.0001f);
			meterFill.localScale = localScale;
			Vector3 localPosition = meterFill.localPosition;
			localPosition.x = (0f - num2) * 0.5f + num2 * num * 0.5f;
			meterFill.localPosition = localPosition;
			if ((Object)(object)meterMaterial != (Object)null)
			{
				meterMaterial.color = MeterColor;
			}
		}
	}

	private void ShiftWhileGrowing()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: 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_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_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_0090: 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_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)
		if (!SemiFunc.IsMasterClientOrSingleplayer() || growShift == Vector3.zero)
		{
			return;
		}
		float num = Mathf.SmoothStep(0f, 1f, size);
		float num2 = num - shiftApplied;
		if (!(num2 <= 0f))
		{
			shiftApplied = num;
			Vector3 val = ((Component)this).transform.TransformVector(growShift * num2);
			Rigidbody val2 = (((Object)(object)physGrabObject != (Object)null) ? physGrabObject.rb : ((Component)this).GetComponent<Rigidbody>());
			Transform transform = ((Component)this).transform;
			transform.position += val;
			if ((Object)(object)val2 != (Object)null)
			{
				val2.position = ((Component)this).transform.position;
			}
			if (num >= 1f)
			{
				growShift = Vector3.zero;
			}
		}
	}

	private void SetSize(float value)
	{
		//IL_002e: 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)
		value = Mathf.Clamp01(value);
		if (!Mathf.Approximately(value, size))
		{
			size = value;
			CartPlusBuilder.Stretch?.Apply(((Component)this).transform, CartPlusBuilder.FullDelta * Mathf.SmoothStep(0f, 1f, size), ownMeshes);
		}
	}

	private void TintButton()
	{
		//IL_0033: 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_0038: 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_00e0: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		int num = ((state == State.Shrinking || state == State.Small) ? 1 : 0);
		if (num == shownVisual)
		{
			return;
		}
		shownVisual = num;
		Color val = ((num == 1) ? Color.green : Color.red);
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor((num == 1) ? 0.5f : 0f, 0f);
		foreach (Material stripMaterial in stripMaterials)
		{
			if ((Object)(object)stripMaterial != (Object)null && stripMaterial.HasProperty("_EmissionColor"))
			{
				stripMaterial.SetColor("_EmissionColor", val);
			}
		}
		foreach (Material buttonMaterial in buttonMaterials)
		{
			if (!((Object)(object)buttonMaterial == (Object)null))
			{
				if (buttonMaterial.HasProperty("_EmissionColor"))
				{
					buttonMaterial.SetColor("_EmissionColor", val);
				}
				if (((Object)buttonMaterial).name.StartsWith("Stasis Button Shrink Icon"))
				{
					buttonMaterial.mainTextureOffset = CartPlusBuilder.IconBaseOffset + val2;
				}
				else
				{
					buttonMaterial.mainTextureOffset = val2;
				}
			}
		}
	}
}
internal static class CartPlusAssets
{
	private static Texture2D shrinkIcon;

	internal static Texture2D ShrinkIcon
	{
		get
		{
			if (!((Object)(object)shrinkIcon != (Object)null))
			{
				return shrinkIcon = Load("cart_plus_shrink_icon.png");
			}
			return shrinkIcon;
		}
	}

	private static Texture2D Load(string file)
	{
		//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_0082: 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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		string text = "HatterCartsPack.Assets." + file;
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text);
		if (stream == null)
		{
			Plugin.Log.LogWarning((object)("Embedded asset '" + text + "' is missing."));
			return null;
		}
		byte[] array = new byte[stream.Length];
		int num;
		for (int i = 0; i < array.Length; i += num)
		{
			num = stream.Read(array, i, array.Length - i);
			if (num <= 0)
			{
				break;
			}
		}
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
		{
			name = Path.GetFileNameWithoutExtension(file),
			wrapMode = (TextureWrapMode)1,
			filterMode = (FilterMode)0,
			hideFlags = (HideFlags)32
		};
		if (!ImageConversion.LoadImage(val, array))
		{
			Plugin.Log.LogWarning((object)("Could not decode embedded asset '" + text + "'."));
			return null;
		}
		return val;
	}
}
internal static class CartPlusBuilder
{
	internal const string PrefabName = "Item Cart Plus";

	internal const string DisplayName = "C.A.R.T. Plus";

	private const string CartPath = "Items/Item Cart Medium";

	internal static readonly Vector3 SizeMultiplier = new Vector3(1.4f, 1.1f, 1.4f);

	internal const float PriceMultiplier = 1.5f;

	private static GameObject holder;

	internal const string MeterName = "Stasis Meter";

	internal const string ButtonBarName = "Cart Handle Bar (Stasis Button)";

	internal const string IconMaterialName = "Stasis Button Shrink Icon";

	private const float ButtonBarScale = 0.7f;

	private const float BarMinY = 0.28f;

	internal const float MeterWidth = 0.6f;

	internal static CartStretch Stretch { get; private set; }

	internal static Vector3 FullDelta { get; private set; }

	internal static Bounds BasketSmall { get; private set; }

	internal static Bounds BasketFull { get; private set; }

	internal static Bounds RoomFull { get; private set; }

	internal static Vector2 IconBaseOffset { get; private set; }

	internal static GameObject Build()
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Resources.Load<GameObject>("Items/Item Cart Medium");
		if ((Object)(object)val == (Object)null)
		{
			Plugin.Log.LogError((object)"Vanilla C.A.R.T. not found at 'Items/Item Cart Medium'. Has the game changed its resource paths?");
			return null;
		}
		ItemAttributes component = val.GetComponent<ItemAttributes>();
		if ((Object)(object)component == (Object)null || (Object)(object)component.item == (Object)null || (Object)(object)val.GetComponent<PhysGrabCart>() == (Object)null)
		{
			Plugin.Log.LogError((object)"Vanilla C.A.R.T. is missing expected components (ItemAttributes / PhysGrabCart).");
			return null;
		}
		holder = new GameObject("HatterCartsPack.CartPlus.PrefabHolder");
		holder.SetActive(false);
		Object.DontDestroyOnLoad((Object)(object)holder);
		((Object)holder).hideFlags = (HideFlags)61;
		GameObject val2 = Object.Instantiate<GameObject>(val, holder.transform);
		((Object)val2).name = "Item Cart Plus";
		Transform transform = val2.transform;
		LogParts(val2);
		SetupItem(val2, component.item);
		if (!TryGetBodyBounds(transform, out var body))
		{
			Plugin.Log.LogError((object)"Couldn't measure the C.A.R.T.'s body; the C.A.R.T. Plus will not be available.");
			return null;
		}
		Vector3 center = ((Bounds)(ref body)).center;
		PhysGrabInCart componentInChildren = val2.GetComponentInChildren<PhysGrabInCart>(true);
		BoxCollider val3 = (((Object)(object)componentInChildren != (Object)null) ? ((Component)componentInChildren).GetComponent<BoxCollider>() : null);
		if ((Object)(object)val3 != (Object)null)
		{
			Bounds val4 = CartStretch.CartBounds(transform, val3);
			center.x = ((Bounds)(ref val4)).center.x;
			center.z = ((Bounds)(ref val4)).center.z;
		}
		CartDebugExport.Export(transform, "cart_vanilla");
		AddButton(transform, center);
		Stretch = CartStretch.Capture(transform, center, ((Bounds)(ref body)).size, (Transform t) => ((Object)t).name == "Cart Handle Bar (Stasis Button)" || ((Object)t).name == "Cart Handle (Stasis Button)" || (Object)(object)((Component)t).GetComponent<CartPlusButton>() != (Object)null);
		FullDelta = Stretch.DeltaForFactor(SizeMultiplier);
		if ((Object)(object)val3 != (Object)null)
		{
			BasketSmall = CartStretch.CartBounds(transform, val3);
		}
		Stretch.Apply(transform, FullDelta, new HashSet<Mesh>());
		if ((Object)(object)val3 != (Object)null)
		{
			BasketFull = CartStretch.CartBounds(transform, val3);
		}
		bool flag = false;
		Bounds roomFull = default(Bounds);
		BoxCollider[] componentsInChildren = ((Component)transform).GetComponentsInChildren<BoxCollider>(true);
		foreach (BoxCollider val5 in componentsInChildren)
		{
			if (!((Collider)val5).isTrigger)
			{
				Bounds val6 = CartStretch.CartBounds(transform, val5);
				if (!flag)
				{
					roomFull = val6;
					flag = true;
				}
				else
				{
					((Bounds)(ref roomFull)).Encapsulate(val6);
				}
			}
		}
		RoomFull = roomFull;
		ManualLogSource log = Plugin.Log;
		Bounds val7 = RoomFull;
		object arg = ((Bounds)(ref val7)).size;
		val7 = RoomFull;
		log.LogInfo((object)$"Room needed to grow back: {arg} around {((Bounds)(ref val7)).center} (cart space).");
		ManualLogSource log2 = Plugin.Log;
		val7 = BasketSmall;
		object arg2 = ((Bounds)(ref val7)).size;
		val7 = BasketFull;
		log2.LogInfo((object)$"Basket: {arg2} at C.A.R.T. size, {((Bounds)(ref val7)).size} at full size.");
		CartDebugExport.Export(transform, "cart_plus");
		CartDebugExport.ExportColliders(transform, "cart_plus_colliders");
		val2.AddComponent<CartPlus>();
		Plugin.Log.LogInfo((object)string.Format("Built {0} prefab ({1} x the C.A.R.T.'s width, height, length; walls {2} further out).", "C.A.R.T. Plus", SizeMultiplier, FullDelta));
		return val2;
	}

	private static void SetupItem(GameObject cart, Item source)
	{
		Item val = Object.Instantiate<Item>(source);
		((Object)val).name = "Item Cart Plus";
		val.itemName = "C.A.R.T. Plus";
		val.itemNameLocalized = null;
		val.description = "A wider, longer C.A.R.T. The button on its far end shrinks it, and everything in it, to fit through tight doors.";
		if ((Object)(object)source.value != (Object)null)
		{
			Value val2 = Object.Instantiate<Value>(source.value);
			((Object)val2).name = "Item Cart Plus Value";
			val2.valueMin *= 1.5f;
			val2.valueMax *= 1.5f;
			val.value = val2;
		}
		cart.GetComponent<ItemAttributes>().item = val;
	}

	private static bool TryGetBodyBounds(Transform cartT, out Bounds body)
	{
		//IL_0001: 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_0052: 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_005d: 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_0081: Unknown result type (might be due to invalid IL or missing references)
		body = default(Bounds);
		Transform val = cartT.Find("Cart Mesh");
		MeshFilter val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<MeshFilter>() : null);
		if ((Object)(object)val2 == (Object)null || (Object)(object)val2.sharedMesh == (Object)null)
		{
			return false;
		}
		body = CartStretch.TransformBounds(val2.sharedMesh.bounds, ((Component)val2).transform, cartT);
		if (((Bounds)(ref body)).size.x > 0.1f && ((Bounds)(ref body)).size.y > 0.1f)
		{
			return ((Bounds)(ref body)).size.z > 0.1f;
		}
		return false;
	}

	private static void AddButton(Transform cartT, Vector3 center)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_012f: 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_0077: 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_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: 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_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Expected O, but got Unknown
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0416: Unknown result type (might be due to invalid IL or missing references)
		//IL_045c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0532: Unknown result type (might be due to invalid IL or missing references)
		//IL_0537: Unknown result type (might be due to invalid IL or missing references)
		//IL_053f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0546: Unknown result type (might be due to invalid IL or missing references)
		//IL_054e: Unknown result type (might be due to invalid IL or missing references)
		//IL_055a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0561: Unknown result type (might be due to invalid IL or missing references)
		//IL_0569: Unknown result type (might be due to invalid IL or missing references)
		//IL_0570: Unknown result type (might be due to invalid IL or missing references)
		//IL_0487: Unknown result type (might be due to invalid IL or missing references)
		//IL_048e: Expected O, but got Unknown
		//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
		Transform val = cartT.Find("Cart Handle");
		Transform val2 = cartT.Find("Cart Grab Point");
		Transform val3 = null;
		float num = float.MaxValue;
		Bounds val5;
		if ((Object)(object)val2 != (Object)null)
		{
			foreach (Transform item2 in cartT)
			{
				Transform val4 = item2;
				if (((Object)val4).name != "Cart Wall Collider")
				{
					continue;
				}
				BoxCollider componentInChildren = ((Component)val4).GetComponentInChildren<BoxCollider>(true);
				if (!((Object)(object)componentInChildren == (Object)null))
				{
					val5 = CartStretch.CartBounds(cartT, componentInChildren);
					float num2 = Vector3.Distance(((Bounds)(ref val5)).center, val2.localPosition);
					if (num2 < num)
					{
						num = num2;
						val3 = val4;
					}
				}
			}
		}
		if ((Object)(object)val == (Object)null || (Object)(object)val3 == (Object)null)
		{
			Plugin.Log.LogError((object)$"The C.A.R.T.'s handle wasn't found (mesh: {(Object)(object)val != (Object)null}, collider: {(Object)(object)val3 != (Object)null}); the C.A.R.T. Plus will have no stasis button.");
			return;
		}
		Transform val6 = cartT.Find("Cart Mesh");
		MeshFilter val7 = (((Object)(object)val6 != (Object)null) ? ((Component)val6).GetComponent<MeshFilter>() : null);
		float num3;
		if (!((Object)(object)val7 != (Object)null) || !((Object)(object)val7.sharedMesh != (Object)null))
		{
			num3 = center.z + 0.97f;
		}
		else
		{
			val5 = CartStretch.TransformBounds(val7.sharedMesh.bounds, val6, cartT);
			num3 = ((Bounds)(ref val5)).max.z;
		}
		float num4 = num3;
		float num5 = 2f * center.z - num4 - 0.005f;
		List<string> list = new List<string>();
		((Object)TurnedCopy(val, cartT, center)).name = "Cart Handle (Stasis Button)";
		list.Add(((Object)val).name);
		GameObject val8 = TurnedCopy(val3, cartT, center);
		((Object)val8).name = ((Object)val3).name;
		Object.DestroyImmediate((Object)(object)val8.GetComponent<MeshRenderer>());
		val8.AddComponent<CartPlusButton>();
		list.Add("handle collider");
		Vector3 localScale = val8.transform.localScale;
		val8.transform.localScale = new Vector3(localScale.x * 0.7f, localScale.y, localScale.z);
		Transform val9 = cartT.Find("Cart Handle (Stasis Button)");
		if ((Object)(object)val9 != (Object)null)
		{
			SetShrinkIcon(val9);
		}
		List<Transform> list2 = new List<Transform>();
		List<Bounds> list3 = new List<Bounds>();
		foreach (Transform item3 in cartT)
		{
			Transform val10 = item3;
			if (((Object)val10).name != "Cart Wall Collider" || (Object)(object)val10 == (Object)(object)val3 || (Object)(object)val10 == (Object)(object)val8.transform)
			{
				continue;
			}
			BoxCollider componentInChildren2 = ((Component)val10).GetComponentInChildren<BoxCollider>(true);
			if (!((Object)(object)componentInChildren2 == (Object)null))
			{
				Bounds item = CartStretch.CartBounds(cartT, componentInChildren2);
				list3.Add(item);
				if (((Bounds)(ref item)).center.z < center.z - 0.3f)
				{
					list2.Add(val10);
				}
			}
		}
		foreach (Transform item4 in list2)
		{
			Bounds b = CartStretch.CartBounds(cartT, ((Component)item4).GetComponentInChildren<BoxCollider>(true));
			Vector3 mirror = new Vector3(2f * center.x - ((Bounds)(ref b)).center.x, ((Bounds)(ref b)).center.y, 2f * center.z - ((Bounds)(ref b)).center.z);
			if (!list3.Exists((Bounds o) => Vector3.Distance(((Bounds)(ref o)).center, mirror) < 0.08f && Vector3.Distance(((Bounds)(ref o)).size, ((Bounds)(ref b)).size) < 0.08f))
			{
				GameObject obj = TurnedCopy(item4, cartT, center);
				((Object)obj).name = ((Object)item4).name;
				Object.DestroyImmediate((Object)(object)obj.GetComponent<MeshRenderer>());
				list.Add($"collider {((Bounds)(ref b)).size.x:F2}x{((Bounds)(ref b)).size.y:F2}x{((Bounds)(ref b)).size.z:F2} at z {((Bounds)(ref b)).center.z:F2}");
			}
		}
		if ((Object)(object)val6 != (Object)null)
		{
			if (CopyHandleFrame(val6, cartT, center, num5))
			{
				list.Add("handle frame");
			}
			foreach (Transform item5 in val6)
			{
				Transform val11 = item5;
				MeshFilter component = ((Component)val11).GetComponent<MeshFilter>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
				{
					val5 = CartStretch.TransformBounds(component.sharedMesh.bounds, val11, cartT);
					if (!(((Bounds)(ref val5)).max.z >= num5))
					{
						((Object)TurnedCopy(val11, cartT, center)).name = ((Object)val11).name + " (Stasis Button)";
						list.Add(((Object)val11).name);
					}
				}
			}
		}
		if (TryGetScreenBounds(cartT, out var bounds))
		{
			Vector3 center2 = ((Bounds)(ref bounds)).center;
			AddMeter(cartT, new Vector3(2f * center.x - center2.x, center2.y, 2f * center.z - center2.z), ((Bounds)(ref bounds)).size);
		}
		else
		{
			Plugin.Log.LogWarning((object)"Stasis button: the haul screen wasn't found; no recharge meter.");
		}
		Plugin.Log.LogInfo((object)string.Format("Stasis button: copied {0} to the far end (frame cut at z={1:F2}, far end z={2:F2}).", string.Join(", ", list), num5, num4));
	}

	private static bool TryGetScreenBounds(Transform cartT, out Bounds bounds)
	{
		//IL_0001: 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_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: 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_00b4: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
		bounds = default(Bounds);
		Transform val = cartT.Find("Screen/Display Wide") ?? cartT.Find("Screen");
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
		if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null)
		{
			bounds = CartStretch.TransformBounds(component.sharedMesh.bounds, val, cartT);
			return true;
		}
		bool flag = false;
		MeshFilter[] componentsInChildren = ((Component)val).GetComponentsInChildren<MeshFilter>(true);
		foreach (MeshFilter val2 in componentsInChildren)
		{
			if (!((Object)(object)val2.sharedMesh == (Object)null))
			{
				Bounds val3 = CartStretch.TransformBounds(val2.sharedMesh.bounds, ((Component)val2).transform, cartT);
				if (!flag)
				{
					bounds = val3;
					flag = true;
				}
				else
				{
					((Bounds)(ref bounds)).Encapsulate(val3);
				}
			}
		}
		return flag;
	}

	private static bool CopyHandleFrame(Transform body, Transform cartT, Vector3 c, float zCut)
	{
		//IL_0058: 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_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)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: 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_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_048b: Unknown result type (might be due to invalid IL or missing references)
		//IL_048d: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
		MeshFilter component = ((Component)body).GetComponent<MeshFilter>();
		MeshRenderer component2 = ((Component)body).GetComponent<MeshRenderer>();
		Mesh val = (((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null) ? CartStretch.ReadableCopy(component.sharedMesh) : null);
		if ((Object)(object)val == (Object)null || (Object)(object)component2 == (Object)null)
		{
			Plugin.Log.LogWarning((object)"Stasis button: couldn't read the body mesh; the far handle has no frame.");
			return false;
		}
		Matrix4x4 toCart = cartT.worldToLocalMatrix * ((Component)component).transform.localToWorldMatrix;
		Vector3[] vertices = val.vertices;
		Vector3[] normals = val.normals;
		Vector2[] uv = val.uv;
		Vector3[] array = (Vector3[])(object)new Vector3[vertices.Length];
		for (int i = 0; i < vertices.Length; i++)
		{
			array[i] = ((Matrix4x4)(ref toCart)).MultiplyPoint3x4(vertices[i]);
		}
		int[] parent = new int[vertices.Length];
		for (int j = 0; j < vertices.Length; j++)
		{
			parent[j] = j;
		}
		Dictionary<Vector3Int, int> dictionary = new Dictionary<Vector3Int, int>();
		Vector3Int key = default(Vector3Int);
		for (int k = 0; k < vertices.Length; k++)
		{
			((Vector3Int)(ref key))..ctor(Mathf.RoundToInt(array[k].x * 1000f), Mathf.RoundToInt(array[k].y * 1000f), Mathf.RoundToInt(array[k].z * 1000f));
			if (dictionary.TryGetValue(key, out var value))
			{
				Join(k, value);
			}
			else
			{
				dictionary[key] = k;
			}
		}
		int[][] array2 = new int[val.subMeshCount][];
		for (int l = 0; l < val.subMeshCount; l++)
		{
			array2[l] = val.GetTriangles(l);
			for (int m = 0; m + 2 < array2[l].Length; m += 3)
			{
				Join(array2[l][m], array2[l][m + 1]);
				Join(array2[l][m], array2[l][m + 2]);
			}
		}
		Dictionary<int, Bounds> dictionary2 = new Dictionary<int, Bounds>();
		for (int n = 0; n < vertices.Length; n++)
		{
			int key2 = Root(n);
			if (dictionary2.TryGetValue(key2, out var value2))
			{
				((Bounds)(ref value2)).Encapsulate(array[n]);
				dictionary2[key2] = value2;
			}
			else
			{
				dictionary2[key2] = new Bounds(array[n], Vector3.zero);
			}
		}
		HashSet<int> hashSet = new HashSet<int>();
		foreach (KeyValuePair<int, Bounds> item in dictionary2)
		{
			Bounds value3 = item.Value;
			bool num = ((Bounds)(ref value3)).min.z < zCut - 0.01f;
			bool flag = ((Bounds)(ref value3)).max.z < zCut + 0.17f;
			bool flag2 = ((Bounds)(ref value3)).size.x > 1f && ((Bounds)(ref value3)).size.y > 0.5f;
			if (num && flag && !flag2)
			{
				hashSet.Add(item.Key);
			}
		}
		List<int>[] array3 = new List<int>[val.subMeshCount];
		List<int>[] array4 = new List<int>[val.subMeshCount];
		int num2 = 0;
		for (int num3 = 0; num3 < val.subMeshCount; num3++)
		{
			array3[num3] = new List<int>();
			array4[num3] = new List<int>();
			int[] array5 = array2[num3];
			for (int num4 = 0; num4 + 2 < array5.Length; num4 += 3)
			{
				if ((array[array5[num4]].z < zCut && array[array5[num4 + 1]].z < zCut && array[array5[num4 + 2]].z < zCut) || hashSet.Contains(Root(array5[num4])))
				{
					List<int> obj = ((array[array5[num4]].y > 0.28f && array[array5[num4 + 1]].y > 0.28f && array[array5[num4 + 2]].y > 0.28f) ? array3[num3] : array4[num3]);
					obj.Add(array5[num4]);
					obj.Add(array5[num4 + 1]);
					obj.Add(array5[num4 + 2]);
					num2++;
				}
			}
		}
		if (num2 == 0)
		{
			Plugin.Log.LogInfo((object)"Stasis button: no body pieces stick out behind the handle-end wall; no frame copied.");
			return false;
		}
		MakeTurnedMesh("Cart Handle Bar (Stasis Button)", array3, val, array, normals, uv, toCart, c, 0.7f, body, component2, cartT);
		MakeTurnedMesh("Cart Handle Frame (Stasis Button)", array4, val, array, normals, uv, toCart, c, 1f, body, component2, cartT);
		Plugin.Log.LogInfo((object)$"Stasis button: handle frame = {hashSet.Count} of the body's {dictionary2.Count} pieces, {num2} triangles (sticking out past z={zCut:F2}); bar above y={0.28f:F2} narrowed to {0.7f:P0}.");
		return true;
		void Join(int a, int b)
		{
			a = Root(a);
			b = Root(b);
			if (a != b)
			{
				parent[a] = b;
			}
		}
		int Root(int x)
		{
			while (parent[x] != x)
			{
				parent[x] = parent[parent[x]];
				x = parent[x];
			}
			return x;
		}
	}

	private static void MakeTurnedMesh(string name, List<int>[] subTris, Mesh src, Vector3[] cartV, Vector3[] n, Vector2[] uv, Matrix4x4 toCart, Vector3 c, float widthScale, Transform body, MeshRenderer mr, Transform cartT)
	{
		//IL_018e: 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)
		//IL_019c: Expected O, but got Unknown
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: 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_009d: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: 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_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: 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_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		Dictionary<int, int> dictionary = new Dictionary<int, int>();
		List<Vector3> list = new List<Vector3>();
		List<Vector3> list2 = new List<Vector3>();
		List<Vector2> list3 = new List<Vector2>();
		List<int>[] array = new List<int>[subTris.Length];
		int num = 0;
		for (int i = 0; i < subTris.Length; i++)
		{
			array[i] = new List<int>();
			foreach (int item in subTris[i])
			{
				if (!dictionary.TryGetValue(item, out var value))
				{
					value = (dictionary[item] = list.Count);
					Vector3 val = cartV[item];
					float num2 = c.x + (val.x - c.x) * widthScale;
					list.Add(new Vector3(2f * c.x - num2, val.y, 2f * c.z - val.z));
					if (n != null && n.Length == cartV.Length)
					{
						Vector3 val2 = ((Matrix4x4)(ref toCart)).MultiplyVector(n[item]);
						val2.x /= Mathf.Max(widthScale, 0.01f);
						Vector3 val3 = new Vector3(0f - val2.x, val2.y, 0f - val2.z);
						list2.Add(((Vector3)(ref val3)).normalized);
					}
					if (uv != null && uv.Length == cartV.Length)
					{
						list3.Add(uv[item]);
					}
				}
				array[i].Add(value);
				num++;
			}
		}
		if (num != 0)
		{
			Mesh val4 = new Mesh
			{
				name = name
			};
			if (list.Count > 65000)
			{
				val4.indexFormat = (IndexFormat)1;
			}
			val4.SetVertices(list);
			if (list2.Count == list.Count)
			{
				val4.SetNormals(list2);
			}
			if (list3.Count == list.Count)
			{
				val4.SetUVs(0, list3);
			}
			val4.subMeshCount = array.Length;
			for (int j = 0; j < array.Length; j++)
			{
				val4.SetTriangles(array[j], j);
			}
			if (list2.Count != list.Count)
			{
				val4.RecalculateNormals();
			}
			val4.RecalculateBounds();
			((Object)val4).hideFlags = (HideFlags)32;
			GameObject val5 = new GameObject(name)
			{
				layer = ((Component)body).gameObject.layer
			};
			val5.transform.SetParent(cartT, false);
			val5.AddComponent<MeshFilter>().sharedMesh = val4;
			MeshRenderer obj = val5.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterials = ((Renderer)mr).sharedMaterials;
			((Renderer)obj).shadowCastingMode = ((Renderer)mr).shadowCastingMode;
		}
	}

	private static void SetShrinkIcon(Transform knobs)
	{
		//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_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_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Expected O, but got Unknown
		//IL_0123: 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_012b: 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_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		Renderer val = null;
		float num = float.MaxValue;
		Renderer[] componentsInChildren = ((Component)knobs).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val2 in componentsInChildren)
		{
			Transform parent = knobs.parent;
			Bounds bounds = val2.bounds;
			float num2 = Mathf.Abs(parent.InverseTransformPoint(((Bounds)(ref bounds)).center).x - knobs.parent.InverseTransformPoint(knobs.position).x);
			if ((Object)(object)((Component)val2).transform != (Object)(object)knobs && num2 < num)
			{
				num = num2;
				val = val2;
			}
		}
		Texture2D shrinkIcon = CartPlusAssets.ShrinkIcon;
		if ((Object)(object)val == (Object)null || (Object)(object)shrinkIcon == (Object)null || (Object)(object)val.sharedMaterial == (Object)null)
		{
			Plugin.Log.LogWarning((object)"Stasis button: couldn't set the shrink icon; the button keeps the hand.");
			return;
		}
		Material val3 = new Material(val.sharedMaterial)
		{
			name = "Stasis Button Shrink Icon"
		};
		val3.mainTexture = (Texture)(object)shrinkIcon;
		if (val3.HasProperty("_BaseMap"))
		{
			val3.SetTexture("_BaseMap", (Texture)(object)shrinkIcon);
		}
		if (val3.HasProperty("_MainTex"))
		{
			val3.SetTexture("_MainTex", (Texture)(object)shrinkIcon);
		}
		if (val3.HasProperty("_EmissionMap"))
		{
			val3.SetTexture("_EmissionMap", (Texture)(object)shrinkIcon);
		}
		Vector2 mainTextureScale = val3.mainTextureScale;
		Vector2 mainTextureOffset = val3.mainTextureOffset;
		string text = "UVs unreadable; kept the hand's tiling";
		MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
		Mesh val4 = (((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null) ? CartStretch.ReadableCopy(component.sharedMesh) : null);
		Vector2[] array = (((Object)(object)val4 != (Object)null) ? val4.uv : null);
		IconBaseOffset = mainTextureOffset;
		if (array != null && array.Length != 0)
		{
			float num3 = float.MaxValue;
			float num4 = float.MinValue;
			float num5 = float.MaxValue;
			float num6 = float.MinValue;
			Vector2[] array2 = array;
			foreach (Vector2 val5 in array2)
			{
				num3 = Mathf.Min(num3, val5.x);
				num4 = Mathf.Max(num4, val5.x);
				num5 = Mathf.Min(num5, val5.y);
				num6 = Mathf.Max(num6, val5.y);
			}
			if (num4 - num3 > 0.0001f && num6 - num5 > 0.0001f)
			{
				Vector2 val6 = default(Vector2);
				((Vector2)(ref val6))..ctor(0.5f / (num4 - num3), 1f / (num6 - num5));
				IconBaseOffset = new Vector2((0f - num3) * val6.x, (0f - num5) * val6.y);
				val3.mainTextureScale = val6;
				text = $"knob UVs u {num3:F3}..{num4:F3}, v {num5:F3}..{num6:F3} -> tiling {val6}, offset {IconBaseOffset}";
			}
		}
		val3.mainTextureOffset = IconBaseOffset;
		val.sharedMaterial = val3;
		Plugin.Log.LogInfo((object)$"Stasis button: '{((Object)val).name}' shows the shrink icon (shader {((Object)val3.shader).name}; the hand's tiling was {mainTextureScale}, offset {mainTextureOffset}; {text}).");
	}

	private static GameObject TurnedCopy(Transform original, Transform cartT, Vector3 c)
	{
		//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_0024: 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_003a: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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_0082: 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_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_0097: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = Object.Instantiate<GameObject>(((Component)original).gameObject, original.parent, false);
		Transform transform = obj.transform;
		Vector3 val = cartT.InverseTransformPoint(original.position);
		transform.position = cartT.TransformPoint(new Vector3(2f * c.x - val.x, val.y, 2f * c.z - val.z));
		transform.rotation = cartT.rotation * Quaternion.Euler(0f, 180f, 0f) * (Quaternion.Inverse(cartT.rotation) * original.rotation);
		return obj;
	}

	private static void AddMeter(Transform cartT, Vector3 position, Vector3 screenSize)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: 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_0097: 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_00d4: 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_0109: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Stasis Meter");
		val.transform.SetParent(cartT, false);
		val.transform.localPosition = position;
		val.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
		Shader shader = Shader.Find("Sprites/Default");
		float num = Mathf.Max(screenSize.x * 0.92f, 0.64000005f);
		float num2 = Mathf.Clamp(screenSize.y * 0.8f, 0.08f, 0.4f);
		MeterPart(val.transform, "Back", Vector3.zero, new Vector3(num, num2, 0.01f), shader, new Color(0.05f, 0.05f, 0.07f), 3000);
		MeterPart(val.transform, "Fill", new Vector3(0f, 0f, -0.012f), new Vector3(0.6f, Mathf.Min(0.07f, num2 * 0.4f), 0.004f), shader, new Color(0.3f, 1f, 0.4f), 3001);
	}

	private static void MeterPart(Transform parent, string name, Vector3 position, Vector3 size, Shader shader, Color color, int renderQueue)
	{
		//IL_002b: 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_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_0066: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Expected O, but got Unknown
		GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
		Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
		((Object)obj).name = name;
		obj.transform.SetParent(parent, false);
		obj.transform.localPosition = position;
		obj.transform.localScale = size;
		MeshRenderer component = obj.GetComponent<MeshRenderer>();
		if ((Object)(object)shader != (Object)null)
		{
			((Renderer)component).sharedMaterial = new Material(shader)
			{
				name = "Stasis Meter " + name,
				color = color,
				renderQueue = renderQueue
			};
		}
		((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
	}

	private static void LogParts(GameObject cart)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		StringBuilder stringBuilder = new StringBuilder("C.A.R.T. parts:");
		foreach (Transform item in cart.transform)
		{
			Transform t = item;
			Describe(stringBuilder, t, cart.transform, 1);
		}
		List<string> list = new List<string>();
		Component[] components = cart.GetComponents<Component>();
		foreach (Component val in components)
		{
			if ((Object)(object)val != (Object)null)
			{
				list.Add(((object)val).GetType().Name);
			}
		}
		stringBuilder.Append("\n  (root) ").Append(string.Join(", ", list));
		Plugin.Log.LogInfo((object)stringBuilder.ToString());
	}

	private static void Describe(StringBuilder sb, Transform t, Transform cartT, int depth)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: 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_0098: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		List<string> list = new List<string>();
		Component[] components = ((Component)t).GetComponents<Component>();
		foreach (Component val in components)
		{
			if ((Object)(object)val != (Object)null && !(val is Transform))
			{
				list.Add(((object)val).GetType().Name);
			}
		}
		Vector3 val2 = cartT.InverseTransformPoint(t.position);
		sb.Append('\n').Append(' ', depth * 2).Append(((Object)t).name)
			.Append(string.Format(" @({0:F2},{1:F2},{2:F2}) s{3} [{4}]", val2.x, val2.y, val2.z, t.localScale, string.Join(", ", list)));
		if (depth >= 2)
		{
			return;
		}
		foreach (Transform item in t)
		{
			Transform t2 = item;
			Describe(sb, t2, cartT, depth + 1);
		}
	}
}
internal class CartPlusContents
{
	private class Item
	{
		internal PhysGrabObject obj;

		internal Transform t;

		internal Rigidbody rb;

		internal PhysGrabObjectImpactDetector impact;

		internal Vector3 full;

		internal Vector3 small;

		internal Quaternion rotation;

		internal Vector3 scale;

		internal Collider[] colliders;

		internal bool riding;
	}

	private class Rider
	{
		internal PlayerAvatar player;

		internal Transform visuals;

		internal Vector3 scale;

		internal float eyeHeight;
	}

	private const float LockRefresh = 0.25f;

	private const float SettleSeconds = 1f;

	private const float GatherMargin = 0.1f;

	private const float LeaveMargin = 0.3f;

	private const float PlayerUp = 1.2f;

	internal static float LocalCameraDrop;

	private static readonly FieldRef<PlayerAvatar, PlayerTumble> TumbleRef = AccessTools.FieldRefAccess<PlayerAvatar, PlayerTumble>("tumble");

	private static readonly FieldRef<PlayerAvatar, bool> IsLocalRef = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isLocal");

	private static readonly FieldRef<PlayerAvatar, bool> DeadRef = AccessTools.FieldRefAccess<PlayerAvatar, bool>("deadSet");

	private static readonly FieldRef<PlayerAvatar, bool> DisabledRef = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isDisabled");

	private static readonly FieldRef<PlayerTumble, PhysGrabObject> TumbleObjectRef = AccessTools.FieldRefAccess<PlayerTumble, PhysGrabObject>("physGrabObject");

	private readonly Transform cart;

	private readonly PhysGrabObject self;

	private readonly List<Collider> cartColliders = new List<Collider>();

	private readonly List<Item> items = new List<Item>();

	private readonly List<Rider> riders = new List<Rider>();

	private float itemScale = 1f;

	private Vector3 anchorFull;

	private Vector3 anchorSmall;

	internal bool Active
	{
		get
		{
			if (items.Count <= 0)
			{
				return riders.Count > 0;
			}
			return true;
		}
	}

	internal int Count => items.Count + riders.Count;

	internal float ItemScale => itemScale;

	private static bool IsLocal(PlayerAvatar p)
	{
		return IsLocalRef.Invoke(p);
	}

	private static bool Gone(PlayerAvatar p)
	{
		if (!DeadRef.Invoke(p))
		{
			return DisabledRef.Invoke(p);
		}
		return true;
	}

	internal CartPlusContents(Transform cart, PhysGrabObject self)
	{
		this.cart = cart;
		this.self = self;
		Collider[] componentsInChildren = ((Component)cart).GetComponentsInChildren<Collider>(true);
		foreach (Collider val in componentsInChildren)
		{
			if (!val.isTrigger)
			{
				cartColliders.Add(val);
			}
		}
	}

	internal List<Component> Gather()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0045: 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_0075: 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)
		List<Component> list = new List<Component>();
		HashSet<PhysGrabObject> hashSet = new HashSet<PhysGrabObject>();
		if (!TryBasket(out var inCart, out var box))
		{
			return list;
		}
		Vector3 val = inCart.TransformPoint(box.center);
		Vector3 val2 = Vector3.Scale(box.size, inCart.lossyScale) * 0.5f;
		((Vector3)(ref val2))..ctor(Mathf.Abs(val2.x), Mathf.Abs(val2.y), Mathf.Abs(val2.z));
		StringBuilder stringBuilder = new StringBuilder();
		Collider[] array = Physics.OverlapBox(val, val2, inCart.rotation, -1, (QueryTriggerInteraction)1);
		for (int i = 0; i < array.Length; i++)
		{
			PhysGrabObject componentInParent = ((Component)array[i]).GetComponentInParent<PhysGrabObject>();
			if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)componentInParent == (Object)(object)self) && hashSet.Add(componentInParent) && !((Component)componentInParent).transform.IsChildOf(cart) && !((Object)(object)((Component)componentInParent).GetComponentInParent<PlayerTumble>() != (Object)null))
			{
				string text = SkipReason(componentInParent, inCart, box);
				stringBuilder.Append((text == null) ? (" +" + ((Object)componentInParent).name) : (" -" + ((Object)componentInParent).name + " (" + text + ")"));
				if (text == null)
				{
					list.Add((Component)(object)componentInParent);
				}
			}
		}
		foreach (PlayerAvatar item in SemiFunc.PlayerGetList())
		{
			if (!((Object)(object)item == (Object)null) && !((Object)(object)item.playerAvatarVisuals == (Object)null) && !((Object)(object)item.photonView == (Object)null) && item.photonView.ViewID < 16000000 && !Gone(item) && PlayerInBasket(item, inCart, box, 0.1f))
			{
				stringBuilder.Append(" +player " + ((Object)item).name);
				list.Add((Component)(object)item);
			}
		}
		Plugin.Log.LogInfo((object)("C.A.R.T. Plus: basket check:" + ((stringBuilder.Length > 0) ? stringBuilder.ToString() : " empty") + "."));
		return list;
	}

	private static string SkipReason(PhysGrabObject obj, Transform inCart, BoxCollider box)
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)((Component)obj).GetComponentInParent<PhysGrabHinge>() != (Object)null)
		{
			return "door/hinge";
		}
		if ((Object)(object)((Component)obj).GetComponentInParent<EnemyRigidbody>() != (Object)null)
		{
			return "enemy";
		}
		if (!((Object)(object)((Component)obj).GetComponentInParent<ValuableObject>() != (Object)null) && !((Object)(object)((Component)obj).GetComponentInParent<ItemAttributes>() != (Object)null) && !((Object)(object)((Component)obj).GetComponentInParent<PlayerDeathHead>() != (Object)null))
		{
			return "not a valuable or item";
		}
		if (obj.playerGrabbing != null && obj.playerGrabbing.Count > 0)
		{
			return "held";
		}
		if (!Inside(Middle(obj), inCart, box, 0.1f))
		{
			return "middle outside the basket";
		}
		return null;
	}

	internal List<Component> FindLeavers()
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		List<Component> list = new List<Component>();
		if (!TryBasket(out var inCart, out var box))
		{
			return list;
		}
		foreach (Item item in items)
		{
			if (!((Object)(object)item.obj == (Object)null) && !item.riding && !Inside(Middle(item.obj), inCart, box, 0.3f))
			{
				list.Add((Component)(object)item.obj);
			}
		}
		foreach (Rider rider in riders)
		{
			if (!((Object)(object)rider.player == (Object)null) && (Gone(rider.player) || !PlayerInBasket(rider.player, inCart, box, 0.3f)))
			{
				list.Add((Component)(object)rider.player);
			}
		}
		return list;
	}

	private bool TryBasket(out Transform inCart, out BoxCollider box)
	{
		inCart = cart.Find("In Cart");
		box = (((Object)(object)inCart != (Object)null) ? ((Component)inCart).GetComponent<BoxCollider>() : null);
		return (Object)(object)box != (Object)null;
	}

	private static Vector3 Middle(PhysGrabObject obj)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		Rigidbody component = ((Component)obj).GetComponent<Rigidbody>();
		if (!((Object)(object)component != (Object)null))
		{
			return ((Component)obj).transform.position;
		}
		return component.worldCenterOfMass;
	}

	private static bool Inside(Vector3 world, Transform inCart, BoxCollider box, float margin, float extraUp = 0f)
	{
		//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_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: 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_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_0063: 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_0071: 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_007f: 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_008d: 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_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_00a9: 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)
		Transform obj = (((Object)(object)inCart.parent != (Object)null) ? inCart.parent : inCart);
		Bounds val = CartStretch.CartBounds(obj, box);
		Vector3 val2 = obj.InverseTransformPoint(world);
		Vector3 val3 = ((Bounds)(ref val)).min - Vector3.one * margin;
		Vector3 val4 = ((Bounds)(ref val)).max + Vector3.one * margin;
		val4.y += extraUp;
		if (val2.x >= val3.x && val2.x <= val4.x && val2.y >= val3.y && val2.y <= val4.y && val2.z >= val3.z)
		{
			return val2.z <= val4.z;
		}
		return false;
	}

	private static bool PlayerInBasket(PlayerAvatar p, Transform inCart, BoxCollider box, float margin)
	{
		//IL_0054: 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_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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		PlayerTumble val = TumbleRef.Invoke(p);
		PhysGrabObject val2 = (((Object)(object)val != (Object)null && ((Behaviour)val).isActiveAndEnabled) ? TumbleObjectRef.Invoke(val) : null);
		if ((Object)(object)val2 != (Object)null && Inside(Middle(val2), inCart, box, margin))
		{
			return true;
		}
		if (!Inside(((Component)p).transform.position, inCart, box, margin))
		{
			return Inside(((Component)p).transform.position + Vector3.up * 0.3f, inCart, box, margin);
		}
		return true;
	}

	internal void Begin(List<Component> things)
	{
		//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_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_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_0060: 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_007f: 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_009c: 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)
		//IL_00ab: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		Bounds basketFull = CartPlusBuilder.BasketFull;
		Bounds basketSmall = CartPlusBuilder.BasketSmall;
		itemScale = Mathf.Min(((Bounds)(ref basketSmall)).size.x / Mathf.Max(((Bounds)(ref basketFull)).size.x, 0.001f), ((Bounds)(ref basketSmall)).size.z / Mathf.Max(((Bounds)(ref basketFull)).size.z, 0.001f));
		float num = FloorTop(((Bounds)(ref basketFull)).min.y);
		float num2 = num + (((Bounds)(ref basketSmall)).min.y - ((Bounds)(ref basketFull)).min.y);
		anchorFull = new Vector3(((Bounds)(ref basketFull)).center.x, num, ((Bounds)(ref basketFull)).center.z);
		anchorSmall = new Vector3(((Bounds)(ref basketSmall)).center.x, num2, ((Bounds)(ref basketSmall)).center.z);
		foreach (Component thing in things)
		{
			PlayerAvatar val = (PlayerAvatar)(object)((thing is PlayerAvatar) ? thing : null);
			if (val != null)
			{
				AddRider(val);
				continue;
			}
			PhysGrabObject val2 = (PhysGrabObject)(object)((thing is PhysGrabObject) ? thing : null);
			if (val2 != null)
			{
				AddItem(val2);
			}
		}
		Hold(1f);
		Plugin.Log.LogInfo((object)string.Format("{0}: shrinking {1} object(s) and {2} player(s) to {3:P0}.", "C.A.R.T. Plus", items.Count, riders.Count, itemScale));
	}

	private void AddItem(PhysGrabObject obj)
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)obj == (Object)null) && !items.Exists((Item i) => (Object)(object)i.obj == (Object)(object)obj))
		{
			Transform transform = ((Component)obj).transform;
			Vector3 val = cart.InverseTransformPoint(transform.position);
			Item item = new Item
			{
				obj = obj,
				t = transform,
				rb = ((Component)obj).GetComponent<Rigidbody>(),
				impact = ((Component)obj).GetComponent<PhysGrabObjectImpactDetector>(),
				full = val,
				small = anchorSmall + (val - anchorFull) * itemScale,
				rotation = Quaternion.Inverse(cart.rotation) * transform.rotation,
				scale = transform.localScale,
				colliders = ((Component)obj).GetComponentsInChildren<Collider>(true)
			};
			items.Add(item);
			Ride(item, on: true);
		}
	}

	private void AddRider(PlayerAvatar p)
	{
		//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_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)p == (Object)null) && !((Object)(object)p.playerAvatarVisuals == (Object)null) && !riders.Exists((Rider r) => (Object)(object)r.player == (Object)(object)p))
		{
			Rider rider = new Rider
			{
				player = p,
				visuals = ((Component)p.playerAvatarVisuals).transform
			};
			rider.scale = rider.visuals.localScale;
			if (IsLocal(p))
			{
				Camera main = Camera.main;
				rider.eyeHeight = (((Object)(object)main != (Object)null) ? Mathf.Clamp(((Component)main).transform.position.y - ((Component)p).transform.position.y, 0.5f, 2f) : 1.4f);
			}
			riders.Add(rider);
		}
	}

	private float FloorTop(float fallback)
	{
		//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_003f: Unknown result type (might be due to invalid IL or missing references)
		Transform val = cart.Find("Inside");
		BoxCollider val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponentInChildren<BoxCollider>(true) : null);
		if ((Object)(object)val2 == (Object)null)
		{
			return fallback;
		}
		Bounds val3 = CartStretch.CartBounds(cart, val2);
		return ((Bounds)(ref val3)).max.y;
	}

	private void Ride(Item it, bool on)
	{
		it.riding = on;
		Collider[] colliders = it.colliders;
		foreach (Collider val in colliders)
		{
			foreach (Collider cartCollider in cartColliders)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)cartCollider != (Object)null)
				{
					Physics.IgnoreCollision(val, cartCollider, on);
				}
			}
		}
	}

	internal void Hold(float w)
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: 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_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		bool flag = SemiFunc.IsMasterClientOrSingleplayer();
		float num = Mathf.Lerp(itemScale, 1f, w);
		foreach (Item item in items)
		{
			if ((Object)(object)item.obj == (Object)null || (Object)(object)item.t == (Object)null || !item.riding)
			{
				continue;
			}
			Vector3 val = cart.TransformPoint(Vector3.Lerp(item.small, item.full, w));
			Quaternion val2 = cart.rotation * item.rotation;
			item.t.SetPositionAndRotation(val, val2);
			item.t.localScale = item.scale * num;
			if ((Object)(object)item.rb != (Object)null)
			{
				item.rb.position = val;
				item.rb.rotation = val2;
				if (!item.rb.isKinematic)
				{
					item.rb.linearVelocity = Vector3.zero;
					item.rb.angularVelocity = Vector3.zero;
				}
			}
			if (flag)
			{
				item.obj.OverrideKinematic(0.25f);
				item.obj.OverrideGrabDisable(0.25f);
				item.obj.OverrideIndestructible(0.25f);
				if ((Object)(object)item.impact != (Object)null)
				{
					item.impact.ImpactDisable(0.25f);
				}
			}
		}
		foreach (Rider rider in riders)
		{
			if (!((Object)(object)rider.player == (Object)null) && !((Object)(object)rider.visuals == (Object)null))
			{
				rider.visuals.localScale = rider.scale * num;
				if (IsLocal(rider.player))
				{
					LocalCameraDrop = rider.eyeHeight * (1f - num);
				}
			}
		}
	}

	internal void Loosen(Vector3 cartVelocity)
	{
		//IL_0082: 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)
		bool flag = SemiFunc.IsMasterClientOrSingleplayer();
		foreach (Item item in items)
		{
			if ((Object)(object)item.obj == (Object)null || !item.riding)
			{
				continue;
			}
			Ride(item, on: false);
			if (flag)
			{
				item.obj.OverrideIndestructible(1f);
				if ((Object)(object)item.impact != (Object)null)
				{
					item.impact.ImpactDisable(0.5f);
				}
				if ((Object)(object)item.rb != (Object)null)
				{
					item.rb.linearVelocity = cartVelocity;
					item.rb.angularVelocity = Vector3.zero;
				}
			}
		}
	}

	internal void Tighten()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: 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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: 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_00aa: Unknown result type (might be due to invalid IL or miss