Skip to content

Commit

Permalink
Fix some false positives with movement anticheat.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratkosrb committed Dec 17, 2023
1 parent 8f93351 commit c0d5742
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
23 changes: 17 additions & 6 deletions src/game/Anticheat/MovementAnticheat/MovementAnticheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ bool MovementAnticheat::CheckMultiJump(uint16 opcode)
return false;
}

#define NO_WALL_CLIMB_CHECK_MOVE_FLAGS (MOVEFLAG_JUMPING | MOVEFLAG_FALLINGFAR | MOVEFLAG_SWIMMING | MOVEFLAG_CAN_FLY | MOVEFLAG_FLYING | MOVEFLAG_PITCH_UP | MOVEFLAG_PITCH_DOWN | MOVEFLAG_ONTRANSPORT)
#define NO_WALL_CLIMB_CHECK_MOVE_FLAGS (MOVEFLAG_JUMPING | MOVEFLAG_FALLINGFAR | MOVEFLAG_SWIMMING | MOVEFLAG_CAN_FLY | MOVEFLAG_FLYING | MOVEFLAG_PITCH_UP | MOVEFLAG_PITCH_DOWN | MOVEFLAG_ONTRANSPORT | MOVEFLAG_SPLINE_ELEVATION)
#define NO_WALL_CLIMB_CHECK_UNIT_FLAGS (UNIT_FLAG_UNK_0 | UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_CONFUSED | UNIT_FLAG_FLEEING | UNIT_FLAG_POSSESSED)

bool MovementAnticheat::CheckWallClimb(MovementInfo const& movementInfo, uint16 opcode) const
Expand All @@ -996,7 +996,17 @@ bool MovementAnticheat::CheckWallClimb(MovementInfo const& movementInfo, uint16
float const angleRad = atan(deltaZ / deltaXY);
//float const angleDeg = angleRad * (360 / (M_PI_F * 2));

return angleRad > sWorld.getConfig(CONFIG_FLOAT_AC_MOVEMENT_CHEAT_WALL_CLIMB_ANGLE);
if (angleRad > sWorld.getConfig(CONFIG_FLOAT_AC_MOVEMENT_CHEAT_WALL_CLIMB_ANGLE))
{
// check height with and without vmaps and compare
// if player is stepping over model like stairs, that can increase wall climb angle
float const height1 = me->GetMap()->GetHeight(movementInfo.pos.x, movementInfo.pos.y, movementInfo.pos.z, false);
float const height2 = me->GetMap()->GetHeight(movementInfo.pos.x, movementInfo.pos.y, movementInfo.pos.z, true);
if ((std::abs(height1 - height2) < 0.5f) || (deltaZ > 5.0f))
return true;
}

return false;
}

bool MovementAnticheat::CheckForbiddenArea(MovementInfo const& movementInfo) const
Expand Down Expand Up @@ -1297,9 +1307,10 @@ bool MovementAnticheat::CheckTeleport(MovementInfo const& movementInfo) const
return true;

