From a1d1c69651f729f5615a26e06cb543a586312d96 Mon Sep 17 00:00:00 2001 From: wootguy Date: Mon, 4 Nov 2024 23:57:57 -0800 Subject: [PATCH] don't mute chats + add new hud message mode scoreboard muting is broken in HL, so at least don't mute the chats for when accidents happen. SVC_DIRECTOR messages have an additional 8 channels to use for HUD messages, now usable by setting channel -1. The client automatically selects a channel to use and overwrites one if none are free. --- dlls/client_commands.cpp | 6 ++- dlls/util.cpp | 81 +++++++++++++++++++++++++--------------- dlls/util.h | 6 +-- 3 files changed, 57 insertions(+), 36 deletions(-) diff --git a/dlls/client_commands.cpp b/dlls/client_commands.cpp index 7f5aa554..667f77d4 100644 --- a/dlls/client_commands.cpp +++ b/dlls/client_commands.cpp @@ -236,8 +236,10 @@ void Host_Say(edict_t* pEntity, int teamonly) continue; // can the receiver hear the sender? or has he muted him? - if (g_VoiceGameMgr.PlayerHasBlockedPlayer(client, player)) - continue; + // TODO: voice muting has a buggy implementation that causes random ppl to get muted + // when you change servers. Create a new system. + //if (g_VoiceGameMgr.PlayerHasBlockedPlayer(client, player)) + // continue; /* if (!player->IsObserver() && teamonly && g_pGameRules->PlayerRelationship(client, CBaseEntity::Instance(pEntity)) != GR_TEAMMATE) diff --git a/dlls/util.cpp b/dlls/util.cpp index 17435e4b..300c70cb 100644 --- a/dlls/util.cpp +++ b/dlls/util.cpp @@ -790,6 +790,10 @@ void WRITE_BYTES(uint8_t* bytes, int count) { } } +void WRITE_FLOAT(float f) { + WRITE_LONG(*(uint32_t*)&f); +} + void UTIL_EmitAmbientSound( edict_t *entity, const float* vecOrigin, const char *samp, float vol, float attenuation, int fFlags, int pitch, edict_t* dest) { float rgfl[3]; @@ -1071,50 +1075,65 @@ const char* BreakupLongLines(const char* pMessage) { void UTIL_HudMessage( CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage, int msgMode) { - if ( !pEntity || !pEntity->IsNetClient() ) + bool isIndividual = msgMode == MSG_ONE || msgMode == MSG_ONE_UNRELIABLE; + + if (isIndividual && (!pEntity || !pEntity->IsNetClient())) return; pMessage = BreakupLongLines(pMessage); - MESSAGE_BEGIN(msgMode, SVC_TEMPENTITY, NULL, pEntity->edict() ); - WRITE_BYTE( TE_TEXTMESSAGE ); - WRITE_BYTE( textparms.channel & 0xFF ); + if (textparms.channel == -1) { + int sz = 7 * sizeof(long) + 3 + strlen(pMessage); + uint32_t color = (textparms.r1 << 16) | (textparms.g1 << 8) | textparms.b1; + + MESSAGE_BEGIN(msgMode, SVC_DIRECTOR, NULL, pEntity ? pEntity->edict() : NULL); + WRITE_BYTE(sz); // message size + WRITE_BYTE(6); // director message + WRITE_BYTE(textparms.effect); // effect + WRITE_LONG(color); // color + WRITE_FLOAT(textparms.x); // x + WRITE_FLOAT(textparms.y); // y + WRITE_FLOAT(textparms.fadeinTime); // fade in + WRITE_FLOAT(textparms.fadeoutTime); // fade out + WRITE_FLOAT(textparms.holdTime); // hold time + WRITE_FLOAT(textparms.fxTime); // fx time + WRITE_STRING(pMessage); // fx time + MESSAGE_END(); + } + else { + MESSAGE_BEGIN(msgMode, SVC_TEMPENTITY, NULL, pEntity ? pEntity->edict() : NULL); + WRITE_BYTE(TE_TEXTMESSAGE); + WRITE_BYTE(textparms.channel & 0xFF); - WRITE_SHORT( FixedSigned16( textparms.x, 1<<13 ) ); - WRITE_SHORT( FixedSigned16( textparms.y, 1<<13 ) ); - WRITE_BYTE( textparms.effect ); + WRITE_SHORT(FixedSigned16(textparms.x, 1 << 13)); + WRITE_SHORT(FixedSigned16(textparms.y, 1 << 13)); + WRITE_BYTE(textparms.effect); - WRITE_BYTE( textparms.r1 ); - WRITE_BYTE( textparms.g1 ); - WRITE_BYTE( textparms.b1 ); - WRITE_BYTE( textparms.a1 ); + WRITE_BYTE(textparms.r1); + WRITE_BYTE(textparms.g1); + WRITE_BYTE(textparms.b1); + WRITE_BYTE(textparms.a1); - WRITE_BYTE( textparms.r2 ); - WRITE_BYTE( textparms.g2 ); - WRITE_BYTE( textparms.b2 ); - WRITE_BYTE( textparms.a2 ); + WRITE_BYTE(textparms.r2); + WRITE_BYTE(textparms.g2); + WRITE_BYTE(textparms.b2); + WRITE_BYTE(textparms.a2); - WRITE_SHORT( FixedUnsigned16( textparms.fadeinTime, 1<<8 ) ); - WRITE_SHORT( FixedUnsigned16( textparms.fadeoutTime, 1<<8 ) ); - WRITE_SHORT( FixedUnsigned16( textparms.holdTime, 1<<8 ) ); + WRITE_SHORT(FixedUnsigned16(textparms.fadeinTime, 1 << 8)); + WRITE_SHORT(FixedUnsigned16(textparms.fadeoutTime, 1 << 8)); + WRITE_SHORT(FixedUnsigned16(textparms.holdTime, 1 << 8)); - if ( textparms.effect == 2 ) - WRITE_SHORT( FixedUnsigned16( textparms.fxTime, 1<<8 ) ); + if (textparms.effect == 2) + WRITE_SHORT(FixedUnsigned16(textparms.fxTime, 1 << 8)); - WRITE_STRING( pMessage ); - MESSAGE_END(); + WRITE_STRING(pMessage); + MESSAGE_END(); + } } -void UTIL_HudMessageAll( const hudtextparms_t &textparms, const char *pMessage ) +void UTIL_HudMessageAll(const hudtextparms_t& textparms, const char* pMessage, int msgMode) { - int i; - - for ( i = 1; i <= gpGlobals->maxClients; i++ ) - { - CBaseEntity *pPlayer = UTIL_PlayerByIndex( i ); - if ( pPlayer ) - UTIL_HudMessage( pPlayer, textparms, pMessage ); - } + UTIL_HudMessage(NULL, textparms, pMessage, MSG_ALL); } diff --git a/dlls/util.h b/dlls/util.h index 448930ac..a349e774 100644 --- a/dlls/util.h +++ b/dlls/util.h @@ -244,6 +244,7 @@ inline void MESSAGE_BEGIN( int msg_dest, int msg_type, const float *pOrigin, ent MESSAGE_BEGIN(msg_dest, msg_type, pOrigin, ENT(ent)); } EXPORT void WRITE_BYTES(uint8_t* bytes, int count); +EXPORT void WRITE_FLOAT(float val); // Testing the three types of "entity" for nullity #define eoNullEntity 0 @@ -428,7 +429,6 @@ EXPORT void UTIL_ClientPrint(edict_t* client, int msg_dest, const char *msg ); EXPORT void UTIL_SayText( const char *pText, CBaseEntity *pEntity ); EXPORT void UTIL_SayTextAll( const char *pText, CBaseEntity *pEntity=NULL ); - typedef struct hudtextparms_s { float x; @@ -440,11 +440,11 @@ typedef struct hudtextparms_s float fadeoutTime; float holdTime; float fxTime; - int channel; + int channel; // -1 = automatic (director message mode) } hudtextparms_t; // prints as transparent 'title' to the HUD -EXPORT void UTIL_HudMessageAll( const hudtextparms_t &textparms, const char *pMessage ); +EXPORT void UTIL_HudMessageAll( const hudtextparms_t &textparms, const char *pMessage, int msgMode = MSG_ALL ); EXPORT void UTIL_HudMessage( CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage, int msgMode = MSG_ONE); // for handy use with ClientPrint params