-
Автор темы
- #1
Код:
void aimbot_helpers::slide_stop( CUserCmd* cmd ) {
const auto weapon = g_cl.m_weapon;
if ( !weapon )
return;
cmd->m_side_move = prediction::unpred_move.y;
cmd->m_forward_move = prediction::unpred_move.x;
const auto is_revolver = weapon->get_weapon_id( ) == REVOLVER;
auto local_player = g_cl.m_local;
// prevent move layer from reaching highest weight...
if ( local_player->get_flags( ) & FL_ONGROUND && !( cmd->m_buttons & IN_JUMP ) && vars::aa.fake->get<bool>( ) && vars::aa.enabled->get<bool>( )
&& cmd->m_command_number > 1 && prediction::get_pred_info( cmd->m_command_number - 1 ).m_flags & FL_ONGROUND ) {
const auto jitter = fabs( sin( fmodf( interfaces::globals( )->m_curtime, .4f ) / .2f * math::pi ) );
const auto amnt = local_player->m_vecVelocity( ).length_2d( ) / 25.f;
stop_to_speed( std::fmax( ( 180.f ) / 3.f - 0.1f - amnt * jitter, 0.f ), cmd );
} else
stop_to_speed( ( 180.f ) / 3.f - 0.1f, cmd );
}
inline void check_parameters( CMoveData* mv, Player* player ) {
const auto speed_squared = ( mv->m_flForwardMove * mv->m_flForwardMove ) +
( mv->m_flSideMove * mv->m_flSideMove ) +
( mv->m_flUpMove * mv->m_flUpMove );
// Slow down by the speed factor
auto speed_factor = 1.0f;
//if (player->get_surface_props())
// speed_factor = player->get_surface_props()->game.maxspeedfactor;
const auto weapon = player->GetActiveWeapon( );
mv->m_flMaxSpeed = weapon ? weapon->GetWpnData( )->m_max_player_speed : mv->m_flClientMaxSpeed;
// check this out
mv->m_flMaxSpeed *= speed_factor;
// stamina slowing factor
if ( player->get_stamina( ) > 0 ) {
auto speed_scale = std::clamp( 1.0f - player->get_stamina( ) / 100.f, 0.f, 1.f );
speed_scale *= speed_scale; // square the scale factor so that it correlates more closely with the jump penalty (i.e. a 50% stamina jumps .25 * normal height)
mv->m_flMaxSpeed *= speed_scale;
}
// Same thing but only do the sqrt if we have to.
if ( ( speed_squared != 0.0 ) && ( speed_squared > mv->m_flMaxSpeed * mv->m_flMaxSpeed ) ) {
const auto ratio = mv->m_flMaxSpeed / sqrt( speed_squared );
mv->m_flForwardMove *= ratio;
mv->m_flSideMove *= ratio;
mv->m_flUpMove *= ratio;
}
}
inline void air_accelerate( vec3_t const& wishdir, float wishspeed, CMoveData* mv, float friction ) {
const auto wishspd = std::min( wishspeed, 30.f );
auto const currentspeed = mv->m_vecVelocity.Dot( wishdir );
auto const addspeed = wishspd - currentspeed;
if ( addspeed <= 0 )
return;
//var(sv_airaccelerate);
auto sv_airaccelerate = g_csgo.sv_airaccelerate;
auto accelspeed = sv_airaccelerate->GetFloat( ) * wishspeed * g_csgo.m_globals->m_interval * friction;
if ( accelspeed > addspeed )
accelspeed = addspeed;
mv->m_vecVelocity += wishdir * accelspeed;
}
__forceinline float VectorNormalize( vec3_t& vec ) {
const auto sqrlen = vec.length_sqr( ) + 1.0e-10f;
float invlen;
const auto xx = _mm_load_ss( &sqrlen );
auto xr = _mm_rsqrt_ss( xx );
auto xt = _mm_mul_ss( xr, xr );
xt = _mm_mul_ss( xt, xx );
xt = _mm_sub_ss( _mm_set_ss( 3.f ), xt );
xt = _mm_mul_ss( xt, _mm_set_ss( 0.5f ) );
xr = _mm_mul_ss( xr, xt );
_mm_store_ss( &invlen, xr );
vec.x *= invlen;
vec.y *= invlen;
vec.z *= invlen;
return sqrlen * invlen;
}
inline void air_move( CMoveData* mv, Player* ent ) {
vec3_t forward, right, up;
math::AngleVectors( mv->m_vecViewAngles, &forward, &right, &up ); // Determine movement angles
// Copy movement amounts
auto const fmove = mv->m_flForwardMove;
auto const smove = mv->m_flSideMove;
forward.z = 0;
right.z = 0;
forward.NormalizeInPlace( );
right.NormalizeInPlace( );
vec3_t wishvel( forward.x * fmove + right.x * smove, forward.y * fmove + right.y * smove, 0.f );
auto wishdir = wishvel;
auto wishspeed = VectorNormalize( wishdir );
// clamp to server defined max speed
if ( wishspeed != 0 && ( wishspeed > mv->m_flMaxSpeed ) ) {
wishvel = wishvel * ( mv->m_flMaxSpeed / wishspeed );
wishspeed = mv->m_flMaxSpeed;
}
air_accelerate( wishdir, wishspeed, mv, ent->m_surfaceFriction( ) );
}
void aimbot_helpers::stop_to_speed( float speed, CUserCmd* cmd ) {
auto local_player = g_cl.m_local;
if ( ( speed == 0.f || prediction::unpred_move.length( ) == 0.f ) && prediction::get_pred_info( cmd->m_command_number - 1 ).velocity.length( ) < 1.1f ) {
// micromove
if ( local_player->get_flags( ) & FL_ONGROUND && !( cmd->m_buttons & IN_JUMP ) && vars::aa.fake->get<bool>( ) && vars::aa.enabled->get<bool>( ) && cmd->m_command_number > 1 && prediction::get_pred_info( cmd->m_command_number - 1 ).m_flags & FL_ONGROUND ) {
auto forwardmove = interfaces::client_state( )->m_choked_commands % 2 ? 1.01f : -1.01f;
forwardmove /= local_player->get_duck_amt( ) * .34f + 1.f - local_player->get_duck_amt( );
cmd->m_forward_move = forwardmove;
cmd->m_side_move = 0.f;
}
return;
}
prediction::run_prediction( cmd->m_command_number - 1 );
CMoveData data{};
g_csgo.m_prediction->SetupMove( local_player, cmd, g_csgo.m_move_helper, &data );
stop_to_speed( speed, &data );
cmd->m_forward_move = data.m_flForwardMove;
cmd->m_side_move = data.m_flSideMove;
const auto forwardmove = cmd->m_command_number % 2 ? 1.01f : -1.01f;
walk_move( &data, local_player );
if ( vars::aa.fake->get<bool>( ) && local_player->m_vecVelocity( ).length( ) <= 1.10f && data.m_vecVelocity.length( ) <= 1.10f && local_player->get_flags( ) & FL_ONGROUND
&& vars::aa.enabled->get<bool>( ) ) {
cmd->m_forward_move = forwardmove;
cmd->m_side_move = 0.f;
}
const auto factor = local_player->get_duck_amt( ) * .34f + 1.f - local_player->get_duck_amt( );
cmd->m_forward_move /= factor;
cmd->m_side_move /= factor;
prediction::run_prediction( cmd->m_command_number );
}
inline void friction( CMoveData* mv, C_CSPlayer* player ) {
// Calculate speed
const auto speed = mv->m_vecVelocity.length( );
// If too slow, return
if ( speed < 0.1f )
return;
auto drop = 0.f;
// apply ground friction
if ( player->GetGroundEntity( ) != 0 ) // On an entity that is the ground
{
//var( sv_friction );
static auto sv_friction = g_csgo.m_cvar->FindVar( HASH( "sv_friction" ) );
const auto friction = sv_friction->GetFloat( ) * player->m_surfaceFriction( );
// Bleed off some speed, but if we have less than the bleed
// threshold, bleed the threshold amount.
//var( sv_stopspeed );
static auto sv_stopspeed = g_csgo.m_cvar->FindVar( HASH( "sv_stopspeed" ) );
const auto control = ( speed < sv_stopspeed->GetFloat( ) ) ? sv_stopspeed->GetFloat( ) : speed;
// Add the amount to the drop amount.
drop += control * friction * interfaces::globals( )->m_interval;
}
// scale the velocity
auto newspeed = speed - drop;
if ( newspeed < 0 )
newspeed = 0;
if ( newspeed != speed ) {
// Determine proportion of old speed we are using.
newspeed /= speed;
// Adjust velocity according to proportion.
mv->m_vecVelocity *= newspeed;
}
mv->m_outWishVel -= mv->m_vecVelocity * ( 1.f - newspeed );
}
void accelerate( const Vector& wishdir, float wishspeed, float accel, CMoveData* mv, C_CSPlayer* ent ) {
auto stored_accel = accel;
auto currentspeed = mv->m_vecVelocity.Dot( wishdir );
const float addspeed = wishspeed - currentspeed;
if ( addspeed <= 0 )
return;
if ( currentspeed < 0 )
currentspeed = 0;
const auto is_ducking = mv->m_nButtons & IN_DUCK || ent->get_ducking( ) || ent->get_flags( ) & FL_DUCKING;
const auto is_walking = ( mv->m_nButtons & IN_SPEED ) != 0 && !is_ducking;
constexpr auto max_speed = 250.0f;
auto acceleration_scale = std::max( max_speed, wishspeed );
auto goal_speed = acceleration_scale;
auto is_slow_sniper_scoped = false;
//var( sv_accelerate_use_weapon_speed );
static auto sv_accelerate_use_weapon_speed = g_csgo.m_cvar->FindVar( HASH( "sv_accelerate_use_weapon_speed" ) );
const auto wpn = ent->GetActiveWeapon( );
if ( sv_accelerate_use_weapon_speed->get_bool( ) && wpn ) {
is_slow_sniper_scoped = ( wpn->get_zoom_level( ) > 0 && wpn->get_wpn_data( )->m_zoom_levels > 1 && ( 250.f * 0.52f ) < 110.0 );
goal_speed *= std::min( 1.0f, ( 250.f / max_speed ) );
if ( ( !is_ducking && !is_walking ) || ( ( is_walking || is_ducking ) && is_slow_sniper_scoped ) )
acceleration_scale *= std::min( 1.0f, ( 250.f / max_speed ) );
}
if ( is_ducking ) {
if ( !is_slow_sniper_scoped )
acceleration_scale *= 0.34f;
goal_speed *= 0.34f;
}
if ( is_walking ) {
if ( !is_slow_sniper_scoped )
acceleration_scale *= 0.52f;
goal_speed *= 0.52f;
}
if ( is_walking && currentspeed > ( goal_speed - 5 ) )
stored_accel *= std::clamp( 1.0f - ( std::max( 0.0f, currentspeed - ( goal_speed - 5 ) ) / std::max( 0.0f, goal_speed - ( goal_speed - 5 ) ) ), 0.0f, 1.0f );
auto accelspeed = stored_accel * interfaces::globals( )->m_interval * acceleration_scale * ent->m_surfaceFriction( );
if ( accelspeed > addspeed )
accelspeed = addspeed;
mv->m_vecVelocity += ( wishdir * accelspeed );
}
void walk_move( CMoveData* mv, C_CSPlayer* ent ) {
Vector forward, right, up;
math::AngleVectors( mv->m_vecViewAngles, &forward, &right, &up ); // Determine movement angles
// Copy movement amounts
auto const fmove = mv->m_flForwardMove;
auto const smove = mv->m_flSideMove;
forward.z = right.z = 0.f;
VectorNormalize( forward );
VectorNormalize( right );
Vector wishvel( forward.x * fmove + right.x * smove, forward.y * fmove + right.y * smove, 0.f );
auto wishdir = wishvel;
auto wishspeed = VectorNormalize( wishdir );
// clamp to server defined max speed
if ( wishspeed != 0 && ( wishspeed > mv->m_flMaxSpeed ) ) {
wishvel = wishvel * ( mv->m_flMaxSpeed / wishspeed );
wishspeed = mv->m_flMaxSpeed;
}
//var( sv_accelerate );
static auto sv_accelerate = g_csgo.m_cvar->FindVar( HASH( "sv_accelerate" ) );
// Set pmove velocity
mv->m_vecVelocity[ 2 ] = 0;
accelerate( wishdir, wishspeed, sv_accelerate->GetFloat( ), mv, ent );
mv->m_vecVelocity[ 2 ] = 0;
// Additional max speed clamp to keep us from going faster than allowed while turning
if ( mv->m_vecVelocity.length_sqr( ) > mv->m_flMaxSpeed * mv->m_flMaxSpeed ) {
float fRatio = mv->m_flMaxSpeed / mv->m_vecVelocity.length( );
mv->m_vecVelocity *= fRatio;
}
// If we made it all the way, then copy trace end as new player position.
mv->m_outWishVel += wishdir * wishspeed;
}
void aimbot_helpers::stop_to_speed( float speed, CMoveData* mv, Player* player ) {
friction( mv, player );
check_parameters( mv, player );
auto mv_cp = *mv;
walk_move( &mv_cp, player );
if ( mv_cp.m_vecVelocity.length_2d( ) <= speed )
return;
if ( mv->m_vecVelocity.length_2d( ) > speed ) {
ang_t ang{};
math::VectorAngles( mv->m_vecVelocity * -1.f, ang );
ang.y = math::normalize_float( mv->m_vecViewAngles.y - ang.y );
Vector forward{};
math::AngleVectors( ang, &forward );
forward = forward.To2D( ).normalized( );
const auto target_move_len = std::min( mv->m_vecVelocity.length_2d( ) - speed, mv->m_flMaxSpeed );
mv->m_flForwardMove = forward.x * target_move_len;
mv->m_flSideMove = forward.y * target_move_len;
mv->m_flUpMove = 0.f;
return;
}
Vector forward, right;
math::AngleVectors( mv->m_vecViewAngles, &forward, &right );
forward.z = right.z = 0.f;
VectorNormalize( forward );
VectorNormalize( right );
Vector wishdir( forward.x * mv->m_flForwardMove + right.x * mv->m_flSideMove, forward.y * mv->m_flForwardMove + right.y * mv->m_flSideMove, 0.f );
VectorNormalize( wishdir );
const auto currentspeed = mv->m_vecVelocity.Dot( wishdir );
const auto target_accelspeed = speed - mv->m_vecVelocity.length_2d( );
const auto target_move_len = std::min( currentspeed + target_accelspeed, mv->m_flMaxSpeed );
const auto speed_squared = ( mv->m_flForwardMove * mv->m_flForwardMove ) + ( mv->m_flSideMove * mv->m_flSideMove ) + ( mv->m_flUpMove * mv->m_flUpMove );
const auto ratio = target_move_len / sqrt( speed_squared );
if ( ratio < 1.f ) {
mv->m_flForwardMove *= ratio;
mv->m_flSideMove *= ratio;
mv->m_flUpMove *= ratio;
}
}