From dbfc1cd881fc6781afe5fb5450018fa033677423 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sat, 7 Mar 2009 03:27:43 +0300 Subject: [PATCH] [7394] Check loot_template.maxcount for max allowed value (255) and make better report for this case. 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. --- src/game/AchievementMgr.cpp | 1 - src/game/LootMgr.cpp | 15 ++++++++++++++- src/game/LootMgr.h | 8 ++++---- 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 df209edf..6048c8ea 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 3097cff4..9571bc35 100644 --- a/src/game/LootMgr.cpp +++ b/src/game/LootMgr.cpp @@ -114,11 +114,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::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::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); @@ -248,6 +255,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 0c34d790..b16757d4 100644 --- a/src/game/LootMgr.h +++ b/src/game/LootMgr.h @@ -63,17 +63,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 2f255c5e..d75e85c3 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__ -- 2.11.4.GIT