🐛 Reject items that would cause an OOB to

This commit is contained in:
Anders Jenbo 2021-09-21 15:12:58 +02:00
commit 0c5bdf5dbf
4 changed files with 9 additions and 7 deletions

View file

@ -13,7 +13,7 @@
namespace devilution {
/** @todo add missing values and apply */
enum _item_indexes : int16_t {
enum _item_indexes : int16_t { // TODO defines all indexes in AllItemsList
IDI_GOLD,
IDI_WARRIOR,
IDI_WARRSHLD,
@ -64,6 +64,9 @@ enum _item_indexes : int16_t {
IDI_FULLNOTE,
IDI_BROWNSUIT,
IDI_GREYSUIT,
IDI_SORCERER_DIABLO = 166,
IDI_LAST = IDI_SORCERER_DIABLO,
IDI_NONE = -1,
};

View file

@ -2516,6 +2516,9 @@ void NextItemRecord(int i)
bool IsItemAvailable(int i)
{
if (i < 0 || i > IDI_LAST)
return false;
if (gbIsSpawn) {
if (i >= 62 && i <= 71)
return false; // Medium and heavy armors

View file

@ -1461,7 +1461,7 @@ _item_indexes RemapItemIdxFromDiablo(_item_indexes i)
{
constexpr auto GetItemIdValue = [](int i) -> int {
if (i == IDI_SORCERER) {
return 166;
return IDI_SORCERER_DIABLO;
}
if (i >= 156) {
i += 5; // Hellfire exclusive items
@ -1482,7 +1482,7 @@ _item_indexes RemapItemIdxFromDiablo(_item_indexes i)
_item_indexes RemapItemIdxToDiablo(_item_indexes i)
{
constexpr auto GetItemIdValue = [](int i) -> int {
if (i == 166) {
if (i == IDI_SORCERER_DIABLO) {
return IDI_SORCERER;
}
if ((i >= 83 && i <= 86) || i == 92 || i >= 161) {

View file

@ -140,10 +140,6 @@ void UnPackItem(const ItemPack *is, Item *id, bool isHellfire)
{
auto &item = Items[MAXITEMS];
auto idx = static_cast<_item_indexes>(SDL_SwapLE16(is->idx));
if (idx == IDI_NONE) {
id->_itype = ItemType::None;
return;
}
if (gbIsSpawn) {
idx = RemapItemIdxFromSpawn(idx);