From d800c87137088f2cfdb66e8086c64321ca9c3509 Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 6 May 2022 18:45:51 +0200 Subject: Core/Misc: Remove implicit conversions from RaceMask class, fixes racemask check failing during loading from db --- src/server/game/Achievements/CriteriaHandler.cpp | 2 +- src/server/game/Conditions/ConditionMgr.cpp | 7 ++++--- src/server/game/DataStores/DB2Stores.cpp | 2 +- src/server/game/Entities/Player/Player.cpp | 4 ++-- src/server/game/Globals/ObjectMgr.cpp | 18 +++++++++--------- src/server/game/Globals/ObjectMgr.h | 2 +- src/server/game/Handlers/CharacterHandler.cpp | 4 ++-- src/server/game/Miscellaneous/RaceMask.h | 19 +++++++++++-------- src/server/game/Reputation/ReputationMgr.cpp | 2 +- src/server/game/Spells/SpellMgr.cpp | 6 +++--- src/server/scripts/Commands/cs_learn.cpp | 2 +- 11 files changed, 36 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/server/game/Achievements/CriteriaHandler.cpp b/src/server/game/Achievements/CriteriaHandler.cpp index 52c6ea3d895..cabcf78e27c 100644 --- a/src/server/game/Achievements/CriteriaHandler.cpp +++ b/src/server/game/Achievements/CriteriaHandler.cpp @@ -264,7 +264,7 @@ bool CriteriaData::IsValid(Criteria const* criteria) criteria->ID, criteria->Entry->Type, DataType, ClassRace.Class); return false; } - if (ClassRace.Race && ((UI64LIT(1) << (ClassRace.Race-1)) & RACEMASK_ALL_PLAYABLE) == 0) + if (ClassRace.Race && !RACEMASK_ALL_PLAYABLE.HasRace(ClassRace.Race)) { TC_LOG_ERROR("sql.sql", "Table `criteria_data` (Entry: %u Type: %u) for data type CRITERIA_DATA_TYPE_S_PLAYER_CLASS_RACE (%u) contains a non-existing race entry in value2 (%u), ignored.", criteria->ID, criteria->Entry->Type, DataType, ClassRace.Race); diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp index 796080a020f..e154df64f7a 100644 --- a/src/server/game/Conditions/ConditionMgr.cpp +++ b/src/server/game/Conditions/ConditionMgr.cpp @@ -2230,9 +2230,10 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) const } case CONDITION_RACE: { - if (uint32(cond->ConditionValue1 & ~RACEMASK_ALL_PLAYABLE)) // uint32 works thanks to weird index remapping in racemask + Trinity::RaceMask invalidRaceMask = Trinity::RaceMask{ cond->ConditionValue1 } & ~RACEMASK_ALL_PLAYABLE; + if (!invalidRaceMask.IsEmpty()) // uint32 works thanks to weird index remapping in racemask { - TC_LOG_ERROR("sql.sql", "%s has non existing racemask (" UI64FMTD "), skipped.", cond->ToString(true).c_str(), cond->ConditionValue1 & ~RACEMASK_ALL_PLAYABLE); + TC_LOG_ERROR("sql.sql", "%s has non existing racemask (" UI64FMTD "), skipped.", cond->ToString(true).c_str(), invalidRaceMask.RawValue); return false; } break; @@ -2821,7 +2822,7 @@ bool ConditionMgr::IsPlayerMeetingCondition(Player const* player, PlayerConditio } } - if (condition->RaceMask && !condition->RaceMask.HasRace(player->GetRace())) + if (!condition->RaceMask.IsEmpty() && !condition->RaceMask.HasRace(player->GetRace())) return false; if (condition->ClassMask && !(player->GetClassMask() & condition->ClassMask)) diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp index 0ee61d79af4..c270088fc76 100644 --- a/src/server/game/DataStores/DB2Stores.cpp +++ b/src/server/game/DataStores/DB2Stores.cpp @@ -2952,7 +2952,7 @@ SkillRaceClassInfoEntry const* DB2Manager::GetSkillRaceClassInfo(uint32 skill, u auto bounds = _skillRaceClassInfoBySkill.equal_range(skill); for (auto itr = bounds.first; itr != bounds.second; ++itr) { - if (itr->second->RaceMask && !(itr->second->RaceMask.HasRace(race))) + if (!itr->second->RaceMask.IsEmpty() && !(itr->second->RaceMask.HasRace(race))) continue; if (itr->second->ClassMask && !(itr->second->ClassMask & (1 << (class_ - 1)))) continue; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 0653036b3f1..eb12ee8b6b4 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -25018,7 +25018,7 @@ void Player::LearnSkillRewardedSpells(uint32 skillId, uint32 skillValue, Races r continue; // Check race if set - if (ability->RaceMask && !ability->RaceMask.HasRace(race)) + if (!ability->RaceMask.IsEmpty() && !ability->RaceMask.HasRace(race)) continue; // Check class if set @@ -25380,7 +25380,7 @@ bool Player::IsSpellFitByClassAndRace(uint32 spell_id) const for (SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx) { // skip wrong race skills - if (_spell_idx->second->RaceMask && !_spell_idx->second->RaceMask.HasRace(race)) + if (!_spell_idx->second->RaceMask.IsEmpty() && !_spell_idx->second->RaceMask.HasRace(race)) continue; // skip wrong class skills diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index a054014d5bd..cd480574a11 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -4076,7 +4076,7 @@ void ObjectMgr::LoadPlayerInfo() uint32 classMask = fields[1].GetUInt32(); uint32 spellId = fields[2].GetUInt32(); - if (raceMask && !(raceMask.RawValue & RACEMASK_ALL_PLAYABLE)) + if (!raceMask.IsEmpty() && (raceMask & RACEMASK_ALL_PLAYABLE).IsEmpty()) { TC_LOG_ERROR("sql.sql", "Wrong race mask " UI64FMTD " in `playercreateinfo_spell_custom` table, ignoring.", raceMask.RawValue); continue; @@ -4090,7 +4090,7 @@ void ObjectMgr::LoadPlayerInfo() for (uint32 raceIndex = RACE_HUMAN; raceIndex < MAX_RACES; ++raceIndex) { - if (!raceMask || raceMask.HasRace(raceIndex)) + if (raceMask.IsEmpty() || raceMask.HasRace(raceIndex)) { for (uint32 classIndex = CLASS_WARRIOR; classIndex < MAX_CLASSES; ++classIndex) { @@ -4137,7 +4137,7 @@ void ObjectMgr::LoadPlayerInfo() uint32 spellId = fields[2].GetUInt32(); int8 playerCreateMode = fields[3].GetInt8(); - if (raceMask && !(raceMask.RawValue & RACEMASK_ALL_PLAYABLE)) + if (!raceMask.IsEmpty() && (raceMask & RACEMASK_ALL_PLAYABLE).IsEmpty()) { TC_LOG_ERROR("sql.sql", "Wrong race mask " UI64FMTD " in `playercreateinfo_cast_spell` table, ignoring.", raceMask.RawValue); continue; @@ -4157,7 +4157,7 @@ void ObjectMgr::LoadPlayerInfo() for (uint32 raceIndex = RACE_HUMAN; raceIndex < MAX_RACES; ++raceIndex) { - if (!raceMask || raceMask.HasRace(raceIndex)) + if (raceMask.IsEmpty() || raceMask.HasRace(raceIndex)) { for (uint32 classIndex = CLASS_WARRIOR; classIndex < MAX_CLASSES; ++classIndex) { @@ -4812,7 +4812,7 @@ void ObjectMgr::LoadQuests() // AllowableRaces, can be -1/RACEMASK_ALL_PLAYABLE to allow any race if (qinfo->_allowableRaces.RawValue != uint64(-1)) { - if (qinfo->_allowableRaces && !(qinfo->_allowableRaces.RawValue & RACEMASK_ALL_PLAYABLE)) + if (!qinfo->_allowableRaces.IsEmpty() && (qinfo->_allowableRaces & RACEMASK_ALL_PLAYABLE).IsEmpty()) { TC_LOG_ERROR("sql.sql", "Quest %u does not contain any playable races in `AllowableRaces` (" UI64FMTD "), value set to -1 (all races).", qinfo->GetQuestId(), qinfo->_allowableRaces.RawValue); qinfo->_allowableRaces.RawValue = uint64(-1); @@ -9071,7 +9071,7 @@ int32 ObjectMgr::GetBaseReputationOf(FactionEntry const* factionEntry, uint8 rac { if ((!factionEntry->ReputationClassMask[i] || factionEntry->ReputationClassMask[i] & classMask) && - (!factionEntry->ReputationRaceMask[i] || + (factionEntry->ReputationRaceMask[i].IsEmpty() || factionEntry->ReputationRaceMask[i].HasRace(race))) return factionEntry->ReputationBase[i]; } @@ -9282,7 +9282,7 @@ void ObjectMgr::LoadMailLevelRewards() Field* fields = result->Fetch(); uint8 level = fields[0].GetUInt8(); - uint64 raceMask = fields[1].GetUInt64(); + Trinity::RaceMask raceMask = { fields[1].GetUInt64() }; uint32 mailTemplateId = fields[2].GetUInt32(); uint32 senderEntry = fields[3].GetUInt32(); @@ -9292,9 +9292,9 @@ void ObjectMgr::LoadMailLevelRewards() continue; } - if (!(raceMask & RACEMASK_ALL_PLAYABLE)) + if ((raceMask & RACEMASK_ALL_PLAYABLE).IsEmpty()) { - TC_LOG_ERROR("sql.sql", "Table `mail_level_reward` has raceMask (" UI64FMTD ") for level %u that not include any player races, ignoring.", raceMask, level); + TC_LOG_ERROR("sql.sql", "Table `mail_level_reward` has raceMask (" UI64FMTD ") for level %u that not include any player races, ignoring.", raceMask.RawValue, level); continue; } diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 70e37e6aa3c..28b8030f0d3 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -687,7 +687,7 @@ struct PetLevelInfo struct MailLevelReward { MailLevelReward() : raceMask({ 0 }), mailTemplateId(0), senderEntry(0) { } - MailLevelReward(uint64 _raceMask, uint32 _mailTemplateId, uint32 _senderEntry) : raceMask({ _raceMask }), mailTemplateId(_mailTemplateId), senderEntry(_senderEntry) { } + MailLevelReward(Trinity::RaceMask _raceMask, uint32 _mailTemplateId, uint32 _senderEntry) : raceMask(_raceMask), mailTemplateId(_mailTemplateId), senderEntry(_senderEntry) { } Trinity::RaceMask raceMask; uint32 mailTemplateId; diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index 7c98070ed15..d893b118470 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -2420,8 +2420,8 @@ void WorldSession::HandleCharRaceOrFactionChangeCallback(std::shared_ptrGetQuestTemplates(); for (auto const& questTemplatePair : questTemplates) { - uint64 newRaceMask = (newTeamId == TEAM_ALLIANCE) ? RACEMASK_ALLIANCE : RACEMASK_HORDE; - if (questTemplatePair.second.GetAllowableRaces().RawValue != uint64(-1) && !(questTemplatePair.second.GetAllowableRaces().RawValue & newRaceMask)) + Trinity::RaceMask newRaceMask = (newTeamId == TEAM_ALLIANCE) ? RACEMASK_ALLIANCE : RACEMASK_HORDE; + if (questTemplatePair.second.GetAllowableRaces().RawValue != uint64(-1) && (questTemplatePair.second.GetAllowableRaces() & newRaceMask).IsEmpty()) { stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_QUESTSTATUS_REWARDED_ACTIVE_BY_QUEST); stmt->setUInt64(0, lowGuid); diff --git a/src/server/game/Miscellaneous/RaceMask.h b/src/server/game/Miscellaneous/RaceMask.h index 7e6d38d277f..07246fd8118 100644 --- a/src/server/game/Miscellaneous/RaceMask.h +++ b/src/server/game/Miscellaneous/RaceMask.h @@ -93,12 +93,15 @@ struct RaceMask return raceId < MAX_RACES && raceBits[raceId] >= 0 && raceBits[raceId] < 64 ? (T(1) << raceBits[raceId]) : T(0); } - constexpr operator bool() const { return RawValue != T(0); } - constexpr bool operator!() const { return !operator bool(); } + constexpr bool IsEmpty() const { return RawValue != T(0); } + + constexpr RaceMask operator&(RaceMask right) const { return { RawValue & right.RawValue }; } + constexpr RaceMask operator|(RaceMask right) const { return { RawValue | right.RawValue }; } + constexpr RaceMask operator~() const { return { ~RawValue }; } }; } -constexpr uint64 RACEMASK_ALL_PLAYABLE = std::integral_constant RACEMASK_ALL_PLAYABLE = { std::integral_constant::GetMaskForRace(RACE_HUMAN) | Trinity::RaceMask::GetMaskForRace(RACE_ORC) | @@ -124,11 +127,11 @@ constexpr uint64 RACEMASK_ALL_PLAYABLE = std::integral_constant::GetMaskForRace(RACE_DARK_IRON_DWARF) | Trinity::RaceMask::GetMaskForRace(RACE_VULPERA) | Trinity::RaceMask::GetMaskForRace(RACE_MAGHAR_ORC) | - Trinity::RaceMask::GetMaskForRace(RACE_MECHAGNOME)>::value; + Trinity::RaceMask::GetMaskForRace(RACE_MECHAGNOME)>::value }; -constexpr uint64 RACEMASK_NEUTRAL = std::integral_constant::GetMaskForRace(RACE_PANDAREN_NEUTRAL)>::value; +constexpr Trinity::RaceMask RACEMASK_NEUTRAL = { std::integral_constant::GetMaskForRace(RACE_PANDAREN_NEUTRAL)>::value }; -constexpr uint64 RACEMASK_ALLIANCE = std::integral_constant RACEMASK_ALLIANCE = { std::integral_constant::GetMaskForRace(RACE_HUMAN) | Trinity::RaceMask::GetMaskForRace(RACE_DWARF) | Trinity::RaceMask::GetMaskForRace(RACE_NIGHTELF) | @@ -140,8 +143,8 @@ constexpr uint64 RACEMASK_ALLIANCE = std::integral_constant::GetMaskForRace(RACE_LIGHTFORGED_DRAENEI) | Trinity::RaceMask::GetMaskForRace(RACE_KUL_TIRAN) | Trinity::RaceMask::GetMaskForRace(RACE_DARK_IRON_DWARF) | - Trinity::RaceMask::GetMaskForRace(RACE_MECHAGNOME)>::value; + Trinity::RaceMask::GetMaskForRace(RACE_MECHAGNOME)>::value }; -constexpr uint64 RACEMASK_HORDE = std::integral_constant::value; +constexpr Trinity::RaceMask RACEMASK_HORDE = { std::integral_constant::value }; #endif // RaceMask_h__ diff --git a/src/server/game/Reputation/ReputationMgr.cpp b/src/server/game/Reputation/ReputationMgr.cpp index eff047a9698..33e8c881f95 100644 --- a/src/server/game/Reputation/ReputationMgr.cpp +++ b/src/server/game/Reputation/ReputationMgr.cpp @@ -727,7 +727,7 @@ int32 ReputationMgr::GetFactionDataIndexForRaceAndClass(FactionEntry const* fact uint32 classMask = _player->GetClassMask(); for (int32 i = 0; i < 4; i++) { - if ((factionEntry->ReputationRaceMask[i].HasRace(race) || (!factionEntry->ReputationRaceMask[i] && factionEntry->ReputationClassMask[i] != 0)) + if ((factionEntry->ReputationRaceMask[i].HasRace(race) || (factionEntry->ReputationRaceMask[i].IsEmpty() && factionEntry->ReputationClassMask[i] != 0)) && (factionEntry->ReputationClassMask[i] & classMask || factionEntry->ReputationClassMask[i] == 0)) return i; diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index fd780964fcb..f1a3f88fead 100644 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -715,7 +715,7 @@ bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32 if (!player || gender != player->GetNativeGender()) return false; - if (raceMask) // is not expected race + if (!raceMask.IsEmpty()) // is not expected race if (!player || !raceMask.HasRace(player->GetRace())) return false; @@ -2291,7 +2291,7 @@ void SpellMgr::LoadSpellAreas() continue; if (spellArea.auraSpell != itr->second.auraSpell) continue; - if ((spellArea.raceMask & itr->second.raceMask) == 0) + if ((spellArea.raceMask & itr->second.raceMask).IsEmpty()) continue; if (spellArea.gender != itr->second.gender) continue; @@ -2382,7 +2382,7 @@ void SpellMgr::LoadSpellAreas() } } - if (spellArea.raceMask && (spellArea.raceMask.RawValue & RACEMASK_ALL_PLAYABLE) == 0) + if (!spellArea.raceMask.IsEmpty() && (spellArea.raceMask & RACEMASK_ALL_PLAYABLE).IsEmpty()) { TC_LOG_ERROR("sql.sql", "The spell %u listed in `spell_area` has wrong race mask (" UI64FMTD ") requirement.", spell, spellArea.raceMask.RawValue); continue; diff --git a/src/server/scripts/Commands/cs_learn.cpp b/src/server/scripts/Commands/cs_learn.cpp index 837245a290c..deba00eac0d 100644 --- a/src/server/scripts/Commands/cs_learn.cpp +++ b/src/server/scripts/Commands/cs_learn.cpp @@ -438,7 +438,7 @@ public: continue; // skip racial skills - if (skillLine->RaceMask) + if (!skillLine->RaceMask.IsEmpty()) continue; // skip wrong class skills -- cgit v1.2.3