From 808be9442f60b4388f68fcef8b2659d0cd6db17b Mon Sep 17 00:00:00 2001 From: a1batross Date: Sun, 24 Apr 2022 01:43:45 +0300 Subject: [PATCH] Use filtered command buffer when string came from network (#241) * cdll_int: add undocumented FilteredClientCmd function to client interface * client: use filtered command buffer where we have to execute command from server * client: use normal pfnClientCmd in place of pfnFilteredClientCmd in case of engine doesn't supports it * client: don't read out of bounds if engine interface is old and don't have pfnFilteredClientCmd * client: fix incorrect cvar pointer comparison --- cl_dll/cdll_int.cpp | 12 +++++++++++- cl_dll/hud_spectator.cpp | 2 +- cl_dll/vgui_TeamFortressViewport.h | 2 +- engine/cdll_int.h | 3 +++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cl_dll/cdll_int.cpp b/cl_dll/cdll_int.cpp index 23da5ae7..17fc06f3 100644 --- a/cl_dll/cdll_int.cpp +++ b/cl_dll/cdll_int.cpp @@ -167,7 +167,17 @@ int DLLEXPORT Initialize( cl_enginefunc_t *pEnginefuncs, int iVersion ) if( iVersion != CLDLL_INTERFACE_VERSION ) return 0; - memcpy( &gEngfuncs, pEnginefuncs, sizeof(cl_enginefunc_t) ); + // for now filterstuffcmd is last in the engine interface + memcpy( &gEngfuncs, pEnginefuncs, sizeof(cl_enginefunc_t) - sizeof( void * ) ); + + if( gEngfuncs.pfnGetCvarPointer( "cl_filterstuffcmd" ) == 0 ) + { + gEngfuncs.pfnFilteredClientCmd = gEngfuncs.pfnClientCmd; + } + else + { + gEngfuncs.pfnFilteredClientCmd = pEnginefuncs->pfnFilteredClientCmd; + } EV_HookEvents(); diff --git a/cl_dll/hud_spectator.cpp b/cl_dll/hud_spectator.cpp index bfd8112b..c20e6ba0 100644 --- a/cl_dll/hud_spectator.cpp +++ b/cl_dll/hud_spectator.cpp @@ -577,7 +577,7 @@ void CHudSpectator::DirectorMessage( int iSize, void *pbuf ) case DRC_CMD_FADE: break; case DRC_CMD_STUFFTEXT: - ClientCmd( READ_STRING() ); + gEngfuncs.pfnFilteredClientCmd( READ_STRING() ); break; default: gEngfuncs.Con_DPrintf( "CHudSpectator::DirectorMessage: unknown command %i.\n", cmd ); diff --git a/cl_dll/vgui_TeamFortressViewport.h b/cl_dll/vgui_TeamFortressViewport.h index 39c6b26f..ee295b59 100644 --- a/cl_dll/vgui_TeamFortressViewport.h +++ b/cl_dll/vgui_TeamFortressViewport.h @@ -667,7 +667,7 @@ public: virtual void actionPerformed(Panel *panel) { - gEngfuncs.pfnClientCmd( m_pszCommand ); + gEngfuncs.pfnFilteredClientCmd( m_pszCommand ); if( m_iCloseVGUIMenu ) gViewPort->HideTopMenu(); diff --git a/engine/cdll_int.h b/engine/cdll_int.h index 02d277dd..64620497 100644 --- a/engine/cdll_int.h +++ b/engine/cdll_int.h @@ -303,6 +303,9 @@ typedef struct cl_enginefuncs_s int (*pfnGetAppID)( void ); cmdalias_t *(*pfnGetAliases)( void ); void (*pfnVguiWrap2_GetMouseDelta)( int *x, int *y ); + + // added in 2019 update, not documented yet + int (*pfnFilteredClientCmd)( const char *cmd ); } cl_enginefunc_t; #define CLDLL_INTERFACE_VERSION 7