From f5b84242666f2f5f1f568d7f02933aa85958c0dd Mon Sep 17 00:00:00 2001 From: shenlei Date: Sat, 24 Oct 2026 15:30:38 +0900 Subject: [PATCH] game: make special storage cells reachable through GetItem CHARACTER::IsValidItemPosition had no case for windows 8-12, so GetItem returned NULL for every special storage cell. ClearItem never freed those items on logout; the next login of the same character failed with ITEM_ID_DUP and the items went missing (dangling owner pointer). The MoveItem routing for these windows was unreachable for the same reason. Co-Authored-By: Claude Opus 5.5 --- src/server/game/src/char_item.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/server/game/src/char_item.cpp b/src/server/game/src/char_item.cpp index c41e36f9..32e20bc1 100755 --- a/src/server/game/src/char_item.cpp +++ b/src/server/game/src/char_item.cpp @@ -699,6 +699,23 @@ void CHARACTER::ClearItem() M2_DESTROY_ITEM(item); } } +#ifdef ENABLE_SPECIAL_STORAGE + // PORT: special storage items outlived logout (dangling owner, ITEM_ID_DUP on the next login) + for (BYTE window = UPGRADE_INVENTORY; window <= COSTUME_INVENTORY; ++window) + { + for (i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i) + { + if ((item = GetItem(TItemPos(window, i)))) + { + item->SetSkipSave(true); + ITEM_MANAGER::instance().FlushDelayedSave(item); + + item->RemoveFromCharacter(); + M2_DESTROY_ITEM(item); + } + } + } +#endif } bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) const @@ -8630,6 +8647,16 @@ bool CHARACTER::IsValidItemPosition(TItemPos Pos) const case SWITCHBOT: return cell < SWITCHBOT_SLOT_COUNT; +#ifdef ENABLE_SPECIAL_STORAGE + // PORT: without these GetItem() returned NULL for every special storage cell + case UPGRADE_INVENTORY: + case BOOK_INVENTORY: + case STONE_INVENTORY: + case CHANGE_INVENTORY: + case COSTUME_INVENTORY: + return cell < SPECIAL_INVENTORY_MAX_NUM; +#endif + case SAFEBOX: if (NULL != m_pkSafebox) return m_pkSafebox->IsValidPosition(cell);