Decompiled source of NumberRow v0.1.1

plugins/NumberRow.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using ChistixWide;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ChistixWide
{
	internal static class Wide
	{
		private sealed class Saved
		{
			internal RectTransform Rect;

			internal Vector2 Pos;

			internal Vector2 Size;
		}

		internal static class SlotPanel
		{
			private const string Guid = "randyknapp.mods.equipmentandquickslots";

			private static bool done;

			private static FieldInfo drag;

			internal static void Ensure()
			{
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				//IL_013f: Expected O, but got Unknown
				//IL_0156: Unknown result type (might be due to invalid IL or missing references)
				//IL_0164: Expected O, but got Unknown
				if (done || Patcher == null)
				{
					return;
				}
				done = true;
				try
				{
					if (Chainloader.PluginInfos.TryGetValue("randyknapp.mods.equipmentandquickslots", out var value) && Object.op_Implicit((Object)(object)value.Instance))
					{
						Type? type = ((object)value.Instance).GetType().Assembly.GetType("EquipmentAndQuickSlots.EquipmentPanel");
						MethodInfo methodInfo = type?.GetProperty("PanelBase", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetGetMethod(nonPublic: true);
						MethodInfo methodInfo2 = type?.GetNestedType("PanelDragHandle", BindingFlags.Public | BindingFlags.NonPublic)?.GetMethod("OnEndDrag", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						drag = type?.GetField("_dragPosition", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
						if (methodInfo == null || methodInfo.ReturnType != typeof(Vector2) || methodInfo2 == null || drag == null || drag.FieldType != typeof(Vector2?))
						{
							Log("Equipment and Quick Slots: its panel layout changed; its panel is not moved for the extra columns.");
							return;
						}
						Patcher.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(SlotPanel), "Base", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Patcher.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(SlotPanel), "Dropped", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log("Equipment and Quick Slots: its panel follows the inventory width.");
					}
				}
				catch (Exception ex)
				{
					Log("Equipment and Quick Slots panel not moved: " + (ex.InnerException ?? ex).Message);
				}
			}

			internal static float Shift(int width, float space)
			{
				if (width <= 8)
				{
					return 0f;
				}
				return (float)(width - 8) * space;
			}

			private static Vector2 Offset()
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				InventoryGui instance = InventoryGui.instance;
				Player localPlayer = Player.m_localPlayer;
				if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.m_playerGrid) || !Object.op_Implicit((Object)(object)localPlayer) || ((Humanoid)localPlayer).GetInventory() == null)
				{
					return Vector2.zero;
				}
				return new Vector2(Shift(((Humanoid)localPlayer).GetInventory().GetWidth(), instance.m_playerGrid.m_elementSpace), 0f);
			}

			private static void Base(ref Vector2 __result)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (drag.GetValue(null) == null)
					{
						__result += Offset();
					}
				}
				catch
				{
				}
			}

			private static void Dropped()
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: 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)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (drag.GetValue(null) is Vector2 val)
					{
						drag.SetValue(null, val - Offset());
					}
				}
				catch
				{
				}
			}
		}

		internal static class Buttons
		{
			private static object input;

			private static MethodInfo add;

			private static IDictionary buttons;

			private static bool broken;

			internal static void Ensure()
			{
				//IL_0130: Unknown result type (might be due to invalid IL or missing references)
				if (broken)
				{
					return;
				}
				try
				{
					Type type = AccessTools.TypeByName("ZInput");
					object obj = type?.GetProperty("instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
					if (obj == null)
					{
						return;
					}
					if (obj != input)
					{
						input = obj;
						buttons = type.GetField("m_buttons", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(obj) as IDictionary;
						add = type.GetMethod("AddButton", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[7]
						{
							typeof(string),
							typeof(string),
							typeof(bool),
							typeof(bool),
							typeof(bool),
							typeof(float),
							typeof(float)
						}, null);
					}
					if (buttons == null || add == null)
					{
						broken = true;
						Log("Hotbar9-12 not added to the game's input (its layout changed); the keys still work.");
						return;
					}
					for (int i = 9; i <= 12; i++)
					{
						string text = "Hotbar" + i;
						string text2 = Path(Default(i));
						if (text2 != null && !buttons.Contains(text))
						{
							add.Invoke(input, new object[7] { text, text2, false, true, false, 0f, 0f });
						}
					}
				}
				catch (Exception ex)
				{
					broken = true;
					Log("Hotbar9-12 not added to the game's input: " + (ex.InnerException ?? ex).Message + "; the keys still work.");
				}
			}
		}

		internal const int Vanilla = 8;

		internal const int Most = 12;

		internal static Func<bool> On = () => false;

		internal static Func<int> Wanted = () => 12;

		internal static Func<int, KeyCode> KeyFor = Default;

		internal static Action<string> Log = delegate
		{
		};

		internal static Harmony Patcher;

		private static float next;

		private static InventoryGui laid;

		private static int laidColumns = 8;

		private static readonly List<Saved> saved = new List<Saved>();

		internal static int Columns
		{
			get
			{
				if (!On())
				{
					return 8;
				}
				return Mathf.Clamp(Wanted(), 8, 12);
			}
		}

		internal static KeyCode Default(int slot)
		{
			return (KeyCode)(slot switch
			{
				9 => 57, 
				10 => 48, 
				11 => 45, 
				12 => 61, 
				_ => 0, 
			});
		}

		internal unsafe static string Label(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected I4, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Invalid comparison between Unknown and I4
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected I4, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			if ((int)key >= 48 && (int)key <= 57)
			{
				return (key - 48).ToString();
			}
			if ((int)key >= 256 && (int)key <= 265)
			{
				return "N" + (key - 256);
			}
			if ((int)key != 0)
			{
				if ((int)key != 45)
				{
					if ((int)key == 61)
					{
						return "=";
					}
					return ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
				}
				return "-";
			}
			return "";
		}

		internal unsafe static string Path(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected I4, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Invalid comparison between Unknown and I4
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			//IL_0036: 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: Expected I4, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Invalid comparison between Unknown and I4
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Invalid comparison between Unknown and I4
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected I4, but got Unknown
			if ((int)key >= 48 && (int)key <= 57)
			{
				return "<Keyboard>/" + (key - 48);
			}
			if ((int)key >= 256 && (int)key <= 265)
			{
				return "<Keyboard>/numpad" + (key - 256);
			}
			if ((int)key >= 97 && (int)key <= 122)
			{
				return "<Keyboard>/" + ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString().ToLowerInvariant();
			}
			if ((int)key >= 282 && (int)key <= 293)
			{
				return "<Keyboard>/" + ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString().ToLowerInvariant();
			}
			if ((int)key != 45)
			{
				if ((int)key != 61)
				{
					return (key - 91) switch
					{
						0 => "<Keyboard>/leftBracket", 
						2 => "<Keyboard>/rightBracket", 
						1 => "<Keyboard>/backslash", 
						5 => "<Keyboard>/backquote", 
						_ => null, 
					};
				}
				return "<Keyboard>/equals";
			}
			return "<Keyboard>/minus";
		}

		internal static int Fit(Inventory inv, int width)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			inv.m_width = width;
			List<ItemData> list = new List<ItemData>();
			foreach (ItemData item in inv.m_inventory)
			{
				if (item.m_gridPos.x >= width)
				{
					list.Add(item);
				}
			}
			if (list.Count == 0)
			{
				return 0;
			}
			int num = 0;
			foreach (ItemData item2 in list)
			{
				inv.m_inventory.Remove(item2);
				Vector2i val = inv.FindEmptySlot(inv.TopFirst(item2));
				if (val.x >= 0 && val.x < width)
				{
					item2.m_gridPos = val;
				}
				else
				{
					num++;
				}
				inv.m_inventory.Add(item2);
			}
			inv.Changed(false, false);
			return num;
		}

		internal static void Apply(Player p, int width)
		{
			if (!Object.op_Implicit((Object)(object)p))
			{
				return;
			}
			Inventory inventory = ((Humanoid)p).GetInventory();
			if (inventory == null || inventory.m_width == width)
			{
				return;
			}
			bool num = width < inventory.m_width;
			int num2 = Fit(inventory, width);
			if (num)
			{
				Log("Inventory narrowed to " + width + " columns; " + ((num2 > 0) ? (num2 + " item(s) without a free cell dropped next to the player.") : "every item found a free cell."));
				if (num2 > 0)
				{
					((Humanoid)p).DropInvalidItems();
				}
			}
		}

		internal static void Tick()
		{
			if (!(Time.unscaledTime < next))
			{
				next = Time.unscaledTime + 0.25f;
				Player localPlayer = Player.m_localPlayer;
				int columns = Columns;
				if (Object.op_Implicit((Object)(object)localPlayer))
				{
					Apply(localPlayer, columns);
				}
				if (Object.op_Implicit((Object)(object)InventoryGui.instance))
				{
					Layout(InventoryGui.instance, columns);
				}
				Buttons.Ensure();
				if (Object.op_Implicit((Object)(object)localPlayer))
				{
					SlotPanel.Ensure();
				}
			}
		}

		internal static void Reset()
		{
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer))
			{
				Apply(localPlayer, 8);
			}
			if (Object.op_Implicit((Object)(object)InventoryGui.instance))
			{
				Layout(InventoryGui.instance, 8);
			}
		}

		internal static bool Pressed(int slot)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			KeyCode val = KeyFor(slot);
			if ((int)val != 0)
			{
				return Input.GetKeyDown(val);
			}
			return false;
		}

		private static void Remember(RectTransform r)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//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)
			if (Object.op_Implicit((Object)(object)r))
			{
				saved.Add(new Saved
				{
					Rect = r,
					Pos = r.anchoredPosition,
					Size = r.sizeDelta
				});
			}
		}

		private static void Layout(InventoryGui gui, int columns)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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_0175: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)gui != (Object)(object)laid)
			{
				laid = gui;
				laidColumns = 8;
				saved.Clear();
			}
			if (columns == laidColumns)
			{
				return;
			}
			foreach (Saved item in saved)
			{
				if (Object.op_Implicit((Object)(object)item.Rect))
				{
					item.Rect.anchoredPosition = item.Pos;
					item.Rect.sizeDelta = item.Size;
				}
			}
			saved.Clear();
			laidColumns = columns;
			if (columns <= 8)
			{
				return;
			}
			RectTransform player = gui.m_player;
			InventoryGrid playerGrid = gui.m_playerGrid;
			if (!Object.op_Implicit((Object)(object)player) || !Object.op_Implicit((Object)(object)playerGrid))
			{
				return;
			}
			float num = (float)(columns - 8) * playerGrid.m_elementSpace;
			Transform parent = ((Transform)player).parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			float x = ((Transform)player).localPosition.x;
			Rect rect = player.rect;
			float num2 = x + ((Rect)(ref rect)).xMax;
			if (Object.op_Implicit((Object)(object)val))
			{
				foreach (Transform item2 in (Transform)val)
				{
					object obj = (object)item2;
					RectTransform val2 = (RectTransform)((obj is RectTransform) ? obj : null);
					if (Object.op_Implicit((Object)(object)val2) && !((Object)(object)val2 == (Object)(object)player))
					{
						float x2 = ((Transform)val2).localPosition.x;
						rect = val2.rect;
						if (!(x2 + ((Rect)(ref rect)).xMin < num2 - 2f))
						{
							Remember(val2);
							val2.anchoredPosition += new Vector2(num, 0f);
						}
					}
				}
			}
			RectTransform[] array = (RectTransform[])(object)new RectTransform[3]
			{
				player,
				(RectTransform)/*isinst with value type is only supported in some contexts*/,
				playerGrid.m_gridRoot
			};
			foreach (RectTransform val3 in array)
			{
				if (Object.op_Implicit((Object)(object)val3) && val3.anchorMin.x == val3.anchorMax.x)
				{
					Remember(val3);
					val3.sizeDelta += new Vector2(num, 0f);
					val3.anchoredPosition += new Vector2(num * val3.pivot.x, 0f);
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class WideHooks
	{
		[HarmonyPostfix]
		[HarmonyPriority(600)]
		[HarmonyPatch(typeof(Player), "Awake")]
		private static void Awake(Player __instance)
		{
			if (Wide.On())
			{
				((Humanoid)__instance).m_inventory.m_width = Wide.Columns;
			}
		}

		[HarmonyPrefix]
		[HarmonyPriority(900)]
		[HarmonyPatch(typeof(Humanoid), "DropInvalidItems")]
		private static void Drop(Humanoid __instance)
		{
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (val != null && (Object)(object)val == (Object)(object)Player.m_localPlayer)
			{
				Inventory inventory = ((Humanoid)val).GetInventory();
				if (inventory != null)
				{
					Wide.Fit(inventory, inventory.m_width);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Player), "Update")]
		private static void Keys(Player __instance)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !Wide.On())
			{
				return;
			}
			int width = ((Humanoid)__instance).GetInventory().m_width;
			bool? flag = null;
			for (int i = 9; i <= width && i <= 12; i++)
			{
				if (Wide.Pressed(i))
				{
					if (!flag.HasValue)
					{
						flag = ((Character)__instance).TakeInput();
					}
					if (flag == true)
					{
						__instance.UseHotbarItem(i);
					}
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(HotkeyBar), "UpdateIcons")]
		private static void Labels(HotkeyBar __instance)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (!Wide.On())
			{
				return;
			}
			List<ElementData> elements = __instance.m_elements;
			if (elements == null || elements.Count <= 8)
			{
				return;
			}
			bool flag = ZInput.IsGamepadActive();
			for (int i = 8; i < elements.Count; i++)
			{
				GameObject go = elements[i].m_go;
				object obj;
				if (!Object.op_Implicit((Object)(object)go))
				{
					obj = null;
				}
				else
				{
					Transform obj2 = go.transform.Find("binding");
					obj = ((obj2 != null) ? ((Component)obj2).GetComponent<TMP_Text>() : null);
				}
				TMP_Text val = (TMP_Text)obj;
				if (Object.op_Implicit((Object)(object)val))
				{
					string text = (flag ? "" : Wide.Label(Wide.KeyFor(i + 1)));
					if (val.text != text)
					{
						val.text = text;
					}
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
		private static void GridLabels(InventoryGrid __instance, Player player)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)player) || !Wide.On() || __instance.m_inventory == null || __instance.m_inventory != ((Humanoid)player).GetInventory())
			{
				return;
			}
			List<InventoryElement> elements = __instance.m_elements;
			int width = __instance.m_inventory.GetWidth();
			for (int i = 8; i < width && i < elements.Count; i++)
			{
				InventoryElement val = elements[i];
				object obj;
				if (!Object.op_Implicit((Object)(object)val))
				{
					obj = null;
				}
				else
				{
					Transform obj2 = ((Component)val).transform.Find("binding");
					obj = ((obj2 != null) ? ((Component)obj2).GetComponent<TMP_Text>() : null);
				}
				TMP_Text val2 = (TMP_Text)obj;
				if (Object.op_Implicit((Object)(object)val2))
				{
					string text = Wide.Label(Wide.KeyFor(i + 1));
					if (val2.text != text)
					{
						val2.text = text;
					}
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Inventory), "GetHotbar")]
		private static void Radial(Inventory __instance, bool includeEmpty, List<ItemData> __result)
		{
			if (includeEmpty && __result != null && Object.op_Implicit((Object)(object)Player.m_localPlayer) && __instance == ((Humanoid)Player.m_localPlayer).GetInventory())
			{
				for (int i = __result.Count; i < __instance.m_width && i < 12; i++)
				{
					__result.Add(__instance.GetItemAt(i, 0));
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Container), "Load")]
		private static void Grave(Container __instance)
		{
			if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<TombStone>()))
			{
				return;
			}
			Inventory inventory = __instance.GetInventory();
			if (inventory == null)
			{
				return;
			}
			foreach (ItemData item in inventory.m_inventory)
			{
				if (item.m_gridPos.x >= inventory.m_width && item.m_gridPos.x < 12)
				{
					inventory.m_width = item.m_gridPos.x + 1;
				}
			}
		}
	}
}
namespace NumberRow
{
	[BepInPlugin("chistix.numberrow", "Number Row", "0.1.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "chistix.numberrow";

		public const string Version = "0.1.1";

		private ConfigEntry<bool> on;

		private ConfigEntry<int> columns;

		private readonly ConfigEntry<KeyCode>[] keys = new ConfigEntry<KeyCode>[4];

		private Harmony harmony;

		private void Awake()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0082: 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_0137: Expected O, but got Unknown
			on = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Wide inventory and the hotbar keys 9, 0, -, =. Off: back to 8 columns, items from the extra columns go to free cells or next to you. / Широкий инвентарь и клавиши 9, 0, -, = на панели. Выключено: снова 8 столбцов, вещи из лишних столбцов в свободные ячейки или рядом на землю.");
			columns = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Columns", 12, new ConfigDescription("Inventory columns: 8 as in the game, up to 12; columns 9-12 are hotbar cells. Chests do not change. Before removing the mod set 8 and enter the world once. / Столбцов в инвентаре: 8 как в игре, до 12; столбцы 9-12 - ячейки панели. Сундуки не меняются. Перед удалением мода верните 8 и зайдите в мир.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 12), Array.Empty<object>()));
			for (int i = 0; i < 4; i++)
			{
				int slot = 9 + i;
				keys[i] = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keys", "Slot" + slot, Wide.Default(slot), "Key of hotbar cell " + slot + ". / Клавиша ячейки панели " + slot + ".");
			}
			Wide.On = () => on.Value;
			Wide.Wanted = () => columns.Value;
			Wide.KeyFor = (int num) => (num < 9 || num > 12) ? ((KeyCode)0) : keys[num - 9].Value;
			Wide.Log = delegate(string text)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)text);
			};
			on.SettingChanged += delegate
			{
				if (!on.Value)
				{
					Wide.Reset();
				}
			};
			harmony = new Harmony("chistix.numberrow");
			harmony.CreateClassProcessor(typeof(WideHooks)).Patch();
			Wide.Patcher = harmony;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Number Row 0.1.1: inventory " + Wide.Columns + " columns, keys 9, 0, -, = by default."));
		}

		private void Update()
		{
			if (on.Value)
			{
				Wide.Tick();
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
}