From d786c607b81f9f82c05c757370ab059ae8a61185 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 6 Jun 2026 09:41:44 -0500 Subject: [PATCH] C_Container.MoveItem: route count == srcStack through swap path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vanilla's CMSG_SPLIT_ITEM rejects splits where count == srcStack (EQUIP_ERR_COULDNT_SPLIT_ITEMS — would leave source empty). The drag-and-drop UI's "drop whole stack on matching stack" goes through CMSG_SWAP_ITEM, which the server merges for same-item destinations. In MoveCount, read ITEM_FIELD_STACK_COUNT off the resolved source CGItem and route count == srcStack to Item::Swap::Containers. Also return false locally for count > srcStack (server would reject anyway, fail fast). count < srcStack keeps the existing SPLIT path. --- src/item/Swap.cpp | 18 ++++++++++++++++++ src/item/Swap.h | 12 +++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/item/Swap.cpp b/src/item/Swap.cpp index 31d375f2..f8de755f 100644 --- a/src/item/Swap.cpp +++ b/src/item/Swap.cpp @@ -254,6 +254,24 @@ bool MoveCount(void *L, int srcBag, int srcSlot, int dstBag, int dstSlot, int co if (srcItem == nullptr) return false; + // Vanilla server rejects `CMSG_SPLIT_ITEM` when count == srcStack + // (`EQUIP_ERR_COULDNT_SPLIT_ITEMS`) — conceptually "split N off, + // leave residual", and splitting the entire stack would leave + // source empty. The drag-and-drop UI's "drop whole stack on + // matching stack" goes through CMSG_SWAP_ITEM instead, which the + // server treats as a merge for same-item destinations (up to + // maxStack). Route there for count == srcStack so callers don't + // have to special-case "move everything". + auto *srcDescriptor = *reinterpret_cast( + srcItem + Offsets::OFF_ITEM_DESCRIPTOR); + const int srcStack = srcDescriptor == nullptr ? 0 : + static_cast(*reinterpret_cast( + srcDescriptor + Offsets::OFF_DESCRIPTOR_STACK_COUNT)); + if (count > srcStack) + return false; // server would reject anyway; fail fast and locally + if (count == srcStack) + return Containers(L, srcBag, srcSlot, dstBag, dstSlot); + void *player = ResolvePlayer(); if (player == nullptr) return false; diff --git a/src/item/Swap.h b/src/item/Swap.h index 7dbaa365..12cba1a2 100644 --- a/src/item/Swap.h +++ b/src/item/Swap.h @@ -82,9 +82,15 @@ bool Containers(void *L, int srcBag, int srcSlot, int dstBag, int dstSlot); // - `dst` same item & fits maxStack → merges `count` into dst // - `dst` different item / overflow → server rejects (no partial) // -// Source must be occupied with at least `count` items; server rejects -// if not. Returns false locally only on bad args or unresolvable bags. -// All other validation is server-side — same as `Containers` above. +// Source must be occupied with at least `count` items. Locally +// validates `count <= srcStack` (server would reject otherwise with +// `EQUIP_ERR_COULDNT_SPLIT_ITEMS` — fail fast). When `count == +// srcStack` ("move the whole stack"), routes through `Containers` +// instead — vanilla's `CMSG_SPLIT_ITEM` rejects splits that would +// leave the source empty, but `CMSG_SWAP_ITEM` handles the case +// (merges into a matching destination stack, swaps otherwise). +// Returns false locally on bad args, unresolvable bags, or +// `count > srcStack`; all other validation is server-side. // // Requires Lua state for the same reason as `Containers`: the source // CGItem lookup goes through `Item::Location::ResolveBag`. Stomps the