Decompiled source of Aicho Mouse Tweaks v1.0.0

Aicho_MouseTweaks.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[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 AichoMouseTweaks
{
	[BepInPlugin("aicho.mousetweaks", "Aicho_MouseTweaks", "0.1.13")]
	public class AichoMouseTweaksPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "aicho.mousetweaks";

		public const string PluginName = "Aicho_MouseTweaks";

		public const string PluginVersion = "0.1.13";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> HalfSplitEnabled;

		internal static ConfigEntry<bool> ShiftMoveEnabled;

		internal static ConfigEntry<bool> RightClickPlaceOneEnabled;

		internal static ConfigEntry<bool> LeftDragSplitEnabled;

		internal static ConfigEntry<bool> DragCollectEnabled;

		internal static ConfigEntry<bool> ShiftSweepMoveEnabled;

		internal static ConfigEntry<bool> WheelEnabled;

		internal static ConfigEntry<WheelDirection> WheelDirectionMode;

		internal static ConfigEntry<bool> WheelSearchFromEnd;

		internal static ConfigEntry<int> WheelShiftAmount;

		internal static ConfigEntry<bool> DropKeyEnabled;

		internal static ConfigEntry<KeyCode> DropKey;

		internal static ConfigEntry<bool> MoveAllOfTypeEnabled;

		internal static ConfigEntry<bool> HotbarKeysEnabled;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			HalfSplitEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Dividir a la mitad", "Activado", true, "Ctrl + clic derecho sobre un stack (con el cursor vacío) lo divide a la mitad. La mitad más grande queda en el cursor y la otra en el slot.");
			ShiftMoveEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Shift + clic para mover", "Activado", true, "Shift + clic izquierdo pasa el ítem al cofre abierto (o del cofre al inventario), completando primero los stacks iguales. Reemplaza la ventana 'Split Stack' de vanilla. Sin cofre abierto no hace nada.");
			RightClickPlaceOneEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Clic derecho con stack en el cursor", "Activado", true, "Con un stack en el cursor, cada clic derecho sobre un slot deja 1 ítem. Manteniendo el clic derecho y arrastrando, deja 1 ítem en cada slot que tocas; si vuelves a pasar por un slot, le suma otro.");
			LeftDragSplitEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Repartir en partes iguales", "Activado", true, "Con un stack en el cursor, mantén el clic izquierdo y pasa por varios slots: el stack se reparte en partes iguales entre todos ellos. Lo que no se puede dividir exacto queda en el cursor.");
			DragCollectEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Juntar ítems iguales", "Activado", true, "Como en Minecraft: toma un ítem con clic izquierdo y, sin soltar, pasa por otros slots con el mismo ítem: se van juntando en el cursor (hasta llenar el stack).");
			ShiftSweepMoveEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("6 - Shift + arrastrar para mover varios", "Activado", true, "Con el cursor vacío y un cofre abierto, mantén Shift + clic izquierdo y pasa el mouse por los ítems: cada uno se mueve al otro inventario (del jugador al cofre o al revés). Sin cofre abierto no hace nada.");
			WheelEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("7 - Rueda del mouse", "Activado", true, "Con el cursor vacío y un cofre abierto, usa la rueda sobre un ítem para moverlo de 1 en 1: una dirección manda 1 unidad al otro inventario y la otra trae 1 unidad del mismo tipo desde el otro inventario.");
			WheelDirectionMode = ((BaseUnityPlugin)this).Config.Bind<WheelDirection>("7 - Rueda del mouse", "DireccionRueda", WheelDirection.SegunPosicion, "SegunPosicion (por defecto): la rueda mueve el ítem como se ve en pantalla. Tu inventario está arriba y el cofre abajo, así que rueda abajo = hacia el cofre y rueda arriba = hacia tu inventario, sin importar sobre cuál esté el mouse. Normal: rueda abajo manda el ítem al otro lado y rueda arriba lo trae. Invertida: al revés de Normal.");
			WheelSearchFromEnd = ((BaseUnityPlugin)this).Config.Bind<bool>("7 - Rueda del mouse", "BuscarDesdeElFinal", true, "Al traer un ítem desde el otro inventario, de qué stack se toma: true = del último slot al primero, false = del primero al último.");
			WheelShiftAmount = ((BaseUnityPlugin)this).Config.Bind<int>("7 - Rueda del mouse", "CantidadConShift", 5, "Cuántas unidades mueve cada paso de la rueda con Shift presionado. 0 = el stack completo.");
			DropKeyEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("8 - Tirar con tecla", "Activado", true, "Con el mouse sobre un ítem (inventario o cofre) y el cursor vacío: la tecla tira 1 unidad al suelo; con Shift tira el stack completo; con Ctrl tira todos los ítems de ese tipo de ese inventario (menos los equipados).");
			DropKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("8 - Tirar con tecla", "Tecla", (KeyCode)113, "Tecla para tirar ítems.");
			MoveAllOfTypeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("9 - Mover todos los del mismo tipo", "Activado", true, "Con un cofre abierto, Ctrl + Shift + clic izquierdo sobre un ítem mueve al otro lado todos los ítems de ese tipo (aunque estén en varios slots). Los ítems equipados no se mueven.");
			HotbarKeysEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("10 - Teclas 1 a 8 para la barra rápida", "Activado", true, "Con el mouse sobre un ítem (inventario o cofre) y el cursor vacío, las teclas 1 a 8 lo mandan a ese slot de la barra rápida. Si ya había algo ahí, se intercambian.");
			_harmony = new Harmony("aicho.mousetweaks");
			_harmony.PatchAll(typeof(AichoMouseTweaksPlugin).Assembly);
			Log.LogInfo((object)"Aicho_MouseTweaks 0.1.13 cargado");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class DragAccess
	{
		private static readonly FieldRef<InventoryGui, GameObject> DragGoRef = AccessTools.FieldRefAccess<InventoryGui, GameObject>("m_dragGo");

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

		private static readonly FieldRef<InventoryGui, ItemData> DragItemRef = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_dragItem");

		private static readonly FieldRef<InventoryGui, Inventory> DragInventoryRef = AccessTools.FieldRefAccess<InventoryGui, Inventory>("m_dragInventory");

		private static readonly FieldRef<InventoryGui, int> DragAmountRef = AccessTools.FieldRefAccess<InventoryGui, int>("m_dragAmount");

		private static readonly FieldRef<InventoryGui, InventoryGrid> ContainerGridRef = AccessTools.FieldRefAccess<InventoryGui, InventoryGrid>("m_containerGrid");

		private static readonly FieldRef<InventoryGui, Container> CurrentContainerRef = AccessTools.FieldRefAccess<InventoryGui, Container>("m_currentContainer");

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

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

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

		internal static Container CurrentContainer(InventoryGui gui)
		{
			return CurrentContainerRef.Invoke(gui);
		}

		internal static void SelectSlot(InventoryGui gui, InventoryGrid grid, Vector2i pos)
		{
			//IL_0006: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			ItemData itemAt = grid.GetInventory().GetItemAt(pos.x, pos.y);
			OnSelectedItemMethod.Invoke(gui, new object[4]
			{
				grid,
				itemAt,
				pos,
				(object)(Modifier)0
			});
		}

		internal static ref ItemData DragItem(InventoryGui gui)
		{
			return ref DragItemRef.Invoke(gui);
		}

		internal static ref Inventory DragInventory(InventoryGui gui)
		{
			return ref DragInventoryRef.Invoke(gui);
		}

		internal static ref int DragAmount(InventoryGui gui)
		{
			return ref DragAmountRef.Invoke(gui);
		}

		internal static bool TryGetHoveredSlot(InventoryGui gui, out InventoryGrid grid, out Vector2i pos)
		{
			if (TryGetHoveredSlot(gui.m_playerGrid, out pos))
			{
				grid = gui.m_playerGrid;
				return true;
			}
			InventoryGrid val = ContainerGridRef.Invoke(gui);
			if (TryGetHoveredSlot(val, out pos))
			{
				grid = val;
				return true;
			}
			grid = null;
			return false;
		}

		private static bool TryGetHoveredSlot(InventoryGrid grid, out Vector2i pos)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			pos = new Vector2i(-1, -1);
			if ((Object)(object)grid == (Object)null || !((Behaviour)grid).isActiveAndEnabled || grid.GetInventory() == null)
			{
				return false;
			}
			object obj = GetHoveredElementMethod.Invoke(grid, null);
			if (obj == null)
			{
				return false;
			}
			pos = (Vector2i)GetElementPosMethod.Invoke(grid, new object[1] { obj });
			if (pos.x >= 0)
			{
				return pos.y >= 0;
			}
			return false;
		}

		internal static bool IsDragging(InventoryGui gui)
		{
			return (Object)(object)DragGoRef.Invoke(gui) != (Object)null;
		}

		internal static void SetupDragItem(InventoryGui gui, ItemData item, Inventory inventory, int amount)
		{
			SetupDragItemMethod.Invoke(gui, new object[3] { item, inventory, amount });
		}
	}
	public enum WheelDirection
	{
		Normal,
		Invertida,
		SegunPosicion
	}
	internal static class InvUtil
	{
		internal static List<ItemData> ItemsInGridOrder(Inventory inventory)
		{
			List<ItemData> list = new List<ItemData>(inventory.GetAllItems());
			list.Sort((ItemData a, ItemData b) => (a.m_gridPos.y == b.m_gridPos.y) ? a.m_gridPos.x.CompareTo(b.m_gridPos.x) : a.m_gridPos.y.CompareTo(b.m_gridPos.y));
			return list;
		}

		internal static bool TryFindEmptySlot(Inventory inventory, out Vector2i pos)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			for (int i = 0; i < inventory.GetHeight(); i++)
			{
				for (int j = 0; j < inventory.GetWidth(); j++)
				{
					if (inventory.GetItemAt(j, i) == null)
					{
						pos = new Vector2i(j, i);
						return true;
					}
				}
			}
			pos = new Vector2i(-1, -1);
			return false;
		}

		internal static int MoveUnits(Inventory fromInventory, ItemData item, Inventory toInventory, Vector2i pos, int amount)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			int stack = item.m_stack;
			toInventory.MoveItemToThis(fromInventory, item, amount, pos.x, pos.y);
			return stack - item.m_stack;
		}

		internal static void UnequipIfLastUnit(Player player, ItemData item, int amount)
		{
			if (amount >= item.m_stack && ((Humanoid)player).IsItemEquiped(item))
			{
				((Humanoid)player).RemoveEquipAction(item);
				((Humanoid)player).UnequipItem(item, false);
			}
		}
	}
	internal static class InputUtil
	{
		internal static bool IsCtrlHeld()
		{
			if (!ZInput.GetKey((KeyCode)306, true))
			{
				return ZInput.GetKey((KeyCode)305, true);
			}
			return true;
		}

		internal static bool IsShiftHeld()
		{
			if (!ZInput.GetKey((KeyCode)304, true))
			{
				return ZInput.GetKey((KeyCode)303, true);
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnRightClickItem")]
	internal static class RightClickPatch
	{
		private static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemData item, Vector2i pos)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)grid == (Object)null)
			{
				return true;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsTeleporting())
			{
				return true;
			}
			if (DragAccess.IsDragging(__instance))
			{
				if (!AichoMouseTweaksPlugin.RightClickPlaceOneEnabled.Value)
				{
					return true;
				}
				RightClickPlaceOne.Begin(__instance, grid, pos);
				return false;
			}
			if (!AichoMouseTweaksPlugin.HalfSplitEnabled.Value || !InputUtil.IsCtrlHeld() || item == null)
			{
				return true;
			}
			if (item.m_stack <= 1)
			{
				return false;
			}
			int amount = (item.m_stack + 1) / 2;
			DragAccess.SetupDragItem(__instance, item, grid.GetInventory(), amount);
			RightMouseCancelGuard.SuppressUntilRightReleased();
			return false;
		}
	}
	internal static class RightClickPlaceOne
	{
		private static bool _painting;

		private static InventoryGrid _lastGrid;

		private static Vector2i _lastPos;

		internal static void Begin(InventoryGui gui, InventoryGrid grid, Vector2i pos)
		{
			//IL_000c: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			_painting = true;
			_lastGrid = grid;
			_lastPos = pos;
			RightMouseCancelGuard.SuppressUntilRightReleased();
			PlaceOne(gui, grid, pos);
		}

		internal static void Tick(InventoryGui gui)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			if (_painting)
			{
				InventoryGrid grid;
				Vector2i pos;
				if (!ZInput.GetMouseButton(1) || !DragAccess.IsDragging(gui))
				{
					_painting = false;
					_lastGrid = null;
				}
				else if (!DragAccess.TryGetHoveredSlot(gui, out grid, out pos))
				{
					_lastGrid = null;
				}
				else if (!((Object)(object)grid == (Object)(object)_lastGrid) || pos.x != _lastPos.x || pos.y != _lastPos.y)
				{
					_lastGrid = grid;
					_lastPos = pos;
					PlaceOne(gui, grid, pos);
				}
			}
		}

		private static void PlaceOne(InventoryGui gui, InventoryGrid grid, Vector2i pos)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			ItemData val = DragAccess.DragItem(gui);
			Inventory val2 = DragAccess.DragInventory(gui);
			Inventory inventory = grid.GetInventory();
			Player localPlayer = Player.m_localPlayer;
			if (val == null || val2 == null || inventory == null || (Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			if (!val2.ContainsItem(val))
			{
				DragAccess.SetupDragItem(gui, null, null, 1);
			}
			else
			{
				if (val.m_shared.m_questItem && val2 != inventory)
				{
					return;
				}
				ItemData itemAt = inventory.GetItemAt(pos.x, pos.y);
				if (itemAt == val || (itemAt != null && (!itemAt.IsSameType(val) || itemAt.m_stack >= itemAt.m_shared.m_maxStackSize)))
				{
					return;
				}
				if (val.m_stack <= 1 && ((Humanoid)localPlayer).IsItemEquiped(val))
				{
					((Humanoid)localPlayer).RemoveEquipAction(val);
					((Humanoid)localPlayer).UnequipItem(val, false);
				}
				int stack = val.m_stack;
				inventory.MoveItemToThis(val2, val, 1, pos.x, pos.y);
				int num = stack - val.m_stack;
				if (num > 0)
				{
					ref int reference = ref DragAccess.DragAmount(gui);
					reference = Mathf.Min(reference - num, val.m_stack);
					if (reference <= 0 || !val2.ContainsItem(val))
					{
						DragAccess.SetupDragItem(gui, null, null, 1);
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
	internal static class ShiftMovePatch
	{
		private static bool Prefix(InventoryGui __instance, ItemData item, ref Modifier mod)
		{
			if (!AichoMouseTweaksPlugin.ShiftMoveEnabled.Value || (int)mod != 1 || !InputUtil.IsShiftHeld())
			{
				return true;
			}
			if (item == null || DragAccess.IsDragging(__instance))
			{
				return true;
			}
			if (!__instance.IsContainerOpen())
			{
				return false;
			}
			mod = (Modifier)2;
			return true;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
	internal static class LeftDragSplitPatch
	{
		private static bool Prefix(InventoryGui __instance, InventoryGrid grid, Vector2i pos)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (!AichoMouseTweaksPlugin.LeftDragSplitEnabled.Value || (Object)(object)grid == (Object)null || !DragAccess.IsDragging(__instance))
			{
				return true;
			}
			if (ZInput.IsTouchActive() || !ZInput.GetMouseButton(0) || InputUtil.IsCtrlHeld())
			{
				return true;
			}
			return !LeftDragSplit.TryBegin(__instance, grid, pos);
		}
	}
	internal static class LeftDragSplit
	{
		private struct Target
		{
			public Inventory Inventory;

			public InventoryGrid Grid;

			public Vector2i Pos;

			public int Placed;
		}

		private static bool _active;

		private static Inventory _srcInventory;

		private static Vector2i _srcPos;

		private static int _total;

		private static readonly List<Target> _targets = new List<Target>();

		internal static bool TryBegin(InventoryGui gui, InventoryGrid grid, Vector2i pos)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			ItemData val = DragAccess.DragItem(gui);
			Inventory val2 = DragAccess.DragInventory(gui);
			Player localPlayer = Player.m_localPlayer;
			if (val == null || val2 == null || (Object)(object)localPlayer == (Object)null || !val2.ContainsItem(val))
			{
				return false;
			}
			if (val.m_shared.m_maxStackSize <= 1 || ((Humanoid)localPlayer).IsItemEquiped(val))
			{
				return false;
			}
			if (!IsValidTarget(val, val2, grid.GetInventory(), pos))
			{
				return false;
			}
			_active = true;
			_srcInventory = val2;
			_srcPos = val.m_gridPos;
			_total = Mathf.Min(DragAccess.DragAmount(gui), val.m_stack);
			_targets.Clear();
			_targets.Add(new Target
			{
				Inventory = grid.GetInventory(),
				Grid = grid,
				Pos = pos
			});
			Redistribute(gui);
			return true;
		}

		internal static void Tick(InventoryGui gui)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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)
			if (!_active)
			{
				return;
			}
			if (!DragAccess.IsDragging(gui))
			{
				End();
			}
			else if (!ZInput.GetMouseButton(0))
			{
				if (DragAccess.DragAmount(gui) <= 0)
				{
					DragAccess.SetupDragItem(gui, null, null, 1);
				}
				End();
			}
			else
			{
				if (!DragAccess.TryGetHoveredSlot(gui, out var grid, out var pos))
				{
					return;
				}
				Inventory inventory = grid.GetInventory();
				foreach (Target target in _targets)
				{
					if (target.Inventory == inventory && target.Pos.x == pos.x && target.Pos.y == pos.y)
					{
						return;
					}
				}
				if (_targets.Count < _total)
				{
					ItemData val = SourceItem() ?? DragAccess.DragItem(gui);
					if (val != null && IsValidTarget(val, _srcInventory, inventory, pos))
					{
						_targets.Add(new Target
						{
							Inventory = inventory,
							Grid = grid,
							Pos = pos
						});
						Redistribute(gui);
					}
				}
			}
		}

		private static void End()
		{
			_active = false;
			_targets.Clear();
			_srcInventory = null;
		}

		private static ItemData SourceItem()
		{
			Inventory srcInventory = _srcInventory;
			if (srcInventory == null)
			{
				return null;
			}
			return srcInventory.GetItemAt(_srcPos.x, _srcPos.y);
		}

		private static bool IsValidTarget(ItemData item, Inventory fromInventory, Inventory toInventory, Vector2i pos)
		{
			//IL_0003: 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_0057: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (toInventory == null || pos.x < 0 || pos.y < 0)
			{
				return false;
			}
			if (item.m_shared.m_questItem && fromInventory != toInventory)
			{
				return false;
			}
			if (toInventory == fromInventory && pos.x == item.m_gridPos.x && pos.y == item.m_gridPos.y)
			{
				return false;
			}
			ItemData itemAt = toInventory.GetItemAt(pos.x, pos.y);
			if (itemAt != null)
			{
				if (itemAt.IsSameType(item))
				{
					return itemAt.m_stack < itemAt.m_shared.m_maxStackSize;
				}
				return false;
			}
			return true;
		}

		private static void Redistribute(InventoryGui gui)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _targets.Count; i++)
			{
				Target value = _targets[i];
				if (value.Placed > 0)
				{
					ItemData itemAt = value.Inventory.GetItemAt(value.Pos.x, value.Pos.y);
					if (itemAt != null)
					{
						_srcInventory.MoveItemToThis(value.Inventory, itemAt, value.Placed, _srcPos.x, _srcPos.y);
					}
					value.Placed = 0;
					_targets[i] = value;
				}
			}
			ItemData val = SourceItem();
			if (val == null)
			{
				End();
				return;
			}
			int num = _total / _targets.Count;
			int num2 = 0;
			for (int j = 0; j < _targets.Count; j++)
			{
				if (num <= 0)
				{
					break;
				}
				Target value2 = _targets[j];
				int stack = val.m_stack;
				value2.Inventory.MoveItemToThis(_srcInventory, val, num, value2.Pos.x, value2.Pos.y);
				value2.Placed = stack - val.m_stack;
				num2 += value2.Placed;
				_targets[j] = value2;
				if (val.m_stack <= 0)
				{
					break;
				}
			}
			ItemData val2 = SourceItem();
			DragAccess.DragItem(gui) = val2 ?? val;
			DragAccess.DragAmount(gui) = _total - num2;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
	internal static class DragCollectPatch
	{
		private static void Prefix(InventoryGui __instance, out bool __state)
		{
			__state = DragAccess.IsDragging(__instance);
		}

		private static void Postfix(InventoryGui __instance, InventoryGrid grid, Vector2i pos, bool __state)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!__state && AichoMouseTweaksPlugin.DragCollectEnabled.Value && !((Object)(object)grid == (Object)null) && DragAccess.IsDragging(__instance) && !ZInput.IsTouchActive() && ZInput.GetMouseButton(0) && !InputUtil.IsCtrlHeld() && !InputUtil.IsShiftHeld())
			{
				DragCollect.BeginAfterPickup(__instance, grid, pos);
			}
		}
	}
	internal static class DragCollect
	{
		private static bool _active;

		private static Inventory _lastInventory;

		private static Vector2i _lastPos;

		internal static void BeginAfterPickup(InventoryGui gui, 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)
			ItemData val = DragAccess.DragItem(gui);
			if (val != null && val.m_shared.m_maxStackSize > 1)
			{
				_active = true;
				_lastInventory = grid.GetInventory();
				_lastPos = pos;
			}
		}

		internal static void Tick(InventoryGui gui)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (!_active)
			{
				return;
			}
			if (!ZInput.GetMouseButton(0) || !DragAccess.IsDragging(gui))
			{
				_active = false;
				_lastInventory = null;
				return;
			}
			if (!DragAccess.TryGetHoveredSlot(gui, out var grid, out var pos))
			{
				_lastInventory = null;
				return;
			}
			Inventory inventory = grid.GetInventory();
			if (inventory != _lastInventory || pos.x != _lastPos.x || pos.y != _lastPos.y)
			{
				_lastInventory = inventory;
				_lastPos = pos;
				CollectFrom(gui, inventory, pos);
			}
		}

		private static void CollectFrom(InventoryGui gui, Inventory slotInventory, Vector2i pos)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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_00d7: 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)
			ItemData val = DragAccess.DragItem(gui);
			Inventory val2 = DragAccess.DragInventory(gui);
			Player localPlayer = Player.m_localPlayer;
			if (val == null || val2 == null || slotInventory == null || (Object)(object)localPlayer == (Object)null || !val2.ContainsItem(val))
			{
				return;
			}
			ItemData itemAt = slotInventory.GetItemAt(pos.x, pos.y);
			if (itemAt == null || itemAt == val || !itemAt.IsSameType(val) || (itemAt.m_shared.m_questItem && slotInventory != val2))
			{
				return;
			}
			int maxStackSize = val.m_shared.m_maxStackSize;
			int num = Mathf.Min(DragAccess.DragAmount(gui), val.m_stack);
			if (num >= maxStackSize)
			{
				return;
			}
			if (val.m_stack > num)
			{
				if (itemAt.m_stack + num <= maxStackSize && (!val.m_shared.m_questItem || slotInventory == val2))
				{
					int amount = itemAt.m_stack + num;
					if (InvUtil.MoveUnits(val2, val, slotInventory, pos, num) == num)
					{
						SetCursor(gui, slotInventory.GetItemAt(pos.x, pos.y), slotInventory, amount);
					}
					return;
				}
				if (InvUtil.TryFindEmptySlot(val2, out var pos2))
				{
					if (InvUtil.MoveUnits(val2, val, val2, pos2, num) != num)
					{
						return;
					}
					val = val2.GetItemAt(pos2.x, pos2.y);
					SetCursor(gui, val, val2, num);
				}
			}
			int num2 = Mathf.Min(maxStackSize - val.m_stack, itemAt.m_stack);
			if (num2 > 0)
			{
				if (num2 >= itemAt.m_stack && ((Humanoid)localPlayer).IsItemEquiped(itemAt))
				{
					((Humanoid)localPlayer).RemoveEquipAction(itemAt);
					((Humanoid)localPlayer).UnequipItem(itemAt, false);
				}
				int num3 = InvUtil.MoveUnits(slotInventory, itemAt, val2, val.m_gridPos, num2);
				if (num3 > 0)
				{
					DragAccess.DragAmount(gui) += num3;
				}
			}
		}

		private static void SetCursor(InventoryGui gui, ItemData item, Inventory inventory, int amount)
		{
			if (item != null)
			{
				DragAccess.DragItem(gui) = item;
				DragAccess.DragInventory(gui) = inventory;
				DragAccess.DragAmount(gui) = Mathf.Min(amount, item.m_stack);
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
	internal static class ShiftSweepMovePatch
	{
		private static void Prefix(InventoryGui __instance, InventoryGrid grid, Vector2i pos)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (AichoMouseTweaksPlugin.ShiftSweepMoveEnabled.Value && !((Object)(object)grid == (Object)null) && !DragAccess.IsDragging(__instance) && !ZInput.IsTouchActive() && ZInput.GetMouseButton(0) && InputUtil.IsShiftHeld() && !InputUtil.IsCtrlHeld() && !((Object)(object)DragAccess.CurrentContainer(__instance) == (Object)null))
			{
				ShiftSweepMove.Begin(grid.GetInventory(), pos);
			}
		}
	}
	internal static class ShiftSweepMove
	{
		private static bool _active;

		private static Inventory _lastInventory;

		private static Vector2i _lastPos;

		internal static void Begin(Inventory inventory, Vector2i pos)
		{
			//IL_000c: 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)
			_active = true;
			_lastInventory = inventory;
			_lastPos = pos;
		}

		internal static void Tick(InventoryGui gui)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (!_active)
			{
				return;
			}
			Container val = DragAccess.CurrentContainer(gui);
			if (!ZInput.GetMouseButton(0) || !InputUtil.IsShiftHeld() || (Object)(object)val == (Object)null || DragAccess.IsDragging(gui))
			{
				_active = false;
				_lastInventory = null;
				return;
			}
			if (!DragAccess.TryGetHoveredSlot(gui, out var grid, out var pos))
			{
				_lastInventory = null;
				return;
			}
			Inventory inventory = grid.GetInventory();
			if (inventory != _lastInventory || pos.x != _lastPos.x || pos.y != _lastPos.y)
			{
				_lastInventory = inventory;
				_lastPos = pos;
				MoveToOtherSide(inventory, val, pos);
			}
		}

		private static void MoveToOtherSide(Inventory inventory, Container container, Vector2i pos)
		{
			//IL_0007: 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)
			Player localPlayer = Player.m_localPlayer;
			ItemData itemAt = inventory.GetItemAt(pos.x, pos.y);
			if (!((Object)(object)localPlayer == (Object)null) && itemAt != null && !itemAt.m_shared.m_questItem)
			{
				Inventory inventory2 = container.GetInventory();
				Inventory inventory3 = ((Humanoid)localPlayer).GetInventory();
				((Humanoid)localPlayer).RemoveEquipAction(itemAt);
				((Humanoid)localPlayer).UnequipItem(itemAt, true);
				if (inventory == inventory2)
				{
					inventory3.MoveItemToThis(inventory, itemAt);
				}
				else
				{
					inventory2.MoveItemToThis(inventory3, itemAt);
				}
			}
		}
	}
	internal static class WheelMove
	{
		private static Container _container;

		private static Inventory _hoverInventory;

		private static Vector2i _hoverPos;

		private static ItemData _sample;

		private static bool _hasPartner;

		private static Vector2i _partnerPos;

		internal static void Tick(InventoryGui gui)
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			if (!AichoMouseTweaksPlugin.WheelEnabled.Value || ZInput.IsTouchActive() || !ZInput.IsMouseActive())
			{
				return;
			}
			float mouseScrollWheel = ZInput.GetMouseScrollWheel();
			if (mouseScrollWheel == 0f || DragAccess.IsDragging(gui))
			{
				return;
			}
			Container val = DragAccess.CurrentContainer(gui);
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)val == (Object)null || (Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsTeleporting() || !DragAccess.TryGetHoveredSlot(gui, out var grid, out var pos))
			{
				return;
			}
			Inventory inventory = grid.GetInventory();
			if ((Object)(object)val != (Object)(object)_container || inventory != _hoverInventory || pos.x != _hoverPos.x || pos.y != _hoverPos.y)
			{
				_container = val;
				_hoverInventory = inventory;
				_hoverPos = pos;
				_sample = null;
				_hasPartner = false;
			}
			ItemData itemAt = inventory.GetItemAt(pos.x, pos.y);
			if (itemAt != null)
			{
				if (_sample != null && !itemAt.IsSameType(_sample))
				{
					_hasPartner = false;
				}
				_sample = itemAt;
			}
			if (_sample == null || _sample.m_shared.m_questItem)
			{
				return;
			}
			Inventory inventory2 = val.GetInventory();
			bool flag = inventory == inventory2;
			Inventory val2 = (flag ? ((Humanoid)localPlayer).GetInventory() : inventory2);
			bool flag2 = mouseScrollWheel > 0f;
			bool flag3 = AichoMouseTweaksPlugin.WheelDirectionMode.Value switch
			{
				WheelDirection.Invertida => flag2, 
				WheelDirection.SegunPosicion => flag ? flag2 : (!flag2), 
				_ => !flag2, 
			};
			int amount = 1;
			if (InputUtil.IsShiftHeld())
			{
				int value = AichoMouseTweaksPlugin.WheelShiftAmount.Value;
				amount = ((value <= 0) ? _sample.m_shared.m_maxStackSize : value);
			}
			if (flag3)
			{
				if (itemAt != null)
				{
					Send(localPlayer, inventory, itemAt, val2, amount);
				}
			}
			else
			{
				Pull(localPlayer, inventory, pos, val2, amount);
			}
		}

		private static bool PartnerAccepts(Inventory otherInventory)
		{
			if (!_hasPartner)
			{
				return false;
			}
			ItemData itemAt = otherInventory.GetItemAt(_partnerPos.x, _partnerPos.y);
			if (itemAt != null)
			{
				if (itemAt.IsSameType(_sample))
				{
					return itemAt.m_stack < itemAt.m_shared.m_maxStackSize;
				}
				return false;
			}
			return true;
		}

		private static ItemData PartnerSource(Inventory otherInventory)
		{
			if (!_hasPartner)
			{
				return null;
			}
			ItemData itemAt = otherInventory.GetItemAt(_partnerPos.x, _partnerPos.y);
			if (itemAt == null || !itemAt.IsSameType(_sample) || itemAt.m_shared.m_questItem)
			{
				return null;
			}
			return itemAt;
		}

		private static void Send(Player player, Inventory fromInventory, ItemData item, Inventory toInventory, int amount)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Min(amount, item.m_stack);
			Vector2i pos = default(Vector2i);
			while (num > 0 && fromInventory.ContainsItem(item))
			{
				if (!PartnerAccepts(toInventory))
				{
					((Vector2i)(ref pos))..ctor(-1, -1);
					foreach (ItemData item2 in InvUtil.ItemsInGridOrder(toInventory))
					{
						if (item2.IsSameType(item) && item2.m_stack < item2.m_shared.m_maxStackSize)
						{
							pos = item2.m_gridPos;
							break;
						}
					}
					if (pos.x < 0 && !InvUtil.TryFindEmptySlot(toInventory, out pos))
					{
						break;
					}
					_hasPartner = true;
					_partnerPos = pos;
				}
				InvUtil.UnequipIfLastUnit(player, item, num);
				int num2 = InvUtil.MoveUnits(fromInventory, item, toInventory, _partnerPos, num);
				if (num2 <= 0)
				{
					break;
				}
				num -= num2;
			}
		}

		private static void Pull(Player player, Inventory toInventory, Vector2i pos, Inventory fromInventory, int amount)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			ItemData itemAt = toInventory.GetItemAt(pos.x, pos.y);
			int num = Mathf.Min(amount, _sample.m_shared.m_maxStackSize - (itemAt?.m_stack ?? 0));
			while (num > 0)
			{
				ItemData val = PartnerSource(fromInventory);
				if (val == null)
				{
					List<ItemData> list = InvUtil.ItemsInGridOrder(fromInventory);
					if (AichoMouseTweaksPlugin.WheelSearchFromEnd.Value)
					{
						list.Reverse();
					}
					foreach (ItemData item in list)
					{
						if (item.IsSameType(_sample) && !item.m_shared.m_questItem)
						{
							val = item;
							break;
						}
					}
					if (val == null)
					{
						break;
					}
					_hasPartner = true;
					_partnerPos = val.m_gridPos;
				}
				int amount2 = Mathf.Min(num, val.m_stack);
				InvUtil.UnequipIfLastUnit(player, val, amount2);
				int num2 = InvUtil.MoveUnits(fromInventory, val, toInventory, pos, amount2);
				if (num2 <= 0)
				{
					break;
				}
				num -= num2;
			}
		}
	}
	internal static class DropKey
	{
		internal static bool IsDropping(InventoryGui gui, out InventoryGrid grid, out ItemData item)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			grid = null;
			item = null;
			if (!AichoMouseTweaksPlugin.DropKeyEnabled.Value || ZInput.IsTouchActive() || !ZInput.GetKeyDown(AichoMouseTweaksPlugin.DropKey.Value, true))
			{
				return false;
			}
			if (((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) || Console.IsVisible() || TextInput.IsVisible())
			{
				return false;
			}
			if (DragAccess.IsDragging(gui) || !DragAccess.TryGetHoveredSlot(gui, out grid, out var pos))
			{
				return false;
			}
			item = grid.GetInventory().GetItemAt(pos.x, pos.y);
			return item != null;
		}

		internal static void Tick(InventoryGui gui)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsTeleporting() || !IsDropping(gui, out var grid, out var item))
			{
				return;
			}
			Inventory inventory = grid.GetInventory();
			if (InputUtil.IsCtrlHeld())
			{
				string name = item.m_shared.m_name;
				{
					foreach (ItemData item2 in InvUtil.ItemsInGridOrder(inventory))
					{
						if (item2.m_shared.m_name == name && !((Humanoid)localPlayer).IsItemEquiped(item2))
						{
							((Humanoid)localPlayer).DropItem(inventory, item2, item2.m_stack);
						}
					}
					return;
				}
			}
			int num = ((!InputUtil.IsShiftHeld()) ? 1 : item.m_stack);
			bool flag = ((Humanoid)localPlayer).IsItemEquiped(item);
			if (((Humanoid)localPlayer).DropItem(inventory, item, num) && flag && inventory.ContainsItem(item))
			{
				((Humanoid)localPlayer).EquipItem(item, false);
			}
		}
	}
	[HarmonyPatch(typeof(TabHandler), "Update")]
	internal static class TabHandlerDropKeyPatch
	{
		private static bool Prefix()
		{
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null || !InventoryGui.IsVisible())
			{
				return true;
			}
			InventoryGrid grid;
			ItemData item;
			return !DropKey.IsDropping(instance, out grid, out item);
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
	internal static class MoveAllOfTypePatch
	{
		private static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemData item)
		{
			if (!AichoMouseTweaksPlugin.MoveAllOfTypeEnabled.Value || (Object)(object)grid == (Object)null || item == null || DragAccess.IsDragging(__instance))
			{
				return true;
			}
			if (ZInput.IsTouchActive() || !InputUtil.IsShiftHeld() || !InputUtil.IsCtrlHeld())
			{
				return true;
			}
			Container val = DragAccess.CurrentContainer(__instance);
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)val == (Object)null || (Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsTeleporting())
			{
				return false;
			}
			Inventory inventory = grid.GetInventory();
			Inventory val2 = ((inventory == val.GetInventory()) ? ((Humanoid)localPlayer).GetInventory() : val.GetInventory());
			string name = item.m_shared.m_name;
			foreach (ItemData item2 in InvUtil.ItemsInGridOrder(inventory))
			{
				if (!(item2.m_shared.m_name != name) && !item2.m_shared.m_questItem && !((Humanoid)localPlayer).IsItemEquiped(item2))
				{
					val2.MoveItemToThis(inventory, item2);
				}
			}
			return false;
		}
	}
	internal static class HotbarKeys
	{
		internal static void Tick(InventoryGui gui)
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			if (!AichoMouseTweaksPlugin.HotbarKeysEnabled.Value || ZInput.IsTouchActive() || DragAccess.IsDragging(gui) || ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) || Console.IsVisible() || TextInput.IsVisible() || ZInput.GetMouseButton(0) || ZInput.GetMouseButton(1))
			{
				return;
			}
			int num = -1;
			for (int i = 1; i <= 8; i++)
			{
				if (ZInput.GetButtonDown($"Hotbar{i}"))
				{
					num = i - 1;
					break;
				}
			}
			Player localPlayer = Player.m_localPlayer;
			if (num < 0 || (Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsTeleporting() || !DragAccess.TryGetHoveredSlot(gui, out var grid, out var pos))
			{
				return;
			}
			Inventory inventory = grid.GetInventory();
			ItemData itemAt = inventory.GetItemAt(pos.x, pos.y);
			InventoryGrid playerGrid = gui.m_playerGrid;
			Vector2i val = default(Vector2i);
			((Vector2i)(ref val))..ctor(num, 0);
			if (itemAt != null && !((Object)(object)playerGrid == (Object)null) && (inventory != playerGrid.GetInventory() || pos.x != val.x || pos.y != val.y))
			{
				DragAccess.SetupDragItem(gui, itemAt, inventory, itemAt.m_stack);
				DragAccess.SelectSlot(gui, playerGrid, val);
				if (DragAccess.IsDragging(gui))
				{
					DragAccess.SetupDragItem(gui, null, null, 1);
				}
			}
		}
	}
	internal static class RightMouseCancelGuard
	{
		private static bool _suppress;

		internal static void SuppressUntilRightReleased()
		{
			_suppress = true;
		}

		internal static void ClearIfReleased()
		{
			if (_suppress && !ZInput.GetMouseButton(1))
			{
				_suppress = false;
			}
		}

		internal static bool GetMouseButton(int button)
		{
			bool mouseButton = ZInput.GetMouseButton(button);
			if (button != 1 || !_suppress)
			{
				return mouseButton;
			}
			if (!mouseButton)
			{
				_suppress = false;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateItemDrag")]
	internal static class UpdateItemDragPatch
	{
		private static void Prefix(InventoryGui __instance)
		{
			RightClickPlaceOne.Tick(__instance);
			LeftDragSplit.Tick(__instance);
			DragCollect.Tick(__instance);
			ShiftSweepMove.Tick(__instance);
			WheelMove.Tick(__instance);
			DropKey.Tick(__instance);
			HotbarKeys.Tick(__instance);
			RightMouseCancelGuard.ClearIfReleased();
		}

		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(RightMouseCancelGuard), "GetMouseButton", (Type[])null, (Type[])null);
			int replaced = 0;
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, original))
				{
					instruction.opcode = OpCodes.Call;
					instruction.operand = replacement;
					replaced++;
				}
				yield return instruction;
			}
			if (replaced == 0)
			{
				AichoMouseTweaksPlugin.Log.LogWarning((object)"UpdateItemDrag: no se encontró ZInput.GetMouseButton, el clic derecho puede cancelar la división");
			}
		}
	}
}