Browse Source

🐛 Reject items that would cause an OOB to

pull/2904/head
Anders Jenbo 5 years ago
parent
commit
0c5bdf5dbf
  1. 5
      Source/itemdat.h
  2. 3
      Source/items.cpp
  3. 4
      Source/loadsave.cpp
  4. 4
      Source/pack.cpp

5
Source/itemdat.h

@ -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,
};

3
Source/items.cpp

@ -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

4
Source/loadsave.cpp

@ -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) {

4
Source/pack.cpp

@ -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);

Loading…
Cancel
Save