Decompiled source of EasyShopping v1.0.1

EasyShopping.dll

Decompiled an hour ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[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("EasyShopping")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("EasyShopping")]
[assembly: AssemblyTitle("EasyShopping")]
[assembly: AssemblyVersion("1.0.1.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 EasyShopping
{
	[BepInPlugin("ThomasPlays.EasyShopping", "EasyShopping", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private static ConfigEntry<Key> _key;

		private static NetworkedEvent _send;

		private float _cool;

		private int _slot;

		private static int _hostSlot;

		private static readonly FieldRef<PhysGrabber, PhysGrabObject> Held = AccessTools.FieldRefAccess<PhysGrabber, PhysGrabObject>("grabbedPhysGrabObject");

		private static readonly FieldRef<PhysGrabber, PhysGrabObject> Looked = AccessTools.FieldRefAccess<PhysGrabber, PhysGrabObject>("currentlyLookingAtPhysGrabObject");

		private static readonly FieldRef<ChatManager, bool> ChatOpen = AccessTools.FieldRefAccess<ChatManager, bool>("chatActive");

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_key = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "SendKey", (Key)20, "Key that sends the item you hold or look at into the shop's checkout area.");
			_send = new NetworkedEvent("EasyShopping_Send_v1", (Action<EventData>)delegate(EventData e)
			{
				if (SemiFunc.IsMasterClientOrSingleplayer() && e.CustomData is int num)
				{
					PhotonView obj = PhotonView.Find(num);
					MoveToCheckout((obj != null) ? ((Component)obj).GetComponent<PhysGrabObject>() : null, ref _hostSlot);
				}
			});
			Log.LogInfo((object)"EasyShopping 1.0.1 loaded");
		}

		private void Update()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			_cool -= Time.deltaTime;
			Keyboard current = Keyboard.current;
			if (current == null || _cool > 0f || !((ButtonControl)current[_key.Value]).wasPressedThisFrame || !SemiFunc.RunIsShop() || ((Object)(object)ChatManager.instance != (Object)null && ChatOpen.Invoke(ChatManager.instance)))
			{
				return;
			}
			PlayerAvatar val = SemiFunc.PlayerAvatarLocal();
			PhysGrabber val2 = (((Object)(object)val != (Object)null) ? val.physGrabber : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			PhysGrabObject val3 = Held.Invoke(val2);
			PhysGrabObject val4 = ((val2.grabbed && (Object)(object)val3 != (Object)null) ? val3 : Looked.Invoke(val2));
			if (!((Object)(object)val4 == (Object)null) && !((Object)(object)((Component)val4).GetComponent<ItemAttributes>() == (Object)null))
			{
				_cool = 0.2f;
				PhotonView component = ((Component)val4).GetComponent<PhotonView>();
				if (val2.grabbed && (Object)(object)val3 == (Object)(object)val4 && (Object)(object)component != (Object)null)
				{
					val2.ReleaseObject(component.ViewID, 0.5f);
				}
				if (SemiFunc.IsMasterClientOrSingleplayer())
				{
					MoveToCheckout(val4, ref _slot);
				}
				else if ((Object)(object)component != (Object)null)
				{
					_send.RaiseEvent((object)component.ViewID, new RaiseEventOptions
					{
						Receivers = (ReceiverGroup)2
					}, SendOptions.SendReliable);
				}
				if ((Object)(object)ItemInfoExtraUI.instance != (Object)null)
				{
					ItemInfoExtraUI.instance.ItemInfoText("SENT TO CHECKOUT", new Color(0.4f, 1f, 0.5f));
				}
			}
		}

		private static void MoveToCheckout(PhysGrabObject pgo, ref int slot)
		{
			//IL_0093: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00ee: 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_0119: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_015f: 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_0169: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)pgo == (Object)null || (Object)(object)ShopManager.instance == (Object)null || (Object)(object)ShopManager.instance.extractionPoint == (Object)null)
			{
				return;
			}
			ExtractionPoint component = ((Component)ShopManager.instance.extractionPoint).GetComponent<ExtractionPoint>();
			Collider val = (((Object)(object)component != (Object)null && (Object)(object)component.extractionArea != (Object)null) ? component.extractionArea.GetComponentInChildren<Collider>() : null);
			Bounds val2 = (Bounds)(((Object)(object)val != (Object)null) ? val.bounds : new Bounds(ShopManager.instance.extractionPoint.position, new Vector3(2f, 1f, 2f)));
			if (((Bounds)(ref val2)).Contains(((Component)pgo).transform.position))
			{
				return;
			}
			int num = slot++ % 16;
			int num2 = (slot - 1) / 16 % 3;
			float num3 = ((float)(num % 4) + 0.5f) / 4f;
			float num4 = ((float)(num / 4) + 0.5f) / 4f;
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(Mathf.Lerp(((Bounds)(ref val2)).min.x, ((Bounds)(ref val2)).max.x, 0.15f + 0.7f * num3), ((Bounds)(ref val2)).max.y, Mathf.Lerp(((Bounds)(ref val2)).min.z, ((Bounds)(ref val2)).max.z, 0.15f + 0.7f * num4));
			RaycastHit val4 = default(RaycastHit);
			float num5 = ((Physics.Raycast(val3 + Vector3.up * 0.5f, Vector3.down, ref val4, ((Bounds)(ref val2)).size.y + 3f, -1, (QueryTriggerInteraction)1) && (Object)(object)((RaycastHit)(ref val4)).collider.attachedRigidbody == (Object)null) ? ((RaycastHit)(ref val4)).point.y : ((Bounds)(ref val2)).min.y);
			float num6 = 0.25f;
			Collider[] componentsInChildren = ((Component)pgo).GetComponentsInChildren<Collider>();
			foreach (Collider val5 in componentsInChildren)
			{
				if (!val5.isTrigger)
				{
					float num7 = num6;
					Bounds bounds = val5.bounds;
					num6 = Mathf.Max(num7, ((Bounds)(ref bounds)).extents.y);
				}
			}
			val3.y = num5 + num6 + 0.1f + (float)num2 * 0.6f;
			pgo.Teleport(val3, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
		}
	}
}