factionTemplate->faction can be 0, add appropriate checks to prevent crashes and unexpected work. Author: VladimirMangos
--HG-- branch : trunk
This commit is contained in:
@@ -86,7 +86,7 @@ ObjectAccessor::GetNPCIfCanInteractWith(Player const &player, uint64 guid, uint3
|
|||||||
if(factionTemplate)
|
if(factionTemplate)
|
||||||
{
|
{
|
||||||
FactionEntry const* faction = sFactionStore.LookupEntry(factionTemplate->faction);
|
FactionEntry const* faction = sFactionStore.LookupEntry(factionTemplate->faction);
|
||||||
if( faction->reputationListID >= 0 && player.GetReputationRank(faction) <= REP_UNFRIENDLY)
|
if( faction && faction->reputationListID >= 0 && player.GetReputationRank(faction) <= REP_UNFRIENDLY)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -5757,7 +5757,8 @@ void Player::SetFactionVisibleForFactionTemplateId(uint32 FactionTemplateId)
|
|||||||
if(!factionTemplateEntry)
|
if(!factionTemplateEntry)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SetFactionVisibleForFactionId(factionTemplateEntry->faction);
|
if(factionTemplateEntry->faction)
|
||||||
|
SetFactionVisibleForFactionId(factionTemplateEntry->faction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::SetFactionVisibleForFactionId(uint32 FactionId)
|
void Player::SetFactionVisibleForFactionId(uint32 FactionId)
|
||||||
@@ -19247,7 +19248,7 @@ BGQueueIdBasedOnLevel Player::GetBattleGroundQueueIdFromLevel(BattleGroundTypeId
|
|||||||
float Player::GetReputationPriceDiscount( Creature const* pCreature ) const
|
float Player::GetReputationPriceDiscount( Creature const* pCreature ) const
|
||||||
{
|
{
|
||||||
FactionTemplateEntry const* vendor_faction = pCreature->getFactionTemplateEntry();
|
FactionTemplateEntry const* vendor_faction = pCreature->getFactionTemplateEntry();
|
||||||
if(!vendor_faction)
|
if(!vendor_faction || !vendor_faction->faction)
|
||||||
return 1.0f;
|
return 1.0f;
|
||||||
|
|
||||||
ReputationRank rank = GetReputationRank(vendor_faction->faction);
|
ReputationRank rank = GetReputationRank(vendor_faction->faction);
|
||||||
|
|||||||
+44
-32
@@ -7369,28 +7369,34 @@ bool Unit::IsHostileTo(Unit const* unit) const
|
|||||||
if(tester->GetTypeId()==TYPEID_PLAYER)
|
if(tester->GetTypeId()==TYPEID_PLAYER)
|
||||||
{
|
{
|
||||||
// forced reaction
|
// forced reaction
|
||||||
ForcedReactions::const_iterator forceItr = ((Player*)tester)->m_forcedReactions.find(target_faction->faction);
|
if(target_faction->faction)
|
||||||
if(forceItr!=((Player*)tester)->m_forcedReactions.end())
|
{
|
||||||
return forceItr->second <= REP_HOSTILE;
|
ForcedReactions::const_iterator forceItr = ((Player*)tester)->m_forcedReactions.find(target_faction->faction);
|
||||||
|
if(forceItr!=((Player*)tester)->m_forcedReactions.end())
|
||||||
|
return forceItr->second <= REP_HOSTILE;
|
||||||
|
|
||||||
// if faction have reputation then hostile state for tester at 100% dependent from at_war state
|
// if faction have reputation then hostile state for tester at 100% dependent from at_war state
|
||||||
if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction))
|
if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction))
|
||||||
if(raw_target_faction->reputationListID >=0)
|
if(raw_target_faction->reputationListID >=0)
|
||||||
if(FactionState const* factionState = ((Player*)tester)->GetFactionState(raw_target_faction))
|
if(FactionState const* factionState = ((Player*)tester)->GetFactionState(raw_target_faction))
|
||||||
return (factionState->Flags & FACTION_FLAG_AT_WAR);
|
return (factionState->Flags & FACTION_FLAG_AT_WAR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// CvP forced reaction and reputation case
|
// CvP forced reaction and reputation case
|
||||||
else if(target->GetTypeId()==TYPEID_PLAYER)
|
else if(target->GetTypeId()==TYPEID_PLAYER)
|
||||||
{
|
{
|
||||||
// forced reaction
|
// forced reaction
|
||||||
ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction);
|
if(tester_faction->faction)
|
||||||
if(forceItr!=((Player const*)target)->m_forcedReactions.end())
|
{
|
||||||
return forceItr->second <= REP_HOSTILE;
|
ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction);
|
||||||
|
if(forceItr!=((Player const*)target)->m_forcedReactions.end())
|
||||||
|
return forceItr->second <= REP_HOSTILE;
|
||||||
|
|
||||||
// apply reputation state
|
// apply reputation state
|
||||||
FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction);
|
FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction);
|
||||||
if(raw_tester_faction && raw_tester_faction->reputationListID >=0 )
|
if(raw_tester_faction && raw_tester_faction->reputationListID >=0 )
|
||||||
return ((Player const*)target)->GetReputationRank(raw_tester_faction) <= REP_HOSTILE;
|
return ((Player const*)target)->GetReputationRank(raw_tester_faction) <= REP_HOSTILE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// common faction based case (CvC,PvC,CvP)
|
// common faction based case (CvC,PvC,CvP)
|
||||||
@@ -7478,28 +7484,34 @@ bool Unit::IsFriendlyTo(Unit const* unit) const
|
|||||||
if(tester->GetTypeId()==TYPEID_PLAYER)
|
if(tester->GetTypeId()==TYPEID_PLAYER)
|
||||||
{
|
{
|
||||||
// forced reaction
|
// forced reaction
|
||||||
ForcedReactions::const_iterator forceItr = ((Player const*)tester)->m_forcedReactions.find(target_faction->faction);
|
if(target_faction->faction)
|
||||||
if(forceItr!=((Player const*)tester)->m_forcedReactions.end())
|
{
|
||||||
return forceItr->second >= REP_FRIENDLY;
|
ForcedReactions::const_iterator forceItr = ((Player const*)tester)->m_forcedReactions.find(target_faction->faction);
|
||||||
|
if(forceItr!=((Player const*)tester)->m_forcedReactions.end())
|
||||||
|
return forceItr->second >= REP_FRIENDLY;
|
||||||
|
|
||||||
// if faction have reputation then friendly state for tester at 100% dependent from at_war state
|
// if faction have reputation then friendly state for tester at 100% dependent from at_war state
|
||||||
if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction))
|
if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction))
|
||||||
if(raw_target_faction->reputationListID >=0)
|
if(raw_target_faction->reputationListID >=0)
|
||||||
if(FactionState const* FactionState = ((Player*)tester)->GetFactionState(raw_target_faction))
|
if(FactionState const* FactionState = ((Player*)tester)->GetFactionState(raw_target_faction))
|
||||||
return !(FactionState->Flags & FACTION_FLAG_AT_WAR);
|
return !(FactionState->Flags & FACTION_FLAG_AT_WAR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// CvP forced reaction and reputation case
|
// CvP forced reaction and reputation case
|
||||||
else if(target->GetTypeId()==TYPEID_PLAYER)
|
else if(target->GetTypeId()==TYPEID_PLAYER)
|
||||||
{
|
{
|
||||||
// forced reaction
|
// forced reaction
|
||||||
ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction);
|
if(tester_faction->faction)
|
||||||
if(forceItr!=((Player const*)target)->m_forcedReactions.end())
|
{
|
||||||
return forceItr->second >= REP_FRIENDLY;
|
ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction);
|
||||||
|
if(forceItr!=((Player const*)target)->m_forcedReactions.end())
|
||||||
|
return forceItr->second >= REP_FRIENDLY;
|
||||||
|
|
||||||
// apply reputation state
|
// apply reputation state
|
||||||
if(FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction))
|
if(FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction))
|
||||||
if(raw_tester_faction->reputationListID >=0 )
|
if(raw_tester_faction->reputationListID >=0 )
|
||||||
return ((Player const*)target)->GetReputationRank(raw_tester_faction) >= REP_FRIENDLY;
|
return ((Player const*)target)->GetReputationRank(raw_tester_faction) >= REP_FRIENDLY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// common faction based case (CvC,PvC,CvP)
|
// common faction based case (CvC,PvC,CvP)
|
||||||
@@ -7509,7 +7521,7 @@ bool Unit::IsFriendlyTo(Unit const* unit) const
|
|||||||
bool Unit::IsHostileToPlayers() const
|
bool Unit::IsHostileToPlayers() const
|
||||||
{
|
{
|
||||||
FactionTemplateEntry const* my_faction = getFactionTemplateEntry();
|
FactionTemplateEntry const* my_faction = getFactionTemplateEntry();
|
||||||
if(!my_faction)
|
if(!my_faction || !my_faction->faction)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction);
|
FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction);
|
||||||
@@ -7522,7 +7534,7 @@ bool Unit::IsHostileToPlayers() const
|
|||||||
bool Unit::IsNeutralToAll() const
|
bool Unit::IsNeutralToAll() const
|
||||||
{
|
{
|
||||||
FactionTemplateEntry const* my_faction = getFactionTemplateEntry();
|
FactionTemplateEntry const* my_faction = getFactionTemplateEntry();
|
||||||
if(!my_faction)
|
if(!my_faction || !my_faction->faction)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction);
|
FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction);
|
||||||
|
|||||||
@@ -735,24 +735,40 @@ struct FactionTemplateEntry
|
|||||||
{
|
{
|
||||||
if(ID == entry.ID)
|
if(ID == entry.ID)
|
||||||
return true;
|
return true;
|
||||||
if(enemyFaction[0] == entry.faction || enemyFaction[1] == entry.faction || enemyFaction[2] == entry.faction || enemyFaction[3] == entry.faction )
|
if(entry.faction)
|
||||||
return false;
|
{
|
||||||
if(friendFaction[0] == entry.faction || friendFaction[1] == entry.faction || friendFaction[2] == entry.faction || friendFaction[3] == entry.faction )
|
for(int i = 0; i < 4; ++i)
|
||||||
return true;
|
if (enemyFaction[i] == entry.faction)
|
||||||
|
return false;
|
||||||
|
for(int i = 0; i < 4; ++i)
|
||||||
|
if (friendFaction[i] == entry.faction)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return (friendlyMask & entry.ourMask) || (ourMask & entry.friendlyMask);
|
return (friendlyMask & entry.ourMask) || (ourMask & entry.friendlyMask);
|
||||||
}
|
}
|
||||||
bool IsHostileTo(FactionTemplateEntry const& entry) const
|
bool IsHostileTo(FactionTemplateEntry const& entry) const
|
||||||
{
|
{
|
||||||
if(ID == entry.ID)
|
if(ID == entry.ID)
|
||||||
return false;
|
return false;
|
||||||
if(enemyFaction[0] == entry.faction || enemyFaction[1] == entry.faction || enemyFaction[2] == entry.faction || enemyFaction[3] == entry.faction )
|
if(entry.faction)
|
||||||
return true;
|
{
|
||||||
if(friendFaction[0] == entry.faction || friendFaction[1] == entry.faction || friendFaction[2] == entry.faction || friendFaction[3] == entry.faction )
|
for(int i = 0; i < 4; ++i)
|
||||||
return false;
|
if (enemyFaction[i] == entry.faction)
|
||||||
|
return true;
|
||||||
|
for(int i = 0; i < 4; ++i)
|
||||||
|
if (friendFaction[i] == entry.faction)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return (hostileMask & entry.ourMask) != 0;
|
return (hostileMask & entry.ourMask) != 0;
|
||||||
}
|
}
|
||||||
bool IsHostileToPlayers() const { return (hostileMask & FACTION_MASK_PLAYER) !=0; }
|
bool IsHostileToPlayers() const { return (hostileMask & FACTION_MASK_PLAYER) !=0; }
|
||||||
bool IsNeutralToAll() const { return hostileMask == 0 && friendlyMask == 0 && enemyFaction[0]==0 && enemyFaction[1]==0 && enemyFaction[2]==0 && enemyFaction[3]==0; }
|
bool IsNeutralToAll() const
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 4; ++i)
|
||||||
|
if (enemyFaction[i] != 0)
|
||||||
|
return false;
|
||||||
|
return hostileMask == 0 && friendlyMask == 0;
|
||||||
|
}
|
||||||
bool IsContestedGuardFaction() const { return (factionFlags & FACTION_TEMPLATE_FLAG_CONTESTED_GUARD)!=0; }
|
bool IsContestedGuardFaction() const { return (factionFlags & FACTION_TEMPLATE_FLAG_CONTESTED_GUARD)!=0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user