From 546d5180247512270a2ccd114266fb36cd426e61 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 13 May 2016 22:03:58 +0300 Subject: Add check asserts in ItemDB. Also fix new asserts from log. --- src/const/resources/item/cards.h | 4 ++++ src/itemcolormanager.cpp | 11 ++++++++++- src/resources/db/itemdb.cpp | 9 ++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/const/resources/item/cards.h b/src/const/resources/item/cards.h index 8e759fbc7..93ca08c90 100644 --- a/src/const/resources/item/cards.h +++ b/src/const/resources/item/cards.h @@ -24,4 +24,8 @@ #define maxCards 4 #define maxMailCards 4 +#define CARD0_FORGE 0x00FF +#define CARD0_CREATE 0x00FE +#define CARD0_PET ((short)0xFF00) + #endif // CONST_RESOURCES_ITEM_CARDS_H diff --git a/src/itemcolormanager.cpp b/src/itemcolormanager.cpp index 9344ff856..0cf48015b 100644 --- a/src/itemcolormanager.cpp +++ b/src/itemcolormanager.cpp @@ -32,9 +32,18 @@ ItemColor ItemColorManager::getColorFromCards(const int *const cards) { if (!cards) return ItemColor_one; + if (cards[0] == CARD0_FORGE || + cards[0] == CARD0_CREATE || + cards[0] == CARD0_PET) + { + return ItemColor_one; + } for (int f = 0; f < maxCards; f ++) { - const ItemInfo &info = ItemDB::get(cards[f]); + const int id = cards[f]; + if (id == 0) + continue; + const ItemInfo &info = ItemDB::get(id); const ItemColor &color = info.getCardColor(); if (color != ItemColor_zero) return color; diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index a6dcd48ab..6c79c12e8 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -38,6 +38,7 @@ #include "net/serverfeatures.h" +#include "utils/checkutils.h" #include "utils/delete2.h" #include "utils/dtor.h" #include "utils/files.h" @@ -285,7 +286,8 @@ void ItemDB::load() // Hairstyles are encoded as negative numbers. Count how far negative // we can go. int hairstyles = 1; - while (ItemDB::get(-hairstyles).getSprite(Gender::MALE, + while (ItemDB::exists(-hairstyles) && + ItemDB::get(-hairstyles).getSprite(Gender::MALE, BeingTypeId_zero) != paths.getStringValue("spriteErrorFile")) { hairstyles ++; @@ -293,7 +295,8 @@ void ItemDB::load() mNumberOfHairstyles = hairstyles; int races = 100; - while (ItemDB::get(-races).getSprite(Gender::MALE, BeingTypeId_zero) != + while (ItemDB::exists(-races) && + ItemDB::get(-races).getSprite(Gender::MALE, BeingTypeId_zero) != paths.getStringValue("spriteErrorFile")) { races ++; @@ -744,7 +747,7 @@ const ItemInfo &ItemDB::get(const int id) if (i == mItemInfos.end()) { - logger->log("ItemDB: Warning, unknown item ID# %d", id); + reportAlways("ItemDB: Warning, unknown item ID# %d", id); return *mUnknown; } -- cgit v1.2.3-70-g09d2