Skip to content

Commit

Permalink
Defuser code refactory and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dystopm committed Jul 13, 2023
1 parent 11d6b08 commit c0b3776
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
10 changes: 1 addition & 9 deletions regamedll/dlls/API/CSPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
66 changes: 53 additions & 13 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1691,12 +1691,16 @@ void CBasePlayer::RemoveAllItems(BOOL removeSuit)
{
RemoveDefuser();

#ifndef REGAMEDLL_FIXES
// NOTE: moved into RemoveDefuser
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();

SendItemStatus();
#endif

bKillProgBar = true;
}

Expand Down Expand Up @@ -2402,8 +2406,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();
Expand Down Expand Up @@ -2433,29 +2437,30 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
RemoveDefuser();

#ifdef REGAMEDLL_FIXES
CItemThighPack *pDefuser = (CItemThighPack *)CBaseEntity::Create("item_thighpack", pev->origin, g_vecZero, ENT(pev));
SpawnDefuser(pev->origin, ENT(pev));

pDefuser->SetThink(&CBaseEntity::SUB_Remove);
pDefuser->pev->nextthink = gpGlobals->time + CGameRules::GetItemKillDelay();
pDefuser->pev->spawnflags |= SF_NORESPAWN;
if (m_bIsDefusing)
SetProgressBarTime(0);

m_bIsDefusing = false;
#else
GiveNamedItem("item_thighpack");
#endif

// NOTE: moved into RemoveDefuser
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();

SendItemStatus();
}

if (m_bIsDefusing)
{
SetProgressBarTime(0);
#endif
}

m_bIsDefusing = false;
#ifndef REGAMEDLL_FIXES
m_bIsDefusing = false; // NOTE: moved above
#endif

BuyZoneIcon_Clear(this);

#ifdef REGAMEDLL_ADD
Expand Down Expand Up @@ -3775,17 +3780,25 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Disappear)()
{
RemoveDefuser();

#ifndef REGAMEDLL_FIXES
#ifdef REGAMEDLL_FIXES
SpawnDefuser(pev->origin, ENT(pev));

if (m_bIsDefusing)
SetProgressBarTime(0);

m_bIsDefusing = false;
#else
GiveNamedItem("item_thighpack");
#endif

// NOTE: moved into RemoveDefuser
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();

SendItemStatus();
SetProgressBarTime(0);
#endif
}

BuyZoneIcon_Clear(this);
Expand Down Expand Up @@ -8286,12 +8299,16 @@ void CBasePlayer::__API_HOOK(SwitchTeam)()
{
RemoveDefuser();

#ifndef REGAMEDLL_FIXES
// NOTE: moved into RemoveDefuser
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();

SendItemStatus();
#endif

SetProgressBarTime(0);

#ifndef REGAMEDLL_FIXES
Expand Down Expand Up @@ -10135,6 +10152,29 @@ void CBasePlayer::RemoveDefuser()
{
m_bHasDefuser = false;
pev->body = 0;

#ifdef REGAMEDLL_FIXES
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, nullptr, pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("defuser");
MESSAGE_END();

SendItemStatus();
#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()
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ class CBasePlayer: public CBaseMonster {

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
{
Expand Down

0 comments on commit c0b3776

Please sign in to comment.