Fixed possible buffer overflow & optimized network
This commit is contained in:
parent
8db1b5ec1a
commit
380f352adf
9 changed files with 233 additions and 352 deletions
|
@ -62,105 +62,100 @@ static inline bool EncodeSpecialFloat( const SendProp *pProp, float fVal, bf_wri
|
|||
// TODO_ENHANCED:
|
||||
// Encoding works by sending a normalized float (from range 0.0 to 1.0)
|
||||
// This works because we know the range we encode the float to
|
||||
static inline void EncodeFloat(const SendProp* pProp,
|
||||
float fVal,
|
||||
bf_write* pOut,
|
||||
int objectID)
|
||||
static inline void EncodeFloat( const SendProp* pProp, float fVal, bf_write* pOut, int objectID )
|
||||
{
|
||||
const auto WriteNormalizedFloat = [&](double dblValue)
|
||||
{
|
||||
bool isPerfectOne = dblValue >= 1.0;
|
||||
const auto WriteNormalizedFloat = [&]( double dblValue )
|
||||
{
|
||||
bool isPerfectOne = dblValue >= 1.0;
|
||||
|
||||
if (isPerfectOne)
|
||||
{
|
||||
pOut->WriteOneBit(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
pOut->WriteOneBit(false);
|
||||
if ( isPerfectOne )
|
||||
{
|
||||
pOut->WriteOneBit( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
pOut->WriteOneBit( false );
|
||||
|
||||
char strNumber[16];
|
||||
V_memset(strNumber, 0, sizeof(strNumber));
|
||||
V_sprintf_safe(strNumber, "%f", static_cast<float>(dblValue));
|
||||
char strNumber[16];
|
||||
V_memset( strNumber, 0, sizeof( strNumber ) );
|
||||
V_sprintf_safe( strNumber, "%f", static_cast< float >( dblValue ) );
|
||||
|
||||
auto sixDigitsValue = V_atoi(&strNumber[2]);
|
||||
auto sixDigitsValue = V_atoi( &strNumber[2] );
|
||||
|
||||
if (sixDigitsValue > 999999)
|
||||
{
|
||||
Sys_Error("EncodeFloat: tell to xutaxkamay that he's "
|
||||
"dumb\n");
|
||||
}
|
||||
if ( sixDigitsValue > 999999 )
|
||||
{
|
||||
Sys_Error( "EncodeFloat: tell to xutaxkamay that he's "
|
||||
"dumb\n" );
|
||||
}
|
||||
|
||||
pOut->WriteUBitLong(sixDigitsValue, 20);
|
||||
}
|
||||
};
|
||||
pOut->WriteUBitLong( sixDigitsValue, 20 );
|
||||
}
|
||||
};
|
||||
|
||||
// Check for special flags like SPROP_COORD, SPROP_NOSCALE, and
|
||||
// SPROP_NORMAL.
|
||||
if (EncodeSpecialFloat(pProp, fVal, pOut))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Check for special flags like SPROP_COORD, SPROP_NOSCALE, and
|
||||
// SPROP_NORMAL.
|
||||
if ( EncodeSpecialFloat( pProp, fVal, pOut ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((pProp->m_fHighValue == 0.0f && pProp->m_fLowValue == 0.0f)
|
||||
|| pProp->m_fHighValue == pProp->m_fLowValue)
|
||||
{
|
||||
pOut->WriteBitFloat(fVal);
|
||||
return;
|
||||
}
|
||||
if ( ( pProp->m_fHighValue == 0.0f && pProp->m_fLowValue == 0.0f ) || pProp->m_fHighValue == pProp->m_fLowValue )
|
||||
{
|
||||
pOut->WriteBitFloat( fVal );
|
||||
return;
|
||||
}
|
||||
|
||||
if (fVal > pProp->m_fHighValue)
|
||||
{
|
||||
Sys_Error("EncodeFloat: %s has value %f which is too big "
|
||||
"(%f)",
|
||||
pProp->GetName(),
|
||||
fVal,
|
||||
pProp->m_fHighValue);
|
||||
}
|
||||
if ( fVal > pProp->m_fHighValue )
|
||||
{
|
||||
Sys_Error( "EncodeFloat: %s has value %f which is too big "
|
||||
"(%f)",
|
||||
pProp->GetName(),
|
||||
fVal,
|
||||
pProp->m_fHighValue );
|
||||
}
|
||||
|
||||
if (fVal < pProp->m_fLowValue)
|
||||
{
|
||||
Sys_Error("EncodeFloat: %s has value %f which is too low "
|
||||
"(%f)",
|
||||
pProp->GetName(),
|
||||
fVal,
|
||||
pProp->m_fLowValue);
|
||||
}
|
||||
if ( fVal < pProp->m_fLowValue )
|
||||
{
|
||||
Sys_Error( "EncodeFloat: %s has value %f which is too low "
|
||||
"(%f)",
|
||||
pProp->GetName(),
|
||||
fVal,
|
||||
pProp->m_fLowValue );
|
||||
}
|
||||
|
||||
if (pProp->m_fLowValue > pProp->m_fHighValue)
|
||||
{
|
||||
Sys_Error("EncodeFloat: %s(%f) low value %f is higher than "
|
||||
"%f",
|
||||
pProp->GetName(),
|
||||
fVal,
|
||||
pProp->m_fLowValue,
|
||||
pProp->m_fHighValue);
|
||||
}
|
||||
if ( pProp->m_fLowValue > pProp->m_fHighValue )
|
||||
{
|
||||
Sys_Error( "EncodeFloat: %s(%f) low value %f is higher than "
|
||||
"%f",
|
||||
pProp->GetName(),
|
||||
fVal,
|
||||
pProp->m_fLowValue,
|
||||
pProp->m_fHighValue );
|
||||
}
|
||||
|
||||
double dblVal = static_cast<double>(fVal);
|
||||
double dblVal = static_cast< double >( fVal );
|
||||
|
||||
// If low value bigger than zero, we need to substract to the
|
||||
// lowest value possible, so we can recover it later.
|
||||
if ((pProp->m_fLowValue > 0.0f && pProp->m_fHighValue > 0.0f)
|
||||
|| (pProp->m_fHighValue < 0.0f && pProp->m_fLowValue < 0.0f))
|
||||
{
|
||||
dblVal -= pProp->m_fLowValue;
|
||||
}
|
||||
// If low value bigger than zero, we need to substract to the
|
||||
// lowest value possible, so we can recover it later.
|
||||
if ( ( pProp->m_fLowValue > 0.0f && pProp->m_fHighValue > 0.0f )
|
||||
|| ( pProp->m_fHighValue < 0.0f && pProp->m_fLowValue < 0.0f ) )
|
||||
{
|
||||
dblVal -= pProp->m_fLowValue;
|
||||
}
|
||||
|
||||
double dblRange = pProp->m_fHighValue - pProp->m_fLowValue;
|
||||
double dblRange = pProp->m_fHighValue - pProp->m_fLowValue;
|
||||
|
||||
bool sign = false;
|
||||
bool sign = false;
|
||||
|
||||
if (dblVal < 0.0)
|
||||
{
|
||||
sign = true;
|
||||
dblVal = -dblVal;
|
||||
}
|
||||
if ( dblVal < 0.0 )
|
||||
{
|
||||
sign = true;
|
||||
dblVal = -dblVal;
|
||||
}
|
||||
|
||||
pOut->WriteOneBit(sign);
|
||||
pOut->WriteOneBit( sign );
|
||||
|
||||
WriteNormalizedFloat(dblRange > 1.0 ? (dblVal / dblRange) :
|
||||
dblVal);
|
||||
WriteNormalizedFloat( dblRange > 1.0 ? ( dblVal / dblRange ) : dblVal );
|
||||
}
|
||||
|
||||
// Look for special flags like SPROP_COORD, SPROP_NOSCALE, and SPROP_NORMAL and
|
||||
|
@ -203,73 +198,73 @@ static inline bool DecodeSpecialFloat( SendProp const *pProp, bf_read *pIn, floa
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline float DecodeNormalizedFloat(const SendProp* pProp, bf_read* pIn)
|
||||
static inline float DecodeNormalizedFloat( const SendProp* pProp, bf_read* pIn )
|
||||
{
|
||||
bool sign = pIn->ReadOneBit();
|
||||
double dblVal;
|
||||
bool sign = pIn->ReadOneBit();
|
||||
double dblVal;
|
||||
|
||||
if (!pIn->ReadOneBit())
|
||||
{
|
||||
const auto fractionPart = pIn->ReadUBitLong(20);
|
||||
if ( !pIn->ReadOneBit() )
|
||||
{
|
||||
const auto fractionPart = pIn->ReadUBitLong( 20 );
|
||||
|
||||
char strNumber[8];
|
||||
V_memset(strNumber, 0, sizeof(strNumber));
|
||||
V_sprintf_safe(strNumber, "%i", fractionPart);
|
||||
char strNumber[8];
|
||||
V_memset( strNumber, 0, sizeof( strNumber ) );
|
||||
V_sprintf_safe( strNumber, "%i", fractionPart );
|
||||
|
||||
int countDigits = 0;
|
||||
while (strNumber[countDigits])
|
||||
{
|
||||
countDigits++;
|
||||
}
|
||||
|
||||
int digitLeft = 6 - countDigits;
|
||||
|
||||
if (digitLeft < 0)
|
||||
{
|
||||
Sys_Error("DecodeNormalizedFloat: digitLeft < 0\n");
|
||||
int countDigits = 0;
|
||||
while ( strNumber[countDigits] )
|
||||
{
|
||||
countDigits++;
|
||||
}
|
||||
|
||||
char strFraction[16];
|
||||
strFraction[0] = '0';
|
||||
strFraction[1] = '.';
|
||||
int digitLeft = 6 - countDigits;
|
||||
|
||||
for (int i = 0; i < digitLeft; i++)
|
||||
{
|
||||
strFraction[2 + i] = '0';
|
||||
}
|
||||
if ( digitLeft < 0 )
|
||||
{
|
||||
Sys_Error( "DecodeNormalizedFloat: digitLeft < 0\n" );
|
||||
}
|
||||
|
||||
for (int i = 0; i < countDigits; i++)
|
||||
{
|
||||
strFraction[2 + digitLeft + i] = strNumber[i];
|
||||
}
|
||||
char strFraction[16];
|
||||
strFraction[0] = '0';
|
||||
strFraction[1] = '.';
|
||||
|
||||
dblVal = V_atof(strFraction);
|
||||
}
|
||||
else
|
||||
{
|
||||
dblVal = 1.0;
|
||||
}
|
||||
for ( int i = 0; i < digitLeft; i++ )
|
||||
{
|
||||
strFraction[2 + i] = '0';
|
||||
}
|
||||
|
||||
if (dblVal <= 0.0)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
for ( int i = 0; i < countDigits; i++ )
|
||||
{
|
||||
strFraction[2 + digitLeft + i] = strNumber[i];
|
||||
}
|
||||
|
||||
double dblRange = pProp->m_fHighValue - pProp->m_fLowValue;
|
||||
dblVal = V_atof( strFraction );
|
||||
}
|
||||
else
|
||||
{
|
||||
dblVal = 1.0;
|
||||
}
|
||||
|
||||
if (dblRange > 1.0)
|
||||
{
|
||||
dblVal *= dblRange;
|
||||
}
|
||||
if ( dblVal <= 0.0 )
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if ((pProp->m_fLowValue > 0.0f && pProp->m_fHighValue > 0.0f)
|
||||
|| (pProp->m_fHighValue < 0.0f && pProp->m_fLowValue < 0.0f))
|
||||
{
|
||||
dblVal += pProp->m_fLowValue;
|
||||
}
|
||||
double dblRange = pProp->m_fHighValue - pProp->m_fLowValue;
|
||||
|
||||
dblVal = sign ? -dblVal : dblVal;
|
||||
return static_cast<float>(dblVal);
|
||||
if ( dblRange > 1.0 )
|
||||
{
|
||||
dblVal *= dblRange;
|
||||
}
|
||||
|
||||
if ( ( pProp->m_fLowValue > 0.0f && pProp->m_fHighValue > 0.0f )
|
||||
|| ( pProp->m_fHighValue < 0.0f && pProp->m_fLowValue < 0.0f ) )
|
||||
{
|
||||
dblVal += pProp->m_fLowValue;
|
||||
}
|
||||
|
||||
dblVal = sign ? -dblVal : dblVal;
|
||||
return static_cast< float >( dblVal );
|
||||
}
|
||||
|
||||
static inline float DecodeFloat(const SendProp* pProp, bf_read* pIn)
|
||||
|
|
|
@ -1018,6 +1018,8 @@ if active == 1 then we are 1) not playing back demos ( where our commands are ig
|
|||
|
||||
void CInput::ExtraMouseSample( float frametime, bool active )
|
||||
{
|
||||
VPROF( "CInput::ExtraMouseSample" );
|
||||
|
||||
CUserCmd dummy;
|
||||
CUserCmd *cmd = &dummy;
|
||||
|
||||
|
@ -1125,13 +1127,14 @@ void CInput::ExtraMouseSample( float frametime, bool active )
|
|||
|
||||
void CInput::CreateMove ( int sequence_number, float input_sample_frametime, bool active )
|
||||
{
|
||||
VPROF( "CInput::CreateMove" );
|
||||
|
||||
CUserCmd *cmd = &m_pCommands[ sequence_number % MULTIPLAYER_BACKUP ];
|
||||
CVerifiedUserCmd *pVerified = &m_pVerifiedCommands[ sequence_number % MULTIPLAYER_BACKUP ];
|
||||
|
||||
cmd->Reset();
|
||||
|
||||
cmd->command_number = sequence_number;
|
||||
cmd->tick_count = gpGlobals->tickcount;
|
||||
|
||||
QAngle viewangles;
|
||||
engine->GetViewAngles( viewangles );
|
||||
|
@ -1301,45 +1304,45 @@ void CInput::CreateMove ( int sequence_number, float input_sample_frametime, boo
|
|||
m_EntityGroundContact.RemoveAll();
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < MAX_EDICTS; i++)
|
||||
{
|
||||
for ( int i = 0; i < MAX_EDICTS; i++ )
|
||||
{
|
||||
cmd->simulationdata[i].m_bEntityExists = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Send interpolated simulation time for lag compensation
|
||||
for (int i = 0; i <= ClientEntityList().GetHighestEntityIndex(); i++)
|
||||
{
|
||||
auto pEntity = ClientEntityList().GetEnt(i);
|
||||
// Send interpolated simulation time for lag compensation, let it also auto-vectorize this.
|
||||
for ( int i = 0; i < MAX_EDICTS; i++ )
|
||||
{
|
||||
auto pEntity = ClientEntityList().GetEnt( i );
|
||||
|
||||
if (!pEntity)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ( !pEntity )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
cmd->simulationdata[pEntity->index].m_flSimulationTime = pEntity->m_flInterpolatedSimulationTime;
|
||||
cmd->simulationdata[pEntity->index].m_flAnimTime = pEntity->m_flSimulationTime;
|
||||
cmd->simulationdata[pEntity->index].m_bEntityExists = true;
|
||||
}
|
||||
cmd->simulationdata[pEntity->index].m_flSimulationTime = pEntity->m_flInterpolatedSimulationTime;
|
||||
cmd->simulationdata[pEntity->index].m_flAnimTime = pEntity->m_flSimulationTime;
|
||||
cmd->simulationdata[pEntity->index].m_bEntityExists = true;
|
||||
}
|
||||
|
||||
#ifdef CSTRIKE_DLL
|
||||
static ConVarRef debug_screenshot_bullet_position("debug_screenshot_bullet_position");
|
||||
static ConVarRef cl_showfirebullethitboxes("cl_showfirebullethitboxes");
|
||||
static ConVarRef cl_showimpacts("cl_showimpacts");
|
||||
static ConVarRef debug_screenshot_bullet_position( "debug_screenshot_bullet_position" );
|
||||
static ConVarRef cl_showfirebullethitboxes( "cl_showfirebullethitboxes" );
|
||||
static ConVarRef cl_showimpacts( "cl_showimpacts" );
|
||||
|
||||
cmd->debug_hitboxes = CUserCmd::DEBUG_HITBOXES_OFF;
|
||||
cmd->debug_hitboxes = CUserCmd::DEBUG_HITBOXES_OFF;
|
||||
|
||||
if (cl_showfirebullethitboxes.GetBool())
|
||||
{
|
||||
cmd->debug_hitboxes |= CUserCmd::DEBUG_HITBOXES_ON_FIRE;
|
||||
}
|
||||
if ( cl_showfirebullethitboxes.GetBool() )
|
||||
{
|
||||
cmd->debug_hitboxes |= CUserCmd::DEBUG_HITBOXES_ON_FIRE;
|
||||
}
|
||||
|
||||
if (cl_showimpacts.GetBool() || debug_screenshot_bullet_position.GetBool())
|
||||
{
|
||||
cmd->debug_hitboxes |= CUserCmd::DEBUG_HITBOXES_ON_HIT;
|
||||
}
|
||||
if ( cl_showimpacts.GetBool() || debug_screenshot_bullet_position.GetBool() )
|
||||
{
|
||||
cmd->debug_hitboxes |= CUserCmd::DEBUG_HITBOXES_ON_HIT;
|
||||
}
|
||||
#endif
|
||||
|
||||
cmd->interpolated_amount = gpGlobals->next_interpolation_amount;
|
||||
cmd->interpolated_amount = gpGlobals->next_interpolation_amount;
|
||||
|
||||
pVerified->m_cmd = *cmd;
|
||||
pVerified->m_crc = cmd->GetChecksum();
|
||||
|
|
|
@ -863,10 +863,6 @@ bool UserCmdChanged( const CUserCmd& lhs, const CUserCmd& rhs )
|
|||
return true;
|
||||
if ( lhs.weaponsubtype != rhs.weaponsubtype )
|
||||
return true;
|
||||
if ( lhs.mousedx != rhs.mousedx )
|
||||
return true;
|
||||
if ( lhs.mousedy != rhs.mousedy )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -606,14 +606,6 @@ void CCSPlayer::PlayerRunCommand( CUserCmd *ucmd, IMoveHelper *moveHelper )
|
|||
if ( !sv_runcmds.GetInt() )
|
||||
return;
|
||||
|
||||
// don't run commands in the future
|
||||
if (!IsEngineThreaded()
|
||||
&& (ucmd->tick_count > (gpGlobals->tickcount + sv_max_usercmd_future_ticks.GetInt())) && !IsBot())
|
||||
{
|
||||
DevMsg( "Client cmd out of sync (delta: %i, client: %i != server: %i).\n", ucmd->tick_count - gpGlobals->tickcount, ucmd->tick_count, gpGlobals->tickcount);
|
||||
return;
|
||||
}
|
||||
|
||||
// If they use a negative bot_mimic value, then don't process their usercmds, but have
|
||||
// bots process them instead (so they can stay still and have the bot move around).
|
||||
CUserCmd tempCmd;
|
||||
|
@ -696,7 +688,6 @@ void CCSPlayer::RunPlayerMove( const QAngle& viewangles, float forwardmove, floa
|
|||
{
|
||||
CUserCmd lastCmd = *GetLastUserCommand();
|
||||
lastCmd.command_number = cmd.command_number;
|
||||
lastCmd.tick_count = cmd.tick_count;
|
||||
SetLastUserCommand( lastCmd );
|
||||
}
|
||||
else
|
||||
|
|
|
@ -3274,7 +3274,6 @@ void CBasePlayer::PhysicsSimulate( void )
|
|||
// run the last known cmd for each dropped cmd we don't have a backup for
|
||||
while ( droppedcmds > numbackup )
|
||||
{
|
||||
m_LastCmd.tick_count++;
|
||||
vecAvailCommands.AddToTail( m_LastCmd );
|
||||
droppedcmds--;
|
||||
}
|
||||
|
@ -3527,13 +3526,7 @@ bool CBasePlayer::IsUserCmdDataValid( CUserCmd *pCmd )
|
|||
if ( IsBot() || IsFakeClient() )
|
||||
return true;
|
||||
|
||||
// Maximum difference between client's and server's tick_count
|
||||
const int nCmdMaxTickDelta = ( 1.f / gpGlobals->interval_per_tick ) * 2.5f;
|
||||
const int nMinDelta = Max( 0, gpGlobals->tickcount - nCmdMaxTickDelta );
|
||||
const int nMaxDelta = gpGlobals->tickcount + nCmdMaxTickDelta;
|
||||
|
||||
bool bValid = ( pCmd->tick_count >= nMinDelta && pCmd->tick_count < nMaxDelta ) &&
|
||||
// Prevent clients from sending invalid view angles to try to get leaf server code to crash
|
||||
bool bValid = // Prevent clients from sending invalid view angles to try to get leaf server code to crash
|
||||
( pCmd->viewangles.IsValid() && IsEntityQAngleReasonable( pCmd->viewangles ) ) &&
|
||||
// Movement ranges
|
||||
( IsFinite( pCmd->forwardmove ) && IsEntityCoordinateReasonable( pCmd->forwardmove ) ) &&
|
||||
|
@ -3547,8 +3540,7 @@ bool CBasePlayer::IsUserCmdDataValid( CUserCmd *pCmd )
|
|||
|
||||
if ( nWarningLevel == 2 )
|
||||
{
|
||||
DevMsg( " tick_count: %i\n viewangles: %5.2f %5.2f %5.2f \n forward: %5.2f \n side: \t%5.2f \n up: \t%5.2f\n",
|
||||
pCmd->tick_count,
|
||||
DevMsg( "viewangles: %5.2f %5.2f %5.2f \n forward: %5.2f \n side: \t%5.2f \n up: \t%5.2f\n",
|
||||
pCmd->viewangles.x,
|
||||
pCmd->viewangles.y,
|
||||
pCmd->viewangles.x,
|
||||
|
@ -9230,13 +9222,8 @@ void CPlayerInfo::RunPlayerMove( CBotCmd *ucmd )
|
|||
cmd.buttons = ucmd->buttons;
|
||||
cmd.command_number = ucmd->command_number;
|
||||
cmd.forwardmove = ucmd->forwardmove;
|
||||
cmd.hasbeenpredicted = ucmd->hasbeenpredicted;
|
||||
cmd.impulse = ucmd->impulse;
|
||||
cmd.mousedx = ucmd->mousedx;
|
||||
cmd.mousedy = ucmd->mousedy;
|
||||
cmd.random_seed = ucmd->random_seed;
|
||||
cmd.sidemove = ucmd->sidemove;
|
||||
cmd.tick_count = ucmd->tick_count;
|
||||
cmd.upmove = ucmd->upmove;
|
||||
cmd.viewangles = ucmd->viewangles;
|
||||
cmd.weaponselect = ucmd->weaponselect;
|
||||
|
@ -9273,13 +9260,8 @@ void CPlayerInfo::SetLastUserCommand( const CBotCmd &ucmd )
|
|||
cmd.buttons = ucmd.buttons;
|
||||
cmd.command_number = ucmd.command_number;
|
||||
cmd.forwardmove = ucmd.forwardmove;
|
||||
cmd.hasbeenpredicted = ucmd.hasbeenpredicted;
|
||||
cmd.impulse = ucmd.impulse;
|
||||
cmd.mousedx = ucmd.mousedx;
|
||||
cmd.mousedy = ucmd.mousedy;
|
||||
cmd.random_seed = ucmd.random_seed;
|
||||
cmd.sidemove = ucmd.sidemove;
|
||||
cmd.tick_count = ucmd.tick_count;
|
||||
cmd.upmove = ucmd.upmove;
|
||||
cmd.viewangles = ucmd.viewangles;
|
||||
cmd.weaponselect = ucmd.weaponselect;
|
||||
|
@ -9299,13 +9281,9 @@ CBotCmd CPlayerInfo::GetLastUserCommand()
|
|||
cmd.buttons = ucmd->buttons;
|
||||
cmd.command_number = ucmd->command_number;
|
||||
cmd.forwardmove = ucmd->forwardmove;
|
||||
cmd.hasbeenpredicted = ucmd->hasbeenpredicted;
|
||||
cmd.impulse = ucmd->impulse;
|
||||
cmd.mousedx = ucmd->mousedx;
|
||||
cmd.mousedy = ucmd->mousedy;
|
||||
cmd.random_seed = ucmd->random_seed;
|
||||
cmd.sidemove = ucmd->sidemove;
|
||||
cmd.tick_count = ucmd->tick_count;
|
||||
cmd.upmove = ucmd->upmove;
|
||||
cmd.viewangles = ucmd->viewangles;
|
||||
cmd.weaponselect = ucmd->weaponselect;
|
||||
|
|
|
@ -450,6 +450,8 @@ void CCSPlayer::FireBullet(
|
|||
float xSpread, float ySpread
|
||||
)
|
||||
{
|
||||
VPROF( "CCSPlayer::FireBullet" );
|
||||
|
||||
float fCurrentDamage = iDamage; // damage of the bullet at it's current trajectory
|
||||
float flCurrentDistance = 0.0; //distance that the bullet has traveled so far
|
||||
|
||||
|
|
|
@ -45,17 +45,6 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
|
|||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
|
||||
if ( to->tick_count != ( from->tick_count + 1 ) )
|
||||
{
|
||||
buf->WriteOneBit( 1 );
|
||||
buf->WriteUBitLong( to->tick_count, 32 );
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
|
||||
|
||||
if ( to->viewangles[ 0 ] != from->viewangles[ 0 ] )
|
||||
{
|
||||
buf->WriteOneBit( 1 );
|
||||
|
@ -157,82 +146,61 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
|
|||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
|
||||
|
||||
// TODO: Can probably get away with fewer bits.
|
||||
if ( to->mousedx != from->mousedx )
|
||||
{
|
||||
buf->WriteOneBit( 1 );
|
||||
buf->WriteShort( to->mousedx );
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
|
||||
if ( to->mousedy != from->mousedy )
|
||||
{
|
||||
buf->WriteOneBit( 1 );
|
||||
buf->WriteShort( to->mousedy );
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
int highestEntityIndex = 0;
|
||||
if (cl_entitylist)
|
||||
highestEntityIndex = cl_entitylist->GetHighestEntityIndex();
|
||||
int highestEntityIndex = 0;
|
||||
if ( cl_entitylist )
|
||||
{
|
||||
highestEntityIndex = cl_entitylist->GetHighestEntityIndex();
|
||||
}
|
||||
#else
|
||||
static constexpr auto highestEntityIndex = MAX_EDICTS-1;
|
||||
static constexpr auto highestEntityIndex = MAX_EDICTS - 1;
|
||||
#endif
|
||||
|
||||
// Write entity count
|
||||
buf->WriteUBitLong(highestEntityIndex, 11);
|
||||
// Write entity count
|
||||
buf->WriteUBitLong( highestEntityIndex, 11 );
|
||||
|
||||
// Write finally simulation data with entity index
|
||||
for (unsigned int i = 0; i <= highestEntityIndex; i++)
|
||||
{
|
||||
if (from->simulationdata[i].m_flSimulationTime != to->simulationdata[i].m_flSimulationTime)
|
||||
{
|
||||
buf->WriteOneBit(1);
|
||||
buf->WriteBitFloat(to->simulationdata[i].m_flSimulationTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit(0);
|
||||
}
|
||||
|
||||
if (from->simulationdata[i].m_flAnimTime != to->simulationdata[i].m_flAnimTime)
|
||||
{
|
||||
buf->WriteOneBit(1);
|
||||
buf->WriteBitFloat(to->simulationdata[i].m_flAnimTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (to->debug_hitboxes != from->debug_hitboxes)
|
||||
{
|
||||
buf->WriteOneBit(1);
|
||||
buf->WriteUBitLong(to->debug_hitboxes, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit(0);
|
||||
}
|
||||
|
||||
if (from->interpolated_amount != to->interpolated_amount)
|
||||
// Write finally simulation data with entity index
|
||||
for ( unsigned int i = 0; i <= highestEntityIndex; i++ )
|
||||
{
|
||||
buf->WriteOneBit(1);
|
||||
buf->WriteBitFloat(to->interpolated_amount);
|
||||
if ( from->simulationdata[i].m_flSimulationTime != to->simulationdata[i].m_flSimulationTime )
|
||||
{
|
||||
buf->WriteOneBit( 1 );
|
||||
buf->WriteBitFloat( to->simulationdata[i].m_flSimulationTime );
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
|
||||
if ( from->simulationdata[i].m_flAnimTime != to->simulationdata[i].m_flAnimTime )
|
||||
{
|
||||
buf->WriteOneBit( 1 );
|
||||
buf->WriteBitFloat( to->simulationdata[i].m_flAnimTime );
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( to->debug_hitboxes != from->debug_hitboxes )
|
||||
{
|
||||
buf->WriteOneBit( 1 );
|
||||
buf->WriteUBitLong( to->debug_hitboxes, 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit(0);
|
||||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
|
||||
if ( from->interpolated_amount != to->interpolated_amount )
|
||||
{
|
||||
buf->WriteOneBit( 1 );
|
||||
buf->WriteBitFloat( to->interpolated_amount );
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
|
||||
#if defined( HL2_CLIENT_DLL )
|
||||
|
@ -277,16 +245,6 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
|
|||
move->command_number = from->command_number + 1;
|
||||
}
|
||||
|
||||
if ( buf->ReadOneBit() )
|
||||
{
|
||||
move->tick_count = buf->ReadUBitLong( 32 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Assume steady increment
|
||||
move->tick_count = from->tick_count + 1;
|
||||
}
|
||||
|
||||
// Read direction
|
||||
if ( buf->ReadOneBit() )
|
||||
{
|
||||
|
@ -332,7 +290,6 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
|
|||
move->impulse = buf->ReadUBitLong( 8 );
|
||||
}
|
||||
|
||||
|
||||
if ( buf->ReadOneBit() )
|
||||
{
|
||||
move->weaponselect = buf->ReadUBitLong( MAX_EDICT_BITS );
|
||||
|
@ -344,17 +301,9 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
|
|||
|
||||
move->random_seed = MD5_PseudoRandom( move->command_number ) & 0x7fffffff;
|
||||
|
||||
if ( buf->ReadOneBit() )
|
||||
{
|
||||
move->mousedx = buf->ReadShort();
|
||||
}
|
||||
auto highestEntityIndex = buf->ReadUBitLong( 11 );
|
||||
|
||||
if ( buf->ReadOneBit() )
|
||||
{
|
||||
move->mousedy = buf->ReadShort();
|
||||
}
|
||||
|
||||
const auto highestEntityIndex = buf->ReadUBitLong(11);
|
||||
highestEntityIndex = MIN(MAX_EDICTS - 1, highestEntityIndex);
|
||||
|
||||
for (unsigned int i = 0; i <= highestEntityIndex; i++)
|
||||
{
|
||||
|
|
|
@ -46,17 +46,17 @@ struct LayerRecord
|
|||
LayerRecord()
|
||||
{
|
||||
m_sequence = 0;
|
||||
m_cycle = 0;
|
||||
m_weight = 0;
|
||||
m_order = 0;
|
||||
m_cycle = 0;
|
||||
m_weight = 0;
|
||||
m_order = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct SimulationData
|
||||
{
|
||||
// TODO_ENHANCED:
|
||||
// For now we send the last received update for animations.
|
||||
// anim time is unreliable on low fps.
|
||||
// TODO_ENHANCED:
|
||||
// For now we send the last received update for animations.
|
||||
// anim time is unreliable on low fps.
|
||||
float m_flSimulationTime;
|
||||
float m_flAnimTime;
|
||||
bool m_bEntityExists;
|
||||
|
@ -83,7 +83,6 @@ public:
|
|||
void Reset()
|
||||
{
|
||||
command_number = 0;
|
||||
tick_count = 0;
|
||||
viewangles.Init();
|
||||
forwardmove = 0.0f;
|
||||
sidemove = 0.0f;
|
||||
|
@ -116,7 +115,6 @@ public:
|
|||
return *this;
|
||||
|
||||
command_number = src.command_number;
|
||||
tick_count = src.tick_count;
|
||||
viewangles = src.viewangles;
|
||||
forwardmove = src.forwardmove;
|
||||
sidemove = src.sidemove;
|
||||
|
@ -155,7 +153,6 @@ public:
|
|||
|
||||
CRC32_Init( &crc );
|
||||
CRC32_ProcessBuffer( &crc, &command_number, sizeof( command_number ) );
|
||||
CRC32_ProcessBuffer( &crc, &tick_count, sizeof( tick_count ) );
|
||||
CRC32_ProcessBuffer( &crc, &viewangles, sizeof( viewangles ) );
|
||||
CRC32_ProcessBuffer( &crc, &forwardmove, sizeof( forwardmove ) );
|
||||
CRC32_ProcessBuffer( &crc, &sidemove, sizeof( sidemove ) );
|
||||
|
@ -165,11 +162,9 @@ public:
|
|||
CRC32_ProcessBuffer( &crc, &weaponselect, sizeof( weaponselect ) );
|
||||
CRC32_ProcessBuffer( &crc, &weaponsubtype, sizeof( weaponsubtype ) );
|
||||
CRC32_ProcessBuffer( &crc, &random_seed, sizeof( random_seed ) );
|
||||
CRC32_ProcessBuffer( &crc, &mousedx, sizeof( mousedx ) );
|
||||
CRC32_ProcessBuffer(&crc, &mousedy, sizeof(mousedy));
|
||||
CRC32_ProcessBuffer(&crc, simulationdata, sizeof(simulationdata));
|
||||
CRC32_ProcessBuffer(&crc, &debug_hitboxes, sizeof(debug_hitboxes));
|
||||
CRC32_ProcessBuffer(&crc, &interpolated_amount, sizeof(interpolated_amount));
|
||||
CRC32_ProcessBuffer( &crc, simulationdata, sizeof( simulationdata ) );
|
||||
CRC32_ProcessBuffer( &crc, &debug_hitboxes, sizeof( debug_hitboxes ) );
|
||||
CRC32_ProcessBuffer( &crc, &interpolated_amount, sizeof( interpolated_amount ) );
|
||||
CRC32_Final( &crc );
|
||||
|
||||
return crc;
|
||||
|
@ -178,22 +173,12 @@ public:
|
|||
// Allow command, but negate gameplay-affecting values
|
||||
void MakeInert( void )
|
||||
{
|
||||
viewangles = vec3_angle;
|
||||
forwardmove = 0.f;
|
||||
sidemove = 0.f;
|
||||
upmove = 0.f;
|
||||
buttons = 0;
|
||||
impulse = 0;
|
||||
debug_hitboxes = DEBUG_HITBOXES_OFF;
|
||||
interpolated_amount = 0.0f;
|
||||
Reset();
|
||||
}
|
||||
|
||||
// For matching server and client commands for debugging
|
||||
int command_number;
|
||||
|
||||
// the tick the client created this command
|
||||
int tick_count;
|
||||
|
||||
// Player instantaneous view angles.
|
||||
QAngle viewangles;
|
||||
// Intended velocities
|
||||
|
@ -219,21 +204,21 @@ public:
|
|||
// Client only, tracks whether we've predicted this command at least once
|
||||
bool hasbeenpredicted;
|
||||
|
||||
// TODO_ENHANCED: Lag compensate also other entities when needed.
|
||||
// Send simulation times for each players for lag compensation.
|
||||
// TODO_ENHANCED: Lag compensate also other entities when needed.
|
||||
// Send simulation times for each players for lag compensation.
|
||||
SimulationData simulationdata[MAX_EDICTS];
|
||||
|
||||
enum debug_hitboxes_t : uint8
|
||||
{
|
||||
enum debug_hitboxes_t : uint8
|
||||
{
|
||||
DEBUG_HITBOXES_OFF,
|
||||
DEBUG_HITBOXES_ON_FIRE = 1 << 0,
|
||||
DEBUG_HITBOXES_ON_HIT = 1 << 1
|
||||
DEBUG_HITBOXES_ON_FIRE = 1 << 0,
|
||||
DEBUG_HITBOXES_ON_HIT = 1 << 1
|
||||
};
|
||||
|
||||
uint8 debug_hitboxes;
|
||||
|
||||
// TODO_ENHANCED: check README_ENHANCED in host.cpp!
|
||||
float interpolated_amount;
|
||||
// TODO_ENHANCED: check README_ENHANCED in host.cpp!
|
||||
float interpolated_amount;
|
||||
|
||||
// Back channel to communicate IK state
|
||||
#if defined( HL2_DLL ) || defined( HL2_CLIENT_DLL )
|
||||
|
|
|
@ -25,7 +25,6 @@ public:
|
|||
void Reset()
|
||||
{
|
||||
command_number = 0;
|
||||
tick_count = 0;
|
||||
viewangles.Init();
|
||||
forwardmove = 0.0f;
|
||||
sidemove = 0.0f;
|
||||
|
@ -35,10 +34,6 @@ public:
|
|||
weaponselect = 0;
|
||||
weaponsubtype = 0;
|
||||
random_seed = 0;
|
||||
mousedx = 0;
|
||||
mousedy = 0;
|
||||
|
||||
hasbeenpredicted = false;
|
||||
}
|
||||
|
||||
CBotCmd& operator =( const CBotCmd& src )
|
||||
|
@ -47,7 +42,6 @@ public:
|
|||
return *this;
|
||||
|
||||
command_number = src.command_number;
|
||||
tick_count = src.tick_count;
|
||||
viewangles = src.viewangles;
|
||||
forwardmove = src.forwardmove;
|
||||
sidemove = src.sidemove;
|
||||
|
@ -57,18 +51,12 @@ public:
|
|||
weaponselect = src.weaponselect;
|
||||
weaponsubtype = src.weaponsubtype;
|
||||
random_seed = src.random_seed;
|
||||
mousedx = src.mousedx;
|
||||
mousedy = src.mousedy;
|
||||
hasbeenpredicted = src.hasbeenpredicted;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// For matching server and client commands for debugging
|
||||
int command_number;
|
||||
|
||||
// the tick the client created this command
|
||||
int tick_count;
|
||||
|
||||
// Player instantaneous view angles.
|
||||
QAngle viewangles;
|
||||
// Intended velocities
|
||||
|
@ -87,12 +75,6 @@ public:
|
|||
int weaponsubtype;
|
||||
|
||||
int random_seed; // For shared random functions
|
||||
|
||||
short mousedx; // mouse accum in x from create move
|
||||
short mousedy; // mouse accum in y from create move
|
||||
|
||||
// Client only, tracks whether we've predicted this command at least once
|
||||
bool hasbeenpredicted;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue