@@ -2164,15 +2164,25 @@ size_t OnDeletePlayerItems(const TCmdDelItem &message, Player &player)
21642164
21652165size_t OnChangeInventoryItems (const TCmdChItem &message, Player &player)
21662166{
2167- if (message.bLoc >= InventoryGridCells)
2167+ const uint8_t topLeft = message.bLoc ;
2168+ if (topLeft >= InventoryGridCells)
21682169 return sizeof (message);
21692170
21702171 if (gbBufferMsgs == 1 ) {
21712172 BufferMessage (player, &message, sizeof (message));
21722173 } else if (&player != MyPlayer && IsItemAvailable (static_cast <_item_indexes>(Swap16LE (message.def .wIndx )))) {
21732174 Item item {};
21742175 RecreateItem (player, message, item);
2175- CheckInvSwap (player, item, message.bLoc );
2176+
2177+ const Size itemSize = GetInventorySize (item);
2178+ const int invPitch = InventorySizeInSlots.width ;
2179+ const int verticalShift = itemSize.width - 1 ;
2180+ const int horizontalShift = itemSize.height - 1 ;
2181+ const uint8_t bottomRight = static_cast <uint8_t >(topLeft + invPitch * verticalShift + horizontalShift);
2182+ if (bottomRight >= InventoryGridCells)
2183+ return sizeof (message);
2184+
2185+ CheckInvSwap (player, item, topLeft);
21762186 }
21772187
21782188 return sizeof (message);
@@ -3228,7 +3238,7 @@ void NetSyncInvItem(const Player &player, int invListIndex)
32283238 return ;
32293239
32303240 for (int j = 0 ; j < InventoryGridCells; j++) {
3231- if (player.InvGrid [j] == invListIndex + 1 ) {
3241+ if (std::abs ( player.InvGrid [j]) == invListIndex + 1 ) {
32323242 NetSendCmdChInvItem (false , j);
32333243 break ;
32343244 }
0 commit comments