From 4b6932ac4a2d6b563f10359352e96c56da660fe6 Mon Sep 17 00:00:00 2001 From: AltimorTASDK Date: Tue, 18 Aug 2015 04:24:59 -0400 Subject: [PATCH] Fixed not restoring pose parameters or checking if GetModelPtr is null Shouldn't write code after staying up 24 hours --- mp/src/game/server/player_lagcompensation.cpp | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/mp/src/game/server/player_lagcompensation.cpp b/mp/src/game/server/player_lagcompensation.cpp index d288fa60..b0d3922f 100644 --- a/mp/src/game/server/player_lagcompensation.cpp +++ b/mp/src/game/server/player_lagcompensation.cpp @@ -24,6 +24,7 @@ #define LC_ANGLES_CHANGED (1<<9) #define LC_SIZE_CHANGED (1<<10) #define LC_ANIMATION_CHANGED (1<<11) +#define LC_POSE_PARAMS_CHANGED (1<<12) static ConVar sv_lagcompensation_teleport_dist( "sv_lagcompensation_teleport_dist", "64", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, "How far a player got moved by game code before we can't lag compensate their position back" ); #define LAG_COMPENSATION_EPS_SQR ( 0.1f * 0.1f ) @@ -322,9 +323,12 @@ void CLagCompensationManager::FrameUpdatePostEntityThink() record.m_masterCycle = pPlayer->GetCycle(); CStudioHdr *hdr = pPlayer->GetModelPtr(); - for( int paramIndex = 0; paramIndex < hdr->GetNumPoseParameters(); paramIndex++ ) + if( hdr ) { - record.m_poseParameters[paramIndex] = pPlayer->GetPoseParameter( paramIndex ); + for( int paramIndex = 0; paramIndex < hdr->GetNumPoseParameters(); paramIndex++ ) + { + record.m_poseParameters[paramIndex] = pPlayer->GetPoseParameter( paramIndex ); + } } } @@ -723,19 +727,22 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, float flTar // Now do pose parameters CStudioHdr *hdr = pPlayer->GetModelPtr(); - for( int paramIndex = 0; paramIndex < hdr->GetNumPoseParameters(); paramIndex++ ) + if( hdr ) { - float poseParameter = record->m_poseParameters[paramIndex]; - if( (frac > 0.0f) && interpolationAllowed ) + for( int paramIndex = 0; paramIndex < hdr->GetNumPoseParameters(); paramIndex++ ) { - // These could wrap like cycles, but there's no way to know. In the most common case - // (move_x/move_y) it's correct to just lerp. Interpolation almost never happens anyways. - float prevPoseParameter = prevRecord->m_poseParameters[paramIndex]; - pPlayer->SetPoseParameter( paramIndex, Lerp( frac, poseParameter, prevPoseParameter ) ); - } - else - { - pPlayer->SetPoseParameter( paramIndex, poseParameter ); + float poseParameter = record->m_poseParameters[paramIndex]; + if( (frac > 0.0f) && interpolationAllowed ) + { + // These could wrap like cycles, but there's no way to know. In the most common case + // (move_x/move_y) it's correct to just lerp. Interpolation almost never happens anyways. + float prevPoseParameter = prevRecord->m_poseParameters[paramIndex]; + pPlayer->SetPoseParameter( paramIndex, Lerp( frac, poseParameter, prevPoseParameter ) ); + } + else + { + pPlayer->SetPoseParameter( paramIndex, poseParameter ); + } } } @@ -860,6 +867,20 @@ void CLagCompensationManager::FinishLagCompensation( CBasePlayer *player ) } } } + + if( restore->m_fFlags & LC_POSE_PARAMS_CHANGED ) + { + restoreSimulationTime = true; + + CStudioHdr *hdr = pPlayer->GetModelPtr(); + if( hdr ) + { + for( int paramIndex = 0; paramIndex < hdr->GetNumPoseParameters(); paramIndex++ ) + { + pPlayer->SetPoseParameter( paramIndex, restore->m_poseParameters[paramIndex] ); + } + } + } if ( restoreSimulationTime ) {