Various defuser fixes and code refactory (#848)

* Defuser code refactory and fix
This commit is contained in:
Francisco Muñoz 2023-09-05 00:52:44 -03:00 committed by GitHub
parent 2e6e77906f
commit facc2be534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 61 deletions

View File

@ -153,15 +153,7 @@ EXT_FUNC bool CCSPlayer::RemovePlayerItemEx(const char* pszItemName, bool bRemov
if (!pPlayer->m_bHasDefuser)
return false;
pPlayer->m_bHasDefuser = false;
pPlayer->pev->body = 0;
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pPlayer->pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();
pPlayer->SendItemStatus();
pPlayer->RemoveDefuser();
}
// item_longjump
else if (FStrEq(pszItemName, "longjump"))

View File

@ -621,6 +621,9 @@ void EXT_FUNC ClientPutInServer(edict_t *pEntity)
return;
}
#ifdef REGAMEDLL_FIXES
pPlayer->m_bHasDefuser = false;
#endif
pPlayer->m_bNotKilled = true;
pPlayer->m_iIgnoreGlobalChat = IGNOREMSG_NONE;
pPlayer->m_iTeamKills = 0;

View File

@ -1690,14 +1690,6 @@ void CBasePlayer::RemoveAllItems(BOOL removeSuit)
if (m_bHasDefuser)
{
RemoveDefuser();
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();
SendItemStatus();
bKillProgBar = true;
}
if (m_bHasC4)
@ -2396,8 +2388,8 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
}
SetSuitUpdate(nullptr, SUIT_SENTENCE, SUIT_REPEAT_OK);
m_iClientHealth = 0;
m_iClientHealth = 0;
MESSAGE_BEGIN(MSG_ONE, gmsgHealth, nullptr, pev);
WRITE_BYTE(m_iClientHealth);
MESSAGE_END();
@ -2425,31 +2417,18 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
else if (m_bHasDefuser)
{
RemoveDefuser();
#ifdef REGAMEDLL_FIXES
CItemThighPack *pDefuser = (CItemThighPack *)CBaseEntity::Create("item_thighpack", pev->origin, g_vecZero, ENT(pev));
pDefuser->SetThink(&CBaseEntity::SUB_Remove);
pDefuser->pev->nextthink = gpGlobals->time + CGameRules::GetItemKillDelay();
pDefuser->pev->spawnflags |= SF_NORESPAWN;
SpawnDefuser(pev->origin, ENT(pev));
#else
GiveNamedItem("item_thighpack");
#endif
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();
SendItemStatus();
}
if (m_bIsDefusing)
{
SetProgressBarTime(0);
}
#ifndef REGAMEDLL_FIXES
// NOTE: moved to RemoveDefuser
m_bIsDefusing = false;
#endif
m_bIsDefusing = false;
BuyZoneIcon_Clear(this);
#ifdef REGAMEDLL_ADD
@ -3640,16 +3619,20 @@ void EXT_FUNC CBasePlayer::__API_HOOK(JoiningThink)()
ResetMenu();
m_iJoiningState = SHOWTEAMSELECT;
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
#ifndef REGAMEDLL_FIXES
// NOTE: client already clears StatusIcon on join
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();
m_bHasDefuser = false;
m_bHasDefuser = false; // set in ClientPutInServer
#endif
m_fLastMovement = gpGlobals->time;
m_bMissionBriefing = false;
SendItemStatus();
SendItemStatus(); // NOTE: must be on UpdateClientData
break;
}
case READINGLTEXT:
@ -3768,18 +3751,11 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Disappear)()
else if (m_bHasDefuser)
{
RemoveDefuser();
#ifndef REGAMEDLL_FIXES
#ifdef REGAMEDLL_FIXES
SpawnDefuser(pev->origin, ENT(pev));
#else
GiveNamedItem("item_thighpack");
#endif
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();
SendItemStatus();
SetProgressBarTime(0);
}
BuyZoneIcon_Clear(this);
@ -5695,10 +5671,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Spawn)()
ReloadWeapons();
#endif
if (m_bHasDefuser)
pev->body = 1;
else
pev->body = 0;
pev->body = m_bHasDefuser ? 1 : 0;
if (m_bMissionBriefing)
{
@ -8293,14 +8266,6 @@ void CBasePlayer::__API_HOOK(SwitchTeam)()
{
RemoveDefuser();
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();
SendItemStatus();
SetProgressBarTime(0);
#ifndef REGAMEDLL_FIXES
// NOTE: unreachable code - Vaqtincha
for (int i = 0; i < MAX_ITEM_TYPES; i++)
@ -10145,6 +10110,37 @@ void CBasePlayer::RemoveDefuser()
{
m_bHasDefuser = false;
pev->body = 0;
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();
SendItemStatus();
#ifdef REGAMEDLL_FIXES
if (m_bIsDefusing)
{
SetProgressBarTime(0);
m_bIsDefusing = false;
}
#else
SetProgressBarTime(0);
#endif
}
CItemThighPack *SpawnDefuser(const Vector &vecOrigin, edict_t *pentOwner)
{
CItemThighPack *pDefuser = (CItemThighPack *)CBaseEntity::Create("item_thighpack", vecOrigin, g_vecZero, pentOwner);
if (pDefuser)
{
pDefuser->SetThink(&CBaseEntity::SUB_Remove);
pDefuser->pev->nextthink = gpGlobals->time + CGameRules::GetItemKillDelay();
pDefuser->pev->spawnflags |= SF_NORESPAWN;
}
return pDefuser;
}
void CBasePlayer::Disconnect()

View File

@ -910,6 +910,7 @@ public:
CWeaponBox *CreateWeaponBox(CBasePlayerItem *pItem, CBasePlayer *pPlayerOwner, const char *modelName, Vector &origin, Vector &angles, Vector &velocity, float lifeTime, bool packAmmo);
CWeaponBox *CreateWeaponBox_OrigFunc(CBasePlayerItem *pItem, CBasePlayer *pPlayerOwner, const char *modelName, Vector &origin, Vector &angles, Vector &velocity, float lifeTime, bool packAmmo);
CItemThighPack *SpawnDefuser(const Vector &vecOrigin, edict_t *pentOwner);
class CWShield: public CBaseEntity
{