Decompiled source of ExpandedPlayerInventory v1.2.0

ExpandedPlayerInventory.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ExpandedPlayerInventory")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+2b14c6d8b227894dc9830fc6dfc87705398296b6")]
[assembly: AssemblyProduct("ExpandedPlayerInventory")]
[assembly: AssemblyTitle("ExpandedPlayerInventory")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ExpandedPlayerInventory
{
	[HarmonyPatch(typeof(InventoryGui), "Awake")]
	public static class InventoryGui_Awake_Patch
	{
		public static void Postfix(InventoryGui __instance)
		{
			try
			{
				InventoryGui_Show_Patch.ResetSessionState();
				InventoryGui_Show_Patch.SetupScrollUI(__instance);
			}
			catch (Exception arg)
			{
				ExpandedPlayerInventoryPlugin.Log.LogError((object)$"InventoryGui_Awake_Patch error: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Hide")]
	public static class InventoryGui_Hide_Patch
	{
		public static void Prefix(InventoryGui __instance)
		{
			try
			{
				if ((Object)(object)__instance != (Object)null && (Object)(object)__instance.m_playerGrid != (Object)null)
				{
					ScrollRect component = ((Component)__instance.m_playerGrid).GetComponent<ScrollRect>();
					if ((Object)(object)component != (Object)null)
					{
						InventoryGui_Show_Patch._savedScrollNormalizedPosition = Mathf.Clamp01(component.verticalNormalizedPosition);
					}
				}
			}
			catch (Exception arg)
			{
				ExpandedPlayerInventoryPlugin.Log.LogError((object)$"InventoryGui_Hide_Patch error: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Update")]
	public static class InventoryGui_Update_Patch
	{
		private const int MaxOpeningFrames = 30;

		public static void Postfix(InventoryGui __instance)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return;
				}
				InventoryGrid playerGrid = __instance.m_playerGrid;
				if ((Object)(object)playerGrid == (Object)null)
				{
					return;
				}
				GameObject gameObject = ((Component)playerGrid).gameObject;
				RectTransform component = gameObject.GetComponent<RectTransform>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				RectMask2D component2 = gameObject.GetComponent<RectMask2D>();
				Rect rect;
				if ((Object)(object)component2 != (Object)null && ((Behaviour)component2).enabled)
				{
					rect = component.rect;
					if (((Rect)(ref rect)).height <= 10f)
					{
						((Behaviour)component2).enabled = false;
					}
				}
				if (!((Object)(object)__instance.m_animator != (Object)null) || !__instance.m_animator.GetBool("visible"))
				{
					return;
				}
				if (InventoryGui_Show_Patch._hasRecordedBaseOffsets)
				{
					int width = Screen.width;
					int height = Screen.height;
					if (InventoryGui_Show_Patch._lastScreenWidth != 0 && (InventoryGui_Show_Patch._lastScreenWidth != width || InventoryGui_Show_Patch._lastScreenHeight != height))
					{
						InventoryGui_Show_Patch._lastScreenWidth = width;
						InventoryGui_Show_Patch._lastScreenHeight = height;
						InventoryGui_Show_Patch._hasRecordedBaseOffsets = false;
						InventoryGui_Show_Patch.SetupScrollUI(__instance);
					}
					else
					{
						InventoryGui_Show_Patch._lastScreenWidth = width;
						InventoryGui_Show_Patch._lastScreenHeight = height;
					}
				}
				ScrollRect component3 = gameObject.GetComponent<ScrollRect>();
				if ((Object)(object)component3 != (Object)null && !InventoryGui_Show_Patch._needsClippingRefresh)
				{
					InventoryGui_Show_Patch._savedScrollNormalizedPosition = Mathf.Clamp01(component3.verticalNormalizedPosition);
				}
				if (!InventoryGui_Show_Patch._needsClippingRefresh)
				{
					return;
				}
				InventoryGui_Show_Patch._openingFrames++;
				int openingFrames = InventoryGui_Show_Patch._openingFrames;
				float num = (((ExpandedPlayerInventoryPlugin.RememberScrollPosition == null || ExpandedPlayerInventoryPlugin.RememberScrollPosition.Value) && InventoryGui_Show_Patch._isWorldSessionInitialized) ? InventoryGui_Show_Patch._savedScrollNormalizedPosition : 1f);
				if (openingFrames <= 3)
				{
					if ((Object)(object)playerGrid.m_gridRoot != (Object)null)
					{
						playerGrid.m_gridRoot.pivot = new Vector2(playerGrid.m_gridRoot.pivot.x, 1f);
					}
					if ((Object)(object)component3 != (Object)null)
					{
						component3.StopMovement();
						component3.verticalNormalizedPosition = num;
					}
					if ((Object)(object)playerGrid.m_scrollbar != (Object)null)
					{
						playerGrid.m_scrollbar.value = num;
					}
				}
				float num2 = Mathf.Abs(((Transform)component).lossyScale.y);
				rect = component.rect;
				float height2 = ((Rect)(ref rect)).height;
				float num3 = height2 * num2;
				if (openingFrames < 2 || height2 <= 10f || num3 <= 10f)
				{
					if ((Object)(object)component2 != (Object)null && ((Behaviour)component2).enabled)
					{
						((Behaviour)component2).enabled = false;
					}
					return;
				}
				bool num4 = num2 >= 0.8f || num3 >= height2 * 0.8f || openingFrames >= 8;
				bool flag = openingFrames >= 30;
				if (!num4 && !flag)
				{
					if ((Object)(object)component2 != (Object)null && ((Behaviour)component2).enabled)
					{
						((Behaviour)component2).enabled = false;
					}
					return;
				}
				InventoryGui_Show_Patch.EnsureScrollRect(__instance);
				if ((Object)(object)playerGrid.m_gridRoot != (Object)null)
				{
					playerGrid.m_gridRoot.pivot = new Vector2(playerGrid.m_gridRoot.pivot.x, 1f);
				}
				Canvas.ForceUpdateCanvases();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.StopMovement();
					component3.verticalNormalizedPosition = num;
				}
				if ((Object)(object)playerGrid.m_scrollbar != (Object)null)
				{
					playerGrid.m_scrollbar.value = num;
				}
				if ((Object)(object)component2 != (Object)null)
				{
					((Behaviour)component2).enabled = true;
					component2.PerformClipping();
				}
				InventoryGui_Show_Patch._isWorldSessionInitialized = true;
				InventoryGui_Show_Patch._needsClippingRefresh = false;
				InventoryGui_Show_Patch._openingFrames = 0;
				ExpandedPlayerInventoryPlugin.Log.LogInfo((object)$"Inventory opening synchronization completed at frame {openingFrames} (scale={num2:F2}, worldHeight={num3:F1}, scroll={num:F2})");
			}
			catch (Exception arg)
			{
				ExpandedPlayerInventoryPlugin.Log.LogError((object)$"InventoryGui_Update_Patch error: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Show")]
	[HarmonyPriority(200)]
	public static class InventoryGui_Show_Patch
	{
		internal static bool _isWorldSessionInitialized = false;

		internal static bool _needsClippingRefresh = false;

		internal static int _openingFrames = 0;

		internal static bool _hasRecordedBaseOffsets = false;

		internal static float _baseGridTopOffset = -60f;

		internal static float _baseGridAnchoredX = 0f;

		internal static float _savedScrollNormalizedPosition = 1f;

		internal static int _lastScreenWidth = 0;

		internal static int _lastScreenHeight = 0;

		public static void ResetSessionState()
		{
			_isWorldSessionInitialized = false;
			_needsClippingRefresh = false;
			_openingFrames = 0;
			_hasRecordedBaseOffsets = false;
			_savedScrollNormalizedPosition = 1f;
			_lastScreenWidth = 0;
			_lastScreenHeight = 0;
		}

		public static void Postfix(InventoryGui __instance)
		{
			EnsurePlayerInventoryScrollbar(__instance);
		}

		public static void EnsureScrollRect(InventoryGui gui)
		{
			if ((Object)(object)gui == (Object)null || (Object)(object)gui.m_playerGrid == (Object)null)
			{
				return;
			}
			InventoryGrid playerGrid = gui.m_playerGrid;
			GameObject gameObject = ((Component)playerGrid).gameObject;
			RectTransform component = gameObject.GetComponent<RectTransform>();
			if (!((Object)(object)component == (Object)null))
			{
				ScrollRect val = gameObject.GetComponent<ScrollRect>();
				if ((Object)(object)val == (Object)null)
				{
					val = gameObject.AddComponent<ScrollRect>();
				}
				val.content = playerGrid.m_gridRoot;
				val.viewport = component;
				val.verticalScrollbar = playerGrid.m_scrollbar;
				val.horizontal = false;
				val.vertical = true;
				val.scrollSensitivity = ((ExpandedPlayerInventoryPlugin.ScrollSensitivity != null && ExpandedPlayerInventoryPlugin.ScrollSensitivity.Value > 0f) ? ExpandedPlayerInventoryPlugin.ScrollSensitivity.Value : 350f);
				val.verticalScrollbarVisibility = (ScrollbarVisibility)0;
				ScrollRectEnsureVisible val2 = gameObject.GetComponent<ScrollRectEnsureVisible>();
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = gameObject.AddComponent<ScrollRectEnsureVisible>();
					val2.Initialize();
				}
				playerGrid.m_ensureVisible = val2;
			}
		}

		public static void SetupScrollUI(InventoryGui gui)
		{
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			//IL_049a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)gui == (Object)null || (Object)(object)gui.m_playerGrid == (Object)null)
			{
				return;
			}
			InventoryGrid playerGrid = gui.m_playerGrid;
			GameObject gameObject = ((Component)playerGrid).gameObject;
			RectTransform component = gameObject.GetComponent<RectTransform>();
			if ((Object)(object)component == (Object)null || (Object)(object)gameObject.transform.parent == (Object)null)
			{
				return;
			}
			int value = ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value;
			int num = Math.Min(6, Math.Max(4, value));
			float num2 = ((gui.m_invGridHeight > 0f) ? gui.m_invGridHeight : ((playerGrid.m_elementSpace > 0f) ? playerGrid.m_elementSpace : 70.5f));
			float num3 = (float)num * num2;
			if ((Object)(object)gui.m_player != (Object)null)
			{
				float num4 = gui.m_playerHeight + (float)(num - 4) * num2;
				gui.m_player.SetSizeWithCurrentAnchors((Axis)1, num4);
			}
			if (!_hasRecordedBaseOffsets)
			{
				_baseGridTopOffset = component.offsetMax.y;
				_baseGridAnchoredX = component.anchoredPosition.x;
				_hasRecordedBaseOffsets = true;
			}
			component.anchorMin = new Vector2(component.anchorMin.x, 1f);
			component.anchorMax = new Vector2(component.anchorMax.x, 1f);
			component.pivot = new Vector2(component.pivot.x, 1f);
			component.sizeDelta = new Vector2(component.sizeDelta.x, num3);
			component.anchoredPosition = new Vector2(_baseGridAnchoredX, _baseGridTopOffset);
			RectMask2D val = gameObject.GetComponent<RectMask2D>();
			if ((Object)(object)val == (Object)null)
			{
				val = gameObject.AddComponent<RectMask2D>();
			}
			((Behaviour)val).enabled = true;
			if ((Object)(object)playerGrid.m_scrollbar == (Object)null)
			{
				Scrollbar val2 = gui.m_recipeListScroll ?? gui.m_trophyListScroll ?? gui.m_achievementsListScroll ?? gui.m_containerGrid?.m_scrollbar ?? ((Component)gui).GetComponentInChildren<Scrollbar>(true);
				if ((Object)(object)val2 == (Object)null)
				{
					Scrollbar[] array = Resources.FindObjectsOfTypeAll<Scrollbar>();
					if (array != null && array.Length != 0)
					{
						val2 = ((IEnumerable<Scrollbar>)array).FirstOrDefault((Func<Scrollbar, bool>)delegate(Scrollbar sb)
						{
							//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)
							if ((Object)(object)sb != (Object)null && (Object)(object)((Component)sb).gameObject != (Object)null)
							{
								Scene scene = ((Component)sb).gameObject.scene;
								return ((Scene)(ref scene)).isLoaded;
							}
							return false;
						});
					}
				}
				GameObject val3;
				if ((Object)(object)val2 != (Object)null)
				{
					val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, gameObject.transform.parent, false);
					((Object)val3).name = "PlayerInventoryScrollbar";
					val3.SetActive(true);
					val3.transform.SetAsLastSibling();
					Scrollbar val4 = (playerGrid.m_scrollbar = val3.GetComponent<Scrollbar>());
					((Selectable)val4).interactable = true;
					((Behaviour)val4).enabled = true;
					Graphic[] componentsInChildren = val3.GetComponentsInChildren<Graphic>(true);
					foreach (Graphic val5 in componentsInChildren)
					{
						((Behaviour)val5).enabled = true;
						Color color = val5.color;
						if (color.a < 0.2f)
						{
							color.a = 1f;
							val5.color = color;
						}
					}
				}
				else
				{
					ExpandedPlayerInventoryPlugin.Log.LogWarning((object)"EnsurePlayerInventoryScrollbar: Template scrollbar not found; creating programmatic fallback scrollbar.");
					val3 = CreateProgrammaticScrollbar(gameObject.transform.parent);
					Scrollbar val4 = val3.GetComponent<Scrollbar>();
					playerGrid.m_scrollbar = val4;
				}
				RectTransform component2 = val3.GetComponent<RectTransform>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.anchorMin = new Vector2(1f, 1f);
					component2.anchorMax = new Vector2(1f, 1f);
					component2.pivot = new Vector2(1f, 1f);
					float num6 = 22f;
					component2.sizeDelta = new Vector2(num6, num3);
					component2.anchoredPosition = new Vector2(-15f, _baseGridTopOffset);
					Rect rect = component.rect;
					float num7 = ((Rect)(ref rect)).width + num6 + 50f;
					if ((Object)(object)gui.m_player != (Object)null)
					{
						rect = gui.m_player.rect;
						if (((Rect)(ref rect)).width < num7)
						{
							gui.m_player.SetSizeWithCurrentAnchors((Axis)0, num7);
						}
					}
				}
				ExpandedPlayerInventoryPlugin.Log.LogInfo((object)$"Player inventory scrollbar ready (configRows={value}, visibleRows={num})");
			}
			else
			{
				((Component)playerGrid.m_scrollbar).gameObject.SetActive(true);
				((Component)playerGrid.m_scrollbar).transform.SetAsLastSibling();
				Transform transform = ((Component)playerGrid.m_scrollbar).transform;
				RectTransform val6 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if ((Object)(object)val6 != (Object)null)
				{
					val6.anchorMin = new Vector2(1f, 1f);
					val6.anchorMax = new Vector2(1f, 1f);
					val6.pivot = new Vector2(1f, 1f);
					val6.sizeDelta = new Vector2((val6.sizeDelta.x > 0f) ? val6.sizeDelta.x : 22f, num3);
					val6.anchoredPosition = new Vector2(-15f, _baseGridTopOffset);
				}
			}
			EnsureScrollRect(gui);
		}

		private static GameObject CreateProgrammaticScrollbar(Transform parent)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("PlayerInventoryScrollbar", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Scrollbar)
			});
			val.transform.SetParent(parent, false);
			((Graphic)val.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.4f);
			GameObject val2 = new GameObject("Sliding Area", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent(val.transform, false);
			RectTransform component = val2.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.sizeDelta = Vector2.zero;
			GameObject val3 = new GameObject("Handle", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val3.transform.SetParent(val2.transform, false);
			RectTransform component2 = val3.GetComponent<RectTransform>();
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			component2.sizeDelta = Vector2.zero;
			Image component3 = val3.GetComponent<Image>();
			((Graphic)component3).color = new Color(0.8f, 0.7f, 0.5f, 0.8f);
			Scrollbar component4 = val.GetComponent<Scrollbar>();
			component4.handleRect = component2;
			((Selectable)component4).targetGraphic = (Graphic)(object)component3;
			component4.direction = (Direction)2;
			return val;
		}

		public static void EnsurePlayerInventoryScrollbar(InventoryGui gui)
		{
			//IL_0099: 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)
			try
			{
				if ((Object)(object)gui == (Object)null || (Object)(object)gui.m_playerGrid == (Object)null)
				{
					return;
				}
				SetupScrollUI(gui);
				InventoryGrid playerGrid = gui.m_playerGrid;
				GameObject gameObject = ((Component)playerGrid).gameObject;
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null)
				{
					return;
				}
				Inventory inventory = ((Humanoid)localPlayer).GetInventory();
				if (inventory == null)
				{
					return;
				}
				int value = ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value;
				if (inventory.GetHeight() < value)
				{
					inventory.SetHeight(value);
				}
				playerGrid.UpdateInventory(inventory, localPlayer, gui.m_dragItem);
				if ((Object)(object)playerGrid.m_gridRoot != (Object)null)
				{
					playerGrid.m_gridRoot.pivot = new Vector2(playerGrid.m_gridRoot.pivot.x, 1f);
				}
				float num = (((ExpandedPlayerInventoryPlugin.RememberScrollPosition == null || ExpandedPlayerInventoryPlugin.RememberScrollPosition.Value) && _isWorldSessionInitialized) ? _savedScrollNormalizedPosition : 1f);
				if ((Object)(object)playerGrid.m_scrollbar != (Object)null)
				{
					playerGrid.m_scrollbar.value = num;
				}
				ScrollRect component = gameObject.GetComponent<ScrollRect>();
				if ((Object)(object)component != (Object)null)
				{
					component.scrollSensitivity = ((ExpandedPlayerInventoryPlugin.ScrollSensitivity != null && ExpandedPlayerInventoryPlugin.ScrollSensitivity.Value > 0f) ? ExpandedPlayerInventoryPlugin.ScrollSensitivity.Value : 350f);
					component.StopMovement();
					component.verticalNormalizedPosition = num;
				}
				RectMask2D component2 = gameObject.GetComponent<RectMask2D>();
				if (_isWorldSessionInitialized)
				{
					if ((Object)(object)component2 != (Object)null)
					{
						((Behaviour)component2).enabled = true;
					}
					_needsClippingRefresh = false;
					_openingFrames = 0;
					return;
				}
				if ((Object)(object)component2 != (Object)null)
				{
					((Behaviour)component2).enabled = false;
				}
				_openingFrames = 0;
				_needsClippingRefresh = true;
				ExpandedPlayerInventoryPlugin.Log.LogInfo((object)$"EnsurePlayerInventoryScrollbar: initialized first-time open for world session, rows={Math.Max(inventory.GetHeight(), value)}");
			}
			catch (Exception arg)
			{
				ExpandedPlayerInventoryPlugin.Log.LogError((object)$"EnsurePlayerInventoryScrollbar error: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(Player), "SetInventorySize")]
	public static class Player_SetInventorySize_Patch
	{
		private static readonly MethodInfo Method_Inventory_SetHeight = AccessTools.Method(typeof(Inventory), "SetHeight", (Type[])null, (Type[])null);

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

		private static readonly MethodInfo Method_AtLeastConfigured = AccessTools.Method(typeof(Player_SetInventorySize_Patch), "AtLeastConfigured", (Type[])null, (Type[])null);

		private static readonly MethodInfo Method_GuiRows = AccessTools.Method(typeof(Player_SetInventorySize_Patch), "GuiRows", (Type[])null, (Type[])null);

		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			if (ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value <= 4)
			{
				return instructions;
			}
			List<CodeInstruction> list = instructions.ToList();
			try
			{
				return new CodeMatcher((IEnumerable<CodeInstruction>)list, (ILGenerator)null).MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Calls(i, Method_Inventory_SetHeight)), (string)null)
				}).ThrowIfNotMatch("No match for this.m_inventory.SetHeight(rows).", Array.Empty<CodeMatch>()).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Call, (object)Method_AtLeastConfigured)
				})
					.MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
					{
						new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Calls(i, Method_InventoryGui_SetInventorySize)), (string)null)
					})
					.ThrowIfNotMatch("No match for InventoryGui.instance.SetInventorySize(rows).", Array.Empty<CodeMatch>())
					.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
					{
						new CodeInstruction(OpCodes.Call, (object)Method_GuiRows)
					})
					.InstructionEnumeration();
			}
			catch (Exception arg)
			{
				ExpandedPlayerInventoryPlugin.Log.LogError((object)$"Player_SetInventorySize_Patch transpiler failed: {arg}");
				return list;
			}
		}

		public static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance == (Object)null || ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value <= 4)
			{
				return;
			}
			try
			{
				Inventory inventory = ((Humanoid)__instance).GetInventory();
				int value = ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value;
				if (inventory != null && inventory.GetHeight() < value)
				{
					inventory.SetHeight(value);
				}
			}
			catch (Exception arg)
			{
				ExpandedPlayerInventoryPlugin.Log.LogError((object)$"Player_SetInventorySize_Patch Postfix error: {arg}");
			}
		}

		public static int AtLeastConfigured(int rows)
		{
			return Math.Max(rows, ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value);
		}

		public static int GuiRows(int rows)
		{
			return Math.Min(6, AtLeastConfigured(rows));
		}
	}
	[HarmonyPatch(typeof(Humanoid), "DropInvalidItems")]
	public static class Humanoid_DropInvalidItems_Patch
	{
		[HarmonyPriority(800)]
		public static void Prefix(Humanoid __instance)
		{
			try
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (val != null && ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value > 4)
				{
					Inventory inventory = ((Humanoid)val).GetInventory();
					int value = ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value;
					if (inventory != null && inventory.GetHeight() < value)
					{
						inventory.SetHeight(value);
					}
				}
			}
			catch (Exception arg)
			{
				ExpandedPlayerInventoryPlugin.Log.LogError((object)$"Humanoid_DropInvalidItems_Patch error: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Load")]
	public static class Player_Load_Patch
	{
		public static void Prefix(Player __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value > 4)
			{
				Inventory inventory = ((Humanoid)__instance).GetInventory();
				int value = ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value;
				if (inventory.GetHeight() < value)
				{
					inventory.SetHeight(value);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "OnSpawned")]
	public static class Player_OnSpawned_Patch
	{
		public static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			int value = ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value;
			if (value > 4)
			{
				Inventory inventory = ((Humanoid)__instance).GetInventory();
				int num = Math.Max(inventory.GetHeight(), value);
				inventory.SetHeight(num);
				if ((Object)(object)InventoryGui.instance != (Object)null)
				{
					InventoryGui.instance.SetInventorySize(Math.Min(6, num));
				}
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "SetInventorySize")]
	public static class InventoryGui_SetInventorySize_Patch
	{
		[HarmonyPriority(800)]
		public static void Prefix(InventoryGui __instance, ref int rows)
		{
			try
			{
				int value = ExpandedPlayerInventoryPlugin.PlayerInventoryRows.Value;
				if (value > 4)
				{
					int num = Math.Min(6, Math.Max(4, value));
					rows = num;
				}
			}
			catch (Exception arg)
			{
				ExpandedPlayerInventoryPlugin.Log.LogError((object)$"InventoryGui_SetInventorySize_Patch error: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(Game), "Logout")]
	public static class Game_Logout_Patch
	{
		public static void Prefix()
		{
			InventoryGui_Show_Patch.ResetSessionState();
		}
	}
	[HarmonyPatch(typeof(Game), "Start")]
	public static class Game_Start_Patch
	{
		public static void Prefix()
		{
			InventoryGui_Show_Patch.ResetSessionState();
		}
	}
	[BepInPlugin("ckforgame.ExpandedPlayerInventory", "ExpandedPlayerInventory", "1.2.0")]
	public class ExpandedPlayerInventoryPlugin : BaseUnityPlugin
	{
		public const string ModGuid = "ckforgame.ExpandedPlayerInventory";

		public const string ModName = "ExpandedPlayerInventory";

		public const string ModVersion = "1.2.0";

		private Harmony _harmony;

		public static ExpandedPlayerInventoryPlugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		public static ConfigEntry<int> PlayerInventoryRows { get; private set; }

		public static ConfigEntry<float> ScrollSensitivity { get; private set; }

		public static ConfigEntry<bool> RememberScrollPosition { get; private set; }

		private void Awake()
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			string text = Path.Combine(Paths.ConfigPath, "com.custom.expandedplayerinventory.cfg");
			string text2 = Path.Combine(Paths.ConfigPath, "ckforgame.ExpandedPlayerInventory.cfg");
			if (File.Exists(text) && !File.Exists(text2))
			{
				try
				{
					File.Copy(text, text2);
					Log.LogInfo((object)("Migrated old configuration from '" + text + "' to '" + text2 + "'."));
					((BaseUnityPlugin)this).Config.Reload();
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("Failed to migrate old configuration: " + ex.Message));
				}
			}
			PlayerInventoryRows = ((BaseUnityPlugin)this).Config.Bind<int>("General", "playerInventoryRows", 20, new ConfigDescription("Number of player inventory rows (min 4, max 50).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(4, 50), Array.Empty<object>()));
			ScrollSensitivity = ((BaseUnityPlugin)this).Config.Bind<float>("General", "scrollSensitivity", 350f, new ConfigDescription("Mouse wheel scroll sensitivity for player inventory (default 350, min 50, max 1500). Higher values scroll faster with less finger movement.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(50f, 1500f), Array.Empty<object>()));
			RememberScrollPosition = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "rememberScrollPosition", true, new ConfigDescription("Remember the last scroll position when opening the inventory, instead of always jumping back to the top.", (AcceptableValueBase)null, Array.Empty<object>()));
			_harmony = new Harmony("ckforgame.ExpandedPlayerInventory");
			_harmony.PatchAll();
			Log.LogInfo((object)string.Format("{0} {1} loaded successfully! Configured rows: {2}, Scroll sensitivity: {3}, Remember scroll position: {4}", "ExpandedPlayerInventory", "1.2.0", PlayerInventoryRows.Value, ScrollSensitivity.Value, RememberScrollPosition.Value));
		}

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