r5sdk/r5dev/game/shared/usercmd.cpp
Kawe Mazidjatari a2468bb184 Normalize view angles in client's usercmd
Must be normalized, bad values (NAN or FLT_MAX) will crash the game. There is more that needs to be clamped, but before we can do this CUserCmd has to be reversed more.
2023-06-06 00:53:05 +02:00

50 lines
1.5 KiB
C++
Raw Blame History

//====== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. =======//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "usercmd.h"
//-----------------------------------------------------------------------------
// Purpose: Read in a delta compressed usercommand.
// Input : *buf -
// *move -
// *from -
// Output : random seed
//-----------------------------------------------------------------------------
int ReadUserCmd(bf_read* buf, CUserCmd* move, CUserCmd* from)
{
// Normalize angles, bogus values will crash the game..
from->viewangles.Normalize();
// More clamps coming soon...
const int seed = v_ReadUserCmd(buf, move, from);
// On the client, the frame time must be within 'usercmd_frametime_min'
// and 'usercmd_frametime_max'. Testing revealed that speed hacking could
// be achieved by sending bogus frametimes. Clamp the networked frame time
// to the exact values that the client should be using to make sure it
// couldn't be circumvented by busting out the client side clamps.
if (host_timescale->GetFloat() == 1.0f)
move->frametime = clamp(move->frametime,
usercmd_frametime_min->GetFloat(),
usercmd_frametime_max->GetFloat());
return seed;
}
//-----------------------------------------------------------------------------
void VUserCmd::Attach() const
{
DetourAttach(&v_ReadUserCmd, &ReadUserCmd);
}
void VUserCmd::Detach() const
{
DetourDetach(&v_ReadUserCmd, &ReadUserCmd);
}