From 3306fd5b21e1131f6eee8db596cba88f6ecb901d Mon Sep 17 00:00:00 2001 From: Kamay Xutax Date: Mon, 15 Jul 2024 16:47:27 +0200 Subject: [PATCH] Fixed buy, hostage, bomb zones detections --- game/client/cstrike/c_cs_player.cpp | 4 ---- game/client/cstrike/cs_prediction.cpp | 2 +- game/client/prediction.cpp | 7 ++----- game/server/cstrike/cs_player.cpp | 9 ++------- game/server/cstrike/cs_playermove.cpp | 5 ----- game/server/cstrike/func_bomb_target.cpp | 12 +++++++++++- game/server/cstrike/func_bomb_target.h | 1 + game/server/cstrike/func_buy_zone.cpp | 13 +++++++++++-- game/server/cstrike/func_hostage_rescue.cpp | 11 +++++++++++ game/server/player_command.cpp | 12 ++++-------- 10 files changed, 43 insertions(+), 33 deletions(-) diff --git a/game/client/cstrike/c_cs_player.cpp b/game/client/cstrike/c_cs_player.cpp index df572adafc..5831224c9c 100644 --- a/game/client/cstrike/c_cs_player.cpp +++ b/game/client/cstrike/c_cs_player.cpp @@ -2231,10 +2231,6 @@ void C_CSPlayer::Simulate( void ) void C_CSPlayer::PostThink() { BaseClass::PostThink(); - // Reset this.. it gets reset each frame that we're in a bomb zone. - m_bInBombZone = false; - m_bInBuyZone = false; - m_bInHostageRescueZone = false; } diff --git a/game/client/cstrike/cs_prediction.cpp b/game/client/cstrike/cs_prediction.cpp index 1b4a0013f9..fd83dfcc41 100644 --- a/game/client/cstrike/cs_prediction.cpp +++ b/game/client/cstrike/cs_prediction.cpp @@ -27,7 +27,7 @@ public: void CCSPrediction::StartCommand(CBasePlayer* player, CUserCmd* cmd) { - CCSPlayer *pPlayer = ToCSPlayer( player ); + CCSPlayer* pPlayer = ToCSPlayer(player); BaseClass::StartCommand( player, cmd ); } diff --git a/game/client/prediction.cpp b/game/client/prediction.cpp index da1a13ce44..6245421217 100644 --- a/game/client/prediction.cpp +++ b/game/client/prediction.cpp @@ -888,12 +888,9 @@ void CPrediction::RunCommand( C_BasePlayer *player, CUserCmd *ucmd, IMoveHelper g_pGameMovement->StartTrackPredictionErrors( player ); gpGlobals->frametime = m_bEnginePaused ? 0 : TICK_INTERVAL; - // Run post think after PreThink/Think function, this makes a room space for local interpolation. - gpGlobals->curtime = (player->m_nTickBase - 1) * TICK_INTERVAL; - - RunPostThink( player ); + gpGlobals->curtime = player->m_nTickBase * TICK_INTERVAL; - gpGlobals->curtime = player->m_nTickBase * TICK_INTERVAL; + RunPostThink( player ); // TODO // TODO: Check for impulse predicted? diff --git a/game/server/cstrike/cs_player.cpp b/game/server/cstrike/cs_player.cpp index a0c546be22..ad8e9df2f8 100644 --- a/game/server/cstrike/cs_player.cpp +++ b/game/server/cstrike/cs_player.cpp @@ -1584,7 +1584,7 @@ void CCSPlayer::UpdateMouseoverHints() } void CCSPlayer::PostThink() -{ +{ BaseClass::PostThink(); UpdateAddonBits(); @@ -1629,12 +1629,7 @@ void CCSPlayer::PostThink() { StopSound( "Player.AmbientUnderWater" ); SetPlayerUnderwater( false ); - } - - // Reset this.. it gets reset each frame that we're in a bomb zone. - m_bInBombZone = false; - m_bInBuyZone = false; - m_bInHostageRescueZone = false; + } } diff --git a/game/server/cstrike/cs_playermove.cpp b/game/server/cstrike/cs_playermove.cpp index a8f4eee96c..5d25962340 100644 --- a/game/server/cstrike/cs_playermove.cpp +++ b/game/server/cstrike/cs_playermove.cpp @@ -52,11 +52,6 @@ void CCSPlayerMove::StartCommand( CBasePlayer *player, CUserCmd *cmd ) { CCSPlayer *pPlayer = ToCSPlayer( player ); - // Reset this.. it gets reset each frame that we're in a bomb zone. - pPlayer->m_bInBombZone = false; - pPlayer->m_bInBuyZone = false; - pPlayer->m_bInHostageRescueZone = false; - BaseClass::StartCommand( player, cmd ); } diff --git a/game/server/cstrike/func_bomb_target.cpp b/game/server/cstrike/func_bomb_target.cpp index a85d646dcc..7ebbedf104 100644 --- a/game/server/cstrike/func_bomb_target.cpp +++ b/game/server/cstrike/func_bomb_target.cpp @@ -13,7 +13,8 @@ LINK_ENTITY_TO_CLASS( func_bomb_target, CBombTarget ); BEGIN_DATADESC( CBombTarget ) DEFINE_FUNCTION( BombTargetTouch ), - DEFINE_FUNCTION( BombTargetUse ), //needed? + DEFINE_FUNCTION( BombTargetUse ), + DEFINE_FUNCTION( EndTouch ), // Inputs DEFINE_INPUTFUNC( FIELD_VOID, "BombExplode", OnBombExplode ), @@ -60,6 +61,15 @@ void CBombTarget::BombTargetTouch( CBaseEntity* pOther ) } } +void CBombTarget::EndTouch(CBaseEntity* pOther) +{ + CCSPlayer *p = dynamic_cast< CCSPlayer* >( pOther ); + if ( p ) + { + p->m_bInBombZone = false; + } +} + void CBombTarget::BombTargetUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { //SUB_UseTargets( NULL, USE_TOGGLE, 0 ); diff --git a/game/server/cstrike/func_bomb_target.h b/game/server/cstrike/func_bomb_target.h index 090b81dd10..2ffa9dc407 100644 --- a/game/server/cstrike/func_bomb_target.h +++ b/game/server/cstrike/func_bomb_target.h @@ -27,6 +27,7 @@ public: bool IsHeistBombTarget( void ) { return m_bIsHeistBombTarget; } const char *GetBombMountTarget( void ){ return STRING( m_szMountTarget ); } + virtual void EndTouch( CBaseEntity *pOther ); private: COutputEvent m_OnBombExplode; //Fired when the bomb explodes COutputEvent m_OnBombPlanted; //Fired when the bomb is planted diff --git a/game/server/cstrike/func_buy_zone.cpp b/game/server/cstrike/func_buy_zone.cpp index a982fe4a1f..2499e65b96 100644 --- a/game/server/cstrike/func_buy_zone.cpp +++ b/game/server/cstrike/func_buy_zone.cpp @@ -23,6 +23,7 @@ public: CBuyZone(); void Spawn(); void EXPORT BuyZoneTouch( CBaseEntity* pOther ); + virtual void EndTouch( CBaseEntity *pOther ); public: int m_LegacyTeamNum; @@ -33,7 +34,7 @@ LINK_ENTITY_TO_CLASS( func_buyzone, CBuyZone ); BEGIN_DATADESC( CBuyZone ) DEFINE_FUNCTION( BuyZoneTouch ), - + DEFINE_FUNCTION( EndTouch ), // This is here to support maps that haven't updated to using "teamnum" yet. DEFINE_INPUT( m_LegacyTeamNum, FIELD_INTEGER, "team" ) END_DATADESC() @@ -70,8 +71,16 @@ void CBuyZone::BuyZoneTouch( CBaseEntity* pOther ) // compare player team with buy zone team number if ( p->GetTeamNumber() == GetTeamNumber() ) { - p->m_bInBuyZone = true; + p->m_bInBuyZone = true; } } } +void CBuyZone::EndTouch( CBaseEntity* pOther ) +{ + CCSPlayer *p = dynamic_cast< CCSPlayer* >( pOther ); + if ( p ) + { + p->m_bInBuyZone = false; + } +} \ No newline at end of file diff --git a/game/server/cstrike/func_hostage_rescue.cpp b/game/server/cstrike/func_hostage_rescue.cpp index 5a5166f535..bf8ab5889d 100644 --- a/game/server/cstrike/func_hostage_rescue.cpp +++ b/game/server/cstrike/func_hostage_rescue.cpp @@ -6,6 +6,7 @@ #include "cbase.h" #include "triggers.h" +#include "cs_player.h" class CHostageRescueZone : public CBaseTrigger { @@ -17,6 +18,8 @@ public: void Spawn(); void HostageRescueTouch( CBaseEntity* pOther ); + + virtual void EndTouch( CBaseEntity *pOther ); }; @@ -43,3 +46,11 @@ void CHostageRescueZone::HostageRescueTouch( CBaseEntity *pOther ) pOther->AcceptInput( "OnRescueZoneTouch", NULL, NULL, emptyVariant, 0 ); } +void CHostageRescueZone::EndTouch( CBaseEntity* pOther ) +{ + CCSPlayer *p = dynamic_cast< CCSPlayer* >( pOther ); + if ( p ) + { + p->m_bInHostageRescueZone = true; + } +} \ No newline at end of file diff --git a/game/server/player_command.cpp b/game/server/player_command.cpp index 642064f21a..6e88218dba 100644 --- a/game/server/player_command.cpp +++ b/game/server/player_command.cpp @@ -339,12 +339,12 @@ void CPlayerMove::RunCommand ( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper return; // Don't process this command } + gpGlobals->frametime = playerFrameTime; + gpGlobals->curtime = player->m_nTickBase * TICK_INTERVAL; + StartCommand( player, ucmd ); g_pGameMovement->StartTrackPredictionErrors( player ); - - gpGlobals->frametime = playerFrameTime; - gpGlobals->curtime = (player->m_nTickBase - 1) * TICK_INTERVAL; if (ucmd->debug_hitboxes) { @@ -363,11 +363,7 @@ void CPlayerMove::RunCommand ( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper lagcompensation->FinishLagCompensation( player ); } - // Run post think first, this will let some space for client side interpolation. - RunPostThink( player ); - - // Set globals appropriately - gpGlobals->curtime = player->m_nTickBase * TICK_INTERVAL; + RunPostThink( player ); // Prevent hacked clients from sending us invalid view angles to try to get leaf server code to crash if ( !ucmd->viewangles.IsValid() || !IsEntityQAngleReasonable(ucmd->viewangles) )