From 37fbba2166154e6e1c449a645e646f101b934009 Mon Sep 17 00:00:00 2001 From: Valkyrie Date: Fri, 12 Feb 2021 17:04:13 -0500 Subject: [PATCH 1/4] Weapon sounds now work on dedicated servers Co-authored-by: Joshua Ashton --- mp/src/game/shared/sdk/sdk_fx_shared.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/mp/src/game/shared/sdk/sdk_fx_shared.cpp b/mp/src/game/shared/sdk/sdk_fx_shared.cpp index 9c34e3f29..e1b28a75b 100644 --- a/mp/src/game/shared/sdk/sdk_fx_shared.cpp +++ b/mp/src/game/shared/sdk/sdk_fx_shared.cpp @@ -100,7 +100,21 @@ void FX_WeaponSound ( int iPlayerIndex, WeaponSound_t sound_type, const Vector &vOrigin, - CSDKWeaponInfo *pWeaponInfo ) {}; + CSDKWeaponInfo *pWeaponInfo ) + { + // make sure we got something + if (iPlayerIndex == -1) + return; + + // If we have some sounds from the weapon classname.txt file, play a random one of them + const char *shootsound = pWeaponInfo->aShootSounds[sound_type]; + if (!shootsound || !shootsound[0]) + return; + + CBroadcastRecipientFilter filter; + filter.RemoveRecipient(UTIL_PlayerByIndex(iPlayerIndex)); + CBaseEntity::EmitSound(filter, iPlayerIndex, shootsound, &vOrigin); + } #endif @@ -168,17 +182,16 @@ void FX_FireBullets( WeaponSound_t sound_type = SINGLE; +#ifdef CLIENT_DLL if ( bDoEffects) { -#ifdef CLIENT_DLL if (pPlayer) pPlayer->m_flMuzzleFlashYaw = random->RandomFloat(0, 360); //ProjectedLightEffectManager( iPlayerIndex ).TriggerMuzzleFlash(); -#endif - - FX_WeaponSound( iPlayerIndex, sound_type, vOrigin, pWeaponInfo ); } +#endif + FX_WeaponSound(iPlayerIndex, sound_type, vOrigin, pWeaponInfo); // Fire bullets, calculate impacts & effects From ccd1c214bb74cbc24398b17963d2f5708ab95fc7 Mon Sep 17 00:00:00 2001 From: Valkyrie Date: Sat, 13 Feb 2021 00:26:50 -0500 Subject: [PATCH 2/4] Fixed problem where weapon sounds from other players play more than once --- mp/src/game/shared/sdk/sdk_fx_shared.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mp/src/game/shared/sdk/sdk_fx_shared.cpp b/mp/src/game/shared/sdk/sdk_fx_shared.cpp index e1b28a75b..8bff2c1a9 100644 --- a/mp/src/game/shared/sdk/sdk_fx_shared.cpp +++ b/mp/src/game/shared/sdk/sdk_fx_shared.cpp @@ -170,9 +170,7 @@ void FX_FireBullets( iMode, iSeed, flSpread - ); - - bDoEffects = false; // no effects on server + ); #endif iSeed++; @@ -182,19 +180,16 @@ void FX_FireBullets( WeaponSound_t sound_type = SINGLE; -#ifdef CLIENT_DLL - if ( bDoEffects) + if (bDoEffects) { +#ifdef CLIENT_DLL if (pPlayer) pPlayer->m_flMuzzleFlashYaw = random->RandomFloat(0, 360); - //ProjectedLightEffectManager( iPlayerIndex ).TriggerMuzzleFlash(); - } #endif - - FX_WeaponSound(iPlayerIndex, sound_type, vOrigin, pWeaponInfo); + FX_WeaponSound(iPlayerIndex, sound_type, vOrigin, pWeaponInfo); + } // Fire bullets, calculate impacts & effects - if ( !pPlayer ) return; From c264c429b3793b30ce4a38bf2498b1f33247e65b Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sat, 13 Feb 2021 17:06:21 +0100 Subject: [PATCH 3/4] whitespace revert --- mp/src/game/shared/sdk/sdk_fx_shared.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mp/src/game/shared/sdk/sdk_fx_shared.cpp b/mp/src/game/shared/sdk/sdk_fx_shared.cpp index 8bff2c1a9..6a392f169 100644 --- a/mp/src/game/shared/sdk/sdk_fx_shared.cpp +++ b/mp/src/game/shared/sdk/sdk_fx_shared.cpp @@ -170,7 +170,7 @@ void FX_FireBullets( iMode, iSeed, flSpread - ); + ); #endif iSeed++; @@ -180,16 +180,20 @@ void FX_FireBullets( WeaponSound_t sound_type = SINGLE; - if (bDoEffects) + if ( bDoEffects) { #ifdef CLIENT_DLL if (pPlayer) pPlayer->m_flMuzzleFlashYaw = random->RandomFloat(0, 360); + //ProjectedLightEffectManager( iPlayerIndex ).TriggerMuzzleFlash(); #endif - FX_WeaponSound(iPlayerIndex, sound_type, vOrigin, pWeaponInfo); + + FX_WeaponSound( iPlayerIndex, sound_type, vOrigin, pWeaponInfo ); } + // Fire bullets, calculate impacts & effects + if ( !pPlayer ) return; From b15cbac2ef883d7c8b1c7f0c16b06cbef52ace0e Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Mon, 15 Feb 2021 18:42:30 +0100 Subject: [PATCH 4/4] Prevent double fires Co-authored-by: Valkyrie --- mp/src/game/client/sdk/c_te_firebullets.cpp | 4 +++- mp/src/game/shared/sdk/sdk_fx_shared.cpp | 6 ++++-- mp/src/game/shared/sdk/sdk_fx_shared.h | 3 ++- mp/src/game/shared/sdk/weapon_sdkbase.cpp | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mp/src/game/client/sdk/c_te_firebullets.cpp b/mp/src/game/client/sdk/c_te_firebullets.cpp index 846be238c..30c43ffa2 100644 --- a/mp/src/game/client/sdk/c_te_firebullets.cpp +++ b/mp/src/game/client/sdk/c_te_firebullets.cpp @@ -43,7 +43,9 @@ void C_TEFireBullets::PostDataUpdate( DataUpdateType_t updateType ) m_iWeaponID, m_iMode, m_iSeed, - m_flSpread ); + m_flSpread, + false + ); } diff --git a/mp/src/game/shared/sdk/sdk_fx_shared.cpp b/mp/src/game/shared/sdk/sdk_fx_shared.cpp index 6a392f169..e269e39f9 100644 --- a/mp/src/game/shared/sdk/sdk_fx_shared.cpp +++ b/mp/src/game/shared/sdk/sdk_fx_shared.cpp @@ -130,7 +130,8 @@ void FX_FireBullets( int iWeaponID, int iMode, int iSeed, - float flSpread + float flSpread, + bool bShouldPlaySound ) { Assert(vOrigin.IsValid()); @@ -188,7 +189,8 @@ void FX_FireBullets( //ProjectedLightEffectManager( iPlayerIndex ).TriggerMuzzleFlash(); #endif - FX_WeaponSound( iPlayerIndex, sound_type, vOrigin, pWeaponInfo ); + if (bShouldPlaySound) + FX_WeaponSound(iPlayerIndex, sound_type, vOrigin, pWeaponInfo); } diff --git a/mp/src/game/shared/sdk/sdk_fx_shared.h b/mp/src/game/shared/sdk/sdk_fx_shared.h index 243790993..8499fdb35 100644 --- a/mp/src/game/shared/sdk/sdk_fx_shared.h +++ b/mp/src/game/shared/sdk/sdk_fx_shared.h @@ -20,7 +20,8 @@ void FX_FireBullets( int iWeaponID, int iMode, int iSeed, - float flSpread + float flSpread, + bool bShouldPlaySound ); diff --git a/mp/src/game/shared/sdk/weapon_sdkbase.cpp b/mp/src/game/shared/sdk/weapon_sdkbase.cpp index 4ce5e0c42..49cb0337e 100644 --- a/mp/src/game/shared/sdk/weapon_sdkbase.cpp +++ b/mp/src/game/shared/sdk/weapon_sdkbase.cpp @@ -326,7 +326,8 @@ void CWeaponSDKBase::FinishAttack (CSDKPlayer *pPlayer) GetWeaponID(), 0, //Tony; fire mode - this is unused at the moment, left over from CSS when SDK* was created in the first place. CBaseEntity::GetPredictionRandomSeed() & 255, - flSpread + flSpread, + true ); //Add our view kick in