Decompiled source of moreslots v1.0.3

moreslots.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Utilities;

[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("moreslots")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f5118a43cf9f4ece6303cba9334d232d7e26cadc")]
[assembly: AssemblyProduct("moreslots")]
[assembly: AssemblyTitle("moreslots")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MoreSlots
{
	[BepInPlugin("chiharul.moreslots", "moreslots", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "chiharul.moreslots";

		public const string Name = "moreslots";

		public const string Version = "1.0.3";

		public const int VanillaSlots = 3;

		public const int MaxSlots = 10;

		internal static ManualLogSource Log;

		internal static ConfigEntry<int> SlotCount;

		internal static ConfigEntry<Key> MenuKey;

		internal static ConfigEntry<string>[] Binds = new ConfigEntry<string>[10];

		internal static int ActiveSlotCount = 3;

		private static readonly MethodInfo TagForPath = AccessTools.Method(typeof(InputGlyphs), "TagForPath", (Type[])null, (Type[])null);

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			SlotCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Slots", 5, new ConfigDescription("How many hotbar slots you get. Applies when the next level loads.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(3, 10), Array.Empty<object>()));
			MenuKey = ((BaseUnityPlugin)this).Config.Bind<Key>("General", "Menu Key", (Key)101, "Key that opens the moreslots menu (slot count and keybinds).");
			for (int i = 0; i < 10; i++)
			{
				string text = ((i < 4) ? ("<Keyboard>/" + (i + 1)) : "");
				Binds[i] = ((BaseUnityPlugin)this).Config.Bind<string>("Keybinds", "Slot " + (i + 1), text, "Input path like <Keyboard>/4 or <Mouse>/forwardButton. Empty = unassigned. Easier to set from the in-game menu.");
			}
			GameObject val = new GameObject("moreslots.Runner")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<HotbarRunner>();
			new Harmony("chiharul.moreslots").PatchAll(typeof(Patches));
			InputGlyphs.OnGlyphsChanged += Patches.RefreshLabels;
			Log.LogInfo((object)"moreslots 1.0.3 loaded.");
		}

		internal static string DefaultBind(int i)
		{
			return (string)((ConfigEntryBase)Binds[i]).DefaultValue;
		}

		internal static string DisplayName(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				return "Unassigned";
			}
			switch (path)
			{
			case "<Mouse>/middleButton":
				return "Middle Mouse";
			case "<Mouse>/forwardButton":
				return "Mouse 5";
			case "<Mouse>/backButton":
				return "Mouse 4";
			default:
				try
				{
					return InputControlPath.ToHumanReadableString(path, (HumanReadableStringOptions)2, (InputControl)null);
				}
				catch
				{
					return path;
				}
			}
		}

		internal static string HudLabel(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				return "-";
			}
			if (TagForPath != null)
			{
				try
				{
					string text = (string)TagForPath.Invoke(null, new object[4]
					{
						path,
						(object)(InputDeviceType)0,
						(object)(InputKey)19,
						true
					});
					if (!string.IsNullOrEmpty(text))
					{
						return text;
					}
				}
				catch (Exception ex)
				{
					Log.LogDebug((object)("TagForPath: " + ex.Message));
				}
			}
			return ShortName(path);
		}

		internal static string ShortName(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				return "-";
			}
			return path switch
			{
				"<Mouse>/middleButton" => "MMB", 
				"<Mouse>/forwardButton" => "M5", 
				"<Mouse>/backButton" => "M4", 
				_ => DisplayName(path).ToUpperInvariant(), 
			};
		}
	}
	internal class HotbarRunner : MonoBehaviour
	{
		private static readonly Action<InventorySpot> HandleInput = AccessTools.MethodDelegate<Action<InventorySpot>>(AccessTools.Method(typeof(InventorySpot), "HandleInput", (Type[])null, (Type[])null), (object)null, true);

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

		private static readonly FieldRef<MenuManager, MenuPage> CurrentMenuPage = AccessTools.FieldRefAccess<MenuManager, MenuPage>("currentMenuPage");

		private static readonly FieldRef<InputManager, float> DisableMovementTimer = AccessTools.FieldRefAccess<InputManager, float>("disableMovementTimer");

		private static readonly List<InputKey> NoKeys = new List<InputKey>();

		private readonly Dictionary<string, InputControl> controlCache = new Dictionary<string, InputControl>();

		private bool open;

		private int capturing = -1;

		private int captureStartFrame;

		private Rect windowRect = new Rect(60f, 60f, 380f, 0f);

		private GUIStyle titleStyle;

		private InventoryUI seenUI;

		private float uiSeenTime;

		private int uiRefreshStep;

		private void Update()
		{
			//IL_0026: 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)
			RefreshNewHud();
			Keyboard current = Keyboard.current;
			if (capturing >= 0)
			{
				Capture(current);
			}
			else if (current != null && (int)Plugin.MenuKey.Value != 0 && ((ButtonControl)current[Plugin.MenuKey.Value]).wasPressedThisFrame && !ChatOpen())
			{
				SetOpen(!open);
			}
			else if (open && current != null && ((ButtonControl)current.escapeKey).wasPressedThisFrame)
			{
				SetOpen(value: false);
			}
			if (open)
			{
				BlockGameInput();
			}
			else
			{
				PollBinds();
			}
		}

		private void RefreshNewHud()
		{
			InventoryUI instance = InventoryUI.instance;
			if ((Object)(object)instance != (Object)(object)seenUI)
			{
				seenUI = instance;
				uiSeenTime = Time.unscaledTime;
				uiRefreshStep = 0;
			}
			if (!((Object)(object)instance == (Object)null))
			{
				float num = Time.unscaledTime - uiSeenTime;
				if (uiRefreshStep == 0 && num > 0.5f)
				{
					uiRefreshStep = 1;
					Patches.RefreshLabels();
				}
				else if (uiRefreshStep == 1 && num > 3f)
				{
					uiRefreshStep = 2;
					Patches.RefreshLabels(logDetails: true);
				}
			}
		}

		private void SetOpen(bool value)
		{
			open = value;
			capturing = -1;
			if (!open)
			{
				Cursor.visible = false;
			}
		}

		private static bool ChatOpen()
		{
			ChatManager instance = ChatManager.instance;
			if ((Object)(object)instance != (Object)null)
			{
				return ChatActive.Invoke(instance);
			}
			return false;
		}

		private static void BlockGameInput()
		{
			try
			{
				if ((Object)(object)InputManager.instance != (Object)null)
				{
					InputManager.instance.DisableMovement(0.1f);
					InputManager.instance.DisableAiming(0.1f);
					InputManager.instance.DisableControlsExcept(0.1f, NoKeys);
				}
				if ((Object)(object)CursorManager.instance != (Object)null)
				{
					CursorManager.instance.Unlock(0.1f);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("BlockGameInput: " + ex.Message));
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}

		private void PollBinds()
		{
			Inventory instance = Inventory.instance;
			if ((Object)(object)instance == (Object)null || !((Behaviour)instance).isActiveAndEnabled || ChatOpen() || ((Object)(object)MenuManager.instance != (Object)null && (Object)(object)CurrentMenuPage.Invoke(MenuManager.instance) != (Object)null) || ((Object)(object)InputManager.instance != (Object)null && DisableMovementTimer.Invoke(InputManager.instance) > 0f))
			{
				return;
			}
			List<InventorySpot> allSpots = instance.GetAllSpots();
			int num = Mathf.Min(Plugin.ActiveSlotCount, allSpots.Count);
			for (int i = 0; i < num; i++)
			{
				if (!Pressed(Plugin.Binds[i].Value))
				{
					continue;
				}
				InventorySpot val = allSpots[i];
				if (!((Object)(object)val == (Object)null))
				{
					try
					{
						HandleInput(val);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)$"Slot {i + 1}: {ex.Message}");
					}
				}
			}
		}

		private bool Pressed(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				return false;
			}
			if (!controlCache.TryGetValue(path, out var value) || value == null || !value.device.added)
			{
				value = InputSystem.FindControl(path);
				controlCache[path] = value;
			}
			ButtonControl val = (ButtonControl)(object)((value is ButtonControl) ? value : null);
			if (val != null)
			{
				return val.wasPressedThisFrame;
			}
			return false;
		}

		private void StartCapture(int slot)
		{
			capturing = slot;
			captureStartFrame = Time.frameCount;
		}

		private void Capture(Keyboard kb)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (Time.frameCount <= captureStartFrame)
			{
				return;
			}
			if (kb != null)
			{
				if (((ButtonControl)kb.escapeKey).wasPressedThisFrame)
				{
					SetBind(capturing, "");
					return;
				}
				Enumerator<KeyControl> enumerator = kb.allKeys.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						KeyControl current = enumerator.Current;
						if (current != null && ((ButtonControl)current).wasPressedThisFrame)
						{
							SetBind(capturing, "<Keyboard>/" + ((InputControl)current).name);
							return;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
				}
			}
			Mouse current2 = Mouse.current;
			if (current2 != null)
			{
				if (current2.middleButton.wasPressedThisFrame)
				{
					SetBind(capturing, "<Mouse>/middleButton");
				}
				else if (current2.forwardButton.wasPressedThisFrame)
				{
					SetBind(capturing, "<Mouse>/forwardButton");
				}
				else if (current2.backButton.wasPressedThisFrame)
				{
					SetBind(capturing, "<Mouse>/backButton");
				}
			}
		}

		private void SetBind(int slot, string path)
		{
			if (!string.IsNullOrEmpty(path))
			{
				for (int i = 0; i < 10; i++)
				{
					if (i != slot && Plugin.Binds[i].Value == path)
					{
						Plugin.Binds[i].Value = "";
					}
				}
			}
			Plugin.Binds[slot].Value = path;
			capturing = -1;
			Patches.RefreshLabels();
		}

		private void OnGUI()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_007f: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			if (open)
			{
				float num = Mathf.Max(1f, (float)Screen.height / 1080f);
				GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
				if (titleStyle == null)
				{
					titleStyle = new GUIStyle(GUI.skin.label)
					{
						fontStyle = (FontStyle)1
					};
				}
				windowRect = GUILayout.Window(1213221971, windowRect, new WindowFunction(DrawWindow), "moreslots", Array.Empty<GUILayoutOption>());
			}
		}

		private void DrawWindow(int id)
		{
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Space(4f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Slots", titleStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
			if (GUILayout.Button("-", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
			{
				Plugin.SlotCount.Value = Mathf.Max(3, Plugin.SlotCount.Value - 1);
			}
			GUILayout.Label(Plugin.SlotCount.Value.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) });
			if (GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
			{
				Plugin.SlotCount.Value = Mathf.Min(10, Plugin.SlotCount.Value + 1);
			}
			GUILayout.EndHorizontal();
			if (Plugin.SlotCount.Value != Plugin.ActiveSlotCount && (Object)(object)Inventory.instance != (Object)null)
			{
				GUILayout.Label("New slot count applies when the next level loads.", Array.Empty<GUILayoutOption>());
			}
			GUILayout.Space(8f);
			GUILayout.Label("Keybinds  (click, then press a key. Esc = unassign)", titleStyle, Array.Empty<GUILayoutOption>());
			for (int i = 0; i < Plugin.SlotCount.Value; i++)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label("Slot " + (i + 1), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
				if (GUILayout.Button((capturing == i) ? "Press a key..." : Plugin.DisplayName(Plugin.Binds[i].Value), Array.Empty<GUILayoutOption>()))
				{
					StartCapture(i);
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.Space(8f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Reset keybinds", Array.Empty<GUILayoutOption>()))
			{
				for (int j = 0; j < 10; j++)
				{
					Plugin.Binds[j].Value = Plugin.DefaultBind(j);
				}
				capturing = -1;
				Patches.RefreshLabels();
			}
			if (GUILayout.Button("Close", Array.Empty<GUILayoutOption>()))
			{
				SetOpen(value: false);
			}
			GUILayout.EndHorizontal();
			GUILayout.Label($"Press {Plugin.MenuKey.Value} to open or close this menu.", Array.Empty<GUILayoutOption>());
			GUI.DragWindow();
		}
	}
	[HarmonyPatch]
	internal static class Patches
	{
		private static bool inSpotUpdate;

		private static readonly HashSet<int> keyLabels = new HashSet<int>();

		private static readonly Dictionary<int, KeyValuePair<int, float>> pendingEquips = new Dictionary<int, KeyValuePair<int, float>>();

		[HarmonyPrefix]
		[HarmonyPatch(typeof(InventoryUI), "Awake")]
		private static void InventoryUIAwakePrefix(InventoryUI __instance)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Clamp(Plugin.SlotCount.Value, 3, 10);
			InventorySpot[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<InventorySpot>(true);
			Array.Sort(componentsInChildren, (InventorySpot a, InventorySpot b) => a.inventorySpotIndex.CompareTo(b.inventorySpotIndex));
			Plugin.ActiveSlotCount = Mathf.Max(num, componentsInChildren.Length);
			if (componentsInChildren.Length == 0 || componentsInChildren.Length >= num)
			{
				return;
			}
			InventorySpot val = componentsInChildren[^1];
			float num2 = ((componentsInChildren.Length > 1) ? (((Component)val).transform.localPosition.x - ((Component)componentsInChildren[^2]).transform.localPosition.x) : 50f);
			if (Mathf.Abs(num2) < 1f)
			{
				num2 = 50f;
			}
			bool activeSelf = ((Component)val).gameObject.activeSelf;
			((Component)val).gameObject.SetActive(false);
			try
			{
				for (int num3 = componentsInChildren.Length; num3 < num; num3++)
				{
					GameObject obj = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent);
					((Object)obj).name = "Inventory Spot " + (num3 + 1) + " (moreslots)";
					PhotonView component = obj.GetComponent<PhotonView>();
					if ((Object)(object)component != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)component);
					}
					obj.GetComponent<InventorySpot>().inventorySpotIndex = num3;
					Vector3 localPosition = ((Component)val).transform.localPosition;
					localPosition.x += num2 * (float)(num3 - val.inventorySpotIndex);
					obj.transform.localPosition = localPosition;
					obj.SetActive(activeSelf);
				}
			}
			finally
			{
				((Component)val).gameObject.SetActive(activeSelf);
			}
			Inventory instance = Inventory.instance;
			if ((Object)(object)instance != (Object)null)
			{
				List<InventorySpot> allSpots = instance.GetAllSpots();
				if (allSpots.Count > Plugin.ActiveSlotCount)
				{
					allSpots.RemoveRange(Plugin.ActiveSlotCount, allSpots.Count - Plugin.ActiveSlotCount);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(InventoryUI), "Awake")]
		private static void InventoryUIAwakePostfix()
		{
			RefreshLabels();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Inventory), "InventorySpotAddAtIndex")]
		private static void InventorySpotAddAtIndexPrefix(Inventory __instance, int index)
		{
			List<InventorySpot> allSpots = __instance.GetAllSpots();
			while (allSpots.Count <= index)
			{
				allSpots.Add(null);
			}
		}

		internal static void RefreshLabels()
		{
			RefreshLabels(logDetails: false);
		}

		internal static void RefreshLabels(bool logDetails)
		{
			InventoryUI instance = InventoryUI.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			InventorySpot[] componentsInChildren = ((Component)instance).GetComponentsInChildren<InventorySpot>(true);
			foreach (InventorySpot val in componentsInChildren)
			{
				int inventorySpotIndex = val.inventorySpotIndex;
				if (inventorySpotIndex < 0 || inventorySpotIndex >= 10)
				{
					continue;
				}
				string text = Plugin.HudLabel(Plugin.Binds[inventorySpotIndex].Value);
				int num = 0;
				InputGlyphText[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<InputGlyphText>(true);
				foreach (InputGlyphText val2 in componentsInChildren2)
				{
					int instanceID = ((Object)val2).GetInstanceID();
					if (keyLabels.Contains(instanceID) || (val2.template != null && val2.template.IndexOf("[inventory", StringComparison.OrdinalIgnoreCase) >= 0))
					{
						keyLabels.Add(instanceID);
						val2.SetTemplate(text);
						TMP_Text val3 = (((Object)(object)val2.label != (Object)null) ? val2.label : ((Component)val2).GetComponent<TMP_Text>());
						if ((Object)(object)val3 != (Object)null && val3.text != text)
						{
							val3.text = text;
						}
						num++;
						if (logDetails)
						{
							Plugin.Log.LogDebug((object)(string.Format("Slot {0} label '{1}': text='{2}' ", inventorySpotIndex + 1, ((Object)val2).name, Object.op_Implicit((Object)(object)val3) ? val3.text : "<no label>") + $"active={((Component)val2).gameObject.activeInHierarchy} enabled={Object.op_Implicit((Object)(object)val3) && ((Behaviour)val3).enabled} " + string.Format("font={0} alpha={1}", (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val3.font)) ? ((Object)val3.font).name : "<none>", Object.op_Implicit((Object)(object)val3) ? val3.alpha : 0f)));
						}
					}
				}
				if (logDetails && num == 0)
				{
					Plugin.Log.LogDebug((object)$"Slot {inventorySpotIndex + 1}: no key label found on '{((Object)val).name}'.");
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(InventorySpot), "Update")]
		private static void InventorySpotUpdatePrefix()
		{
			inSpotUpdate = true;
		}

		[HarmonyFinalizer]
		[HarmonyPatch(typeof(InventorySpot), "Update")]
		private static void InventorySpotUpdateFinalizer()
		{
			inSpotUpdate = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SemiFunc), "InputDown")]
		private static bool InputDownPrefix(InputKey key, ref bool __result)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_001a: 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_0011: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			if (!inSpotUpdate)
			{
				return true;
			}
			if ((int)key != 19 && (int)key != 20 && (int)key != 21)
			{
				return true;
			}
			if ((int)SemiFunc.InputMode() != 0)
			{
				return true;
			}
			__result = false;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ItemEquippable), "RequestEquip")]
		private static void RequestEquipPrefix(ItemEquippable __instance, ref int spot, int requestingPlayerId)
		{
			if (spot < 3 || !SemiFunc.IsMultiplayer() || SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			PhysGrabber instance = PhysGrabber.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.photonView == (Object)null || instance.photonView.ViewID != requestingPlayerId)
			{
				return;
			}
			PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			int num = 0;
			for (int i = 0; i < 3; i++)
			{
				if (!Inventory.instance.IsSpotOccupied(i))
				{
					num = i;
					break;
				}
			}
			pendingEquips[component.ViewID] = new KeyValuePair<int, float>(spot, Time.time);
			spot = num;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ItemEquippable), "RPC_UpdateItemState")]
		private static void UpdateItemStatePrefix(ItemEquippable __instance, int state, ref int spotIndex, int ownerId)
		{
			if (state != 2 || pendingEquips.Count == 0)
			{
				return;
			}
			PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
			if (!((Object)(object)component == (Object)null) && pendingEquips.TryGetValue(component.ViewID, out var value))
			{
				pendingEquips.Remove(component.ViewID);
				PhysGrabber instance = PhysGrabber.instance;
				if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.photonView == (Object)null) && instance.photonView.ViewID == ownerId && !(Time.time - value.Value > 5f))
				{
					spotIndex = value.Key;
				}
			}
		}
	}
}