// check moving in given axis without appropriate move flags
// during fall collision with cliffs can change xy so skip that case
if (GetLastMovementInfo().ctime &&
!GetLastMovementInfo().HasMovementFlag(MOVEFLAG_MASK_XZ) &&
!movementInfo.HasMovementFlag(MOVEFLAG_MASK_XZ) &&
!GetLastMovementInfo().HasMovementFlag(MOVEFLAG_MASK_XZ | MOVEFLAG_JUMPING | MOVEFLAG_FALLINGFAR) &&
!movementInfo.HasMovementFlag(MOVEFLAG_MASK_XZ | MOVEFLAG_JUMPING | MOVEFLAG_FALLINGFAR) &&
GetLastMovementInfo().HasMovementFlag(MOVEFLAG_ONTRANSPORT) == movementInfo.HasMovementFlag(MOVEFLAG_ONTRANSPORT))
{
float const distance2d = movementInfo.HasMovementFlag(MOVEFLAG_ONTRANSPORT) ?
Expand All @@ -1311,8 +1322,8 @@ bool MovementAnticheat::CheckTeleport(MovementInfo const& movementInfo) const

// swimming flag only included in check because of 1.14
// vanilla clients do not have a descend/ascend flag
if (!GetLastMovementInfo().HasMovementFlag(MOVEFLAG_JUMPING | MOVEFLAG_FALLINGFAR | MOVEFLAG_SWIMMING) &&
!movementInfo.HasMovementFlag(MOVEFLAG_JUMPING | MOVEFLAG_FALLINGFAR | MOVEFLAG_SWIMMING))
if (!GetLastMovementInfo().HasMovementFlag(MOVEFLAG_SWIMMING) &&
!movementInfo.HasMovementFlag(MOVEFLAG_SWIMMING))
{
float const distanceZ = movementInfo.HasMovementFlag(MOVEFLAG_ONTRANSPORT) ?
std::abs(GetLastMovementInfo().t_pos.z - movementInfo.t_pos.z) :
Expand Down
2 changes: 1 addition & 1 deletion src/game/Movement/PointMovementGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void ChargeMovementGenerator<T>::Initialize(T& unit)
return;

unit.AddUnitState(UNIT_STAT_ROAMING | UNIT_STAT_ROAMING_MOVE);
unit.m_movementInfo.moveFlags = unit.m_movementInfo.moveFlags & ~MOVEFLAG_MASK_MOVING_OR_TURN;
unit.m_movementInfo.RemoveMovementFlag(MOVEFLAG_MASK_MOVING_OR_TURN);
unit.m_movementInfo.ctime = 0;

Movement::MoveSplineInit init(unit, "ChargeMovementGenerator<T>::Initialize");
Expand Down
1 change: 1 addition & 0 deletions src/game/Movement/spline/MoveSplineInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ int32 MoveSplineInit::Launch()
if (unit.IsPlayer() || unit.GetPossessorGuid().IsPlayer())
unit.SetSplineDonePending(true);

unit.m_movementInfo.ctime = 0;
unit.m_movementInfo.SetMovementFlags((MovementFlags)moveFlags);
move_spline.SetMovementOrigin(movementType);
move_spline.Initialize(args);
Expand Down
4 changes: 2 additions & 2 deletions src/game/Objects/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
DuelComplete(DUEL_FLED);

// reset movement flags at teleport, because player will continue move with these flags after teleport
m_movementInfo.ctime = 0;
m_movementInfo.RemoveMovementFlag(MOVEFLAG_MASK_MOVING_OR_TURN);
if (!(options & TELE_TO_NOT_LEAVE_TRANSPORT) || !m_transport)
m_movementInfo.RemoveMovementFlag(MOVEFLAG_ONTRANSPORT);
Expand Down Expand Up @@ -2366,7 +2367,6 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
m_teleportRecover = wps;
wps();
}
m_movementInfo.moveFlags &= ~MOVEFLAG_MASK_MOVING_OR_TURN; // For extrapolation
}
else
{
Expand Down Expand Up @@ -4994,7 +4994,7 @@ void Player::SetFly(bool enable)
pTransport->RemovePassenger(this);
StopMoving(true);
}

m_movementInfo.moveFlags = (MOVEFLAG_LEVITATING | MOVEFLAG_SWIMMING | MOVEFLAG_CAN_FLY | MOVEFLAG_FLYING);
AddUnitState(UNIT_STAT_FLYING_ALLOWED);
}
Expand Down
5 changes: 4 additions & 1 deletion src/game/Objects/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9057,7 +9057,8 @@ void Unit::ModConfuseSpell(bool apply, ObjectGuid casterGuid, uint32 spellId, Mo
else
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);

m_movementInfo.moveFlags &= ~MOVEFLAG_MASK_MOVING_OR_TURN;
m_movementInfo.ctime = 0;
m_movementInfo.RemoveMovementFlag(MOVEFLAG_MASK_MOVING_OR_TURN);

if (apply)
{
Expand Down Expand Up @@ -9139,6 +9140,7 @@ void Unit::SetFeignDeath(bool apply, ObjectGuid casterGuid, bool success)
{
if (apply)
{
m_movementInfo.ctime = 0;
m_movementInfo.RemoveMovementFlag(MOVEFLAG_MASK_MOVING_OR_TURN);
if (!IsPlayer())
StopMoving();
Expand Down Expand Up @@ -10622,6 +10624,7 @@ void Unit::DisableSpline()
if (Player* me = ToPlayer())
me->SetFallInformation(0, me->GetPositionZ());
m_movementInfo.RemoveMovementFlag(MOVEFLAG_SPLINE_ENABLED | MOVEFLAG_FORWARD);
m_movementInfo.ctime = 0;
movespline->_Interrupt();
}

Expand Down

0 comments on commit c0d5742

Please sign in to comment.