Decompiled source of Inventory v1.0.1

meadworks.inventory.dll

Decompiled 29 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using MeadWorks.Core;
using MeadWorks.UI;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("expDARE")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) 2026 expDARE")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("meadworks.inventory")]
[assembly: AssemblyTitle("meadworks.inventory")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[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 MeadWorks.Inventory
{
	public static class AutoEquip
	{
		private static class Patches
		{
			[HarmonyPatch(typeof(Humanoid), "Pickup")]
			[HarmonyPrefix]
			private static void PickupPre(GameObject go, out ItemData __state)
			{
				ItemDrop val = (((Object)(object)go == (Object)null) ? null : go.GetComponent<ItemDrop>());
				__state = (((Object)(object)val == (Object)null) ? null : val.m_itemData);
			}

			[HarmonyPatch(typeof(Humanoid), "Pickup")]
			[HarmonyPostfix]
			private static void PickupPost(Humanoid __instance, bool __result, bool autoequip, ItemData __state)
			{
				if (__result && __state != null && On && autoequip)
				{
					Player val = (Player)(object)((__instance is Player) ? __instance : null);
					if ((Object)(object)val != (Object)null && val == Player.m_localPlayer)
					{
						Picked(val, __state);
					}
				}
			}
		}

		private static Setting<bool> _on;

		public static bool On
		{
			get
			{
				if (_on != null)
				{
					return _on.Value;
				}
				return false;
			}
		}

		public static void Init(SettingsPage page)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			_on = page.Toggle("auto_equip", "Auto equip", true, (SettingPolicy)0, false);
			Harmony val = new Harmony("expdare.meadworks.inventory.autoequip");
			val.PatchAll(typeof(Patches));
			LedgerTrack.Patch(val, "inventory auto equip");
			ShieldEquip.Init();
			Ledger.Add("inventory auto equip state", (Action)delegate
			{
				_on = null;
			});
		}

		private static ItemData Worn(Player p, GearSlot slot)
		{
			return (ItemData)(slot switch
			{
				GearSlot.Head => ((Humanoid)p).m_helmetItem, 
				GearSlot.Chest => ((Humanoid)p).m_chestItem, 
				GearSlot.Legs => ((Humanoid)p).m_legItem, 
				GearSlot.Cape => ((Humanoid)p).m_shoulderItem, 
				GearSlot.Pack => Backpack.Worn(p), 
				_ => null, 
			});
		}

		private static void Picked(Player p, ItemData item)
		{
			GearSlot gearSlot = AutoEquipRules.SlotFor(((object)Unsafe.As<ItemType, ItemType>(ref item.m_shared.m_itemType)/*cast due to .constrained prefix*/).ToString(), Backpack.Is(item));
			bool slotEmpty = ((gearSlot == GearSlot.Utility) ? WornExtras.UtilitySlotFree(p) : (Worn(p, gearSlot) == null));
			if (AutoEquipRules.ShouldEquip(On, gearSlot, slotEmpty) && ((Humanoid)p).GetInventory().ContainsItem(item) && ((Humanoid)p).EquipItem(item, true) && gearSlot == GearSlot.Pack && Slots.ClaimPickedPack(((Humanoid)p).GetInventory(), item))
			{
				((Humanoid)p).GetInventory().Changed(false, false);
			}
		}
	}
	public enum GearSlot
	{
		None,
		Head,
		Chest,
		Legs,
		Cape,
		Utility,
		Pack
	}
	public static class AutoEquipRules
	{
		public static GearSlot SlotFor(string itemType, bool pack = false)
		{
			if (pack)
			{
				return GearSlot.Pack;
			}
			return itemType switch
			{
				"Helmet" => GearSlot.Head, 
				"Chest" => GearSlot.Chest, 
				"Legs" => GearSlot.Legs, 
				"Shoulder" => GearSlot.Cape, 
				"Utility" => GearSlot.Utility, 
				_ => GearSlot.None, 
			};
		}

		public static bool UtilitySlotFree(bool nativeFree, int wornBeside, int count)
		{
			Wear wear = UtilityRules.Equip(nativeFree, wornBeside, count);
			if (wear != Wear.Native)
			{
				return wear == Wear.Extra;
			}
			return true;
		}

		public static bool ShouldEquip(bool enabled, GearSlot slot, bool slotEmpty)
		{
			return enabled && slot != GearSlot.None && slotEmpty;
		}
	}
	internal sealed class AutoFood : MonoBehaviour
	{
		private float _next;

		private readonly List<string> _active = new List<string>(3);

		private readonly List<AutoFoodRules.Candidate> _candidates = new List<AutoFoodRules.Candidate>(3);

		private readonly List<ItemData> _items = new List<ItemData>(3);

		private void LateUpdate()
		{
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Invalid comparison between Unknown and I4
			if (Time.time < _next)
			{
				return;
			}
			_next = Time.time + 1f;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || !AutoFoodRules.CanRun(Slots.Active, ((Character)localPlayer).IsDead(), ((Character)localPlayer).IsTeleporting(), ((Character)localPlayer).InCutscene()))
			{
				return;
			}
			List<Food> foods = localPlayer.GetFoods();
			if (foods.Count >= 3)
			{
				return;
			}
			_active.Clear();
			foreach (Food item in foods)
			{
				_active.Add(item.m_item.m_shared.m_name);
			}
			if (!FoodCountdown.Read(localPlayer).State.MatchesActive((IList<string>)_active))
			{
				return;
			}
			_candidates.Clear();
			_items.Clear();
			InventoryGui instance = InventoryGui.instance;
			SlotRules.Def[] all = SlotRules.All;
			for (int i = 0; i < all.Length; i++)
			{
				SlotRules.Def def = all[i];
				if (def.Kind == SlotKind.Food && Slots.Available(def))
				{
					ItemData val = Slots.ItemAt(def.Key);
					bool nativeAllowed = val != null && (!((Object)(object)instance != (Object)null) || instance.m_dragItem != val) && (int)val.m_shared.m_itemType == 2 && val.m_shared.m_food > 0f && localPlayer.CanEat(val, false);
					_items.Add(val);
					_candidates.Add(new AutoFoodRules.Candidate
					{
						Name = val?.m_shared.m_name,
						Stack = (val?.m_stack ?? 0),
						Food = (val != null && val.m_shared.m_food > 0f),
						NativeAllowed = nativeAllowed
					});
				}
			}
			int num = AutoFoodRules.Choose(_active, _candidates);
			while (num >= 0 && !Eat(localPlayer, _items[num]))
			{
				AutoFoodRules.Candidate value = _candidates[num];
				value.NativeAllowed = false;
				_candidates[num] = value;
				num = AutoFoodRules.Choose(_active, _candidates);
			}
		}

		private static bool Eat(Player p, ItemData item)
		{
			if (!((Humanoid)p).CanConsumeItem(item, true))
			{
				return false;
			}
			((Humanoid)p).UseItem(((Humanoid)p).GetInventory(), item, true);
			return true;
		}
	}
	public static class AutoFoodRules
	{
		public struct Candidate
		{
			public string Name;

			public int Stack;

			public bool Food;

			public bool NativeAllowed;
		}

		public static bool CanRun(bool slots, bool dead, bool teleporting, bool cutscene)
		{
			if (slots && !dead && !teleporting)
			{
				return !cutscene;
			}
			return false;
		}

		public static int Choose(IList<string> active, IList<Candidate> slots)
		{
			if (active.Count >= 3)
			{
				return -1;
			}
			for (int i = 0; i < slots.Count; i++)
			{
				Candidate candidate = slots[i];
				if (candidate.Food && candidate.NativeAllowed && candidate.Stack > 0 && !string.IsNullOrEmpty(candidate.Name) && !active.Contains(candidate.Name))
				{
					return i;
				}
			}
			return -1;
		}
	}
	public static class Backpack
	{
		private static class Patches
		{
			[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
			[HarmonyPrefix]
			[HarmonyPriority(903)]
			private static bool Selecting(InventoryGui __instance, InventoryGrid grid, ItemData item, Modifier mod, out bool __state, bool __runOriginal = true)
			{
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Invalid comparison between Unknown and I4
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Invalid comparison between Unknown and I4
				__state = false;
				if (!__runOriginal)
				{
					return false;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null || (Object)(object)grid == (Object)null)
				{
					return true;
				}
				Inventory inventory = ((Humanoid)localPlayer).GetInventory();
				Inventory inventory2 = grid.GetInventory();
				if ((Object)(object)__instance.m_dragGo != (Object)null)
				{
					Inventory dragInventory = __instance.m_dragInventory;
					if (dragInventory == inventory && inventory2 != inventory && Refuse(localPlayer, __instance.m_dragItem, leaves: true))
					{
						return false;
					}
					if (dragInventory != inventory && inventory2 == inventory && Refuse(localPlayer, item, leaves: true))
					{
						return false;
					}
				}
				else if (inventory2 == inventory && ((int)mod == 2 || (int)mod == 3) && Refuse(localPlayer, item, leaves: true))
				{
					return false;
				}
				__state = true;
				_quiet++;
				return true;
			}

			[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
			[HarmonyFinalizer]
			private static void Selected(bool __state)
			{
				if (__state && _quiet > 0)
				{
					_quiet--;
				}
				if (!Quiet && _clearDrag)
				{
					_clearDrag = false;
					ClearDrag();
				}
			}

			[HarmonyPatch(typeof(InventoryGrid), "DropItem")]
			[HarmonyPrefix]
			[HarmonyPriority(800)]
			private static bool Dropping(InventoryGrid __instance, Inventory fromInventory, ItemData item, Vector2i pos, ref bool __result, bool __runOriginal = true)
			{
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				if (!__runOriginal)
				{
					return false;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null)
				{
					return true;
				}
				Inventory inventory = ((Humanoid)localPlayer).GetInventory();
				Inventory inventory2 = __instance.GetInventory();
				bool num = fromInventory == inventory && inventory2 != inventory && Refuse(localPlayer, item, leaves: true);
				bool flag = fromInventory != inventory && inventory2 == inventory && Refuse(localPlayer, inventory2.GetItemAt(pos.x, pos.y), leaves: true);
				if (!num && !flag)
				{
					return true;
				}
				__result = false;
				return false;
			}

			[HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[]
			{
				typeof(Inventory),
				typeof(ItemData)
			})]
			[HarmonyPrefix]
			[HarmonyPriority(901)]
			private static bool Moving(Inventory __instance, Inventory fromInventory, ItemData item, bool __runOriginal = true)
			{
				if (!__runOriginal)
				{
					return false;
				}
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null) && fromInventory == ((Humanoid)localPlayer).GetInventory() && __instance != fromInventory)
				{
					return !Refuse(localPlayer, item, leaves: true);
				}
				return true;
			}

			[HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[]
			{
				typeof(Inventory),
				typeof(ItemData),
				typeof(int),
				typeof(int),
				typeof(int)
			})]
			[HarmonyPrefix]
			[HarmonyPriority(901)]
			private static bool MovingTo(Inventory __instance, Inventory fromInventory, ItemData item, ref bool __result, bool __runOriginal = true)
			{
				if (!__runOriginal)
				{
					return false;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null || fromInventory != ((Humanoid)localPlayer).GetInventory() || __instance == fromInventory || !Refuse(localPlayer, item, leaves: true))
				{
					return true;
				}
				__result = false;
				return false;
			}

			[HarmonyPatch(typeof(Humanoid), "DropItem")]
			[HarmonyPrefix]
			[HarmonyPriority(800)]
			private static bool DroppingOut(Humanoid __instance, ItemData item, ref bool __result, bool __runOriginal = true)
			{
				if (!__runOriginal)
				{
					return false;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null || (object)__instance != localPlayer || !Refuse(localPlayer, item, leaves: true))
				{
					return true;
				}
				__result = false;
				return false;
			}

			[HarmonyPatch(typeof(StoreGui), "SellItem")]
			[HarmonyPrefix]
			[HarmonyPriority(800)]
			private static bool Selling(StoreGui __instance, bool __runOriginal = true)
			{
				if (!__runOriginal)
				{
					return false;
				}
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null))
				{
					return !Refuse(localPlayer, __instance.GetSellableItem(), leaves: true);
				}
				return true;
			}
		}

		private static Setting<bool> _on;

		private static bool _changing;

		private static Player _player;

		private static int _rows = -1;

		private static bool _waiting;

		private static float _next;

		private static int _quiet;

		private static bool _clearDrag;

		private static Inventory _rowInventory;

		private static ItemData _savedPack;

		private static int _rowVersion = -1;

		private static readonly List<BackpackRules.Cell> Cells = new List<BackpackRules.Cell>();

		private static readonly List<ItemData> Items = new List<ItemData>();

		internal static bool Quiet => _quiet > 0;

		internal static bool Available
		{
			get
			{
				if (PackAvailability.Enabled && (Object)(object)ObjectDB.instance != (Object)null)
				{
					return (Object)(object)ObjectDB.instance.GetItemPrefab(PackRules.All[0].Prefab) != (Object)null;
				}
				return false;
			}
		}

		public static void Init(SettingsPage page)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			_on = page.Toggle("backpacks", "Backpacks", false, (SettingPolicy)1, false);
			((Setting)_on).Changed += OnChanged;
			PackAvailability.Bind(_on);
			Ledger.Add("backpack setting", (Action)delegate
			{
				((Setting)_on).Changed -= OnChanged;
				_on = null;
				PackAvailability.Bind((Setting<bool>)null);
			});
			Harmony val = new Harmony("expdare.meadworks.inventory.backpack");
			val.PatchAll(typeof(Patches));
			LedgerTrack.Patch(val, "inventory backpack");
			Ledger.Add("inventory backpack state", (Action)delegate
			{
				ForgetRows();
				_player = null;
				_rows = -1;
				_waiting = false;
				_quiet = 0;
				_clearDrag = false;
				Cells.Clear();
				Items.Clear();
			});
		}

		private static void OnChanged()
		{
			if (_changing)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null && !((Character)localPlayer).IsDead() && !GridSize.Hold)
			{
				ItemData val = Worn(localPlayer);
				if (!((Setting)_on).ServerInEffect && PackToggleRules.RefuseDisable(_on.Value, val != null, val == null || Fits(localPlayer, 0, val, 1)))
				{
					_changing = true;
					try
					{
						string text = default(string);
						_on.TrySetLocal(true, ref text);
					}
					finally
					{
						_changing = false;
					}
					Full(localPlayer);
					return;
				}
				if (!_on.Value)
				{
					WornExtras.DisablePacks(localPlayer);
				}
				GridSize.Apply(localPlayer, notify: false);
				Slots.Run();
			}
			EquipmentPanel.Apply();
		}

		internal static bool Is(ItemData item)
		{
			if (item != null && (Object)(object)item.m_dropPrefab != (Object)null)
			{
				return PackRules.Is(((Object)item.m_dropPrefab).name);
			}
			return false;
		}

		internal static int RowsOf(ItemData item)
		{
			if (!Is(item))
			{
				return 0;
			}
			return PackToggleRules.Rows(PackAvailability.Enabled, ((Object)item.m_dropPrefab).name);
		}

		internal static ItemData Worn(Player p)
		{
			if ((Object)(object)p == (Object)null || p != Player.m_localPlayer)
			{
				return null;
			}
			Inventory inventory = ((Humanoid)p).GetInventory();
			ItemData pack = WornExtras.Pack;
			if (pack == null || !inventory.ContainsItem(pack))
			{
				return null;
			}
			return pack;
		}

		internal static int Rows(Player p)
		{
			if (!PackAvailability.Enabled)
			{
				return 0;
			}
			ItemData val = Worn(p);
			if (val == null && (Object)(object)p != (Object)null && p == Player.m_localPlayer)
			{
				val = SavedPack(((Humanoid)p).GetInventory(), WornExtras.Version);
			}
			return RowsOf(val);
		}

		internal static void ForgetRows()
		{
			if (_rowInventory != null)
			{
				Inventory rowInventory = _rowInventory;
				rowInventory.m_onChanged = (Action)Delegate.Remove(rowInventory.m_onChanged, new Action(RowsChanged));
			}
			_rowInventory = null;
			_savedPack = null;
			_rowVersion = -1;
		}

		private static void RowsChanged()
		{
			_rowVersion = -1;
		}

		private static ItemData SavedPack(Inventory inventory, int version)
		{
			if (inventory != _rowInventory)
			{
				ForgetRows();
				_rowInventory = inventory;
				inventory.m_onChanged = (Action)Delegate.Combine(inventory.m_onChanged, new Action(RowsChanged));
			}
			if (_rowVersion != version || (_savedPack != null && !_savedPack.m_equipped))
			{
				_savedPack = PackSlotRules.Restore(null, inventory.GetAllItems(), Is, (ItemData item) => item.m_equipped);
				_rowVersion = version;
			}
			return _savedPack;
		}

		private static void Read(Inventory inv, ItemData leaving, out int skip)
		{
			Cells.Clear();
			Items.Clear();
			skip = -1;
			int num = Slots.Rows(inv);
			bool flag = Slots.Banded(inv);
			foreach (ItemData allItem in inv.GetAllItems())
			{
				if (!flag || allItem.m_gridPos.y < num)
				{
					if (allItem == leaving)
					{
						skip = Cells.Count;
					}
					Cells.Add(new BackpackRules.Cell(allItem.m_gridPos.x, allItem.m_gridPos.y));
					Items.Add(allItem);
				}
			}
		}

		internal static bool Fits(Player p, int packRows, ItemData leaving, int reserve = 0)
		{
			Inventory inventory = ((Humanoid)p).GetInventory();
			Read(inventory, leaving, out var skip);
			return BackpackRules.Fits(Cells, inventory.GetWidth(), BackpackRules.WantedRows(GridSize.Height, packRows), skip, reserve);
		}

		internal static bool Blocked(Player p, ItemData item, bool leaves)
		{
			if (item == null || (Object)(object)p == (Object)null || !Is(item) || item != Worn(p))
			{
				return false;
			}
			return BackpackRules.Refuses(worn: true, ((Character)p).IsDead(), Fits(p, 0, item, (!leaves) ? 1 : 0));
		}

		internal static bool Refuse(Player p, ItemData item, bool leaves)
		{
			if (!Blocked(p, item, leaves))
			{
				return false;
			}
			Full(p);
			ClearDrag();
			return true;
		}

		internal static void ClearDrag()
		{
			if (Quiet)
			{
				_clearDrag = true;
				return;
			}
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)instance.m_dragGo != (Object)null)
			{
				instance.SetupDragItem((ItemData)null, (Inventory)null, 0);
			}
		}

		internal static void Full(Player p)
		{
			if ((Object)(object)MessageHud.instance != (Object)null)
			{
				((Character)p).Message((MessageType)2, "$inventory_full", 0, (Sprite)null, false);
			}
		}

		internal static int PlaceRows(Inventory inv)
		{
			Player localPlayer = Player.m_localPlayer;
			int num = Slots.Rows(inv);
			if ((Object)(object)localPlayer == (Object)null || inv != ((Humanoid)localPlayer).GetInventory())
			{
				return num;
			}
			return BackpackRules.PlaceRows(num, BackpackRules.WantedRows(GridSize.Height, Rows(localPlayer)));
		}

		internal static void Drain(Inventory inv, int want)
		{
			//IL_0050: 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)
			int num = Slots.Rows(inv);
			if (num <= want)
			{
				return;
			}
			Read(inv, null, out var _);
			BackpackRules.Plan plan = BackpackRules.Drain(Cells, inv.GetWidth(), num, want);
			if (plan.Changed)
			{
				for (int i = 0; i < Items.Count; i++)
				{
					Items[i].m_gridPos = new Vector2i(plan.X[i], plan.Y[i]);
				}
				inv.Changed(false, false);
			}
		}

		internal static void Applied(Player p, int setting, int bagRows, int wanted)
		{
			if (!((Object)(object)p == (Object)null) && p == Player.m_localPlayer)
			{
				_waiting = bagRows > wanted;
				string text = BackpackRules.SavedRows(bagRows, setting);
				if (text == null)
				{
					p.m_customData.Remove("mw.inventory.packrows");
				}
				else
				{
					p.m_customData["mw.inventory.packrows"] = text;
				}
			}
		}

		internal static int LoadRows(Player p)
		{
			string value;
			return BackpackRules.LoadRows(p.m_customData.TryGetValue("mw.inventory.packrows", out value) ? value : null, Rows(p));
		}

		internal static void Tick(Player p)
		{
			if ((Object)(object)p == (Object)null || ((Character)p).IsDead() || GridSize.Hold)
			{
				return;
			}
			int num = Rows(p);
			bool flag = _waiting && Time.unscaledTime >= _next;
			if (p != _player || num != _rows || flag)
			{
				bool num2 = p == _player;
				_player = p;
				_rows = num;
				_next = Time.unscaledTime + 1f;
				if (num2)
				{
					GridSize.Apply(p, notify: false);
				}
			}
		}
	}
	public static class BackpackRules
	{
		public struct Cell
		{
			public int X;

			public int Y;

			public Cell(int x, int y)
			{
				X = x;
				Y = y;
			}
		}

		public sealed class Plan
		{
			public int[] X;

			public int[] Y;

			public int Rows;

			public bool Changed;
		}

		public const string RowsKey = "mw.inventory.packrows";

		public static int ClampRows(int rows)
		{
			return Math.Max(0, Math.Min(3, rows));
		}

		public static int WantedRows(int setting, int packRows)
		{
			return setting + ClampRows(packRows);
		}

		public static int LoadRows(string saved, int wornRows)
		{
			if (!int.TryParse(saved, out var result))
			{
				result = 0;
			}
			return Math.Max(ClampRows(result), ClampRows(wornRows));
		}

		public static string SavedRows(int bagRows, int setting)
		{
			int num = ClampRows(bagRows - setting);
			if (num <= 0)
			{
				return null;
			}
			return num.ToString();
		}

		public static bool Fits(IList<Cell> bagItems, int width, int keepRows, int skip = -1, int reserve = 0)
		{
			int num = reserve;
			int num2 = 0;
			for (int i = 0; i < bagItems.Count; i++)
			{
				if (bagItems[i].Y >= keepRows)
				{
					if (i != skip)
					{
						num++;
					}
				}
				else if (i != skip && bagItems[i].X < width)
				{
					num2++;
				}
			}
			return num <= Math.Max(0, width * keepRows - num2);
		}

		public static bool Refuses(bool worn, bool dying, bool fits)
		{
			if (worn && !dying)
			{
				return !fits;
			}
			return false;
		}

		public static Plan Drain(IList<Cell> bagItems, int width, int haveRows, int keepRows)
		{
			Plan plan = new Plan
			{
				X = new int[bagItems.Count],
				Y = new int[bagItems.Count],
				Rows = Math.Min(haveRows, keepRows)
			};
			HashSet<long> taken = new HashSet<long>();
			List<int> list = new List<int>();
			for (int i = 0; i < bagItems.Count; i++)
			{
				plan.X[i] = bagItems[i].X;
				plan.Y[i] = bagItems[i].Y;
				taken.Add(At(bagItems[i].X, bagItems[i].Y));
				if (bagItems[i].Y >= keepRows)
				{
					list.Add(i);
				}
			}
			list.Sort(delegate(int a, int b)
			{
				int num = bagItems[a].Y.CompareTo(bagItems[b].Y);
				return (num == 0) ? bagItems[a].X.CompareTo(bagItems[b].X) : num;
			});
			foreach (int item in list)
			{
				if (InventoryActionRules.FirstEmpty(width, keepRows, (int cx, int cy) => taken.Contains(At(cx, cy)), out var x, out var y))
				{
					plan.X[item] = x;
					plan.Y[item] = y;
					plan.Changed = true;
					taken.Add(At(x, y));
				}
				else
				{
					plan.Rows = Math.Max(plan.Rows, bagItems[item].Y + 1);
				}
			}
			return plan;
		}

		public static int SettingAfterRefusal(int applied, int asked, int resolvedRows, int packRows)
		{
			if (asked >= applied)
			{
				return asked;
			}
			return Math.Min(applied, Math.Max(asked, resolvedRows - ClampRows(packRows)));
		}

		public static int PlaceRows(int bagRows, int wantedRows)
		{
			return Math.Max(1, Math.Min(bagRows, wantedRows));
		}

		private static long At(int x, int y)
		{
			return ((long)y << 16) | (uint)(x & 0xFFFF);
		}
	}
	public static class BagPanelRules
	{
		public static string Held(bool available, int stacks)
		{
			if (!available || stacks <= 0)
			{
				return "";
			}
			return Lang.T("inventory.held", "+{0} held", new object[1] { stacks.ToString(CultureInfo.InvariantCulture) });
		}

		public static string Heading(string title, bool available, int stacks)
		{
			string text = Held(available, stacks);
			if (text.Length != 0)
			{
				return title + " · " + text;
			}
			return title;
		}

		public static bool CellVisible(float width, float height, float left, float top, float right, float bottom)
		{
			if (width > 0f && height > 0f && left >= -0.01f && top >= -0.01f && right <= width + 0.01f)
			{
				return bottom <= height + 0.01f;
			}
			return false;
		}

		public static float HorizontalWheel(float x, float y, bool shift, bool verticalOverflow)
		{
			if (x == 0f)
			{
				if (!shift && verticalOverflow)
				{
					return 0f;
				}
				return 0f - y;
			}
			return 0f - x;
		}

		public static float RevealOffset(float viewMin, float viewMax, float itemMin, float itemMax)
		{
			if (!(itemMin <= viewMin) || !(itemMax >= viewMax))
			{
				return ScrollRevealRules.Offset(viewMin, viewMax, itemMin, itemMax);
			}
			return 0f;
		}
	}
	internal static class BagViewport
	{
		private sealed class View
		{
			private InventoryGrid _grid;

			private KitList _list;

			private Transform _parent;

			private int _sibling;

			private Layout3.RectState _root;

			private ScrollRect _native;

			private ScrollRect _scroll;

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

			private bool _nativeEnabled;

			private bool _barActive;

			private ScrollRectEnsureVisible _ensure;

			private float _contentHeight;

			private float _scale = 1f;

			internal float RootHeight => _contentHeight / _scale;

			internal bool OwnsRoot(RectTransform root)
			{
				if ((Object)(object)_grid != (Object)null)
				{
					return (Object)(object)_grid.m_gridRoot == (Object)(object)root;
				}
				return false;
			}

			internal bool Owns(InventoryGrid grid)
			{
				if ((Object)(object)_grid == (Object)(object)grid)
				{
					return (Object)(object)_list != (Object)null;
				}
				return false;
			}

			internal void Place(InventoryGrid grid, float height, float contentHeight, float contentWidth, float scale)
			{
				//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f9: Expected O, but got Unknown
				//IL_021c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0221: Unknown result type (might be due to invalid IL or missing references)
				//IL_0231: Unknown result type (might be due to invalid IL or missing references)
				//IL_0236: Unknown result type (might be due to invalid IL or missing references)
				//IL_022a: 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_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_0195: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a0: 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_0246: Unknown result type (might be due to invalid IL or missing references)
				//IL_024b: 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_025b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0260: Unknown result type (might be due to invalid IL or missing references)
				//IL_0254: Unknown result type (might be due to invalid IL or missing references)
				//IL_0285: Unknown result type (might be due to invalid IL or missing references)
				//IL_028a: 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_0293: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_0300: Unknown result type (might be due to invalid IL or missing references)
				//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0301: Unknown result type (might be due to invalid IL or missing references)
				//IL_0323: Unknown result type (might be due to invalid IL or missing references)
				//IL_0328: Unknown result type (might be due to invalid IL or missing references)
				//IL_034c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0351: Unknown result type (might be due to invalid IL or missing references)
				//IL_033b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0377: Unknown result type (might be due to invalid IL or missing references)
				//IL_037c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0365: Unknown result type (might be due to invalid IL or missing references)
				//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_038f: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
				_scale = Mathf.Max(0.01f, scale);
				if (!Owns(grid))
				{
					_grid = grid;
					_root = new Layout3.RectState(grid.m_gridRoot);
					_parent = ((Transform)grid.m_gridRoot).parent;
					_sibling = ((Transform)grid.m_gridRoot).GetSiblingIndex();
					_native = ((Component)grid.m_gridRoot).GetComponentInParent<ScrollRect>();
					if ((Object)(object)_native != (Object)null)
					{
						_nativeEnabled = ((Behaviour)_native).enabled;
						((Behaviour)_native).enabled = false;
					}
					_ensure = grid.m_ensureVisible;
					grid.m_ensureVisible = null;
					if ((Object)(object)grid.m_scrollbar != (Object)null)
					{
						_barActive = ((Component)grid.m_scrollbar).gameObject.activeSelf;
						((Component)grid.m_scrollbar).gameObject.SetActive(false);
					}
					_list = Kit.List(((Component)grid).transform, height);
					_list.Bare = true;
					_list.EveryPass = true;
					((Component)_list).GetComponent<LayoutElement>().ignoreLayout = true;
					((Behaviour)((Component)_list.Content).GetComponent<VerticalLayoutGroup>()).enabled = false;
					((Behaviour)((Component)_list.Content).GetComponent<ContentSizeFitter>()).enabled = false;
					((Transform)grid.m_gridRoot).SetParent((Transform)(object)_list.Content, false);
					RectTransform gridRoot = grid.m_gridRoot;
					gridRoot.anchorMin = new Vector2(0f, 1f);
					gridRoot.anchorMax = new Vector2(1f, 1f);
					gridRoot.pivot = new Vector2(0f, 1f);
					gridRoot.anchoredPosition = Vector2.zero;
					gridRoot.sizeDelta = new Vector2(0f, contentHeight / _scale);
				}
				if (_list.Height != height)
				{
					_list.Height = height;
				}
				_contentHeight = contentHeight;
				RefreshRoot();
				RectTransform val = (RectTransform)((Component)_list).transform;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0f, 1f);
				Vector2 val3 = default(Vector2);
				((Vector2)(ref val3))..ctor(1f, 1f);
				if (val.anchorMin != val2)
				{
					val.anchorMin = val2;
				}
				if (val.anchorMax != val3)
				{
					val.anchorMax = val3;
				}
				if (val.pivot != val2)
				{
					val.pivot = val2;
				}
				if (val.anchoredPosition != Vector2.zero)
				{
					val.anchoredPosition = Vector2.zero;
				}
				Vector2 val4 = default(Vector2);
				((Vector2)(ref val4))..ctor(12f, height);
				if (val.sizeDelta != val4)
				{
					val.sizeDelta = val4;
				}
				if ((Object)(object)_scroll == (Object)null)
				{
					_scroll = ((Component)_list).GetComponent<ScrollRect>();
				}
				Rect rect = ((RectTransform)((Component)grid).transform).rect;
				bool flag = contentWidth > ((Rect)(ref rect)).width + 0.01f;
				if (_scroll.horizontal != flag)
				{
					_scroll.horizontal = flag;
				}
				Vector2 val5 = (flag ? val2 : val3);
				Vector2 val6 = default(Vector2);
				((Vector2)(ref val6))..ctor(flag ? contentWidth : 0f, contentHeight);
				if (_list.Content.anchorMin != val2)
				{
					_list.Content.anchorMin = val2;
				}
				if (_list.Content.anchorMax != val5)
				{
					_list.Content.anchorMax = val5;
				}
				if (_list.Content.pivot != val2)
				{
					_list.Content.pivot = val2;
				}
				if (_list.Content.sizeDelta != val6)
				{
					_list.Content.sizeDelta = val6;
				}
			}

			internal void Touch()
			{
				if ((Object)(object)_list != (Object)null)
				{
					_list.Touch();
				}
			}

			internal void RefreshRoot()
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: 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_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: 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_00bd: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ef: 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_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_012a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0133: Unknown result type (might be due to invalid IL or missing references)
				RectTransform gridRoot = _grid.m_gridRoot;
				if (gridRoot.anchorMin != new Vector2(0f, 1f))
				{
					gridRoot.anchorMin = new Vector2(0f, 1f);
				}
				if (gridRoot.anchorMax != new Vector2(1f, 1f))
				{
					gridRoot.anchorMax = new Vector2(1f, 1f);
				}
				if (gridRoot.pivot != new Vector2(0f, 1f))
				{
					gridRoot.pivot = new Vector2(0f, 1f);
				}
				if (gridRoot.anchoredPosition != Vector2.zero)
				{
					gridRoot.anchoredPosition = Vector2.zero;
				}
				if (gridRoot.sizeDelta.x != 0f)
				{
					gridRoot.sizeDelta = new Vector2(0f, gridRoot.sizeDelta.y);
				}
				Rect rect = gridRoot.rect;
				if (((Rect)(ref rect)).height != RootHeight)
				{
					gridRoot.SetSizeWithCurrentAnchors((Axis)1, RootHeight);
				}
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(_scale, _scale, 1f);
				if (((Transform)gridRoot).localScale != val)
				{
					((Transform)gridRoot).localScale = val;
				}
			}

			internal void RevealSelection(InventoryGrid grid)
			{
				//IL_0064: 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_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				//IL_010c: 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)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_012a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				//IL_0156: 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_0177: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ab: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0208: Unknown result type (might be due to invalid IL or missing references)
				//IL_020e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0210: Unknown result type (might be due to invalid IL or missing references)
				//IL_0215: Unknown result type (might be due to invalid IL or missing references)
				if (!Owns(grid) || !ZInput.IsExclusiveGamepadActive())
				{
					return;
				}
				int num = grid.m_selected.y * grid.m_width + grid.m_selected.x;
				if (num < 0 || num >= grid.m_elements.Count)
				{
					return;
				}
				InventoryElement val = grid.m_elements[num];
				if (!((Component)val).gameObject.activeInHierarchy)
				{
					return;
				}
				((RectTransform)((Component)val).transform).GetWorldCorners(_corners);
				RectTransform viewport = _scroll.viewport;
				Vector3 val2 = ((Transform)viewport).InverseTransformPoint(_corners[0]);
				Vector3 val3 = ((Transform)viewport).InverseTransformPoint(_corners[2]);
				Rect rect = viewport.rect;
				if (!(val2.x >= ((Rect)(ref rect)).xMin) || !(val3.x <= ((Rect)(ref rect)).xMax) || !(val2.y >= ((Rect)(ref rect)).yMin) || !(val3.y <= ((Rect)(ref rect)).yMax))
				{
					_scroll.content.GetWorldCorners(_corners);
					Vector3 val4 = ((Transform)viewport).InverseTransformPoint(_corners[0]);
					Vector3 val5 = ((Transform)viewport).InverseTransformPoint(_corners[2]);
					Vector3 val6 = default(Vector3);
					((Vector3)(ref val6))..ctor(_scroll.horizontal ? ScrollRevealRules.Clamp(BagPanelRules.RevealOffset(((Rect)(ref rect)).xMin, ((Rect)(ref rect)).xMax, val2.x, val3.x), ((Rect)(ref rect)).xMin, ((Rect)(ref rect)).xMax, val4.x, val5.x) : 0f, _scroll.vertical ? ScrollRevealRules.Clamp(BagPanelRules.RevealOffset(((Rect)(ref rect)).yMin, ((Rect)(ref rect)).yMax, val2.y, val3.y), ((Rect)(ref rect)).yMin, ((Rect)(ref rect)).yMax, val4.y, val5.y) : 0f, 0f);
					if (!(((Vector3)(ref val6)).sqrMagnitude < 1E-06f))
					{
						_scroll.StopMovement();
						RectTransform content = _scroll.content;
						((Transform)content).position = ((Transform)content).position + ((Transform)viewport).TransformVector(val6);
					}
				}
			}

			internal bool Contains(InventoryGrid grid, Vector3 screen)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				if (!Owns(grid))
				{
					return true;
				}
				RectTransform viewport = _scroll.viewport;
				Rect rect = viewport.rect;
				return ((Rect)(ref rect)).Contains(((Transform)viewport).InverseTransformPoint(screen));
			}

			internal bool ContainsCell(InventoryElement cell)
			{
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)cell == (Object)null || !((Component)cell).gameObject.activeInHierarchy)
				{
					return false;
				}
				RectTransform viewport = _scroll.viewport;
				cell.GetElementRectTransform().GetWorldCorners(_corners);
				Vector3 val = ((Transform)viewport).InverseTransformPoint(_corners[0]);
				Vector3 val2 = ((Transform)viewport).InverseTransformPoint(_corners[2]);
				Rect rect = viewport.rect;
				return BagPanelRules.CellVisible(((Rect)(ref rect)).width, ((Rect)(ref rect)).height, val.x - ((Rect)(ref rect)).xMin, ((Rect)(ref rect)).yMax - val2.y, val2.x - ((Rect)(ref rect)).xMin, ((Rect)(ref rect)).yMax - val.y);
			}

			internal bool Scroll(ScrollRect scroll, PointerEventData data)
			{
				//IL_0030: 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_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: 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_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0112: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: 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_0152: Unknown result type (might be due to invalid IL or missing references)
				//IL_0157: Unknown result type (might be due to invalid IL or missing references)
				//IL_016c: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)scroll == (Object)null || (Object)(object)scroll != (Object)(object)_scroll)
				{
					return false;
				}
				if (!((Behaviour)scroll).isActiveAndEnabled)
				{
					return true;
				}
				RectTransform content = scroll.content;
				Rect rect = scroll.viewport.rect;
				Vector2 anchoredPosition = content.anchoredPosition;
				Rect rect2 = content.rect;
				bool verticalOverflow = ((Rect)(ref rect2)).height > ((Rect)(ref rect)).height + 0.01f;
				bool flag = ZInput.GetKey((KeyCode)304, true) || ZInput.GetKey((KeyCode)303, true);
				float num = (scroll.horizontal ? BagPanelRules.HorizontalWheel(data.scrollDelta.x, data.scrollDelta.y, flag, verticalOverflow) : 0f);
				float num2 = ((num == 0f && !(scroll.horizontal && flag)) ? data.scrollDelta.y : 0f);
				if (num == 0f && num2 == 0f)
				{
					return true;
				}
				scroll.StopMovement();
				float num3 = 0f - anchoredPosition.x;
				float num4 = 0f - ScrollRevealRules.Wheel(num, _grid.m_elementSpace * _scale, 1f);
				rect2 = content.rect;
				float num5 = 0f - ScrollRevealRules.Moved(num3, num4, ((Rect)(ref rect2)).width, ((Rect)(ref rect)).width);
				float y = anchoredPosition.y;
				float num6 = ScrollRevealRules.Wheel(num2, _grid.m_elementSpace * _scale, 1f);
				rect2 = content.rect;
				content.anchoredPosition = new Vector2(num5, ScrollRevealRules.Moved(y, num6, ((Rect)(ref rect2)).height, ((Rect)(ref rect)).height));
				return true;
			}

			internal void Clear()
			{
				if ((Object)(object)_grid != (Object)null)
				{
					if ((Object)(object)_grid.m_gridRoot != (Object)null && (Object)(object)_parent != (Object)null)
					{
						((Transform)_grid.m_gridRoot).SetParent(_parent, false);
						((Transform)_grid.m_gridRoot).SetSiblingIndex(_sibling);
						_root.Restore();
					}
					_grid.m_ensureVisible = _ensure;
					if ((Object)(object)_grid.m_scrollbar != (Object)null)
					{
						((Component)_grid.m_scrollbar).gameObject.SetActive(_barActive);
					}
				}
				if ((Object)(object)_native != (Object)null)
				{
					((Behaviour)_native).enabled = _nativeEnabled;
				}
				if ((Object)(object)_list != (Object)null)
				{
					((Component)_list).gameObject.SetActive(false);
					Object.Destroy((Object)(object)((Component)_list).gameObject);
				}
				_grid = null;
				_list = null;
				_native = null;
				_parent = null;
				_ensure = null;
				_scroll = null;
			}
		}

		private static readonly Dictionary<InventoryGrid, View> Views = new Dictionary<InventoryGrid, View>();

		internal static bool Owns(InventoryGrid grid)
		{
			if ((Object)(object)grid != (Object)null)
			{
				return Views.ContainsKey(grid);
			}
			return false;
		}

		internal static void Place(InventoryGrid grid, float height, float contentHeight, float contentWidth = 0f, float scale = 1f)
		{
			if (!Views.TryGetValue(grid, out var value))
			{
				Views.Add(grid, value = new View());
			}
			value.Place(grid, height, contentHeight, contentWidth, scale);
		}

		internal static void RevealSelection(InventoryGrid grid)
		{
			if (Views.TryGetValue(grid, out var value))
			{
				value.RevealSelection(grid);
			}
		}

		internal static void RefreshRoot(InventoryGrid grid)
		{
			if (Views.TryGetValue(grid, out var value))
			{
				value.RefreshRoot();
			}
		}

		internal static void Touch(InventoryGrid grid)
		{
			if (Views.TryGetValue(grid, out var value))
			{
				value.Touch();
			}
		}

		internal static void SizeRoot(RectTransform root, Axis axis, float size)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_005f: 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_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_0070: Unknown result type (might be due to invalid IL or missing references)
			if ((int)axis == 1)
			{
				foreach (View value in Views.Values)
				{
					if (value.OwnsRoot(root))
					{
						size = value.RootHeight;
						break;
					}
				}
			}
			Rect rect;
			float num;
			if ((int)axis != 1)
			{
				rect = root.rect;
				num = ((Rect)(ref rect)).width;
			}
			else
			{
				rect = root.rect;
				num = ((Rect)(ref rect)).height;
			}
			if (num != size)
			{
				root.SetSizeWithCurrentAnchors(axis, size);
			}
		}

		internal static bool Contains(InventoryGrid grid, Vector3 screen)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (Views.TryGetValue(grid, out var value))
			{
				return value.Contains(grid, screen);
			}
			return true;
		}

		internal static bool ContainsCell(InventoryGrid grid, InventoryElement cell)
		{
			if (Views.TryGetValue(grid, out var value))
			{
				return value.ContainsCell(cell);
			}
			return true;
		}

		internal static bool CanAct(InventoryGrid grid, Vector2i pos)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)grid != (Object)(object)((instance != null) ? instance.ContainerGrid : null))
			{
				return true;
			}
			if (!Views.TryGetValue(grid, out var value))
			{
				return true;
			}
			value.RevealSelection(grid);
			if (pos.x < 0 || pos.x >= grid.m_width || pos.y < 0)
			{
				return false;
			}
			int num = pos.y * grid.m_width + pos.x;
			if (num < grid.m_elements.Count)
			{
				return value.ContainsCell(grid.m_elements[num]);
			}
			return false;
		}

		internal static bool Scroll(ScrollRect scroll, PointerEventData data)
		{
			foreach (View value in Views.Values)
			{
				if (value.Scroll(scroll, data))
				{
					return true;
				}
			}
			return false;
		}

		internal static void Clear(InventoryGrid grid = null)
		{
			if ((Object)(object)grid != (Object)null)
			{
				if (Views.TryGetValue(grid, out var value))
				{
					value.Clear();
					Views.Remove(grid);
				}
				return;
			}
			foreach (View value2 in Views.Values)
			{
				value2.Clear();
			}
			Views.Clear();
		}
	}
	public static class BarHold
	{
		public const string Key = "mw.inventory.bar";

		public const float Dim = 0.45f;

		public static readonly ItemData[] Hold = (ItemData[])(object)new ItemData[8];

		public static readonly ItemData[] View = (ItemData[])(object)new ItemData[8];

		public static int Column(string mark)
		{
			if (mark == null || mark.Length != 1 || mark[0] < '0' || mark[0] > '7')
			{
				return -1;
			}
			return mark[0] - 48;
		}

		public static string Name(int column)
		{
			if (column < 0 || column >= 8)
			{
				return null;
			}
			return ((char)(48 + column)).ToString();
		}

		public static string Read(ItemData item)
		{
			if (item == null || item.m_customData == null || !item.m_customData.TryGetValue("mw.inventory.bar", out var value))
			{
				return null;
			}
			return value;
		}

		public static void Write(ItemData item, string mark)
		{
			if (item == null)
			{
				return;
			}
			if (item.m_customData == null)
			{
				if (mark == null)
				{
					return;
				}
				item.m_customData = new Dictionary<string, string>();
			}
			if (mark == null)
			{
				item.m_customData.Remove("mw.inventory.bar");
			}
			else
			{
				item.m_customData["mw.inventory.bar"] = mark;
			}
		}

		public static string Keep(int x, int y, string current, bool worn, bool claimed)
		{
			if (!worn || !claimed)
			{
				return null;
			}
			if (Column(current) >= 0)
			{
				return current;
			}
			if (y != 0)
			{
				return null;
			}
			return Name(x);
		}

		public static int Home(string mark, bool worn, Func<int, int, bool> taken)
		{
			int num = Column(mark);
			if (worn || num < 0 || taken(num, 0))
			{
				return -1;
			}
			return num;
		}

		public static string Move(string mark, int x, int y, int width, bool sameInventory, bool reserved)
		{
			int num = Column(mark);
			if (num < 0 || x == num || x >= width || y != 0 || !sameInventory || reserved)
			{
				return null;
			}
			return Name(x);
		}

		public static bool Blocks(int y, bool reserved)
		{
			return y == 0 && reserved;
		}

		internal static ItemData Reserved(int x, int y)
		{
			if (y != 0 || (uint)x >= (uint)Hold.Length)
			{
				return null;
			}
			return Hold[x];
		}

		internal static bool Blocked(Inventory inv, int x, int y)
		{
			ItemData val = Reserved(x, y);
			if (val != null && Slots.Banded(inv))
			{
				return inv.ContainsItem(val);
			}
			return false;
		}

		internal static ItemData DragOwner(Inventory inv, ItemData display)
		{
			if (display == null || !Slots.Banded(inv) || display.m_gridPos.y != 0)
			{
				return null;
			}
			int x = display.m_gridPos.x;
			if ((uint)x >= (uint)View.Length || View[x] != display)
			{
				return null;
			}
			ItemData val = Hold[x];
			if (Column(Read(val)) != x || !inv.ContainsItem(val))
			{
				return null;
			}
			return val;
		}

		public static void Refresh(Inventory inv)
		{
			//IL_00ad: 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)
			ItemData[] array = (ItemData[])(object)new ItemData[8];
			if (inv != null)
			{
				foreach (ItemData allItem in inv.GetAllItems())
				{
					int num = Column(Read(allItem));
					if (num >= 0 && allItem.m_gridPos.y != 0 && array[num] == null)
					{
						array[num] = allItem;
					}
				}
			}
			for (int i = 0; i < 8; i++)
			{
				if (Hold[i] != array[i])
				{
					Hold[i] = array[i];
					View[i] = ((array[i] == null) ? null : array[i].Clone());
					if (View[i] != null)
					{
						View[i].m_gridPos = new Vector2i(i, 0);
						View[i].m_equipped = false;
					}
				}
			}
		}
	}
	internal static class BarHoldPatches
	{
		private static FieldInfo _elements;

		private static FieldInfo _icon;

		[HarmonyPatch(typeof(Player), "UseHotbarItem")]
		[HarmonyPrefix]
		private static bool Press(Player __instance, int index, bool __runOriginal = true)
		{
			if (!__runOriginal)
			{
				return false;
			}
			int num = index - 1;
			Inventory inventory = ((Humanoid)__instance).GetInventory();
			if (num < 0 || num > 7 || inventory.GetItemAt(num, 0) != null)
			{
				return true;
			}
			ItemData val = BarHold.Hold[num];
			if (val == null || !inventory.ContainsItem(val))
			{
				return true;
			}
			((Humanoid)__instance).UseItem(inventory, val, false);
			Slots.Run();
			return false;
		}

		[HarmonyPatch(typeof(Inventory), "GetBoundItems")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void Bound(List<ItemData> bound)
		{
			for (int i = 0; i < 8; i++)
			{
				ItemData val = BarHold.View[i];
				if (val == null)
				{
					continue;
				}
				bool flag = false;
				for (int j = 0; j < bound.Count; j++)
				{
					if (bound[j] != null && bound[j].m_gridPos.y == 0 && bound[j].m_gridPos.x == i)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					bound.Add(val);
				}
			}
		}

		[HarmonyPatch(typeof(HotkeyBar), "UpdateIcons")]
		[HarmonyPostfix]
		private static void Icons(HotkeyBar __instance)
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			if (_elements == null)
			{
				_elements = AccessTools.Field(typeof(HotkeyBar), "m_elements");
			}
			IList list = ((_elements == null) ? null : (_elements.GetValue(__instance) as IList));
			if (list == null || list.Count == 0)
			{
				return;
			}
			if (_icon == null)
			{
				_icon = list[0].GetType().GetField("m_icon");
			}
			if (_icon == null)
			{
				return;
			}
			for (int i = 0; i < list.Count && i < 8; i++)
			{
				if (BarHold.Hold[i] != null)
				{
					object? value = _icon.GetValue(list[i]);
					Image val = (Image)((value is Image) ? value : null);
					if (!((Object)(object)val == (Object)null))
					{
						((Graphic)val).color = new Color(1f, 1f, 1f, 0.45f);
					}
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
		[HarmonyPostfix]
		private static void Grid(InventoryGrid __instance)
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null || __instance != instance.m_playerGrid || __instance.m_elements == null || __instance.m_width <= 0)
			{
				return;
			}
			for (int i = 0; i < 8 && i < __instance.m_width && i < __instance.m_elements.Count; i++)
			{
				InventoryElement val = __instance.m_elements[i];
				if (!((Object)(object)val == (Object)null) && !val.m_used)
				{
					ItemData val2 = BarHold.Reserved(i, 0);
					if ((Object)(object)UITooltip.m_current == (Object)(object)val.m_tooltip)
					{
						ItemTips.Bind((Component)(object)val.m_tooltip, val2, false, 0);
					}
					if (val2 != null && !((Object)(object)val.m_icon == (Object)null))
					{
						((Behaviour)val.m_icon).enabled = true;
						val.m_icon.sprite = ItemIcons.Get(val2);
						((Graphic)val.m_icon).color = new Color(1f, 1f, 1f, 0.45f);
					}
				}
			}
		}
	}
	public static class BaseCarry
	{
		private static class Patches
		{
			[HarmonyPatch(typeof(Player), "SetLocalPlayer")]
			[HarmonyPostfix]
			private static void Local(Player __instance)
			{
				Apply(__instance);
			}
		}

		private static Setting<float> _base;

		private static Player _player;

		private static float _own;

		public static void Init(SettingsPage page)
		{
			//IL_0055: 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_0074: Expected O, but got Unknown
			_base = page.Slider("base_carry_weight", "Base carry weight", 300f, 100f, 1000f, 50f, (SettingPolicy)1, false);
			((Setting)_base).Changed += Changed;
			Harmony val = new Harmony("expdare.meadworks.inventory.basecarry");
			val.PatchAll(typeof(Patches));
			LedgerTrack.Patch(val, "inventory base carry");
			Ledger.Add("inventory base carry state", (Action)delegate
			{
				((Setting)_base).Changed -= Changed;
				_base = null;
				if ((Object)(object)_player != (Object)null)
				{
					_player.m_maxCarryWeight = _own;
				}
				_player = null;
			});
			Apply(Player.m_localPlayer);
		}

		private static void Changed()
		{
			Apply(Player.m_localPlayer);
		}

		private static void Apply(Player player)
		{
			if (_base != null && !((Object)(object)player == (Object)null))
			{
				if (player != _player)
				{
					_player = player;
					_own = player.m_maxCarryWeight;
				}
				float num = BaseCarryRules.Limit(_base.Value, _own);
				if (player.m_maxCarryWeight != num)
				{
					player.m_maxCarryWeight = num;
				}
			}
		}
	}
	public static class BaseCarryRules
	{
		public const float Native = 300f;

		public const float Minimum = 100f;

		public const float Maximum = 1000f;

		public const float Step = 50f;

		public static float Limit(float setting, float own)
		{
			if (float.IsNaN(setting) || float.IsInfinity(setting))
			{
				return own;
			}
			float num = Math.Max(100f, Math.Min(1000f, (float)Math.Round(setting / 50f) * 50f));
			if (num != 300f)
			{
				return num;
			}
			return own;
		}
	}
	public static class BiggerStacks
	{
		private sealed class Original
		{
			public int Maximum;

			public float Weight;

			public bool Coin;

			public bool Key;

			public string Prefab;
		}

		private sealed class ScaledInventory
		{
			public int Factor;

			public int Count;
		}

		private static class Patches
		{
			[HarmonyPatch(typeof(Inventory), "UpdateTotalWeight")]
			[HarmonyPrefix]
			private static void WeightChanging(Inventory __instance)
			{
				ScaleInventory(__instance);
			}

			[HarmonyPatch(typeof(ItemDrop), "Awake")]
			[HarmonyPostfix]
			private static void Created(ItemDrop __instance)
			{
				Scale(__instance.m_itemData);
			}

			[HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })]
			[HarmonyPrefix]
			private static void Adding(Inventory __instance, ItemData item)
			{
				Inserting(__instance, item);
			}

			[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
			{
				typeof(ItemData),
				typeof(Vector2i)
			})]
			[HarmonyPrefix]
			private static void Placing(Inventory __instance, ItemData item)
			{
				Inserting(__instance, item);
			}

			[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
			{
				typeof(ItemData),
				typeof(int),
				typeof(int),
				typeof(int),
				typeof(bool)
			})]
			[HarmonyPrefix]
			private static void Moving(Inventory __instance, ItemData item)
			{
				Inserting(__instance, item);
			}

			[HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[]
			{
				typeof(ItemData),
				typeof(int)
			})]
			[HarmonyPrefix]
			private static void Checking(Inventory __instance, ItemData item)
			{
				Inserting(__instance, item);
			}

			private static void Inserting(Inventory __instance, ItemData item)
			{
				Scale(item);
				if (!InventoryCurrent(__instance))
				{
					ScaleInventory(__instance);
				}
			}

			[HarmonyPatch(typeof(ObjectDB), "Awake")]
			[HarmonyPostfix]
			private static void Loaded()
			{
				Apply();
			}

			[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
			[HarmonyPostfix]
			private static void Copied()
			{
				Apply();
			}
		}

		private static Setting<float> _factor;

		private static ConditionalWeakTable<SharedData, Original> Originals = new ConditionalWeakTable<SharedData, Original>();

		private static readonly List<WeakReference<SharedData>> Known = new List<WeakReference<SharedData>>();

		private static int _pruneAt = 256;

		private static BulkTable<StackRow> _table;

		private static Dictionary<string, int> _listed = new Dictionary<string, int>();

		private static ConditionalWeakTable<Inventory, ScaledInventory> ScaledInventories = new ConditionalWeakTable<Inventory, ScaledInventory>();

		private static bool _unloading;

		private static readonly List<ItemDrop> Drops = new List<ItemDrop>();

		private static readonly List<Container> Chests = new List<Container>();

		internal static int VanillaMaximum(ItemData item)
		{
			return OriginalFor(Source(item)?.m_shared ?? item.m_shared).Maximum;
		}

		public static void Init(SettingsPage page)
		{
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			_factor = page.Slider("stack_multiplier", "Stack multiplier", 2f, 1f, 10f, 1f, (SettingPolicy)1, false);
			((Setting)_factor).Changed += Changed;
			try
			{
				_table = BulkTables.Register<StackRow>("inventory", "stacks", (BulkRowReader<StackRow>)StackTableRules.Read, new BulkTableBounds(262144, 1024, 65536, 6), (string)null);
				_listed = StackTableRules.Index(_table.Rows);
				_table.Changed += TableChanged;
			}
			catch (Exception ex)
			{
				MwLog.WarnOnce("inventory stack table", (object)("The item stack table is not in use: " + ex.Message));
			}
			Harmony val = new Harmony("expdare.meadworks.inventory.stacks");
			val.PatchAll(typeof(Patches));
			LedgerTrack.Patch(val, "inventory stacks");
			Ledger.Add("inventory stack originals", (Action)delegate
			{
				((Setting)_factor).Changed -= Changed;
				_factor = null;
				if (_table != null)
				{
					_table.Changed -= TableChanged;
					_table.Dispose();
					_table = null;
				}
				_listed = new Dictionary<string, int>();
				_unloading = true;
				try
				{
					ApplyKnown(1);
				}
				finally
				{
					_unloading = false;
				}
				Originals = new ConditionalWeakTable<SharedData, Original>();
				ScaledInventories = new ConditionalWeakTable<Inventory, ScaledInventory>();
				Known.Clear();
				_pruneAt = 256;
				_factor = null;
			});
			Apply();
		}

		private static void Name(ItemData item, string prefab)
		{
			if (item?.m_shared != null && _factor != null && !string.IsNullOrEmpty(prefab))
			{
				OriginalFor(Source(item)?.m_shared ?? item.m_shared).Prefab = prefab;
			}
		}

		private static void Scale(ItemData item)
		{
			if (item?.m_shared != null && _factor != null)
			{
				ItemData val = Source(item);
				if (val?.m_shared != null)
				{
					VanillaItemCatalog.BeforeStackEdit(val);
				}
				string text = ((item.m_dropPrefab != null && (Object)(object)item.m_dropPrefab != (Object)null) ? ((Object)item.m_dropPrefab).name : null);
				Original original = OriginalFor(val?.m_shared ?? item.m_shared);
				if (text != null)
				{
					original.Prefab = text;
				}
				original.Coin = CoinRules.IsCoin(text, item.m_shared.m_name);
				original.Key = KeyRingRules.IsGameKey(text);
				ScaleShared(item.m_shared, val?.m_shared ?? item.m_shared, StackRules.Factor(_factor.Value));
			}
		}

		private static ItemData Source(ItemData item)
		{
			if (item.m_dropPrefab != null && !((Object)(object)item.m_dropPrefab == (Object)null))
			{
				return item.m_dropPrefab.GetComponent<ItemDrop>()?.m_itemData;
			}
			return null;
		}

		private static Original OriginalFor(SharedData shared)
		{
			if (!Originals.TryGetValue(shared, out var value))
			{
				return Remember(shared, shared.m_maxStackSize, shared.m_weight);
			}
			return value;
		}

		private static Original Remember(SharedData shared, int maximum, float weight)
		{
			if (!Originals.TryGetValue(shared, out var value))
			{
				if (Known.Count >= _pruneAt)
				{
					PruneKnown();
				}
				value = new Original();
				Originals.Add(shared, value);
				Known.Add(new WeakReference<SharedData>(shared));
			}
			value.Maximum = maximum;
			value.Weight = weight;
			return value;
		}

		private static void PruneKnown()
		{
			int num = 0;
			for (int i = 0; i < Known.Count; i++)
			{
				if (Known[i].TryGetTarget(out var _))
				{
					Known[num++] = Known[i];
				}
			}
			Known.RemoveRange(num, Known.Count - num);
			_pruneAt = Math.Max(256, num * 2);
		}

		private static void ScaleShared(SharedData shared, SharedData source, int factor)
		{
			Original original = OriginalFor(source);
			Original original2 = Remember(shared, original.Maximum, original.Weight);
			original2.Coin = original.Coin;
			original2.Key = original.Key;
			original2.Prefab = original.Prefab;
			Set(shared, original, factor);
		}

		private static void Set(SharedData shared, Original original, int factor)
		{
			shared.m_maxStackSize = (original.Coin ? 999 : ((original.Key && !_unloading) ? 10 : StackTableRules.Maximum(original.Maximum, factor, Listed(original))));
			shared.m_weight = (original.Coin ? original.Weight : StackRules.Weight(original.Weight, original.Maximum, factor));
		}

		private static int Listed(Original original)
		{
			if (_unloading || original.Prefab == null || !_listed.TryGetValue(original.Prefab, out var value))
			{
				return 0;
			}
			return value;
		}

		private static void TableChanged()
		{
			if (_table == null)
			{
				return;
			}
			Dictionary<string, int> dictionary = StackTableRules.Index(_table.Rows);
			if (!StackTableRules.Same(dictionary, _listed))
			{
				_listed = dictionary;
				if (_factor != null)
				{
					Changed();
				}
			}
		}

		private static void ApplyKnown(int factor)
		{
			PruneKnown();
			foreach (WeakReference<SharedData> item in Known)
			{
				if (item.TryGetTarget(out var target) && Originals.TryGetValue(target, out var value))
				{
					Set(target, value, factor);
				}
			}
		}

		private static void Apply()
		{
			VanillaItemCatalog.Capture(ObjectDB.instance);
			if ((Object)(object)ObjectDB.instance != (Object)null)
			{
				foreach (GameObject item in ObjectDB.instance.m_items)
				{
					if (!((Object)(object)item == (Object)null))
					{
						ItemDrop component = item.GetComponent<ItemDrop>();
						if ((Object)(object)component != (Object)null)
						{
							Name(component.m_itemData, ((Object)item).name);
							Scale(component.m_itemData);
						}
					}
				}
			}
			if (_factor != null)
			{
				ApplyKnown(StackRules.Factor(_factor.Value));
			}
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				ScaleInventory(((Humanoid)Player.m_localPlayer).GetInventory());
			}
			VanillaSaves.Normalize();
		}

		private static void Changed()
		{
			//IL_0027: 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_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)
			//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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			Apply();
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			Refresh(((Humanoid)localPlayer).GetInventory(), merge: true);
			Vector3 position = ((Component)localPlayer).transform.position;
			float range = ChestRegistry.Range;
			Drops.Clear();
			Vector3 val;
			foreach (ItemDrop s_instance in ItemDrop.s_instances)
			{
				if ((Object)(object)s_instance != (Object)null)
				{
					val = ((Component)s_instance).transform.position - position;
					if (ChestRangeRules.Within(((Vector3)(ref val)).sqrMagnitude, range))
					{
						Drops.Add(s_instance);
					}
				}
			}
			foreach (ItemDrop drop in Drops)
			{
				if (!((Object)(object)drop == (Object)null))
				{
					Scale(drop.m_itemData);
					VanillaSaves.NormalizeLooseDrop(drop);
				}
			}
			Drops.Clear();
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				Humanoid val2 = (Humanoid)(object)((allCharacter is Humanoid) ? allCharacter : null);
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)localPlayer)
				{
					val = ((Component)val2).transform.position - position;
					if (ChestRangeRules.Within(((Vector3)(ref val)).sqrMagnitude, range))
					{
						Refresh(val2.GetInventory());
					}
				}
			}
			ChestRegistry.Near(position, range, Chests);
			foreach (Container chest in Chests)
			{
				Refresh(chest.m_inventory);
			}
			Chests.Clear();
		}

		private static void ScaleInventory(Inventory inventory)
		{
			if (inventory == null || _factor == null)
			{
				return;
			}
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				Scale(allItem);
			}
			if (!ScaledInventories.TryGetValue(inventory, out var value))
			{
				value = new ScaledInventory();
				ScaledInventories.Add(inventory, value);
			}
			value.Factor = StackRules.Factor(_factor.Value);
			value.Count = inventory.GetAllItems().Count;
		}

		private static bool InventoryCurrent(Inventory inventory)
		{
			if (inventory == null || _factor == null)
			{
				return true;
			}
			if (ScaledInventories.TryGetValue(inventory, out var value) && value.Factor == StackRules.Factor(_factor.Value))
			{
				return value.Count == inventory.GetAllItems().Count;
			}
			return false;
		}

		private static void Refresh(Inventory inventory, bool merge = false)
		{
			if (inventory != null)
			{
				ScaleInventory(inventory);
				if (merge)
				{
					InventoryActions.Merge(inventory, player: true);
				}
				inventory.UpdateTotalWeight();
			}
		}
	}
	public sealed class BulkActionRules
	{
		private readonly HashSet<string> _chests = new HashSet<string>();

		private readonly Dictionary<long, string> _pending = new Dictionary<long, string>();

		public int Moved { get; private set; }

		public int Pending => _pending.Count;

		public void Add(string chest, int amount)
		{
			if (amount > 0)
			{
				Moved += amount;
				_chests.Add(chest);
			}
		}

		public void Ask(long ticket, string chest)
		{
			_pending[ticket] = chest;
		}

		public void Settle(long ticket, int amount)
		{
			if (_pending.TryGetValue(ticket, out var value))
			{
				_pending.Remove(ticket);
				Add(value, Math.Max(0, amount));
			}
		}

		public string Message(bool restock)
		{
			if (Pending <= 0)
			{
				if (Moved != 0)
				{
					return Done(restock, Moved, _chests.Count);
				}
				if (!restock)
				{
					return Lang.T("inventory.nothing_to_store", "Nothing to store");
				}
				return Lang.T("inventory.nothing_to_restock", "Nothing to restock");
			}
			if (!restock)
			{
				return Lang.T("inventory.storing_items", "Storing items...");
			}
			return Lang.T("inventory.restocking_items", "Restocking items...");
		}

		private static string Done(bool restock, int moved, int chests)
		{
			if (restock)
			{
				if (moved != 1)
				{
					if (chests != 1)
					{
						return Lang.T("inventory.restocked_items_chests", "Restocked {0} items from {1} chests", new object[2] { moved, chests });
					}
					return Lang.T("inventory.restocked_items_chest", "Restocked {0} items from {1} chest", new object[2] { moved, chests });
				}
				if (chests != 1)
				{
					return Lang.T("inventory.restocked_item_chests", "Restocked {0} item from {1} chests", new object[2] { moved, chests });
				}
				return Lang.T("inventory.restocked_item_chest", "Restocked {0} item from {1} chest", new object[2] { moved, chests });
			}
			if (moved != 1)
			{
				if (chests != 1)
				{
					return Lang.T("inventory.stored_items_chests", "Stored {0} items in {1} chests", new object[2] { moved, chests });
				}
				return Lang.T("inventory.stored_items_chest", "Stored {0} items in {1} chest", new object[2] { moved, chests });
			}
			if (chests != 1)
			{
				return Lang.T("inventory.stored_item_chests", "Stored {0} item in {1} chests", new object[2] { moved, chests });
			}
			return Lang.T("inventory.stored_item_chest", "Stored {0} item in {1} chest", new object[2] { moved, chests });
		}

		public static string Merged(int moved)
		{
			return moved switch
			{
				1 => Lang.T("inventory.merged_item", "Merged {0} item in your bag", new object[1] { moved }), 
				0 => Lang.T("inventory.nothing_to_merge", "Nothing to merge"), 
				_ => Lang.T("inventory.merged_items", "Merged {0} items in your bag", new object[1] { moved }), 
			};
		}
	}
	internal sealed class BulkFeedback : IDisposable
	{
		private static BulkFeedback _current;

		private readonly BulkActionRules _counts = new BulkActionRules();

		private readonly bool _restock;

		private bool _finished;

		internal BulkFeedback(bool restock)
		{
			_restock = restock;
			_current = this;
		}

		internal void Add(Container chest, int amount)
		{
			_counts.Add(((object)Unsafe.As<ZDOID, ZDOID>(ref chest.m_nview.GetZDO().m_uid)/*cast due to .constrained prefix*/).ToString(), amount);
		}

		internal unsafe static Action<int> Track(long ticket, ZDOID chest)
		{
			BulkFeedback batch = _current;
			if (batch == null)
			{
				return null;
			}
			batch._counts.Ask(ticket, ((object)(*(ZDOID*)(&chest))/*cast due to .constrained prefix*/).ToString());
			return delegate(int amount)
			{
				batch._counts.Settle(ticket, amount);
				if (batch._finished && batch._counts.Pending == 0)
				{
					Layout3.Toast(batch._counts.Message(batch._restock));
				}
			};
		}

		public void Dispose()
		{
			_current = null;
			_finished = true;
			Layout3.Toast(_counts.Message(_restock));
		}
	}
	internal sealed class CharacterColumn : MonoBehaviour
	{
		private sealed class WornSlot
		{
			public Layout3Rules.Worn Def;

			public KitSlot Slot;

			public TMP_Text Label;

			public TMP_Text Amount;

			public UITooltip Tip;

			public bool Dim;

			public Sprite Icon;

			public int Count;

			public int Quality;

			public float? Durability;

			public bool Drawn;
		}

		private sealed class Entry
		{
			public bool Head;

			public string Label;

			public string Value;

			public string Baseline;

			public StatTone Tone;

			public List<StatPart> Parts;

			public float Total;

			public bool Based;

			public string Unit = "";

			public KitStat Row;

			public bool Effect;

			public TextMeshProUGUI Timer;

			public string Detail;

			public string Tip;

			public Sprite Icon;

			public HudEffectTone TimeTone;

			public Image IconView;

			public TextMeshProUGUI DetailText;
		}

		private const int Character = 0;

		private const int SkillsPage = 1;

		private const int StatsPage = 2;

		private static int _tab;

		private static SkillOrder _order;

		private readonly List<Line> _effectLines = new List<Line>();

		private InventoryGui _gui;

		private readonly RectTransform[] _pages = (RectTransform[])(object)new RectTransform[3];

		private readonly KitTab[] _tabs = (KitTab[])(object)new KitTab[3];

		private readonly List<WornSlot> _slots = new List<WornSlot>();

		private KitStat _armour;

		private string _armourText;

		private TextMeshProUGUI _name;

		private List<Entry> _entries = new List<Entry>();

		private string _shape;

		private int _hover = -1;

		private RectTransform _card;

		private string _cardText;

		private KitSection _skillCount;

		private KitButton _sort;

		private KitList _skills;

		private KitList _character;

		private string _skillShape;

		private float _next;

		private string _nameRead;

		private float _armourRead = float.NaN;

		public RectTransform Model { get; private set; }

		public static GameObject Build(InventoryGui gui, RectTransform parent, bool slots)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0035: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0051: 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_0058: 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_009e: Expected O, but got Unknown
			GameObject val = new GameObject("MeadWorks.Equipment", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent((Transform)(object)parent, false);
			RectTransform val2 = (RectTransform)val.transform;
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			Vector2 offsetMin = (val2.offsetMax = Vector2.zero);
			val2.offsetMin = offsetMin;
			CharacterColumn characterColumn = val.AddComponent<CharacterColumn>();
			characterColumn._gui = gui;
			characterColumn.BuildTabs();
			characterColumn.BuildCharacter(slots);
			characterColumn.BuildSkills();
			characterColumn._pages[2] = characterColumn.Page("Stats");
			characterColumn.Show(_tab);
			return val;
		}

		private RectTransform Page(string name)
		{
			//IL_0014: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)component).SetParent(((Component)this).transform, false);
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			Vector2 offsetMin = (component.offsetMax = Vector2.zero);
			component.offsetMin = offsetMin;
			return component;
		}

		private void BuildTabs()
		{
			//IL_0030: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0051: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			KitTabStrip val = Kit.TabStrip((Transform)(object)Layout3.Space(((Component)this).transform, "Tabs", 0f, 0f, 254f, 34f));
			RectTransform val2 = (RectTransform)((Component)val).transform;
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			Vector2 offsetMin = (val2.offsetMax = Vector2.zero);
			val2.offsetMin = offsetMin;
			for (int i = 0; i < _tabs.Length; i++)
			{
				int index = i;
				_tabs[i] = val.Tab(Layout3Rules.ColumnTabs[i], (Action)delegate
				{
					Show(index);
				});
			}
		}

		private void BuildCharacter(bool slots)
		{
			//IL_004d: 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_0053: 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_0068: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: 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_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: 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_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: 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_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: 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_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0505: Expected O, but got Unknown
			//IL_051b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: Unknown result type (might be due to invalid IL or missing references)
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			//IL_0536: Unknown result type (might be due to invalid IL or missing references)
			//IL_0555: Unknown result type (might be due to invalid IL or missing references)
			//IL_0598: Unknown result type (might be due to invalid IL or missing references)
			_character = Kit.List((Transform)(object)(_pages[0] = Page("Character")), 0f);
			_character.Bare = true;
			_character.EveryPass = true;
			RectTransform val = (RectTransform)((Component)_character).transform;
			val.anchorMin = Vector2.zero;
			val.anchorMax = Vector2.one;
			val.offsetMin = Vector2.zero;
			val.offsetMax = new Vector2(12f, -42f);
			((Behaviour)((Component)_character.Content).GetComponent<VerticalLayoutGroup>()).enabled = false;
			((Behaviour)((Component)_character.Content).GetComponent<ContentSizeFitter>()).enabled = false;
			_character.Content.SetSizeWithCurrentAnchors((Axis)1, 337f);
			RectTransform val2 = Layout3.Space((Transform)(object)_character.Content, "CharacterBody", 0f, -42f, 254f, 379f);
			float num = (slots ? 180f : 242f);
			Model = Layout3.Space((Transform)(object)val2, "Model", 64f, 42f, 126f, num);
			HudParts.Box((Transform)(object)Model, Theme.Soft(Color.black, 0.16f), new Color(0f, 0f, 0f, 0f), Theme.RadiusWindow, 1f);
			float num2 = ModelPreviewRules.GroundHeight(num);
			float num3 = 56.699997f;
			((Graphic)HudParts.Box((Transform)(object)Layout3.Space((Transform)(object)Model, "Ground", (126f - num3) / 2f, num - num2, num3, 1f), Theme.Line, Color.clear, 0f, 0f)).raycastTarget = false;
			RectTransform component = new GameObject("Figure", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)Model, false);
			component.anchorMin = new Vector2(0.5f, 0f);
			component.anchorMax = new Vector2(0.5f, 1f);
			float num4 = (num - num2 - 14f) * 100f / 250f;
			component.offsetMin = new Vector2((0f - num4) / 2f, num2);
			component.offsetMax = new Vector2(num4 / 2f, -14f);
			Image obj = ((Component)component).gameObject.AddComponent<Image>();
			obj.sprite = FigureSprite.Get();
			((Graphic)obj).color = Theme.Soft(Theme.Heading, 0.12f);
			((Graphic)obj).raycastTarget = false;
			_name = Kit.Label((Transform)(object)Model, "Name", "");
			((TMP_Text)_name).font = Theme.HeadingFont;
			((TMP_Text)_name).fontSize = Theme.TextSize((TextRole)0);
			((TMP_Text)_name).characterSpacing = 0f;
			((Graphic)_name).color = Theme.TextDim;
			((TMP_Text)_name).alignment = (TextAlignmentOptions)1026;
			RectTransform rectTransform = ((TMP_Text)_name).rectTransform;
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = new Vector2(1f, 0f);
			rectTransform.pivot = new Vector2(0.5f, 0f);
			rectTransform.anchoredPosition = new Vector2(0f, 8f);
			rectTransform.sizeDelta = new Vector2(0f, 20f);
			_armour = Kit.Stat((Transform)(object)val2, Lang.T("inventory.armor", "Armor"), "0");
			_armour.SetDifference("0", (string)null, (Tone)0);
			Layout3.Position(_armour.Rect, 0f, 354f, 116f, 25f);
			Layout3.BuildWeight((Transform)(object)val2);
			if (!slots)
			{
				return;
			}
			GameObject elementPrefab = _gui.m_playerGrid.m_elementPrefab;
			UITooltip val3 = (((Object)(object)elementPrefab != (Object)null) ? elementPrefab.GetComponentInChildren<UITooltip>(true) : null);
			(Layout3Rules.Worn[], float, float, float, float)[] wornGroups = Layout3Rules.WornGroups;
			for (int i = 0; i < wornGroups.Length; i++)
			{
				(Layout3Rules.Worn[], float, float, float, float) tuple = wornGroups[i];
				for (int j = 0; j < tuple.Item1.Length; j++)
				{
					Layout3Rules.Worn def = tuple.Item1[j];
					bool flag = TrinketPairRules.IsTrinket(def.Key);
					WornSlot wornSlot = new WornSlot
					{
						Def = def,
						Slot = Kit.Slot((Transform)(object)val2, (SlotSize)0)
					};
					wornSlot.Amount = ((Component)((Component)wornSlot.Slot).transform.Find("Count")).GetComponent<TMP_Text>();
					((Object)((Component)wornSlot.Slot).gameObject).name = "Slot " + def.Key;
					wornSlot.Slot.SetEmpty(def.Glyph, "");
					Layout3.Position((RectTransform)((Component)wornSlot.Slot).transform, tuple.Item2 + (float)j * tuple.Item4, tuple.Item3 + (float)j * tuple.Item5, 56f, 56f);
					RectTransform val4 = (RectTransform)((Component)wornSlot.Slot).transform.Find("Icon");
					val4.sizeDelta = Vector2.one * (flag ? 30f : 38.5f);
					val4.anchoredPosition = new Vector2(0f, flag ? 12f : 4f);
					TextMeshProUGUI val5 = Kit.Label(((Component)wornSlot.Slot).transform, "EquipmentLabel", TypographyRules.SectionLabel(Layout3Rules.SlotText(def.Label)));
					Theme.StyleText((TMP_Text)(object)val5, (TextRole)10);
					((Graphic)val5).color = Theme.TextDim;
					((TMP_Text)val5).alignment = (TextAlignmentOptions)1026;
					((TMP_Text)val5).overflowMode = (TextOverflowModes)1;
					((Graphic)val5).raycastTarget = false;
					Layout3.Position(((TMP_Text)val5).rectTransform, 0f, 56f - (flag ? 29f : 16f), 56f, 14f);
					wornSlot.Label = (TMP_Text)(object)val5;
					SlotInput.Bind(wornSlot.Slot, def.Key, delegate
					{
						RightClick(def.Key);
					});
					if ((Object)(object)val3 != (Object)null && (Object)(object)val3.m_tooltipPrefab != (Object)null)
					{
						wornSlot.Tip = ((Component)wornSlot.Slot).gameObject.AddComponent<UITooltip>();
						wornSlot.Tip.m_tooltipPrefab = val3.m_tooltipPrefab;
					}
					int order = _slots.Count;
					wornSlot.Slot.GamepadVerticalFocus = (bool forward) => WornFocus(order, forward);
					_slots.Add(wornSlot);
				}
			}
		}

		private KitSlot WornFocus(int order, bool forward)
		{
			int num = (forward ? 1 : (-1));
			for (int i = order + num; i >= 0 && i < _slots.Count; i += num)
			{
				KitSlot slot = _slots[i].Slot;
				if (((UIBehaviour)slot).IsActive() && ((Selectable)slot).IsInteractable())
				{
					return slot;
				}
			}
			return null;
		}

		private void BuildSkills()
		{
			RectTransform val = (_pages[1] = Page("Skills"));
			RectTransform val2 = Layout3.Space((Transform)(object)val, "Head", 0f, 42f, 254f, 28f);
			HorizontalLayoutGroup obj = ((Component)val2).gameObject.AddComponent<HorizontalLayoutGroup>();
			((LayoutGroup)obj).childAlignment = (TextAnchor)5;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = childControlWidth;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false);
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = childControlWidth;
			_sort = Kit.Button((Transform)(object)val2, StatSheetRules.OrderLabel(_order), (Action)CycleOrder, false);
			_sort.Compact = true;
			_sort.Glyph = "sort";
			_skillCount = Kit.Section((Transform)(object)val, StatSheetRules.SkillCount(0), (string)null, false);
			Layout3.Position(_skillCount.Rect, 0f, 47f, 160f, 18f);
			_skills = Kit.List((Transform)(object)val, 100f);
			_skills.Bare = true;
		}

		private void CycleOrder()
		{
			_order = StatSheetRules.Next(_order);
			_sort.Label = StatSheetRules.OrderLabel(_order);
			_skillShape = null;
			_next = 0f;
		}

		public bool Open(string tab)
		{
			for (int i = 0; i < Layout3Rules.ColumnTabs.Length; i++)
			{
				if (string.Equals(Layout3Rules.ColumnTabs[i], tab, StringComparison.OrdinalIgnoreCase))
				{
					Show(i);
					return true;
				}
			}
			return false;
		}

		private void Show(int tab)
		{
			_tab = ((tab >= 0 && tab < _pages.Length) ? tab : 0);
			for (int i = 0; i < _pages.Length; i++)
			{
				((Component)_pages[i]).gameObject.SetActive(i == _tab);
				_tabs[i].Open = i == _tab;
			}
			HideCard();
			_next = 0f;
		}

		private void LateUpdate()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)_gui == (Object)null || (Object)(object)localPlayer == (Object)null || !InventoryGui.IsVisible())
			{
				HideCard();
			}
			else if (!(Time.unscaledTime < _next))
			{
				_next = Time.unscaledTime + ((_tab == 0) ? 0.1f : 0.5f);
				if (_tab == 0)
				{
					RefreshCharacter(localPlayer);
				}
				else if (_tab == 1)
				{
					RefreshSkills(localPlayer);
				}
				else
				{
					RefreshStats(localPlayer);
				}
			}
		}

		private void OnDisable()
		{
			HideCard();
		}

		private void RefreshCharacter(Player p)
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			string playerName = p.GetPlayerName();
			if ((object)playerName != _nameRead && playerName != _nameRead)
			{
				_nameRead = playerName;
				string text = playerName ?? "";
				if (((TMP_Text)_name).text != text)
				{
					((TMP_Text)_name).text = text;
				}
			}
			float bodyArmor = ((Character)p).GetBodyArmor();
			if (bodyArmor != _armourRead || _armourText == null)
			{
				_armourRead = bodyArmor;
				string text2 = StatSheetRules.Number(bodyArmor);
				if (text2 != _armourText)
				{
					_armour.SetDifference(_armourText = text2, (string)null, (Tone)0);
				}
			}
			if (_slots.Count == 0)
			{
				return;
			}
			List<ItemData> equippedItems = ((Humanoid)p).GetInventory().GetEquippedItems();
			RectTransform tooltipAnchor = _gui.m_playerGrid.m_tooltipAnchor;
			foreach (WornSlot slot in _slots)
			{
				if (slot.Def.Key == "KEY RING")
				{
					List<ItemData> list = Slots.RingItems();
					KeyRingPanel.Anchor = (RectTransform)((Component)slot.Slot).transform;
					KeyRingPanel.Track(p, list);
					slot.Slot.Clear();
					if (list.Count > 0)
					{
						slot.Slot.Icon = ItemIcons.Get(list[0]);
					}
					slot.Slot.Chosen = KeyRingPanel.Fresh;
					int num = 0;
					foreach (ItemData item in list)
					{
						num += item.m_stack;
					}
					slot.Amount.text = SlotRules.RingCount(num);
					if ((Object)(object)slot.Label != (Object)null)
					{
						((Behaviour)slot.Label).enabled = Layout3Rules.WornLabelShown(list.Count > 0, slot.Def.Key);
					}
					if ((Object)(object)slot.Tip != (Object)null)
					{
						slot.Tip.Set("KEY RING", KeyRingPanel.Tip, tooltipAnchor, default(Vector2));
					}
					ItemSlots.Refresh((Component)(object)slot.Slot, (ItemData)null);
					continue;
				}
				bool dim;
				ItemData val = EquipmentPanel.Worn(p, equippedItems, slot.Def.Key, out dim);
				ItemData val2 = Slots.ItemAt(slot.Def.Key);
				if (val2 != null)
				{
					val = val2;
					dim = !val2.m_equipped && slot.Def.Key != "COINS";
				}
				bool flag = UtilityRules.SlotShown(slot.Def.Key, val != null, Slots.Active, Backpack.Available, WornExtras.Count);
				if (((Component)slot.Slot).gameObject.activeSelf != flag)
				{
					((Component)slot.Slot).gameObject.SetActive(flag);
				}
				SetTip(slot, val, tooltipAnchor);
				ItemSlots.Refresh((Component)(object)slot.Slot, val);
				if (val == null)
				{
					if (slot.Drawn)
					{
						slot.Slot.Clear();
					}
					slot.Drawn = false;
					if ((Object)(object)slot.Label != (Object)null && !((Behaviour)slot.Label).enabled)
					{
						((Behaviour)slot.Label).enabled = true;
					}
					continue;
				}
				Sprite val3 = ItemIcons.Get(val);
				int num2 = ((!dim && val.m_shared.m_maxStackSize > 1) ? val.m_stack : 0);
				int num3 = ((!dim) ? SlotMath.ShownQuality(val.m_quality, val.m_shared.m_maxQuality) : 0);
				float? num4 = ((!dim && val.m_shared.m_useDurability) ? new float?(val.GetDurabilityPercentage()) : ((float?)null));
				if (!slot.Drawn || slot.Dim != dim || !((Object)(object)slot.Icon == (Object)(object)val3) || slot.Count != num2 || slot.Quality != num3 || slot.Durability != num4)
				{
					slot.Drawn = true;
					slot.Dim = dim;
					slot.Icon = val3;
					slot.Count = num2;
					slot.Quality = num3;
					slot.Durability = num4;
					slot.Slot.Icon = val3;
					slot.Slot.Worn = !dim && slot.Def.Key != "COINS";
					slot.Slot.Dimmed = dim;
					slot.Slot.Count = num2;
					slot.Slot.Quality = num3;
					slot.Slot.Durability = num4;
					if ((Object)(object)slot.Label != (Object)null)
					{
						((Behaviour)slot.Label).enabled = Layout3Rules.WornLabelShown(occupied: true, slot.Def.Key);
					}
				}
			}
		}

		private static void SetTip(WornSlot s, ItemData item, RectTransform anchor)
		{
			Kit.ItemTooltip((Component)(object)s.Slot, item, 0);
			if (Slots.StorageActive)
			{
				ItemTips.Bind((Component)(object)((Component)s.Slot).GetComponent<UITooltip>(), item, false, 0);
			}
		}

		public bool Unequip(string slot)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!EquipmentPanel.Unequip(localPlayer, slot))
			{
				return false;
			}
			RefreshCharacter(localPlayer);
			return true;
		}

		private void RightClick(string slot)
		{
			ItemData val = Slots.ItemAt(slot);
			if (val != null && !val.m_equipped)
			{
				if (Slots.Use(slot))
				{
					RefreshCharacter(Player.m_localPlayer);
				}
			}
			else
			{
				Unequip(slot);
			}
		}

		private void RefreshSkills(Player p)
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: 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_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: 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_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Expected O, but got Unknown
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Expected O, but got Unknown
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: 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)
			List<SkillLine> list = StatSheetRules.Sort(ReadSkills(p), _order);
			StringBuilder stringBuilder = new StringBuilder(_order.ToString()).Append(Lang.Language);
			foreach (SkillLine item in list)
			{
				stringBuilder.Append('|').Append(item.Name).Append(':')
					.Append(item.Level)