Core/Movement: use helpers for validation

(cherry picked from commit 7118806231)
This commit is contained in:
ccrs
2018-04-23 23:35:31 +02:00
committed by Shauren
parent d59a6af9c6
commit 0b6049fe0b
4 changed files with 8 additions and 7 deletions

View File

@@ -920,7 +920,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
}
case SMART_EVENT_MOVEMENTINFORM:
{
if (e.event.movementInform.type >= MAX_MOTION_TYPE)
if (IsInvalidMovementGeneratorType(e.event.movementInform.type))
{
TC_LOG_ERROR("sql.sql", "SmartAIMgr: Entry " SI64FMTD " SourceType %u Event %u Action %u uses invalid Motion type %u, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.event.movementInform.type);
return false;

View File

@@ -9785,7 +9785,7 @@ void Unit::StopMoving()
void Unit::PauseMovement(uint32 timer/* = 0*/, uint8 slot/* = 0*/, bool forced/* = true*/)
{
if (slot >= MAX_MOTION_SLOT)
if (IsInvalidMovementSlot(slot))
return;
if (MovementGenerator* movementGenerator = GetMotionMaster()->GetMotionSlot(MovementSlot(slot)))
@@ -9797,7 +9797,7 @@ void Unit::PauseMovement(uint32 timer/* = 0*/, uint8 slot/* = 0*/, bool forced/*
void Unit::ResumeMovement(uint32 timer/* = 0*/, uint8 slot/* = 0*/)
{
if (slot >= MAX_MOTION_SLOT)
if (IsInvalidMovementSlot(slot))
return;
if (MovementGenerator* movementGenerator = GetMotionMaster()->GetMotionSlot(MovementSlot(slot)))

View File

@@ -137,7 +137,7 @@ void MotionMaster::Clear(bool reset /*= true*/)
void MotionMaster::Clear(MovementSlot slot)
{
if (empty() || slot >= MAX_MOTION_SLOT)
if (empty() || IsInvalidMovementSlot(slot))
return;
if (_cleanFlag & MOTIONMMASTER_CLEANFLAG_UPDATE)
@@ -174,7 +174,7 @@ MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const
MovementGeneratorType MotionMaster::GetMotionSlotType(MovementSlot slot) const
{
if (empty() || slot >= MAX_MOTION_SLOT || !_slot[slot])
if (empty() || IsInvalidMovementSlot(slot) || !_slot[slot])
return MAX_MOTION_TYPE;
return _slot[slot]->GetMovementGeneratorType();
@@ -182,7 +182,7 @@ MovementGeneratorType MotionMaster::GetMotionSlotType(MovementSlot slot) const
MovementGenerator* MotionMaster::GetMotionSlot(MovementSlot slot) const
{
if (empty() || slot >= MAX_MOTION_SLOT || !_slot[slot])
if (empty() || IsInvalidMovementSlot(slot) || !_slot[slot])
return nullptr;
return _slot[slot];

View File

@@ -99,6 +99,7 @@ struct JumpArrivalCastArgs
ObjectGuid Target;
};
inline bool IsInvalidMovementGeneratorType(MovementGeneratorType const type) { return type == MAX_DB_MOTION_TYPE || type == MAX_MOTION_TYPE; }
inline bool IsInvalidMovementGeneratorType(uint8 const type) { return type == MAX_DB_MOTION_TYPE || type >= MAX_MOTION_TYPE; }
inline bool IsInvalidMovementSlot(uint8 const slot) { return slot >= MAX_MOTION_SLOT; }
#endif