Decompiled source of PeekaChest v1.0.0

PeekaChest.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("PeekaChest")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Show the contents of any chest when hovering over it. Inspired by ContentsWithin, ported for Valheim 1.0.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PeekaChest")]
[assembly: AssemblyTitle("PeekaChest")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ContentsWithin;

[BepInPlugin("com.yumileashen.valheim.peekachest", "PeekaChest", "1.0.0")]
public class ContentsWithin : BaseUnityPlugin
{
	public static class PlayerPatch
	{
		public static void UpdateHoverPostfix(Player __instance)
		{
			object obj = Get(PlayerHoveringField, __instance);
			GameObject val = (GameObject)((obj is GameObject) ? obj : null);
			if (isModEnabled.Value && !((Object)(object)lastHoverObject == (Object)(object)val))
			{
				lastHoverObject = val;
				lastHoverContainer = (Object.op_Implicit((Object)(object)lastHoverObject) ? lastHoverObject.GetComponentInParent<Container>() : null);
			}
		}
	}

	public static class InventoryGridPatch
	{
		public static void AwakePostfix(InventoryGrid __instance)
		{
			initializedGrids.Add(__instance);
		}
	}

	public static class InventoryGuiPatch
	{
		private static bool hierarchyDumped;

		private static float lastPreviewDebugTime;

		private static void DumpHierarchy(Transform t, int depth, StringBuilder sb)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if ((Object)(object)t == (Object)null || depth > 3)
			{
				return;
			}
			foreach (Transform item in t)
			{
				Transform val = item;
				sb.Append(new string(' ', depth * 2)).Append(((Object)val).name).Append(" active=")
					.Append(((Component)val).gameObject.activeSelf)
					.Append('\n');
				DumpHierarchy(val, depth + 1, sb);
			}
		}

		private static void EnsureAncestorsActive(Transform t, Transform stopAt)
		{
			while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)stopAt)
			{
				if (!((Component)t).gameObject.activeSelf)
				{
					((Component)t).gameObject.SetActive(true);
				}
				t = t.parent;
			}
		}

		public static void AwakePostfix(ref InventoryGui __instance)
		{
			object obj = Get(GuiPlayerField, __instance);
			object obj2 = ((obj is Component) ? obj : null);
			Transform obj3 = ((obj2 != null) ? ((Component)obj2).transform : null);
			Transform obj4 = obj3.Ref<Transform>();
			inventoryPanel = ((obj4 != null) ? ((Component)obj4).gameObject : null);
			playerPanelTransform = obj3;
			object obj5 = Get(GuiInfoPanelField, __instance);
			Component obj6 = ((Component)((obj5 is Component) ? obj5 : null)).Ref<Component>();
			infoPanel = ((obj6 != null) ? obj6.gameObject : null);
			object obj7 = Get(GuiInventoryRootField, __instance);
			Transform val = (Transform)((obj7 is Transform) ? obj7 : null);
			object craftingPanel;
			if (val == null)
			{
				craftingPanel = null;
			}
			else
			{
				Transform obj8 = val.Find("Crafting").Ref<Transform>();
				craftingPanel = ((obj8 != null) ? ((Component)obj8).gameObject : null);
			}
			ContentsWithin.craftingPanel = (GameObject)craftingPanel;
			object obj9 = Get(GuiTakeAllButtonField, __instance);
			Component obj10 = ((Component)((obj9 is Component) ? obj9 : null)).Ref<Component>();
			takeAllButton = ((obj10 != null) ? obj10.gameObject : null);
			object obj11 = Get(GuiStackAllButtonField, __instance);
			Component obj12 = ((Component)((obj11 is Component) ? obj11 : null)).Ref<Component>();
			stackAllButton = ((obj12 != null) ? obj12.gameObject : null);
			if (Chainloader.PluginInfos.ContainsKey("randyknapp.mods.auga"))
			{
				object craftingPanel2;
				if (val == null)
				{
					craftingPanel2 = null;
				}
				else
				{
					Transform obj13 = val.Find("RightPanel").Ref<Transform>();
					craftingPanel2 = ((obj13 != null) ? ((Component)obj13).gameObject : null);
				}
				ContentsWithin.craftingPanel = (GameObject)craftingPanel2;
			}
		}

		public static void ShowPostfix()
		{
			isRealGuiVisible = true;
		}

		public static void HidePostfix()
		{
			isRealGuiVisible = false;
		}

		public static void UpdatePrefix(InventoryGui __instance)
		{
			if (!ShowRealGUI())
			{
				object obj = Get(GuiAnimatorField, __instance);
				object obj2 = ((obj is Animator) ? obj : null);
				if (obj2 != null)
				{
					((Animator)obj2).SetBool("visible", false);
				}
			}
		}

		public static void UpdatePostfix(InventoryGui __instance)
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Expected O, but got Unknown
			bool flag = true;
			if (debugLogging.Value && Time.time - lastDebugLogTime > 1f)
			{
				lastDebugLogTime = Time.time;
				bool flag2 = Object.op_Implicit((Object)(object)lastHoverContainer) && HasContainerAccess(lastHoverContainer);
				Debug.Log((object)string.Format("{0} DEBUG hoverObj={1} hoverContainer={2} showRealGui={3} hasAccess={4}", "[PeekaChest]", lastHoverObject, lastHoverContainer, ShowRealGUI(), flag2));
			}
			if (Chainloader.PluginInfos.ContainsKey("org.bepinex.plugins.jewelcrafting"))
			{
				flag = !(jewelcraftingOpenInventoryField?.GetValue(null) is Inventory);
			}
			if ((Object)(object)playerPanelTransform != (Object)null)
			{
				foreach (Transform item in playerPanelTransform)
				{
					Transform val = item;
					if (!(((Object)val).name == "Container"))
					{
						((Component)val).gameObject.SetActive(ShowRealGUI());
					}
				}
			}
			GameObject obj = craftingPanel.Ref<GameObject>();
			if (obj != null)
			{
				obj.SetActive(ShowRealGUI());
			}
			GameObject obj2 = infoPanel.Ref<GameObject>();
			if (obj2 != null)
			{
				obj2.SetActive(ShowRealGUI());
			}
			GameObject obj3 = takeAllButton.Ref<GameObject>();
			if (obj3 != null)
			{
				obj3.SetActive(flag && ShowRealGUI());
			}
			GameObject obj4 = stackAllButton.Ref<GameObject>();
			if (obj4 != null)
			{
				obj4.SetActive(flag && ShowRealGUI());
			}
			if (Object.op_Implicit((Object)(object)takeAllButton) && Chainloader.PluginInfos.ContainsKey("goldenrevolver.quick_stack_store"))
			{
				bool flag3 = false;
				foreach (Transform item2 in takeAllButton.transform.parent)
				{
					Transform val2 = item2;
					switch (((Object)val2).name)
					{
					case "quickStackToContainerButton":
						flag3 = true;
						((Component)val2).gameObject.SetActive(flag && ShowRealGUI());
						break;
					case "storeAllButton":
					case "sortContainerButton":
					case "restockFromContainerButton":
						((Component)val2).gameObject.SetActive(flag && ShowRealGUI());
						break;
					}
				}
				if (flag3)
				{
					GameObject obj5 = stackAllButton.Ref<GameObject>();
					if (obj5 != null)
					{
						obj5.SetActive(false);
					}
				}
			}
			if (!ShowRealGUI())
			{
				if (HasContainerAccess(lastHoverContainer))
				{
					ShowPreviewContainer(lastHoverContainer.GetInventory());
				}
				else
				{
					HidePreviewContainer();
				}
			}
		}

		private static void HidePreviewContainer()
		{
			object obj = Get(GuiAnimatorField, InventoryGui.instance);
			object obj2 = ((obj is Animator) ? obj : null);
			if (obj2 != null)
			{
				((Animator)obj2).SetBool("visible", false);
			}
			object obj3 = Get(GuiContainerField, InventoryGui.instance);
			object obj4 = ((obj3 is Transform) ? obj3 : null);
			if (obj4 != null)
			{
				((Component)obj4).gameObject.SetActive(false);
			}
		}

		private static bool HasContainerAccess(Container container)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)container))
			{
				return false;
			}
			bool flag = PrivateArea.CheckAccess(((Component)container).transform.position, 0f, false, false);
			if (ContainerCheckAccessMethod == null)
			{
				return flag;
			}
			object instance = Get(GamePlayerProfileField, Game.instance);
			object obj = Get(ProfilePlayerIdField, instance);
			if (obj == null)
			{
				return flag;
			}
			ParameterInfo[] parameters = ContainerCheckAccessMethod.GetParameters();
			object[] array = new object[parameters.Length];
			array[0] = Convert.ChangeType(obj, parameters[0].ParameterType);
			for (int i = 1; i < parameters.Length; i++)
			{
				array[i] = (parameters[i].HasDefaultValue ? parameters[i].DefaultValue : GetDefault(parameters[i].ParameterType));
			}
			bool flag2;
			try
			{
				flag2 = (bool)ContainerCheckAccessMethod.Invoke(container, array);
			}
			catch (Exception arg)
			{
				Debug.LogError((object)string.Format("{0} CheckAccess invocation failed: {1}", "[PeekaChest]", arg));
				flag2 = false;
			}
			return flag && flag2;
		}

		public static bool SetupDragItemPrefix()
		{
			return ShowRealGUI();
		}

		private static void ShowPreviewContainer(Inventory container)
		{
			//IL_0048: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			((Component)InventoryGui.instance).gameObject.SetActive(true);
			object obj = Get(GuiAnimatorField, InventoryGui.instance);
			Animator val = (Animator)((obj is Animator) ? obj : null);
			if (val != null)
			{
				val.SetBool("visible", true);
			}
			string text = "";
			if ((Object)(object)val != (Object)null)
			{
				AnimatorStateInfo currentAnimatorStateInfo = val.GetCurrentAnimatorStateInfo(0);
				RectTransform component = ((Component)val).GetComponent<RectTransform>();
				text = string.Format("boolReadback={0} stateHash={1} normalizedTime={2:F2} enabled={3} scale={4} pos={5}", val.GetBool("visible"), ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash, ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime, ((Behaviour)val).enabled, (component != null) ? new Vector3?(((Transform)component).localScale) : ((Vector3?)null), (component != null) ? new Vector2?(component.anchoredPosition) : ((Vector2?)null));
			}
			CanvasGroup[] array = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponentsInParent<CanvasGroup>(true) : Array.Empty<CanvasGroup>());
			string text2 = string.Join(", ", array.Select((CanvasGroup cg) => $"{((Object)cg).name}(alpha={cg.alpha},interactable={cg.interactable},raycasts={cg.blocksRaycasts})"));
			CanvasGroup[] array2 = array;
			foreach (CanvasGroup obj2 in array2)
			{
				obj2.alpha = 1f;
				obj2.interactable = true;
				obj2.blocksRaycasts = true;
			}
			Set(GuiHiddenFramesField, InventoryGui.instance, 10);
			object obj3 = Get(GuiContainerField, InventoryGui.instance);
			Transform val2 = (Transform)((obj3 is Transform) ? obj3 : null);
			if (val2 != null)
			{
				((Component)val2).gameObject.SetActive(true);
			}
			if ((Object)(object)val2 != (Object)null)
			{
				EnsureAncestorsActive(val2.parent, ((Component)InventoryGui.instance).transform);
				if (!hierarchyDumped)
				{
					hierarchyDumped = true;
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.Append("[PeekaChest] DEBUG3 hierarchy from InventoryGui root:\n");
					DumpHierarchy(((Component)InventoryGui.instance).transform, 0, stringBuilder);
					Debug.Log((object)stringBuilder.ToString());
				}
			}
			object obj4 = Get(GuiContainerGridField, InventoryGui.instance);
			InventoryGrid val3 = (InventoryGrid)((obj4 is InventoryGrid) ? obj4 : null);
			if (debugLogging.Value && Time.time - lastPreviewDebugTime > 1f)
			{
				lastPreviewDebugTime = Time.time;
				string text3 = "";
				if ((Object)(object)val2 != (Object)null)
				{
					Transform val4 = val2;
					while ((Object)(object)val4 != (Object)null)
					{
						text3 += $"{((Object)val4).name}(active={((Component)val4).gameObject.activeSelf})<-";
						val4 = val4.parent;
					}
				}
				Debug.Log((object)string.Format("{0} DEBUG2 animator={1} animatorActive={2} [{3}] containerTransform={4} containerTransformActive={5} containerInHierarchy={6} ancestors=[{7}] containerGrid={8} inGridSet={9} canvasGroups=[{10}]", "[PeekaChest]", val, (val != null) ? new bool?(((Component)val).gameObject.activeInHierarchy) : ((bool?)null), text, val2, (val2 != null) ? new bool?(((Component)val2).gameObject.activeSelf) : ((bool?)null), (val2 != null) ? new bool?(((Component)val2).gameObject.activeInHierarchy) : ((bool?)null), text3, val3, (Object)(object)val3 != (Object)null && initializedGrids.Contains(val3), text2));
			}
			if (!((Object)(object)val3 == (Object)null) && (initializedGrids.Count <= 0 || initializedGrids.Contains(val3)))
			{
				val3.UpdateInventory(container, (Player)null, (ItemData)null);
				val3.ResetView();
				SetTextValue(Get(GuiContainerNameField, InventoryGui.instance), Localization.instance.Localize(container.GetName()));
				int num2 = Mathf.CeilToInt(container.GetTotalWeight());
				SetTextValue(Get(GuiContainerWeightField, InventoryGui.instance), num2.ToString());
			}
		}

		private static void SetTextValue(object textComponent, string value)
		{
			textComponent?.GetType().GetProperty("text")?.SetValue(textComponent, value);
		}
	}

	public const string PluginGUID = "com.yumileashen.valheim.peekachest";

	public const string PluginName = "PeekaChest";

	public const string PluginVersion = "1.0.0";

	private const string LogPrefix = "[PeekaChest]";

	private static ConfigEntry<bool> isModEnabled;

	private static ConfigEntry<bool> startHidden;

	private static ConfigEntry<KeyboardShortcut> toggleShowContentsShortcut;

	private static ConfigEntry<float> openDelayTime;

	private static ConfigEntry<bool> debugLogging;

	private static float lastDebugLogTime;

	private static bool isRealGuiVisible;

	private static bool showContent = true;

	private static float delayTime;

	private static Inventory emptyInventory = new Inventory("", (Sprite)null, 0, 0);

	private static HashSet<InventoryGrid> initializedGrids = new HashSet<InventoryGrid>();

	private static Container lastHoverContainer;

	private static GameObject lastHoverObject;

	private static GameObject inventoryPanel;

	private static Transform playerPanelTransform;

	private static GameObject infoPanel;

	private static GameObject craftingPanel;

	private static GameObject takeAllButton;

	private static GameObject stackAllButton;

	private Harmony harmony;

	private static FieldInfo jewelcraftingOpenInventoryField;

	private static readonly FieldInfo PlayerHoveringField = AccessTools.Field(typeof(Player), "m_hovering");

	private static readonly FieldInfo GuiPlayerField = AccessTools.Field(typeof(InventoryGui), "m_player");

	private static readonly FieldInfo GuiInfoPanelField = AccessTools.Field(typeof(InventoryGui), "m_infoPanel");

	private static readonly FieldInfo GuiInventoryRootField = AccessTools.Field(typeof(InventoryGui), "m_inventoryRoot");

	private static readonly FieldInfo GuiTakeAllButtonField = AccessTools.Field(typeof(InventoryGui), "m_takeAllButton");

	private static readonly FieldInfo GuiStackAllButtonField = AccessTools.Field(typeof(InventoryGui), "m_stackAllButton");

	private static readonly FieldInfo GuiAnimatorField = AccessTools.Field(typeof(InventoryGui), "m_animator");

	private static readonly FieldInfo GuiHiddenFramesField = AccessTools.Field(typeof(InventoryGui), "m_hiddenFrames");

	private static readonly FieldInfo GuiContainerField = AccessTools.Field(typeof(InventoryGui), "m_container");

	private static readonly FieldInfo GuiContainerGridField = AccessTools.Field(typeof(InventoryGui), "m_containerGrid");

	private static readonly FieldInfo GuiContainerNameField = AccessTools.Field(typeof(InventoryGui), "m_containerName");

	private static readonly FieldInfo GuiContainerWeightField = AccessTools.Field(typeof(InventoryGui), "m_containerWeight");

	private static readonly FieldInfo GamePlayerProfileField = AccessTools.Field(typeof(Game), "m_playerProfile");

	private static readonly FieldInfo ProfilePlayerIdField = AccessTools.Field(typeof(PlayerProfile), "m_playerID");

	private static readonly MethodInfo ContainerCheckAccessMethod = (from m in typeof(Container).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
		where m.Name == "CheckAccess"
		orderby m.GetParameters().Length
		select m).FirstOrDefault();

	private static object GetDefault(Type t)
	{
		if (!t.IsValueType)
		{
			return null;
		}
		return Activator.CreateInstance(t);
	}

	private static void WarnIfMissing(FieldInfo field, string name)
	{
		if (field == null)
		{
			Debug.LogWarning((object)("[PeekaChest] Field '" + name + "' not found — this game version renamed it, mod may misbehave."));
		}
	}

	private static object Get(FieldInfo field, object instance)
	{
		if (!(field == null) && instance != null)
		{
			return field.GetValue(instance);
		}
		return null;
	}

	private static void Set(FieldInfo field, object instance, object value)
	{
		field?.SetValue(instance, value);
	}

	private static FieldInfo GetJewelcraftingOpenInventoryField()
	{
		return AccessTools.Field(AccessTools.TypeByName("Jewelcrafting.GemStones+AddFakeSocketsContainer"), "openInventory");
	}

	private static bool TryPatch(Harmony h, Type targetType, string methodName, MethodInfo prefix, MethodInfo postfix, string label)
	{
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		MethodInfo methodInfo = AccessTools.Method(targetType, methodName, (Type[])null, (Type[])null);
		if (methodInfo == null)
		{
			string text = string.Join(", ", from n in (from m in targetType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
					select m.Name).Distinct()
				orderby n
				select n);
			Debug.LogWarning((object)("[PeekaChest] Could not find method '" + targetType.Name + "." + methodName + "' to patch (" + label + ") — this game version may have renamed it. Declared methods on " + targetType.Name + ": " + text));
			return false;
		}
		try
		{
			h.Patch((MethodBase)methodInfo, (!(prefix != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(prefix), (!(postfix != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(postfix), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return true;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)string.Format("{0} Failed to patch '{1}.{2}' ({3}): {4}", "[PeekaChest]", targetType.Name, methodName, label, ex));
			return false;
		}
	}

	public void Awake()
	{
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Expected O, but got Unknown
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		isModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("_Global", "isModEnabled", true, "Globally enable or disable this mod. When disabled, no container contents will be shown and hotkeys will not work.");
		startHidden = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "startHidden", false, "Hide the container contents until the hotkey is pressed.");
		openDelayTime = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "openDelayTime", 0.3f, "Time before the UI is closed when not hovering over a chest. This reduces the amount of animations when switching between chests.");
		toggleShowContentsShortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "toggleShowContentsShortcut", new KeyboardShortcut((KeyCode)112, (KeyCode[])(object)new KeyCode[1] { (KeyCode)303 }), "Shortcut to toggle on/off the 'show container contents' feature.");
		debugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "debugLogging", false, "Log hover/access state to the console once a second. Turn on for troubleshooting.");
		showContent = !startHidden.Value;
		WarnIfMissing(PlayerHoveringField, "Player.m_hovering");
		WarnIfMissing(GuiPlayerField, "InventoryGui.m_player");
		WarnIfMissing(GuiInfoPanelField, "InventoryGui.m_infoPanel");
		WarnIfMissing(GuiInventoryRootField, "InventoryGui.m_inventoryRoot");
		WarnIfMissing(GuiTakeAllButtonField, "InventoryGui.m_takeAllButton");
		WarnIfMissing(GuiStackAllButtonField, "InventoryGui.m_stackAllButton");
		WarnIfMissing(GuiAnimatorField, "InventoryGui.m_animator");
		WarnIfMissing(GuiHiddenFramesField, "InventoryGui.m_hiddenFrames");
		WarnIfMissing(GuiContainerField, "InventoryGui.m_container");
		WarnIfMissing(GuiContainerGridField, "InventoryGui.m_containerGrid");
		WarnIfMissing(GuiContainerNameField, "InventoryGui.m_containerName");
		WarnIfMissing(GuiContainerWeightField, "InventoryGui.m_containerWeight");
		WarnIfMissing(GamePlayerProfileField, "Game.m_playerProfile");
		WarnIfMissing(ProfilePlayerIdField, "PlayerProfile.m_playerID");
		if (ContainerCheckAccessMethod == null)
		{
			Debug.LogWarning((object)"[PeekaChest] Could not find Container.CheckAccess — falling back to area-only access checks.");
		}
		harmony = new Harmony("com.yumileashen.valheim.peekachest");
		int ok = 0;
		int total = 0;
		P(typeof(Player), "UpdateHover", null, AccessTools.Method(typeof(PlayerPatch), "UpdateHoverPostfix", (Type[])null, (Type[])null), "hover tracking");
		P(typeof(InventoryGrid), "OnEnable", null, AccessTools.Method(typeof(InventoryGridPatch), "AwakePostfix", (Type[])null, (Type[])null), "grid tracking");
		P(typeof(InventoryGui), "Awake", null, AccessTools.Method(typeof(InventoryGuiPatch), "AwakePostfix", (Type[])null, (Type[])null), "panel refs");
		P(typeof(InventoryGui), "Show", null, AccessTools.Method(typeof(InventoryGuiPatch), "ShowPostfix", (Type[])null, (Type[])null), "show flag");
		P(typeof(InventoryGui), "Hide", null, AccessTools.Method(typeof(InventoryGuiPatch), "HidePostfix", (Type[])null, (Type[])null), "hide flag");
		P(typeof(InventoryGui), "Update", AccessTools.Method(typeof(InventoryGuiPatch), "UpdatePrefix", (Type[])null, (Type[])null), AccessTools.Method(typeof(InventoryGuiPatch), "UpdatePostfix", (Type[])null, (Type[])null), "main update");
		P(typeof(InventoryGui), "SetupDragItem", AccessTools.Method(typeof(InventoryGuiPatch), "SetupDragItemPrefix", (Type[])null, (Type[])null), null, "drag guard");
		Debug.Log((object)string.Format("{0} v{1} loaded. Patched {2}/{3} methods successfully. Toggle key: {4}", "[PeekaChest]", "1.0.0", ok, total, toggleShowContentsShortcut.Value));
		void P(Type targetType, string methodName, MethodInfo prefix, MethodInfo postfix, string label)
		{
			total++;
			if (TryPatch(harmony, targetType, methodName, prefix, postfix, label))
			{
				ok++;
			}
		}
	}

	private void Start()
	{
		if (Chainloader.PluginInfos.ContainsKey("org.bepinex.plugins.jewelcrafting"))
		{
			jewelcraftingOpenInventoryField = GetJewelcraftingOpenInventoryField();
		}
	}

	private void Update()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (!isModEnabled.Value)
		{
			return;
		}
		KeyboardShortcut value = toggleShowContentsShortcut.Value;
		if (((KeyboardShortcut)(ref value)).IsDown())
		{
			showContent = !showContent;
			if (Object.op_Implicit((Object)(object)MessageHud.instance))
			{
				MessageHud.instance.ShowMessage((MessageType)2, $"ShowContainerContents: {showContent}", 0, (Sprite)null, false, true);
			}
			if (!showContent && !isRealGuiVisible && Object.op_Implicit((Object)(object)InventoryGui.instance))
			{
				InventoryGui.instance.Hide();
			}
		}
	}

	private static bool ShowRealGUI()
	{
		if (isModEnabled.Value && showContent)
		{
			return isRealGuiVisible;
		}
		return true;
	}
}
public static class ObjectExtensions
{
	public static T Ref<T>(this T o) where T : Object
	{
		if (!Object.op_Implicit((Object)(object)o))
		{
			return default(T);
		}
		return o;
	}
}