Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various defuser fixes and code refactory #848

Merged
merged 5 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
100 changes: 48 additions & 52 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -5682,10 +5658,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)
{
Expand Down Expand Up @@ -8280,14 +8253,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++)
Expand Down Expand Up @@ -10132,6 +10097,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()
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,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