Skip to content

Commit

Permalink
Don't apply dungeon item validation to town items
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenCWills authored and AJenbo committed Jan 2, 2025
1 parent a12b536 commit 0d188dd
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions Source/items/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "items.h"
#include "monstdat.h"
#include "player.h"
#include "spells.h"

namespace devilution {

Expand Down Expand Up @@ -137,26 +138,37 @@ bool IsDungeonItemValid(uint16_t iCreateInfo, uint32_t dwBuff)
return level <= (diabloMaxDungeonLevel * 2);
}

bool IsHellfireSpellBookValid(const Item &spellBook)
{
// Hellfire uses the spell book level when generating items via CreateSpellBook()
int spellBookLevel = GetSpellBookLevel(spellBook._iSpell);

// CreateSpellBook() adds 1 to the spell level for ilvl
spellBookLevel++;

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
return true;
}

return IsDungeonItemValid(spellBook._iCreateInfo, spellBook.dwBuff);
}

bool IsItemValid(const Player &player, const Item &item)
{
if (!gbIsMultiplayer)
return true;

if (item.IDidx != IDI_GOLD && !IsCreationFlagComboValid(item._iCreateInfo))
return false;

if ((item._iCreateInfo & CF_TOWN) != 0) {
if (!IsTownItemValid(item._iCreateInfo, player) || !IsShopPriceValid(item))
return false;
} else if ((item._iCreateInfo & CF_USEFUL) == CF_UPER15) {
if (!IsUniqueMonsterItemValid(item._iCreateInfo, item.dwBuff))
return false;
}

if (!IsDungeonItemValid(item._iCreateInfo, item.dwBuff))
return false;

return true;
if ((item._iCreateInfo & CF_TOWN) != 0)
return IsTownItemValid(item._iCreateInfo, player) && IsShopPriceValid(item);
if ((item._iCreateInfo & CF_USEFUL) == CF_UPER15)
return IsUniqueMonsterItemValid(item._iCreateInfo, item.dwBuff);
if ((item.dwBuff & CF_HELLFIRE) != 0 && AllItemsList[item.IDidx].iMiscId == IMISC_BOOK)
return IsHellfireSpellBookValid(item);

return IsDungeonItemValid(item._iCreateInfo, item.dwBuff);
}

} // namespace devilution

0 comments on commit 0d188dd

Please sign in to comment.