From b83d221ec4a0a151d0c278552608099b2c8c48b1 Mon Sep 17 00:00:00 2001 From: Vaqtincha <51029683+Vaqtincha@users.noreply.github.com> Date: Tue, 17 Sep 2019 17:06:21 +0500 Subject: [PATCH] Fixes (attempt 999) (#413) * Fix func_healthcharger & func_recharge bug * active weapon check * fix entity leak * item_airbox: little optimizations * Use IsPlayer check instead of FClassnameIs --- regamedll/dlls/addons/item_airbox.cpp | 12 +++++++++++- regamedll/dlls/func_break.cpp | 14 +++++++++++++- regamedll/dlls/func_tank.cpp | 7 ++++++- regamedll/dlls/h_battery.cpp | 28 +++++++++++++++++---------- regamedll/dlls/healthkit.cpp | 6 +++++- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/regamedll/dlls/addons/item_airbox.cpp b/regamedll/dlls/addons/item_airbox.cpp index c342899c..a3637ea9 100644 --- a/regamedll/dlls/addons/item_airbox.cpp +++ b/regamedll/dlls/addons/item_airbox.cpp @@ -57,8 +57,12 @@ void CItemAirBox::Touch(CBaseEntity *pOther) CArmoury::Touch(pOther); // airbox was picked up, so sprite to turn off - if ((pev->effects & EF_NODRAW) == EF_NODRAW) { + if ((pev->effects & EF_NODRAW) == EF_NODRAW) + { m_hSprite->TurnOff(); + + pev->nextthink = 0; + SetThink(nullptr); } } @@ -66,6 +70,12 @@ void CItemAirBox::Restart() { CArmoury::Restart(); UTIL_SetOrigin(pev, pev->oldorigin); + + if (m_flyup > 0 && m_delay > 0.01f) + { + SetThink(&CItemAirBox::MoveUp); + pev->nextthink = gpGlobals->time + 0.1f; + } } void CItemAirBox::Precache() diff --git a/regamedll/dlls/func_break.cpp b/regamedll/dlls/func_break.cpp index 60093d88..5cc9cd40 100644 --- a/regamedll/dlls/func_break.cpp +++ b/regamedll/dlls/func_break.cpp @@ -817,7 +817,19 @@ void CBreakable::Die() if (m_iszSpawnObject) { - CBaseEntity::Create((char *)STRING(m_iszSpawnObject), VecBModelOrigin(pev), pev->angles, edict()); + // TODO: Implement a list of entities to remove them on restart round + auto pItem = CBaseEntity::Create((char *)STRING(m_iszSpawnObject), VecBModelOrigin(pev), pev->angles, edict()); + +#ifdef REGAMEDLL_FIXES + // FIX: entity leak! + if (pItem) + { + pItem->pev->spawnflags |= SF_NORESPAWN; + pItem->SetThink(&CBaseEntity::SUB_Remove); + pItem->pev->nextthink = gpGlobals->time + CGameRules::GetItemKillDelay(); + } +#endif + } if (Explodable()) diff --git a/regamedll/dlls/func_tank.cpp b/regamedll/dlls/func_tank.cpp index a3538202..4f278fc5 100644 --- a/regamedll/dlls/func_tank.cpp +++ b/regamedll/dlls/func_tank.cpp @@ -275,7 +275,12 @@ void CFuncTank::StopControl() ALERT(at_console, "stopped using TANK\n"); - m_pController->m_iHideHUD &= ~HIDEHUD_WEAPONS; +#ifdef REGAMEDLL_FIXES + if (m_pController->m_pActiveItem) +#endif + { + m_pController->m_iHideHUD &= ~HIDEHUD_WEAPONS; + } pev->nextthink = 0; m_pController = nullptr; diff --git a/regamedll/dlls/h_battery.cpp b/regamedll/dlls/h_battery.cpp index 8d74cae0..7d36c1c7 100644 --- a/regamedll/dlls/h_battery.cpp +++ b/regamedll/dlls/h_battery.cpp @@ -67,11 +67,6 @@ void CRecharge::Restart() UTIL_SetSize(pev, pev->mins, pev->maxs); SET_MODEL(ENT(pev), STRING(pev->model)); - int armorValue = (int)gSkillData.suitchargerCapacity; - if (pev->armorvalue != 0.0f) { - armorValue = (int)pev->armorvalue; - } - pev->nextthink = pev->ltime + 0.1f; SetThink(&CRecharge::Recharge); } @@ -86,12 +81,25 @@ void CRecharge::Precache() void CRecharge::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) { - // if it's not a player, ignore - if (!FClassnameIs(pActivator->pev, "player")) +#ifdef REGAMEDLL_FIXES + // Make sure that we have a caller + if (!pActivator) return; - + + // if it's not a player, ignore + if (!pActivator->IsPlayer()) + return; +#else + if (!FClassnameIs(pActivator->pev, "player")) + return; +#endif // #ifdef REGAMEDLL_FIXES + // if there is no juice left, turn it off - if (m_iJuice <= 0) + if (m_iJuice <= 0 +#ifdef REGAMEDLL_FIXES + && pev->frame != 1.0f // recharging... don't reset think +#endif + ) { pev->frame = 1.0f; Off(); @@ -126,7 +134,7 @@ void CRecharge::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useT m_hActivator = pActivator;//EHANDLE::CBaseEntity *operator= - //only recharge the player + // only recharge the player if (!m_hActivator->IsPlayer()) return; diff --git a/regamedll/dlls/healthkit.cpp b/regamedll/dlls/healthkit.cpp index e27986c6..a1b57d31 100644 --- a/regamedll/dlls/healthkit.cpp +++ b/regamedll/dlls/healthkit.cpp @@ -138,7 +138,11 @@ void CWallHealth::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE us return; // if there is no juice left, turn it off - if (m_iJuice <= 0) + if (m_iJuice <= 0 +#ifdef REGAMEDLL_FIXES + && pev->frame != 1.0f // recharging... don't reset think +#endif + ) { pev->frame = 1.0f; Off();