From 9ac6d4c6e4eda02d37043f8d53a8db23ef8531f0 Mon Sep 17 00:00:00 2001 From: Kamay Xutax Date: Tue, 23 Jan 2024 14:32:02 +0100 Subject: [PATCH] Add weapon_accuracy_nospread & posparam lagcomp --- game/server/player_lagcompensation.cpp | 47 ++++++++++++++++++++++++ game/shared/cstrike/cs_player_shared.cpp | 7 ++++ 2 files changed, 54 insertions(+) diff --git a/game/server/player_lagcompensation.cpp b/game/server/player_lagcompensation.cpp index 1bec034dc8..fcee4bbc42 100644 --- a/game/server/player_lagcompensation.cpp +++ b/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 ) @@ -41,6 +42,7 @@ ConVar sv_unlag_fixstuck( "sv_unlag_fixstuck", "0", FCVAR_DEVELOPMENTONLY, "Disa // Purpose: //----------------------------------------------------------------------------- #define MAX_LAYER_RECORDS (CBaseAnimatingOverlay::MAX_OVERLAYS) +#define MAX_POSE_PARAMETERS (CBaseAnimating::NUM_POSEPAREMETERS) struct LayerRecord { @@ -112,6 +114,7 @@ public: LayerRecord m_layerRecords[MAX_LAYER_RECORDS]; int m_masterSequence; float m_masterCycle; + float m_poseParameters[MAX_POSE_PARAMETERS]; }; @@ -313,6 +316,15 @@ void CLagCompensationManager::FrameUpdatePostEntityThink() } record.m_masterSequence = pPlayer->GetSequence(); record.m_masterCycle = pPlayer->GetCycle(); + + CStudioHdr *hdr = pPlayer->GetModelPtr(); + if( hdr ) + { + for( int paramIndex = 0; paramIndex < hdr->GetNumPoseParameters(); paramIndex++ ) + { + record.m_poseParameters[paramIndex] = pPlayer->GetPoseParameter( paramIndex ); + } + } } //Clear the current player. @@ -704,6 +716,27 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, float flTar } } + // Now do pose parameters + CStudioHdr *hdr = pPlayer->GetModelPtr(); + if( hdr ) + { + for( int paramIndex = 0; paramIndex < hdr->GetNumPoseParameters(); paramIndex++ ) + { + 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 ); + } + } + } + if ( !flags ) return; // we didn't change anything @@ -823,6 +856,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 ) { pPlayer->SetSimulationTime( restore->m_flSimulationTime ); diff --git a/game/shared/cstrike/cs_player_shared.cpp b/game/shared/cstrike/cs_player_shared.cpp index e0f3d91d63..c35a4da46e 100644 --- a/game/shared/cstrike/cs_player_shared.cpp +++ b/game/shared/cstrike/cs_player_shared.cpp @@ -34,6 +34,7 @@ ConVar sv_showimpacts("sv_showimpacts", "0", FCVAR_REPLICATED, "Shows client (red) and server (blue) bullet impact point (1=both, 2=client-only, 3=server-only)" ); ConVar sv_showplayerhitboxes( "sv_showplayerhitboxes", "0", FCVAR_REPLICATED, "Show lag compensated hitboxes for the specified player index whenever a player fires." ); +ConVar weapon_accuracy_nospread( "weapon_accuracy_nospread", "0", FCVAR_REPLICATED ); #define CS_MASK_SHOOT (MASK_SOLID|CONTENTS_DEBRIS) @@ -354,6 +355,12 @@ void CCSPlayer::FireBullet( if ( !pevAttacker ) pevAttacker = this; // the default attacker is ourselves + if ( weapon_accuracy_nospread.GetBool() ) + { + xSpread = 0.0f; + ySpread = 0.0f; + } + // add the spray Vector vecDir = vecDirShooting + xSpread * vecRight + ySpread * vecUp;