Skip to content

Commit f3c08cb

Browse files
committed
Add !zsounds toggle
1 parent a283a7e commit f3c08cb

File tree

7 files changed

+122
-56
lines changed

7 files changed

+122
-56
lines changed

src/cs2fixes.cpp

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -757,69 +757,76 @@ void CS2Fixes::Hook_PostEvent(CSplitScreenSlot nSlot, bool bLocalOnly, int nClie
757757
if (g_cvarEnableNoShake.Get())
758758
*(uint64*)clients &= ~g_playerManager->GetNoShakeMask();
759759
}
760-
else if (g_cvarEnableStopSound.Get() && info->m_MessageId == GE_SosStartSoundEvent)
760+
else if (info->m_MessageId == GE_SosStartSoundEvent)
761761
{
762-
static std::set<uint32> soundEventHashes;
763762
auto msg = const_cast<CNetMessage*>(pData)->ToPB<CMsgSosStartSoundEvent>();
764763

765-
ExecuteOnce(
766-
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.HitWall"));
767-
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.Slash"));
768-
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.Hit"));
769-
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.Stab"));
770-
soundEventHashes.insert(GetSoundEventHash("Weapon_sg556.ZoomIn"));
771-
soundEventHashes.insert(GetSoundEventHash("Weapon_sg556.ZoomOut"));
772-
soundEventHashes.insert(GetSoundEventHash("Weapon_AUG.ZoomIn"));
773-
soundEventHashes.insert(GetSoundEventHash("Weapon_AUG.ZoomOut"));
774-
soundEventHashes.insert(GetSoundEventHash("Weapon_SSG08.Zoom"));
775-
soundEventHashes.insert(GetSoundEventHash("Weapon_SSG08.ZoomOut"));
776-
soundEventHashes.insert(GetSoundEventHash("Weapon_SCAR20.Zoom"));
777-
soundEventHashes.insert(GetSoundEventHash("Weapon_SCAR20.ZoomOut"));
778-
soundEventHashes.insert(GetSoundEventHash("Weapon_G3SG1.Zoom"));
779-
soundEventHashes.insert(GetSoundEventHash("Weapon_G3SG1.ZoomOut"));
780-
soundEventHashes.insert(GetSoundEventHash("Weapon_AWP.Zoom"));
781-
soundEventHashes.insert(GetSoundEventHash("Weapon_AWP.ZoomOut"));
782-
soundEventHashes.insert(GetSoundEventHash("Weapon_Revolver.Prepare"));
783-
soundEventHashes.insert(GetSoundEventHash("Weapon.AutoSemiAutoSwitch")););
784-
785-
if (!soundEventHashes.contains(msg->soundevent_hash()))
786-
return;
787-
788-
uint64 stopSoundMask = g_playerManager->GetStopSoundMask();
789-
uint64 silenceSoundMask = g_playerManager->GetSilenceSoundMask();
790-
791-
if (!msg->has_source_entity_index())
792-
return;
793-
794-
CBaseEntity* pSourceEntity = (CBaseEntity*)g_pEntitySystem->GetEntityInstance(CEntityIndex(msg->source_entity_index()));
795-
int playerSlot = -1;
796-
797-
if (!pSourceEntity)
798-
return;
799-
800-
if (!V_strcasecmp(pSourceEntity->GetClassname(), "player"))
801-
{
802-
playerSlot = ((CCSPlayerPawn*)pSourceEntity)->GetController()->GetPlayerSlot();
803-
}
804-
else if (!V_strncasecmp(pSourceEntity->GetClassname(), "weapon_", 7))
764+
if (g_cvarEnableZR.Get())
765+
ZR_PostEventAbstract_SosStartSoundEvent(clients, msg);
766+
767+
if (g_cvarEnableStopSound.Get())
805768
{
806-
CCSPlayerPawn* pPawn = (CCSPlayerPawn*)pSourceEntity->m_hOwnerEntity().Get();
769+
static std::set<uint32> soundEventHashes;
770+
771+
ExecuteOnce(
772+
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.HitWall"));
773+
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.Slash"));
774+
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.Hit"));
775+
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.Stab"));
776+
soundEventHashes.insert(GetSoundEventHash("Weapon_sg556.ZoomIn"));
777+
soundEventHashes.insert(GetSoundEventHash("Weapon_sg556.ZoomOut"));
778+
soundEventHashes.insert(GetSoundEventHash("Weapon_AUG.ZoomIn"));
779+
soundEventHashes.insert(GetSoundEventHash("Weapon_AUG.ZoomOut"));
780+
soundEventHashes.insert(GetSoundEventHash("Weapon_SSG08.Zoom"));
781+
soundEventHashes.insert(GetSoundEventHash("Weapon_SSG08.ZoomOut"));
782+
soundEventHashes.insert(GetSoundEventHash("Weapon_SCAR20.Zoom"));
783+
soundEventHashes.insert(GetSoundEventHash("Weapon_SCAR20.ZoomOut"));
784+
soundEventHashes.insert(GetSoundEventHash("Weapon_G3SG1.Zoom"));
785+
soundEventHashes.insert(GetSoundEventHash("Weapon_G3SG1.ZoomOut"));
786+
soundEventHashes.insert(GetSoundEventHash("Weapon_AWP.Zoom"));
787+
soundEventHashes.insert(GetSoundEventHash("Weapon_AWP.ZoomOut"));
788+
soundEventHashes.insert(GetSoundEventHash("Weapon_Revolver.Prepare"));
789+
soundEventHashes.insert(GetSoundEventHash("Weapon.AutoSemiAutoSwitch")););
790+
791+
if (!soundEventHashes.contains(msg->soundevent_hash()))
792+
return;
793+
794+
uint64 stopSoundMask = g_playerManager->GetStopSoundMask();
795+
uint64 silenceSoundMask = g_playerManager->GetSilenceSoundMask();
796+
797+
if (!msg->has_source_entity_index())
798+
return;
799+
800+
CBaseEntity* pSourceEntity = (CBaseEntity*)g_pEntitySystem->GetEntityInstance(CEntityIndex(msg->source_entity_index()));
801+
int playerSlot = -1;
802+
803+
if (!pSourceEntity)
804+
return;
805+
806+
if (!V_strcasecmp(pSourceEntity->GetClassname(), "player"))
807+
{
808+
playerSlot = ((CCSPlayerPawn*)pSourceEntity)->GetController()->GetPlayerSlot();
809+
}
810+
else if (!V_strncasecmp(pSourceEntity->GetClassname(), "weapon_", 7))
811+
{
812+
CCSPlayerPawn* pPawn = (CCSPlayerPawn*)pSourceEntity->m_hOwnerEntity().Get();
807813

808-
if (pPawn && pPawn->IsPawn())
809-
playerSlot = pPawn->GetController()->GetPlayerSlot();
810-
}
814+
if (pPawn && pPawn->IsPawn())
815+
playerSlot = pPawn->GetController()->GetPlayerSlot();
816+
}
811817

812-
// Remove player who triggered this sound from masks
813-
// Because some of these sounds never get played locally (Zoom's, Knife Hit/Stab)
814-
if (playerSlot != -1 && g_playerManager->IsPlayerUsingStopSound(playerSlot))
815-
stopSoundMask &= ~((uint64)1 << playerSlot);
818+
// Remove player who triggered this sound from masks
819+
// Because some of these sounds never get played locally (Zoom's, Knife Hit/Stab)
820+
if (playerSlot != -1 && g_playerManager->IsPlayerUsingStopSound(playerSlot))
821+
stopSoundMask &= ~((uint64)1 << playerSlot);
816822

817-
if (playerSlot != -1 && g_playerManager->IsPlayerUsingSilenceSound(playerSlot))
818-
silenceSoundMask &= ~((uint64)1 << playerSlot);
823+
if (playerSlot != -1 && g_playerManager->IsPlayerUsingSilenceSound(playerSlot))
824+
silenceSoundMask &= ~((uint64)1 << playerSlot);
819825

820-
// Filter out people using stop/silence sound from hearing this sound from other players
821-
*(uint64*)clients &= ~stopSoundMask;
822-
*(uint64*)clients &= ~silenceSoundMask;
826+
// Filter out people using stop/silence sound from hearing this sound from other players
827+
*(uint64*)clients &= ~stopSoundMask;
828+
*(uint64*)clients &= ~silenceSoundMask;
829+
}
823830
}
824831
}
825832

src/cs2fixes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extern CCSGameRules* g_pGameRules;
5353
extern CSpawnGroupMgrGameSystem* g_pSpawnGroupMgr;
5454
extern double g_flUniversalTime;
5555
extern CGlobalVars* GetGlobals();
56+
extern uint32 GetSoundEventHash(const char* pszSoundEventName);
5657
extern CUtlVector<CServerSideClient*>* GetClientList();
5758
extern CServerSideClient* GetClientBySlot(CPlayerSlot slot);
5859
extern void FullUpdateAllClients();

src/playermanager.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,22 @@ void CPlayerManager::SetPlayerSilenceSound(int slot, bool set)
17721772
g_pUserPreferencesSystem->SetPreferenceInt(slot, SOUND_STATUS_PREF_KEY_NAME, iStopPreferenceStatus + iSilencePreferenceStatus);
17731773
}
17741774

1775+
void CPlayerManager::SetPlayerZSounds(int slot, bool set)
1776+
{
1777+
if (set)
1778+
m_nUsingZSounds |= ((uint64)1 << slot);
1779+
else
1780+
m_nUsingZSounds &= ~((uint64)1 << slot);
1781+
1782+
// Set the user prefs if the player is ingame
1783+
ZEPlayer* pPlayer = m_vecPlayers[slot];
1784+
if (!pPlayer) return;
1785+
1786+
uint64 iSlotMask = (uint64)1 << slot;
1787+
int iZSoundsPreferenceStatus = (m_nUsingZSounds & iSlotMask) ? 1 : 0;
1788+
g_pUserPreferencesSystem->SetPreferenceInt(slot, ZSOUNDS_PREF_KEY_NAME, iZSoundsPreferenceStatus);
1789+
}
1790+
17751791
void CPlayerManager::SetPlayerStopDecals(int slot, bool set)
17761792
{
17771793
if (set)
@@ -1808,6 +1824,7 @@ void CPlayerManager::ResetPlayerFlags(int slot)
18081824
{
18091825
SetPlayerStopSound(slot, true);
18101826
SetPlayerSilenceSound(slot, false);
1827+
SetPlayerZSounds(slot, true);
18111828
SetPlayerStopDecals(slot, true);
18121829
SetPlayerNoShake(slot, false);
18131830
}

src/playermanager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extern CConVar<CUtlString> g_cvarFlashLightAttachment;
5353
#define SOUND_STATUS_PREF_KEY_NAME "sound_status"
5454
#define NO_SHAKE_PREF_KEY_NAME "no_shake"
5555
#define BUTTON_WATCH_PREF_KEY_NAME "button_watch"
56+
#define ZSOUNDS_PREF_KEY_NAME "zsounds"
5657
#define INVALID_ZEPLAYERHANDLE_INDEX 0u
5758

5859
static uint32 iZEPlayerHandleSerial = 0u; // this should actually be 3 bytes large, but no way enough players join in servers lifespan for this to be an issue
@@ -398,6 +399,7 @@ class CPlayerManager
398399
V_memset(m_vecPlayers, 0, sizeof(m_vecPlayers));
399400
m_nUsingStopSound = -1; // On by default
400401
m_nUsingSilenceSound = 0;
402+
m_nUsingZSounds = -1; // On by default
401403
m_nUsingStopDecals = -1; // On by default
402404
m_nUsingNoShake = 0;
403405
}
@@ -425,18 +427,21 @@ class CPlayerManager
425427

