Merge pull request #124 from Arkshine/fix-sound-onbuy

Block weapon pickup sound if shield is disallowed in CS_OnBuy forward.
This commit is contained in:
Vincent Herbet 2014-08-19 19:27:36 +02:00
commit 9e0f946696

View File

@ -36,6 +36,8 @@ CDetour *AddAccountDetour = NULL;
int CurrentItemId = 0; int CurrentItemId = 0;
StringHashMap<int> ItemAliasList; StringHashMap<int> ItemAliasList;
extern enginefuncs_t *g_pengfuncsTable;
void InitializeHacks() void InitializeHacks()
{ {
#if defined AMD64 #if defined AMD64
@ -69,6 +71,16 @@ const char *CMD_ARGV(int i)
return g_engfuncs.pfnCmd_Argv(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 ("items/gunpickup2.wav")
// as well played right after. Why this sound is not contained in GiveShield()?
g_pengfuncsTable->pfnEmitSound = NULL;
RETURN_META(MRES_SUPERCEDE);
}
DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientCommand(edict_t *pEntity) DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientCommand(edict_t *pEntity)
{ {
const char *command = CMD_ARGV(0); const char *command = CMD_ARGV(0);
@ -213,6 +225,12 @@ DETOUR_DECL_MEMBER2(AddAccount, void, int, amount, bool, bTrackChange) // void C
{ {
DETOUR_MEMBER_CALL(AddAccount)(amount, bTrackChange); 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. // Let's reset this right away to avoid issues.
CurrentItemId = 0; CurrentItemId = 0;