From 8b1be212bff47463844ac8c57540d5d2e3444e32 Mon Sep 17 00:00:00 2001 From: In-line Date: Sat, 19 Aug 2017 19:01:33 +0400 Subject: [PATCH] Fix some of C4 related bugs. (#179) - Cancel C4 planting bartime on weapon change - Infinite round, when bomb exploded underwater - C4 explode after defuse - Moving while defusing and silent defuse (partially) - Silent defuse --- regamedll/dlls/ggrenade.cpp | 19 ++++++++++++++++++- regamedll/dlls/weapons.cpp | 6 +++++- regamedll/dlls/wpn_shared/wpn_c4.cpp | 8 ++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/regamedll/dlls/ggrenade.cpp b/regamedll/dlls/ggrenade.cpp index 3a981835..761eab0f 100644 --- a/regamedll/dlls/ggrenade.cpp +++ b/regamedll/dlls/ggrenade.cpp @@ -983,7 +983,9 @@ void CGrenade::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useTy // TODO show messages on clients on event ClientPrint(player->pev, HUD_PRINTCENTER, "#Defusing_Bomb_With_Defuse_Kit"); +#ifndef REGAMEDLL_FIXES EMIT_SOUND(ENT(player->pev), CHAN_ITEM, "weapons/c4_disarm.wav", VOL_NORM, ATTN_NORM); +#endif player->m_bIsDefusing = true; m_pBombDefuser = pActivator; @@ -1003,7 +1005,9 @@ void CGrenade::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useTy // TODO: show messages on clients on event ClientPrint(player->pev, HUD_PRINTCENTER, "#Defusing_Bomb_Without_Defuse_Kit"); +#ifndef REGAMEDLL_FIXES EMIT_SOUND(ENT(player->pev), CHAN_ITEM, "weapons/c4_disarm.wav", VOL_NORM, ATTN_NORM); +#endif player->m_bIsDefusing = true; m_pBombDefuser = pActivator; @@ -1014,6 +1018,10 @@ void CGrenade::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useTy // start the progress bar player->SetProgressBarTime(10); } + +#ifdef REGAMEDLL_FIXES + EMIT_SOUND(edict(), CHAN_ITEM, "weapons/c4_disarm.wav", VOL_NORM, ATTN_NORM); // Emit sound using bomb. +#endif } CGrenade *CGrenade::ShootSatchelCharge(entvars_t *pevOwner, Vector vecStart, Vector vecAngles) @@ -1201,7 +1209,11 @@ void CGrenade::C4Think() } // If the timer has expired ! blow this bomb up! +#ifdef REGAMEDLL_FIXES + if(gpGlobals->time >= m_flC4Blow && (!(m_bStartDefuse && m_pBombDefuser) || gpGlobals->time < m_flDefuseCountDown)) // Prevent exploding after defusing. +#else if (gpGlobals->time >= m_flC4Blow) +#endif { if (TheBots) { @@ -1232,10 +1244,15 @@ void CGrenade::C4Think() g_pGameRules->m_bBombDropped = FALSE; +#ifndef REGAMEDLL_FIXES if (pev->waterlevel != 0) - UTIL_Remove(this); + UTIL_Remove(this); // Causes infinite round else +#endif + { SetThink(&CGrenade::Detonate2); + } + } // if the defusing process has started diff --git a/regamedll/dlls/weapons.cpp b/regamedll/dlls/weapons.cpp index 568372a0..85fd9177 100644 --- a/regamedll/dlls/weapons.cpp +++ b/regamedll/dlls/weapons.cpp @@ -960,7 +960,11 @@ void CBasePlayerWeapon::ItemPostFrame() m_fInReload = FALSE; } - if ((usableButtons & IN_ATTACK2) && CanAttack(m_flNextSecondaryAttack, UTIL_WeaponTimeBase(), UseDecrement())) + if ((usableButtons & IN_ATTACK2) && CanAttack(m_flNextSecondaryAttack, UTIL_WeaponTimeBase(), UseDecrement()) +#ifdef REGAMEDLL_FIXES + && !m_pPlayer->m_bIsDefusing // In-line: I think it's fine to block secondary attack, when defusing. It's better then blocking speed resets in weapons. +#endif + ) { if (pszAmmo2() && !m_pPlayer->m_rgAmmo[SecondaryAmmoIndex()]) { diff --git a/regamedll/dlls/wpn_shared/wpn_c4.cpp b/regamedll/dlls/wpn_shared/wpn_c4.cpp index 985403fe..f930cf55 100644 --- a/regamedll/dlls/wpn_shared/wpn_c4.cpp +++ b/regamedll/dlls/wpn_shared/wpn_c4.cpp @@ -72,6 +72,14 @@ BOOL CC4::Deploy() void CC4::Holster(int skiplocal) { m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f; + +#ifdef REGAMEDLL_FIXES + if(m_bStartedArming) + { + m_pPlayer->SetProgressBarTime(0); + } +#endif + m_bStartedArming = false; // stop arming sequence if (!m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])