-
Автор темы
- #1
C++:
void Animations::RebuiltLayer6( Player* player, LagComp::LagRecord_t::LayerData_t* layer_data ) {
// rebuilt layer 6 calculations from csgo
// links:
// https://github.com/perilouswithadollarsign/cstrike15_src/blob/master/game/shared/cstrike15/csgo_playeranimstate.cpp#L1393
// https://github.com/click4dylan/CSGO_AnimationCode_Reversed/blob/master/CCSGOPlayerAnimState_New.cpp#L2323
auto m_pState = player->m_PlayerAnimState( );
static const float CS_PLAYER_SPEED_RUN = 260.0f;
// TODO: Find these members in the actual animstate struct
auto m_flLastUpdateIncrement = *( float* )( ( DWORD )m_pState + 0x74 );
auto m_flFootYaw = m_pState->goal_feet_yaw;
auto m_flMoveYaw = m_pState->torso_yaw;
auto m_vecVelocityNormalizedNonZero = *( vec3_t* )( ( DWORD )m_pState + 0xE0 );
auto m_flInAirSmoothValue = *( float* )( ( DWORD )m_pState + 0x124 );
AnimationData_t& m_AnimationData = m_animation_data[ player->index( ) ];
char m_szDestination[ 64 ];
sprintf_s( m_szDestination, XOR( "move_%s" ), m_pState->GetWeaponPrefix( ) );
int m_nMoveSequence = player->LookupSequence( m_szDestination );
if ( m_nMoveSequence == -1 )
{
m_nMoveSequence = player->LookupSequence( XOR( "move" ) );
}
// NOTE:
// player->get<int>( 0x3984 ) is m_iMoveState
if ( player->get<int>( 0x3984 ) != m_AnimationData.m_iMoveState )
m_AnimationData.m_flMovePlaybackRate += 10.0f;
m_AnimationData.m_iMoveState = player->get<int>( 0x3984 );
float m_flMovementTimeDelta = *( float* )( ( DWORD )m_pState + 0x74 ) * 40.0f;
if ( -m_AnimationData.m_flMovePlaybackRate <= m_flMovementTimeDelta )
{
if ( -m_flMovementTimeDelta <= -m_AnimationData.m_flMovePlaybackRate )
m_AnimationData.m_flMovePlaybackRate = 0.0f;
else
m_AnimationData.m_flMovePlaybackRate = m_AnimationData.m_flMovePlaybackRate - m_flMovementTimeDelta;
}
else
{
m_AnimationData.m_flMovePlaybackRate = m_AnimationData.m_flMovePlaybackRate + m_flMovementTimeDelta;
}
m_AnimationData.m_flMovePlaybackRate = std::clamp( m_AnimationData.m_flMovePlaybackRate, 0.0f, 100.0f );
float m_flDuckSpeedClamped = std::clamp( *( float* )( ( DWORD )m_pState + 0xFC ), 0.0f, 1.0f );
float m_flRunSpeedClamped = std::clamp( *( float* )( ( DWORD )m_pState + 0xF8 ), 0.0f, 1.0f );
float m_flSpeedWeight = ( ( m_flDuckSpeedClamped - m_flRunSpeedClamped ) * *( float* )( ( DWORD )m_pState + 0xA4 ) ) + m_flRunSpeedClamped;
if ( m_flSpeedWeight < layer_data->m_flFeetWeight )
{
float v34 = std::clamp( m_AnimationData.m_flMovePlaybackRate * 0.01f, 0.0f, 1.0f );
float m_flFeetWeightElapsed = ( ( v34 * 18.0f ) + 2.0f ) * *( float* )( ( DWORD )m_pState + 0x74 );
if ( m_flSpeedWeight - layer_data->m_flFeetWeight <= m_flFeetWeightElapsed )
layer_data->m_flFeetWeight = -m_flFeetWeightElapsed <= ( m_flSpeedWeight - layer_data->m_flFeetWeight ) ? m_flSpeedWeight : layer_data->m_flFeetWeight - m_flFeetWeightElapsed;
else
layer_data->m_flFeetWeight = m_flFeetWeightElapsed + layer_data->m_flFeetWeight;
}
else
{
layer_data->m_flFeetWeight = m_flSpeedWeight;
}
float m_flYaw = math::AngleNormalize( ( m_pState->torso_yaw + m_pState->goal_feet_yaw ) + 180.0f );
ang_t m_angAngle = { 0.0f, m_flYaw, 0.0f };
vec3_t m_vecDirection;
math::AngleVectors( m_angAngle, &m_vecDirection );
float m_flMovementSide = math::DotProduct( m_vecVelocityNormalizedNonZero, m_vecDirection );
if ( m_flMovementSide < 0.0f )
m_flMovementSide = -m_flMovementSide;
float m_flNewFeetWeight = math::Bias( m_flMovementSide, 0.2f ) * layer_data->m_flFeetWeight;
float m_flNewFeetWeightWithAirSmooth = m_flNewFeetWeight * m_flInAirSmoothValue;
// m_flLayer5Weight looks a bit weird so i decided to name it m_flLayer5_Weight instead.
float m_flLayer5_Weight = player->GetLayerWeight( 5 );
float m_flNewWeight = 0.55f;
if ( 1.0f - m_flLayer5_Weight > 0.55f )
m_flNewWeight = 1.0f - m_flLayer5_Weight;
float m_flNewFeetWeightLayerWeight = m_flNewWeight * m_flNewFeetWeightWithAirSmooth;
float m_flFeetCycleRate = 0.0f;
float m_flSpeed = std::fmin( player->m_vecVelocity( ).length( ), 260.f );
if ( m_flSpeed > 0.00f )
{
float m_flSequenceCycleRate = player->GetSequenceCycleRate( player->GetModelPtr( ), m_nMoveSequence );
float m_flSequenceMoveDist = player->GetSequenceMoveDist( player->GetModelPtr( ), m_nMoveSequence );
m_flSequenceMoveDist *= 1.0f / ( 1.0f / m_flSequenceCycleRate );
if ( m_flSequenceMoveDist <= 0.001f )
m_flSequenceMoveDist = 0.001f;
float m_flSpeedMultiplier = m_flSpeed / m_flSequenceMoveDist;
m_flFeetCycleRate = ( 1.0f - ( m_pState->stop_to_full_running_fraction * 0.15f ) ) * ( m_flSpeedMultiplier * m_flSequenceCycleRate );
}
float m_flFeetCyclePlaybackRate = ( *( float* )( ( DWORD )m_pState + 0x74 ) * m_flFeetCycleRate );
m_AnimationData.m_flPrimaryCycle = m_flFeetCyclePlaybackRate + m_AnimationData.m_flPrimaryCycle;
// store possible information for resolving.
layer_data->m_flMovementSide = m_flMovementSide;
layer_data->m_angMoveYaw = m_angAngle;
layer_data->m_vecDirection = m_vecDirection;
layer_data->m_flFeetWeight = m_flNewFeetWeight;
layer_data->m_nSequence = m_nMoveSequence;
layer_data->m_flPlaybackRate = m_flFeetCyclePlaybackRate;
layer_data->m_flCycle = m_AnimationData.m_flPrimaryCycle;
layer_data->m_flWeight = std::clamp( m_flNewFeetWeightLayerWeight, 0.0f, 1.0f );
}