Начинающий
			
			
				
					
				
			
		Начинающий
		- Статус
 - Оффлайн
 
- Регистрация
 - 5 Авг 2023
 
- Сообщения
 - 67
 
- Реакции
 - 23
 
credits: llama/phillip/raxer and csgo source leak
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
				
			
			
				anims.cpp:
			
		
		
		#include "includes.h"
void anims::mini_update( Player* player ) {
    C_AnimationLayer backup_layers[ 13 ];
    player->GetAnimLayers( backup_layers );
    // backup globalvars
    float curtime = g_csgo.m_globals->m_curtime;
    float frame = g_csgo.m_globals->m_frame;
    float frametime = g_csgo.m_globals->m_frametime;
    // set frametime to ipt just like on the server during simulation
    g_csgo.m_globals->m_curtime   = player->m_flSimulationTime( );
    g_csgo.m_globals->m_frame     = g_csgo.m_cl->m_server_tick;
    g_csgo.m_globals->m_frametime = g_csgo.m_globals->m_interval;
    // remove abs velocity
    player->m_iEFlags( ) &= ~0x1000;
    player->SetAbsVelocity( player->m_vecVelocity( ) );
    // update animations
    g_hooks.m_UpdateClientSideAnimation( player );
    // restore layers to networked
    player->SetAnimLayers( backup_layers );
    // restore once we're done
    g_csgo.m_globals->m_frame      = frame;
    g_csgo.m_globals->m_curtime   = curtime;
    g_csgo.m_globals->m_frametime = frametime;
}
void anims::update( Player* player, LagRecord* record, LagRecord* previous ) {
    // get anim state
    CCSGOPlayerAnimState *state = player->m_PlayerAnimState( );
    // backup globalvars
    float curtime = g_csgo.m_globals->m_curtime;
    float frame = g_csgo.m_globals->m_frame;
    float frametime = g_csgo.m_globals->m_frametime;
    // backup stuff that we do not want to fuck with.
    AnimationBackup_t backup;
    backup.store( player );
    // set frametime to ipt just like on the server during simulation
    g_csgo.m_globals->m_curtime   = record->m_anim_time;
    g_csgo.m_globals->m_frame     = g_csgo.m_cl->m_server_tick;    // frame is server_tick on server simulation
    g_csgo.m_globals->m_frametime = g_csgo.m_globals->m_interval;
    // fuck origin interpolation
    player->SetAbsOrigin( player->m_vecOrigin( ) );
    // fix our animstate vars when animstate resets
    if( state->m_last_update_time == 0.f || !previous ) {
        state->m_on_ground              = !!( player->m_fFlags( ) & FL_ONGROUND );
        state->m_landing              = false;
        state->m_foot_yaw_last          = state->m_foot_yaw = player->m_flLowerBodyYawTarget( );
        state->m_eye_yaw              = player->m_flLowerBodyYawTarget( );
        state->m_eye_pitch              = record->m_eye_angles.x;
        state->m_primary_cycle          = record->m_layers[ 6 ].m_cycle;
        state->m_move_weight          = record->m_layers[ 6 ].m_weight;
        state->m_strafe_sequence      = record->m_layers[ 7 ].m_sequence;
        state->m_strafe_change_weight = record->m_layers[ 7 ].m_weight;
        state->m_strafe_change_cycle  = record->m_layers[ 7 ].m_cycle;
        state->m_acceleration_weight  = record->m_layers[ 12 ].m_weight;
        player->m_flOldSimulationTime( ) = state->m_last_update_time = record->m_sim_time - g_csgo.m_globals->m_interval;
        state->m_last_update_frame    = g_csgo.m_cl->m_server_tick - 1;
        state->m_duration_in_air      = 0.f;
       record->m_anim_velocity = player->m_vecVelocity( );
        if( state->m_on_ground ) {
            record->m_anim_velocity.z = 0.f;
            if( ( state->m_primary_cycle == 0.f || state->m_move_weight == 0.f ) )
                record->m_anim_velocity = vec3_t( );
        }
    }
    // or fix animstate netvars using networked values
    else if( previous ) {
        player->SetAnimLayers( previous->m_layers );
        player->SetPoseParameters( previous->m_poses );
        state->m_primary_cycle          = previous->m_layers[ 6 ].m_cycle;
        state->m_move_weight          = previous->m_layers[ 6 ].m_weight;
        state->m_strafe_sequence      = previous->m_layers[ 7 ].m_sequence;
        state->m_strafe_change_weight = previous->m_layers[ 7 ].m_weight;
        state->m_strafe_change_cycle  = previous->m_layers[ 7 ].m_cycle;
        state->m_acceleration_weight  = previous->m_layers[ 12 ].m_weight;
        // https://gitlab.com/KittenPopo/csgo-2018-source/-/blob/main/game/client/c_baseplayer.cpp#L1139
        // void C_BasePlayer::PostDataUpdate( DataUpdateType_t updateType )
        record->m_anim_velocity = ( record->m_origin - previous->m_origin ) * ( 1.f / game::TICKS_TO_TIME( record->m_lag ) );
        // fix gravity
        if( ( previous->m_flags & FL_ONGROUND )
            && ( record->m_flags & FL_ONGROUND ) ) {
            record->m_anim_velocity.z = 0.f;
            // fix fakewalk
            if( record->m_layers[ 6 ].m_playback_rate == 0.f )
                record->m_anim_velocity = vec3_t( );
        }
        // task for reader: add proper velocity recalculation
        // hint CCSGOPlayerAnimState::SetUpAliveLoop
    }
    // run our resolver
    if( !previous || ( record->m_lag != 1 || previous->m_lag != 1 ) )
        g_resolver.ResolveAngles( player, record );
    // update animations
    for( int i = 1; i <= record->m_lag; i++ ) {
        const float interp = std::clamp( static_cast< float >( i ) / static_cast< float >( record->m_lag ), 0.f, 1.f );
        // interpolate everything to have an approximative simulation
        if( previous && record->m_lag > 1 ) {
            g_csgo.m_globals->m_curtime = math::Lerp( interp, previous->m_sim_time, record->m_sim_time );
             player->m_vecVelocity( ) = math::Lerp( interp, previous->m_anim_velocity, record->m_anim_velocity );
             player->m_flDuckAmount( ) = math::Lerp( interp, previous->m_duck, record->m_duck );
             // task: fix land by calculating land time with layer 4 and 5
        }
        else
              player->m_vecVelocity( ) = record->m_anim_velocity;
        // remove abs velocity
        player->m_iEFlags( ) &= ~0x1000;
        player->SetAbsVelocity( player->m_vecVelocity( ) );
        // apply our angles
        player->m_angEyeAngles( ) = record->m_eye_angles;
        // update animations
        g_hooks.m_UpdateClientSideAnimation( player );
        // store our abs angles and pose parameters
        record->m_abs_ang = ang_t( 0.f, state->m_foot_yaw, 0.f );
        player->GetPoseParameters( record->m_poses );
    }
    // update player bounds
    player->UpdateCollisionBounds();
    record->m_maxs = player->m_vecMaxs( );
    record->m_mins = player->m_vecMins( );
    // restore our layers to networked and run our setupbones
    player->SetAnimLayers( record->m_layers );
    record->m_setup = player->SetupBones( record->m_bones, 128, BONE_USED_BY_ANYTHING, state->m_last_update_time );
    // restore our animation data
    backup.apply( player );
    // restore once we're done
    g_csgo.m_globals->m_frame      = frame;
    g_csgo.m_globals->m_curtime   = curtime;
    g_csgo.m_globals->m_frametime = frametime;
}
// task: hook C_BasePlayer::PostDataUpdate() and call this in it
// or use FRAME_NET_UPDATE_POSTDATAUPDATE_START
void anims::player_instance( Player* player ) {
    if( !player )
        return;
    CCSGOPlayerAnimState *state = player->m_PlayerAnimState( );
    if ( !state )
        return;
    AimPlayer* data = &g_aimbot.m_players[ player->index( ) - 1 ];
    if( !player->alive( ) || !g_cl.m_processing ) {
        if( player->m_flSimulationTime( ) != player->m_flOldSimulationTime( ) )
            mini_update( player );
        data->m_records.clear( );
        data->m_clear_next = true;
        return;
    }
    if( player->dormant( ) ) {
        if( data->m_records.empty( ) || !data->m_records[ 0 ]->dormant( ) ) {
            data->m_records.emplace_front( std::make_shared< LagRecord >( player ) );
            LagRecord* current = data->m_records.front( ).get( );
            current->m_dormant = true;
            current->m_setup   = false;
        }
        data->m_clear_next = true;
        return;
    }
    const float new_spawn = player->m_flSpawnTime( );
    // fix
    if( player != data->m_player || data->m_clear_next || data->m_spawn != new_spawn ) {
        // reset animation state and records (they're all invalid)
        game::ResetAnimationState( state );
        data->m_records.clear( );
        data->m_walk_record = LagRecordMove{ };
        // alternative fix
        player->m_flOldSimulationTime( ) = player->m_flSimulationTime( ) - g_csgo.m_globals->m_interval;
    }
    // update our vars
    data->m_player = player;
    data->m_clear_next = false;
    data->m_spawn = new_spawn;
    // player updated
    if( data->m_records.empty( ) || data->m_records[ 0 ]->m_sim_time != player->m_flSimulationTime( ) ) {
        // emplace new record
        data->m_records.emplace_front( std::make_shared< LagRecord >( player ) );
        // get our new record
        LagRecord* current = data->m_records.front( ).get( );
        current->m_dormant = false;
        // update animations
        update( player, current, data->m_records.size( ) > 1 ? data->m_records[ 1 ].get( ) : nullptr );
    }
    // don't store records that are too old
    while( data->m_records.size( ) > 1 ) {
        if( std::abs( g_csgo.m_cl->m_server_tick - data->m_records.back( )->m_tick ) < 256 )
            break;
        data->m_records.pop_back( );
    }
}
	
			
				anims.h:
			
		
		
		#pragma once
