Core/Units: Fixed possible use after free in ThreatManager
Port From (https://github.com/TrinityCore/TrinityCore/commit/3e3968b63c4192b766de69c8f4744adba406c94b)
This commit is contained in:
@@ -23,7 +23,7 @@ namespace Game.Combat
|
|||||||
uint _updateTimer;
|
uint _updateTimer;
|
||||||
List<ThreatReference> _sortedThreatList = new();
|
List<ThreatReference> _sortedThreatList = new();
|
||||||
Dictionary<ObjectGuid, ThreatReference> _myThreatListEntries = new();
|
Dictionary<ObjectGuid, ThreatReference> _myThreatListEntries = new();
|
||||||
List<ThreatReference> _needsAIUpdate = new();
|
List<ObjectGuid> _needsAIUpdate = new();
|
||||||
ThreatReference _currentVictimRef;
|
ThreatReference _currentVictimRef;
|
||||||
ThreatReference _fixateRef;
|
ThreatReference _fixateRef;
|
||||||
|
|
||||||
@@ -497,12 +497,18 @@ namespace Game.Combat
|
|||||||
|
|
||||||
void ProcessAIUpdates()
|
void ProcessAIUpdates()
|
||||||
{
|
{
|
||||||
CreatureAI ai = _owner.ToCreature().GetAI();
|
CreatureAI ai = _owner.ToCreature()?.GetAI();
|
||||||
List<ThreatReference> v = new(_needsAIUpdate); // _needClientUpdate is now empty in case this triggers a recursive call
|
|
||||||
if (ai == null)
|
if (ai == null)
|
||||||
return;
|
return;
|
||||||
foreach (ThreatReference refe in v)
|
|
||||||
ai.JustStartedThreateningMe(refe.GetVictim());
|
List<ObjectGuid> v = new(_needsAIUpdate); // _needClientUpdate is now empty in case this triggers a recursive call
|
||||||
|
|
||||||
|
foreach (ObjectGuid guid in v)
|
||||||
|
{
|
||||||
|
var refe = _myThreatListEntries.LookupByKey(guid);
|
||||||
|
if (refe != null)
|
||||||
|
ai.JustStartedThreateningMe(refe.GetVictim());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if a is LOWER on the threat list than b
|
// returns true if a is LOWER on the threat list than b
|
||||||
@@ -794,7 +800,7 @@ namespace Game.Combat
|
|||||||
// Resets the specified unit's threat to zero
|
// Resets the specified unit's threat to zero
|
||||||
public void ResetThreat(Unit target) { ScaleThreat(target, 0.0f); }
|
public void ResetThreat(Unit target) { ScaleThreat(target, 0.0f); }
|
||||||
|
|
||||||
public void RegisterForAIUpdate(ThreatReference refe) { _needsAIUpdate.Add(refe); }
|
public void RegisterForAIUpdate(ObjectGuid guid) { _needsAIUpdate.Add(guid); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum TauntState
|
public enum TauntState
|
||||||
@@ -864,7 +870,7 @@ namespace Game.Combat
|
|||||||
{
|
{
|
||||||
Online = ShouldBeSuppressed() ? OnlineState.Suppressed : OnlineState.Online;
|
Online = ShouldBeSuppressed() ? OnlineState.Suppressed : OnlineState.Online;
|
||||||
ListNotifyChanged();
|
ListNotifyChanged();
|
||||||
_mgr.RegisterForAIUpdate(this);
|
_mgr.RegisterForAIUpdate(GetVictim().GetGUID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user