Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions src/playermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "utils/entity.h"
#include "utlstring.h"
#include "votemanager.h"
#include "zombiereborn.h"
#include <../cs2fixes.h>

#include "tier0/memdbgon.h"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 6 additions & 2 deletions src/playermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ enum class ETargetError
class ZEPlayer;
struct ZRClass;
struct ZRModelEntry;
enum class EZSoundsType;

class ZEPlayerHandle
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -432,20 +434,21 @@ 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);

void ResetPlayerFlags(int slot);

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); }

Expand All @@ -461,6 +464,7 @@ class CPlayerManager
uint64 m_nUsingStopSound;
uint64 m_nUsingSilenceSound;
uint64 m_nUsingZSounds;
uint64 m_nUsingZSoundsInfect;
uint64 m_nUsingStopDecals;
uint64 m_nUsingNoShake;
};
Expand Down
5 changes: 3 additions & 2 deletions src/user_preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "httpmanager.h"
#include "playermanager.h"
#include "strtools.h"
#include "zombiereborn.h"
#include <string>
#undef snprintf
#include "vendor/nlohmann/json.hpp"
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
27 changes: 22 additions & 5 deletions src/zombiereborn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,16 +1800,19 @@ void ZR_FinishRound(int iTeamNum)

void ZR_PostEventAbstract_SosStartSoundEvent(const uint64* pClients, CNetMessagePB<CMsgSosStartSoundEvent>* pMsg)
{
static uint32 screamHash;
static std::set<uint32> 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();
}

Expand All @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions src/zombiereborn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading