Skip to content

Commit

Permalink
Apply Hellfire spellbook validation to PItem packet handling
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenCWills authored and AJenbo committed Feb 13, 2024
1 parent a218b60 commit ab601ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Source/msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,8 @@ bool IsPItemValid(const TCmdPItem &message, const Player &player)
ValidateField(creationFlags, IsTownItemValid(creationFlags, player));
else if ((creationFlags & CF_USEFUL) == CF_UPER15)
ValidateFields(creationFlags, dwBuff, IsUniqueMonsterItemValid(creationFlags, dwBuff));
else if ((dwBuff & CF_HELLFIRE) != 0 && AllItemsList[idx].iMiscId == IMISC_BOOK)
return RecreateHellfireSpellBook(player, message.item);
else
ValidateFields(creationFlags, dwBuff, IsDungeonItemValid(creationFlags, dwBuff));
}
Expand Down
12 changes: 7 additions & 5 deletions Source/pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ bool IsDungeonItemValid(uint16_t iCreateInfo, uint32_t dwBuff)
return level <= (diabloMaxDungeonLevel * 2);
}

bool RecreateHellfireSpellBook(const Player &player, const ItemNetPack &packedItem, Item &item)
bool RecreateHellfireSpellBook(const Player &player, const TItem &packedItem, Item *item)
{
Item spellBook {};
RecreateItem(player, packedItem.item, spellBook);
RecreateItem(player, packedItem, spellBook);

// Hellfire uses the spell book level when generating items via CreateSpellBook()
int spellBookLevel = GetSpellBookLevel(spellBook._iSpell);
Expand All @@ -191,12 +191,14 @@ bool RecreateHellfireSpellBook(const Player &player, const ItemNetPack &packedIt

if (spellBookLevel >= 1 && (spellBook._iCreateInfo & CF_LEVEL) == spellBookLevel * 2) {
// The ilvl matches the result for a spell book drop, so we confirm the item is legitimate
item = spellBook;
if (item != nullptr)
*item = spellBook;
return true;
}

ValidateFields(spellBook._iCreateInfo, spellBook.dwBuff, IsDungeonItemValid(spellBook._iCreateInfo, spellBook.dwBuff));
item = spellBook;
if (item != nullptr)
*item = spellBook;
return true;
}

Expand Down Expand Up @@ -529,7 +531,7 @@ bool UnPackNetItem(const Player &player, const ItemNetPack &packedItem, Item &it
else if ((creationFlags & CF_USEFUL) == CF_UPER15)
ValidateFields(creationFlags, dwBuff, IsUniqueMonsterItemValid(creationFlags, dwBuff));
else if ((dwBuff & CF_HELLFIRE) != 0 && AllItemsList[idx].iMiscId == IMISC_BOOK)
return RecreateHellfireSpellBook(player, packedItem, item);
return RecreateHellfireSpellBook(player, packedItem.item, &item);
else
ValidateFields(creationFlags, dwBuff, IsDungeonItemValid(creationFlags, dwBuff));

Expand Down
1 change: 1 addition & 0 deletions Source/pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ bool IsCreationFlagComboValid(uint16_t iCreateInfo);
bool IsTownItemValid(uint16_t iCreateInfo, const Player &player);
bool IsUniqueMonsterItemValid(uint16_t iCreateInfo, uint32_t dwBuff);
bool IsDungeonItemValid(uint16_t iCreateInfo, uint32_t dwBuff);
bool RecreateHellfireSpellBook(const Player &player, const TItem &packedItem, Item *item = nullptr);
void PackPlayer(PlayerPack &pPack, const Player &player);
void UnPackPlayer(const PlayerPack &pPack, Player &player);
void PackNetPlayer(PlayerNetPack &packed, const Player &player);
Expand Down

0 comments on commit ab601ee

Please sign in to comment.