2021-12-25 22:36:38 +01:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: Interface the engine exposes to the game DLL
|
|
|
|
//
|
|
|
|
//=============================================================================//
|
|
|
|
|
|
|
|
#include "core/stdafx.h"
|
2023-11-25 17:41:08 +01:00
|
|
|
#include "engine/cmd.h"
|
2023-05-10 00:05:38 +02:00
|
|
|
#include "clientstate.h"
|
|
|
|
#include "vengineclient_impl.h"
|
2022-05-06 00:34:46 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: define if commands from the server should be restricted or not.
|
|
|
|
// Input : bRestricted -
|
|
|
|
// Output :
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
void CEngineClient::SetRestrictServerCommands(bool bRestricted)
|
|
|
|
{
|
2022-08-15 22:29:16 +02:00
|
|
|
g_pClientState->m_bRestrictServerCommands = bRestricted;
|
2022-05-06 00:34:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: get value for if commands are restricted from servers.
|
|
|
|
// Input :
|
|
|
|
// Output : bool
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-07 12:28:58 +02:00
|
|
|
bool CEngineClient::GetRestrictServerCommands() const
|
2022-05-06 00:34:46 +02:00
|
|
|
{
|
2022-08-15 22:29:16 +02:00
|
|
|
return g_pClientState->m_bRestrictServerCommands;
|
2022-05-06 00:34:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: define if commands on the client should be restricted or not.
|
|
|
|
// Input : bRestricted -
|
|
|
|
// Output :
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
void CEngineClient::SetRestrictClientCommands(bool bRestricted)
|
|
|
|
{
|
2022-08-15 22:29:16 +02:00
|
|
|
g_pClientState->m_bRestrictClientCommands = bRestricted;
|
2022-05-06 00:34:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: get value for if commands are restricted for clients.
|
|
|
|
// Input :
|
|
|
|
// Output : bool
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-07 12:28:58 +02:00
|
|
|
bool CEngineClient::GetRestrictClientCommands() const
|
2022-05-06 00:34:46 +02:00
|
|
|
{
|
2022-08-15 22:29:16 +02:00
|
|
|
return g_pClientState->m_bRestrictClientCommands;
|
2022-05-06 00:34:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: get local player
|
|
|
|
// Input :
|
2022-07-24 14:05:38 +02:00
|
|
|
// Output : int
|
2022-05-06 00:34:46 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
2022-07-24 14:05:38 +02:00
|
|
|
int CEngineClient::GetLocalPlayer()
|
2022-05-06 00:34:46 +02:00
|
|
|
{
|
2022-08-31 14:38:49 +02:00
|
|
|
const static int index = 36;
|
2022-07-24 14:05:38 +02:00
|
|
|
return CallVFunc<int>(index, this);
|
2023-11-25 17:41:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: execute client command
|
|
|
|
// Input : *thisptr -
|
|
|
|
// *szCmdString -
|
|
|
|
// Output :
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
void CEngineClient::_ClientCmd(CEngineClient* thisptr, const char* const szCmdString)
|
|
|
|
{
|
|
|
|
const bool restrictClientCommands = g_pClientState->m_bRestrictClientCommands;
|
|
|
|
const int numMarkers = 2;
|
|
|
|
|
|
|
|
if (restrictClientCommands && !Cbuf_HasRoomForExecutionMarkers(numMarkers))
|
|
|
|
{
|
|
|
|
DevWarning(eDLL_T::CLIENT, "%s: No room for %i execution markers; command \"%s\" ignored\n",
|
|
|
|
__FUNCTION__, numMarkers, szCmdString);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restrictClientCommands)
|
|
|
|
{
|
|
|
|
Cbuf_AddExecutionMarker(Cbuf_GetCurrentPlayer(), eCmdExecutionMarker_Enable_FCVAR_CLIENTCMD_CAN_EXECUTE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), szCmdString, cmd_source_t::kCommandSrcCode);
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "\n", cmd_source_t::kCommandSrcCode);
|
|
|
|
|
|
|
|
if (restrictClientCommands)
|
|
|
|
{
|
|
|
|
Cbuf_AddExecutionMarker(Cbuf_GetCurrentPlayer(), eCmdExecutionMarker_Disable_FCVAR_CLIENTCMD_CAN_EXECUTE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-26 13:21:20 +01:00
|
|
|
void HVEngineClient::Detour(const bool bAttach) const
|
2023-11-25 17:41:08 +01:00
|
|
|
{
|
2023-11-26 13:21:20 +01:00
|
|
|
DetourSetup(&CEngineClient__ClientCmd, &CEngineClient::_ClientCmd, bAttach);
|
2023-11-25 17:41:08 +01:00
|
|
|
}
|