public static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemDrop.ItemData item, Vector2i pos, InventoryGrid.Modifier mod)
 {
     // if we're not moving from the spellbars, do nothing (normal flow)
     if (__instance.m_dragInventory?.m_name != "spellsBarInventory")
     {
         return(true);
     }
     // if we moving TO the spellsbars, do nothing (normal flow)
     if (grid.m_inventory?.m_name == "spellsBarInventory")
     {
         return(true);
     }
     // so if we're moving from the spellsbar to another inventory
     ItemDrop.ItemData itemAt = grid.GetInventory().GetItemAt(pos.x, pos.y);
     if (itemAt != null)
     {
         // and there is an item at the destination
         var runeData = itemAt.GetRuneData();
         // and its not a rune
         if (runeData == null)
         {
             // we cant swap that!
             Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You can't swap a rune for a non-rune item.");
             return(false);
         }
     }
     return(true);
 }
        public void RebuildPlayerButton(InventoryGrid playerGrid, bool force = false)
        {
            if (playerGrid is null)
            {
                throw new ArgumentNullException("playerGrid");
            }

            var newSize = playerGrid?.GetInventory()?.GetHeight();

            if (newSize is null || playerHeight == newSize && !force)
            {
                return;
            }

            Logger.LogInfo(force ? "Player sort button being forcibly rebuilt." : $"Player inventory grid changed size from {playerHeight} to {newSize}, rebuilding.");

            if (playerButton != null)
            {
                Destroy(playerButton);
            }

            playerButton = MakePlayerButton();
            playerHeight = (int)newSize;

            var gui = InventoryGui.instance;

            if (gui is null)
            {
                return;
            }

            var bkg = gui.m_player.Find("Bkg");

            if (bkg is null)
            {
                return;
            }

            var scale = bkg.transform.localScale;

            if (scale != playerButton.transform.localScale)
            {
                playerButton.transform.localScale = new Vector3(
                    playerButton.transform.localScale.x / scale.x,
                    playerButton.transform.localScale.y / scale.y,
                    0);
            }
        }
 static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemDrop.ItemData item, int ___m_dragAmount)
 {
     if (ZInput.GetButton("JoyLTrigger") || CheckModKey(modKey.Value))
     {
         if (item != null && item.m_stack > 1 && Player.m_localPlayer)
         {
             int amount = ___m_dragAmount > 0 ? (item.m_stack - ___m_dragAmount) / 2 + ___m_dragAmount : item.m_stack / 2;
             //Dbgl($"auto stacking: {amount}/{ item.m_stack } {item?.m_shared.m_name}");
             __instance.GetType().GetMethod("SetupDragItem", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { item, grid.GetInventory(), amount });
             autoSplitting = true;
         }
         return(false);
     }
     return(true);
 }