From 0d188dd073351c1d7fb22b85c36b514dadd402f1 Mon Sep 17 00:00:00 2001 From: staphen Date: Wed, 1 Jan 2025 18:16:21 -0500 Subject: [PATCH] Don't apply dungeon item validation to town items --- Source/items/validation.cpp | 38 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/Source/items/validation.cpp b/Source/items/validation.cpp index ff2394dca70..b5d71a95fe9 100644 --- a/Source/items/validation.cpp +++ b/Source/items/validation.cpp @@ -11,6 +11,7 @@ #include "items.h" #include "monstdat.h" #include "player.h" +#include "spells.h" namespace devilution { @@ -137,6 +138,22 @@ 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) @@ -144,19 +161,14 @@ bool IsItemValid(const Player &player, const Item &item) 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