Decompiled source of PEAK Tool Belt v1.0.0

tony4twentys-PEAK Tool Belt.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using PhotonCustomPropsUtils;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.Core.Serizalization;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PEAK Tool Belt")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PEAK Tool Belt")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5790c129-81b9-40c2-bbe5-e13b4d2fbd84")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
namespace PEAK_Tool_Belt
{
	public class ToolBeltSlotUI : MonoBehaviour
	{
		public RawImage icon;

		public TextMeshProUGUI nameText;

		public Image borderImage;

		public Image innerBackground;

		public Image cooldownOverlay;

		public int slotIndex;

		public bool isSelected = false;

		public bool isOnCooldown = false;

		public void SetItem(ushort itemId, string itemName, bool isOneTimeUse)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			Item val = default(Item);
			if (ItemDatabase.TryGetItem(itemId, ref val))
			{
				Texture2D val2 = val.UIData.GetIcon();
				if ((Object)(object)val2 != (Object)null)
				{
					icon.texture = (Texture)(object)val2;
					((Behaviour)icon).enabled = true;
				}
			}
			((TMP_Text)nameText).text = itemName;
			PEAKToolBeltPlugin instance = PEAKToolBeltPlugin.Instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)innerBackground != (Object)null)
			{
				((Graphic)innerBackground).color = instance.ParseHexColor(instance.slotBackgroundColor.Value);
			}
		}

		public void SetSelected(bool selected)
		{
			//IL_0067: 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_00c7: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			isSelected = selected;
			PEAKToolBeltPlugin instance = PEAKToolBeltPlugin.Instance;
			if (!((Object)(object)instance != (Object)null))
			{
				return;
			}
			if ((Object)(object)borderImage != (Object)null)
			{
				if (selected)
				{
					((Graphic)borderImage).color = instance.ParseHexColor(instance.selectedSlotColor.Value);
				}
				else
				{
					((Graphic)borderImage).color = instance.ParseHexColor(instance.slotBorderColor.Value);
				}
			}
			else if ((Object)(object)innerBackground != (Object)null)
			{
				if (selected)
				{
					((Graphic)innerBackground).color = instance.ParseHexColor(instance.selectedSlotColor.Value);
				}
				else
				{
					((Graphic)innerBackground).color = instance.ParseHexColor(instance.slotBackgroundColor.Value);
				}
			}
			else if ((Object)(object)nameText != (Object)null)
			{
				if (selected)
				{
					((Graphic)nameText).color = instance.ParseHexColor(instance.selectedSlotColor.Value);
				}
				else
				{
					((Graphic)nameText).color = instance.ParseHexColor(instance.textColor.Value);
				}
			}
		}

		public void SetCooldown(bool onCooldown, float cooldownProgress = 0f)
		{
			isOnCooldown = onCooldown;
			((Component)cooldownOverlay).gameObject.SetActive(onCooldown);
			if (onCooldown)
			{
				cooldownOverlay.fillAmount = cooldownProgress;
			}
		}
	}
	[BepInPlugin("tony4twentys.PEAK_Tool_Belt", "PEAK Tool Belt", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class PEAKToolBeltPlugin : BaseUnityPlugin, IOnEventCallback
	{
		[Serializable]
		public class CustomItemConfig
		{
			public ushort itemID;

			public bool isOneTimeUse;
		}

		[CompilerGenerated]
		private sealed class <AutoDestroyStone>d__62 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public PEAKToolBeltPlugin <>4__this;

			private Character <localCharacter>5__1;

			private Player <player>5__2;

			private bool <stoneFound>5__3;

			private int <maxAttempts>5__4;

			private int <attempt>5__5;

			private ItemSlot <tempSlot>5__6;

			private int <i>5__7;

			private ItemSlot <slot>5__8;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <AutoDestroyStone>d__62(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<localCharacter>5__1 = null;
				<player>5__2 = null;
				<tempSlot>5__6 = null;
				<slot>5__8 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0297: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a1: Expected O, but got Unknown
				//IL_013e: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_0245: Unknown result type (might be due to invalid IL or missing references)
				//IL_024f: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
				{
					<>1__state = -1;
					<localCharacter>5__1 = Character.localCharacter;
					Character obj = <localCharacter>5__1;
					if ((Object)(object)((obj != null) ? obj.player : null) == (Object)null)
					{
						return false;
					}
					<player>5__2 = <localCharacter>5__1.player;
					<stoneFound>5__3 = false;
					<maxAttempts>5__4 = ((!PhotonNetwork.IsConnected) ? 1 : 3);
					<attempt>5__5 = 0;
					goto IL_027a;
				}
				case 1:
					<>1__state = -1;
					goto IL_0260;
				case 2:
					{
						<>1__state = -1;
						return false;
					}
					IL_027a:
					if (<attempt>5__5 < <maxAttempts>5__4)
					{
						if ((Object)(object)<localCharacter>5__1.refs?.items != (Object)null)
						{
							<localCharacter>5__1.refs.items.photonView.RPC("DestroyHeldItemRpc", (RpcTarget)0, Array.Empty<object>());
						}
						<tempSlot>5__6 = <player>5__2.GetItemSlot((byte)250);
						if (<tempSlot>5__6 != null && !<tempSlot>5__6.IsEmpty() && (Object)(object)<tempSlot>5__6.prefab != (Object)null && <tempSlot>5__6.prefab.itemID == 72)
						{
							<player>5__2.EmptySlot(Optionable<byte>.Some((byte)250));
							<stoneFound>5__3 = true;
						}
						<i>5__7 = 0;
						while (<i>5__7 < <player>5__2.itemSlots.Length)
						{
							<slot>5__8 = <player>5__2.itemSlots[<i>5__7];
							if (!<slot>5__8.IsEmpty() && (Object)(object)<slot>5__8.prefab != (Object)null && <slot>5__8.prefab.itemID == 72)
							{
								<player>5__2.EmptySlot(Optionable<byte>.Some((byte)<i>5__7));
								<stoneFound>5__3 = true;
							}
							<slot>5__8 = null;
							<i>5__7++;
						}
						if (!<stoneFound>5__3)
						{
							if (<attempt>5__5 < <maxAttempts>5__4 - 1)
							{
								<>2__current = (object)new WaitForSeconds(PhotonNetwork.IsConnected ? 0.2f : 0.1f);
								<>1__state = 1;
								return true;
							}
							goto IL_0260;
						}
					}
					<>2__current = (object)new WaitForSeconds(0.1f);
					<>1__state = 2;
					return true;
					IL_0260:
					<tempSlot>5__6 = null;
					<attempt>5__5++;
					goto IL_027a;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <AutoProcessStoneSelection>d__61 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public PEAKToolBeltPlugin <>4__this;

			private float <waitTime>5__1;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <AutoProcessStoneSelection>d__61(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Expected O, but got Unknown
				//IL_0172: Unknown result type (might be due to invalid IL or missing references)
				//IL_017c: Expected O, but got Unknown
				//IL_0126: Unknown result type (might be due to invalid IL or missing references)
				//IL_0130: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>4__this.isAutoProcessing = true;
					<>2__current = (object)new WaitForSeconds(0.1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.currentItemIndex = 0;
					<>4__this.UpdateUISelection();
					<>2__current = (object)new WaitForSeconds(0.2f);
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					if (<>4__this.currentItemIndex >= 0 && <>4__this.currentItemIndex < <>4__this.toolBeltItems.Count)
					{
						<>4__this.RemoveCurrentItem();
						<>4__this.SpawnCurrentItem();
						<>4__this.lastItemSpawnTime = Time.time;
					}
					<waitTime>5__1 = (PhotonNetwork.IsConnected ? 0.5f : 0.1f);
					<>2__current = (object)new WaitForSeconds(<waitTime>5__1);
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					<>2__current = ((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.AutoDestroyStone());
					<>1__state = 4;
					return true;
				case 4:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 5;
					return true;
				case 5:
					<>1__state = -1;
					if ((Object)(object)<>4__this.toolBeltCanvas != (Object)null)
					{
						<>4__this.toolBeltCanvas.SetActive(true);
					}
					<>4__this.toolBeltActive = true;
					<>4__this.currentItemIndex = 0;
					((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.ForceSelectorUpdate());
					<>4__this.isAutoProcessing = false;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <ForceSelectorUpdate>d__72 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public PEAKToolBeltPlugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ForceSelectorUpdate>d__72(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.UpdateUISelection();
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <GetSpawnedItemReference>d__78 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public PEAKToolBeltPlugin <>4__this;

			private Character <localCharacter>5__1;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GetSpawnedItemReference>d__78(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<localCharacter>5__1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					<localCharacter>5__1 = Character.localCharacter;
					Character obj = <localCharacter>5__1;
					object obj2;
					if (obj == null)
					{
						obj2 = null;
					}
					else
					{
						CharacterData data = obj.data;
						obj2 = ((data != null) ? data.currentItem : null);
					}
					if ((Object)obj2 != (Object)null)
					{
						<>4__this.currentHeldItem = <localCharacter>5__1.data.currentItem;
					}
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <HostSyncCoroutine>d__56 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public PEAKToolBeltPlugin <>4__this;

			private int <attempts>5__1;

			private int <maxAttempts>5__2;

			private Hashtable <roomProps>5__3;

			private string <hostConfig>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <HostSyncCoroutine>d__56(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<roomProps>5__3 = null;
				<hostConfig>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_012a: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<attempts>5__1 = 0;
					<maxAttempts>5__2 = 20;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<attempts>5__1 < <maxAttempts>5__2 && !PhotonNetwork.IsMasterClient && <>4__this.hasHostHandshake)
				{
					<attempts>5__1++;
					if (<>4__this.photonManager != null)
					{
						<roomProps>5__3 = ((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties;
						if (((Dictionary<object, object>)(object)<roomProps>5__3).ContainsKey((object)"toolBeltConfig"))
						{
							<hostConfig>5__4 = <roomProps>5__3[(object)"toolBeltConfig"] as string;
							if (!string.IsNullOrEmpty(<hostConfig>5__4))
							{
								<>4__this.UnpackConfigData(<hostConfig>5__4);
								if ((Object)(object)<>4__this.toolBeltCanvas != (Object)null && <>4__this.toolBeltActive)
								{
									((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.ForceSelectorUpdate());
								}
								goto IL_0167;
							}
							<hostConfig>5__4 = null;
						}
						<roomProps>5__3 = null;
					}
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				}
				goto IL_0167;
				IL_0167:
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <InitializeUI>d__90 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public PEAKToolBeltPlugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <InitializeUI>d__90(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					try
					{
						<>4__this.CreateToolBeltUI();
						<>4__this.uiInitialized = true;
					}
					catch (Exception)
					{
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <InitializeUIWithSelection>d__91 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public PEAKToolBeltPlugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <InitializeUIWithSelection>d__91(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Expected O, but got Unknown
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Expected O, but got Unknown
				//IL_0101: Unknown result type (might be due to invalid IL or missing references)
				//IL_010b: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					try
					{
						<>4__this.CreateToolBeltUI();
						<>4__this.uiInitialized = true;
					}
					catch (Exception)
					{
					}
					<>2__current = (object)new WaitForSeconds(0.1f);
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>4__this.UpdateUISelection();
					if (<>4__this.needsDummyItem && <>4__this.toolBeltItems.Count > 0 && <>4__this.toolBeltItems[0].itemId == 72)
					{
						<>4__this.currentItemIndex = 0;
						<>4__this.UpdateUISelection();
						<>2__current = (object)new WaitForSeconds(0.2f);
						<>1__state = 3;
						return true;
					}
					break;
				case 3:
					<>1__state = -1;
					<>4__this.needsDummyItem = false;
					break;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <InputDetectionCoroutine>d__59 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public PEAKToolBeltPlugin <>4__this;

			private bool <currentToggleKeyState>5__1;

			private bool <currentNextKeyState>5__2;

			private bool <currentPreviousKeyState>5__3;

			private bool <currentSelectKeyState>5__4;

			private bool <currentUpKeyState>5__5;

			private bool <currentDownKeyState>5__6;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <InputDetectionCoroutine>d__59(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c7: Expected O, but got Unknown
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0177: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0229: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				<currentToggleKeyState>5__1 = Input.GetKey(<>4__this.toggleToolBeltKey.Value);
				if (<currentToggleKeyState>5__1 && !<>4__this.lastToggleKeyState)
				{
					<>4__this.ToggleToolBelt();
				}
				<>4__this.lastToggleKeyState = <currentToggleKeyState>5__1;
				if (<>4__this.toolBeltActive && (Object)(object)<>4__this.toolBeltCanvas != (Object)null && <>4__this.toolBeltCanvas.activeInHierarchy)
				{
					<currentNextKeyState>5__2 = Input.GetKey(<>4__this.nextItemKey.Value);
					if (<currentNextKeyState>5__2 && !<>4__this.lastNextKeyState)
					{
						<>4__this.CycleToNextItem();
					}
					<>4__this.lastNextKeyState = <currentNextKeyState>5__2;
					<currentPreviousKeyState>5__3 = Input.GetKey(<>4__this.previousItemKey.Value);
					if (<currentPreviousKeyState>5__3 && !<>4__this.lastPreviousKeyState)
					{
						<>4__this.CycleToPreviousItem();
					}
					<>4__this.lastPreviousKeyState = <currentPreviousKeyState>5__3;
					<currentSelectKeyState>5__4 = Input.GetKey(<>4__this.selectItemKey.Value);
					if (<currentSelectKeyState>5__4 && !<>4__this.lastSelectKeyState)
					{
						<>4__this.SelectCurrentItem();
					}
					<>4__this.lastSelectKeyState = <currentSelectKeyState>5__4;
					<currentUpKeyState>5__5 = Input.GetKey(<>4__this.upItemKey.Value);
					if (<currentUpKeyState>5__5 && !<>4__this.lastUpKeyState)
					{
						<>4__this.CycleUpItem();
					}
					<>4__this.lastUpKeyState = <currentUpKeyState>5__5;
					<currentDownKeyState>5__6 = Input.GetKey(<>4__this.downItemKey.Value);
					if (<currentDownKeyState>5__6 && !<>4__this.lastDownKeyState)
					{
						<>4__this.CycleDownItem();
					}
					<>4__this.lastDownKeyState = <currentDownKeyState>5__6;
				}
				else
				{
					<>4__this.lastNextKeyState = false;
					<>4__this.lastPreviousKeyState = false;
					<>4__this.lastSelectKeyState = false;
					<>4__this.lastUpKeyState = false;
					<>4__this.lastDownKeyState = false;
				}
				<>2__current = (object)new WaitForSeconds(0.1f);
				<>1__state = 1;
				return true;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static PEAKToolBeltPlugin Instance;

		private Harmony harmony;

		private PhotonScopedManager photonManager;

		public bool IsHost = false;

		public bool allowToolBeltUsage = false;

		public bool hasHostHandshake = false;

		private string currentSceneName = "";

		private bool isInValidScene = false;

		private bool needsDummyItem = false;

		private const ushort DUMMY_ITEM_ID = 72;

		private const string DUMMY_ITEM_NAME = "Stone";

		private int toolBeltOpenCount = 0;

		private bool isAutoProcessing = false;

		private Coroutine hostSyncCoroutine;

		private ConfigEntry<KeyCode> toggleToolBeltKey;

		private ConfigEntry<KeyCode> nextItemKey;

		private ConfigEntry<KeyCode> previousItemKey;

		private ConfigEntry<KeyCode> selectItemKey;

		private ConfigEntry<KeyCode> upItemKey;

		private ConfigEntry<KeyCode> downItemKey;

		private ConfigEntry<string> customItems;

		public ConfigEntry<string> slotBackgroundColor;

		public ConfigEntry<string> slotBorderColor;

		public ConfigEntry<string> selectedSlotColor;

		public ConfigEntry<string> textColor;

		public ConfigEntry<bool> showSlotBackground;

		public ConfigEntry<bool> showSlotBorder;

		private bool toolBeltActive = false;

		private int currentItemIndex = 0;

		private Item currentHeldItem = null;

		private float lastItemSpawnTime = 0f;

		private float itemSpawnCooldown = 2f;

		private GameObject toolBeltCanvas;

		private List<ToolBeltSlotUI> toolBeltSlots = new List<ToolBeltSlotUI>();

		private bool uiInitialized = false;

		private List<(ushort itemId, string itemName, bool isOneTimeUse, bool isFromCustomConfig)> toolBeltItems;

		private Coroutine inputDetectionCoroutine = null;

		private bool lastToggleKeyState = false;

		private bool lastNextKeyState = false;

		private bool lastPreviousKeyState = false;

		private bool lastSelectKeyState = false;

		private bool lastUpKeyState = false;

		private bool lastDownKeyState = false;

		private void Awake()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Instance = this;
			harmony = new Harmony("tony4twentys.PEAK_Tool_Belt");
			InitializeToolBeltItems();
			toggleToolBeltKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "ToggleToolBelt", (KeyCode)116, "Key to toggle tool belt on/off");
			nextItemKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "NextItem", (KeyCode)93, "Key to cycle to next item");
			previousItemKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "PreviousItem", (KeyCode)91, "Key to cycle to previous item");
			selectItemKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "SelectItem", (KeyCode)13, "Key to select/spawn the currently highlighted item");
			upItemKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "UpItem", (KeyCode)61, "Key to cycle up in the UI (previous row)");
			downItemKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "DownItem", (KeyCode)45, "Key to cycle down in the UI (next row)");
			customItems = ((BaseUnityPlugin)this).Config.Bind<string>("General", "CustomItems", "[]", "Custom items in JSON format: [{\"itemID\": 123, \"isOneTimeUse\": true}]");
			slotBackgroundColor = ((BaseUnityPlugin)this).Config.Bind<string>("UI Colors", "SlotBackground", "#2D2D2DFF", "Background color for tool belt slots");
			slotBorderColor = ((BaseUnityPlugin)this).Config.Bind<string>("UI Colors", "SlotBorder", "#FFFFFF80", "Border color for tool belt slots");
			selectedSlotColor = ((BaseUnityPlugin)this).Config.Bind<string>("UI Colors", "SelectedSlot", "#00FF00FF", "Highlight color for selected slot");
			textColor = ((BaseUnityPlugin)this).Config.Bind<string>("UI Colors", "TextColor", "#FFFFFFFF", "Text color for item names");
			showSlotBackground = ((BaseUnityPlugin)this).Config.Bind<bool>("UI Display", "ShowSlotBackground", true, "Show slot background images");
			showSlotBorder = ((BaseUnityPlugin)this).Config.Bind<bool>("UI Display", "ShowSlotBorder", true, "Show slot border images");
			if (PhotonNetwork.IsMasterClient || !PhotonNetwork.IsConnected)
			{
				LoadCustomItems();
			}
			InitializePhotonManager();
			PhotonNetwork.AddCallbackTarget((object)this);
			SceneManager.sceneLoaded += OnSceneLoaded;
			SceneManager.activeSceneChanged += OnActiveSceneChanged;
			((MonoBehaviour)this).StartCoroutine(InitializeUI());
			StartInputDetection();
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			PhotonNetwork.RemoveCallbackTarget((object)this);
			SceneManager.sceneLoaded -= OnSceneLoaded;
			SceneManager.activeSceneChanged -= OnActiveSceneChanged;
			if (inputDetectionCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(inputDetectionCoroutine);
				inputDetectionCoroutine = null;
			}
			if (hostSyncCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(hostSyncCoroutine);
				hostSyncCoroutine = null;
			}
			if (toolBeltActive)
			{
				RemoveCurrentItem();
			}
			if ((Object)(object)toolBeltCanvas != (Object)null)
			{
				Object.Destroy((Object)(object)toolBeltCanvas);
			}
		}

		private void InitializeToolBeltItems()
		{
			toolBeltItems = new List<(ushort, string, bool, bool)>
			{
				(14, "Binoculars", false, false),
				(15, "Bugle", false, false),
				(23, "Compass", false, false),
				(69, "Conch", false, false),
				(32, "Flare", true, false),
				(99, "Frisbee", true, false),
				(34, "Guidebook", false, false),
				(42, "Lantern", true, false),
				(78, "Megaphone", false, false),
				(18, "Piton", true, false),
				(59, "Passport", false, false),
				(65, "Rope Spool", true, false),
				(30, "Seagull Flag", false, false),
				(71, "Sports Drink", true, false),
				(73, "Trail Mix", true, false),
				(48, "Turtle Flag", false, false)
			};
			toolBeltItems.Insert(0, (72, "Stone", true, false));
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			CheckSceneValidity(((Scene)(ref scene)).name);
		}

		private void OnActiveSceneChanged(Scene previousScene, Scene newActiveScene)
		{
			CheckSceneValidity(((Scene)(ref newActiveScene)).name);
		}

		private void CheckSceneValidity(string sceneName)
		{
			string text = currentSceneName;
			currentSceneName = sceneName;
			bool flag = isInValidScene;
			isInValidScene = sceneName == "Airport" || sceneName.StartsWith("Level_");
			if (isInValidScene && (!flag || text != sceneName))
			{
				RestockToolBelt();
				if (!PhotonNetwork.IsMasterClient && hasHostHandshake)
				{
					StartHostSync();
				}
			}
			allowToolBeltUsage = isInValidScene && hasHostHandshake;
		}

		private void RestockToolBelt()
		{
			toolBeltOpenCount = 0;
			isAutoProcessing = false;
			InitializeToolBeltItems();
			LoadCustomItems();
			currentItemIndex = 0;
			if ((Object)(object)toolBeltCanvas != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)toolBeltCanvas);
				toolBeltCanvas = null;
			}
			if (toolBeltSlots != null)
			{
				toolBeltSlots.Clear();
			}
			((MonoBehaviour)this).StartCoroutine(InitializeUI());
		}

		private void InitializePhotonManager()
		{
			if (PhotonCustomPropsUtilsPlugin.IsReady)
			{
				SetupPhotonManager();
			}
			else
			{
				PhotonCustomPropsUtilsPlugin.OnReady += SetupPhotonManager;
			}
		}

		private void SetupPhotonManager()
		{
			photonManager = PhotonCustomPropsUtilsPlugin.GetManager("tony4twentys.PEAK_Tool_Belt");
			photonManager.RegisterOnJoinedRoom((Action<Player>)delegate
			{
				CheckHostStatus();
			});
			photonManager.RegisterRoomProperty<string>("toolBeltConfig", (RoomEventType)2, (Action<string>)delegate(string configData)
			{
				if (!PhotonNetwork.IsMasterClient && !string.IsNullOrEmpty(configData))
				{
					UnpackConfigData(configData);
					hasHostHandshake = true;
					allowToolBeltUsage = isInValidScene && hasHostHandshake;
					StartHostSync();
				}
			});
		}

		private void CheckHostStatus()
		{
			if (PhotonNetwork.InRoom)
			{
				if (PhotonNetwork.IsMasterClient)
				{
					IsHost = true;
					hasHostHandshake = true;
					allowToolBeltUsage = isInValidScene && hasHostHandshake;
					LoadCustomItems();
					PublishHostConfig();
				}
				else
				{
					IsHost = false;
					hasHostHandshake = false;
					allowToolBeltUsage = false;
					StartHostSync();
				}
			}
		}

		private void PublishHostConfig()
		{
			if (PhotonNetwork.IsMasterClient && photonManager != null)
			{
				string text = PackConfigData();
				photonManager.SetRoomProperty("toolBeltConfig", (object)text);
			}
		}

		private string PackConfigData()
		{
			return customItems.Value;
		}

		private void UnpackConfigData(string configData)
		{
			try
			{
				string value = customItems.Value;
				customItems.Value = configData;
				InitializeToolBeltItems();
				LoadCustomItems();
				if ((Object)(object)toolBeltCanvas != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)toolBeltCanvas);
					toolBeltCanvas = null;
				}
				needsDummyItem = true;
				((MonoBehaviour)this).StartCoroutine(InitializeUIWithSelection());
				customItems.Value = value;
			}
			catch (Exception)
			{
			}
		}

		[IteratorStateMachine(typeof(<HostSyncCoroutine>d__56))]
		private IEnumerator HostSyncCoroutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <HostSyncCoroutine>d__56(0)
			{
				<>4__this = this
			};
		}

		private void StartHostSync()
		{
			if (hostSyncCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(hostSyncCoroutine);
			}
			if (!PhotonNetwork.IsMasterClient && hasHostHandshake)
			{
				hostSyncCoroutine = ((MonoBehaviour)this).StartCoroutine(HostSyncCoroutine());
			}
		}

		private void StartInputDetection()
		{
			if (inputDetectionCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(inputDetectionCoroutine);
			}
			inputDetectionCoroutine = ((MonoBehaviour)this).StartCoroutine(InputDetectionCoroutine());
		}

		[IteratorStateMachine(typeof(<InputDetectionCoroutine>d__59))]
		private IEnumerator InputDetectionCoroutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <InputDetectionCoroutine>d__59(0)
			{
				<>4__this = this
			};
		}

		private void ToggleToolBelt()
		{
			if (!uiInitialized || !allowToolBeltUsage)
			{
				return;
			}
			if (toolBeltActive)
			{
				if ((Object)(object)toolBeltCanvas != (Object)null)
				{
					toolBeltCanvas.SetActive(false);
				}
				toolBeltActive = false;
				isAutoProcessing = false;
				return;
			}
			if ((Object)(object)toolBeltCanvas != (Object)null)
			{
				toolBeltCanvas.SetActive(true);
			}
			toolBeltActive = true;
			currentItemIndex = 0;
			if (toolBeltOpenCount == 0)
			{
				toolBeltOpenCount = 1;
				if (!isAutoProcessing)
				{
					((MonoBehaviour)this).StartCoroutine(AutoProcessStoneSelection());
				}
				else
				{
					((MonoBehaviour)this).StartCoroutine(ForceSelectorUpdate());
				}
			}
			else
			{
				((MonoBehaviour)this).StartCoroutine(ForceSelectorUpdate());
			}
			lastItemSpawnTime = Time.time;
		}

		[IteratorStateMachine(typeof(<AutoProcessStoneSelection>d__61))]
		private IEnumerator AutoProcessStoneSelection()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <AutoProcessStoneSelection>d__61(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<AutoDestroyStone>d__62))]
		private IEnumerator AutoDestroyStone()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <AutoDestroyStone>d__62(0)
			{
				<>4__this = this
			};
		}

		private void CycleToNextItem()
		{
			if (toolBeltActive)
			{
				currentItemIndex = (currentItemIndex + 1) % toolBeltItems.Count;
				SelectItem(currentItemIndex);
				CheckAndRemoveDummyItem();
			}
		}

		private void CycleToPreviousItem()
		{
			if (toolBeltActive)
			{
				currentItemIndex = (currentItemIndex - 1 + toolBeltItems.Count) % toolBeltItems.Count;
				SelectItem(currentItemIndex);
				CheckAndRemoveDummyItem();
			}
		}

		private void CycleUpItem()
		{
			if (!toolBeltActive)
			{
				return;
			}
			int num = 5;
			int num2 = currentItemIndex - num;
			if (num2 < 0)
			{
				num2 = toolBeltItems.Count + num2;
				if (num2 < 0)
				{
					num2 = 0;
				}
			}
			currentItemIndex = num2;
			SelectItem(currentItemIndex);
			CheckAndRemoveDummyItem();
		}

		private void CycleDownItem()
		{
			if (toolBeltActive)
			{
				int num = 5;
				int num2 = currentItemIndex + num;
				if (num2 >= toolBeltItems.Count)
				{
					num2 %= toolBeltItems.Count;
				}
				currentItemIndex = num2;
				SelectItem(currentItemIndex);
				CheckAndRemoveDummyItem();
			}
		}

		private void CheckAndRemoveDummyItem()
		{
			if (needsDummyItem && currentItemIndex != 0)
			{
				needsDummyItem = false;
			}
		}

		private void SelectCurrentItem()
		{
			if (toolBeltActive && currentItemIndex >= 0 && currentItemIndex < toolBeltItems.Count && CanSpawnItem())
			{
				RemoveCurrentItem();
				SpawnCurrentItem();
				lastItemSpawnTime = Time.time;
			}
		}

		private void SelectItem(int index)
		{
			if (index >= 0 && index < toolBeltItems.Count)
			{
				currentItemIndex = index;
				UpdateUISelection();
			}
		}

		private void RemoveItemFromToolBelt(int index)
		{
			if (index >= 0 && index < toolBeltItems.Count)
			{
				toolBeltItems.RemoveAt(index);
				if (currentItemIndex >= toolBeltItems.Count)
				{
					currentItemIndex = Math.Max(0, toolBeltItems.Count - 1);
				}
				if (uiInitialized)
				{
					RecreateUI();
				}
			}
		}

		private void RecreateUI()
		{
			RemoveDuplicateItems();
			if ((Object)(object)toolBeltCanvas != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)toolBeltCanvas);
			}
			toolBeltSlots.Clear();
			uiInitialized = false;
			((MonoBehaviour)this).StartCoroutine(InitializeUI());
		}

		[IteratorStateMachine(typeof(<ForceSelectorUpdate>d__72))]
		private IEnumerator ForceSelectorUpdate()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ForceSelectorUpdate>d__72(0)
			{
				<>4__this = this
			};
		}

		private void UpdateUISelection()
		{
			if (!uiInitialized || toolBeltSlots == null)
			{
				return;
			}
			for (int i = 0; i < toolBeltSlots.Count; i++)
			{
				if ((Object)(object)toolBeltSlots[i] != (Object)null)
				{
					bool selected = i == currentItemIndex;
					toolBeltSlots[i].SetSelected(selected);
				}
			}
		}

		private bool CanSpawnItem()
		{
			return Time.time - lastItemSpawnTime >= itemSpawnCooldown;
		}

		private void SpawnCurrentItem()
		{
			if (currentItemIndex < toolBeltItems.Count)
			{
				(ushort, string, bool, bool) tuple = toolBeltItems[currentItemIndex];
				RemoveCurrentItem();
				SpawnItemForPlayer(tuple.Item1, tuple.Item2);
				if (tuple.Item3)
				{
					RemoveItemFromToolBelt(currentItemIndex);
				}
			}
		}

		private void RemoveCurrentItem()
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: 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_019a: Expected O, but got Unknown
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)((localCharacter != null) ? localCharacter.player : null) == (Object)null)
			{
				return;
			}
			Player player = localCharacter.player;
			bool flag = false;
			if ((Object)(object)localCharacter.refs?.items != (Object)null)
			{
				localCharacter.refs.items.photonView.RPC("DestroyHeldItemRpc", (RpcTarget)0, Array.Empty<object>());
				flag = true;
			}
			ItemSlot itemSlot = player.GetItemSlot((byte)250);
			if (itemSlot != null && !itemSlot.IsEmpty())
			{
				player.EmptySlot(Optionable<byte>.Some((byte)250));
				flag = true;
			}
			for (int i = 0; i < player.itemSlots.Length; i++)
			{
				ItemSlot val = player.itemSlots[i];
				if (!val.IsEmpty() && IsToolBeltItem(val.prefab))
				{
					player.EmptySlot(Optionable<byte>.Some((byte)i));
					flag = true;
				}
			}
			BackpackData val2 = default(BackpackData);
			if (player.backpackSlot != null && player.backpackSlot.hasBackpack && ((ItemSlot)player.backpackSlot).data != null && ((ItemSlot)player.backpackSlot).data.TryGetDataEntry<BackpackData>((DataEntryKey)7, ref val2) && val2 != null)
			{
				for (int j = 0; j < val2.itemSlots.Length; j++)
				{
					ItemSlot val3 = val2.itemSlots[j];
					if (!val3.IsEmpty() && IsToolBeltItem(val3.prefab))
					{
						val2.itemSlots[j] = new ItemSlot((byte)j);
						flag = true;
					}
				}
			}
			if (flag)
			{
				InventorySyncData val4 = default(InventorySyncData);
				((InventorySyncData)(ref val4))..ctor(player.itemSlots, player.backpackSlot, player.tempFullSlot);
				((MonoBehaviourPun)player).photonView.RPC("SyncInventoryRPC", (RpcTarget)1, new object[2]
				{
					IBinarySerializable.ToManagedArray<InventorySyncData>(val4),
					false
				});
			}
			currentHeldItem = null;
		}

		private void SpawnItemForPlayer(ushort itemId, string itemPrefabName)
		{
			try
			{
				Character localCharacter = Character.localCharacter;
				if (!((Object)(object)localCharacter == (Object)null))
				{
					string prefabNameFromItemId = GetPrefabNameFromItemId(itemId);
					if (!string.IsNullOrEmpty(prefabNameFromItemId))
					{
						localCharacter.refs.items.SpawnItemInHand(prefabNameFromItemId);
						((MonoBehaviour)this).StartCoroutine(GetSpawnedItemReference());
					}
				}
			}
			catch (Exception)
			{
			}
		}

		[IteratorStateMachine(typeof(<GetSpawnedItemReference>d__78))]
		private IEnumerator GetSpawnedItemReference()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GetSpawnedItemReference>d__78(0)
			{
				<>4__this = this
			};
		}

		private bool IsToolBeltItem(Item prefab)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				return false;
			}
			foreach (var toolBeltItem in toolBeltItems)
			{
				if (prefab.itemID == toolBeltItem.itemId)
				{
					return true;
				}
			}
			return false;
		}

		private string GetPrefabNameFromItemId(ushort itemId)
		{
			try
			{
				Item val = default(Item);
				if (ItemDatabase.TryGetItem(itemId, ref val))
				{
					return ((Object)val).name;
				}
				List<Item> objects = ((DatabaseAsset<ItemDatabase, Item>)(object)SingletonAsset<ItemDatabase>.Instance).Objects;
				foreach (Item item in objects)
				{
					if (item.itemID == itemId)
					{
						return ((Object)item).name;
					}
				}
				return null;
			}
			catch (Exception)
			{
				return null;
			}
		}

		private void LoadCustomItems()
		{
			try
			{
				string value = customItems.Value;
				if (string.IsNullOrEmpty(value) || value == "[]")
				{
					return;
				}
				List<CustomItemConfig> list = ParseCustomItemsJson(value);
				if (list == null || list.Count == 0)
				{
					return;
				}
				toolBeltItems.RemoveAll(((ushort itemId, string itemName, bool isOneTimeUse, bool isFromCustomConfig) item) => item.isFromCustomConfig);
				int num = 0;
				foreach (CustomItemConfig item in list)
				{
					if (item.itemID > 0)
					{
						string text = GetItemNameFromID(item.itemID);
						if (string.IsNullOrEmpty(text))
						{
							text = $"Item_{item.itemID}";
						}
						toolBeltItems.Add((item.itemID, text, item.isOneTimeUse, true));
						num++;
					}
				}
				if (num > 0)
				{
					SortItemsPreservingStone();
				}
			}
			catch (Exception)
			{
			}
		}

		private List<CustomItemConfig> ParseCustomItemsJson(string jsonContent)
		{
			try
			{
				List<CustomItemConfig> list = new List<CustomItemConfig>();
				string jsonArray = jsonContent.Trim().TrimStart(new char[1] { '[' }).TrimEnd(new char[1] { ']' });
				List<string> list2 = SplitJsonObjects(jsonArray);
				foreach (string item in list2)
				{
					CustomItemConfig customItemConfig = new CustomItemConfig();
					Match match = Regex.Match(item, "\"itemID\"\\s*:\\s*(\\d+)");
					if (match.Success && ushort.TryParse(match.Groups[1].Value, out var result))
					{
						customItemConfig.itemID = result;
					}
					Match match2 = Regex.Match(item, "\"isOneTimeUse\"\\s*:\\s*(true|false)");
					if (match2.Success && bool.TryParse(match2.Groups[1].Value, out var result2))
					{
						customItemConfig.isOneTimeUse = result2;
					}
					if (customItemConfig.itemID > 0)
					{
						list.Add(customItemConfig);
					}
				}
				return list;
			}
			catch (Exception)
			{
				return new List<CustomItemConfig>();
			}
		}

		private List<string> SplitJsonObjects(string jsonArray)
		{
			List<string> list = new List<string>();
			string text = "";
			int num = 0;
			bool flag = false;
			bool flag2 = false;
			for (int i = 0; i < jsonArray.Length; i++)
			{
				char c = jsonArray[i];
				if (flag2)
				{
					text += c;
					flag2 = false;
					continue;
				}
				switch (c)
				{
				case '\\':
					flag2 = true;
					text += c;
					continue;
				case '"':
					flag = !flag;
					break;
				}
				if (!flag)
				{
					switch (c)
					{
					case '{':
						num++;
						break;
					case '}':
						num--;
						if (num == 0)
						{
							list.Add(text.Trim());
							text = "";
							continue;
						}
						break;
					case ',':
						if (num == 0)
						{
							continue;
						}
						break;
					}
				}
				text += c;
			}
			return list;
		}

		private Sprite LoadCustomBorderSprite()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_005e: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				string path = Path.Combine(directoryName, "Boarder.png");
				if (File.Exists(path))
				{
					byte[] array = File.ReadAllBytes(path);
					Texture2D val = new Texture2D(2, 2);
					ImageConversion.LoadImage(val, array);
					return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(8f, 8f, 8f, 8f));
				}
			}
			catch (Exception)
			{
			}
			return null;
		}

		private Sprite LoadCustomSlotBackgroundSprite()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_005e: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				string path = Path.Combine(directoryName, "Slot Background.png");
				if (File.Exists(path))
				{
					byte[] array = File.ReadAllBytes(path);
					Texture2D val = new Texture2D(2, 2);
					ImageConversion.LoadImage(val, array);
					return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(8f, 8f, 8f, 8f));
				}
			}
			catch (Exception)
			{
			}
			return null;
		}

		public Color ParseHexColor(string hexColor)
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			try
			{
				if (string.IsNullOrEmpty(hexColor))
				{
					return Color.white;
				}
				if (hexColor.StartsWith("#"))
				{
					hexColor = hexColor.Substring(1);
				}
				if (hexColor.Length == 6)
				{
					hexColor += "FF";
				}
				if (hexColor.Length != 8)
				{
					return Color.white;
				}
				int num = Convert.ToInt32(hexColor.Substring(0, 2), 16);
				int num2 = Convert.ToInt32(hexColor.Substring(2, 2), 16);
				int num3 = Convert.ToInt32(hexColor.Substring(4, 2), 16);
				int num4 = Convert.ToInt32(hexColor.Substring(6, 2), 16);
				return new Color((float)num / 255f, (float)num2 / 255f, (float)num3 / 255f, (float)num4 / 255f);
			}
			catch
			{
				return Color.white;
			}
		}

		private string GetItemNameFromID(ushort itemID)
		{
			try
			{
				Item val = default(Item);
				if (ItemDatabase.TryGetItem(itemID, ref val))
				{
					return ((Object)val).name;
				}
			}
			catch
			{
			}
			return null;
		}

		private void RemoveDuplicateItems()
		{
			if (toolBeltItems == null || toolBeltItems.Count <= 1)
			{
				return;
			}
			int count = toolBeltItems.Count;
			List<(ushort, string, bool, bool)> list = new List<(ushort, string, bool, bool)>();
			HashSet<ushort> hashSet = new HashSet<ushort>();
			if (toolBeltItems.Count > 0 && toolBeltItems[0].itemId == 72)
			{
				list.Add(toolBeltItems[0]);
			}
			foreach (var toolBeltItem in toolBeltItems)
			{
				if (toolBeltItem.itemId != 72)
				{
					if (toolBeltItem.isFromCustomConfig)
					{
						list.Add(toolBeltItem);
					}
					else if (!hashSet.Contains(toolBeltItem.itemId))
					{
						list.Add(toolBeltItem);
						hashSet.Add(toolBeltItem.itemId);
					}
				}
			}
			toolBeltItems = list;
		}

		[IteratorStateMachine(typeof(<InitializeUI>d__90))]
		private IEnumerator InitializeUI()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <InitializeUI>d__90(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<InitializeUIWithSelection>d__91))]
		private IEnumerator InitializeUIWithSelection()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <InitializeUIWithSelection>d__91(0)
			{
				<>4__this = this
			};
		}

		private void RemoveDummyItem()
		{
			if (needsDummyItem)
			{
				needsDummyItem = false;
				currentItemIndex = 0;
				UpdateUISelection();
			}
		}

		private void SortItemsPreservingStone()
		{
			if (toolBeltItems.Count > 1)
			{
				(ushort, string, bool, bool) item = ((toolBeltItems.Count > 0 && toolBeltItems[0].itemId == 72) ? toolBeltItems[0] : default((ushort, string, bool, bool)));
				bool flag = item.Item1 == 72;
				if (flag)
				{
					toolBeltItems.RemoveAt(0);
				}
				toolBeltItems.Sort(((ushort itemId, string itemName, bool isOneTimeUse, bool isFromCustomConfig) a, (ushort itemId, string itemName, bool isOneTimeUse, bool isFromCustomConfig) b) => a.itemName.CompareTo(b.itemName));
				if (flag)
				{
					toolBeltItems.Insert(0, item);
				}
			}
		}

		private void CreateToolBeltUI()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			RemoveDuplicateItems();
			float num = Screen.width;
			float num2 = Screen.height;
			toolBeltCanvas = new GameObject("ToolBeltCanvas");
			Canvas val = toolBeltCanvas.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.sortingOrder = 1000;
			CanvasScaler val2 = toolBeltCanvas.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)1;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			val2.screenMatchMode = (ScreenMatchMode)0;
			val2.matchWidthOrHeight = 0.5f;
			toolBeltCanvas.AddComponent<GraphicRaycaster>();
			Object.DontDestroyOnLoad((Object)(object)toolBeltCanvas);
			int num3 = 5;
			int num4 = Mathf.CeilToInt((float)toolBeltItems.Count / (float)num3);
			float num5 = 60f;
			float num6 = Mathf.Min(num / 1920f, num2 / 1080f);
			float num7 = num5 * num6;
			float num8 = 8f * num6;
			float totalWidth = (float)num3 * num7 + (float)(num3 - 1) * num8;
			float totalHeight = (float)num4 * num7 + (float)(num4 - 1) * num8;
			for (int i = 0; i < toolBeltItems.Count; i++)
			{
				int row = i / num3;
				int col = i % num3;
				CreateToolBeltSlot(i, toolBeltCanvas.transform, row, col, num7, num8, totalWidth, totalHeight, num4);
			}
			toolBeltCanvas.SetActive(false);
		}

		private void CreateToolBeltSlot(int index, Transform parent, int row, int col, float slotSize, float spacing, float totalWidth, float totalHeight, int totalRows)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_005a: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_0147: 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_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Expected O, but got Unknown
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Expected O, but got Unknown
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Expected O, but got Unknown
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			float num = Screen.width;
			float num2 = Screen.height;
			float num3 = Mathf.Min(num / 1920f, num2 / 1080f);
			GameObject val = new GameObject($"ToolBeltSlot_{index}");
			val.transform.SetParent(parent);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.anchorMin = new Vector2(0.5f, 0f);
			val2.anchorMax = new Vector2(0.5f, 0f);
			float num4 = (0f - totalWidth) / 2f + slotSize / 2f;
			float num5 = 30f * num3 + slotSize / 2f;
			float num6 = num4 + (float)col * (slotSize + spacing);
			float num7 = num5 + (float)(totalRows - 1 - row) * (slotSize + spacing);
			val2.anchoredPosition = new Vector2(num6, num7);
			val2.sizeDelta = new Vector2(slotSize, slotSize);
			ToolBeltSlotUI toolBeltSlotUI = val.AddComponent<ToolBeltSlotUI>();
			toolBeltSlotUI.slotIndex = index;
			if (showSlotBackground.Value)
			{
				GameObject val3 = new GameObject("InnerBackground");
				val3.transform.SetParent(val.transform, false);
				toolBeltSlotUI.innerBackground = val3.AddComponent<Image>();
				RectTransform component = ((Component)toolBeltSlotUI.innerBackground).GetComponent<RectTransform>();
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				((Graphic)toolBeltSlotUI.innerBackground).color = ParseHexColor(slotBackgroundColor.Value);
				((Graphic)toolBeltSlotUI.innerBackground).raycastTarget = false;
				Sprite val4 = LoadCustomSlotBackgroundSprite();
				if ((Object)(object)val4 != (Object)null)
				{
					toolBeltSlotUI.innerBackground.sprite = val4;
					toolBeltSlotUI.innerBackground.type = (Type)1;
				}
			}
			if (showSlotBorder.Value)
			{
				GameObject val5 = new GameObject("Border");
				val5.transform.SetParent(val.transform, false);
				toolBeltSlotUI.borderImage = val5.AddComponent<Image>();
				RectTransform component2 = ((Component)toolBeltSlotUI.borderImage).GetComponent<RectTransform>();
				component2.anchorMin = Vector2.zero;
				component2.anchorMax = Vector2.one;
				component2.offsetMin = Vector2.zero;
				component2.offsetMax = Vector2.zero;
				((Graphic)toolBeltSlotUI.borderImage).color = ParseHexColor(slotBorderColor.Value);
				((Graphic)toolBeltSlotUI.borderImage).raycastTarget = false;
				Sprite val6 = LoadCustomBorderSprite();
				if ((Object)(object)val6 != (Object)null)
				{
					toolBeltSlotUI.borderImage.sprite = val6;
					toolBeltSlotUI.borderImage.type = (Type)1;
				}
				else
				{
					Outline val7 = val.AddComponent<Outline>();
					((Shadow)val7).effectColor = ParseHexColor(slotBorderColor.Value);
					((Shadow)val7).effectDistance = new Vector2(2f, 2f);
				}
			}
			GameObject val8 = new GameObject("Icon");
			val8.transform.SetParent(val.transform);
			RectTransform val9 = val8.AddComponent<RectTransform>();
			val9.anchorMin = new Vector2(0.1f, 0.25f);
			val9.anchorMax = new Vector2(0.9f, 0.75f);
			val9.anchoredPosition = Vector2.zero;
			val9.sizeDelta = Vector2.zero;
			toolBeltSlotUI.icon = val8.AddComponent<RawImage>();
			GameObject val10 = new GameObject("Name");
			val10.transform.SetParent(val.transform);
			RectTransform val11 = val10.AddComponent<RectTransform>();
			val11.anchorMin = new Vector2(0f, 0f);
			val11.anchorMax = new Vector2(1f, 0.25f);
			val11.anchoredPosition = Vector2.zero;
			val11.sizeDelta = Vector2.zero;
			toolBeltSlotUI.nameText = val10.AddComponent<TextMeshProUGUI>();
			((TMP_Text)toolBeltSlotUI.nameText).fontSize = Mathf.RoundToInt(8f * num3);
			((Graphic)toolBeltSlotUI.nameText).color = ParseHexColor(textColor.Value);
			((TMP_Text)toolBeltSlotUI.nameText).alignment = (TextAlignmentOptions)514;
			GameObject val12 = new GameObject("Cooldown");
			val12.transform.SetParent(val.transform);
			RectTransform val13 = val12.AddComponent<RectTransform>();
			val13.anchorMin = Vector2.zero;
			val13.anchorMax = Vector2.one;
			val13.anchoredPosition = Vector2.zero;
			val13.sizeDelta = Vector2.zero;
			toolBeltSlotUI.cooldownOverlay = val12.AddComponent<Image>();
			((Graphic)toolBeltSlotUI.cooldownOverlay).color = new Color(0f, 0f, 0f, 0.6f);
			toolBeltSlotUI.cooldownOverlay.fillMethod = (FillMethod)1;
			toolBeltSlotUI.cooldownOverlay.type = (Type)3;
			((Component)toolBeltSlotUI.cooldownOverlay).gameObject.SetActive(false);
			(ushort, string, bool, bool) tuple = toolBeltItems[index];
			toolBeltSlotUI.SetItem(tuple.Item1, tuple.Item2, tuple.Item3);
			toolBeltSlots.Add(toolBeltSlotUI);
		}

		public void OnJoinedRoom()
		{
			CheckHostStatus();
		}

		public void OnLeftRoom()
		{
			IsHost = false;
			hasHostHandshake = false;
			allowToolBeltUsage = false;
		}

		public void OnMasterClientSwitched(Player _)
		{
			CheckHostStatus();
		}

		public void OnPlayerEnteredRoom(Player _)
		{
			if (PhotonNetwork.IsMasterClient && photonManager != null)
			{
				PublishHostConfig();
			}
		}

		public void OnPlayerLeftRoom(Player _)
		{
		}

		public void OnRoomPropertiesUpdate(Hashtable _)
		{
		}

		public void OnPlayerPropertiesUpdate(Player _, Hashtable _1)
		{
		}

		public void OnConnected()
		{
		}

		public void OnConnectedToMaster()
		{
		}

		public void OnDisconnected(DisconnectCause _)
		{
		}

		public void OnRegionListReceived(RegionHandler _)
		{
		}

		public void OnCustomAuthenticationResponse(Dictionary<string, object> _)
		{
		}

		public void OnCustomAuthenticationFailed(string _)
		{
		}

		public void OnFriendListUpdate(List<FriendInfo> _)
		{
		}

		public void OnCreatedRoom()
		{
		}

		public void OnCreateRoomFailed(short _, string _1)
		{
		}

		public void OnJoinRoomFailed(short _, string _1)
		{
		}

		public void OnJoinRandomFailed(short _, string _1)
		{
		}

		public void OnEvent(EventData photonEvent)
		{
		}
	}
}