Начинающий
-
Автор темы
- #1
Код:
void c_resolver::instance(c_base_player* player, c_lag_record& lag_record, const c_lag_record previous_record)
{
if (!player || !player->is_alive())
return;
if (!player->get_anim_state())
return;
if (player->get_anim_state()->m_velocity.length_2d() > 1.2f || player->get_anim_state()->m_velocity_length_xy > 0.1f && fabsf(player->get_anim_state()->m_velocity_length_z) > 100.0f)
{
lag_record.m_is_moving = true;
lag_record.m_is_standing = false;
resolve_moves(player, lag_record);
detect_side_of_playback_rate(player, lag_record, previous_record);
}
else
{
lag_record.m_is_moving = false;
lag_record.m_is_standing = true;
resolve_stand(player, lag_record);
}
// Use a combination of techniques to determine the enemy's yaw
float yaw = player->goal_feet_yaw();
float velocity_yaw = atan2(player->get_anim_state()->m_velocity.y, player->get_anim_state()->m_velocity.x);
float delta = fabs(math::normalize_yaw(yaw - velocity_yaw));
if (delta < 35.f) // If the difference between the two yaws is small, use the velocity yaw
lag_record.m_server_abs_ang = velocity_yaw;
else // If the difference is large, use the goal feet yaw
lag_record.m_server_abs_ang = yaw;
// Use the previous record to detect desync
if (previous_record.m_server_abs_ang != lag_record.m_server_abs_ang)
{
if (previous_record.m_is_moving && !lag_record.m_is_moving)
{
// If the enemy was moving but is now standing, check if the yaw changed significantly
float delta = fabs(math::normalize_yaw(previous_record.m_server_abs_ang - lag_record.m_server_abs_ang));
if (delta > 35.f)
lag_record.m_is_desynced = true;
}
else if (lag_record.m_is_moving && lag_record.m_is_desynced)
{
// If the enemy is moving and was previously desynced, check if the yaw changed significantly
float delta = fabs(math::normalize_yaw(previous_record.m_server_abs_ang - lag_record.m_server_abs_ang));
if (delta < 35.f)
lag_record.m_is_moving = true;
else
lag_record.m_is_moving = false;
// If the enemy is moving, check the velocity to determine if they are running or walking
if (lag_record.m_is_moving) {
float speed = player->get_anim_state()->m_velocity.length_2d();
if (speed > 1.2f)
lag_record.m_is_running = true;
else
lag_record.m_is_running = false;
}
// If the enemy is not moving, check the previous record to see if they were moving
else if (!lag_record.m_is_moving && previous_record.m_is_moving) {
// If the enemy stopped moving and was previously running, assume they are standing still
if (previous_record.m_is_running)
lag_record.m_is_standing = true;
// If the enemy stopped moving and was previously walking, assume they are desynced
else
lag_record.m_is_desynced = true;
}
// If the enemy is not moving and was not previously moving, assume they are standing still
else
lag_record.m_is_standing = true;
// If the enemy is desynced, check if the yaw changed significantly
if (lag_record.m_is_desynced) {
float delta = fabs(math::normalize_yaw(previous_record.m_server_abs_ang - lag_record.m_server_abs_ang));
if (delta > 35.f)
lag_record.m_is_desynced = false;
}
// If the enemy is standing still, check if the yaw changed significantly
if (lag_record.m_is_standing) {
float delta = fabs(math::normalize_yaw(previous_record.m_server_abs_ang - lag_record.m_server_abs_ang));
if (delta > 35.f)
lag_record.m_is_standing = false;
}
// If the enemy is moving and not desynced, check if the yaw is consistent with the velocity
if (lag_record.m_is_moving && !lag_record.m_is_desynced) {
Vector velocity = player->get_anim_state()->m_velocity;
float speed = velocity.length_2d();
float yaw = math::normalize_yaw(velocity.yaw());
float delta = fabs(math::normalize_yaw(lag_record.m_server_abs_ang - yaw));
if (delta > 35.f || speed < 1.2f)
lag_record.m_is_desynced = true;
}
// If the enemy is running, check if the yaw is consistent with the velocity
if (lag_record.m_is_running) {
Vector velocity = player->get_anim_state()->m_velocity;
float yaw = math::normalize_yaw(velocity.yaw());
float delta = fabs(math::normalize_yaw(lag_record.m_server_abs_ang - yaw));
if (delta > 35.f) {
lag_record.m_server_abs_ang = yaw;
}
}
// If the enemy is standing and was previously desynced, check if the yaw changed significantly
if (lag_record.m_is_standing) {
float delta = fabs(math::normalize_yaw(previous_record.m_server_abs_ang - lag_record.m_server_abs_ang));
if (delta > 35.f) {
lag_record.m_server_abs_ang = previous_record.m_server_abs_ang;
}
}
// If the enemy is shooting, check if the yaw is consistent with the aim punch
if (player->is_shooting()) {
Vector aim_punch = player->get_aim_punch();
float yaw = math::normalize_yaw(aim_punch.yaw());
float delta = fabs(math::normalize_yaw(lag_record.m_server_abs_ang - yaw));
if (delta < 35.f) {
lag_record.m_server_abs_ang = yaw;
}
}
// If the enemy is moving and was previously desynced, check if the yaw changed significantly
float delta = fabs(math::normalize_yaw(previous_record.m_server_abs_ang - lag_record.m_server_abs_ang));
if (delta < 35.f)
lag_record.m_server_abs_ang = previous_record.m_server_abs_ang;
}