From e7d7de870a3841783d2e670cce8ac88baae0e87f Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 18 Aug 2014 22:02:08 +0200 Subject: [PATCH 1/2] Block weapon pickup sound if shield is disallowed in CS_OnBuy forward. --- dlls/cstrike/cstrike/CstrikeHacks.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index 4094d4e4..0bc4ec54 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -36,6 +36,8 @@ CDetour *AddAccountDetour = NULL; int CurrentItemId = 0; StringHashMap ItemAliasList; +extern enginefuncs_t *g_pengfuncsTable; + void InitializeHacks() { #if defined AMD64 @@ -69,6 +71,21 @@ const char *CMD_ARGV(int i) return g_engfuncs.pfnCmd_Argv(i); } +void OnEmitSound(edict_t *entity, int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch) +{ + // If shield is blocked with CS_OnBuy, we need to block the pickup sound as well played right after. + // Why this sound is not contained in GiveShield()? + + g_pengfuncsTable->pfnEmitSound = NULL; + + if (CurrentItemId == 0 && strcmp(sample, "items/gunpickup2.wav") == 0) // Safety checks. + { + RETURN_META(MRES_SUPERCEDE); + } + + RETURN_META(MRES_IGNORED); +} + DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientCommand(edict_t *pEntity) { const char *command = CMD_ARGV(0); @@ -213,6 +230,12 @@ DETOUR_DECL_MEMBER2(AddAccount, void, int, amount, bool, bTrackChange) // void C { DETOUR_MEMBER_CALL(AddAccount)(amount, bTrackChange); } + // Shield is blocked. + // We need to hook EmitSound to block pickup sound played right after. + else if (CurrentItemId == CSI_SHIELDGUN) + { + g_pengfuncsTable->pfnEmitSound = OnEmitSound; + } // Let's reset this right away to avoid issues. CurrentItemId = 0; From 9cd90838e1bd74984731a17c2045cf9f006a189c Mon Sep 17 00:00:00 2001 From: Arkshine Date: Tue, 19 Aug 2014 09:04:09 +0200 Subject: [PATCH 2/2] Remove safety checks as it's not really necessary. --- dlls/cstrike/cstrike/CstrikeHacks.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index 0bc4ec54..a631effd 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -73,17 +73,12 @@ const char *CMD_ARGV(int i) void OnEmitSound(edict_t *entity, int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch) { - // If shield is blocked with CS_OnBuy, we need to block the pickup sound as well played right after. - // Why this sound is not contained in GiveShield()? + // If shield is blocked with CS_OnBuy, we need to block the pickup sound ("items/gunpickup2.wav") + // as well played right after. Why this sound is not contained in GiveShield()? g_pengfuncsTable->pfnEmitSound = NULL; - if (CurrentItemId == 0 && strcmp(sample, "items/gunpickup2.wav") == 0) // Safety checks. - { - RETURN_META(MRES_SUPERCEDE); - } - - RETURN_META(MRES_IGNORED); + RETURN_META(MRES_SUPERCEDE); } DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientCommand(edict_t *pEntity)