From c4b043d39f9f2ac687a36307bfb223728779d18d Mon Sep 17 00:00:00 2001 From: Spoike Date: Wed, 29 Jun 2022 07:20:24 +0000 Subject: [PATCH] Fix some missing ambient sounds on large bloated maps/mods (this really should have been fixed years ago). git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6281 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cl_parse.c | 22 ++++++++++++++++++---- engine/common/protocol.h | 1 + engine/server/pr_cmds.c | 2 +- engine/server/sv_send.c | 7 ++----- engine/server/sv_user.c | 14 ++++++++++++-- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index f56bfc6c1..a22dfc1bc 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -4973,23 +4973,34 @@ static void CL_ParseStaticProt (int baselinetype) CL_ParseStaticSound =================== */ -static void CL_ParseStaticSound (qboolean large) +static void CL_ParseStaticSound (unsigned int flags) { extern cvar_t cl_staticsounds; vec3_t org; - int sound_num; + size_t sound_num; float vol, atten; int i; + if (flags & ~(1)) + Host_EndGame("CL_ParseStaticSound: unsupported flags & %x\n", flags&~(1)); + for (i=0 ; i<3 ; i++) org[i] = MSG_ReadCoord (); - if (large || (cls.protocol == CP_NETQUAKE && cls.protocol_nq == CPNQ_BJP2)) - sound_num = (unsigned short)MSG_ReadShort(); + if (flags || (cls.protocol == CP_NETQUAKE && cls.protocol_nq == CPNQ_BJP2)) + { + if (cls.fteprotocolextensions2&PEXT2_LERPTIME) + sound_num = (unsigned short)MSG_ReadULEB128(); + else + sound_num = (unsigned short)MSG_ReadShort(); + } else sound_num = MSG_ReadByte (); vol = MSG_ReadByte ()/255.0; atten = MSG_ReadByte ()/64.0; + if (sound_num >= countof(cl.sound_precache)) + return; //no crashing, please. + vol *= cl_staticsounds.value; if (vol < 0) return; @@ -7520,6 +7531,9 @@ void CLQW_ParseServerMessage (void) case svc_spawnstaticsound: CL_ParseStaticSound (false); break; + case svcfte_spawnstaticsound2: + CL_ParseStaticSound (MSG_ReadByte()); + break; case svc_cdtrack: { diff --git a/engine/common/protocol.h b/engine/common/protocol.h index df9ced935..7441c38b8 100644 --- a/engine/common/protocol.h +++ b/engine/common/protocol.h @@ -334,6 +334,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define svcfte_temp_entity_sized 91 //svc_temp_entity with an extra short size right after the svc (high bit means nq, unset means qw). #define svcfte_csqcentities_sized 92 //entity lump for csqc (with size info) #define svcfte_setanglebase 93 //updates the base angle (and optionally locks the view, otherwise nudging it without race conditions.) +#define svcfte_spawnstaticsound2 94 //*sigh* //fitz svcs #define svcfitz_skybox 37 diff --git a/engine/server/pr_cmds.c b/engine/server/pr_cmds.c index 8013d5f95..f5e561e50 100644 --- a/engine/server/pr_cmds.c +++ b/engine/server/pr_cmds.c @@ -3675,7 +3675,7 @@ void PF_ambientsound_Internal (float *pos, const char *samp, float vol, float at VectorCopy(pos, state->position); state->soundnum = soundnum; state->volume = bound(0, (int)(vol*255), 255); - state->attenuation = attenuation*64; + state->attenuation = bound(0,attenuation*64,255); } static void QCBUILTIN PF_ambientsound (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals) diff --git a/engine/server/sv_send.c b/engine/server/sv_send.c index 1ad4ed3c1..db83406e2 100644 --- a/engine/server/sv_send.c +++ b/engine/server/sv_send.c @@ -1201,11 +1201,8 @@ void SV_StartSound (int ent, vec3_t origin, float *velocity, int seenmask, int c return; } - if (attenuation < 0 || attenuation > 4) - { - Con_Printf ("SV_StartSound: attenuation = %f", attenuation); - return; - } + if (attenuation < 0 || attenuation >= 4) + Con_DPrintf ("SV_StartSound: attenuation = %f", attenuation); if (channel < 0 || channel > 255) { diff --git a/engine/server/sv_user.c b/engine/server/sv_user.c index e60f84806..75634463e 100644 --- a/engine/server/sv_user.c +++ b/engine/server/sv_user.c @@ -1694,9 +1694,14 @@ void SV_SendClientPrespawnInfo(client_t *client) large = true; if (client->protocol == SCP_BJP3) continue; //not supported + else if (ISQWCLIENT(client) && (client->fteprotocolextensions2 & PEXT2_REPLACEMENTDELTAS)) + { + MSG_WriteByte(&client->netchan.message, svcfte_spawnstaticsound2); + MSG_WriteByte(&client->netchan.message, 1); + } else if (ISDPCLIENT(client)) MSG_WriteByte(&client->netchan.message, svcdp_spawnstaticsound2); - else if (ISNQCLIENT(client)) + else if (client->protocol == SCP_FITZ666) MSG_WriteByte(&client->netchan.message, svcfitz_spawnstaticsound2); else continue; //not supported @@ -1707,7 +1712,12 @@ void SV_SendClientPrespawnInfo(client_t *client) for (i=0 ; i<3 ; i++) MSG_WriteCoord(&client->netchan.message, sound->position[i]); if (large) - MSG_WriteShort(&client->netchan.message, sound->soundnum); + { + if (client->fteprotocolextensions2&PEXT2_LERPTIME) + MSG_WriteULEB128(&client->netchan.message, sound->soundnum); + else + MSG_WriteShort(&client->netchan.message, sound->soundnum); + } else MSG_WriteByte(&client->netchan.message, sound->soundnum); MSG_WriteByte(&client->netchan.message, sound->volume);