Decompiled source of OreAutoPickup v0.1.0

plugins\StonewardsOreAutoPickup.dll

Decompiled a day ago
using System;
using System.Collections;
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 Mirror;
using UnityEngine;

[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("StonewardsOreAutoPickup")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+db2d248ead104d1036c9ca74be9b58f7e3f31452")]
[assembly: AssemblyProduct("StonewardsOreAutoPickup")]
[assembly: AssemblyTitle("StonewardsOreAutoPickup")]
[assembly: AssemblyVersion("0.1.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 StonewardsOreAutoPickup
{
	[BepInPlugin("community.stonewards.oreautopickup", "Stonewards Ore Auto Pickup", "0.1.0")]
	public sealed class OreAutoPickupPlugin : BaseUnityPlugin
	{
		private sealed class PendingPickup
		{
			public int LastCount;

			public float Deadline;
		}

		private sealed class PickupToast
		{
			public string Id;

			public string Name;

			public int Amount;

			public Color Tint;

			public float Expires;
		}

		private sealed class OreOption
		{
			public string Id;

			public string Name;

			public Sprite Icon;

			public Color Tint;

			public ConfigEntry<bool> AutoPick;
		}

		public const string PluginGuid = "community.stonewards.oreautopickup";

		public const string PluginName = "Stonewards Ore Auto Pickup";

		public const string PluginVersion = "0.1.0";

		private const float ScanInterval = 0.32f;

		private const float DiscoveryInterval = 4f;

		private const float RetryDelay = 7f;

		private const float AckTimeout = 6f;

		private const float ToastDuration = 1.8f;

		private const int MaxVisibleToasts = 4;

		private const int MaxPickupRequestsPerScan = 8;

		private const float WindowWidth = 516f;

		private const float WindowHeight = 390f;

		private static readonly Color Frame = new Color(0.72f, 0.64f, 0.48f, 1f);

		private static readonly Color Background = new Color(0.07450981f, 0.09019608f, 0.1254902f, 0.99f);

		private static readonly Color Header = new Color(0.29803923f, 0.18039216f, 16f / 85f, 1f);

		private static readonly Color Slot = new Color(0.25f, 0.32f, 0.38f, 1f);

		private static readonly Color MutedSlot = new Color(0.15f, 0.19f, 0.24f, 1f);

		private static readonly Color Gold = new Color(0.9411765f, 40f / 51f, 0.36862746f, 1f);

		private static readonly Color Text = new Color(0.95f, 0.95f, 0.95f, 1f);

		private static readonly Color MutedText = new Color(0.69f, 0.72f, 0.76f, 1f);

		private static readonly Color Divider = new Color(0.71f, 0.63f, 0.48f, 0.42f);

		private readonly Dictionary<string, OreOption> _oresById = new Dictionary<string, OreOption>(StringComparer.Ordinal);

		private readonly List<OreOption> _orderedOres = new List<OreOption>();

		private readonly Dictionary<int, float> _recentAttempts = new Dictionary<int, float>();

		private readonly Dictionary<string, PendingPickup> _pendingPickups = new Dictionary<string, PendingPickup>(StringComparer.Ordinal);

		private readonly List<PickupToast> _pickupToasts = new List<PickupToast>();

		private static readonly MethodInfo InventoryGetItemCountMethod = typeof(InventorySystem).GetMethod("GetItemCount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null);

		private bool _warnedAboutInventoryCount;

		private static readonly BindingFlags AllInstance = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly FieldInfo ResourceClustersField = typeof(DigMatterProfileSO).GetField("resourceClusters", AllInstance);

		private readonly Dictionary<Type, FieldInfo> _clusterItemFields = new Dictionary<Type, FieldInfo>();

		private ConfigEntry<bool> _enabled;

		private ConfigEntry<float> _radius;

		private ConfigEntry<bool> _useManualPickup;

		private ConfigEntry<KeyboardShortcut> _settingsKey;

		private bool _menuOpen;

		private bool _oreWindowOpen;

		private bool _captureShortcut;

		private bool _ownsInputState;

		private InputState _returnInputState;

		private CursorLockMode _previousCursorLock;

		private bool _previousCursorVisible;

		private float _nextDiscovery;

		private float _nextScan;

		private float _nextCleanup;

		private Vector2 _scroll;

		private string _oreSearch = "";

		private string _notice = "";

		private bool _warnedNoProfileField;

		private bool _loggedDiscovery;

		private GUIStyle _titleStyle;

		private GUIStyle _labelStyle;

		private GUIStyle _mutedStyle;

		private GUIStyle _buttonStyle;

		private GUIStyle _miniStyle;

		private GUIStyle _searchStyle;

		private GUIStyle _smallGoldStyle;

		private GUIStyle _pickupToastStyle;

		private Font _nativeUiFont;

		private float _nextFontLookup;

		private const float OreWindowWidth = 572f;

		private const float OreWindowHeight = 616f;

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Automatically collect only the selected mined resources.");
			_radius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PickupRadius", 2.5f, new ConfigDescription("Pickup radius in meters; avoid values larger than native interaction range.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 4f), Array.Empty<object>()));
			_useManualPickup = ((BaseUnityPlugin)this).Config.Bind<bool>("Advanced", "UseManualPickupRoute", true, "Use the native manual pickup command for full-stack collection. Set false to restore the previous game's auto-pickup command if needed.");
			_settingsKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "ToggleSettings", new KeyboardShortcut((KeyCode)291, Array.Empty<KeyCode>()), "Open/close the built-in ore selection menu. Ctrl/Shift/Alt combinations are supported.");
			OwnDroppedOre.IsOreId = (string id) => _oresById.ContainsKey(id);
			OwnDroppedOre.Install(((BaseUnityPlugin)this).Logger);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Ore Auto Pickup v0.1.0 initialized.");
		}

		private void Update()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Invalid comparison between Unknown and I4
			KeyboardShortcut value;
			if (_menuOpen && !_captureShortcut)
			{
				value = _settingsKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown() || Input.GetKeyDown((KeyCode)27))
				{
					CloseMenu();
					goto IL_005a;
				}
			}
			if (!_menuOpen)
			{
				value = _settingsKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					OpenMenu();
				}
			}
			goto IL_005a;
			IL_005a:
			if (_menuOpen)
			{
				InputManager instance = InputManager.Instance;
				if ((Object)(object)instance == (Object)null || (int)instance.CurrentInputState != 13)
				{
					CloseMenu(restoreInput: false);
				}
				else
				{
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
				}
			}
			if (!NetworkClient.active)
			{
				OwnDroppedOre.Clear();
			}
			CheckPendingPickupCounts();
			if (Time.unscaledTime >= _nextDiscovery)
			{
				_nextDiscovery = Time.unscaledTime + 4f;
				DiscoverOres();
			}
			if (_enabled.Value && !_menuOpen && !(Time.unscaledTime < _nextScan))
			{
				_nextScan = Time.unscaledTime + 0.32f;
				TryPickupNearbyOres();
			}
		}

		private void DiscoverOres()
		{
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: 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)
			if (ResourceClustersField == null)
			{
				if (!_warnedNoProfileField)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"DigMatterProfileSO.resourceClusters is unavailable. No ore type is assumed or guessed.");
					_warnedNoProfileField = true;
				}
				return;
			}
			try
			{
				DigMatterProfileSO[] array = Resources.FindObjectsOfTypeAll<DigMatterProfileSO>();
				bool flag = false;
				DigMatterProfileSO[] array2 = array;
				foreach (DigMatterProfileSO val in array2)
				{
					if ((Object)(object)val == (Object)null || !(ResourceClustersField.GetValue(val) is IEnumerable enumerable))
					{
						continue;
					}
					foreach (object item in enumerable)
					{
						if (item == null)
						{
							continue;
						}
						Type type = item.GetType();
						if (!_clusterItemFields.TryGetValue(type, out var value))
						{
							value = type.GetField("resourceCluster", AllInstance);
							_clusterItemFields[type] = value;
						}
						ItemDataSO val2 = (ItemDataSO)((value == null) ? null : /*isinst with value type is only supported in some contexts*/);
						if ((Object)(object)val2 == (Object)null || val2.isScrapItem || string.IsNullOrEmpty(val2.itemID) || _oresById.ContainsKey(val2.itemID))
						{
							continue;
						}
						string itemID = val2.itemID;
						string text = itemID;
						try
						{
							string localizedName = val2.GetLocalizedName();
							if (!string.IsNullOrEmpty(localizedName))
							{
								text = localizedName;
							}
						}
						catch (Exception)
						{
						}
						bool flag2 = itemID == "STONE" || itemID == "STONE_MAP_2";
						OreOption oreOption = new OreOption();
						oreOption.Id = itemID;
						oreOption.Name = text;
						oreOption.Icon = val2.itemIcon;
						oreOption.Tint = OreTint(itemID, val2.itemIcon);
						oreOption.AutoPick = ((BaseUnityPlugin)this).Config.Bind<bool>("Ores", itemID, !flag2, "Automatically collect the mined resource " + text + " (" + itemID + ").");
						OreOption oreOption2 = oreOption;
						if (flag2)
						{
							ConfigEntry<bool> val3 = ((BaseUnityPlugin)this).Config.Bind<bool>("Migrations", "StoneDefaultDisabled_" + itemID + "_v026", false, "Internal one-time migration for the new Stone default.");
							if (!val3.Value)
							{
								oreOption2.AutoPick.Value = false;
								val3.Value = true;
								((BaseUnityPlugin)this).Logger.LogInfo((object)("Stone default migrated to IGNORE for " + itemID + ". Users may enable it again from CONFIGURE ORES."));
							}
						}
						_oresById.Add(itemID, oreOption2);
						_orderedOres.Add(oreOption2);
						((BaseUnityPlugin)this).Logger.LogInfo((object)("Discovered real mined resource: ID=" + itemID + "; Name=" + text + "; Icon=" + (((Object)(object)val2.itemIcon == (Object)null) ? "<none>" : ((Object)val2.itemIcon).name) + "; Rarity=" + ((object)Unsafe.As<Rarity, Rarity>(ref val2.Rarity)/*cast due to .constrained prefix*/).ToString() + "; Tint=#" + ColorUtility.ToHtmlStringRGB(oreOption2.Tint)));
						flag = true;
					}
				}
				if (flag)
				{
					_orderedOres.Sort((OreOption a, OreOption b) => string.Compare(a.Name, b.Name, StringComparison.CurrentCultureIgnoreCase));
					((BaseUnityPlugin)this).Config.Save();
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Found " + _orderedOres.Count + " mined resource types: " + string.Join(", ", _orderedOres.ConvertAll((OreOption x) => x.Id).ToArray())));
					_loggedDiscovery = true;
				}
				else if (!_loggedDiscovery && _orderedOres.Count == 0)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Ore data not loaded yet; enter a level to discover actual mined resources.");
					_loggedDiscovery = true;
				}
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Ore discovery failed: " + ex2.Message));
			}
		}

		private static FirstPersonController LocalPlayer()
		{
			List<FirstPersonController> localPlayers = FirstPersonController.LocalPlayers;
			if (localPlayers == null)
			{
				return null;
			}
			foreach (FirstPersonController item in localPlayers)
			{
				if ((Object)(object)item != (Object)null && ((NetworkBehaviour)item).isLocalPlayer)
				{
					return item;
				}
			}
			return null;
		}

		private void TryPickupNearbyOres()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			if (_oresById.Count == 0 || !NetworkClient.active)
			{
				return;
			}
			InputManager instance = InputManager.Instance;
			if ((Object)(object)instance == (Object)null || (int)instance.CurrentInputState != 2)
			{
				return;
			}
			FirstPersonController val = LocalPlayer();
			if ((Object)(object)val == (Object)null || (Object)(object)val.PlayerStats == (Object)null || val.PlayerStats.isDead)
			{
				return;
			}
			float num = _radius.Value * _radius.Value;
			Vector3 position = ((Component)val).transform.position;
			int num2 = 0;
			try
			{
				PickableItem[] array = Object.FindObjectsOfType<PickableItem>();
				OwnDroppedOre.Observe(array, position);
				PickableItem[] array2 = array;
				foreach (PickableItem val2 in array2)
				{
					if ((Object)(object)val2 == (Object)null || !((Behaviour)val2).isActiveAndEnabled || val2.NetworkSyncPlayerID != 0L)
					{
						continue;
					}
					ItemDataSO itemDataSO = val2.ItemDataSO;
					if ((Object)(object)itemDataSO == (Object)null || string.IsNullOrEmpty(itemDataSO.itemID) || !_oresById.TryGetValue(itemDataSO.itemID, out var value) || !value.AutoPick.Value || OwnDroppedOre.ShouldIgnore(val2, itemDataSO.itemID))
					{
						continue;
					}
					Vector3 val3 = ((Component)val2).transform.position - position;
					if (((Vector3)(ref val3)).sqrMagnitude > num)
					{
						continue;
					}
					int instanceID = ((Object)val2).GetInstanceID();
					if (!_recentAttempts.TryGetValue(instanceID, out var value2) || !(Time.unscaledTime < value2))
					{
						_recentAttempts[instanceID] = Time.unscaledTime + 7f;
						TrackRequestedPickup(val, itemDataSO.itemID);
						if (_useManualPickup.Value)
						{
							val.CmdPickupItem(val, val2);
						}
						else
						{
							val.CmdAutoPickupItem(val, val2);
						}
						((BaseUnityPlugin)this).Logger.LogDebug((object)("Pickup request: item=" + itemDataSO.itemID + ", world object=" + ((Object)val2).GetInstanceID() + ", route=" + (_useManualPickup.Value ? "manual" : "auto")));
						num2++;
						if (num2 >= 8)
						{
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Pickup scan failed: " + ex.Message));
			}
			if (!(Time.unscaledTime > _nextCleanup))
			{
				return;
			}
			_nextCleanup = Time.unscaledTime + 30f;
			List<int> list = new List<int>();
			foreach (KeyValuePair<int, float> recentAttempt in _recentAttempts)
			{
				if (recentAttempt.Value + 30f < Time.unscaledTime)
				{
					list.Add(recentAttempt.Key);
				}
			}
			foreach (int item in list)
			{
				_recentAttempts.Remove(item);
			}
		}

		private int ReadInventoryCount(FirstPersonController player, string itemId)
		{
			if ((Object)(object)player == (Object)null || (Object)(object)player.InventorySystem == (Object)null || InventoryGetItemCountMethod == null)
			{
				if (InventoryGetItemCountMethod == null && !_warnedAboutInventoryCount)
				{
					_warnedAboutInventoryCount = true;
					((BaseUnityPlugin)this).Logger.LogWarning((object)"InventorySystem.GetItemCount(string) unavailable. Pickup notifications will not guess amounts.");
				}
				return -1;
			}
			try
			{
				return Convert.ToInt32(InventoryGetItemCountMethod.Invoke(player.InventorySystem, new object[1] { itemId }));
			}
			catch (Exception ex)
			{
				if (!_warnedAboutInventoryCount)
				{
					_warnedAboutInventoryCount = true;
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Unable to read confirmed inventory counts: " + ex.Message));
				}
				return -1;
			}
		}

		private void TrackRequestedPickup(FirstPersonController player, string id)
		{
			int num = ReadInventoryCount(player, id);
			if (num >= 0)
			{
				if (_pendingPickups.TryGetValue(id, out var value))
				{
					value.Deadline = Time.unscaledTime + 6f;
					return;
				}
				_pendingPickups.Add(id, new PendingPickup
				{
					LastCount = num,
					Deadline = Time.unscaledTime + 6f
				});
			}
		}

		private void CheckPendingPickupCounts()
		{
			if (_pendingPickups.Count == 0)
			{
				return;
			}
			FirstPersonController val = LocalPlayer();
			if ((Object)(object)val == (Object)null || !NetworkClient.active)
			{
				_pendingPickups.Clear();
				return;
			}
			List<string> list = new List<string>();
			foreach (KeyValuePair<string, PendingPickup> pendingPickup in _pendingPickups)
			{
				PendingPickup value = pendingPickup.Value;
				if (Time.unscaledTime > value.Deadline)
				{
					list.Add(pendingPickup.Key);
					continue;
				}
				int num = ReadInventoryCount(val, pendingPickup.Key);
				if (num >= 0)
				{
					int num2 = num - value.LastCount;
					if (num2 > 0 && _oresById.TryGetValue(pendingPickup.Key, out var value2))
					{
						PushPickupToast(value2, num2);
						((BaseUnityPlugin)this).Logger.LogDebug((object)("Confirmed pickup: " + pendingPickup.Key + " +" + num2 + " (" + value.LastCount + " -> " + num + ")"));
					}
					value.LastCount = num;
				}
			}
			foreach (string item in list)
			{
				_pendingPickups.Remove(item);
			}
		}

		private void PushPickupToast(OreOption ore, int received)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			foreach (PickupToast pickupToast in _pickupToasts)
			{
				if (pickupToast.Id == ore.Id && pickupToast.Expires - Time.unscaledTime > 0.65f)
				{
					pickupToast.Amount += received;
					pickupToast.Expires = Time.unscaledTime + 1.8f;
					return;
				}
			}
			_pickupToasts.Add(new PickupToast
			{
				Id = ore.Id,
				Name = ore.Name,
				Tint = ore.Tint,
				Amount = received,
				Expires = Time.unscaledTime + 1.8f
			});
			while (_pickupToasts.Count > 4)
			{
				_pickupToasts.RemoveAt(0);
			}
		}

		private void DrawPickupToasts()
		{
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			for (int num = _pickupToasts.Count - 1; num >= 0; num--)
			{
				if (Time.unscaledTime >= _pickupToasts[num].Expires)
				{
					_pickupToasts.RemoveAt(num);
				}
			}
			if (_pickupToasts.Count == 0)
			{
				return;
			}
			EnsureStyles();
			int depth = GUI.depth;
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			Color contentColor = GUI.contentColor;
			try
			{
				GUI.depth = -540;
				float num2 = Mathf.Clamp((float)Screen.height / 1080f, 0.8f, 1.5f);
				GUI.matrix = Matrix4x4.Scale(new Vector3(num2, num2, 1f));
				float num3 = (float)Screen.width / num2 * 0.5f;
				float num4 = (float)Screen.height / num2 * 0.322f;
				for (int i = 0; i < _pickupToasts.Count; i++)
				{
					PickupToast pickupToast = _pickupToasts[i];
					float num5 = Mathf.Clamp01((pickupToast.Expires - Time.unscaledTime) / 0.42f);
					GUI.color = Color.white;
					_pickupToastStyle.normal.textColor = Color.white;
					GUI.contentColor = new Color(pickupToast.Tint.r, pickupToast.Tint.g, pickupToast.Tint.b, num5);
					GUI.Label(new Rect(num3 - 190f, num4 + (float)i * 37f, 380f, 36f), "+" + pickupToast.Amount + " " + pickupToast.Name.ToUpperInvariant(), _pickupToastStyle);
				}
			}
			finally
			{
				GUI.depth = depth;
				GUI.matrix = matrix;
				GUI.color = color;
				GUI.contentColor = contentColor;
			}
		}

		private static Color OreTint(string id, Sprite icon)
		{
			//IL_0240: 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_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			switch (id)
			{
			case "STONE":
			case "STONE_MAP_2":
				return Color32.op_Implicit(new Color32((byte)190, (byte)190, (byte)178, byte.MaxValue));
			case "IRON":
				return Color32.op_Implicit(new Color32((byte)170, (byte)194, (byte)206, byte.MaxValue));
			case "DIAMOND":
				return Color32.op_Implicit(new Color32((byte)123, (byte)223, (byte)241, byte.MaxValue));
			case "GOLD":
				return Color32.op_Implicit(new Color32(byte.MaxValue, (byte)205, (byte)86, byte.MaxValue));
			case "EMERALD":
				return Color32.op_Implicit(new Color32((byte)87, (byte)219, (byte)128, byte.MaxValue));
			case "IRON_MAP_2":
				return Color32.op_Implicit(new Color32((byte)235, (byte)142, (byte)86, byte.MaxValue));
			case "GOLD_MAP_2":
				return Color32.op_Implicit(new Color32((byte)216, (byte)225, (byte)236, byte.MaxValue));
			case "EMERALD_MAP_2":
				return Color32.op_Implicit(new Color32((byte)244, (byte)93, (byte)115, byte.MaxValue));
			default:
			{
				if (TrySampleIconColor(icon, out var tint))
				{
					return tint;
				}
				uint num = 2166136261u;
				foreach (char c in id)
				{
					num ^= c;
					num *= 16777619;
				}
				return Color.HSVToRGB((float)(num % 360) / 360f, 0.67f, 1f);
			}
			}
		}

		private static bool TrySampleIconColor(Sprite sprite, out Color tint)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			tint = Color.white;
			if ((Object)(object)sprite == (Object)null || (Object)(object)sprite.texture == (Object)null)
			{
				return false;
			}
			Texture2D texture = sprite.texture;
			if (!((Texture)texture).isReadable)
			{
				return false;
			}
			try
			{
				Rect textureRect = sprite.textureRect;
				int num = Mathf.Clamp(Mathf.FloorToInt(((Rect)(ref textureRect)).xMin), 0, ((Texture)texture).width - 1);
				int num2 = Mathf.Clamp(Mathf.CeilToInt(((Rect)(ref textureRect)).xMax), num + 1, ((Texture)texture).width);
				int num3 = Mathf.Clamp(Mathf.FloorToInt(((Rect)(ref textureRect)).yMin), 0, ((Texture)texture).height - 1);
				int num4 = Mathf.Clamp(Mathf.CeilToInt(((Rect)(ref textureRect)).yMax), num3 + 1, ((Texture)texture).height);
				int num5 = Mathf.Max(1, (num2 - num) / 16);
				int num6 = Mathf.Max(1, (num4 - num3) / 16);
				float num7 = 0f;
				float num8 = 0f;
				float num9 = 0f;
				float num10 = 0f;
				for (int i = num3; i < num4; i += num6)
				{
					for (int j = num; j < num2; j += num5)
					{
						Color pixel = texture.GetPixel(j, i);
						if (!(pixel.a < 0.45f))
						{
							float num11 = Mathf.Max(pixel.r, Mathf.Max(pixel.g, pixel.b));
							float num12 = Mathf.Min(pixel.r, Mathf.Min(pixel.g, pixel.b));
							float num13 = ((num11 <= 0f) ? 0f : ((num11 - num12) / num11));
							if (!(num11 < 0.18f))
							{
								float num14 = pixel.a * (0.35f + num13 * 1.5f) * num11;
								num7 += pixel.r * num14;
								num8 += pixel.g * num14;
								num9 += pixel.b * num14;
								num10 += num14;
							}
						}
					}
				}
				if (num10 < 0.001f)
				{
					return false;
				}
				float num15 = default(float);
				float num16 = default(float);
				float num17 = default(float);
				Color.RGBToHSV(new Color(num7 / num10, num8 / num10, num9 / num10), ref num15, ref num16, ref num17);
				if (num16 < 0.12f)
				{
					return false;
				}
				tint = Color.HSVToRGB(num15, Mathf.Clamp(num16 * 1.28f, 0.45f, 0.87f), Mathf.Clamp(num17 * 1.24f, 0.85f, 1f));
				return true;
			}
			catch (Exception)
			{
				return false;
			}
		}

		private void OpenMenu()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			InputManager instance = InputManager.Instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)GameManager.Instance == (Object)null))
			{
				InputState currentInputState = instance.CurrentInputState;
				if ((int)currentInputState == 2 || (int)currentInputState == 4)
				{
					_returnInputState = currentInputState;
					_previousCursorLock = Cursor.lockState;
					_previousCursorVisible = Cursor.visible;
					_menuOpen = true;
					_oreWindowOpen = false;
					_ownsInputState = true;
					_captureShortcut = false;
					_notice = "";
					DiscoverOres();
					instance.SetState((InputState)13, true);
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
				}
			}
		}

		private void CloseMenu(bool restoreInput = true)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			if (_menuOpen)
			{
				_menuOpen = false;
				_oreWindowOpen = false;
				_captureShortcut = false;
				InputManager instance = InputManager.Instance;
				if (_ownsInputState && (Object)(object)instance != (Object)null && (int)instance.CurrentInputState == 13 && restoreInput)
				{
					FirstPersonController val = LocalPlayer();
					InputState val2 = (InputState)((!((Object)(object)val != (Object)null) || !((Object)(object)val.PlayerStats != (Object)null)) ? ((int)_returnInputState) : (val.PlayerStats.isDead ? 4 : 2));
					instance.SetState(val2, true);
				}
				_ownsInputState = false;
				if (restoreInput)
				{
					Cursor.lockState = _previousCursorLock;
					Cursor.visible = _previousCursorVisible;
				}
			}
		}

		private void OnDisable()
		{
			CloseMenu();
		}

		private void OnDestroy()
		{
			CloseMenu();
			OwnDroppedOre.Uninstall();
		}

		private static void Fill(Rect r, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Color color2 = GUI.color;
			GUI.color = color;
			GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color2;
		}

		private static void Panel(Rect r, Color background)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			Fill(r, Frame);
			Fill(new Rect(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width - 4f, ((Rect)(ref r)).height - 4f), background);
		}

		private bool Button(Rect r, string content, bool selected = false)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Fill(r, selected ? Header : Slot);
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, 1f), selected ? Gold : Frame);
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + ((Rect)(ref r)).height - 1f, ((Rect)(ref r)).width, 1f), Frame);
			return GUI.Button(r, content, _buttonStyle);
		}

		private void EnsureStyles()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			if (_titleStyle == null)
			{
				_titleStyle = MakeStyle(24, Gold, (TextAnchor)3);
				_labelStyle = MakeStyle(18, Text, (TextAnchor)3);
				_mutedStyle = MakeStyle(15, MutedText, (TextAnchor)3);
				_mutedStyle.wordWrap = true;
				_smallGoldStyle = MakeStyle(16, Gold, (TextAnchor)3);
				_pickupToastStyle = MakeStyle(26, Text, (TextAnchor)4);
				_miniStyle = MakeStyle(14, MutedText, (TextAnchor)5);
				GUIStyle val = new GUIStyle(GUI.skin.textField)
				{
					fontSize = 18,
					fontStyle = (FontStyle)0,
					alignment = (TextAnchor)3
				};
				val.normal.textColor = Text;
				val.focused.textColor = Text;
				_searchStyle = val;
				GUIStyle val2 = new GUIStyle(GUI.skin.button)
				{
					fontSize = 18,
					fontStyle = (FontStyle)0,
					alignment = (TextAnchor)4
				};
				val2.normal.background = null;
				val2.normal.textColor = Text;
				val2.hover.background = null;
				val2.hover.textColor = Gold;
				val2.active.background = null;
				val2.active.textColor = Gold;
				val2.focused.background = null;
				val2.focused.textColor = Text;
				_buttonStyle = val2;
			}
			TryApplyNativeFont();
		}

		private static GUIStyle MakeStyle(int size, Color color, TextAnchor align)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				fontSize = size,
				fontStyle = (FontStyle)0,
				alignment = align,
				clipping = (TextClipping)1,
				richText = false
			};
			val.normal.textColor = color;
			return val;
		}

		private void TryApplyNativeFont()
		{
			if ((Object)(object)_nativeUiFont != (Object)null || Time.unscaledTime < _nextFontLookup)
			{
				return;
			}
			_nextFontLookup = Time.unscaledTime + 8f;
			Font val = null;
			Font val2 = null;
			Font[] array = Resources.FindObjectsOfTypeAll<Font>();
			foreach (Font val3 in array)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					if (((Object)val3).name == "Jersey10-Regular")
					{
						val = val3;
					}
					else if (((Object)val3).name == "Jersey10-Regular2")
					{
						val2 = val3;
					}
				}
			}
			_nativeUiFont = (((Object)(object)val != (Object)null) ? val : val2);
			if (!((Object)(object)_nativeUiFont == (Object)null))
			{
				GUIStyle[] array2 = (GUIStyle[])(object)new GUIStyle[8] { _titleStyle, _labelStyle, _mutedStyle, _smallGoldStyle, _miniStyle, _searchStyle, _buttonStyle, _pickupToastStyle };
				foreach (GUIStyle obj in array2)
				{
					obj.font = _nativeUiFont;
					obj.fontStyle = (FontStyle)0;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Ore Auto Pickup native UI font: " + ((Object)_nativeUiFont).name));
			}
		}

		private void OnGUI()
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (Event.current == null)
			{
				return;
			}
			if ((int)Event.current.type == 7)
			{
				DrawPickupToasts();
			}
			if (!_menuOpen)
			{
				return;
			}
			EnsureStyles();
			Matrix4x4 matrix = GUI.matrix;
			int depth = GUI.depth;
			float num = Mathf.Clamp(Mathf.Min((float)Screen.width / 1120f, (float)Screen.height / 740f), 0.65f, 1.25f);
			try
			{
				GUI.depth = -550;
				GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
				float num2 = (_oreWindowOpen ? 572f : 516f);
				float num3 = (_oreWindowOpen ? 616f : 390f);
				float x = Mathf.Max(0f, ((float)Screen.width / num - num2) * 0.5f);
				float y = Mathf.Max(0f, ((float)Screen.height / num - num3) * 0.5f);
				DrawMenu(x, y);
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.depth = depth;
			}
		}

		private void DrawMenu(float x, float y)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: 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_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			if (_oreWindowOpen)
			{
				DrawOreSelection(x, y);
				return;
			}
			Panel(new Rect(x, y, 516f, 390f), Background);
			Fill(new Rect(x + 2f, y + 2f, 512f, 58f), Header);
			Fill(new Rect(x + 2f, y + 58f, 512f, 2f), Gold);
			GUI.Label(new Rect(x + 20f, y + 10f, 392f, 38f), "ORE AUTO PICKUP", _titleStyle);
			if (Button(new Rect(x + 516f - 55f, y + 14f, 32f, 31f), "X"))
			{
				CloseMenu();
				return;
			}
			GUI.Label(new Rect(x + 20f, y + 73f, 292f, 31f), "Auto pickup", _labelStyle);
			if (Button(new Rect(x + 341f, y + 74f, 150f, 31f), _enabled.Value ? "ENABLED" : "DISABLED", _enabled.Value))
			{
				_enabled.Value = !_enabled.Value;
				((BaseUnityPlugin)this).Config.Save();
			}
			GUI.Label(new Rect(x + 20f, y + 117f, 226f, 31f), "Pickup radius", _labelStyle);
			float num = GUI.HorizontalSlider(new Rect(x + 242f, y + 126f, 166f, 18f), _radius.Value, 1f, 4f);
			if (Mathf.Abs(num - _radius.Value) > 0.05f)
			{
				_radius.Value = (float)Math.Round(num * 10f) / 10f;
				((BaseUnityPlugin)this).Config.Save();
			}
			GUI.Label(new Rect(x + 421f, y + 116f, 79f, 31f), _radius.Value.ToString("0.0") + " m", _smallGoldStyle);
			Fill(new Rect(x + 20f, y + 162f, 476f, 1f), Divider);
			GUI.Label(new Rect(x + 20f, y + 170f, 263f, 33f), "Ore selection", _labelStyle);
			int num2 = 0;
			foreach (OreOption orderedOre in _orderedOres)
			{
				if (orderedOre.AutoPick.Value)
				{
					num2++;
				}
			}
			if (Button(new Rect(x + 291f, y + 170f, 200f, 34f), "CONFIGURE ORES  >"))
			{
				_scroll = Vector2.zero;
				_oreWindowOpen = true;
				DiscoverOres();
			}
			GUI.Label(new Rect(x + 20f, y + 203f, 476f, 25f), num2 + " / " + _orderedOres.Count + " resource types enabled", _mutedStyle);
			Fill(new Rect(x + 20f, y + 239f, 476f, 1f), Divider);
			GUI.Label(new Rect(x + 20f, y + 250f, 255f, 30f), "Settings shortcut", _labelStyle);
			if (Button(new Rect(x + 281f, y + 250f, 210f, 31f), _captureShortcut ? "PRESS KEY..." : ((object)_settingsKey.Value/*cast due to .constrained prefix*/).ToString(), _captureShortcut))
			{
				_captureShortcut = true;
				_notice = "Press Esc to cancel";
			}
			if (_captureShortcut)
			{
				CaptureShortcut();
			}
			GUI.Label(new Rect(x + 20f, y + 286f, 476f, 35f), "Nearby mined ore only. Other items use vanilla pickup.", _mutedStyle);
			if (!string.IsNullOrEmpty(_notice))
			{
				GUI.Label(new Rect(x + 20f, y + 323f, 476f, 22f), _notice, _smallGoldStyle);
			}
			if (Button(new Rect(x + 20f, y + 354f, 476f, 28f), "CLOSE SETTINGS"))
			{
				CloseMenu();
			}
		}

		private void DrawOreSelection(float x, float y)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_056a: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0591: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d4: Unknown result type (might be due to invalid IL or missing references)
			Panel(new Rect(x, y, 572f, 616f), Background);
			Fill(new Rect(x + 2f, y + 2f, 568f, 58f), Header);
			Fill(new Rect(x + 2f, y + 58f, 568f, 2f), Gold);
			GUI.Label(new Rect(x + 20f, y + 11f, 420f, 37f), "ORE PICKUP FILTER", _titleStyle);
			if (Button(new Rect(x + 572f - 56f, y + 14f, 34f, 31f), "X"))
			{
				_oreWindowOpen = false;
				return;
			}
			GUI.Label(new Rect(x + 20f, y + 72f, 532f, 33f), "Choose which mined resources go into your inventory.", _mutedStyle);
			if (Button(new Rect(x + 20f, y + 112f, 152f, 33f), "ENABLE ALL"))
			{
				SetAll(value: true);
			}
			if (Button(new Rect(x + 181f, y + 112f, 154f, 33f), "DISABLE ALL"))
			{
				SetAll(value: false);
			}
			GUI.Label(new Rect(x + 351f, y + 112f, 198f, 33f), _orderedOres.Count + " discovered", _miniStyle);
			GUI.Label(new Rect(x + 20f, y + 160f, 91f, 29f), "FIND", _labelStyle);
			Fill(new Rect(x + 99f, y + 161f, 452f, 29f), Slot);
			_oreSearch = GUI.TextField(new Rect(x + 106f, y + 160f, 437f, 31f), _oreSearch, 60, _searchStyle);
			List<OreOption> list = new List<OreOption>();
			foreach (OreOption orderedOre in _orderedOres)
			{
				if (string.IsNullOrWhiteSpace(_oreSearch) || orderedOre.Name.IndexOf(_oreSearch, StringComparison.OrdinalIgnoreCase) >= 0 || orderedOre.Id.IndexOf(_oreSearch, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					list.Add(orderedOre);
				}
			}
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(x + 20f, y + 202f, 532f, 315f);
			Panel(r, MutedSlot);
			float num = Mathf.Max(((Rect)(ref r)).height - 7f, (float)list.Count * 57f + 13f);
			_scroll = GUI.BeginScrollView(new Rect(((Rect)(ref r)).x + 3f, ((Rect)(ref r)).y + 3f, ((Rect)(ref r)).width - 6f, ((Rect)(ref r)).height - 6f), _scroll, new Rect(0f, 0f, ((Rect)(ref r)).width - 26f, num));
			if (_orderedOres.Count == 0)
			{
				GUI.Label(new Rect(12f, 12f, ((Rect)(ref r)).width - 42f, 82f), "Ore types are not available yet. Enter a level and mine a resource.", _mutedStyle);
			}
			else if (list.Count == 0)
			{
				GUI.Label(new Rect(12f, 12f, ((Rect)(ref r)).width - 42f, 52f), "Nothing matches the filter.", _mutedStyle);
			}
			for (int i = 0; i < list.Count; i++)
			{
				OreOption oreOption = list[i];
				float num2 = (float)i * 57f + 8f;
				Fill(new Rect(8f, num2, ((Rect)(ref r)).width - 33f, 51f), Slot);
				DrawOreIcon(oreOption.Icon, new Rect(16f, num2 + 5f, 41f, 41f));
				Color contentColor = GUI.contentColor;
				GUI.contentColor = oreOption.Tint;
				GUI.Label(new Rect(71f, num2 + 5f, ((Rect)(ref r)).width - 237f, 40f), oreOption.Name, _labelStyle);
				GUI.contentColor = contentColor;
				if (Button(new Rect(((Rect)(ref r)).width - 150f, num2 + 8f, 112f, 33f), oreOption.AutoPick.Value ? "PICK UP" : "IGNORE", oreOption.AutoPick.Value))
				{
					oreOption.AutoPick.Value = !oreOption.AutoPick.Value;
					((BaseUnityPlugin)this).Config.Save();
					_notice = oreOption.Name + (oreOption.AutoPick.Value ? " enabled" : " disabled");
				}
			}
			GUI.EndScrollView();
			Fill(new Rect(x + 20f, y + 530f, 532f, 1f), Divider);
			GUI.Label(new Rect(x + 20f, y + 539f, 532f, 26f), string.IsNullOrEmpty(_notice) ? "Changes are saved immediately." : _notice, _mutedStyle);
			if (Button(new Rect(x + 20f, y + 576f, 532f, 29f), "<  BACK TO SETTINGS"))
			{
				_oreWindowOpen = false;
			}
		}

		private static void DrawOreIcon(Sprite icon, Rect rect)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)icon == (Object)null || (Object)(object)icon.texture == (Object)null)
			{
				Panel(rect, MutedSlot);
				return;
			}
			try
			{
				Texture2D texture = icon.texture;
				Rect textureRect = icon.textureRect;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(((Rect)(ref textureRect)).x / (float)((Texture)texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)texture).height);
				GUI.DrawTextureWithTexCoords(rect, (Texture)(object)texture, val, true);
			}
			catch (Exception)
			{
				Panel(rect, MutedSlot);
			}
		}

		private void SetAll(bool value)
		{
			foreach (OreOption orderedOre in _orderedOres)
			{
				orderedOre.AutoPick.Value = value;
			}
			((BaseUnityPlugin)this).Config.Save();
			_notice = (value ? "All mined resources enabled" : "All mined resources disabled");
		}

		private void CaptureShortcut()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			Event current = Event.current;
			if ((int)current.type != 4)
			{
				return;
			}
			if ((int)current.keyCode == 27)
			{
				_captureShortcut = false;
				_notice = "Shortcut change canceled";
				current.Use();
			}
			else if ((int)current.keyCode != 0 && !IsModifier(current.keyCode))
			{
				List<KeyCode> list = new List<KeyCode>(3);
				if (current.control)
				{
					list.Add((KeyCode)306);
				}
				if (current.shift)
				{
					list.Add((KeyCode)304);
				}
				if (current.alt)
				{
					list.Add((KeyCode)308);
				}
				_settingsKey.Value = new KeyboardShortcut(current.keyCode, list.ToArray());
				((BaseUnityPlugin)this).Config.Save();
				_captureShortcut = false;
				_notice = "Shortcut saved";
				current.Use();
			}
		}

		private static bool IsModifier(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			if ((int)key != 306 && (int)key != 305 && (int)key != 308 && (int)key != 307 && (int)key != 304)
			{
				return (int)key == 303;
			}
			return true;
		}
	}
	internal static class OwnDroppedOre
	{
		private sealed class DropRequest
		{
			internal string Id;

			internal Vector3 Position;

			internal float Deadline;

			internal readonly HashSet<int> Existing = new HashSet<int>();
		}

		private const float IdentificationWindow = 12f;

		private const float MatchRadius = 2.8f;

		private const float FallbackRadius = 3f;

		private const float LeaveDistance = 5f;

		private static readonly List<DropRequest> Pending = new List<DropRequest>();

		private static readonly Dictionary<int, PickableItem> Ignored = new Dictionary<int, PickableItem>();

		private static ManualLogSource _log;

		private static Harmony _harmony;

		private static float _nextPrune;

		internal static Func<string, bool> IsOreId;

		internal static void Install(ManualLogSource log)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			_log = log;
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(FirstPersonController), "CmdReleaseItem", (Type[])null, (Type[])null);
				if (methodInfo == null)
				{
					log.LogWarning((object)"Own-drop guard disabled: CmdReleaseItem method not found.");
					return;
				}
				HarmonyMethod val = new HarmonyMethod(typeof(OwnDroppedOre).GetMethod("BeforeItemRelease", BindingFlags.Static | BindingFlags.NonPublic));
				_harmony = new Harmony("community.stonewards.oreautopickup.dropguard");
				_harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				log.LogInfo((object)"Own-drop guard enabled.");
			}
			catch (Exception ex)
			{
				log.LogWarning((object)("Own-drop guard could not hook inventory release: " + ex.Message));
			}
		}

		private static void BeforeItemRelease(FirstPersonController __instance, object[] __args)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance == (Object)null || !((NetworkBehaviour)__instance).isLocalPlayer || __args == null || __args.Length < 5 || __args[0] != __instance)
				{
					return;
				}
				string text = __args[1] as string;
				if (string.IsNullOrEmpty(text) || !(__args[4] is Vector3) || IsOreId == null || !IsOreId(text))
				{
					return;
				}
				Vector3 position = (Vector3)__args[4];
				DropRequest dropRequest = new DropRequest
				{
					Id = text,
					Position = position,
					Deadline = Time.unscaledTime + 12f
				};
				PickableItem[] array = Object.FindObjectsOfType<PickableItem>();
				foreach (PickableItem val in array)
				{
					if ((Object)(object)val != (Object)null)
					{
						dropRequest.Existing.Add(((Object)val).GetInstanceID());
					}
				}
				Pending.Add(dropRequest);
				ManualLogSource log = _log;
				if (log != null)
				{
					log.LogInfo((object)("Ore dropped manually: " + text + " (auto pickup protected)."));
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = _log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Own-drop guard could not inspect drop: " + ex.Message));
				}
			}
		}

		internal static void Observe(PickableItem[] pickups, Vector3 playerPosition)
		{
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			float unscaledTime = Time.unscaledTime;
			float num = 7.8399997f;
			for (int num2 = Pending.Count - 1; num2 >= 0; num2--)
			{
				DropRequest dropRequest = Pending[num2];
				Vector3 val3;
				if (unscaledTime < dropRequest.Deadline)
				{
					PickableItem val = null;
					float num3 = num;
					foreach (PickableItem val2 in pickups)
					{
						if ((Object)(object)val2 == (Object)null || !((Behaviour)val2).isActiveAndEnabled || dropRequest.Existing.Contains(((Object)val2).GetInstanceID()) || (Ignored.TryGetValue(((Object)val2).GetInstanceID(), out var value) && (Object)(object)value == (Object)(object)val2))
						{
							continue;
						}
						ItemDataSO itemDataSO = val2.ItemDataSO;
						if (!((Object)(object)itemDataSO == (Object)null) && !(itemDataSO.itemID != dropRequest.Id))
						{
							val3 = ((Component)val2).transform.position - dropRequest.Position;
							float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
							if (sqrMagnitude < num3)
							{
								val = val2;
								num3 = sqrMagnitude;
							}
						}
					}
					if ((Object)(object)val != (Object)null)
					{
						Ignored[((Object)val).GetInstanceID()] = val;
						Pending.RemoveAt(num2);
						ManualLogSource log = _log;
						if (log != null)
						{
							log.LogInfo((object)("Excluding own dropped " + dropRequest.Id + " from auto pickup, object " + ((Object)val).GetInstanceID()));
						}
						continue;
					}
				}
				if (unscaledTime >= dropRequest.Deadline)
				{
					val3 = playerPosition - dropRequest.Position;
					if (((Vector3)(ref val3)).sqrMagnitude > 25f)
					{
						Pending.RemoveAt(num2);
					}
				}
			}
			if (!(unscaledTime >= _nextPrune))
			{
				return;
			}
			_nextPrune = unscaledTime + 10f;
			List<int> list = new List<int>();
			foreach (KeyValuePair<int, PickableItem> item in Ignored)
			{
				if ((Object)(object)item.Value == (Object)null)
				{
					list.Add(item.Key);
				}
			}
			foreach (int item2 in list)
			{
				Ignored.Remove(item2);
			}
		}

		internal static bool ShouldIgnore(PickableItem item, string id)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (Ignored.TryGetValue(((Object)item).GetInstanceID(), out var value) && (Object)(object)value == (Object)(object)item)
			{
				return true;
			}
			foreach (DropRequest item2 in Pending)
			{
				if (item2.Id == id)
				{
					Vector3 val = ((Component)item).transform.position - item2.Position;
					if (((Vector3)(ref val)).sqrMagnitude <= 9f)
					{
						return true;
					}
				}
			}
			return false;
		}

		internal static void Clear()
		{
			Pending.Clear();
			Ignored.Clear();
		}

		internal static void Uninstall()
		{
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
				_harmony = null;
			}
			IsOreId = null;
			Clear();
		}
	}
}