From 1423f7e3fada88fefda0ae0cb6b5dbc8814dfe6b Mon Sep 17 00:00:00 2001 From: s1lentq Date: Tue, 27 Sep 2016 03:16:33 +0700 Subject: [PATCH] Fix: CleanUpMap before the players spawn. Fix: ValveSoftware/halflife#1567 --- regamedll/dlls/multiplay_gamerules.cpp | 19 ++++++++-- regamedll/dlls/player.cpp | 52 ++++++++++++++++++++++++++ regamedll/dlls/player.h | 3 ++ 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/regamedll/dlls/multiplay_gamerules.cpp b/regamedll/dlls/multiplay_gamerules.cpp index 0b74ea78..7e12f43c 100644 --- a/regamedll/dlls/multiplay_gamerules.cpp +++ b/regamedll/dlls/multiplay_gamerules.cpp @@ -1940,6 +1940,11 @@ void CHalfLifeMultiplay::__API_VHOOK(RestartRound)() m_iLoserBonus = m_rgRewardAccountRules[RR_LOSER_BONUS_DEFAULT]; } +#ifdef REGAMEDLL_FIXES + // Respawn entities (glass, doors, etc..) + CleanUpMap(); +#endif + // tell bots that the round is restarting CBaseEntity *pPlayer = NULL; while ((pPlayer = UTIL_FindEntityByClassname(pPlayer, "player")) != NULL) @@ -1987,11 +1992,17 @@ void CHalfLifeMultiplay::__API_VHOOK(RestartRound)() if (player->m_iTeam != UNASSIGNED && player->m_iTeam != SPECTATOR) { +#ifdef REGAMEDLL_FIXES + // remove the c4 if the player is carrying it + if (player->m_bHasC4) { + player->RemoveBomb(); + } +#else // drop the c4 if the player is carrying it - if (player->m_bHasC4) - { + if (player->m_bHasC4) { player->DropPlayerItem("weapon_c4"); } +#endif player->RoundRespawn(); } @@ -2001,8 +2012,10 @@ void CHalfLifeMultiplay::__API_VHOOK(RestartRound)() // for EVERY player (regardless of what team they're on) } - // Respawn entities (glass, doors, etc..) + // Moved above the loop spawning the players +#ifndef REGAMEDLL_FIXES CleanUpMap(); +#endif // Give C4 to the terrorists if (m_bMapHasBombTarget) diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index ecee6ad9..2f00ef0a 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -6006,8 +6006,14 @@ void CBasePlayer::FlashlightTurnOff() void CBasePlayer::ForceClientDllUpdate() { +#ifdef REGAMEDLL_FIXES + // fix for https://github.com/ValveSoftware/halflife/issues/1567 + m_iClientHideHUD = -1; +#endif + m_iClientHealth = -1; m_iClientBattery = -1; + m_fWeapon = FALSE; m_fInitHUD = TRUE; m_iTrain |= TRAIN_NEW; @@ -6786,6 +6792,17 @@ void EXT_FUNC CBasePlayer::__API_VHOOK(UpdateClientData)() WRITE_SHORT(CSGameRules()->m_iNumTerroristWins); MESSAGE_END(); } + +#ifdef REGAMEDLL_FIXES + // send "flashlight" update message + if (FlashlightIsOn()) + { + MESSAGE_BEGIN(MSG_ONE, gmsgFlashlight, NULL, pev); + WRITE_BYTE(1); + WRITE_BYTE(m_iFlashBattery); + MESSAGE_END(); + } +#endif } if (m_iHideHUD != m_iClientHideHUD) @@ -9442,3 +9459,38 @@ void CBasePlayer::DropPrimary() #endif } + +CBasePlayerItem *CBasePlayer::GetItemOfNamed(const char *pszItemName) +{ + for (auto pItem : m_rgpPlayerItems) { + while (pItem) { + if (FClassnameIs(pItem->pev, pszItemName)) + return pItem; + + pItem = pItem->m_pNext; + } + } + + return nullptr; +} + +void CBasePlayer::RemoveBomb() +{ + auto pBomb = GetItemOfNamed("weapon_c4"); + if (!pBomb) + return; + + m_bHasC4 = false; + pev->body = 0; + SetBombIcon(FALSE); + SetProgressBarTime(0); + + if (m_pActiveItem == pBomb) { + ((CBasePlayerWeapon *)pBomb)->RetireWeapon(); + } + + if (RemovePlayerItem(pBomb)) { + pev->weapons &= ~(1 << pBomb->m_iId); + pBomb->Kill(); + } +} diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index 13d604d1..a89b1dc5 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -603,6 +603,9 @@ public: void DropSecondary(); void DropPrimary(); + void RemoveBomb(); + CBasePlayerItem *GetItemOfNamed(const char *pszItemName); + #ifdef REGAMEDLL_ADD CCSPlayer *CSPlayer() const; #endif