Decompiled source of NajShopCart v1.0.0

NajShopCart.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using REPOLib;
using REPOLib.Modules;
using TMPro;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

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

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NajShopCart
{
	internal sealed class CartDisplay : IDisposable
	{
		private static readonly int MainTex = Shader.PropertyToID("_MainTex");

		private static readonly Dictionary<char, byte[]> Glyphs = new Dictionary<char, byte[]>
		{
			['0'] = new byte[7] { 14, 17, 19, 21, 25, 17, 14 },
			['1'] = new byte[7] { 4, 12, 4, 4, 4, 4, 14 },
			['2'] = new byte[7] { 14, 17, 1, 2, 4, 8, 31 },
			['3'] = new byte[7] { 30, 1, 1, 14, 1, 1, 30 },
			['4'] = new byte[7] { 2, 6, 10, 18, 31, 2, 2 },
			['5'] = new byte[7] { 31, 16, 16, 30, 1, 1, 30 },
			['6'] = new byte[7] { 14, 16, 16, 30, 17, 17, 14 },
			['7'] = new byte[7] { 31, 1, 2, 4, 8, 8, 8 },
			['8'] = new byte[7] { 14, 17, 17, 14, 17, 17, 14 },
			['9'] = new byte[7] { 14, 17, 17, 15, 1, 1, 14 },
			['$'] = new byte[7] { 4, 15, 20, 14, 5, 30, 4 },
			['K'] = new byte[7] { 17, 18, 20, 24, 20, 18, 17 },
			['I'] = new byte[7] { 14, 4, 4, 4, 4, 4, 14 },
			['T'] = new byte[7] { 31, 4, 4, 4, 4, 4, 4 },
			['E'] = new byte[7] { 31, 16, 16, 30, 16, 16, 31 },
			['M'] = new byte[7] { 17, 27, 21, 21, 17, 17, 17 },
			['S'] = new byte[7] { 15, 16, 16, 14, 1, 1, 30 }
		};

		private readonly Texture2D texture;

		private readonly Color32[] referencePixels;

		private readonly Color32[] pixels;

		private readonly int width;

		private readonly int height;

		internal CartDisplay(MeshRenderer renderer)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			Texture2D val = (Texture2D)((Renderer)renderer).sharedMaterial.mainTexture;
			width = ((Texture)val).width;
			height = ((Texture)val).height;
			referencePixels = val.GetPixels32();
			pixels = (Color32[])(object)new Color32[referencePixels.Length];
			texture = new Texture2D(width, height, (TextureFormat)4, true)
			{
				name = "NajShopCart checkout display",
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			MaterialPropertyBlock val2 = new MaterialPropertyBlock();
			((Renderer)renderer).GetPropertyBlock(val2);
			val2.SetTexture(MainTex, (Texture)(object)texture);
			((Renderer)renderer).SetPropertyBlock(val2);
		}

		internal static Color32 PriceColor(int count, bool affordable)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (count != 0)
			{
				if (!affordable)
				{
					return new Color32(byte.MaxValue, (byte)102, (byte)98, byte.MaxValue);
				}
				return new Color32((byte)126, (byte)249, (byte)156, byte.MaxValue);
			}
			return new Color32((byte)109, (byte)203, (byte)251, byte.MaxValue);
		}

		internal void Render(int total, int count, bool affordable)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0071: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			Color32 val = PriceColor(count, affordable);
			Array.Copy(referencePixels, pixels, pixels.Length);
			Color32 val2 = default(Color32);
			for (int i = 12; i < height - 12; i++)
			{
				int num = i * width;
				float num2 = (float)(int)referencePixels[num + width - 17].b / 255f * 0.64f;
				((Color32)(ref val2))..ctor((byte)((float)(int)val.r * num2), (byte)((float)(int)val.g * num2), (byte)((float)(int)val.b * num2), byte.MaxValue);
				for (int j = 10; j < width - 10; j++)
				{
					pixels[num + j] = val2;
				}
			}
			Draw("$" + total.ToString(CultureInfo.InvariantCulture) + "K", height - 16, 11, val);
			Draw("ITEMS " + count.ToString(CultureInfo.InvariantCulture), 30, 3, val);
			texture.SetPixels32(pixels);
			texture.Apply(true);
		}

		private void Draw(string text, int top, int maxScale, Color32 color)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			int num = text.Length * 6 - 1;
			int num2 = Math.Min(maxScale, (width - 24) / num);
			int num3 = (width - num * num2) / 2;
			foreach (char key in text)
			{
				if (Glyphs.TryGetValue(key, out byte[] value))
				{
					for (int j = 0; j < 7; j++)
					{
						for (int k = 0; k < 5; k++)
						{
							if ((value[j] & (1 << 4 - k)) == 0)
							{
								continue;
							}
							for (int l = 0; l < num2; l++)
							{
								for (int m = 0; m < num2; m++)
								{
									pixels[(top - j * num2 - l) * width + num3 + k * num2 + m] = color;
								}
							}
						}
					}
				}
				num3 += 6 * num2;
			}
		}

		public void Dispose()
		{
			Object.Destroy((Object)(object)texture);
		}
	}
	internal sealed class CartPriceLabel : IDisposable
	{
		private const float VisibilityRadius = 3f;

		private const float HeightAboveCart = 0.95f;

		private static readonly FieldRef<WorldSpaceUIValue, Vector3> NativeScale = AccessTools.FieldRefAccess<WorldSpaceUIValue, Vector3>("scale");

		private readonly TextMeshProUGUI text;

		private int shownTotal = -1;

		internal bool IsAlive => (Object)(object)text != (Object)null;

		private CartPriceLabel(TextMeshProUGUI text)
		{
			this.text = text;
		}

		internal static CartPriceLabel? Create()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//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_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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			WorldSpaceUIValue instance = WorldSpaceUIValue.instance;
			TextMeshProUGUI val = default(TextMeshProUGUI);
			if (!Object.op_Implicit((Object)(object)instance) || !((Component)instance).TryGetComponent<TextMeshProUGUI>(ref val))
			{
				return null;
			}
			GameObject val2 = new GameObject("NajShopCart Price", new Type[1] { typeof(RectTransform) });
			val2.SetActive(false);
			RectTransform val3 = (RectTransform)val2.transform;
			((Transform)val3).SetParent(((TMP_Text)val).transform.parent, false);
			val3.anchorMin = ((TMP_Text)val).rectTransform.anchorMin;
			val3.anchorMax = ((TMP_Text)val).rectTransform.anchorMax;
			val3.pivot = ((TMP_Text)val).rectTransform.pivot;
			val3.sizeDelta = ((TMP_Text)val).rectTransform.sizeDelta;
			((Transform)val3).localScale = NativeScale.Invoke(instance);
			TextMeshProUGUI obj = val2.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).font = ((TMP_Text)val).font;
			((TMP_Text)obj).fontSharedMaterial = ((TMP_Text)val).fontSharedMaterial;
			((TMP_Text)obj).alignment = ((TMP_Text)val).alignment;
			((TMP_Text)obj).fontStyle = ((TMP_Text)val).fontStyle;
			((TMP_Text)obj).fontSize = instance.textSizeCost;
			((Graphic)obj).raycastTarget = false;
			val2.SetActive(true);
			return new CartPriceLabel(obj);
		}

		internal void Update(Vector3 cartPosition, int total, Color32 color)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_00b8: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			PlayerController instance = PlayerController.instance;
			int num;
			if (Object.op_Implicit((Object)(object)instance) && ((Behaviour)instance).isActiveAndEnabled)
			{
				Vector3 val = ((Component)instance).transform.position - cartPosition;
				if (((Vector3)(ref val)).sqrMagnitude <= 9f && Object.op_Implicit((Object)(object)HUDCanvas.instance) && Object.op_Implicit((Object)(object)CameraUtils.Instance) && Object.op_Implicit((Object)(object)CameraUtils.Instance.MainCamera))
				{
					num = (Object.op_Implicit((Object)(object)RenderTextureMain.instance) ? 1 : 0);
					goto IL_006c;
				}
			}
			num = 0;
			goto IL_006c;
			IL_006c:
			bool flag = (byte)num != 0;
			((Behaviour)text).enabled = flag;
			if (flag)
			{
				((TMP_Text)text).rectTransform.anchoredPosition = Vector2.op_Implicit(SemiFunc.UIWorldToCanvasPosition(cartPosition + Vector3.up * 0.95f));
				if (((Graphic)text).color != Color32.op_Implicit(color))
				{
					((Graphic)text).color = Color32.op_Implicit(color);
				}
				if (shownTotal != total)
				{
					((TMP_Text)text).text = "-$" + SemiFunc.DollarGetString(total) + "K";
					shownTotal = total;
				}
			}
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)text))
			{
				Object.Destroy((Object)(object)((Component)text).gameObject);
			}
		}
	}
	[DefaultExecutionOrder(10)]
	public sealed class ShopCart : MonoBehaviourPunCallbacks
	{
		internal const int FloorMask = 1;

		private const float SampleInterval = 0.18f;

		private const float ProbeHeight = 0.6f;

		private const float FloorProbeDistance = 4f;

		private const float MaximumStep = 0.27f;

		private const float FloorRiseSpeed = 2.2f;

		private const float FloorFallSpeed = 1.25f;

		private const float HandleMassFraction = 0.25f;

		private const float HandleDistance = 1.5f;

		private const float HandleFollowGain = 5f;

		private const float HandleMaxSpeed = 5f;

		private const float HandleAcceleration = 8f;

		private const float HandleYawGain = 4f;

		private const float HandleMaxTurnSpeed = 4f;

		private const float HandleTurnAcceleration = 14f;

		private const float GrabOverrideDuration = 0.1f;

		private const float ReleaseBrakeRate = 6f;

		private const float StopSpeed = 0.03f;

		private static readonly int FlowTexture = Shader.PropertyToID("_FlowTexture");

		private static readonly Vector3[] FloorOffsets = (Vector3[])(object)new Vector3[5]
		{
			Vector3.zero,
			new Vector3(-0.3f, 0f, -0.33f),
			new Vector3(0.3f, 0f, -0.33f),
			new Vector3(-0.3f, 0f, 0.39f),
			new Vector3(0.3f, 0f, 0.39f)
		};

		private static readonly FieldRef<RoundDirector, List<PhysGrabObject>> GrabObjects = AccessTools.FieldRefAccess<RoundDirector, List<PhysGrabObject>>("physGrabObjects");

		private static readonly FieldRef<ItemAttributes, bool> IsShopItem = AccessTools.FieldRefAccess<ItemAttributes, bool>("shopItem");

		private static readonly FieldRef<ItemAttributes, bool> IsExtractionBlocked = AccessTools.FieldRefAccess<ItemAttributes, bool>("blockExtraction");

		private static readonly FieldRef<ItemAttributes, int> Price = AccessTools.FieldRefAccess<ItemAttributes, int>("value");

		private static readonly FieldRef<PhysGrabObject, bool> NativeMaster = AccessTools.FieldRefAccess<PhysGrabObject, bool>("isMaster");

		private static readonly FieldRef<PhysGrabber, Collider> GrabbedCollider = AccessTools.FieldRefAccess<PhysGrabber, Collider>("grabbedPhysGrabObjectCollider");

		private Rigidbody body;

		private PhotonTransformView transformView;

		private PhysGrabObject grabObject;

		private Collider handle;

		private CartDisplay display;

		private CartPriceLabel? priceLabel;

		private Bounds basket;

		private float restingMass;

		private float floorHeight;

		private int cartBodyId;

		private HashSet<int>? cargoBodyIds;

		private float nextSample;

		private int total;

		private int count;

		private bool affordable = true;

		private bool sendSnapshot;

		internal static ShopCart? Active { get; private set; }

		private void Awake()
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			body = ((Component)this).GetComponent<Rigidbody>();
			cartBodyId = ((Object)body).GetInstanceID();
			BoxCollider[] componentsInChildren = ((Component)this).GetComponentsInChildren<BoxCollider>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Collider)componentsInChildren[i]).hasModifiableContacts = true;
			}
			transformView = ((Component)this).GetComponent<PhotonTransformView>();
			grabObject = ((Component)this).GetComponent<PhysGrabObject>();
			handle = ((Component)((Component)this).transform.Find("Grab Colliders/Handle")).GetComponent<Collider>();
			restingMass = body.mass;
			grabObject.OverrideZeroGravity(float.PositiveInfinity);
			((Component)this).GetComponent<PhysGrabObjectImpactDetector>().ImpactDisable(float.PositiveInfinity);
			Transform val = ((Component)this).transform.Find("Visual");
			SetHoverTexture(val.Find("Hover Effects"));
			display = new CartDisplay(((Component)val.Find("Screens")).GetComponent<MeshRenderer>());
			Transform val2 = ((Component)this).transform.Find("Basket Volume");
			basket = new Bounds(val2.localPosition, val2.localScale);
			floorHeight = body.position.y;
			display.Render(total, count, affordable);
		}

		private static void SetHoverTexture(Transform effects)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			GameObject val = Resources.Load<GameObject>("Items/Item Cart Small");
			PhysGrabCart val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponentInChildren<PhysGrabCart>(true) : null);
			Renderer val3 = default(Renderer);
			if (!((Object)(object)val2 == (Object)null) && Object.op_Implicit((Object)(object)val2.thrustEffect) && ((Component)val2.thrustEffect).TryGetComponent<Renderer>(ref val3) && Object.op_Implicit((Object)(object)val3.sharedMaterial) && Object.op_Implicit((Object)(object)val3.sharedMaterial.mainTexture))
			{
				MaterialPropertyBlock val4 = new MaterialPropertyBlock();
				val4.SetTexture(FlowTexture, val3.sharedMaterial.mainTexture);
				MeshRenderer[] componentsInChildren = ((Component)effects).GetComponentsInChildren<MeshRenderer>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Renderer)componentsInChildren[i]).SetPropertyBlock(val4);
				}
			}
		}

		public override void OnEnable()
		{
			((MonoBehaviourPunCallbacks)this).OnEnable();
			Active = this;
			Physics.ContactModifyEvent += ModifyCargoContacts;
			Physics.ContactModifyEventCCD += ModifyCargoContacts;
		}

		public override void OnDisable()
		{
			if ((Object)(object)Active == (Object)(object)this)
			{
				Active = null;
			}
			Physics.ContactModifyEvent -= ModifyCargoContacts;
			Physics.ContactModifyEventCCD -= ModifyCargoContacts;
			Volatile.Write(ref cargoBodyIds, null);
			priceLabel?.Dispose();
			priceLabel = null;
			((MonoBehaviourPunCallbacks)this).OnDisable();
		}

		private void OnDestroy()
		{
			display?.Dispose();
		}

		private void FixedUpdate()
		{
			//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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.IsMasterClientOrSingleplayer() || body.isKinematic)
			{
				return;
			}
			if (SemiFunc.IsMultiplayer())
			{
				transformView.KinematicClientForce(0.4f);
			}
			bool flag = false;
			PhysGrabber val = null;
			foreach (PhysGrabber item in grabObject.playerGrabbing)
			{
				if (!Object.op_Implicit((Object)(object)item) || !item.grabbed)
				{
					continue;
				}
				flag = true;
				if ((Object)(object)GrabbedCollider.Invoke(item) == (Object)(object)handle)
				{
					item.OverridePhysGrabForcesDisable(0.1f);
					if (val == null)
					{
						val = item;
					}
				}
			}
			KeepUpright();
			Vector3 position = body.position;
			Vector3 linearVelocity = body.linearVelocity;
			Vector3 val2 = Vector3.ProjectOnPlane(linearVelocity, Vector3.up);
			if ((Object)(object)val != (Object)null)
			{
				grabObject.OverrideMass(restingMass * 0.25f, 0.1f);
				val2 = FollowHandle(val, position, val2);
				body.linearVelocity = val2 + Vector3.up * linearVelocity.y;
			}
			else if (!flag && ((Vector3)(ref val2)).sqrMagnitude > 0f)
			{
				val2 *= Mathf.Exp(-6f * Time.fixedDeltaTime);
				if (((Vector3)(ref val2)).sqrMagnitude < 0.0009f)
				{
					val2 = Vector3.zero;
				}
				body.linearVelocity = val2 + Vector3.up * linearVelocity.y;
			}
			Vector3 lookAhead = Vector3.ClampMagnitude(val2 * 0.18f, 0.22f);
			if (TrySampleFloor(position, lookAhead, out var height))
			{
				float num = ((height > floorHeight) ? 2.2f : 1.25f);
				floorHeight = Mathf.MoveTowards(floorHeight, height, num * Time.fixedDeltaTime);
			}
			float num2 = (floorHeight - position.y) * 144f - linearVelocity.y * 24f;
			float num3 = ((flag && (Object)(object)val == (Object)null) ? 0f : (-7f));
			body.AddForce(Vector3.up * Mathf.Clamp(num2, num3, 32f), (ForceMode)5);
		}

		private Vector3 FollowHandle(PhysGrabber holder, Vector3 position, Vector3 velocity)
		{
			//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_0024: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a7: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position2 = ((Component)holder).transform.position;
			float num = 8f * Time.fixedDeltaTime;
			if (((Bounds)(ref basket)).Contains(((Component)this).transform.InverseTransformPoint(position2 + Vector3.up * 0.25f)))
			{
				return Vector3.MoveTowards(velocity, Vector3.zero, num);
			}
			Vector3 val = Vector3.ProjectOnPlane(((Component)holder).transform.forward, Vector3.up);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3 val2 = Vector3.ProjectOnPlane(position - position2, Vector3.up);
			Vector3 val3 = normalized * 1.5f - val2;
			float num2 = Mathf.Sqrt(16f * ((Vector3)(ref val3)).magnitude);
			Vector3 val4 = Vector3.ClampMagnitude(val3 * 5f, Mathf.Min(5f, num2));
			if (((Vector3)(ref val2)).sqrMagnitude >= 0.0025f)
			{
				float num3 = Mathf.Atan2(val2.x, val2.z) * 57.29578f;
				Quaternion rotation = body.rotation;
				float num4 = Mathf.Clamp(Mathf.DeltaAngle(((Quaternion)(ref rotation)).eulerAngles.y, num3) * (MathF.PI / 180f) * 4f, -4f, 4f);
				body.angularVelocity = Vector3.up * Mathf.MoveTowards(body.angularVelocity.y, num4, 14f * Time.fixedDeltaTime);
			}
			return Vector3.MoveTowards(velocity, val4, num);
		}

		private void ModifyCargoContacts(PhysicsScene _, NativeArray<ModifiableContactPair> pairs)
		{
			//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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			HashSet<int> hashSet = Volatile.Read(in cargoBodyIds);
			if (hashSet == null)
			{
				return;
			}
			for (int i = 0; i < pairs.Length; i++)
			{
				ModifiableContactPair val = pairs[i];
				ModifiableMassProperties massProperties = ((ModifiableContactPair)(ref val)).massProperties;
				if (((ModifiableContactPair)(ref val)).bodyInstanceID == cartBodyId && hashSet.Contains(((ModifiableContactPair)(ref val)).otherBodyInstanceID))
				{
					massProperties.inverseMassScale = 0f;
					massProperties.inverseInertiaScale = 0f;
				}
				else
				{
					if (((ModifiableContactPair)(ref val)).otherBodyInstanceID != cartBodyId || !hashSet.Contains(((ModifiableContactPair)(ref val)).bodyInstanceID))
					{
						continue;
					}
					massProperties.otherInverseMassScale = 0f;
					massProperties.otherInverseInertiaScale = 0f;
				}
				((ModifiableContactPair)(ref val)).massProperties = massProperties;
			}
		}

		private void KeepUpright()
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//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_0055: 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_0062: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			Quaternion rotation = body.rotation;
			if ((rotation * Vector3.up).y < 0.999999f)
			{
				body.rotation = Quaternion.Euler(0f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f);
			}
			Vector3 angularVelocity = body.angularVelocity;
			if (angularVelocity.x * angularVelocity.x + angularVelocity.z * angularVelocity.z > 1E-06f)
			{
				body.angularVelocity = Vector3.up * angularVelocity.y;
			}
		}

		private bool TrySampleFloor(Vector3 position, Vector3 lookAhead, out float height)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0044: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_009c: 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_00b1: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			height = float.NegativeInfinity;
			Vector3[] floorOffsets = FloorOffsets;
			RaycastHit val4 = default(RaycastHit);
			foreach (Vector3 val in floorOffsets)
			{
				Vector3 val2 = body.rotation * val;
				Vector3 val3 = ((Vector3.Dot(val2, lookAhead) > 0f) ? lookAhead : Vector3.zero);
				if (Physics.Raycast(position + val2 + val3 + Vector3.up * 0.6f, Vector3.down, ref val4, 4f, 1, (QueryTriggerInteraction)1) && !(((RaycastHit)(ref val4)).normal.y < 0.6f) && !(((RaycastHit)(ref val4)).point.y > position.y + 0.27f))
				{
					float num = (0f - Vector3.Dot(((RaycastHit)(ref val4)).normal, lookAhead - val3)) / ((RaycastHit)(ref val4)).normal.y;
					height = Mathf.Max(height, ((RaycastHit)(ref val4)).point.y + Mathf.Clamp(num, 0f, 0.13f));
				}
			}
			return !float.IsNegativeInfinity(height);
		}

		private void LateUpdate()
		{
			//IL_0077: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			PhysGrabber instance = PhysGrabber.instance;
			if (Object.op_Implicit((Object)(object)instance) && instance.grabbed && (Object)(object)GrabbedCollider.Invoke(instance) == (Object)(object)handle)
			{
				instance.OverrideGrabDistance(1.5f);
				instance.OverridePhysGrabForcesDisable(0.1f);
			}
			if (priceLabel == null || !priceLabel.IsAlive)
			{
				priceLabel = CartPriceLabel.Create();
			}
			priceLabel?.Update(((Component)this).transform.position, total, CartDisplay.PriceColor(count, affordable));
			if (Time.time < nextSample || !SemiFunc.IsMasterClientOrSingleplayer() || !Object.op_Implicit((Object)(object)RoundDirector.instance) || !Object.op_Implicit((Object)(object)StatsManager.instance))
			{
				return;
			}
			nextSample = Time.time + 0.18f;
			int num = 0;
			int num2 = 0;
			HashSet<int> hashSet = null;
			Rigidbody val = default(Rigidbody);
			PlayerTumble val2 = default(PlayerTumble);
			ItemAttributes val3 = default(ItemAttributes);
			foreach (PhysGrabObject item in GrabObjects.Invoke(RoundDirector.instance))
			{
				if (Object.op_Implicit((Object)(object)item) && !((Object)(object)item == (Object)(object)grabObject) && ((Bounds)(ref basket)).Contains(((Component)this).transform.InverseTransformPoint(((Component)item).transform.TransformPoint(item.midPointOffset))))
				{
					if (((Component)item).TryGetComponent<Rigidbody>(ref val) && !val.isKinematic && !((Component)item).TryGetComponent<PlayerTumble>(ref val2))
					{
						(hashSet ?? (hashSet = new HashSet<int>())).Add(((Object)val).GetInstanceID());
					}
					if (((Component)item).TryGetComponent<ItemAttributes>(ref val3) && IsShopItem.Invoke(val3) && !IsExtractionBlocked.Invoke(val3))
					{
						num += Mathf.Max(0, Price.Invoke(val3));
						num2++;
					}
				}
			}
			Volatile.Write(ref cargoBodyIds, hashSet);
			bool newAffordable = num <= SemiFunc.StatGetRunCurrency();
			if ((ApplyDisplay(num, num2, newAffordable) || sendSnapshot) && SemiFunc.IsMultiplayer() && ((MonoBehaviourPun)this).photonView.IsMine)
			{
				((MonoBehaviourPun)this).photonView.RPC("ReceiveCartTotals", (RpcTarget)1, new object[3] { total, count, affordable });
				sendSnapshot = false;
			}
		}

		private bool ApplyDisplay(int newTotal, int newCount, bool newAffordable)
		{
			if (total == newTotal && count == newCount && affordable == newAffordable)
			{
				return false;
			}
			total = newTotal;
			count = newCount;
			affordable = newAffordable;
			display.Render(total, count, affordable);
			return true;
		}

		[PunRPC]
		private void ReceiveCartTotals(int newTotal, int newCount, bool newAffordable, PhotonMessageInfo info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (info.Sender != null && info.Sender == PhotonNetwork.MasterClient && newTotal >= 0 && newCount >= 0)
			{
				ApplyDisplay(newTotal, newCount, newAffordable);
			}
		}

		public override void OnPlayerEnteredRoom(Player newPlayer)
		{
			if (PhotonNetwork.IsMasterClient && ((MonoBehaviourPun)this).photonView.IsMine)
			{
				((MonoBehaviourPun)this).photonView.RPC("ReceiveCartTotals", newPlayer, new object[3] { total, count, affordable });
			}
		}

		public override void OnMasterClientSwitched(Player newMasterClient)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			bool isLocal = newMasterClient.IsLocal;
			NativeMaster.Invoke(grabObject) = isLocal;
			Volatile.Write(ref cargoBodyIds, null);
			body.isKinematic = !isLocal;
			if (isLocal)
			{
				body.collisionDetectionMode = (CollisionDetectionMode)2;
				floorHeight = body.position.y;
				nextSample = 0f;
				sendSnapshot = true;
			}
		}
	}
	[BepInPlugin("com.najvlad.najshopcart", "NajShopCart", "1.0.0")]
	[BepInDependency("REPOLib", "4.5.1")]
	public sealed class ShopCartPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(SemiFunc), "OnSceneSwitch")]
		private static class SceneSwitchPatch
		{
			private static void Prefix()
			{
				if ((Object)(object)instance == (Object)null)
				{
					return;
				}
				instance.closingLevel = LevelGenerator.Instance;
				ShopCart active = ShopCart.Active;
				if ((Object)(object)active == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
				{
					return;
				}
				if (PhotonNetwork.InRoom && ((MonoBehaviourPun)active).photonView.ViewID != 0)
				{
					if (((MonoBehaviourPun)active).photonView.IsMine)
					{
						PhotonNetwork.Destroy(((Component)active).gameObject);
					}
				}
				else
				{
					Object.Destroy((Object)(object)((Component)active).gameObject);
				}
			}
		}

		private const string PluginGuid = "com.najvlad.najshopcart";

		private const string PrefabId = "Najvlad/NajShopCart";

		private const string PrefabPath = "assets/shopcart/generated/najshopcart.prefab";

		private const string GrabTag = "Phys Grab Object";

		private static readonly Vector2[] CheckoutOffsets = (Vector2[])(object)new Vector2[9]
		{
			new Vector2(1.45f, 0.7f),
			new Vector2(-1.45f, 0.7f),
			new Vector2(1.95f, 0.9f),
			new Vector2(-1.95f, 0.9f),
			new Vector2(1.25f, 1.65f),
			new Vector2(-1.25f, 1.65f),
			new Vector2(0f, 2.1f),
			new Vector2(2.35f, 1.25f),
			new Vector2(-2.35f, 1.25f)
		};

		private static ShopCartPlugin? instance;

		private PrefabRef? prefabRef;

		private GameObject? registeredPrefab;

		private LevelGenerator? spawnedFor;

		private LevelGenerator? closingLevel;

		private LevelGenerator? waitingForPlacement;

		private float nextSpawnCheck;

		private Harmony? harmony;

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			instance = this;
			BundleLoader.OnAllBundlesLoaded += RegisterPrefab;
			harmony = new Harmony("com.najvlad.najshopcart");
			harmony.PatchAll(typeof(ShopCartPlugin).Assembly);
		}

		private void OnDestroy()
		{
			BundleLoader.OnAllBundlesLoaded -= RegisterPrefab;
			Harmony? obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			if (Object.op_Implicit((Object)(object)registeredPrefab))
			{
				Object.Destroy((Object)(object)registeredPrefab);
			}
			instance = null;
		}

		private void RegisterPrefab()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			if (prefabRef != null)
			{
				return;
			}
			GameObject val = null;
			foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
			{
				if (allLoadedAssetBundle.Contains("assets/shopcart/generated/najshopcart.prefab"))
				{
					val = allLoadedAssetBundle.LoadAsset<GameObject>("assets/shopcart/generated/najshopcart.prefab");
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"NajShopCart.repobundle did not provide the cart prefab.");
				return;
			}
			GameObject val2 = new GameObject("NajShopCart Template Parent");
			val2.SetActive(false);
			GameObject val3 = null;
			try
			{
				val3 = Object.Instantiate<GameObject>(val, val2.transform);
				((Object)val3).name = "NajShopCart";
				val3.SetActive(false);
				ConfigurePrefab(val3);
				val3.transform.SetParent((Transform)null, false);
				Object.DontDestroyOnLoad((Object)(object)val3);
				prefabRef = NetworkPrefabs.RegisterNetworkPrefab("Najvlad/NajShopCart", val3);
				if (prefabRef == null)
				{
					throw new InvalidOperationException("REPOLib declined registration of Najvlad/NajShopCart");
				}
				registeredPrefab = val3;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered the NajShopCart network prefab.");
			}
			catch (Exception ex)
			{
				if (Object.op_Implicit((Object)(object)val3))
				{
					Object.Destroy((Object)(object)val3);
				}
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
			finally
			{
				Object.Destroy((Object)(object)val2);
			}
		}

		private void ConfigurePrefab(GameObject template)
		{
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Expected O, but got Unknown
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Expected O, but got Unknown
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Expected O, but got Unknown
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Expected O, but got Unknown
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Expected O, but got Unknown
			int num = LayerMask.NameToLayer("PhysGrabObject");
			if (num < 0)
			{
				throw new InvalidOperationException("The PhysGrabObject layer is missing.");
			}
			int num2 = FindBodyLayer(num);
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Cart body collision layer: " + LayerMask.LayerToName(num2) + "."));
			Transform val = template.transform.Find("Body Colliders");
			BoxCollider[] componentsInChildren = ((Component)val).GetComponentsInChildren<BoxCollider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.layer = num2;
			}
			ConfigureBasketFloor(((Component)val.Find("basket_floor")).GetComponent<BoxCollider>());
			template.layer = num;
			template.tag = "Phys Grab Object";
			componentsInChildren = ((Component)template.transform.Find("Grab Colliders")).GetComponentsInChildren<BoxCollider>(true);
			foreach (BoxCollider obj in componentsInChildren)
			{
				((Component)obj).gameObject.layer = num;
				((Component)obj).gameObject.tag = "Phys Grab Object";
				((Component)obj).gameObject.AddComponent<PhysGrabObjectCollider>();
			}
			PhotonView obj2 = template.AddComponent<PhotonView>();
			PhotonTransformView item = template.AddComponent<PhotonTransformView>();
			obj2.observableSearch = (ObservableSearch)0;
			obj2.ObservedComponents = new List<Component> { (Component)(object)item };
			obj2.Synchronization = (ViewSynchronization)3;
			PhysGrabObject obj3 = template.AddComponent<PhysGrabObject>();
			obj3.overrideTagsAndLayers = false;
			obj3.ignoreGrabPointCentering = true;
			PhysGrabObjectImpactDetector obj4 = template.AddComponent<PhysGrabObjectImpactDetector>();
			obj4.playerHurtDisable = true;
			obj4.destroyDisable = true;
			obj4.particleDisable = true;
			obj4.slidingDisable = true;
			obj4.destroyInvestigate = false;
			obj4.indestructibleBreakEffects = false;
			obj4.onAllImpacts = new UnityEvent();
			obj4.onImpactLight = new UnityEvent();
			obj4.onImpactMedium = new UnityEvent();
			obj4.onImpactHeavy = new UnityEvent();
			obj4.onAllBreaks = new UnityEvent();
			obj4.onBreakLight = new UnityEvent();
			obj4.onBreakMedium = new UnityEvent();
			obj4.onBreakHeavy = new UnityEvent();
			obj4.onDestroy = new UnityEvent();
			obj4.onHurtColliderHit = new UnityEvent();
			template.AddComponent<ShopCart>();
		}

		private static void ConfigureBasketFloor(BoxCollider floor)
		{
			//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_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_005e: 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_0087: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			int num = LayerMask.NameToLayer("PlayerOnlyCollision");
			int num2 = LayerMask.NameToLayer("Player");
			if (num < 0 || num2 < 0)
			{
				throw new InvalidOperationException("The player collision layers are missing.");
			}
			GameObject val = new GameObject("Player Floor")
			{
				layer = num,
				tag = "Phys Grab Object"
			};
			val.transform.SetParent(((Component)floor).transform, false);
			BoxCollider obj = val.AddComponent<BoxCollider>();
			obj.center = floor.center;
			obj.size = floor.size;
			((Collider)obj).sharedMaterial = ((Collider)floor).sharedMaterial;
			((Collider)obj).excludeLayers = LayerMask.op_Implicit(~(1 << num2));
			((Collider)floor).excludeLayers = LayerMask.op_Implicit(LayerMask.op_Implicit(((Collider)floor).excludeLayers) | (1 << num2));
		}

		private static int FindBodyLayer(int grabLayer)
		{
			//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)
			LayerMask val = SemiFunc.LayerMaskGetVisionObstruct();
			int value = ((LayerMask)(ref val)).value;
			int num = LayerMask.NameToLayer("Player");
			string[] array = new string[2] { "IgnorePhysGrab", "Ignore Raycast" };
			for (int i = 0; i < array.Length; i++)
			{
				int num2 = LayerMask.NameToLayer(array[i]);
				if (num2 >= 0 && (value & (1 << num2)) == 0 && !Physics.GetIgnoreLayerCollision(num2, grabLayer) && !Physics.GetIgnoreLayerCollision(num2, 0) && (num < 0 || !Physics.GetIgnoreLayerCollision(num2, num)))
				{
					return num2;
				}
			}
			throw new InvalidOperationException("No game layer collides with players and products while allowing the grab beam through the basket.");
		}

		private void Update()
		{
			//IL_008b: 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_00e0: 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_0130: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < nextSpawnCheck)
			{
				return;
			}
			nextSpawnCheck = Time.unscaledTime + 0.5f;
			LevelGenerator val = LevelGenerator.Instance;
			if (prefabRef == null || !Object.op_Implicit((Object)(object)val) || !val.Generated || (Object)(object)val == (Object)(object)spawnedFor || (Object)(object)val == (Object)(object)closingLevel || !Object.op_Implicit((Object)(object)RunManager.instance) || !SemiFunc.RunIsShop() || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			if ((Object)(object)ShopCart.Active != (Object)null && ((Component)ShopCart.Active).gameObject.scene == ((Component)val).gameObject.scene)
			{
				spawnedFor = val;
			}
			else
			{
				ExtractionPoint val2 = default(ExtractionPoint);
				if (!Object.op_Implicit((Object)(object)ShopManager.instance) || !Object.op_Implicit((Object)(object)ShopManager.instance.extractionPoint) || !((Component)ShopManager.instance.extractionPoint).TryGetComponent<ExtractionPoint>(ref val2) || ((Component)val2).gameObject.scene != ((Component)val).gameObject.scene)
				{
					return;
				}
				if (!TryFindPlacement(val2, out var position, out var rotation))
				{
					if ((Object)(object)waitingForPlacement != (Object)(object)val)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)"Waiting for free floor space next to the checkout.");
					}
					waitingForPlacement = val;
					return;
				}
				GameObject val3 = NetworkPrefabs.SpawnNetworkPrefab(prefabRef, position, rotation, (byte)0, (object[])null);
				if (!((Object)(object)val3 == (Object)null))
				{
					spawnedFor = val;
					val3.SetActive(true);
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Spawned one NajShopCart near the checkout at {position:F2}.");
				}
			}
		}

		private static bool TryFindPlacement(ExtractionPoint checkout, out Vector3 position, out Quaternion rotation)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0027: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0046: 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_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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: 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)
			Vector3 position2 = checkout.platform.position;
			Vector3 val = Vector3.ProjectOnPlane(checkout.ramp.position - position2, Vector3.up);
			if (((Vector3)(ref val)).sqrMagnitude < 0.04f)
			{
				val = Vector3.ProjectOnPlane(((Component)checkout).transform.forward, Vector3.up);
			}
			((Vector3)(ref val)).Normalize();
			rotation = Quaternion.LookRotation(val);
			Vector3 val2 = rotation * Vector3.right;
			int num = LayerMask.op_Implicit(SemiFunc.LayerMaskGetShouldHits());
			RaycastHit val3 = default(RaycastHit);
			foreach (Vector2 checkoutOffset in GetCheckoutOffsets())
			{
				if (Physics.Raycast(position2 + val2 * checkoutOffset.x + val * checkoutOffset.y + Vector3.up * 0.75f, Vector3.down, ref val3, 1.6f, 1, (QueryTriggerInteraction)1) && !(((RaycastHit)(ref val3)).normal.y < 0.7f) && !(Mathf.Abs(((RaycastHit)(ref val3)).point.y - position2.y) > 0.5f) && !((RaycastHit)(ref val3)).transform.IsChildOf(checkout.platform) && !((RaycastHit)(ref val3)).transform.IsChildOf(checkout.ramp))
				{
					Vector3 val4 = ((RaycastHit)(ref val3)).point + rotation * new Vector3(0f, 0.405f, 0.04f);
					Vector3 val5 = ((RaycastHit)(ref val3)).point + rotation * new Vector3(0f, 0.75f, -0.38f);
					if (!Physics.CheckBox(val4, new Vector3(0.385f, 0.325f, 0.465f), rotation, num, (QueryTriggerInteraction)1) && !Physics.CheckBox(val5, new Vector3(0.305f, 0.1f, 0.145f), rotation, num, (QueryTriggerInteraction)1))
					{
						position = ((RaycastHit)(ref val3)).point;
						return true;
					}
				}
			}
			position = default(Vector3);
			return false;
		}

		private static IEnumerable<Vector2> GetCheckoutOffsets()
		{
			Vector2[] checkoutOffsets = CheckoutOffsets;
			for (int i = 0; i < checkoutOffsets.Length; i++)
			{
				yield return checkoutOffsets[i];
			}
			for (float radius = 1.3f; radius <= 4.4f; radius += 0.55f)
			{
				for (int i = 0; i < 16; i++)
				{
					float num = (float)i * (MathF.PI / 8f);
					yield return radius * new Vector2(Mathf.Sin(num), Mathf.Cos(num));
				}
			}
		}
	}
}