namespace anims {
    void mini_update( Player* player );
    void update( Player* player, LagRecord* record, LagRecord* previous );
    void player_instance( Player* player );
}
struct AnimationBackup_t {
    vec3_t           m_origin, m_abs_origin;
    vec3_t           m_velocity, m_abs_velocity;
    int              m_flags, m_eflags;
    float            m_duck, m_body;
    C_AnimationLayer m_layers[ 13 ];
    __forceinline void apply( Player* m_player ) {
        m_player->m_vecOrigin( ) = m_origin;
        m_player->m_vecVelocity( ) = m_velocity;
        m_player->m_vecAbsVelocity( ) = m_abs_velocity;
        m_player->m_fFlags( ) = m_flags;
        m_player->m_iEFlags( ) = m_eflags;
        m_player->m_flDuckAmount( ) = m_duck;
        m_player->m_flLowerBodyYawTarget( ) = m_body;
        m_player->SetAbsOrigin( m_abs_origin );
        m_player->SetAnimLayers( m_layers );
    }
    __forceinline void store( Player* m_player ) {
        m_origin = m_player->m_vecOrigin( );
        m_abs_origin = m_player->GetAbsOrigin( );
        m_velocity = m_player->m_vecVelocity( );
        m_abs_velocity = m_player->m_vecAbsVelocity( );
        m_flags = m_player->m_fFlags( );
        m_eflags = m_player->m_iEFlags( );
        m_duck = m_player->m_flDuckAmount( );
        m_body = m_player->m_flLowerBodyYawTarget( );
        m_player->GetAnimLayers( m_layers );
    }
};
	
			
				Последнее редактирование: