From 324be193c9d88454be7c53291ce780f3be4cfe5c Mon Sep 17 00:00:00 2001 From: Thomas Kain Date: Mon, 3 Mar 2025 15:28:38 -0500 Subject: [PATCH] Fix client-side entities playing some sounds incorrectly --- src/game/shared/SoundEmitterSystem.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/game/shared/SoundEmitterSystem.cpp b/src/game/shared/SoundEmitterSystem.cpp index 2c93c4919..270166833 100644 --- a/src/game/shared/SoundEmitterSystem.cpp +++ b/src/game/shared/SoundEmitterSystem.cpp @@ -1138,7 +1138,16 @@ void CBaseEntity::EmitSound( const char *soundname, float soundtime /*= 0.0f*/, params.m_pflSoundDuration = duration; params.m_bWarnOnDirectWaveReference = true; - EmitSound( filter, entindex(), params ); + int iEntIndex = entindex(); +#if defined( CLIENT_DLL ) + if ( iEntIndex == -1 ) + { + // If we're a clientside entity, we need to use the soundsourceindex instead of the entindex + iEntIndex = GetSoundSourceIndex(); + } +#endif + + EmitSound( filter, iEntIndex, params ); } #if !defined ( CLIENT_DLL ) @@ -1177,7 +1186,16 @@ void CBaseEntity::EmitSound( const char *soundname, HSOUNDSCRIPTHANDLE& handle, params.m_pflSoundDuration = duration; params.m_bWarnOnDirectWaveReference = true; - EmitSound( filter, entindex(), params, handle ); + int iEntIndex = entindex(); +#if defined( CLIENT_DLL ) + if ( iEntIndex == -1 ) + { + // If we're a clientside entity, we need to use the soundsourceindex instead of the entindex + iEntIndex = GetSoundSourceIndex(); + } +#endif + + EmitSound( filter, iEntIndex, params, handle ); } //-----------------------------------------------------------------------------