diff --git a/Source/inv.cpp b/Source/inv.cpp index 3509f6284..1344455bf 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1452,17 +1452,10 @@ bool GoldAutoPlace(Player &player, Item &goldStack) return goldStack._ivalue == 0; } -void CheckInvSwap(Player &player, inv_body_loc bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff) +void CheckInvSwap(Player &player, inv_body_loc bLoc) { Item &item = player.InvBody[bLoc]; - item = {}; - RecreateItem(player, item, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0); - - if (bId) { - item._iIdentified = true; - } - if (bLoc == INVLOC_HAND_LEFT && player.GetItemLocation(item) == ILOC_TWOHAND) { player.InvBody[INVLOC_HAND_RIGHT].clear(); } else if (bLoc == INVLOC_HAND_RIGHT && player.GetItemLocation(item) == ILOC_TWOHAND) { @@ -1479,15 +1472,8 @@ void inv_update_rem_item(Player &player, inv_body_loc iv) CalcPlrInv(player, player._pmode != PM_DEATH); } -void CheckInvSwap(Player &player, int invGridIndex, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff) +void CheckInvSwap(Player &player, const Item &item, int invGridIndex) { - Item item = {}; - RecreateItem(player, item, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0); - - if (bId) { - item._iIdentified = true; - } - auto itemSize = GetInventorySize(item); const int pitch = 10; @@ -1536,18 +1522,6 @@ void CheckInvRemove(Player &player, int invGridIndex) } } -void CheckBeltSwap(Player &player, int beltIndex, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff) -{ - Item &item = player.SpdList[beltIndex]; - - item = {}; - RecreateItem(player, item, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0); - - if (bId) { - item._iIdentified = true; - } -} - void TransferItemToStash(Player &player, int location) { if (location == -1) { diff --git a/Source/inv.h b/Source/inv.h index 02485ed25..fbda4fa5b 100644 --- a/Source/inv.h +++ b/Source/inv.h @@ -180,11 +180,10 @@ int RoomForGold(); */ int AddGoldToInventory(Player &player, int value); bool GoldAutoPlace(Player &player, Item &goldStack); -void CheckInvSwap(Player &player, inv_body_loc bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff); +void CheckInvSwap(Player &player, inv_body_loc bLoc); void inv_update_rem_item(Player &player, inv_body_loc iv); -void CheckInvSwap(Player &player, int invGridIndex, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff); +void CheckInvSwap(Player &player, const Item &item, int invGridIndex); void CheckInvRemove(Player &player, int invGridIndex); -void CheckBeltSwap(Player &player, int beltIndex, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff); void TransferItemToStash(Player &player, int location); void CheckInvItem(bool isShiftHeld = false, bool isCtrlHeld = false); diff --git a/Source/msg.cpp b/Source/msg.cpp index 023741060..af6a63c33 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -1832,8 +1832,43 @@ size_t OnChangePlayerItems(const TCmd *pCmd, size_t pnum) if (gbBufferMsgs == 1) { SendPacket(pnum, &message, sizeof(message)); - } else if (&player != MyPlayer && message.wIndx <= IDI_LAST) { - CheckInvSwap(player, bodyLocation, message.wIndx, message.wCI, message.dwSeed, message.bId != 0, message.dwBuff); + } else if (&player != MyPlayer && IsItemAvailable(message.def.wIndx)) { + Item &item = player.InvBody[message.bLoc]; + item = {}; + + if (message.def.wIndx == IDI_EAR) { + RecreateEar( + item, + message.ear.wCI, + message.ear.dwSeed, + message.ear.bCursval, + message.ear.heroname); + } else { + RecreateItem( + player, + item, + message.item.wIndx, + message.item.wCI, + message.item.dwSeed, + message.item.wValue, + (message.item.dwBuff & CF_HELLFIRE) != 0); + + if (message.item.bId != 0) + item._iIdentified = true; + item._iDurability = message.item.bDur; + item._iMaxDur = message.item.bMDur; + item._iCharges = message.item.bCh; + item._iMaxCharges = message.item.bMCh; + item._iPLToHit = message.item.wToHit; + item._iMaxDam = message.item.wMaxDam; + item._iMinStr = message.item.bMinStr; + item._iMinMag = message.item.bMinMag; + item._iMinDex = message.item.bMinDex; + item._iAC = message.item.bAC; + item.dwBuff = message.item.dwBuff; + } + + CheckInvSwap(player, bodyLocation); } player.ReadySpellFromEquipment(bodyLocation); @@ -1861,10 +1896,47 @@ size_t OnChangeInventoryItems(const TCmd *pCmd, int pnum) const auto &message = *reinterpret_cast(pCmd); Player &player = Players[pnum]; + if (message.bLoc >= InventoryGridCells) + return sizeof(message); + if (gbBufferMsgs == 1) { SendPacket(pnum, &message, sizeof(message)); - } else if (&player != MyPlayer && message.bLoc < InventoryGridCells && message.wIndx <= IDI_LAST) { - CheckInvSwap(player, message.bLoc, message.wIndx, message.wCI, message.dwSeed, message.bId != 0, message.dwBuff); + } else if (&player != MyPlayer && IsItemAvailable(message.def.wIndx)) { + Item item {}; + + if (message.def.wIndx == IDI_EAR) { + RecreateEar( + item, + message.ear.wCI, + message.ear.dwSeed, + message.ear.bCursval, + message.ear.heroname); + } else { + RecreateItem( + player, + item, + message.item.wIndx, + message.item.wCI, + message.item.dwSeed, + message.item.wValue, + (message.item.dwBuff & CF_HELLFIRE) != 0); + + if (message.item.bId != 0) + item._iIdentified = true; + item._iDurability = message.item.bDur; + item._iMaxDur = message.item.bMDur; + item._iCharges = message.item.bCh; + item._iMaxCharges = message.item.bMCh; + item._iPLToHit = message.item.wToHit; + item._iMaxDam = message.item.wMaxDam; + item._iMinStr = message.item.bMinStr; + item._iMinMag = message.item.bMinMag; + item._iMinDex = message.item.bMinDex; + item._iAC = message.item.bAC; + item.dwBuff = message.item.dwBuff; + } + + CheckInvSwap(player, item, message.bLoc); } return sizeof(message); @@ -1889,10 +1961,46 @@ size_t OnChangeBeltItems(const TCmd *pCmd, int pnum) const auto &message = *reinterpret_cast(pCmd); Player &player = Players[pnum]; + if (message.bLoc >= MaxBeltItems) + return sizeof(message); + if (gbBufferMsgs == 1) { SendPacket(pnum, &message, sizeof(message)); - } else if (&player != MyPlayer && message.bLoc < MaxBeltItems && message.wIndx <= IDI_LAST) { - CheckBeltSwap(player, message.bLoc, message.wIndx, message.wCI, message.dwSeed, message.bId != 0, message.dwBuff); + } else if (&player != MyPlayer && IsItemAvailable(message.def.wIndx)) { + Item &item = player.SpdList[message.bLoc]; + item = {}; + + if (message.def.wIndx == IDI_EAR) { + RecreateEar( + item, + message.ear.wCI, + message.ear.dwSeed, + message.ear.bCursval, + message.ear.heroname); + } else { + RecreateItem( + player, + item, + message.item.wIndx, + message.item.wCI, + message.item.dwSeed, + message.item.wValue, + (message.item.dwBuff & CF_HELLFIRE) != 0); + + if (message.item.bId != 0) + item._iIdentified = true; + item._iDurability = message.item.bDur; + item._iMaxDur = message.item.bMDur; + item._iCharges = message.item.bCh; + item._iMaxCharges = message.item.bMCh; + item._iPLToHit = message.item.wToHit; + item._iMaxDam = message.item.wMaxDam; + item._iMinStr = message.item.bMinStr; + item._iMinMag = message.item.bMinMag; + item._iMinDex = message.item.bMinDex; + item._iAC = message.item.bAC; + item.dwBuff = message.item.dwBuff; + } } return sizeof(message); @@ -3045,17 +3153,34 @@ void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item void NetSendCmdChItem(bool bHiPri, uint8_t bLoc) { - TCmdChItem cmd; + TCmdChItem cmd {}; Item &item = MyPlayer->InvBody[bLoc]; cmd.bCmd = CMD_CHANGEPLRITEMS; cmd.bLoc = bLoc; - cmd.wIndx = item.IDidx; - cmd.wCI = item._iCreateInfo; - cmd.dwSeed = item._iSeed; - cmd.bId = item._iIdentified ? 1 : 0; - cmd.dwBuff = item.dwBuff; + cmd.def.wIndx = item.IDidx; + cmd.def.wCI = item._iCreateInfo; + cmd.def.dwSeed = item._iSeed; + + if (item.IDidx == IDI_EAR) { + cmd.ear.bCursval = item._ivalue | ((item._iCurs - ICURS_EAR_SORCERER) << 6); + CopyUtf8(cmd.ear.heroname, item._iIName, sizeof(cmd.ear.heroname)); + } else { + cmd.item.bId = item._iIdentified ? 1 : 0; + cmd.item.bDur = item._iDurability; + cmd.item.bMDur = item._iMaxDur; + cmd.item.bCh = item._iCharges; + cmd.item.bMCh = item._iMaxCharges; + cmd.item.wValue = item._ivalue; + cmd.item.wToHit = item._iPLToHit; + cmd.item.wMaxDam = item._iMaxDam; + cmd.item.bMinStr = item._iMinStr; + cmd.item.bMinMag = item._iMinMag; + cmd.item.bMinDex = item._iMinDex; + cmd.item.bAC = item._iAC; + cmd.item.dwBuff = item.dwBuff; + } if (bHiPri) NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); @@ -3077,18 +3202,35 @@ void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc) void NetSendCmdChInvItem(bool bHiPri, int invGridIndex) { - TCmdChItem cmd; + TCmdChItem cmd {}; int8_t invListIndex = abs(MyPlayer->InvGrid[invGridIndex]) - 1; const Item &item = MyPlayer->InvList[invListIndex]; cmd.bCmd = CMD_CHANGEINVITEMS; cmd.bLoc = invGridIndex; - cmd.wIndx = item.IDidx; - cmd.wCI = item._iCreateInfo; - cmd.dwSeed = item._iSeed; - cmd.bId = item._iIdentified ? 1 : 0; - cmd.dwBuff = item.dwBuff; + cmd.def.wIndx = item.IDidx; + cmd.def.wCI = item._iCreateInfo; + cmd.def.dwSeed = item._iSeed; + + if (item.IDidx == IDI_EAR) { + cmd.ear.bCursval = item._ivalue | ((item._iCurs - ICURS_EAR_SORCERER) << 6); + CopyUtf8(cmd.ear.heroname, item._iIName, sizeof(cmd.ear.heroname)); + } else { + cmd.item.bId = item._iIdentified ? 1 : 0; + cmd.item.bDur = item._iDurability; + cmd.item.bMDur = item._iMaxDur; + cmd.item.bCh = item._iCharges; + cmd.item.bMCh = item._iMaxCharges; + cmd.item.wValue = item._ivalue; + cmd.item.wToHit = item._iPLToHit; + cmd.item.wMaxDam = item._iMaxDam; + cmd.item.bMinStr = item._iMinStr; + cmd.item.bMinMag = item._iMinMag; + cmd.item.bMinDex = item._iMinDex; + cmd.item.bAC = item._iAC; + cmd.item.dwBuff = item.dwBuff; + } if (bHiPri) NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); @@ -3098,17 +3240,34 @@ void NetSendCmdChInvItem(bool bHiPri, int invGridIndex) void NetSendCmdChBeltItem(bool bHiPri, int beltIndex) { - TCmdChItem cmd; + TCmdChItem cmd {}; const Item &item = MyPlayer->SpdList[beltIndex]; cmd.bCmd = CMD_CHANGEBELTITEMS; cmd.bLoc = beltIndex; - cmd.wIndx = item.IDidx; - cmd.wCI = item._iCreateInfo; - cmd.dwSeed = item._iSeed; - cmd.bId = item._iIdentified ? 1 : 0; - cmd.dwBuff = item.dwBuff; + cmd.def.wIndx = item.IDidx; + cmd.def.wCI = item._iCreateInfo; + cmd.def.dwSeed = item._iSeed; + + if (item.IDidx == IDI_EAR) { + cmd.ear.bCursval = item._ivalue | ((item._iCurs - ICURS_EAR_SORCERER) << 6); + CopyUtf8(cmd.ear.heroname, item._iIName, sizeof(cmd.ear.heroname)); + } else { + cmd.item.bId = item._iIdentified ? 1 : 0; + cmd.item.bDur = item._iDurability; + cmd.item.bMDur = item._iMaxDur; + cmd.item.bCh = item._iCharges; + cmd.item.bMCh = item._iMaxCharges; + cmd.item.wValue = item._ivalue; + cmd.item.wToHit = item._iPLToHit; + cmd.item.wMaxDam = item._iMaxDam; + cmd.item.bMinStr = item._iMinStr; + cmd.item.bMinMag = item._iMinMag; + cmd.item.bMinDex = item._iMinDex; + cmd.item.bAC = item._iAC; + cmd.item.dwBuff = item.dwBuff; + } if (bHiPri) NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); diff --git a/Source/msg.h b/Source/msg.h index 654c7927d..16ff11536 100644 --- a/Source/msg.h +++ b/Source/msg.h @@ -626,11 +626,12 @@ struct TCmdPItem { struct TCmdChItem { _cmd_id bCmd; uint8_t bLoc; - uint16_t wIndx; - uint16_t wCI; - int32_t dwSeed; - uint8_t bId; - uint32_t dwBuff; + + union { + TItemDef def; + TItem item; + TEar ear; + }; }; struct TCmdDelItem {