Decompiled source of MouseStacks v1.3.0

MouseStacks.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("1.3.0.0")]
namespace MouseStacks;

[BepInProcess("valheim.exe")]
[BepInPlugin("ovida.valheim.mousestacks", "Mouse Stacks", "1.3.0")]
public sealed class Plugin : BaseUnityPlugin
{
	private sealed class Slot
	{
		public InventoryGrid Grid;

		public Inventory Inventory;

		public Vector2i Position;

		public Image PreviewIcon;

		public TMP_Text PreviewAmount;
	}

	[HarmonyPatch(typeof(InventoryGui), "Update")]
	private static class GestureUpdatePatch
	{
		private static void Prefix(InventoryGui __instance)
		{
			UpdateGestures(__instance);
		}

		private static void Postfix(InventoryGui __instance)
		{
			UpdatePreviews(__instance);
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
	private static class DistributionStartPatch
	{
		private static bool Prefix(InventoryGui __instance, InventoryGrid __0, ItemData __1, Vector2i __2)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if (committing)
			{
				return true;
			}
			if (!modEnabled.Value || !distribution.Value)
			{
				return true;
			}
			if (distributingItem != null)
			{
				return false;
			}
			ItemData val = (ItemData)DragItem.GetValue(__instance);
			if (!Ready(__instance) || !ZInput.GetMouseButton(0) || __1 != null || !Stackable(val))
			{
				return true;
			}
			distributingItem = val;
			distributingInventory = (Inventory)DragInventory.GetValue(__instance);
			if (distributingInventory == null || !distributingInventory.ContainsItem(val))
			{
				CancelDistribution();
				return true;
			}
			AddSlot(__0, __2);
			if (Slots.Count == 0)
			{
				CancelDistribution();
				return true;
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "OnEnterElement")]
	private static class DistributionEnterPatch
	{
		private static void Postfix(InventoryGrid __0, Vector2i __1)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (distributingItem != null && ZInput.GetMouseButton(0))
			{
				AddSlot(__0, __1);
			}
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "Hide")]
	private static class HidePatch
	{
		private static void Prefix()
		{
			CancelDistribution();
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "SetupDragItem")]
	private static class CursorRaycastPatch
	{
		private static void Postfix(InventoryGui __instance)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if (!modEnabled.Value)
			{
				return;
			}
			GameObject val = (GameObject)DragGo.GetValue(__instance);
			if (Object.op_Implicit((Object)(object)val))
			{
				Graphic[] componentsInChildren = val.GetComponentsInChildren<Graphic>(true);
				foreach (Graphic val2 in componentsInChildren)
				{
					val2.raycastTarget = false;
				}
				CanvasGroup component = val.GetComponent<CanvasGroup>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.blocksRaycasts = false;
				}
			}
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "OnRightClickItem")]
	private static class RightClickPatch
	{
		private static bool Prefix(InventoryGui __instance, InventoryGrid __0, ItemData __1)
		{
			return !HandleRight(__instance, __0);
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "UpdateItemDrag")]
	private static class WheelPatch
	{
		private static void Prefix(InventoryGui __instance)
		{
			HandleWheel(__instance);
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo original = AccessTools.Method(typeof(ZInput), "GetMouseButton", new Type[1] { typeof(int) }, (Type[])null);
			MethodInfo replacement = AccessTools.Method(typeof(Plugin), "DragCancelButton", (Type[])null, (Type[])null);
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, original))
				{
					instruction.opcode = OpCodes.Call;
					instruction.operand = replacement;
				}
				yield return instruction;
			}
		}
	}

	[HarmonyPatch(typeof(ScrollRect), "OnScroll")]
	private static class ScrollPatch
	{
		private static bool Prefix()
		{
			return !HandleWheel(InventoryGui.instance);
		}
	}

	private Harmony harmony;

	private static ConfigEntry<bool> modEnabled;

	private static ConfigEntry<bool> rightClick;

	private static ConfigEntry<bool> wheelAdjust;

	private static ConfigEntry<bool> wheelStart;

	private static ConfigEntry<bool> middleClick;

	private static ConfigEntry<bool> distribution;

	private static ConfigEntry<bool> previews;

	private static ConfigEntry<KeyCode> useItemKey;

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

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

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

	private static readonly FieldInfo DragGo = AccessTools.Field(typeof(InventoryGui), "m_dragGo");

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

	private static readonly MethodInfo Hover = AccessTools.Method(typeof(InventoryGrid), "GetHoveredElement", (Type[])null, (Type[])null);

	private static readonly MethodInfo Position = AccessTools.Method(typeof(InventoryGrid), "GetElementPos", (Type[])null, (Type[])null);

	private static readonly List<RaycastResult> Hits = new List<RaycastResult>();

	private static int wheelFrame = -1;

	private static int consumedFrame = -1;

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

	private static readonly List<Slot> Slots = new List<Slot>();

	private static ItemData distributingItem;

	private static Inventory distributingInventory;

	private static bool committing;

	private static int rightFrame = -1;

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

	private void Awake()
	{
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Expected O, but got Unknown
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enable mod", true, "Enable Mouse Stacks. Disable to restore normal inventory controls.");
		rightClick = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Features", "Right-click to collect", true, "Pick up one item and add more by right-clicking the source stack. Disable to use or eat items with normal right-click, without holding a key.");
		wheelAdjust = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Features", "Scroll to adjust", true, "Use the wheel to adjust the carried quantity. Scrolling down to zero cancels the selection.");
		wheelStart = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Features", "Scroll to start", true, "Scroll up over a stack with an empty cursor to pick up one item.");
		middleClick = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Features", "Middle-click for half", true, "Pick up half a stack with the middle mouse button. Odd quantities round down.");
		distribution = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Features", "Drag to distribute", true, "Hold left-click across empty slots to distribute the carried stack on release. Remainders go to the first visited slots.");
		previews = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Features", "Distribution preview", true, "Show translucent icons and quantities while distributing. Distribution still works when this is disabled.");
		useItemKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("3 - Controls", "Use item modifier", (KeyCode)308, "Hold this key and right-click to use items (including food) instead of collecting them. LeftAlt or RightAlt accepts either Alt key. None disables this extra shortcut. Shift, Ctrl and Alt retain their normal inventory behavior.");
		((BaseUnityPlugin)this).Config.SettingChanged += OnSettingChanged;
		harmony = new Harmony("ovida.valheim.mousestacks");
		harmony.PatchAll(typeof(Plugin).Assembly);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Mouse Stacks 1.3.0 loaded: individual feature settings and configurable item-use modifier.");
	}

	private void OnSettingChanged(object sender, SettingChangedEventArgs args)
	{
		CancelDistribution();
		wheelFrame = (consumedFrame = (rightFrame = -1));
	}

	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.SettingChanged -= OnSettingChanged;
		CancelDistribution();
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	private static bool UseItemModifierHeld()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: 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_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Invalid comparison between Unknown and I4
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Invalid comparison between Unknown and I4
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		KeyCode value = useItemKey.Value;
		if ((int)value == 0)
		{
			return false;
		}
		if ((int)value == 308 || (int)value == 307)
		{
			if (!ZInput.GetKey((KeyCode)308, true))
			{
				return ZInput.GetKey((KeyCode)307, true);
			}
			return true;
		}
		return ZInput.GetKey(value, true);
	}

	private static bool Modified()
	{
		if (!ZInput.GetKey((KeyCode)308, true) && !ZInput.GetKey((KeyCode)307, true) && !ZInput.GetKey((KeyCode)304, true) && !ZInput.GetKey((KeyCode)303, true) && !ZInput.GetKey((KeyCode)306, true))
		{
			return ZInput.GetKey((KeyCode)305, true);
		}
		return true;
	}

	private static bool Ready(InventoryGui gui)
	{
		if (modEnabled.Value && Object.op_Implicit((Object)(object)gui) && InventoryGui.IsVisible() && Object.op_Implicit((Object)(object)Player.m_localPlayer) && ZInput.IsMouseActive() && !ZInput.IsTouchActive())
		{
			return !Modified();
		}
		return false;
	}

	private static bool Stackable(ItemData item)
	{
		if (item != null && item.m_shared != null && item.m_shared.m_maxStackSize > 1)
		{
			return item.m_stack > 0;
		}
		return false;
	}

	private static void Select(InventoryGui gui, ItemData item, Inventory inv, int amount)
	{
		Setup.Invoke(gui, new object[3] { item, inv, amount });
	}

	private static void Adjust(InventoryGui gui, int delta)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		ItemData val = (ItemData)DragItem.GetValue(gui);
		Inventory val2 = (Inventory)DragInventory.GetValue(gui);
		if (val == null || val2 == null || !val2.ContainsItem(val) || val.m_stack <= 0)
		{
			Select(gui, null, null, 0);
			return;
		}
		int num = AdjustedAmount((int)DragAmount.GetValue(gui), val.m_stack, delta);
		if (num == 0)
		{
			Select(gui, null, null, 0);
		}
		else
		{
			DragAmount.SetValue(gui, num);
		}
	}

	private static InventoryGrid HoveredGrid()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_001a: 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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)EventSystem.current))
		{
			return null;
		}
		PointerEventData val = new PointerEventData(EventSystem.current);
		val.position = Vector2.op_Implicit(ZInput.pointerPosition);
		Hits.Clear();
		EventSystem.current.RaycastAll(val, Hits);
		GameObject val2 = ((!Object.op_Implicit((Object)(object)InventoryGui.instance)) ? ((GameObject)null) : ((GameObject)DragGo.GetValue(InventoryGui.instance)));
		foreach (RaycastResult hit in Hits)
		{
			RaycastResult current = hit;
			if (Object.op_Implicit((Object)(object)((RaycastResult)(ref current)).gameObject) && (!Object.op_Implicit((Object)(object)val2) || !((RaycastResult)(ref current)).gameObject.transform.IsChildOf(val2.transform)))
			{
				return ((RaycastResult)(ref current)).gameObject.GetComponentInParent<InventoryGrid>();
			}
		}
		return null;
	}

	private static ItemData HoveredItem(InventoryGrid grid)
	{
		//IL_003b: 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)
		if (!Object.op_Implicit((Object)(object)grid) || grid.GetInventory() == null)
		{
			return null;
		}
		object obj = Hover.Invoke(grid, null);
		if (obj == null)
		{
			return null;
		}
		Vector2i val = (Vector2i)Position.Invoke(grid, new object[1] { obj });
		return grid.GetInventory().GetItemAt(val.x, val.y);
	}

	private static bool HandleWheel(InventoryGui gui)
	{
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		if (!modEnabled.Value || (!wheelAdjust.Value && !wheelStart.Value))
		{
			return false;
		}
		if (distributingItem != null)
		{
			return true;
		}
		if (consumedFrame == Time.frameCount)
		{
			return true;
		}
		if (wheelFrame == Time.frameCount || !Ready(gui))
		{
			return false;
		}
		float mouseScrollWheel = ZInput.GetMouseScrollWheel();
		if (mouseScrollWheel == 0f)
		{
			return false;
		}
		InventoryGrid val = HoveredGrid();
		ItemData val2 = (ItemData)DragItem.GetValue(gui);
		if (val2 != null)
		{
			if (!wheelAdjust.Value || !Stackable(val2))
			{
				return false;
			}
			wheelFrame = (consumedFrame = Time.frameCount);
			Adjust(gui, (mouseScrollWheel > 0f) ? 1 : (-1));
			return true;
		}
		val2 = HoveredItem(val);
		if (!wheelStart.Value || mouseScrollWheel < 0f || !Stackable(val2))
		{
			return false;
		}
		wheelFrame = (consumedFrame = Time.frameCount);
		Select(gui, val2, val.GetInventory(), 1);
		return true;
	}

	private static void CancelDistribution()
	{
		foreach (Slot slot in Slots)
		{
			ClearPreview(slot);
		}
		Slots.Clear();
		distributingItem = null;
		distributingInventory = null;
	}

	private static void ClearPreview(Slot slot)
	{
		if (Object.op_Implicit((Object)(object)slot.PreviewIcon))
		{
			((Component)slot.PreviewIcon).gameObject.SetActive(false);
			Object.Destroy((Object)(object)((Component)slot.PreviewIcon).gameObject);
		}
		if (Object.op_Implicit((Object)(object)slot.PreviewAmount))
		{
			((Component)slot.PreviewAmount).gameObject.SetActive(false);
			Object.Destroy((Object)(object)((Component)slot.PreviewAmount).gameObject);
		}
		slot.PreviewIcon = null;
		slot.PreviewAmount = null;
	}

	private static void UpdatePreviews(InventoryGui gui)
	{
		//IL_0110: 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_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		if (!previews.Value || distributingItem == null)
		{
			return;
		}
		List<Slot> list = Slots.FindAll(ValidSlot);
		foreach (Slot slot2 in Slots)
		{
			if (!ValidSlot(slot2))
			{
				ClearPreview(slot2);
			}
		}
		int total = Math.Max(0, Math.Min((int)DragAmount.GetValue(gui), distributingItem.m_stack));
		for (int i = 0; i < list.Count; i++)
		{
			Slot slot = list[i];
			if (!Object.op_Implicit((Object)(object)slot.PreviewIcon) || !Object.op_Implicit((Object)(object)slot.PreviewAmount))
			{
				ClearPreview(slot);
				foreach (InventoryElement item in (List<InventoryElement>)Elements.GetValue(slot.Grid))
				{
					Vector2i val = (Vector2i)Position.Invoke(slot.Grid, new object[1] { item });
					if (val.x == slot.Position.x && val.y == slot.Position.y)
					{
						slot.PreviewIcon = Object.Instantiate<Image>(item.m_icon, ((Component)item.m_icon).transform.parent);
						slot.PreviewAmount = Object.Instantiate<TMP_Text>(item.m_amount, item.m_amount.transform.parent);
						((Object)slot.PreviewIcon).name = "MouseStacksPreviewIcon";
						((Object)slot.PreviewAmount).name = "MouseStacksPreviewAmount";
						((Graphic)slot.PreviewIcon).raycastTarget = false;
						((Graphic)slot.PreviewAmount).raycastTarget = false;
						((Component)slot.PreviewIcon).transform.SetAsLastSibling();
						slot.PreviewAmount.transform.SetAsLastSibling();
						break;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)slot.PreviewIcon) && Object.op_Implicit((Object)(object)slot.PreviewAmount))
			{
				int num = Math.Min(Share(total, list.Count, i), distributingItem.m_shared.m_maxStackSize);
				slot.PreviewIcon.sprite = distributingItem.GetIcon();
				((Graphic)slot.PreviewIcon).color = new Color(1f, 1f, 1f, 0.45f);
				((Behaviour)slot.PreviewIcon).enabled = true;
				slot.PreviewAmount.text = num.ToString();
				((Graphic)slot.PreviewAmount).color = new Color(1f, 1f, 1f, 0.85f);
				((Behaviour)slot.PreviewAmount).enabled = true;
				((Component)slot.PreviewIcon).gameObject.SetActive(num > 0);
				((Component)slot.PreviewAmount).gameObject.SetActive(true);
			}
		}
	}

	private static bool ValidSlot(Slot slot)
	{
		if (Object.op_Implicit((Object)(object)slot.Grid) && ((Behaviour)slot.Grid).isActiveAndEnabled && object.ReferenceEquals(slot.Grid.GetInventory(), slot.Inventory) && slot.Position.x >= 0 && slot.Position.y >= 0 && slot.Position.x < slot.Inventory.GetWidth() && slot.Position.y < slot.Inventory.GetHeight())
		{
			return slot.Inventory.GetItemAt(slot.Position.x, slot.Position.y) == null;
		}
		return false;
	}

	private static void AddSlot(InventoryGrid grid, Vector2i pos)
	{
		//IL_002b: 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)grid) || grid.GetInventory() == null)
		{
			return;
		}
		Slot slot = new Slot();
		slot.Grid = grid;
		slot.Inventory = grid.GetInventory();
		slot.Position = pos;
		Slot slot2 = slot;
		if (!ValidSlot(slot2) || (distributingItem.m_shared.m_questItem && !object.ReferenceEquals(slot2.Inventory, distributingInventory)))
		{
			return;
		}
		foreach (Slot slot3 in Slots)
		{
			if (object.ReferenceEquals(slot3.Inventory, slot2.Inventory) && slot3.Position.x == pos.x && slot3.Position.y == pos.y)
			{
				return;
			}
		}
		Slots.Add(slot2);
	}

	internal static int Share(int total, int count, int index)
	{
		return total / count + ((index < total % count) ? 1 : 0);
	}

	internal static int Half(int total)
	{
		return Math.Max(1, total / 2);
	}

	internal static int AdjustedAmount(int current, int available, int delta)
	{
		current = Math.Max(0, Math.Min(current, available));
		return (int)Math.Max(0L, Math.Min((long)current + (long)delta, available));
	}

	private static void FinishDistribution(InventoryGui gui)
	{
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		ItemData val = distributingItem;
		Inventory val2 = distributingInventory;
		List<Slot> list = Slots.FindAll(ValidSlot);
		int num = Math.Min((int)DragAmount.GetValue(gui), val.m_stack);
		CancelDistribution();
		if (list.Count == 0 || num <= 0)
		{
			return;
		}
		int total = num;
		committing = true;
		try
		{
			for (int i = 0; i < list.Count; i++)
			{
				if (num <= 0)
				{
					break;
				}
				Slot slot = list[i];
				int num2 = Math.Min(Share(total, list.Count, i), val.m_shared.m_maxStackSize);
				if (num2 > 0 && ValidSlot(slot) && val2.ContainsItem(val))
				{
					num2 = Math.Min(num2, Math.Min(num, val.m_stack));
					int stack = val.m_stack;
					Select(gui, val, val2, num2);
					Selected.Invoke(gui, new object[4]
					{
						slot.Grid,
						null,
						slot.Position,
						(object)(Modifier)0
					});
					int val3 = (val2.ContainsItem(val) ? Math.Max(0, stack - val.m_stack) : stack);
					num -= Math.Min(num2, val3);
				}
			}
		}
		finally
		{
			committing = false;
			if (num > 0 && val2.ContainsItem(val) && val.m_stack > 0)
			{
				Select(gui, val, val2, Math.Min(num, val.m_stack));
			}
			else
			{
				Select(gui, null, null, 0);
			}
		}
	}

	private static void UpdateGestures(InventoryGui gui)
	{
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		if (distributingItem != null)
		{
			if (!distribution.Value || !Ready(gui) || !Application.isFocused || !object.ReferenceEquals(DragItem.GetValue(gui), distributingItem) || !object.ReferenceEquals(DragInventory.GetValue(gui), distributingInventory) || !distributingInventory.ContainsItem(distributingItem))
			{
				CancelDistribution();
				return;
			}
			InventoryGrid val = HoveredGrid();
			if (Object.op_Implicit((Object)(object)val))
			{
				object obj = Hover.Invoke(val, null);
				if (obj != null)
				{
					AddSlot(val, (Vector2i)Position.Invoke(val, new object[1] { obj }));
				}
			}
			if (ZInput.GetMouseButtonUp(0))
			{
				FinishDistribution(gui);
			}
			else if (!ZInput.GetMouseButton(0))
			{
				CancelDistribution();
			}
		}
		else
		{
			if (!Ready(gui))
			{
				return;
			}
			if (ZInput.GetMouseButtonDown(1))
			{
				HandleRight(gui, HoveredGrid());
			}
			if (middleClick.Value && ZInput.GetMouseButtonDown(2) && DragItem.GetValue(gui) == null)
			{
				InventoryGrid val2 = HoveredGrid();
				ItemData val3 = HoveredItem(val2);
				if (Stackable(val3))
				{
					Select(gui, val3, val2.GetInventory(), Half(val3.m_stack));
				}
			}
		}
	}

	private static bool HandleRight(InventoryGui gui, InventoryGrid grid)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		if (!modEnabled.Value || !rightClick.Value || UseItemModifierHeld())
		{
			return false;
		}
		if (rightFrame == Time.frameCount || distributingItem != null)
		{
			return true;
		}
		if (!Ready(gui) || !Object.op_Implicit((Object)(object)grid))
		{
			return false;
		}
		ItemData val = (ItemData)DragItem.GetValue(gui);
		ItemData val2 = HoveredItem(grid);
		if (val != null)
		{
			if (Stackable(val) && object.ReferenceEquals(val, val2) && object.ReferenceEquals(DragInventory.GetValue(gui), grid.GetInventory()))
			{
				Adjust(gui, 1);
			}
			rightFrame = Time.frameCount;
			return true;
		}
		if (!Stackable(val2))
		{
			return false;
		}
		Inventory inventory = grid.GetInventory();
		if (inventory == null || !inventory.ContainsItem(val2))
		{
			return false;
		}
		rightFrame = Time.frameCount;
		Select(gui, val2, inventory, 1);
		return true;
	}

	private static bool DragCancelButton(int button)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		InventoryGui instance = InventoryGui.instance;
		if (button == 1 && rightClick.Value && !UseItemModifierHeld() && Ready(instance) && Stackable((ItemData)DragItem.GetValue(instance)))
		{
			return false;
		}
		return ZInput.GetMouseButton(button);
	}
}