diff --git a/src/playermanager.cpp b/src/playermanager.cpp index 4bd47367..2cbc3584 100644 --- a/src/playermanager.cpp +++ b/src/playermanager.cpp @@ -36,6 +36,7 @@ #include "utils/entity.h" #include "utlstring.h" #include "votemanager.h" +#include "zombiereborn.h" #include <../cs2fixes.h> #include "tier0/memdbgon.h" @@ -1775,22 +1776,43 @@ void CPlayerManager::SetPlayerSilenceSound(int slot, bool set) g_pUserPreferencesSystem->SetPreferenceInt(slot, SOUND_STATUS_PREF_KEY_NAME, iStopPreferenceStatus + iSilencePreferenceStatus); } -void CPlayerManager::SetPlayerZSounds(int slot, bool set) +void CPlayerManager::SetPlayerZSounds(int slot, EZSoundsType mode) { - if (set) - m_nUsingZSounds |= ((uint64)1 << slot); - else - m_nUsingZSounds &= ~((uint64)1 << slot); + switch (mode) + { + case EZSoundsType::ON: + m_nUsingZSounds |= ((uint64)1 << slot); + m_nUsingZSoundsInfect |= ((uint64)1 << slot); + break; + case EZSoundsType::INFECT_ONLY: + m_nUsingZSounds &= ~((uint64)1 << slot); + m_nUsingZSoundsInfect |= ((uint64)1 << slot); + break; + case EZSoundsType::OFF: + m_nUsingZSounds &= ~((uint64)1 << slot); + m_nUsingZSoundsInfect &= ~((uint64)1 << slot); + break; + } // Set the user prefs if the player is ingame ZEPlayer* pPlayer = m_vecPlayers[slot]; if (!pPlayer) return; - uint64 iSlotMask = (uint64)1 << slot; - int iZSoundsPreferenceStatus = (m_nUsingZSounds & iSlotMask) ? 1 : 0; + int iZSoundsPreferenceStatus = (int)mode; g_pUserPreferencesSystem->SetPreferenceInt(slot, ZSOUNDS_PREF_KEY_NAME, iZSoundsPreferenceStatus); } +EZSoundsType CPlayerManager::GetPlayerZSoundsMode(int slot) +{ + if (m_nUsingZSounds & ((uint64)1 << slot)) + return EZSoundsType::ON; + + if (m_nUsingZSoundsInfect & ((uint64)1 << slot)) + return EZSoundsType::INFECT_ONLY; + + return EZSoundsType::OFF; +} + void CPlayerManager::SetPlayerStopDecals(int slot, bool set) { if (set) @@ -1827,7 +1849,7 @@ void CPlayerManager::ResetPlayerFlags(int slot) { SetPlayerStopSound(slot, true); SetPlayerSilenceSound(slot, false); - SetPlayerZSounds(slot, true); + SetPlayerZSounds(slot, EZSoundsType::ON); SetPlayerStopDecals(slot, true); SetPlayerNoShake(slot, false); } diff --git a/src/playermanager.h b/src/playermanager.h index 458a21a0..757b9589 100644 --- a/src/playermanager.h +++ b/src/playermanager.h @@ -110,6 +110,7 @@ enum class ETargetError class ZEPlayer; struct ZRClass; struct ZRModelEntry; +enum class EZSoundsType; class ZEPlayerHandle { @@ -404,6 +405,7 @@ class CPlayerManager m_nUsingStopSound = -1; // On by default m_nUsingSilenceSound = 0; m_nUsingZSounds = -1; // On by default + m_nUsingZSoundsInfect = -1; // On by default m_nUsingStopDecals = -1; // On by default m_nUsingNoShake = 0; } @@ -432,12 +434,13 @@ class CPlayerManager uint64 GetStopSoundMask() { return m_nUsingStopSound; } uint64 GetSilenceSoundMask() { return m_nUsingSilenceSound; } uint64 GetZSoundsMask() { return m_nUsingZSounds; } + uint64 GetZSoundsInfectMask() { return m_nUsingZSoundsInfect; } uint64 GetStopDecalsMask() { return m_nUsingStopDecals; } uint64 GetNoShakeMask() { return m_nUsingNoShake; } void SetPlayerStopSound(int slot, bool set); void SetPlayerSilenceSound(int slot, bool set); - void SetPlayerZSounds(int slot, bool set); + void SetPlayerZSounds(int slot, EZSoundsType mode); void SetPlayerStopDecals(int slot, bool set); void SetPlayerNoShake(int slot, bool set); @@ -445,7 +448,7 @@ class CPlayerManager bool IsPlayerUsingStopSound(int slot) { return m_nUsingStopSound & ((uint64)1 << slot); } bool IsPlayerUsingSilenceSound(int slot) { return m_nUsingSilenceSound & ((uint64)1 << slot); } - bool IsPlayerUsingZSounds(int slot) { return m_nUsingZSounds & ((uint64)1 << slot); } + EZSoundsType GetPlayerZSoundsMode(int slot); bool IsPlayerUsingStopDecals(int slot) { return m_nUsingStopDecals & ((uint64)1 << slot); } bool IsPlayerUsingNoShake(int slot) { return m_nUsingNoShake & ((uint64)1 << slot); } @@ -461,6 +464,7 @@ class CPlayerManager uint64 m_nUsingStopSound; uint64 m_nUsingSilenceSound; uint64 m_nUsingZSounds; + uint64 m_nUsingZSoundsInfect; uint64 m_nUsingStopDecals; uint64 m_nUsingNoShake; }; diff --git a/src/user_preferences.cpp b/src/user_preferences.cpp index 04f251e7..27f41e47 100644 --- a/src/user_preferences.cpp +++ b/src/user_preferences.cpp @@ -24,6 +24,7 @@ #include "httpmanager.h" #include "playermanager.h" #include "strtools.h" +#include "zombiereborn.h" #include #undef snprintf #include "vendor/nlohmann/json.hpp" @@ -112,7 +113,7 @@ void CUserPreferencesSystem::OnPutPreferences(int iSlot) bool bHideDecals = (bool)GetPreferenceInt(iSlot, DECAL_PREF_KEY_NAME, 1); bool bNoShake = (bool)GetPreferenceInt(iSlot, NO_SHAKE_PREF_KEY_NAME, 0); int iButtonWatchMode = GetPreferenceInt(iSlot, BUTTON_WATCH_PREF_KEY_NAME, 0); - bool bZSounds = (bool)GetPreferenceInt(iSlot, ZSOUNDS_PREF_KEY_NAME, 1); + int iZSounds = GetPreferenceInt(iSlot, ZSOUNDS_PREF_KEY_NAME, (int)EZSoundsType::ON); // EntWatch int iEntwatchMode = GetPreferenceInt(iSlot, EW_PREF_HUD_MODE, 0); @@ -125,7 +126,7 @@ void CUserPreferencesSystem::OnPutPreferences(int iSlot) // Set the values that we just loaded --- the player is guaranteed available g_playerManager->SetPlayerStopSound(iSlot, bStopSound); g_playerManager->SetPlayerSilenceSound(iSlot, bSilenceSound); - g_playerManager->SetPlayerZSounds(iSlot, bZSounds); + g_playerManager->SetPlayerZSounds(iSlot, (EZSoundsType)iZSounds); g_playerManager->SetPlayerStopDecals(iSlot, bHideDecals); g_playerManager->SetPlayerNoShake(iSlot, bNoShake); diff --git a/src/zombiereborn.cpp b/src/zombiereborn.cpp index 00de8278..be60f539 100644 --- a/src/zombiereborn.cpp +++ b/src/zombiereborn.cpp @@ -1800,16 +1800,19 @@ void ZR_FinishRound(int iTeamNum) void ZR_PostEventAbstract_SosStartSoundEvent(const uint64* pClients, CNetMessagePB* pMsg) { + static uint32 screamHash; static std::set soundEventHashes; ExecuteOnce( - soundEventHashes.insert(GetSoundEventHash("zr.amb.scream")); + screamHash = GetSoundEventHash("zr.amb.scream"); soundEventHashes.insert(GetSoundEventHash("zr.amb.zombie_die")); soundEventHashes.insert(GetSoundEventHash("zr.amb.zombie_pain")); soundEventHashes.insert(GetSoundEventHash("zr.amb.zombie_voice_idle"));); // Filter out people with zsounds disabled from hearing this sound - if (soundEventHashes.contains(pMsg->soundevent_hash())) + if (pMsg->soundevent_hash() == screamHash) + *(uint64*)pClients &= g_playerManager->GetZSoundsInfectMask(); + else if (soundEventHashes.contains(pMsg->soundevent_hash())) *(uint64*)pClients &= g_playerManager->GetZSoundsMask(); } @@ -1822,11 +1825,25 @@ CON_COMMAND_CHAT(zsounds, "- Toggle zombie sounds") } int iPlayer = player->GetPlayerSlot(); - bool bSet = !g_playerManager->IsPlayerUsingZSounds(iPlayer); + EZSoundsType state = g_playerManager->GetPlayerZSoundsMode(iPlayer); - g_playerManager->SetPlayerZSounds(iPlayer, bSet); + if (state == EZSoundsType::ON) + { + state = EZSoundsType::INFECT_ONLY; + ClientPrint(player, HUD_PRINTTALK, ZR_PREFIX "Zombie sounds\x04 enabled\x10 (Infect sounds only)."); + } + else if (state == EZSoundsType::INFECT_ONLY) + { + state = EZSoundsType::OFF; + ClientPrint(player, HUD_PRINTTALK, ZR_PREFIX "Zombie sounds\x07 disabled."); + } + else if (state == EZSoundsType::OFF) + { + state = EZSoundsType::ON; + ClientPrint(player, HUD_PRINTTALK, ZR_PREFIX "Zombie sounds\x04 enabled."); + } - ClientPrint(player, HUD_PRINTTALK, ZR_PREFIX "You have %s zombie sounds.", bSet ? "enabled" : "disabled"); + g_playerManager->SetPlayerZSounds(iPlayer, state); } CON_COMMAND_CHAT(ztele, "- Teleport to spawn") diff --git a/src/zombiereborn.h b/src/zombiereborn.h index 8a548dfc..c42eadb0 100644 --- a/src/zombiereborn.h +++ b/src/zombiereborn.h @@ -50,6 +50,13 @@ enum EZRSpawnType RESPAWN, }; +enum class EZSoundsType +{ + OFF, // No zombie sounds heard + ON, // All zombie sounds heard + INFECT_ONLY, // Only the infect scream heard +}; + // model entries in zr classes struct ZRModelEntry {