Skip to content

Commit

Permalink
don't mute chats + add new hud message mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wootguy committed Nov 5, 2024
1 parent 1de871f commit a1d1c69
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 36 deletions.
6 changes: 4 additions & 2 deletions dlls/client_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
81 changes: 50 additions & 31 deletions dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}


Expand Down
6 changes: 3 additions & 3 deletions dlls/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit a1d1c69

Please sign in to comment.