From 2daaa946662620212ca2042fbc4b56e33a142780 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 3 Sep 2025 03:07:36 +0500 Subject: [PATCH] engine: voice: fix voice loopback on GoldSrc proto --- engine/client/cl_main.c | 6 +++++- engine/client/voice.c | 7 +------ engine/client/voice.h | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index ff62956e..f2a9627f 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -789,6 +789,7 @@ static void CL_WritePacket( void ) { int newcmds, numcmds; int from, i, key; + int packet_loss = bound( 0, (int)cls.packet_loss, 100 ); cls.nextcmdtime = host.realtime + ( 1.0f / cl_cmdrate.value ); @@ -808,7 +809,10 @@ static void CL_WritePacket( void ) key = MSG_GetRealBytesWritten( &buf ); MSG_WriteByte( &buf, 0 ); - MSG_WriteByte( &buf, bound( 0, (int)cls.packet_loss, 100 )); + if( proto == PROTO_GOLDSRC && voice_loopback.value ) + SetBits( packet_loss, 7 ); // set 7-th bit to tell server that we want voice loopback + + MSG_WriteByte( &buf, packet_loss ); MSG_WriteByte( &buf, numbackup ); MSG_WriteByte( &buf, newcmds ); diff --git a/engine/client/voice.c b/engine/client/voice.c index b3e45652..55b610e3 100644 --- a/engine/client/voice.c +++ b/engine/client/voice.c @@ -984,7 +984,7 @@ void Voice_AddIncomingData( int ent, const byte *data, uint size, uint frames ) return; // must notify through as both local player and normal client - if( ent == ( cl.playernum + 1 )) + if( playernum == cl.playernum ) Voice_StatusAck( &voice.local, VOICE_LOOPBACK_INDEX ); status = Voice_GetPlayerStatus( ent ); @@ -1057,11 +1057,6 @@ void CL_AddVoiceToDatagram( void ) MSG_BeginClientCmd( &cls.datagram, clc_voicedata ); MSG_WriteShort( &cls.datagram, packet_size ); MSG_WriteBytes( &cls.datagram, voice.compress_buffer, packet_size ); - - if( voice_loopback.value && packet_size > 0 && frames > 0 ) - { - Voice_AddIncomingData( cl.playernum + 1, voice.compress_buffer, packet_size, frames ); - } } return; } diff --git a/engine/client/voice.h b/engine/client/voice.h index 704336fa..894f619d 100644 --- a/engine/client/voice.h +++ b/engine/client/voice.h @@ -119,6 +119,8 @@ typedef struct voice_state_s extern voice_state_t voice; +extern convar_t voice_loopback; + void CL_AddVoiceToDatagram( void ); void Voice_RegisterCvars( void ); qboolean Voice_Init( const char *pszCodecName, int quality, qboolean preinit );