Decompiled source of HipCharms v0.4.0

plugins/HipCharms/HipCharms.dll

Decompiled 16 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HipCharms.Core;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HipCharms")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4.0")]
[assembly: AssemblyProduct("HipCharms")]
[assembly: AssemblyTitle("HipCharms")]
[assembly: AssemblyVersion("0.4.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 HipCharms
{
	internal sealed class BeltVisuals : MonoBehaviour
	{
		private const string StateKey = "hipcharms.visuals.v2";

		private const string CountKey = "hipcharms.arrowCounts.v3";

		private static readonly string[] ArrowKeys = new string[3] { "hipcharms.arrow0.v2", "hipcharms.arrow1.v2", "hipcharms.arrow2.v2" };

		internal const int Belt = 1;

		internal const int Key = 2;

		internal const int Bone = 4;

		internal const int Lantern = 8;

		internal const int Quiver = 16;

		private const int LeftQuiver = 32;

		private const int RightQuiver = 64;

		private const int Pouch = 128;

		private const int SingleBack = 256;

		private const int QuiverMask = 112;

		private Player player;

		private ZNetView view;

		private Transform anchor;

		private Transform hips;

		private Transform wispCenter;

		private GameObject key;

		private GameObject bone;

		private GameObject lantern;

		private GameObject pouch;

		private readonly GameObject[] quivers = (GameObject[])(object)new GameObject[3];

		private readonly int[] hashes = new int[3];

		private readonly int[] appliedHashes = new int[3];

		private readonly int[] publishedHashes = new int[3];

		private int appliedFlags = -1;

		private int revision = -1;

		private int quiverRevision = -1;

		private int publishedFlags = -1;

		private int appliedCounts = -1;

		private int publishedCounts = -1;

		private float nextCheck;

		private bool warned;

		internal Transform WispCenter => wispCenter;

		internal bool HasLantern
		{
			get
			{
				if (Object.op_Implicit((Object)(object)lantern))
				{
					return lantern.activeInHierarchy;
				}
				return false;
			}
		}

		private void Awake()
		{
			player = ((Component)this).GetComponent<Player>();
			view = ((Component)this).GetComponent<ZNetView>();
		}

		private void LateUpdate()
		{
			if (!Object.op_Implicit((Object)(object)player) || !Object.op_Implicit((Object)(object)view) || !view.IsValid() || Time.unscaledTime < nextCheck)
			{
				return;
			}
			nextCheck = Time.unscaledTime + 0.15f;
			try
			{
				int num = 0;
				int num2;
				if (view.IsOwner())
				{
					num2 = GetLocalFlags();
					for (int i = 0; i < 3; i++)
					{
						ItemData slotItem = StandaloneInventory.GetSlotItem(player, 9 + i);
						bool flag = (num2 & (16 << i)) != 0 && slotItem != null && Object.op_Implicit((Object)(object)slotItem.m_dropPrefab) && slotItem.m_stack > 0 && StandaloneSlots.IsAllowed(9 + i, slotItem) && StandaloneSlots.IsUnlocked(player, 9 + i);
						hashes[i] = (flag ? StringExtensionMethods.GetStableHashCode(((Object)slotItem.m_dropPrefab).name) : 0);
						num |= (flag ? Mathf.Min(9, slotItem.m_stack) : 0) << i * 4;
						if (publishedHashes[i] != hashes[i])
						{
							view.GetZDO().Set(ArrowKeys[i], hashes[i]);
							publishedHashes[i] = hashes[i];
						}
					}
					if (publishedCounts != num)
					{
						view.GetZDO().Set("hipcharms.arrowCounts.v3", num);
						publishedCounts = num;
					}
					if (publishedFlags != num2)
					{
						view.GetZDO().Set("hipcharms.visuals.v2", num2);
						publishedFlags = num2;
					}
				}
				else
				{
					num2 = view.GetZDO().GetInt("hipcharms.visuals.v2", 0) & 0x1FF;
					num = view.GetZDO().GetInt("hipcharms.arrowCounts.v3", 0) & 0xFFF;
					for (int j = 0; j < 3; j++)
					{
						int num3 = view.GetZDO().GetInt(ArrowKeys[j], 0);
						hashes[j] = (((num2 & (16 << j)) != 0 && Object.op_Implicit((Object)(object)NativeArrowVisual.Resolve(num3))) ? num3 : 0);
					}
				}
				if (!Plugin.Enabled.Value || ((Character)player).IsDead())
				{
					num2 = 0;
				}
				if (!Object.op_Implicit((Object)(object)anchor) && num2 != 0 && !TryCreateAnchor())
				{
					return;
				}
				if (revision != Plugin.VisualRevision || quiverRevision != QuiverVisualConfig.Revision)
				{
					ClearModels();
					revision = Plugin.VisualRevision;
					quiverRevision = QuiverVisualConfig.Revision;
					appliedFlags = -1;
				}
				bool flag2 = num != appliedCounts;
				for (int k = 0; k < 3; k++)
				{
					flag2 |= hashes[k] != appliedHashes[k];
				}
				if (num2 != appliedFlags || flag2)
				{
					bool flag3 = ((num2 ^ appliedFlags) & 0x170) != 0;
					if (flag2 || flag3)
					{
						ClearQuivers();
					}
					appliedFlags = num2;
					appliedCounts = num;
					Array.Copy(hashes, appliedHashes, 3);
					Apply(num2, num);
				}
			}
			catch (Exception ex)
			{
				if (!warned)
				{
					warned = true;
					Plugin.LogWarning("Hip cosmetics could not be built: " + ex);
				}
				appliedFlags = -1;
				nextCheck = Time.unscaledTime + 5f;
			}
		}

		private int GetLocalFlags()
		{
			if (!Plugin.Enabled.Value || ((Character)player).IsDead())
			{
				return 0;
			}
			int num = (QuiverVisualConfig.BackOnly ? 256 : 0);
			for (int i = 0; i < 3; i++)
			{
				if (StandaloneSlots.Prefab(StandaloneInventory.GetSlotItem(player, 27 + i), "HC_Quiver"))
				{
					num |= 16 << i;
				}
			}
			if (!IsBeltWorn(player))
			{
				return num;
			}
			num |= 1;
			if (StandaloneSlots.IsAttachmentActive(player, "CryptKey"))
			{
				num |= 2;
			}
			if (StandaloneSlots.IsAttachmentActive(player, "Wishbone"))
			{
				num |= 4;
			}
			if (StandaloneSlots.IsAttachmentActive(player, "Demister"))
			{
				num |= 8;
			}
			if (StandaloneSlots.Prefab(StandaloneInventory.GetSlotItem(player, 31), "HC_ValuablesPouch"))
			{
				num |= 0x80;
			}
			return num;
		}

		internal static bool IsBeltWorn(Player owner)
		{
			if (!Object.op_Implicit((Object)(object)owner))
			{
				return false;
			}
			foreach (ItemData allItem in ((Humanoid)owner).GetInventory().GetAllItems())
			{
				if (allItem.m_equipped && Object.op_Implicit((Object)(object)allItem.m_dropPrefab))
				{
					string name = ((Object)allItem.m_dropPrefab).name;
					if (name == "BeltStrength" || name == "BeltStrengthWishbone")
					{
						return true;
					}
				}
			}
			return false;
		}

		private bool TryCreateAnchor()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			VisEquipment visEquipment = ((Humanoid)player).GetVisEquipment();
			if (!Object.op_Implicit((Object)(object)visEquipment) || !Object.op_Implicit((Object)(object)visEquipment.m_bodyModel))
			{
				return false;
			}
			Transform[] bones = visEquipment.m_bodyModel.bones;
			foreach (Transform val in bones)
			{
				if (Object.op_Implicit((Object)(object)val) && ((Object)val).name == "Hips")
				{
					hips = val;
					break;
				}
			}
			if (!Object.op_Implicit((Object)(object)hips))
			{
				return false;
			}
			anchor = new GameObject("HipCharms.Attachments").transform;
			anchor.SetParent(hips, false);
			Vector3 lossyScale = hips.lossyScale;
			anchor.localScale = new Vector3(InverseScale(lossyScale.x), InverseScale(lossyScale.y), InverseScale(lossyScale.z));
			anchor.localPosition = Vector3.zero;
			anchor.localRotation = Quaternion.identity;
			return true;
		}

		private static float InverseScale(float value)
		{
			if (!(Mathf.Abs(value) > 0.0001f))
			{
				return 1f;
			}
			return 1f / value;
		}

		private void Apply(int flags, int counts)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_0102: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)anchor))
			{
				return;
			}
			if ((flags & 2) != 0 && !Object.op_Implicit((Object)(object)key))
			{
				key = VisualFactory.Item("CryptKey", "attach/key", anchor, Plugin.KeyHeight.Value * Plugin.CharmScale.Value, Quaternion.identity, Plugin.KeyPosition.Value, Plugin.KeyRotation.Value, blue: false);
			}
			if ((flags & 4) != 0 && !Object.op_Implicit((Object)(object)bone))
			{
				bone = VisualFactory.Item("Wishbone", "model/wishbone", anchor, Plugin.WishboneHeight.Value * Plugin.CharmScale.Value, Quaternion.Euler(90f, 0f, 0f), Plugin.WishbonePosition.Value, Plugin.WishboneRotation.Value, blue: false);
			}
			if ((flags & 8) != 0 && !Object.op_Implicit((Object)(object)lantern))
			{
				lantern = VisualFactory.Item("Lantern", "attach/equiped/default", anchor, Plugin.LanternHeight.Value, Quaternion.identity, Plugin.LanternPosition.Value, Plugin.LanternRotation.Value, blue: true);
				if (Object.op_Implicit((Object)(object)lantern))
				{
					wispCenter = VisualFactory.AddWispCore(lantern.transform, Plugin.LanternHeight.Value);
				}
			}
			if ((flags & 0x80) != 0 && Plugin.ShowPouch.Value && !Object.op_Implicit((Object)(object)pouch))
			{
				pouch = VisualFactory.CoinPouch(anchor, Plugin.PouchPosition.Value);
			}
			if ((flags & 0x100) != 0)
			{
				if ((flags & 0x70) != 0 && !Object.op_Implicit((Object)(object)quivers[0]))
				{
					List<int> list = new List<int>();
					for (int i = 0; i < 3; i++)
					{
						if ((flags & (16 << i)) != 0 && hashes[i] != 0 && ((counts >> i * 4) & 0xF) > 0)
						{
							for (int j = 0; j < Mathf.Min(3, (counts >> i * 4) & 0xF); j++)
							{
								list.Add(hashes[i]);
							}
						}
					}
					quivers[0] = MakeQuiver(0, list.ToArray());
				}
				SetVisible(quivers[0], (flags & 0x70) != 0);
			}
			else
			{
				for (int k = 0; k < 3; k++)
				{
					if ((flags & (16 << k)) != 0 && !Object.op_Implicit((Object)(object)quivers[k]))
					{
						int num = Mathf.Min(9, (counts >> k * 4) & 0xF);
						int[] array = new int[num];
						for (int l = 0; l < num; l++)
						{
							array[l] = hashes[k];
						}
						quivers[k] = MakeQuiver(k, array);
					}
					SetVisible(quivers[k], (flags & (16 << k)) != 0);
				}
			}
			HangingSway.Attach(key);
			HangingSway.Attach(bone);
			HangingSway.Attach(lantern);
			HangingSway.Attach(pouch);
			SetVisible(key, (flags & 2) != 0);
			SetVisible(bone, (flags & 4) != 0);
			SetVisible(lantern, (flags & 8) != 0);
			SetVisible(pouch, (flags & 0x80) != 0 && Plugin.ShowPouch.Value);
			if (((flags & 2) != 0 && !Object.op_Implicit((Object)(object)key)) || ((flags & 4) != 0 && !Object.op_Implicit((Object)(object)bone)) || ((flags & 8) != 0 && !Object.op_Implicit((Object)(object)lantern)) || ((flags & 0x80) != 0 && Plugin.ShowPouch.Value && !Object.op_Implicit((Object)(object)pouch)))
			{
				appliedFlags = -2;
			}
			for (int m = 0; m < 3; m++)
			{
				if ((flags & (16 << m)) != 0 && !Object.op_Implicit((Object)(object)quivers[((flags & 0x100) == 0) ? m : 0]))
				{
					appliedFlags = -2;
				}
			}
		}

		private GameObject MakeQuiver(int index, int[] arrowHashes)
		{
			//IL_0019: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = QuiverVisual.CreateModel(anchor, arrowHashes);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			Vector3 localPosition = QuiverVisualConfig.Position(index);
			localPosition.x *= 0.94f;
			localPosition.z *= 0.9f;
			val.transform.localPosition = localPosition;
			val.transform.localRotation = Quaternion.Euler(QuiverVisualConfig.Rotation(index));
			val.transform.localScale = Vector3.one * QuiverVisualConfig.Scale(index);
			HangingSway.Attach(val, 0.3f);
			return val;
		}

		private static void SetVisible(GameObject model, bool visible)
		{
			if (Object.op_Implicit((Object)(object)model) && model.activeSelf != visible)
			{
				model.SetActive(visible);
			}
		}

		private void ClearQuivers()
		{
			for (int i = 0; i < 3; i++)
			{
				if (Object.op_Implicit((Object)(object)quivers[i]))
				{
					Object.Destroy((Object)(object)quivers[i]);
				}
				quivers[i] = null;
			}
		}

		private void ClearModels()
		{
			if (Object.op_Implicit((Object)(object)key))
			{
				Object.Destroy((Object)(object)key);
			}
			if (Object.op_Implicit((Object)(object)bone))
			{
				Object.Destroy((Object)(object)bone);
			}
			if (Object.op_Implicit((Object)(object)lantern))
			{
				Object.Destroy((Object)(object)lantern);
			}
			if (Object.op_Implicit((Object)(object)pouch))
			{
				Object.Destroy((Object)(object)pouch);
			}
			ClearQuivers();
			key = (bone = (lantern = (pouch = null)));
			wispCenter = null;
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)anchor))
			{
				Object.Destroy((Object)(object)((Component)anchor).gameObject);
			}
		}
	}
	internal static class CraftedGear
	{
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class RegisterItemsPatch
		{
			[HarmonyPostfix]
			private static void Postfix(ObjectDB __instance)
			{
				Register(__instance);
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
		private static class CopyItemsPatch
		{
			[HarmonyPostfix]
			private static void Postfix(ObjectDB __instance)
			{
				Register(__instance);
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private static class NetworkItemsPatch
		{
			[HarmonyPostfix]
			private static void Postfix(ZNetScene __instance)
			{
				Register(ObjectDB.instance);
				RegisterNetwork(__instance);
			}
		}

		[HarmonyPatch(typeof(Player), "AddKnownItem")]
		private static class BeltDiscoveryPatch
		{
			[HarmonyPrefix]
			private static void Prefix(Player __instance, ItemData item)
			{
				if (IsBelt(item))
				{
					__instance.m_customData["HipCharms.StrengthBeltDiscovered.v1"] = "1";
				}
			}

			[HarmonyPostfix]
			private static void Postfix(Player __instance, ItemData item)
			{
				if (IsBelt(item))
				{
					DiscoverUpgrade(__instance, notify: true);
				}
			}
		}

		[HarmonyPatch(typeof(Player), "Load")]
		private static class RestoreDiscoveryPatch
		{
			[HarmonyPostfix]
			private static void Postfix(Player __instance)
			{
				DiscoverUpgrade(__instance, notify: false);
			}
		}

		[HarmonyPatch(typeof(Player), "HaveRequirements", new Type[]
		{
			typeof(Recipe),
			typeof(bool),
			typeof(int),
			typeof(int)
		})]
		private static class RecipeGatePatch
		{
			[HarmonyPrefix]
			private static bool Prefix(Player __instance, Recipe recipe, ref bool __result)
			{
				if (RecipeAllowed(__instance, recipe))
				{
					return true;
				}
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(Player), "AddKnownRecipe")]
		private static class MaterialDiscoveryGatePatch
		{
			private static bool Prefix(Player __instance, Recipe recipe)
			{
				return RecipeAllowed(__instance, recipe);
			}
		}

		[HarmonyPatch(typeof(Player), "GetAvailableRecipes")]
		private static class RecipeListPatch
		{
			[HarmonyPrefix]
			private static void Prefix(Player __instance)
			{
				DiscoverUpgrade(__instance, notify: false);
			}

			[HarmonyPostfix]
			private static void Postfix(Player __instance, ref List<Recipe> available)
			{
				available.RemoveAll((Recipe r) => !RecipeAllowed(__instance, r));
			}
		}

		internal const string QuiverPrefab = "HC_Quiver";

		internal const string BeltUpgradePrefab = "HC_BeltCharms";

		internal const string PouchPrefab = "HC_ValuablesPouch";

		private const string BeltDiscoveryKey = "HipCharms.StrengthBeltDiscovered.v1";

		private static readonly string[] Names = new string[3] { "HC_Quiver", "HC_BeltCharms", "HC_ValuablesPouch" };

		private static readonly string[] Titles = new string[3] { "Leather quiver", "Hip charms belt upgrade", "Valuables pouch" };

		private static readonly string[] Descriptions = new string[3] { "Equip in a quiver socket to hold one arrow type. Craft up to three for your back and hips.", "Fit to a worn strength belt to gain one inventory row and hooks for a swamp key, wishbone and wisp lantern. The belt keeps its carry-weight bonus.", "Fit to a worn strength belt for 12 valuables cells and a separate coin stack without the normal stack cap. Contents are weightless by default; withdraw coins in normal stacks." };

		private static readonly Dictionary<string, GameObject> Prefabs = new Dictionary<string, GameObject>();

		private static readonly List<Object> Icons = new List<Object>();

		private static readonly ConfigEntry<string>[] Costs = new ConfigEntry<string>[3];

		private static ConfigEntry<int> stationLevel;

		private static GameObject prefabRoot;

		private static Sprite lanternIcon;

		private static bool lanternIconAttempted;

		private static Color lanternIconColor;

		private static float lanternIconGlow;

		private static float lanternIconHeight;

		private static bool registering;

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

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

		private static readonly FieldInfo KnownRecipes = AccessTools.Field(typeof(Player), "m_knownRecipes");

		private static readonly FieldInfo NamedPrefabs = AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs");

		internal static void Initialize(ConfigFile config)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			string[] array = new string[3] { "LeatherScraps:8,DeerHide:4,Wood:2", "DeerHide:6,Bronze:2,Resin:4", "LeatherScraps:6,DeerHide:2,Resin:2" };
			for (int i = 0; i < Names.Length; i++)
			{
				Costs[i] = config.Bind<string>("Crafting", Titles[i] + " materials", array[i], "Comma-separated native item prefab:amount costs. Amounts 1–1000; invalid rules keep the previous valid recipe. Changes apply live. The belt upgrade always requires first discovering a strength belt.");
			}
			stationLevel = config.Bind<int>("Crafting", "Workbench level", 1, new ConfigDescription("Required workbench level for the quiver, belt upgrade and pouch.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5), Array.Empty<object>()));
			config.SettingChanged += delegate(object _, SettingChangedEventArgs args)
			{
				if (args.ChangedSetting.Definition.Section == "Crafting" && Object.op_Implicit((Object)(object)ObjectDB.instance))
				{
					RegisterRecipes(ObjectDB.instance);
				}
			};
		}

		internal static Sprite GetIcon(string prefabName)
		{
			if (!Prefabs.TryGetValue(prefabName, out var value) || !Object.op_Implicit((Object)(object)value))
			{
				return null;
			}
			return value.GetComponent<ItemDrop>().m_itemData.GetIcon();
		}

		internal static Sprite GetLanternIcon()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Invalid comparison between Unknown and I4
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			//IL_0119: 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)
			GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab("Demister") : null);
			if (lanternIconAttempted && lanternIconColor == Plugin.LanternColor.Value && lanternIconGlow == Plugin.LanternEmission.Value && lanternIconHeight == Plugin.LanternHeight.Value)
			{
				if (!Object.op_Implicit((Object)(object)lanternIcon))
				{
					if (!Object.op_Implicit((Object)(object)val))
					{
						return null;
					}
					return val.GetComponent<ItemDrop>().m_itemData.GetIcon();
				}
				return lanternIcon;
			}
			if (!Object.op_Implicit((Object)(object)ObjectDB.instance) || (int)SystemInfo.graphicsDeviceType == 4)
			{
				if (!Object.op_Implicit((Object)(object)val))
				{
					return null;
				}
				return val.GetComponent<ItemDrop>().m_itemData.GetIcon();
			}
			lanternIconAttempted = true;
			lanternIconColor = Plugin.LanternColor.Value;
			lanternIconGlow = Plugin.LanternEmission.Value;
			lanternIconHeight = Plugin.LanternHeight.Value;
			GameObject val2 = new GameObject("HipCharms lantern icon source");
			val2.SetActive(false);
			try
			{
				GameObject val3 = VisualFactory.Item("Lantern", "attach/equiped/default", val2.transform, Plugin.LanternHeight.Value, Quaternion.identity, new Vector3(0f, 0.27f, 0.13f), Vector3.zero, blue: true);
				if (!Object.op_Implicit((Object)(object)val3))
				{
					return Object.op_Implicit((Object)(object)val) ? val.GetComponent<ItemDrop>().m_itemData.GetIcon() : null;
				}
				VisualFactory.AddWispCore(val3.transform, Plugin.LanternHeight.Value);
				List<Object> owned = new List<Object>();
				Sprite val4 = CraftingModels.RenderIcon(val3, owned);
				if (Object.op_Implicit((Object)(object)val4))
				{
					if (Object.op_Implicit((Object)(object)lanternIcon))
					{
						Object.Destroy((Object)(object)lanternIcon.texture);
						Object.Destroy((Object)(object)lanternIcon);
					}
					lanternIcon = val4;
				}
				return Object.op_Implicit((Object)(object)lanternIcon) ? lanternIcon : (Object.op_Implicit((Object)(object)val) ? val.GetComponent<ItemDrop>().m_itemData.GetIcon() : null);
			}
			finally
			{
				Object.Destroy((Object)(object)val2);
			}
		}

		private static void Register(ObjectDB db)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)db) || registering)
			{
				return;
			}
			GameObject val = ((IEnumerable<GameObject>)db.m_items).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => Object.op_Implicit((Object)(object)p) && ((Object)p).name == "LeatherScraps"));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			registering = true;
			try
			{
				if (!Object.op_Implicit((Object)(object)prefabRoot))
				{
					prefabRoot = new GameObject("HipCharms registered item prefabs");
					prefabRoot.SetActive(false);
					Object.DontDestroyOnLoad((Object)(object)prefabRoot);
				}
				for (int num = 0; num < Names.Length; num++)
				{
					if (!Prefabs.TryGetValue(Names[num], out var prefab) || !Object.op_Implicit((Object)(object)prefab))
					{
						prefab = MakeItem(val, num);
						Prefabs[Names[num]] = prefab;
					}
					if (!db.m_items.Any((GameObject p) => Object.op_Implicit((Object)(object)p) && ((Object)p).name == ((Object)prefab).name))
					{
						db.m_items.Add(prefab);
					}
				}
				UpdateRegisters.Invoke(db, null);
				ValidateRegistration(db);
				RegisterRecipes(db);
				RegisterNetwork(ZNetScene.instance);
			}
			finally
			{
				registering = false;
			}
		}

		private static GameObject MakeItem(GameObject source, int kind)
		{
			//IL_0025: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_014b: 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_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: 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_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(source, prefabRoot.transform, false);
			((Object)val).name = Names[kind];
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one;
			foreach (Transform item in val.transform)
			{
				((Component)item).gameObject.SetActive(false);
			}
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].enabled = false;
			}
			ItemDrop component = val.GetComponent<ItemDrop>();
			Sprite icon = source.GetComponent<ItemDrop>().m_itemData.GetIcon();
			ItemData val2 = new ItemData();
			val2.m_dropPrefab = val;
			val2.m_stack = 1;
			val2.m_quality = 1;
			val2.m_variant = 0;
			SharedData val3 = new SharedData();
			val3.m_name = Titles[kind];
			val3.m_description = Descriptions[kind];
			val3.m_itemType = (ItemType)1;
			val3.m_icons = (Sprite[])(object)new Sprite[1] { icon };
			val3.m_maxStackSize = 1;
			val3.m_maxQuality = 1;
			val3.m_weight = 1f;
			val3.m_autoStack = false;
			val3.m_useDurability = false;
			val3.m_questItem = false;
			val3.m_value = 0;
			val3.m_dlc = "";
			val3.m_teleportable = true;
			val2.m_shared = val3;
			component.m_itemData = val2;
			component.m_autoPickup = true;
			component.m_pieceEnableObj = null;
			component.m_pieceDisabledObj = null;
			GameObject val4 = (GameObject)(kind switch
			{
				0 => QuiverVisual.CreateModel(val.transform, Array.Empty<int>(), includeHarness: false), 
				2 => VisualFactory.CoinPouch(val.transform, new Vector3(0f, 0.27f, 0.13f)), 
				_ => CraftingModels.BeltUpgrade(val.transform), 
			});
			if (Object.op_Implicit((Object)(object)val4))
			{
				val4.transform.localPosition = Vector3.zero;
				val4.transform.localRotation = Quaternion.identity;
				Bounds val5 = CraftingModels.LocalBounds(val4.transform);
				val4.transform.localPosition = -((Bounds)(ref val5)).center;
				val.AddComponent<BoxCollider>().size = Vector3.Max(((Bounds)(ref val5)).size, Vector3.one * 0.08f);
				Sprite val6 = CraftingModels.RenderIcon(val4, Icons);
				if (Object.op_Implicit((Object)(object)val6))
				{
					component.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { val6 };
				}
			}
			else
			{
				val.AddComponent<BoxCollider>().size = Vector3.one * 0.2f;
			}
			val.SetActive(true);
			return val;
		}

		private static void ValidateRegistration(ObjectDB db)
		{
			string[] names = Names;
			foreach (string text in names)
			{
				GameObject val = Prefabs[text];
				ItemData itemData = val.GetComponent<ItemDrop>().m_itemData;
				if ((Object)(object)db.GetItemPrefab(text) != (Object)(object)val || (Object)(object)db.GetItemPrefab(itemData.m_shared) != (Object)(object)val || (Object)(object)itemData.m_dropPrefab != (Object)(object)val)
				{
					throw new InvalidOperationException("Hip Charms item identity did not register: " + text);
				}
				if (itemData.m_stack != 1 || itemData.m_quality != 1 || itemData.m_shared.m_maxStackSize != 1 || !Object.op_Implicit((Object)(object)itemData.GetIcon()))
				{
					throw new InvalidOperationException("Hip Charms item data is incomplete: " + text);
				}
			}
		}

		private static void RegisterNetwork(ZNetScene scene)
		{
			if (!Object.op_Implicit((Object)(object)scene))
			{
				return;
			}
			Dictionary<int, GameObject> dictionary = (Dictionary<int, GameObject>)NamedPrefabs.GetValue(scene);
			foreach (GameObject value in Prefabs.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					if (!scene.m_prefabs.Contains(value))
					{
						scene.m_prefabs.Add(value);
					}
					int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)value).name);
					if (!dictionary.ContainsKey(stableHashCode))
					{
						dictionary.Add(stableHashCode, value);
					}
				}
			}
		}

		private static void RegisterRecipes(ObjectDB db)
		{
			//IL_015c: 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_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			CraftingStation val = (from r in db.m_recipes
				where Object.op_Implicit((Object)(object)r) && Object.op_Implicit((Object)(object)r.m_craftingStation)
				select r.m_craftingStation).FirstOrDefault((Func<CraftingStation, bool>)((CraftingStation s) => s.m_name == "$piece_workbench"));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			for (int num = 0; num < Names.Length; num++)
			{
				if (!Prefabs.TryGetValue(Names[num], out var value) || !Object.op_Implicit((Object)(object)value))
				{
					continue;
				}
				List<Requirement> list = new List<Requirement>();
				bool flag = true;
				HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
				string[] array = Costs[num].Value.Split(',');
				for (int num2 = 0; num2 < array.Length; num2++)
				{
					string[] array2 = array[num2].Trim().Split(':');
					if (array2.Length != 2 || !int.TryParse(array2[1], out var result) || result < 1 || result > 1000 || !hashSet.Add(array2[0].Trim()))
					{
						flag = false;
						break;
					}
					GameObject itemPrefab = db.GetItemPrefab(array2[0].Trim());
					if (!Object.op_Implicit((Object)(object)itemPrefab) || !Object.op_Implicit((Object)(object)itemPrefab.GetComponent<ItemDrop>()))
					{
						flag = false;
						break;
					}
					list.Add(new Requirement
					{
						m_resItem = itemPrefab.GetComponent<ItemDrop>(),
						m_amount = result,
						m_amountPerLevel = 0
					});
				}
				if (!flag || list.Count == 0)
				{
					Plugin.LogWarning("Invalid crafting costs for " + Titles[num] + "; the last valid recipe is retained.");
					continue;
				}
				string name = "Recipe_" + Names[num];
				Recipe val2 = ((IEnumerable<Recipe>)db.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe r) => Object.op_Implicit((Object)(object)r) && ((Object)r).name == name));
				if (!Object.op_Implicit((Object)(object)val2))
				{
					val2 = ScriptableObject.CreateInstance<Recipe>();
					((Object)val2).name = name;
					db.m_recipes.Add(val2);
				}
				val2.m_item = value.GetComponent<ItemDrop>();
				val2.m_amount = 1;
				val2.m_enabled = true;
				val2.m_minStationLevel = stationLevel.Value;
				val2.m_craftingStation = val;
				val2.m_resources = list.ToArray();
			}
		}

		private static bool IsBelt(ItemData item)
		{
			if (Object.op_Implicit((Object)(object)item?.m_dropPrefab))
			{
				if (!(((Object)item.m_dropPrefab).name == "BeltStrength"))
				{
					return ((Object)item.m_dropPrefab).name == "BeltStrengthWishbone";
				}
				return true;
			}
			return false;
		}

		internal static bool HasDiscoveredBelt(Player player)
		{
			if (!Object.op_Implicit((Object)(object)player))
			{
				return false;
			}
			if (player.m_customData.ContainsKey("HipCharms.StrengthBeltDiscovered.v1"))
			{
				return true;
			}
			string[] array = new string[2] { "BeltStrength", "BeltStrengthWishbone" };
			foreach (string text in array)
			{
				GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab(text) : null);
				if (Object.op_Implicit((Object)(object)val) && player.IsMaterialKnown(val.GetComponent<ItemDrop>().m_itemData.m_shared.m_name))
				{
					player.m_customData["HipCharms.StrengthBeltDiscovered.v1"] = "1";
					return true;
				}
			}
			if (((Humanoid)player).GetInventory().GetAllItems().Any(IsBelt))
			{
				player.m_customData["HipCharms.StrengthBeltDiscovered.v1"] = "1";
				return true;
			}
			return false;
		}

		private static bool IsOurRecipe(Recipe recipe)
		{
			if (Object.op_Implicit((Object)(object)recipe) && Object.op_Implicit((Object)(object)recipe.m_item))
			{
				return Names.Contains(((Object)recipe.m_item).name);
			}
			return false;
		}

		private static bool RecipeAllowed(Player player, Recipe recipe)
		{
			if (IsOurRecipe(recipe))
			{
				if (Object.op_Implicit((Object)(object)player) && Plugin.Enabled.Value && recipe.m_resources.All((Requirement r) => Object.op_Implicit((Object)(object)r.m_resItem) && player.IsMaterialKnown(r.m_resItem.m_itemData.m_shared.m_name)))
				{
					if (!(((Object)recipe.m_item).name != "HC_BeltCharms"))
					{
						return HasDiscoveredBelt(player);
					}
					return true;
				}
				return false;
			}
			return true;
		}

		internal static bool HasUnlockedRecipe(Player player, string prefab)
		{
			if (!Object.op_Implicit((Object)(object)player) || !Object.op_Implicit((Object)(object)ObjectDB.instance))
			{
				return false;
			}
			Recipe val = ((IEnumerable<Recipe>)ObjectDB.instance.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe r) => Object.op_Implicit((Object)(object)r) && Object.op_Implicit((Object)(object)r.m_item) && ((Object)r.m_item).name == prefab));
			if (Object.op_Implicit((Object)(object)val) && RecipeAllowed(player, val))
			{
				return player.IsRecipeKnown(val.m_item.m_itemData.m_shared.m_name);
			}
			return false;
		}

		internal static bool ShowSlot(Player player, int slot)
		{
			if (StandaloneInventory.GetSlotItem(player, slot) != null)
			{
				return true;
			}
			if ((slot >= 6 && slot <= 8) || slot == 30)
			{
				return HasUnlockedRecipe(player, "HC_BeltCharms");
			}
			if ((slot >= 9 && slot <= 11) || (slot >= 27 && slot <= 29))
			{
				return HasUnlockedRecipe(player, "HC_Quiver");
			}
			if ((slot >= 15 && slot <= 26) || slot == 31 || slot == 32)
			{
				return HasUnlockedRecipe(player, "HC_ValuablesPouch");
			}
			return true;
		}

		private static void DiscoverUpgrade(Player player, bool notify)
		{
			if (!Plugin.Enabled.Value || !HasDiscoveredBelt(player) || !Object.op_Implicit((Object)(object)ObjectDB.instance))
			{
				return;
			}
			Recipe val = ((IEnumerable<Recipe>)ObjectDB.instance.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe r) => Object.op_Implicit((Object)(object)r) && Object.op_Implicit((Object)(object)r.m_item) && ((Object)r.m_item).name == "HC_BeltCharms"));
			if (Object.op_Implicit((Object)(object)val) && RecipeAllowed(player, val) && !player.IsRecipeKnown(val.m_item.m_itemData.m_shared.m_name))
			{
				if (notify && Object.op_Implicit((Object)(object)MessageHud.instance))
				{
					AddKnownRecipe.Invoke(player, new object[1] { val });
				}
				else
				{
					((HashSet<string>)KnownRecipes.GetValue(player)).Add(val.m_item.m_itemData.m_shared.m_name);
				}
			}
		}
	}
	internal static class CraftingModels
	{
		internal static GameObject BeltUpgrade(Transform parent)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_008a: 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_0107: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("HipCharms belt charm hooks");
			val.transform.SetParent(parent, false);
			VisualResources visualResources = val.AddComponent<VisualResources>();
			Material val2 = new Material(((Renderer)ObjectDB.instance.GetItemPrefab("LeatherScraps").GetComponentInChildren<MeshRenderer>(true)).sharedMaterial);
			visualResources.Materials.Add(val2);
			if (val2.HasProperty("_Color"))
			{
				val2.SetColor("_Color", new Color(0.32f, 0.22f, 0.14f));
			}
			if (val2.HasProperty("_EmissionColor"))
			{
				val2.SetColor("_EmissionColor", Color.black);
			}
			Material val3 = new Material(val2);
			visualResources.Materials.Add(val3);
			if (val3.HasProperty("_Color"))
			{
				val3.SetColor("_Color", new Color(0.65f, 0.43f, 0.18f));
			}
			if (val3.HasProperty("_Metallic"))
			{
				val3.SetFloat("_Metallic", 0.7f);
			}
			Block(val.transform, visualResources, val2, new Vector3(0f, 0.03f, 0f), new Vector3(0.32f, 0.08f, 0.024f));
			for (int i = -1; i <= 1; i++)
			{
				Block(val.transform, visualResources, val2, new Vector3((float)i * 0.105f, -0.01f, 0.015f), new Vector3(0.027f, 0.1f, 0.012f));
				GameObject val4 = new GameObject("Bronze charm ring");
				val4.transform.SetParent(val.transform, false);
				val4.transform.localPosition = new Vector3((float)i * 0.105f, -0.063f, 0.02f);
				Mesh val5 = Ring();
				visualResources.Meshes.Add(val5);
				val4.AddComponent<MeshFilter>().sharedMesh = val5;
				((Renderer)val4.AddComponent<MeshRenderer>()).sharedMaterial = val3;
			}
			return val;
		}

		private static void Block(Transform parent, VisualResources resources, Material material, Vector3 position, Vector3 scale)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)obj).name = "Leather harness";
			Object.Destroy((Object)(object)obj.GetComponent<Collider>());
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = position;
			obj.transform.localScale = scale;
			((Renderer)obj.GetComponent<MeshRenderer>()).sharedMaterial = material;
		}

		private static Mesh Ring()
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<int> list2 = new List<int>();
			Vector3 val = default(Vector3);
			for (int i = 0; i <= 16; i++)
			{
				float num = MathF.PI * 2f * (float)i / 16f;
				((Vector3)(ref val))..ctor(Mathf.Cos(num), Mathf.Sin(num), 0f);
				for (int j = 0; j <= 6; j++)
				{
					float num2 = MathF.PI * 2f * (float)j / 6f;
					list.Add(val * (0.022f + 0.004f * Mathf.Cos(num2)) + Vector3.forward * (0.004f * Mathf.Sin(num2)));
					if (i != 16 && j != 6)
					{
						int num3 = i * 7 + j;
						list2.AddRange(new int[6]
						{
							num3,
							num3 + 6 + 1,
							num3 + 1,
							num3 + 1,
							num3 + 6 + 1,
							num3 + 6 + 2
						});
					}
				}
			}
			Mesh val2 = new Mesh
			{
				name = "Belt upgrade bronze ring"
			};
			val2.SetVertices(list);
			val2.SetTriangles(list2, 0);
			val2.RecalculateNormals();
			val2.RecalculateBounds();
			return val2;
		}

		internal static Bounds LocalBounds(Transform root)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_003b: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			Bounds result = default(Bounds);
			bool flag = true;
			MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val.sharedMesh))
				{
					continue;
				}
				Bounds bounds = val.sharedMesh.bounds;
				Matrix4x4 val2 = root.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val3 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(new Vector3(((j & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((j & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((j & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z));
					if (flag)
					{
						((Bounds)(ref result))..ctor(val3, Vector3.zero);
						flag = false;
					}
					else
					{
						((Bounds)(ref result)).Encapsulate(val3);
					}
				}
			}
			return result;
		}

		internal static Sprite RenderIcon(GameObject model, List<Object> owned)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Expected O, but got Unknown
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00ab: 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_0115: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//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_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: 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_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: 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_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)model) || owned == null)
			{
				return null;
			}
			Texture2D val = null;
			try
			{
				List<ThumbnailRaster.Face> list = new List<ThumbnailRaster.Face>();
				Matrix4x4 val2 = Matrix4x4.Rotate(Quaternion.Euler(10f, -20f, 0f));
				MeshFilter[] componentsInChildren = model.GetComponentsInChildren<MeshFilter>(true);
				foreach (MeshFilter val3 in componentsInChildren)
				{
					MeshRenderer component = ((Component)val3).GetComponent<MeshRenderer>();
					Mesh sharedMesh = val3.sharedMesh;
					if (!Object.op_Implicit((Object)(object)component) || !((Renderer)component).enabled || !Object.op_Implicit((Object)(object)sharedMesh) || !sharedMesh.isReadable)
					{
						continue;
					}
					Matrix4x4 val4 = val2 * model.transform.worldToLocalMatrix * ((Component)val3).transform.localToWorldMatrix;
					Vector3[] vertices = sharedMesh.vertices;
					Material[] sharedMaterials = ((Renderer)component).sharedMaterials;
					for (int j = 0; j < sharedMesh.subMeshCount; j++)
					{
						if ((int)sharedMesh.GetTopology(j) != 0)
						{
							continue;
						}
						Material val5 = ((sharedMaterials.Length == 0) ? null : sharedMaterials[Mathf.Min(j, sharedMaterials.Length - 1)]);
						Color val6 = (Color)((Object.op_Implicit((Object)(object)val5) && val5.HasProperty("_Color")) ? val5.GetColor("_Color") : new Color(0.55f, 0.4f, 0.24f));
						Color val7 = ((Object.op_Implicit((Object)(object)val5) && val5.HasProperty("_EmissionColor") && val5.IsKeywordEnabled("_EMISSION")) ? val5.GetColor("_EmissionColor") : Color.black);
						int[] triangles = sharedMesh.GetTriangles(j);
						for (int k = 0; k + 2 < triangles.Length; k += 3)
						{
							Vector3 val8 = ((Matrix4x4)(ref val4)).MultiplyPoint3x4(vertices[triangles[k]]);
							Vector3 val9 = ((Matrix4x4)(ref val4)).MultiplyPoint3x4(vertices[triangles[k + 1]]);
							Vector3 val10 = ((Matrix4x4)(ref val4)).MultiplyPoint3x4(vertices[triangles[k + 2]]);
							Vector3 val11 = Vector3.Cross(val9 - val8, val10 - val8);
							Vector3 val12 = ((Vector3)(ref val11)).normalized;
							if (val12.z > 0f)
							{
								val12 = -val12;
							}
							Vector3 val13 = val12;
							val11 = new Vector3(-0.45f, 0.65f, -0.62f);
							float num = 0.62f + 0.62f * Mathf.Max(0f, Vector3.Dot(val13, ((Vector3)(ref val11)).normalized));
							Color val14 = val6 * num + val7 * 0.2f;
							list.Add(new ThumbnailRaster.Face(Point(val8), Point(val9), Point(val10), Channel(val14.r), Channel(val14.g), Channel(val14.b)));
						}
					}
				}
				byte[] array = ThumbnailRaster.Render(list, 128);
				if (array == null)
				{
					return null;
				}
				val = new Texture2D(128, 128, (TextureFormat)4, false)
				{
					name = ((Object)model).name + " inventory icon",
					filterMode = (FilterMode)1,
					wrapMode = (TextureWrapMode)1
				};
				val.LoadRawTextureData(array);
				val.Apply(false, true);
				Sprite val15 = Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
				((Object)val15).name = ((Object)model).name + " inventory icon";
				owned.Add((Object)(object)val);
				owned.Add((Object)(object)val15);
				val = null;
				return val15;
			}
			catch (Exception ex)
			{
				Plugin.LogWarning("Could not build crafted item icon: " + ex.Message);
				return null;
			}
			finally
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		private static ThumbnailRaster.Point Point(Vector3 value)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			return new ThumbnailRaster.Point(value.x, value.y, value.z);
		}

		private static byte Channel(float value)
		{
			return (byte)Mathf.RoundToInt(Mathf.Clamp01(value) * 255f);
		}
	}
	internal sealed class EquipmentCellView
	{
		internal readonly InventoryElement Element;

		internal readonly int Slot;

		private readonly Color foodEitr;

		private readonly Color foodHealth;

		private readonly Color foodStamina;

		internal EquipmentCellView(GameObject template, Transform parent, InventoryGrid nativeGrid, int slot, Action<int, Modifier> selected, Action<int> use, Action<int, bool> hover, Action clearDrag)
		{
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Expected O, but got Unknown
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			Slot = slot;
			GameObject val = Object.Instantiate<GameObject>(template, parent, false);
			((Object)val).name = "HipCharms.Slot." + slot;
			Element = val.GetComponent<InventoryElement>();
			if (!Object.op_Implicit((Object)(object)Element) || !Object.op_Implicit((Object)(object)Element.m_button) || !Object.op_Implicit((Object)(object)Element.m_icon) || !Object.op_Implicit((Object)(object)Element.m_amount) || !Object.op_Implicit((Object)(object)Element.m_quality) || !Object.op_Implicit((Object)(object)Element.m_equiped) || !Object.op_Implicit((Object)(object)Element.m_queued) || !Object.op_Implicit((Object)(object)Element.m_selected) || !Object.op_Implicit((Object)(object)Element.m_noteleport) || !Object.op_Implicit((Object)(object)Element.m_food) || !Object.op_Implicit((Object)(object)Element.m_tooltip) || !Object.op_Implicit((Object)(object)Element.m_durability) || !Object.op_Implicit((Object)(object)Element.m_dropFocus))
			{
				throw new InvalidOperationException("The native inventory cell is missing a required UI reference.");
			}
			UIInputHandler componentInChildren = val.GetComponentInChildren<UIInputHandler>(true);
			UIDragHandler componentInChildren2 = val.GetComponentInChildren<UIDragHandler>(true);
			if (!Object.op_Implicit((Object)(object)componentInChildren) || !Object.op_Implicit((Object)(object)componentInChildren2))
			{
				throw new InvalidOperationException("The native inventory cell is missing its input handlers.");
			}
			componentInChildren.m_onLeftDown = delegate
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				if (!ZInput.IsTouchActive())
				{
					selected(slot, Modifier());
				}
			};
			componentInChildren.m_onLeftClick = delegate
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				if (ZInput.IsTouchActive())
				{
					selected(slot, Modifier());
				}
			};
			componentInChildren.m_onLeftUp = null;
			componentInChildren.m_onRightDown = delegate
			{
				use(slot);
			};
			componentInChildren.m_onRightClick = (componentInChildren.m_onRightUp = null);
			componentInChildren.m_onMiddleClick = (componentInChildren.m_onMiddleDown = (componentInChildren.m_onMiddleUp = null));
			componentInChildren.m_onPointerEnter = delegate
			{
				hover(slot, arg2: true);
			};
			componentInChildren.m_onPointerExit = delegate
			{
				hover(slot, arg2: false);
			};
			componentInChildren2.m_onBeginDrag = delegate
			{
				if (ZInput.IsTouchActive())
				{
					selected(slot, (Modifier)0);
				}
			};
			componentInChildren2.m_onReleasedOn = delegate
			{
				if (ZInput.IsTouchActive())
				{
					selected(slot, (Modifier)0);
				}
			};
			componentInChildren2.m_onEndDrag = delegate
			{
				if (ZInput.IsTouchActive())
				{
					clearDrag();
				}
			};
			componentInChildren2.m_onDrag = null;
			Element.m_button.onClick = new ButtonClickedEvent();
			Button button = Element.m_button;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)button).navigation = navigation;
			Transform val2 = val.transform.Find("binding");
			if (Object.op_Implicit((Object)(object)val2))
			{
				((Component)val2).gameObject.SetActive(false);
			}
			Element.m_icon.overrideSprite = null;
			((Graphic)Element.m_icon).material = null;
			Element.m_icon.sprite = null;
			((Behaviour)Element.m_icon).enabled = false;
			foodEitr = (Color)AccessTools.Field(typeof(InventoryGrid), "m_foodEitrColor").GetValue(nativeGrid);
			foodHealth = (Color)AccessTools.Field(typeof(InventoryGrid), "m_foodHealthColor").GetValue(nativeGrid);
			foodStamina = (Color)AccessTools.Field(typeof(InventoryGrid), "m_foodStaminaColor").GetValue(nativeGrid);
			val.SetActive(true);
		}

		private static Modifier Modifier()
		{
			if (!Input.GetKey((KeyCode)304) && !Input.GetKey((KeyCode)303))
			{
				if (!Input.GetKey((KeyCode)306) && !Input.GetKey((KeyCode)305))
				{
					return (Modifier)0;
				}
				return (Modifier)2;
			}
			return (Modifier)1;
		}

		internal void Refresh(Player player, ItemData dragged, bool hovered, RectTransform tooltipAnchor)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0026: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Invalid comparison between Unknown and I4
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			Vector2i slotPosition = StandaloneInventory.GetSlotPosition(player, Slot);
			if (Element.Position != slotPosition)
			{
				Element.Initialize(slotPosition.x, slotPosition.y);
			}
			ItemData slotItem = StandaloneInventory.GetSlotItem(player, Slot);
			bool flag = slotItem?.m_shared != null;
			Element.m_used = flag;
			Element.m_canBeDroppedOn = false;
			Element.m_selected.SetActive(false);
			((Graphic)Element.m_dropFocus).color = Color.clear;
			((Behaviour)Element.m_icon).enabled = flag;
			((Component)Element.m_icon).gameObject.SetActive(true);
			((Behaviour)Element.m_amount).enabled = flag && slotItem.m_shared.m_maxStackSize > 1;
			((Behaviour)Element.m_quality).enabled = flag && slotItem.m_shared.m_maxQuality > 1;
			((Behaviour)Element.m_equiped).enabled = flag && slotItem.m_equipped;
			((Behaviour)Element.m_queued).enabled = flag && player.IsEquipActionQueued(slotItem);
			((Behaviour)Element.m_noteleport).enabled = flag && !slotItem.m_shared.m_teleportable && Object.op_Implicit((Object)(object)ZoneSystem.instance) && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)35);
			bool flag2 = flag && slotItem.m_shared.m_useDurability && slotItem.m_durability < slotItem.GetMaxDurability();
			((Component)Element.m_durability).gameObject.SetActive(flag2);
			((Behaviour)Element.m_food).enabled = flag && (int)slotItem.m_shared.m_itemType == 2 && (slotItem.m_shared.m_food > 0f || slotItem.m_shared.m_foodStamina > 0f || slotItem.m_shared.m_foodEitr > 0f);
			if (!flag)
			{
				Element.m_icon.sprite = null;
				Element.m_tooltip.m_topic = (Element.m_tooltip.m_text = "");
				return;
			}
			Element.m_icon.overrideSprite = null;
			Element.m_icon.sprite = slotItem.GetIcon();
			((Graphic)Element.m_icon).color = ((slotItem == dragged) ? Color.grey : Color.white);
			Element.m_amount.text = ((Slot != 32) ? (slotItem.m_stack + "/" + slotItem.m_shared.m_maxStackSize) : ((slotItem.m_stack >= 1000000000) ? (((double)slotItem.m_stack / 1000000000.0).ToString("0.#") + "B") : ((slotItem.m_stack >= 1000000) ? (((double)slotItem.m_stack / 1000000.0).ToString("0.#") + "M") : ((slotItem.m_stack >= 10000) ? (((double)slotItem.m_stack / 1000.0).ToString("0.#") + "K") : slotItem.m_stack.ToString()))));
			Element.m_quality.text = slotItem.m_quality.ToString();
			if (flag2)
			{
				Element.m_durability.SetValue((slotItem.m_durability <= 0f) ? 1f : slotItem.GetDurabilityPercentage());
				if (slotItem.m_durability <= 0f)
				{
					Element.m_durability.SetColor(Color.red);
				}
				else
				{
					Element.m_durability.ResetColor();
				}
			}
			if (((Behaviour)Element.m_food).enabled)
			{
				SharedData shared = slotItem.m_shared;
				((Graphic)Element.m_food).color = ((shared.m_food < shared.m_foodEitr / 2f && shared.m_foodStamina < shared.m_foodEitr / 2f) ? foodEitr : ((shared.m_foodStamina < shared.m_food / 2f) ? foodHealth : ((shared.m_food < shared.m_foodStamina / 2f) ? foodStamina : Color.white)));
			}
			if (hovered)
			{
				Element.m_tooltip.Set(slotItem.m_shared.m_name, slotItem.GetTooltip(-1), tooltipAnchor, Vector2.zero);
			}
		}
	}
	public sealed class EquipmentPanel : MonoBehaviour
	{
		[HarmonyPatch(typeof(InventoryGui), "Awake")]
		private static class CreatePanelPatch
		{
			[HarmonyPriority(800)]
			private static void Prefix(InventoryGui __instance)
			{
				EquipmentPanel equipmentPanel = ((Component)__instance).GetComponent<EquipmentPanel>() ?? ((Component)__instance).gameObject.AddComponent<EquipmentPanel>();
				if (Object.op_Implicit((Object)(object)__instance.m_player))
				{
					equipmentPanel.CaptureCellTemplate(((Component)__instance.m_player).GetComponentInChildren<InventoryGrid>(true));
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
		private static class HideReservedMainCellsPatch
		{
			private static void Postfix(InventoryGrid __instance)
			{
				InventoryGui instance = InventoryGui.instance;
				Player localPlayer = Player.m_localPlayer;
				if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)localPlayer) && (Object)(object)__instance == (Object)(object)instance.m_playerGrid)
				{
					ApplyMainGridVisibility(instance, localPlayer);
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "UpdateGamepad")]
		private static class LimitMainGamepadGridPatch
		{
			private static bool Prefix(InventoryGrid __instance, ref int ___m_height, ref Vector2i ___m_selected, out int __state)
			{
				__state = -1;
				if (((Object)__instance).name == "HipCharms.SlotGrid")
				{
					return false;
				}
				InventoryGui instance = InventoryGui.instance;
				Player localPlayer = Player.m_localPlayer;
				if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)localPlayer) || (Object)(object)__instance != (Object)(object)instance.m_playerGrid || !HasReadyPanel(instance))
				{
					return true;
				}
				__state = ___m_height;
				___m_height = StandaloneInventory.GetVisibleRows(localPlayer);
				___m_selected.y = Mathf.Clamp(___m_selected.y, 0, Math.Max(0, ___m_height - 1));
				return true;
			}

			private static void Finalizer(ref int ___m_height, int __state)
			{
				if (__state >= 0)
				{
					___m_height = __state;
				}
			}
		}

		private static readonly FieldInfo Elements = AccessTools.Field(typeof(InventoryGrid), "m_elements");

		private static readonly FieldInfo InventoryField = AccessTools.Field(typeof(InventoryGrid), "m_inventory");

		private static readonly FieldInfo DragItem = AccessTools.Field(typeof(InventoryGui), "m_dragItem");

		private static readonly FieldInfo DragInventory = AccessTools.Field(typeof(InventoryGui), "m_dragInventory");

		private static readonly FieldInfo DragAmount = AccessTools.Field(typeof(InventoryGui), "m_dragAmount");

		private static readonly MethodInfo SetupDrag = AccessTools.Method(typeof(InventoryGui), "SetupDragItem", (Type[])null, (Type[])null);

		private static readonly MethodInfo SelectedItem = AccessTools.Method(typeof(InventoryGui), "OnSelectedItem", (Type[])null, (Type[])null);

		private static readonly MethodInfo ResizePlayerPanel = AccessTools.Method(typeof(InventoryGui), "SetInventorySize", (Type[])null, (Type[])null);

		private const float Cell = 46f;

		private const float Width = 330f;

		private const float Height = 410f;

		private const float PouchWidth = 248f;

		private const float PouchHeight = 280f;

		private InventoryGui gui;

		private InventoryGrid grid;

		private GameObject templateRoot;

		private GameObject cellTemplate;

		private RectTransform panel;

		private RectTransform pouch;

		private RectTransform pouchCells;

		private TMP_Text pouchCount;

		private TMP_Text moveHint;

		private Button pouchButton;

		private readonly List<EquipmentCellView> cells = new List<EquipmentCellView>();

		private readonly Dictionary<int, TMP_Text> labels = new Dictionary<int, TMP_Text>();

		private readonly Dictionary<string, TMP_Text> headings = new Dictionary<string, TMP_Text>();

		private readonly Vector3[] corners = (Vector3[])(object)new Vector3[4];

		private bool ready;

		private bool built;

		private bool moving;

		private bool failed;

		private bool pouchOpen;

		private int hoveredSlot = -1;

		private int previousRows = -1;

		private float nextBuildAttempt;

		private QuickSlotHud shortcuts;

		internal bool IsItemDragActive
		{
			get
			{
				if (Object.op_Implicit((Object)(object)gui))
				{
					return DragItem.GetValue(gui) != null;
				}
				return false;
			}
		}

		internal RectTransform WindowParent
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)panel))
				{
					return null;
				}
				Transform parent = ((Transform)panel).parent;
				return (RectTransform)(object)((parent is RectTransform) ? parent : null);
			}
		}

		internal Vector2 WindowPosition
		{
			get
			{
				//IL_0019: 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)
				if (!Object.op_Implicit((Object)(object)panel))
				{
					return EquipmentPanelSettings.Position;
				}
				return panel.anchoredPosition;
			}
		}

		internal void BeginWindowDrag()
		{
			moving = true;
		}

		internal void MoveWindow(Vector2 position)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)panel))
			{
				panel.anchoredPosition = position;
				ClampToScreen();
			}
		}

		internal void EndWindowDrag()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			moving = false;
			if (Object.op_Implicit((Object)(object)panel))
			{
				EquipmentPanelSettings.SavePosition(panel.anchoredPosition);
			}
		}

		private void Awake()
		{
			gui = ((Component)this).GetComponent<InventoryGui>();
		}

		private void OnDestroy()
		{
			DestroyPanel();
			if (Object.op_Implicit((Object)(object)templateRoot))
			{
				Object.Destroy((Object)(object)templateRoot);
			}
			shortcuts?.Dispose();
		}

		private void CaptureCellTemplate(InventoryGrid source)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)cellTemplate) && Object.op_Implicit((Object)(object)source) && Object.op_Implicit((Object)(object)source.m_elementPrefab))
			{
				templateRoot = new GameObject("HipCharms.NativeCellTemplate");
				templateRoot.transform.SetParent(((Component)this).transform, false);
				templateRoot.SetActive(false);
				cellTemplate = Object.Instantiate<GameObject>(source.m_elementPrefab, templateRoot.transform, false);
				cellTemplate.SetActive(false);
			}
		}

		private void DestroyPanel()
		{
			ready = (built = false);
			if (Object.op_Implicit((Object)(object)panel))
			{
				((Component)panel).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)panel).gameObject);
			}
			if (Object.op_Implicit((Object)(object)grid))
			{
				Object.Destroy((Object)(object)((Component)grid).gameObject);
			}
			panel = (pouch = (pouchCells = null));
			grid = null;
			cells.Clear();
			labels.Clear();
			headings.Clear();
			hoveredSlot = (previousRows = -1);
		}

		private static bool HasReadyPanel(InventoryGui owner)
		{
			EquipmentPanel equipmentPanel = (Object.op_Implicit((Object)(object)owner) ? ((Component)owner).GetComponent<EquipmentPanel>() : null);
			if (Object.op_Implicit((Object)(object)equipmentPanel))
			{
				return equipmentPanel.ready;
			}
			return false;
		}

		private static void ApplyMainGridVisibility(InventoryGui owner, Player player)
		{
			//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_00ba: Unknown result type (might be due to invalid IL or missing references)
			InventoryGrid playerGrid = owner.m_playerGrid;
			if (!Object.op_Implicit((Object)(object)playerGrid) || playerGrid.GetInventory() != ((Humanoid)player).GetInventory())
			{
				return;
			}
			int num = (HasReadyPanel(owner) ? StandaloneInventory.GetVisibleRows(player) : ((Humanoid)player).GetInventory().GetHeight());
			foreach (InventoryElement item in (List<InventoryElement>)Elements.GetValue(playerGrid))
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					((Component)item).gameObject.SetActive(item.Position.y < num);
				}
			}
			Vector2 sizeDelta = playerGrid.m_gridRoot.sizeDelta;
			sizeDelta.y = (float)num * playerGrid.m_elementSpace;
			playerGrid.m_gridRoot.sizeDelta = sizeDelta;
		}

		private void LateUpdate()
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)gui) || !Object.op_Implicit((Object)(object)localPlayer) || !Object.op_Implicit((Object)(object)gui.m_playerGrid))
			{
				return;
			}
			try
			{
				if (shortcuts == null && Object.op_Implicit((Object)(object)Hud.instance))
				{
					shortcuts = new QuickSlotHud(gui, ((Component)Hud.instance).transform);
				}
				shortcuts?.Refresh(localPlayer, ((Component)gui.m_player).gameObject.activeInHierarchy);
				if (!built)
				{
					if (Time.unscaledTime < nextBuildAttempt)
					{
						return;
					}
					Build();
				}
				if (!((Component)gui.m_player).gameObject.activeInHierarchy)
				{
					((Component)panel).gameObject.SetActive(false);
					return;
				}
				if (EquipmentPanelSettings.ConsumeReset())
				{
					moving = false;
					panel.anchoredPosition = EquipmentPanelSettings.DefaultOffset;
				}
				if (!moving)
				{
					panel.anchoredPosition = EquipmentPanelSettings.Position;
				}
				InventoryField.SetValue(grid, ((Humanoid)localPlayer).GetInventory());
				ItemData dragged = (ItemData)DragItem.GetValue(gui);
				foreach (EquipmentCellView cell in cells)
				{
					cell.Refresh(localPlayer, dragged, cell.Slot == hoveredSlot, grid.m_tooltipAnchor);
				}
				Layout(localPlayer);
				ready = true;
				((Component)panel).gameObject.SetActive(true);
				int visibleRows = StandaloneInventory.GetVisibleRows(localPlayer);
				if (previousRows != visibleRows)
				{
					ResizePlayerPanel.Invoke(gui, new object[1] { visibleRows });
					previousRows = visibleRows;
				}
				ApplyMainGridVisibility(gui, localPlayer);
				failed = false;
			}
			catch (Exception ex)
			{
				DestroyPanel();
				nextBuildAttempt = Time.unscaledTime + 2f;
				ApplyMainGridVisibility(gui, localPlayer);
				ResizePlayerPanel.Invoke(gui, new object[1] { ((Humanoid)localPlayer).GetInventory().GetHeight() });
				if (!failed)
				{
					failed = true;
					Plugin.LogError("Equipment panel: " + ex);
				}
			}
		}

		private void Build()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Expected O, but got Unknown
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			CaptureCellTemplate(gui.m_playerGrid);
			if (!Object.op_Implicit((Object)(object)cellTemplate))
			{
				throw new InvalidOperationException("Native item cell unavailable.");
			}
			panel = NativeEquipmentSkin.Panel("HipCharms.EquipmentPanel", gui.m_crafting, (Transform)(object)gui.m_player, Vector2.zero, new Vector2(330f, 410f));
			((Component)panel).gameObject.SetActive(false);
			RectTransform obj = panel;
			RectTransform obj2 = panel;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f, 1f);
			obj2.anchorMax = val;
			obj.anchorMin = val;
			((Component)panel).gameObject.AddComponent<EquipmentWindowDrag>().Owner = this;
			NativeEquipmentSkin.Text("Equipment", gui.m_containerName, (Transform)(object)panel, new Vector2(12f, -6f), new Vector2(306f, 28f), 24f, (TextAlignmentOptions)514);
			moveHint = NativeEquipmentSkin.Text("Alt + drag to move", gui.m_recipeDecription, (Transform)(object)panel, new Vector2(12f, -384f), new Vector2(306f, 18f), 13f, (TextAlignmentOptions)514);
			Heading("Worn gear", 12f, 34f, 150f);
			Heading("Charms", 176f, 34f, 146f);
			Heading("Quivers", 12f, 198f, 306f);
			Heading("Food", 12f, 302f, 150f);
			pouch = NativeEquipmentSkin.Panel("Valuables", gui.m_crafting, (Transform)(object)panel, new Vector2(338f, -120f), new Vector2(248f, 280f));
			((Component)pouch).gameObject.AddComponent<EquipmentWindowDrag>().Owner = this;
			pouchCells = NativeEquipmentSkin.Rect("Valuables cells", (Transform)(object)pouch, Vector2.zero, new Vector2(248f, 280f));
			NativeEquipmentSkin.Text("Valuables", gui.m_containerName, (Transform)(object)pouch, new Vector2(12f, -8f), new Vector2(224f, 24f), 22f, (TextAlignmentOptions)514);
			pouchCount = NativeEquipmentSkin.Text("Coins / 12 valuables", gui.m_recipeDecription, (Transform)(object)pouch, new Vector2(72f, -42f), new Vector2(166f, 42f), 14f, (TextAlignmentOptions)514);
			GameObject val2 = new GameObject("HipCharms.SlotGrid");
			val2.transform.SetParent(templateRoot.transform, false);
			grid = val2.AddComponent<InventoryGrid>();
			((Behaviour)grid).enabled = false;
			grid.m_gridRoot = NativeEquipmentSkin.Rect("Equipment cells", (Transform)(object)panel, Vector2.zero, new Vector2(330f, 410f));
			grid.m_elementPrefab = cellTemplate;
			grid.m_elementSpace = gui.m_playerGrid.m_elementSpace;
			grid.m_tooltipAnchor = gui.m_playerGrid.m_tooltipAnchor;
			grid.CanDropDragOntoItem = gui.m_playerGrid.CanDropDragOntoItem ?? ((Func<ItemData, bool>)((ItemData _) => false));
			grid.m_onSelected = OnSelected;
			grid.m_uiGroup = gui.m_playerGrid.m_uiGroup;
			for (int num = 0; num < 33; num++)
			{
				cells.Add(new EquipmentCellView(cellTemplate, (Transform)(object)grid.m_gridRoot, gui.m_playerGrid, num, SelectCell, UseCell, delegate(int s, bool enter)
				{
					if (enter)
					{
						hoveredSlot = s;
					}
					else if (hoveredSlot == s)
					{
						hoveredSlot = -1;
					}
				}, delegate
				{
					SetupDrag.Invoke(gui, new object[3] { null, null, 1 });
				}));
			}
			Elements.SetValue(grid, cells.Select((EquipmentCellView c) => c.Element).ToList());
			pouchButton = NativeEquipmentSkin.Button("Valuables", gui.m_takeAllButton, (Transform)(object)panel, new Vector2(190f, -332f), new Vector2(120f, 32f), delegate
			{
				pouchOpen = !pouchOpen;
			});
			built = true;
		}

		private void Heading(string name, float x, float y, float width)
		{
			//IL_001c: 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)
			headings[name] = NativeEquipmentSkin.Text(name, gui.m_containerName, (Transform)(object)panel, new Vector2(x, 0f - y), new Vector2(width, 18f), 15f, (TextAlignmentOptions)514);
		}

		private static Vector2 Position(int slot)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			(float, float) tuple = EquipmentLayout.Position(slot);
			return new Vector2(tuple.Item1, tuple.Item2);
		}

		private static string CellLabel(int slot)
		{
			if (slot < 27 || slot > 29)
			{
				if (slot != 30)
				{
					return StandaloneSlots.Label(slot);
				}
				return "Add-on";
			}
			return (new string[3] { "Back", "Left", "Right" })[slot - 27];
		}

		private void Layout(Player player)
		{
			//IL_0182: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: 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_0364: Unknown result type (might be due to invalid IL or missing references)
			bool flag = CraftedGear.ShowSlot(player, 31) || StandaloneInventory.GetSlotItem(player, 32) != null || Enumerable.Range(15, 12).Any((int s) => StandaloneInventory.GetSlotItem(player, s) != null);
			if (!flag)
			{
				pouchOpen = false;
			}
			((Component)pouchButton).gameObject.SetActive(flag);
			((Component)pouch).gameObject.SetActive(pouchOpen);
			((Component)headings["Charms"]).gameObject.SetActive(Enumerable.Range(6, 3).Any((int s) => CraftedGear.ShowSlot(player, s)));
			((Component)headings["Quivers"]).gameObject.SetActive(Enumerable.Range(27, 3).Any((int s) => CraftedGear.ShowSlot(player, s)));
			Canvas componentInParent = ((Component)panel).GetComponentInParent<Canvas>();
			RectTransform val = (RectTransform)(Object.op_Implicit((Object)(object)componentInParent) ? /*isinst with value type is only supported in some contexts*/: null);
			float num = EquipmentPanelSettings.Scale;
			if (Object.op_Implicit((Object)(object)val))
			{
				float[] obj = new float[3] { num, 0f, 0f };
				Rect rect = val.rect;
				obj[1] = (((Rect)(ref rect)).height - 24f) / 410f;
				rect = val.rect;
				obj[2] = (((Rect)(ref rect)).width - 24f) / (pouchOpen ? 586f : 330f);
				num = Mathf.Min(obj);
			}
			((Transform)panel).localScale = new Vector3(num, num, 1f);
			ClampToScreen();
			moveHint.text = (EquipmentPanelSettings.Locked ? "Position locked" : "Alt + drag to move");
			foreach (EquipmentCellView cell in cells)
			{
				int slot = cell.Slot;
				InventoryElement element = cell.Element;
				bool flag2 = (slot >= 15 && slot <= 26) || slot == 32;
				bool flag3 = CraftedGear.ShowSlot(player, slot) && (!flag2 || pouchOpen);
				((Component)element).gameObject.SetActive(flag3);
				if (!flag3)
				{
					continue;
				}
				RectTransform elementRectTransform = element.GetElementRectTransform();
				RectTransform val2 = (flag2 ? pouchCells : grid.m_gridRoot);
				if ((Object)(object)((Transform)elementRectTransform).parent != (Object)(object)val2)
				{
					((Transform)elementRectTransform).SetParent((Transform)(object)val2, false);
				}
				Vector2 val3 = (elementRectTransform.pivot = new Vector2(0f, 1f));
				Vector2 anchorMin = (elementRectTransform.anchorMax = val3);
				elementRectTransform.anchorMin = anchorMin;
				elementRectTransform.anchoredPosition = Position(slot);
				float num2 = 46f / Mathf.Max(1f, grid.m_elementSpace);
				((Transform)elementRectTransform).localScale = Vector3.one * num2;
				if (!flag2 && (slot < 12 || slot > 14))
				{
					if (!labels.TryGetValue(slot, out var value))
					{
						bool flag4 = (slot >= 9 && slot <= 11) || (slot >= 27 && slot <= 29);
						value = NativeEquipmentSkin.Text(CellLabel(slot), gui.m_recipeDecription, (Transform)(object)elementRectTransform, new Vector2(0f, flag4 ? (-46f / num2 - 2f) : (19f / num2)), new Vector2(46f / num2, 17f / num2), 12f / num2, (TextAlignmentOptions)514);
						labels[slot] = value;
					}
					Color color = ((Graphic)gui.m_recipeDecription).color;
					if (!StandaloneSlots.IsUnlocked(player, slot))
					{
						color.a *= 0.5f;
					}
					((Graphic)value).color = color;
				}
				if (slot == 8 && StandaloneSlots.Prefab(StandaloneInventory.GetSlotItem(player, 8), "Demister"))
				{
					Sprite lanternIcon = CraftedGear.GetLanternIcon();
					if (Object.op_Implicit((Object)(object)lanternIcon))
					{
						element.m_icon.sprite = lanternIcon;
					}
				}
			}
			pouchCount.text = (StandaloneInventory.GetSlotItem(player, 32)?.m_stack ?? 0).ToString("N0") + " coins\n" + Enumerable.Range(15, 12).Count((int s) => StandaloneInventory.GetSlotItem(player, s) != null) + " / 12 valuables";
		}

		private void ClampToScreen()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: 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_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)panel) || !Object.op_Implicit((Object)(object)WindowParent))
			{
				return;
			}
			Canvas componentInParent = ((Component)panel).GetComponentInParent<Canvas>();
			RectTransform val = (RectTransform)(Object.op_Implicit((Object)(object)componentInParent) ? /*isinst with value type is only supported in some contexts*/: null);
			if (Object.op_Implicit((Object)(object)val))
			{
				panel.GetWorldCorners(corners);
				Vector3 val2 = ((Transform)val).InverseTransformPoint(corners[0]);
				Vector3 val3 = ((Transform)val).InverseTransformPoint(corners[2]);
				if (pouchOpen && Object.op_Implicit((Object)(object)pouch))
				{
					pouch.GetWorldCorners(corners);
					val2 = Vector3.Min(val2, ((Transform)val).InverseTransformPoint(corners[0]));
					val3 = Vector3.Max(val3, ((Transform)val).InverseTransformPoint(corners[2]));
				}
				Rect rect = val.rect;
				float num = ((val2.x < ((Rect)(ref rect)).xMin + 12f) ? (((Rect)(ref rect)).xMin + 12f - val2.x) : ((val3.x > ((Rect)(ref rect)).xMax - 12f) ? (((Rect)(ref rect)).xMax - 12f - val3.x) : 0f));
				float num2 = ((val2.y < ((Rect)(ref rect)).yMin + 12f) ? (((Rect)(ref rect)).yMin + 12f - val2.y) : ((val3.y > ((Rect)(ref rect)).yMax - 12f) ? (((Rect)(ref rect)).yMax - 12f - val3.y) : 0f));
				Vector3 val4 = ((Transform)WindowParent).InverseTransformVector(((Transform)val).TransformVector(new Vector3(num, num2, 0f)));
				RectTransform obj = panel;
				obj.anchoredPosition += new Vector2(val4.x, val4.y);
			}
		}

		private void SelectCell(int slot, Modifier modifier)
		{
			//IL_0026: 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)
			Player localPlayer = Player.m_localPlayer;
			if (ready && Object.op_Implicit((Object)(object)localPlayer))
			{
				OnSelected(grid, StandaloneInventory.GetSlotItem(localPlayer, slot), StandaloneInventory.GetSlotPosition(localPlayer, slot), modifier);
			}
		}

		private void UseCell(int slot)
		{
			if (ready && !moving && !IsItemDragActive)
			{
				StandaloneSlots.UseSlot(Player.m_localPlayer, slot);
			}
		}

		private void OnSelected(InventoryGrid selectedGrid, ItemData item, Vector2i position, Modifier modifier)
		{
			//IL_001f: 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_0060: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Invalid comparison between Unknown and I4
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || ((Character)localPlayer).IsTeleporting() || moving)
			{
				return;
			}
			int num = (position.y - StandaloneInventory.GetVisibleRows(localPlayer)) * ((Humanoid)localPlayer).GetInventory().GetWidth() + position.x;
			if (num < 0 || num >= 33)
			{
				return;
			}
			ItemData val = (ItemData)DragItem.GetValue(gui);
			if (val != null)
			{
				if (StandaloneInventory.TryMoveToSlot(localPlayer, (Inventory)DragInventory.GetValue(gui), val, num, (int)DragAmount.GetValue(gui)))
				{
					SetupDrag.Invoke(gui, new object[3] { null, null, 1 });
					StandaloneSlots.RefreshEffects(localPlayer);
				}
				else
				{
					((Character)localPlayer).Message((MessageType)2, "This item does not fit here, or the required equipment is missing.", 0, (Sprite)null, false);
				}
			}
			else if (item != null)
			{
				if ((int)modifier == 2 && !gui.IsContainerOpen())
				{
					StandaloneInventory.TryMoveToInventory(localPlayer, item);
					return;
				}
				SelectedItem.Invoke(gui, new object[4] { selectedGrid, item, position, modifier });
			}
		}
	}
	public static class EquipmentPanelSettings
	{
		internal static readonly Vector2 DefaultOffset = new Vector2(12f, 0f);

		private static ConfigFile file;

		private static ConfigEntry<Vector2> offset;

		private static ConfigEntry<bool> locked;

		private static ConfigEntry<bool> reset;

		private static ConfigEntry<float> scale;

		internal static ConfigEntry<bool> ShowShortcuts;

		internal static ConfigEntry<Vector2> ShortcutPosition;

		internal static bool Locked => locked?.Value ?? false;

		internal static float Scale => scale?.Value ?? 1f;

		internal static Vector2 Position
		{
			get
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: 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_004c: 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_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: 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)
				Vector2 val = offset?.Value ?? DefaultOffset;
				if (!float.IsNaN(val.x) && !float.IsInfinity(val.x) && !float.IsNaN(val.y) && !float.IsInfinity(val.y))
				{
					return val;
				}
				return DefaultOffset;
			}
		}

		public static void Initialize(ConfigFile config)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			file = config;
			ShowShortcuts = config.Bind<bool>("Quick slots", "Show food and arrows", true, "Show food and arrow icons with their current shortcuts while inventory is closed.");
			ShortcutPosition = config.Bind<Vector2>("Quick slots", "HUD position", new Vector2(260f, 150f), "Shortcut panel top-left position measured from the bottom-left of the HUD.");
			offset = config.Bind<Vector2>("Equipment window", "Position", DefaultOffset, "Window offset from the native inventory's upper-right corner. Hold Alt and drag the header or empty background to move it; the position is saved when you release.");
			locked = config.Bind<bool>("Equipment window", "Lock position", false, "Prevent Alt-drag from moving the equipment window. Item dragging is unaffected.");
			scale = config.Bind<float>("Equipment window", "Scale", 1f, new ConfigDescription("Size of the equipment window relative to the game's UI scale. The window is kept within the screen.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.6f, 1.5f), Array.Empty<object>()));
			reset = config.Bind<bool>("Equipment window", "Reset position", false, "Turn on to return the equipment window beside the native inventory. This setting resets itself after applying.");
		}

		internal static bool ConsumeReset()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<bool> obj = reset;
			if (obj == null || !obj.Value)
			{
				return false;
			}
			offset.Value = DefaultOffset;
			reset.Value = false;
			file.Save();
			return true;
		}

		internal static void SavePosition(Vector2 position)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (offset != null)
			{
				offset.Value = position;
				file.Save();
			}
		}
	}
	public sealed class EquipmentWindowDrag : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler
	{
		internal EquipmentPanel Owner;

		private Vector2 startPointer;

		private Vector2 startPosition;

		private bool dragging;

		private static bool AltHeld
		{
			get
			{
				if (!Input.GetKey((KeyCode)308))
				{
					return Input.GetKey((KeyCode)307);
				}
				return true;
			}
		}

		public void OnBeginDrag(PointerEventData data)
		{
			//IL_0029: 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_0037: 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_0099: 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)
			if (!Object.op_Implicit((Object)(object)Owner) || EquipmentPanelSettings.Locked || !AltHeld || Owner.IsItemDragActive || (int)data.button != 0)
			{
				return;
			}
			RaycastResult pointerPressRaycast = data.pointerPressRaycast;
			GameObject gameObject = ((RaycastResult)(ref pointerPressRaycast)).gameObject;
			if (!Object.op_Implicit((Object)(object)gameObject) || (!Object.op_Implicit((Object)(object)gameObject.GetComponentInParent<InventoryElement>()) && !Object.op_Implicit((Object)(object)gameObject.GetComponentInParent<Selectable>())))
			{
				RectTransform windowParent = Owner.WindowParent;
				if (Object.op_Implicit((Object)(object)windowParent) && RectTransformUtility.ScreenPointToLocalPointInRectangle(windowParent, data.position, data.pressEventCamera, ref startPointer))
				{
					startPosition = Owner.WindowPosition;
					dragging = true;
					Owner.BeginWindowDrag();
				}
			}
		}

		public void OnDrag(PointerEventData data)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			if (dragging && Object.op_Implicit((Object)(object)Owner) && !EquipmentPanelSettings.Locked && AltHeld && !Owner.IsItemDragActive && Rec