From a386ef41ea887d560d0458d3f6ec5a721ee62050 Mon Sep 17 00:00:00 2001 From: Vaqtincha <51029683+Vaqtincha@users.noreply.github.com> Date: Sun, 22 Sep 2019 19:39:06 +0500 Subject: [PATCH] Invisible shield fix (#422) * add constants for entvar "gamestate" magic number * invisible shield (https://github.com/s1lentq/ReGameDLL_CS/projects/1#card-26566008) --- regamedll/dlls/player.cpp | 19 +++++++++++++------ regamedll/dlls/player.h | 4 ++++ regamedll/dlls/wpn_shared/wpn_c4.cpp | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index c77f72f7..d2d427c6 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -2031,7 +2031,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib) pev->movetype = MOVETYPE_TOSS; pev->takedamage = DAMAGE_NO; - pev->gamestate = 1; + pev->gamestate = HITGROUP_SHIELD_DISABLED; m_bShieldDrawn = false; pev->flags &= ~FL_ONGROUND; @@ -2997,6 +2997,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveShield)(bool bDeploy) m_bOwnsShield = true; m_bHasPrimary = true; +#ifdef REGAMEDLL_FIXES + pev->gamestate = HITGROUP_SHIELD_ENABLED; +#endif + if (m_pActiveItem) { CBasePlayerWeapon *pWeapon = static_cast(m_pActiveItem); @@ -3011,7 +3015,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveShield)(bool bDeploy) } } - pev->gamestate = 0; +#ifndef REGAMEDLL_FIXES + // NOTE: Moved above, because CC4::Deploy can reset hitbox of shield + pev->gamestate = HITGROUP_SHIELD_ENABLED; +#endif } void CBasePlayer::RemoveShield() @@ -3021,7 +3028,7 @@ void CBasePlayer::RemoveShield() m_bOwnsShield = false; m_bHasPrimary = false; m_bShieldDrawn = false; - pev->gamestate = 1; + pev->gamestate = HITGROUP_SHIELD_DISABLED; UpdateShieldCrosshair(true); } @@ -5210,9 +5217,9 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Spawn)() m_pentCurBombTarget = nullptr; if (m_bOwnsShield) - pev->gamestate = 0; + pev->gamestate = HITGROUP_SHIELD_ENABLED; else - pev->gamestate = 1; + pev->gamestate = HITGROUP_SHIELD_DISABLED; ResetStamina(); pev->friction = 1; @@ -6501,7 +6508,7 @@ BOOL EXT_FUNC CBasePlayer::__API_HOOK(AddPlayerItem)(CBasePlayerItem *pItem) m_rgpPlayerItems[pItem->iItemSlot()] = pItem; if (HasShield()) - pev->gamestate = 0; + pev->gamestate = HITGROUP_SHIELD_ENABLED; // should we switch to this item? if (g_pGameRules->FShouldSwitchWeapon(this, pItem)) diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index 8624511d..e6a4576c 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -112,6 +112,10 @@ const int MONEY_BLINK_AMOUNT = 30; #define PFLAG_USING BIT(4) // Using a continuous entity #define PFLAG_OBSERVER BIT(5) // Player is locked in stationary cam mode. Spectators can move, observers can't. +// Player gamestate flags +#define HITGROUP_SHIELD_ENABLED 0 +#define HITGROUP_SHIELD_DISABLED 1 + #define TRAIN_OFF 0x00 #define TRAIN_NEUTRAL 0x01 #define TRAIN_SLOW 0x02 diff --git a/regamedll/dlls/wpn_shared/wpn_c4.cpp b/regamedll/dlls/wpn_shared/wpn_c4.cpp index 0b960e25..e1a0c0a0 100644 --- a/regamedll/dlls/wpn_shared/wpn_c4.cpp +++ b/regamedll/dlls/wpn_shared/wpn_c4.cpp @@ -67,7 +67,7 @@ BOOL CC4::Deploy() if (m_pPlayer->HasShield()) { m_bHasShield = true; - m_pPlayer->pev->gamestate = 1; + m_pPlayer->pev->gamestate = HITGROUP_SHIELD_DISABLED; } return DefaultDeploy("models/v_c4.mdl", "models/p_c4.mdl", C4_DRAW, "c4", UseDecrement() != FALSE); @@ -94,7 +94,7 @@ void CC4::Holster(int skiplocal) if (m_bHasShield) { - m_pPlayer->pev->gamestate = 0; + m_pPlayer->pev->gamestate = HITGROUP_SHIELD_ENABLED; m_bHasShield = false; } }