diff options
author | megamage <none@none> | 2009-03-06 19:39:42 -0600 |
---|---|---|
committer | megamage <none@none> | 2009-03-06 19:39:42 -0600 |
commit | 4f6c96b98c5d5a065f902aa6106c928bf0b2a668 (patch) | |
tree | e790dd5071091cbaeffb9d919eba777b519cf25f | |
parent | 417c7c83196aba0c4afdefd75c3edaba91337a88 (diff) |
[7394] Check loot_template.maxcount for max allowed value (255) and make better report for this case. Author: VladimirMangos
Also optimize strcture LootStoreItem that let use 4 byte for loot template element in memory instead 5 bytes.
But limit group id to 127 max value. Check this at loading.
--HG--
branch : trunk
-rw-r--r-- | src/game/AchievementMgr.cpp | 1 | ||||
-rw-r--r-- | src/game/LootMgr.cpp | 15 | ||||
-rw-r--r-- | src/game/LootMgr.h | 8 | ||||
-rw-r--r-- | src/shared/revision_nr.h | 2 |
4 files changed, 19 insertions, 7 deletions
diff --git a/src/game/AchievementMgr.cpp b/src/game/AchievementMgr.cpp index df209edf978..6048c8ea78d 100644 --- a/src/game/AchievementMgr.cpp +++ b/src/game/AchievementMgr.cpp @@ -606,7 +606,6 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui { if(Player::GetDrunkenstateByValue(GetPlayer()->GetDrunkValue()) != DRUNKEN_SMASHED) continue; - // TODO: hardcoding eventid is bad, it can differ from DB to DB - maye implement something using HolidayNames.dbc? if(!IsHolidayActive(HOLIDAY_BREWFEST)) continue; } diff --git a/src/game/LootMgr.cpp b/src/game/LootMgr.cpp index da5b4343d24..046fa28f106 100644 --- a/src/game/LootMgr.cpp +++ b/src/game/LootMgr.cpp @@ -117,11 +117,18 @@ void LootStore::LoadLootTable() float chanceOrQuestChance = fields[2].GetFloat(); uint8 group = fields[3].GetUInt8(); int32 mincountOrRef = fields[4].GetInt32(); - uint8 maxcount = fields[5].GetUInt8(); + uint32 maxcount = fields[5].GetUInt32(); ConditionType condition = (ConditionType)fields[6].GetUInt8(); uint32 cond_value1 = fields[7].GetUInt32(); uint32 cond_value2 = fields[8].GetUInt32(); + if(maxcount > std::numeric_limits<uint8>::max()) + { + sLog.outErrorDb("Table '%s' entry %d item %d: maxcount value (%u) to large. must be less %u - skipped", GetName(), entry, maxcount,std::numeric_limits<uint8>::max()); + continue; // error already printed to log/console. + } + + if(!PlayerCondition::IsValid(condition,cond_value1, cond_value2)) { sLog.outErrorDb("... in table '%s' entry %u item %u", GetName(), entry, item); @@ -251,6 +258,12 @@ bool LootStoreItem::Roll(bool rate) const // Checks correctness of values bool LootStoreItem::IsValid(LootStore const& store, uint32 entry) const { + if(group >= 1 << 7) // it stored in 7 bit field + { + sLog.outErrorDb("Table '%s' entry %d item %d: group (%u) must be less %u - skipped", store.GetName(), entry, itemid, group, 1 << 7); + return false; + } + if (mincountOrRef == 0) { sLog.outErrorDb("Table '%s' entry %d item %d: wrong mincountOrRef (%d) - skipped", store.GetName(), entry, itemid, mincountOrRef); diff --git a/src/game/LootMgr.h b/src/game/LootMgr.h index 7841a2e0d3b..79d292cf8d4 100644 --- a/src/game/LootMgr.h +++ b/src/game/LootMgr.h @@ -65,17 +65,17 @@ struct LootStoreItem uint32 itemid; // id of the item float chance; // always positive, chance to drop for both quest and non-quest items, chance to be used for refs int32 mincountOrRef; // mincount for drop items (positive) or minus referenced TemplateleId (negative) - uint8 group :8; + uint8 group :7; + bool needs_quest :1; // quest drop (negative ChanceOrQuestChance in DB) uint8 maxcount :8; // max drop count for the item (mincountOrRef positive) or Ref multiplicator (mincountOrRef negative) uint16 conditionId :16; // additional loot condition Id - bool needs_quest :1; // quest drop (negative ChanceOrQuestChance in DB) // Constructor, converting ChanceOrQuestChance -> (chance, needs_quest) // displayid is filled in IsValid() which must be called after LootStoreItem(uint32 _itemid, float _chanceOrQuestChance, int8 _group, uint8 _conditionId, int32 _mincountOrRef, uint8 _maxcount) : itemid(_itemid), chance(fabs(_chanceOrQuestChance)), mincountOrRef(_mincountOrRef), - group(_group), maxcount(_maxcount), conditionId(_conditionId), - needs_quest(_chanceOrQuestChance < 0) {} + group(_group), needs_quest(_chanceOrQuestChance < 0), maxcount(_maxcount), conditionId(_conditionId) + {} bool Roll(bool rate) const; // Checks if the entry takes it's chance (at loot generation) bool IsValid(LootStore const& store, uint32 entry) const; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 2f255c5e69b..d75e85c3f61 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7393" + #define REVISION_NR "7394" #endif // __REVISION_NR_H__ |