Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't apply dungeon item validation to town items #7612

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading