Mask off FCVAR_DEVELOPMENTONLY from essential commands

Only mask FCVAR_DEVELOPMENTONLY off from essential commands if launched in retail mode (this hardens security and increases performance).
This commit is contained in:
Kawe Mazidjatari 2022-08-13 21:38:44 +02:00
parent 515487c63a
commit 8068bcf176
5 changed files with 77 additions and 21 deletions

View File

@ -214,10 +214,16 @@ void ConVar::InitShipped(void) const
ai_script_nodes_draw = g_pCVar->FindVar("ai_script_nodes_draw");
bhit_enable = g_pCVar->FindVar("bhit_enable");
#endif // !CLIENT_DLL
#ifndef DEDICATED
cl_threaded_bone_setup = g_pCVar->FindVar("cl_threaded_bone_setup");
#endif // !DEDICATED
single_frame_shutdown_for_reload = g_pCVar->FindVar("single_frame_shutdown_for_reload");
enable_debug_overlays = g_pCVar->FindVar("enable_debug_overlays");
model_defaultFadeDistScale = g_pCVar->FindVar("model_defaultFadeDistScale");
model_defaultFadeDistMin = g_pCVar->FindVar("model_defaultFadeDistMin");
#ifndef DEDICATED
rui_defaultDebugFontFace = g_pCVar->FindVar("rui_defaultDebugFontFace");
#endif // !DEDICATED
staticProp_no_fade_scalar = g_pCVar->FindVar("staticProp_no_fade_scalar");
staticProp_gather_size_weight = g_pCVar->FindVar("staticProp_gather_size_weight");
stream_overlay = g_pCVar->FindVar("stream_overlay");
@ -234,6 +240,10 @@ void ConVar::InitShipped(void) const
#ifndef CLIENT_DLL
ai_script_nodes_draw->SetValue(-1);
#endif // !CLIENT_DLL
#ifndef DEDICATED
cl_threaded_bone_setup->RemoveFlags(FCVAR_DEVELOPMENTONLY);
rui_defaultDebugFontFace->RemoveFlags(FCVAR_DEVELOPMENTONLY);
#endif // !DEDICATED
mp_gamemode->RemoveChangeCallback(mp_gamemode->m_fnChangeCallbacks[0]);
mp_gamemode->InstallChangeCallback(MP_GameMode_Changed_f, false);
}

View File

@ -7,6 +7,7 @@
#include "core/stdafx.h"
#include "tier0/tslist.h"
#include "tier0/memstd.h"
#include "tier0/commandline.h"
#include "tier1/cmd.h"
#include "tier1/cvar.h"
#include "tier1/characterset.h"
@ -287,7 +288,7 @@ ConCommand* ConCommand::Create(const char* pszName, const char* pszHelpString, i
pCommand->m_bUsingCommandCallbackInterface = false;
pCommand->m_fnCompletionCallback = pCompletionFunc ? pCompletionFunc : CallbackStub;
ConCommandBase_Init(pCommand);
g_pCVar->RegisterConCommand(pCommand);
return pCommand;
}
@ -373,17 +374,66 @@ void ConCommand::Init(void)
//-----------------------------------------------------------------------------
void ConCommand::InitShipped(void)
{
///------------------------------------------------------ [ CALLBACK SWAP ]
//-------------------------------------------------------------------------
// ENGINE DLL |
g_pCVar->FindCommand("help")->m_fnCommandCallback = CVHelp_f;
g_pCVar->FindCommand("convar_list")->m_fnCommandCallback = CVList_f;
g_pCVar->FindCommand("convar_differences")->m_fnCommandCallback = CVDiff_f;
g_pCVar->FindCommand("convar_findByFlags")->m_fnCommandCallback = CVFlag_f;
ConCommand* help = g_pCVar->FindCommand("help");
ConCommand* convar_list = g_pCVar->FindCommand("convar_list");
ConCommand* convar_differences = g_pCVar->FindCommand("convar_differences");
ConCommand* convar_findByFlags = g_pCVar->FindCommand("convar_findByFlags");
#ifndef DEDICATED
//-------------------------------------------------------------------------
// MATERIAL SYSTEM
g_pCVar->FindCommand("mat_crosshair")->m_fnCommandCallback = Mat_CrossHair_f; // Patch callback function to working callback.
ConCommand* mat_crosshair = g_pCVar->FindCommand("mat_crosshair"); // Patch callback function to working callback.
mat_crosshair->m_fnCommandCallback = Mat_CrossHair_f;
#endif // !DEDICATED
help->m_fnCommandCallback = CVHelp_f;
convar_list->m_fnCommandCallback = CVList_f;
convar_differences->m_fnCommandCallback = CVDiff_f;
convar_findByFlags->m_fnCommandCallback = CVFlag_f;
/// ------------------------------------------------------ [ FLAG REMOVAL ]
//-------------------------------------------------------------------------
if (!CommandLine()->CheckParm("-devsdk"))
{
const char* pszMaskedBases[] =
{
"changelevel",
#ifndef DEDICATED
"connect",
"connectAsSpectator",
"connectWithKey",
#endif // !DEDICATED
"exit",
"map",
"map_background",
#ifndef DEDICATED
"ping",
#endif // !DEDICATED
"quit",
"restart",
"status",
#ifndef DEDICATED
"set",
"silentconnect",
#endif // !DEDICATED
"version",
};
for (size_t i = 0; i < SDK_ARRAYSIZE(pszMaskedBases); i++)
{
if (ConCommandBase* pCommandBase = g_pCVar->FindCommandBase(pszMaskedBases[i]))
{
pCommandBase->RemoveFlags(FCVAR_DEVELOPMENTONLY);
}
}
help->RemoveFlags(FCVAR_DEVELOPMENTONLY);
convar_list->RemoveFlags(FCVAR_DEVELOPMENTONLY);
convar_differences->RemoveFlags(FCVAR_DEVELOPMENTONLY);
convar_findByFlags->RemoveFlags(FCVAR_DEVELOPMENTONLY);
}
}
//-----------------------------------------------------------------------------
@ -439,7 +489,7 @@ void ConCommand::PurgeShipped(void) const
"-scriptCommand9",
};
for (int i = 0; i < (&pszCommandToRemove)[1] - pszCommandToRemove; i++)
for (size_t i = 0; i < SDK_ARRAYSIZE(pszCommandToRemove); i++)
{
ConCommandBase* pCommandBase = g_pCVar->FindCommandBase(pszCommandToRemove[i]);

View File

@ -165,15 +165,9 @@ inline CMemory p_Cbuf_Execute;
inline auto Cbuf_Execute = p_Cbuf_Execute.RCast<void (*)(void)>();
/* ==== CONCOMMAND ====================================================================================================================================================== */
inline CMemory p_ConCommandBase_Init;
inline auto ConCommandBase_Init = p_ConCommandBase_Init.RCast<void* (*)(ConCommand* pCommand)>();
inline CMemory p_ConCommandBase_IsFlagSet;
inline auto ConCommandBase_IsFlagSet = p_ConCommandBase_IsFlagSet.RCast<bool (*)(ConCommandBase* pCommand, int nFlag)>();
inline CMemory p_ConCommand_CMaterialSystemCmdInit;
inline auto ConCommand_CMaterialSystemCmdInit = p_ConCommand_CMaterialSystemCmdInit.RCast<ConCommand* (*)(void)>();
inline CMemory p_NullSub;
inline auto NullSub = p_NullSub.RCast<void(*)(void)>();
@ -198,9 +192,7 @@ class VConCommand : public IDetour
spdlog::debug("| FUN: Cbuf_AddText : {:#18x} |\n", p_Cbuf_AddText.GetPtr());
spdlog::debug("| FUN: Cbuf_Execute : {:#18x} |\n", p_Cbuf_Execute.GetPtr());
spdlog::debug("+----------------------------------------------------------------+\n");
spdlog::debug("| FUN: ConCommandBase::Init : {:#18x} |\n", p_ConCommandBase_Init.GetPtr());
spdlog::debug("| FUN: ConCommandBase::IsFlagSet : {:#18x} |\n", p_ConCommandBase_IsFlagSet.GetPtr());
spdlog::debug("| FUN: ConCommand::CMaterialSystemCmdInit : {:#18x} |\n", p_ConCommand_CMaterialSystemCmdInit.GetPtr());
spdlog::debug("+----------------------------------------------------------------+\n");
spdlog::debug("| FUN: CallbackStub : {:#18x} |\n", p_CallbackStub.GetPtr());
spdlog::debug("| FUN: NullSub : {:#18x} |\n", p_NullSub.GetPtr());
@ -212,23 +204,21 @@ class VConCommand : public IDetour
{
p_Cbuf_AddText = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x20\x48\x63\xD9\x41\x8B\xF8\x48\x8D\x0D\x00\x00\x00\x00\x48\x8B\xF2\xFF\x15\x00\x00\x00\x00\x48\x8D\x05\x00\x00\x00\x00\x41\xB9\x00\x00\x00\x00"), "xxxx?xxxx?xxxxxxxxxxxxxx????xxxxx????xxx????xx????");
p_Cbuf_Execute = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x20\xFF\x15\x00\x00\x00\x00"), "xxxx?xxxx?xxxx?xxxxxxx????");
p_ConCommandBase_Init = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x8B\xD1\x48\x8B\x0D\x00\x00\x00\x00\x48\x85\xC9\x74\x06"), "xxxxxx????xxxxx");
p_ConCommandBase_IsFlagSet = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x85\x51\x38\x0F\x95\xC0\xC3"), "xxxxxxx");
p_ConCommand_CMaterialSystemCmdInit = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x55\x41\x54\x41\x55\x41\x56\x41\x57\x48\x8B\xEC\x48\x83\xEC\x50\x48\x8B\x15\x00\x00\x00\x00"), "xxxx?xxxx?xxxx?xxxxxxxxxxxxxxxxxxx????");
p_NullSub = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\xC2\x00\x00\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x40\x53\x48\x83\xEC\x20\x48\x8D\x05\x00\x00\x00\x00"), "xxxxxxxxxxxxxxxxxxxxxxxxx????");
p_CallbackStub = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x33\xC0\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x80\x49\x68\x08"), "xxxxxxxxxxxxxxxxxxxx");
Cbuf_AddText = p_Cbuf_AddText.RCast<void (*)(ECommandTarget_t, const char*, cmd_source_t)>(); /*48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 48 63 D9 41 8B F8 48 8D 0D ?? ?? ?? ?? 48 8B F2 FF 15 ?? ?? ?? ?? 48 8D 05 ?? ?? ?? ?? 41 B9 ?? ?? ?? ??*/
Cbuf_Execute = p_Cbuf_Execute.RCast<void (*)(void)>(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 FF 15 ?? ?? ?? ??*/
ConCommandBase_Init = p_ConCommandBase_Init.RCast<void* (*)(ConCommand*)>(); /*48 8B D1 48 8B 0D ?? ?? ?? ?? 48 85 C9 74 06*/
ConCommandBase_IsFlagSet = p_ConCommandBase_IsFlagSet.RCast<bool (*)(ConCommandBase*, int)>(); /*85 51 38 0F 95 C0 C3*/
ConCommand_CMaterialSystemCmdInit = p_ConCommand_CMaterialSystemCmdInit.RCast<ConCommand* (*)(void)>(); /*48 89 5C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 55 41 54 41 55 41 56 41 57 48 8B EC 48 83 EC 50 48 8B 15 ?? ?? ?? ??*/
NullSub = p_NullSub.RCast<void(*)(void)>(); /*C2 00 00 CC CC CC CC CC CC CC CC CC CC CC CC CC 40 53 48 83 EC 20 48 8D 05 ?? ?? ?? ??*/
CallbackStub = p_CallbackStub.RCast<FnCommandCompletionCallback>(); /*33 C0 C3 CC CC CC CC CC CC CC CC CC CC CC CC CC 80 49 68 08*/ /*UserMathErrorFunction*/
}
virtual void GetVar(void) const
{
g_pConCommandVtable = p_ConCommand_CMaterialSystemCmdInit.FindPatternSelf("4C 8D 25", CMemory::Direction::DOWN, 150).ResolveRelativeAddressSelf(0x3, 0x7);
g_pConCommandVtable = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>(
"\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x55\x41\x54\x41\x55\x41\x56\x41\x57\x48\x8B\xEC\x48\x83\xEC\x50\x48\x8B\x15\x00\x00\x00\x00"),
"xxxx?xxxx?xxxx?xxxxxxxxxxxxxxxxxxx????").FindPatternSelf("4C 8D 25", CMemory::Direction::DOWN, 150).ResolveRelativeAddressSelf(0x3, 0x7);
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }

View File

@ -126,6 +126,8 @@ ConVar* cl_showmaterialinfo = nullptr;
ConVar* cl_materialinfo_offset_x = nullptr;
ConVar* cl_materialinfo_offset_y = nullptr;
ConVar* cl_threaded_bone_setup = nullptr;
ConVar* con_max_size_logvector = nullptr;
ConVar* con_suggestion_limit = nullptr;
ConVar* con_suggestion_showhelptext = nullptr;
@ -163,6 +165,7 @@ ConVar* pylon_showdebug = nullptr;
// RUI |
#ifndef DEDICATED
ConVar* rui_drawEnable = nullptr;
ConVar* rui_defaultDebugFontFace = nullptr;
#endif // !DEDICATED
struct ConVarFlags_t

View File

@ -121,6 +121,8 @@ extern ConVar* cl_showmaterialinfo;
extern ConVar* cl_materialinfo_offset_x;
extern ConVar* cl_materialinfo_offset_y;
extern ConVar* cl_threaded_bone_setup;
extern ConVar* con_max_size_logvector;
extern ConVar* con_suggestion_limit;
extern ConVar* con_suggestion_showhelptext;
@ -158,6 +160,7 @@ extern ConVar* pylon_showdebug;
// RUI |
#ifndef DEDICATED
extern ConVar* rui_drawEnable;
extern ConVar* rui_defaultDebugFontFace;
#endif // !DEDICATED
//-----------------------------------------------------------------------------
@ -209,7 +212,7 @@ private:
extern CCvarUtilities* cv;
class CCvar
class CCvar // TODO: interface class !!!
{
public:
ConCommandBase* RegisterConCommand(ConCommandBase* pCommandToAdd);