From 80d9845607058a85c5250aebca1280324b811285 Mon Sep 17 00:00:00 2001 From: navewindre Date: Wed, 5 Sep 2018 23:19:33 +0200 Subject: whole bunch of shit --- internal_rewrite/c_base_player.cpp | 173 ++++++++++++++++++++----------------- 1 file changed, 95 insertions(+), 78 deletions(-) (limited to 'internal_rewrite/c_base_player.cpp') diff --git a/internal_rewrite/c_base_player.cpp b/internal_rewrite/c_base_player.cpp index a96a4b4..0e03518 100644 --- a/internal_rewrite/c_base_player.cpp +++ b/internal_rewrite/c_base_player.cpp @@ -388,6 +388,9 @@ bool c_base_player::can_attack( bool ignore_rapid ) { auto weapon = get_weapon( ); if( !weapon ) return false; + if( weapon->is_sniper( ) && g_cheat.m_lagmgr.has_fired( ) ) + return false; + float time = g_ctx.pred_time( ); float next_attack = m_flNextAttack( ); @@ -649,36 +652,36 @@ void c_base_player::compute_move_cycle( bool reset, bool moving ) { void c_base_player::calc_anim_velocity( bool reset ) { int idx = ce( )->GetIndex( ); - auto accelerate = [ & ]( vec3_t velocity, vec3_t direction, float speed, float accel ) { - float addspeed, accelspeed, currentspeed; - - velocity.z = 0.f; - currentspeed = velocity.dot( direction ); - - addspeed = speed - currentspeed; - - if( addspeed <= 0.f ) { - return velocity; - } - - //guess how many fucks i give, this works - accelspeed = std::min( accel * 10.f * TICK_INTERVAL( ) * std::max( speed, 250.f ), currentspeed ); - - for( size_t i{ }; i < 3; ++i ) { - velocity[ i ] += accelspeed * direction[ i ]; - } - - return velocity; - }; - - auto friction = [ & ]( vec3_t velocity ) { - static auto sv_friction = g_csgo.m_cvar( )->FindVar( xors( "sv_friction" ) ); - static auto sv_stopspeed = g_csgo.m_cvar( )->FindVar( xors( "sv_stopspeed" ) ); - - float speed = velocity.length2d( ); - if( speed < 0.1f ) - return vec3_t{ }; - + auto accelerate = [ & ]( vec3_t velocity, vec3_t direction, float speed, float accel ) { + float addspeed, accelspeed, currentspeed; + + velocity.z = 0.f; + currentspeed = velocity.dot( direction ); + + addspeed = speed - currentspeed; + + if( addspeed <= 0.f ) { + return velocity; + } + + //guess how many fucks i give, this works + accelspeed = std::min( accel * 10.f * TICK_INTERVAL( ) * std::max( speed, 250.f ), currentspeed ); + + for( size_t i{ }; i < 3; ++i ) { + velocity[ i ] += accelspeed * direction[ i ]; + } + + return velocity; + }; + + auto friction = [ & ]( vec3_t velocity ) { + static auto sv_friction = g_csgo.m_cvar( )->FindVar( xors( "sv_friction" ) ); + static auto sv_stopspeed = g_csgo.m_cvar( )->FindVar( xors( "sv_stopspeed" ) ); + + float speed = velocity.length2d( ); + if( speed < 0.1f ) + return vec3_t{ }; + float friction = sv_friction->get_float( ); float control = ( speed < sv_stopspeed->get_float( ) ) ? sv_stopspeed->get_float( ) : speed; float drop = control * friction * TICK_INTERVAL( ); @@ -690,9 +693,9 @@ void c_base_player::calc_anim_velocity( bool reset ) { if( newspeed != speed ) { newspeed /= speed; velocity *= newspeed; - } - - return velocity; + } + + return velocity; }; if( reset ) { @@ -713,33 +716,46 @@ void c_base_player::calc_anim_velocity( bool reset ) { vec3_t origin_delta = origin - sm_animdata[ idx ].m_last_origin; vec3_t velocity = origin_delta / delta; - vec3_t last_velocity = sm_animdata[ idx ].m_last_velocity; - - vec3_t anim_vel; - - if( on_ground ) { - vec3_t ang = math::vector_angles( vec3_t( ), velocity ); - - float move_yaw = math::vector_angles( velocity ).y; - float move_delta = math::vector_angles( last_velocity ).y; - move_delta -= move_yaw; - move_delta = std::remainderf( move_delta, 360.f ); - - vec3_t move_dir = math::angle_vectors( vec3_t( 0.f, move_delta, 0.f ) ) * 450.f; - - vec3_t forward, right, up; - math::angle_vectors( ang, &forward, &right, &up ); - - vec3_t wishdir; - for( size_t i{ }; i < 2; ++i ) - wishdir[ i ] = forward[ i ] * move_dir.x + right[ i ] * move_dir.y; - - anim_vel = friction( last_velocity ); - if( anim_vel.length2d( ) < 15.f ) - anim_vel = vec3_t( ); - - if( anim_vel.length2d( ) >= 0.1f && velocity.length2d( ) > last_velocity.length2d( ) ) { - anim_vel = accelerate( anim_vel, wishdir, 250.f, sv_accelerate->get_float( ) ); + vec3_t last_velocity = sm_animdata[ idx ].m_last_velocity; + + vec3_t anim_vel; + + if( on_ground ) { + vec3_t ang = math::vector_angles( vec3_t( ), velocity ); + + float move_yaw = math::vector_angles( velocity ).y; + float move_delta = math::vector_angles( last_velocity ).y; + move_delta -= move_yaw; + move_delta = std::remainderf( move_delta, 360.f ); + + vec3_t move_dir = math::angle_vectors( vec3_t( 0.f, move_delta, 0.f ) ) * 450.f; + + vec3_t forward, right, up; + math::angle_vectors( ang, &forward, &right, &up ); + + vec3_t wishdir; + for( size_t i{ }; i < 2; ++i ) + wishdir[ i ] = forward[ i ] * move_dir.x + right[ i ] * move_dir.y; + + anim_vel = friction( last_velocity ); + if( anim_vel.length2d( ) < 1.f ) + anim_vel = vec3_t( ); + + int ticks = ( int )( 0.5f + TICK_INTERVAL( ) / delta ); + vec3_t est_tick_vel = math::lerp( last_velocity, velocity, .5f ); + for( int i{ }; i < ticks; i++ ) { + if( est_tick_vel.length2d( ) < 1.f ) + break; + + est_tick_vel = friction( est_tick_vel ); + } + + //assume fakewalk + if( est_tick_vel.length2d( ) < 5.f ) + anim_vel = vec3_t( ); + + else if( anim_vel.length2d( ) >= 0.1f && velocity.length2d( ) > last_velocity.length2d( ) ) { + anim_vel = accelerate( anim_vel, wishdir, 250.f, sv_accelerate->get_float( ) ); } } else { @@ -883,8 +899,9 @@ void c_base_player::fix_animations( bool reset, bool resolver_change ) { m_AnimOverlay( ).GetElements( )[ 6 ].m_flPlaybackRate, TICK_INTERVAL( ) / ( m_flSimulationTime( ) - m_flOldSimulationTime( ) ) ); - m_AnimOverlay( ).GetElements( )[ 6 ].m_flCycle = prev_cycle + lerp_rate; - + if( !reset ) { + m_AnimOverlay( ).GetElements( )[ 6 ].m_flCycle = prev_cycle + lerp_rate; + } get_animdata( ).m_prev_flags = flags; memcpy( @@ -1000,26 +1017,26 @@ void c_base_player::get_name_safe( char* buf ) { } } -void c_base_player::set_local_view_angles( vec3_t *angle ) { - using fn = void( __thiscall * )( void *, vec3_t * ); - util::get_vfunc< fn >( this, 363 )( this, angle ); -} - -bool c_base_player::run_physics_think( int unk01 ) { +void c_base_player::set_local_view_angles( vec3_t *angle ) { + using fn = void( __thiscall * )( void *, vec3_t * ); + util::get_vfunc< fn >( this, 363 )( this, angle ); +} + +bool c_base_player::run_physics_think( int unk01 ) { static auto impl = reinterpret_cast< bool( __thiscall * )( void *, int ) >( pattern::first_code_match( g_csgo.m_chl.dll( ), xors( "55 8B EC 83 EC 10 53 56 57 8B F9 8B 87 ? ? ? ? C1 E8 16" ) ) ); - return impl( this, unk01 ); -} - -void c_base_player::pre_think( ) { - using fn = void( __thiscall * )( void * ); - util::get_vfunc< fn >( this, 309 )( this ); -} - -void c_base_player::think( ) { - using fn = void( __thiscall * )( void * ); + return impl( this, unk01 ); +} + +void c_base_player::pre_think( ) { + using fn = void( __thiscall * )( void * ); + util::get_vfunc< fn >( this, 309 )( this ); +} + +void c_base_player::think( ) { + using fn = void( __thiscall * )( void * ); util::get_vfunc< fn >( this, 137 )( this ); } -- cgit v1.2.3