From 3b2fa899261f3216b75e0ed7c1a02438edf1fd71 Mon Sep 17 00:00:00 2001 From: rtldg <55846624+rtldg@users.noreply.github.com> Date: Thu, 24 Jun 2021 21:32:47 +0000 Subject: [PATCH] sdktools: Clean non-ingame clients from NormalSHook (#1450) --- extensions/sdktools/vsound.cpp | 52 +++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/extensions/sdktools/vsound.cpp b/extensions/sdktools/vsound.cpp index eb58020b..375573ef 100644 --- a/extensions/sdktools/vsound.cpp +++ b/extensions/sdktools/vsound.cpp @@ -388,6 +388,17 @@ void SoundHooks::OnEmitSound(IRecipientFilter &filter, int iEntIndex, int iChann } case Pl_Changed: { + if (size < 0 || size > SM_ARRAYSIZE(players)) + { + pFunc->GetParentContext()->BlamePluginError(pFunc, "Callback-provided size %d is invalid", size); + +#if SOURCE_ENGINE >= SE_PORTAL2 + RETURN_META_VALUE(MRES_IGNORED, -1); +#else + return; +#endif + } + /* Client validation */ for (int i = 0; i < size; i++) { @@ -397,17 +408,18 @@ void SoundHooks::OnEmitSound(IRecipientFilter &filter, int iEntIndex, int iChann if (!pPlayer) { pFunc->GetParentContext()->BlamePluginError(pFunc, "Callback-provided client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - pFunc->GetParentContext()->BlamePluginError(pFunc, "Client %d is not in game", client); - } else { - continue; - } #if SOURCE_ENGINE >= SE_PORTAL2 - RETURN_META_VALUE(MRES_IGNORED, -1 ); + RETURN_META_VALUE(MRES_IGNORED, -1); #else - return; + return; #endif + } else if (!pPlayer->IsInGame()) { + // Shift array down to remove non-ingame client + memmove(&players[i], &players[i+1], (size-i-1) * sizeof(int)); + --i; + --size; + } } #if SOURCE_ENGINE >= SE_PORTAL2 @@ -540,6 +552,17 @@ void SoundHooks::OnEmitSound2(IRecipientFilter &filter, int iEntIndex, int iChan } case Pl_Changed: { + if (size < 0 || size > SM_ARRAYSIZE(players)) + { + pFunc->GetParentContext()->BlamePluginError(pFunc, "Callback-provided size %d is invalid", size); + +#if SOURCE_ENGINE >= SE_PORTAL2 + RETURN_META_VALUE(MRES_IGNORED, -1); +#else + return; +#endif + } + /* Client validation */ for (int i = 0; i < size; i++) { @@ -549,17 +572,18 @@ void SoundHooks::OnEmitSound2(IRecipientFilter &filter, int iEntIndex, int iChan if (!pPlayer) { pFunc->GetParentContext()->BlamePluginError(pFunc, "Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - pFunc->GetParentContext()->BlamePluginError(pFunc, "Client %d is not in game", client); - } else { - continue; - } #if SOURCE_ENGINE >= SE_PORTAL2 - RETURN_META_VALUE(MRES_IGNORED, -1 ); + RETURN_META_VALUE(MRES_IGNORED, -1); #else - return; + return; #endif + } else if (!pPlayer->IsInGame()) { + // Shift array down to remove non-ingame client + memmove(&players[i], &players[i+1], (size-i-1) * sizeof(int)); + --i; + --size; + } } #if SOURCE_ENGINE >= SE_PORTAL2