426428
uint64 GetStopSoundMask() { return m_nUsingStopSound; }
427429
uint64 GetSilenceSoundMask() { return m_nUsingSilenceSound; }
430+
uint64 GetZSoundsMask() { return m_nUsingZSounds; }
428431
uint64 GetStopDecalsMask() { return m_nUsingStopDecals; }
429432
uint64 GetNoShakeMask() { return m_nUsingNoShake; }
430433

431434
void SetPlayerStopSound(int slot, bool set);
432435
void SetPlayerSilenceSound(int slot, bool set);
436+
void SetPlayerZSounds(int slot, bool set);
433437
void SetPlayerStopDecals(int slot, bool set);
434438
void SetPlayerNoShake(int slot, bool set);
435439

436440
void ResetPlayerFlags(int slot);
437441

438442
bool IsPlayerUsingStopSound(int slot) { return m_nUsingStopSound & ((uint64)1 << slot); }
439443
bool IsPlayerUsingSilenceSound(int slot) { return m_nUsingSilenceSound & ((uint64)1 << slot); }
444+
bool IsPlayerUsingZSounds(int slot) { return m_nUsingZSounds & ((uint64)1 << slot); }
440445
bool IsPlayerUsingStopDecals(int slot) { return m_nUsingStopDecals & ((uint64)1 << slot); }
441446
bool IsPlayerUsingNoShake(int slot) { return m_nUsingNoShake & ((uint64)1 << slot); }
442447

@@ -450,6 +455,7 @@ class CPlayerManager
450455

451456
uint64 m_nUsingStopSound;
452457
uint64 m_nUsingSilenceSound;
458+
uint64 m_nUsingZSounds;
453459
uint64 m_nUsingStopDecals;
454460
uint64 m_nUsingNoShake;
455461
};

src/user_preferences.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ void CUserPreferencesSystem::OnPutPreferences(int iSlot)
112112
bool bHideDecals = (bool)GetPreferenceInt(iSlot, DECAL_PREF_KEY_NAME, 1);
113113
bool bNoShake = (bool)GetPreferenceInt(iSlot, NO_SHAKE_PREF_KEY_NAME, 0);
114114
int iButtonWatchMode = GetPreferenceInt(iSlot, BUTTON_WATCH_PREF_KEY_NAME, 0);
115+
bool bZSounds = (bool)GetPreferenceInt(iSlot, ZSOUNDS_PREF_KEY_NAME, 1);
115116

116117
// EntWatch
117118
int iEntwatchMode = GetPreferenceInt(iSlot, EW_PREF_HUD_MODE, 0);
@@ -125,6 +126,7 @@ void CUserPreferencesSystem::OnPutPreferences(int iSlot)
125126
// Set the values that we just loaded --- the player is guaranteed available
126127
g_playerManager->SetPlayerStopSound(iSlot, bStopSound);
127128
g_playerManager->SetPlayerSilenceSound(iSlot, bSilenceSound);
129+
g_playerManager->SetPlayerZSounds(iSlot, bZSounds);
128130
g_playerManager->SetPlayerStopDecals(iSlot, bHideDecals);
129131
g_playerManager->SetPlayerNoShake(iSlot, bNoShake);
130132

src/zombiereborn.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,37 @@ void ZR_EndRoundAndAddTeamScore(int iTeamNum)
17501750
}
17511751
}
17521752

1753+
void ZR_PostEventAbstract_SosStartSoundEvent(const uint64* pClients, CNetMessagePB<CMsgSosStartSoundEvent>* pMsg)
1754+
{
1755+
static std::set<uint32> soundEventHashes;
1756+
1757+
ExecuteOnce(
1758+
soundEventHashes.insert(GetSoundEventHash("zr.amb.scream"));
1759+
soundEventHashes.insert(GetSoundEventHash("zr.amb.zombie_die"));
1760+
soundEventHashes.insert(GetSoundEventHash("zr.amb.zombie_pain"));
1761+
soundEventHashes.insert(GetSoundEventHash("zr.amb.zombie_voice_idle")););
1762+
1763+
// Filter out people with zsounds disabled from hearing this sound
1764+
if (soundEventHashes.contains(pMsg->soundevent_hash()))
1765+
*(uint64*)pClients &= g_playerManager->GetZSoundsMask();
1766+
}
1767+
1768+
CON_COMMAND_CHAT(zsounds, "- Toggle zombie sounds")
1769+
{
1770+
if (!player)
1771+
{
1772+
ClientPrint(player, HUD_PRINTCONSOLE, ZR_PREFIX "You cannot use this command from the server console.");
1773+
return;
1774+
}
1775+
1776+
int iPlayer = player->GetPlayerSlot();
1777+
bool bSet = !g_playerManager->IsPlayerUsingZSounds(iPlayer);
1778+
1779+
g_playerManager->SetPlayerZSounds(iPlayer, bSet);
1780+
1781+
ClientPrint(player, HUD_PRINTTALK, ZR_PREFIX "You have %s zombie sounds.", bSet ? "enabled" : "disabled");
1782+
}
1783+
17531784
CON_COMMAND_CHAT(ztele, "- Teleport to spawn")
17541785
{
17551786
// Silently return so the command is completely hidden

src/zombiereborn.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "entity/ccsplayerpawn.h"
2525
#include "eventlistener.h"
2626
#include "gamesystem.h"
27+
#include "gameevents.pb.h"
2728
#include "vendor/nlohmann/json_fwd.hpp"
2829

2930
using ordered_json = nlohmann::ordered_json;
@@ -276,4 +277,5 @@ void ZR_Detour_CEntityIdentity_AcceptInput(CEntityIdentity* pThis, CUtlSymbolLar
276277
void ZR_Hook_ClientPutInServer(CPlayerSlot slot, char const* pszName, int type, uint64 xuid);
277278
void ZR_Hook_ClientCommand_JoinTeam(CPlayerSlot slot, const CCommand& args);
278279
void ZR_Precache(IEntityResourceManifest* pResourceManifest);
279-
bool ZR_CheckTeamWinConditions(int iTeamNum);
280+
bool ZR_CheckTeamWinConditions(int iTeamNum);
281+
void ZR_PostEventAbstract_SosStartSoundEvent(const uint64* pClients, CNetMessagePB<CMsgSosStartSoundEvent>* pMsg);

0 commit comments

Comments
 (0)