Merge pull request #2 from Vaqtincha/refcatoring

Refcatoring and Fixes
This commit is contained in:
Dmitry Novikov 2024-05-19 05:07:40 +07:00 committed by GitHub
commit 6ddf1f4187
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -69,6 +69,20 @@ void CGameData::Init()
SetStartEdict(INDEXENT(0)); SetStartEdict(INDEXENT(0));
} }
inline void ClearAllClients()
{
for (int i = 0; i < g_GameData.GetMaxClients(); i++)
{
CGamePlayer *pPlayer = PLAYER_FOR_NUM(i);
if (!pPlayer) {
continue;
}
pPlayer->Player_Clear();
}
}
void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax) void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax)
{ {
bActivated = true; bActivated = true;
@ -112,16 +126,7 @@ void ServerDeactivate_Post()
{ {
if (bActivated) if (bActivated)
{ {
for (int i = 0; i < g_GameData.GetMaxClients(); i++) ClearAllClients();
{
CGamePlayer *pPlayer = PLAYER_FOR_NUM(i);
if (!pPlayer) {
continue;
}
pPlayer->Player_Clear();
}
} }
bInitialized = false; bInitialized = false;
@ -256,6 +261,20 @@ void CBasePlayer_Spawn(IReGameHook_CBasePlayer_Spawn *chain, CBasePlayer *pthis)
chain->callNext(pthis); chain->callNext(pthis);
} }
inline bool IsTeamAllowed(CBasePlayer *HostPlayer, CBasePlayer *EntPlayer)
{
auto hostTeam = HostPlayer->m_iTeam;
if (hostTeam == SPECTATOR || g_Config.GetTeam() == SC_TEAM_ALL)
return true;
if (g_Config.GetTeam() == SC_TEAM_TEAMMATE)
return (CSGameRules()->PlayerRelationship(HostPlayer, EntPlayer) == GR_TEAMMATE);
// SC_TEAM_T, SC_TEAM_CT
return (hostTeam == g_Config.GetTeam() && EntPlayer->m_iTeam == g_Config.GetTeam());
}
inline bool allowDontSolid(playermove_t *pm, edict_t *pHost, int host, int j) inline bool allowDontSolid(playermove_t *pm, edict_t *pHost, int host, int j)
{ {
pHost = EDICT(host); pHost = EDICT(host);
@ -285,14 +304,10 @@ inline bool allowDontSolid(playermove_t *pm, edict_t *pHost, int host, int j)
int entTeamId = EntPlayer->m_iTeam; int entTeamId = EntPlayer->m_iTeam;
*pPlayer->GetDiff(pObject) = GET_DISTANCE(hostOrigin, entOrigin); *pPlayer->GetDiff(pObject) = GET_DISTANCE(hostOrigin, entOrigin);
*pPlayer->GetSolid(pObject) = (hostTeamId == SPECTATOR *pPlayer->GetSolid(pObject) =
|| ((g_Config.GetEffects() (
|| *pPlayer->GetDiff(pObject) < g_Config.GetDistance()) (g_Config.GetEffects() || *pPlayer->GetDiff(pObject) < g_Config.GetDistance()) && IsTeamAllowed(HostPlayer, EntPlayer) && !pObject->GetDont()
&& ((g_Config.GetTeam() == SC_TEAM_ALL) ? 1 );
: (g_Config.GetTeam() == SC_TEAM_TEAMMATE) ? (CSGameRules()->PlayerRelationship(HostPlayer, EntPlayer) == GR_TEAMMATE)
: (hostTeamId == g_Config.GetTeam()
&& entTeamId == g_Config.GetTeam()))
&& !pObject->GetDont()));
if (g_Config.GetCrouch() && pPlayer->GetSolid(IndexObject)) if (g_Config.GetCrouch() && pPlayer->GetSolid(IndexObject))
{ {
@ -428,10 +443,7 @@ void PM_Move(playermove_t *pm, int server)
continue; continue;
} }
if ((g_Config.GetTeam() == SC_TEAM_ALL) ? 1 if (IsTeamAllowed(pCBasePlayer, EntPlayer))
: (g_Config.GetTeam() == SC_TEAM_TEAMMATE) ? (CSGameRules()->PlayerRelationship(pCBasePlayer, EntPlayer) == GR_TEAMMATE)
: (hostTeamId == g_Config.GetTeam()
&& EntPlayer->m_iTeam == g_Config.GetTeam()))
{ {
bCollide = true; bCollide = true;
} }
@ -495,16 +507,7 @@ void CSGameRules_OnRoundFreezeEnd(IReGameHook_CSGameRules_OnRoundFreezeEnd *chai
{ {
chain->callNext(); chain->callNext();
for (int i = 0; i < g_GameData.GetMaxClients(); i++) ClearAllClients();
{
CGamePlayer *pPlayer = PLAYER_FOR_NUM(i);
if (!pPlayer) {
continue;
}
pPlayer->Player_Clear();
}
g_Config.SetCount(gpGlobals->time + g_Config.GetTime()); g_Config.SetCount(gpGlobals->time + g_Config.GetTime());
@ -513,8 +516,12 @@ void CSGameRules_OnRoundFreezeEnd(IReGameHook_CSGameRules_OnRoundFreezeEnd *chai
g_ReGameHookchains->CBasePlayer_Spawn()->unregisterHook(&CBasePlayer_Spawn); g_ReGameHookchains->CBasePlayer_Spawn()->unregisterHook(&CBasePlayer_Spawn);
g_ReGameHookchains->CBasePlayer_Spawn()->registerHook(&CBasePlayer_Spawn, HC_PRIORITY_DEFAULT + 1); g_ReGameHookchains->CBasePlayer_Spawn()->registerHook(&CBasePlayer_Spawn, HC_PRIORITY_DEFAULT + 1);
g_ReGameHookchains->CBasePlayer_TraceAttack()->unregisterHook(&CBasePlayer_TraceAttack);
g_ReGameHookchains->CBasePlayer_TraceAttack()->registerHook(&CBasePlayer_TraceAttack, HC_PRIORITY_DEFAULT + 1); if (g_Config.GetPenetFire())
{
g_ReGameHookchains->CBasePlayer_TraceAttack()->unregisterHook(&CBasePlayer_TraceAttack);
g_ReGameHookchains->CBasePlayer_TraceAttack()->registerHook(&CBasePlayer_TraceAttack, HC_PRIORITY_DEFAULT + 1);
}
g_pFunctionTable->pfnPM_Move = PM_Move; g_pFunctionTable->pfnPM_Move = PM_Move;
g_pNewFunctionTable->pfnShouldCollide = ShouldCollide; g_pNewFunctionTable->pfnShouldCollide = ShouldCollide;
@ -551,34 +558,31 @@ void SVR_SemiclipOption()
} }
else else
{ {
if (!strcasecmp(argv, "time")) if (!strcasecmp(argv, "semiclip"))
{
ClearAllClients();
g_RehldsHookchains->SV_CreatePacketEntities()->unregisterHook(&SV_CreatePacketEntities);
g_RehldsHookchains->SV_CreatePacketEntities()->registerHook(&SV_CreatePacketEntities, HC_PRIORITY_HIGH);
g_ReGameHookchains->CBasePlayer_Spawn()->unregisterHook(&CBasePlayer_Spawn);
g_ReGameHookchains->CBasePlayer_Spawn()->registerHook(&CBasePlayer_Spawn, HC_PRIORITY_DEFAULT + 1);
g_ReGameHookchains->CSGameRules_OnRoundFreezeEnd()->unregisterHook(&CSGameRules_OnRoundFreezeEnd);
if (g_Config.GetPenetFire())
{
g_ReGameHookchains->CBasePlayer_TraceAttack()->unregisterHook(&CBasePlayer_TraceAttack);
g_ReGameHookchains->CBasePlayer_TraceAttack()->registerHook(&CBasePlayer_TraceAttack, HC_PRIORITY_DEFAULT + 1);
}
g_pFunctionTable->pfnPM_Move = PM_Move;
g_pNewFunctionTable->pfnShouldCollide = ShouldCollide;
}
else if (!strcasecmp(argv, "time"))
{ {
if (g_Config.GetTime()) { if (g_Config.GetTime()) {
g_ReGameHookchains->CSGameRules_OnRoundFreezeEnd()->registerHook(&CSGameRules_OnRoundFreezeEnd, HC_PRIORITY_DEFAULT + 1); g_ReGameHookchains->CSGameRules_OnRoundFreezeEnd()->registerHook(&CSGameRules_OnRoundFreezeEnd, HC_PRIORITY_DEFAULT + 1);
} }
else
{
for (int i = 0; i < g_GameData.GetMaxClients(); i++)
{
CGamePlayer *pPlayer = PLAYER_FOR_NUM(i);
if (!pPlayer) {
continue;
}
pPlayer->Player_Clear();
}
g_RehldsHookchains->SV_CreatePacketEntities()->unregisterHook(&SV_CreatePacketEntities);
g_RehldsHookchains->SV_CreatePacketEntities()->registerHook(&SV_CreatePacketEntities, HC_PRIORITY_HIGH);
g_ReGameHookchains->CBasePlayer_Spawn()->unregisterHook(&CBasePlayer_Spawn);
g_ReGameHookchains->CBasePlayer_Spawn()->registerHook(&CBasePlayer_Spawn, HC_PRIORITY_DEFAULT + 1);
g_ReGameHookchains->CSGameRules_OnRoundFreezeEnd()->unregisterHook(&CSGameRules_OnRoundFreezeEnd);
g_pFunctionTable->pfnPM_Move = PM_Move;
g_pNewFunctionTable->pfnShouldCollide = ShouldCollide;
}
} }
else if (!strcasecmp(argv, "penetfire")) else if (!strcasecmp(argv, "penetfire"))
{ {