From 39f70b7b843d926eeb534ac1de25cc38b13c493d Mon Sep 17 00:00:00 2001 From: navewindre Date: Mon, 3 Sep 2018 23:48:51 +0200 Subject: ah --- internal_rewrite/c_base_player.cpp | 112 ++++++++++++++++++++++++++++++----- internal_rewrite/context.cpp | 12 ++-- internal_rewrite/extra.cpp | 4 +- internal_rewrite/hooks.cpp | 2 + internal_rewrite/hooks.hpp | 3 + internal_rewrite/lag_mgr.cpp | 13 ++++ internal_rewrite/lag_mgr.hpp | 13 +--- internal_rewrite/proxies.cpp | 37 ++++++++++++ internal_rewrite/ragebot_lagcomp.cpp | 2 +- internal_rewrite/simple_settings.hpp | 32 +++++++--- internal_rewrite/simulate.cpp | 2 + internal_rewrite/visual_player.cpp | 6 ++ 12 files changed, 196 insertions(+), 42 deletions(-) diff --git a/internal_rewrite/c_base_player.cpp b/internal_rewrite/c_base_player.cpp index 1d31756..24f75cd 100644 --- a/internal_rewrite/c_base_player.cpp +++ b/internal_rewrite/c_base_player.cpp @@ -649,6 +649,52 @@ 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{ }; + + float friction = sv_friction->get_float( ); + float control = ( speed < sv_stopspeed->get_float( ) ) ? sv_stopspeed->get_float( ) : speed; + float drop = control * friction * TICK_INTERVAL( ); + + float newspeed = speed - drop; + if( newspeed < 0.f ) + newspeed = 0.f; + + if( newspeed != speed ) { + newspeed /= speed; + velocity *= newspeed; + } + + return velocity; + }; + if( reset ) { vec3_t velocity = m_vecVelocity( ); sm_animdata[ idx ].m_last_origin = m_vecOrigin( ); @@ -656,27 +702,55 @@ void c_base_player::calc_anim_velocity( bool reset ) { sm_animdata[ idx ].m_anim_velocity = velocity; } else { + static auto sv_accelerate = g_csgo.m_cvar( )->FindVar( xors( "sv_accelerate" ) ); + float delta = m_flSimulationTime( ) - m_flOldSimulationTime( ); delta = std::max( delta, TICK_INTERVAL( ) ); - vec3_t origin = m_vecOrigin( ); + bool on_ground = m_fFlags( ) & FL_ONGROUND; + vec3_t origin = m_vecOrigin( ); 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_velocity = math::lerp( - last_velocity, - velocity, - TICK_INTERVAL( ) / delta ); - - if( anim_velocity.length2d( ) < 3.f ) { - anim_velocity.x = anim_velocity.y = 0.f; - velocity = anim_velocity; + 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( ) ); + } + } + else { + anim_vel = math::lerp( + last_velocity, + velocity, + TICK_INTERVAL( ) / delta + ); } - sm_animdata[ idx ].m_anim_velocity = anim_velocity; + sm_animdata[ idx ].m_anim_velocity = anim_vel; sm_animdata[ idx ].m_last_velocity = velocity; sm_animdata[ idx ].m_last_origin = origin; } @@ -798,7 +872,12 @@ void c_base_player::fix_animations( bool reset, bool resolver_change ) { sm_animdata[ idx ].m_last_duck = m_flDuckAmount( ); + float prev_cycle = m_AnimOverlay( ).GetElements( )[ 6 ].m_flPrevCycle; + float prev_rate = m_AnimOverlay( ).GetElements( )[ 6 ].m_flPlaybackRate; get_animstate( )->update( eye_angles.y, eye_angles.x ); + m_AnimOverlay( ).GetElements( )[ 6 ].m_flPrevCycle = m_AnimOverlay( ).GetElements( )[ 6 ].m_flCycle; + m_AnimOverlay( ).GetElements( )[ 6 ].m_flCycle = prev_cycle + prev_rate; + get_animdata( ).m_prev_flags = flags; memcpy( @@ -830,14 +909,17 @@ void c_base_player::fix_animations( bool reset, bool resolver_change ) { bool moving = sm_animdata[ idx ].m_anim_velocity.length( ) > 0.1f; //compute_move_cycle( reset, moving ); + - float backup_weight = m_AnimOverlay( ).GetElements( )[ 6 ].m_flWeight; if( is_fakewalking( ) && !reset ) { - sm_animdata[ idx ].m_last_velocity = vec3_t( ); - sm_animdata[ idx ].m_anim_velocity = vec3_t( ); + //sm_animdata[ idx ].m_last_velocity = vec3_t( ); + //sm_animdata[ idx ].m_anim_velocity = vec3_t( ); } + if( !moving ) + m_AnimOverlay( ).GetElements( )[ 6 ].m_flWeight = 0.f; + ce( )->GetRenderAngles( ).y = std::remainderf( ce( )->GetRenderAngles( ).y, 360.f ); m_flDuckAmount( ) = original_duck; diff --git a/internal_rewrite/context.cpp b/internal_rewrite/context.cpp index cf0f9ee..421bc06 100644 --- a/internal_rewrite/context.cpp +++ b/internal_rewrite/context.cpp @@ -22,6 +22,7 @@ void c_context::on_cmove_end( user_cmd_t* cmd ) { if( send ) { m_last_fakeangle = cmd->m_viewangles; + m_last_origin = m_local->m_vecOrigin( ); } else { @@ -53,8 +54,6 @@ void c_context::on_cmove_end( user_cmd_t* cmd ) { m_last_shot %= 128; m_shot_data[ m_last_shot ] = new_shot; - - //g_con->log( "incrementing shots( in attack )" ); m_has_incremented_shots = true; } @@ -62,9 +61,12 @@ void c_context::on_cmove_end( user_cmd_t* cmd ) { } } - weapon_info_t* wpn_info = m_local->get_weapon( )->get_wpn_info( ); - if( wpn_info && m_has_fired_this_frame ) - m_local->get_weapon( )->m_flNextPrimaryAttack( ) += wpn_info->cycle_time; + auto wep = m_local->get_weapon( ); + if( wep ) { + weapon_info_t* wpn_info = m_local->get_weapon( )->get_wpn_info( ); + if( wpn_info && m_has_fired_this_frame ) + m_local->get_weapon( )->m_flNextPrimaryAttack( ) += wpn_info->cycle_time; + } if( g_settings.misc.log_hits( ) ) { for( auto& it : m_shot_data ) { diff --git a/internal_rewrite/extra.cpp b/internal_rewrite/extra.cpp index 58fa03a..d67b0d7 100644 --- a/internal_rewrite/extra.cpp +++ b/internal_rewrite/extra.cpp @@ -242,7 +242,9 @@ namespace features void c_extra::no_flash( ) { static bool once = false; - if( !g_ctx.m_local || !g_ctx.m_local->is_valid( ) ) { + + + if( !g_ctx.run_frame( ) || !g_ctx.m_local->is_valid( ) ) { return; } diff --git a/internal_rewrite/hooks.cpp b/internal_rewrite/hooks.cpp index 3d21d2a..a02537a 100644 --- a/internal_rewrite/hooks.cpp +++ b/internal_rewrite/hooks.cpp @@ -5,6 +5,7 @@ hooks::c_netvar_proxy hooks::lby_proxy; hooks::c_netvar_proxy hooks::last_shot_proxy; +hooks::c_netvar_proxy hooks::simtime_proxy; bool hooks::commit( factory::c_csgo* instance ) { while ( !( instance->m_hwnd = FindWindowA( xors( "Valve001" ), 0 ) ) ) @@ -17,6 +18,7 @@ bool hooks::commit( factory::c_csgo* instance ) { lby_proxy.init( g_netvars.get_prop( fnv( "DT_CSPlayer" ), fnv( "m_flLowerBodyYawTarget" ) ), &lby_proxy_fn ); last_shot_proxy.init( g_netvars.get_prop( fnv( "DT_WeaponCSBaseGun" ), fnv( "m_fLastShotTime" ) ), &last_shot_proxy_fn ); + simtime_proxy.init( g_netvars.get_prop( fnv( "DT_BaseEntity" ), fnv( "m_flSimulationTime" ) ), &simtime_proxy_fn ); // god i'm thriving the d auto* d = &memory::detours; diff --git a/internal_rewrite/hooks.hpp b/internal_rewrite/hooks.hpp index 4e8a736..41e36ad 100644 --- a/internal_rewrite/hooks.hpp +++ b/internal_rewrite/hooks.hpp @@ -46,6 +46,8 @@ namespace hooks bool __fastcall fire_event_clientside( void* ecx_, void* edx, IGameEvent* event ); void __cdecl lby_proxy_fn( const CRecvProxyData* proxy_data_const, void* entity, void* output ); void __cdecl last_shot_proxy_fn( const CRecvProxyData* proxy_data_const, void* entity, void* output ); + void __cdecl simtime_proxy_fn( const CRecvProxyData* proxy_data_const, void* ent, void* output ); + int __fastcall send_datagram( INetChannel* channel, void* edx, void* datagram ); bool __fastcall is_paused( void* ecx_, void* edx_ ); bool __fastcall do_post_screen_space_effects( void* ecx_, void* edx_, CViewSetup* setup ); @@ -60,6 +62,7 @@ namespace hooks extern c_netvar_proxy lby_proxy; extern c_netvar_proxy last_shot_proxy; + extern c_netvar_proxy simtime_proxy; //do we wanna only run menu in d3d or visuals too? namespace d3d { diff --git a/internal_rewrite/lag_mgr.cpp b/internal_rewrite/lag_mgr.cpp index ed01568..3aff26d 100644 --- a/internal_rewrite/lag_mgr.cpp +++ b/internal_rewrite/lag_mgr.cpp @@ -148,4 +148,17 @@ namespace features last_rand = ( 1.f + math::random_number( -settings.fluctuate, settings.fluctuate( ) ) * 0.01f ); } } + + void c_lagmgr::on_cmove_end( ) { + if( !m_sendpacket ) return; + + if( *m_sendpacket ) { + ++m_sent_ticks; + m_held_ticks = 0; + } + else { + ++m_held_ticks; + m_sent_ticks = 0; + } + } } \ No newline at end of file diff --git a/internal_rewrite/lag_mgr.hpp b/internal_rewrite/lag_mgr.hpp index 21360dd..aa22c29 100644 --- a/internal_rewrite/lag_mgr.hpp +++ b/internal_rewrite/lag_mgr.hpp @@ -24,18 +24,7 @@ namespace features fakelag( ); } - void on_cmove_end( ) { - if( !m_sendpacket ) return; - - if( *m_sendpacket ) { - ++m_sent_ticks; - m_held_ticks = 0; - } - else { - ++m_held_ticks; - m_sent_ticks = 0; - } - } + void on_cmove_end( ); void set_state( bool state ) { *m_sendpacket = state; diff --git a/internal_rewrite/proxies.cpp b/internal_rewrite/proxies.cpp index 13466b4..d214751 100644 --- a/internal_rewrite/proxies.cpp +++ b/internal_rewrite/proxies.cpp @@ -100,4 +100,41 @@ void __cdecl hooks::last_shot_proxy_fn( const CRecvProxyData* proxy_data_const, } } } +} + +void __cdecl hooks::simtime_proxy_fn( const CRecvProxyData* proxy_data_const, void* entity, void* output ) { + auto old_fn = simtime_proxy.get_old_function( ); + + /*auto ent = ( c_base_player* )( entity ); + if( ent && ent->is_valid( ) && ent->has_valid_anim( ) && ( ent->m_iTeamNum( ) != g_ctx.m_local->m_iTeamNum( ) || g_settings.rage.friendlies( ) ) && ent != g_ctx.m_local ) { + auto time = proxy_data_const->m_Value.m_Int; + auto id = proxy_data_const->m_ObjectID; + auto ptr = proxy_data_const->m_pRecvProp; + auto element = proxy_data_const->m_iElement; + + auto name = proxy_data_const->m_pRecvProp->GetName( ); + + //static float last_time[ 65 ]{ }; + + /*printf( "PROXY[ %d ]:\n" + "\tname: %s\n" + //"\tdelta: %f\n" + "\tm_Int: %d\n" + "\ttime: %f\n" + "\tid: %d\n" + "\tptr: %08x\n" + "\telement: %d\n", + ent->ce( )->GetIndex( ), + name, + //time - last_time[ ent->ce( )->GetIndex( ) ], + time, + ent->m_flSimulationTime( ), + id, + ptr, + element ); + + //last_time[ ent->ce( )->GetIndex( ) ] = ent->m_flSimulationTime( ); + }*/ + + old_fn( proxy_data_const, entity, output ); } \ No newline at end of file diff --git a/internal_rewrite/ragebot_lagcomp.cpp b/internal_rewrite/ragebot_lagcomp.cpp index f19828f..7b65e38 100644 --- a/internal_rewrite/ragebot_lagcomp.cpp +++ b/internal_rewrite/ragebot_lagcomp.cpp @@ -478,8 +478,8 @@ namespace features m_data_normal[ i ].push_front( new_record ); } } - } + } ent->do_ent_interpolation( false ); m_last_simtime[ i ] = simtime; diff --git a/internal_rewrite/simple_settings.hpp b/internal_rewrite/simple_settings.hpp index 5d5636e..6371992 100644 --- a/internal_rewrite/simple_settings.hpp +++ b/internal_rewrite/simple_settings.hpp @@ -143,22 +143,38 @@ public: __declspec( noinline ) void load( const char* path, const char* file ) override { static char str[ MAX_PATH ]; + static char full_path[ MAX_PATH ]; + static bool taken = false; - GetModuleFileNameA( nullptr, str, MAX_PATH - 1 ); - PathRemoveFileSpecA( str ); - strcat_s< MAX_PATH >( str, "\\csgo\\cfg\\" ); - strcat_s< MAX_PATH >( str, file ); + if( !taken ) { + GetModuleFileNameA( nullptr, str, MAX_PATH - 1 ); + PathRemoveFileSpecA( str ); + strcat_s< MAX_PATH >( str, "\\csgo\\cfg\\" ); + + taken = true; + } + + memcpy( full_path, str, MAX_PATH ); + strcat_s< MAX_PATH >( full_path, file ); simple_load( path, std::to_string( name_ ).c_str( ), &value_, sizeof( value_ ), str ); } __declspec( noinline ) void save( const char* path, const char* file ) const override { static char str[ MAX_PATH ]; + static char full_path[ MAX_PATH ]; + static bool taken = false; + + if( !taken ) { + GetModuleFileNameA( nullptr, str, MAX_PATH - 1 ); + PathRemoveFileSpecA( str ); + strcat_s< MAX_PATH >( str, "\\csgo\\cfg\\" ); + + taken = true; + } - GetModuleFileNameA( nullptr, str, MAX_PATH - 1 ); - PathRemoveFileSpecA( str ); - strcat_s< MAX_PATH >( str, "\\csgo\\cfg\\" ); - strcat_s< MAX_PATH >( str, file ); + memcpy( full_path, str, MAX_PATH ); + strcat_s< MAX_PATH >( full_path, file ); simple_save( path, std::to_string( name_ ).c_str( ), &value_, sizeof( value_ ), str ); } diff --git a/internal_rewrite/simulate.cpp b/internal_rewrite/simulate.cpp index fed0840..6404a1c 100644 --- a/internal_rewrite/simulate.cpp +++ b/internal_rewrite/simulate.cpp @@ -10,6 +10,8 @@ void __fastcall hooks::simulate( void* ecx, void* edx ) { static auto ret_addr = pattern::first_code_match< void* >( g_csgo.m_engine.dll( ), "8B CE 6A FF 8B 06", -0x81 ); if( _ReturnAddress( ) == (void*)ret_addr ) { + g_ctx.run_frame( ); + g_ctx.m_stage = FRAME_RENDER_START; g_cheat.m_visuals.world_modulate( ); diff --git a/internal_rewrite/visual_player.cpp b/internal_rewrite/visual_player.cpp index a1089e7..1594c88 100644 --- a/internal_rewrite/visual_player.cpp +++ b/internal_rewrite/visual_player.cpp @@ -635,6 +635,12 @@ namespace features draw_string( x, y, ALIGN_RIGHT, false, clr_t( 255, 255, 255 ), "%d %f", i, ent->m_AnimOverlay( ).GetElements( )[ i ].m_flCycle ); } + + auto ent_origin = ent->m_vecOrigin( ); + auto ent_origin_vel = origin + ent->get_animdata( ).m_anim_velocity; + ent_origin_vel.z = ent_origin.z; + + draw_line( util::screen_transform( ent_origin ), util::screen_transform( ent_origin_vel ), esp_blue( ) ); } #endif } -- cgit v1.2.3