Dedicated and SDK improvements

* Improve ConVar class (fixed several bugs).
* Hook CEngineAPI::ModInit() and set m_bRestrictServerCommands from there.
* Disable unused ConVar's and purge unused ConCommands in CEngineAPI::ModInit() for dedicated.
* Small relocation of malloc related signatures.
This commit is contained in:
Kawe Mazidjatari 2022-04-15 04:02:33 +02:00
parent b753295a49
commit 196db8660e
18 changed files with 387 additions and 184 deletions

View File

@ -29,9 +29,6 @@ void CHLClient::FrameStageNotify(CHLClient* pHLClient, ClientFrameStage_t frameS
static bool bInitialized = false;
if (!bInitialized)
{
#ifdef GAMEDLL_S3
g_pConVar->ClearHostNames();
#endif // GAMEDLL_S3
KeyValues::Init();
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2) // !TEMP UNTIL CHOSTSTATE IS BUILD AGNOSTIC! //
if (!g_pCmdLine->CheckParm("-devsdk"))
@ -56,10 +53,6 @@ void CHLClient::FrameStageNotify(CHLClient* pHLClient, ClientFrameStage_t frameS
}
Cbuf_Execute();
*(bool*)m_bRestrictServerCommands = true; // Restrict commands.
ConCommandBase* disconnect = (ConCommandBase*)g_pCVar->FindCommand("disconnect");
disconnect->AddFlags(FCVAR_SERVER_CAN_EXECUTE); // Make sure server is not restricted to this.
if (net_userandomkey->GetBool())
{
HNET_GenerateKey();

View File

@ -6,6 +6,7 @@
#include "core/stdafx.h"
#include "core/init.h"
#include "tier0/tslist.h"
#include "tier0/fasttimer.h"
#include "tier0/cpu.h"
#include "tier0/commandline.h"
@ -179,6 +180,7 @@ void Systems_Init()
#endif // !DEDICATED
SysDll_Attach();
SysDll2_Attach();
SysUtils_Attach();
#ifndef DEDICATED
@ -276,6 +278,7 @@ void Systems_Shutdown()
#endif // !DEDICATED
SysDll_Detach();
SysDll2_Detach();
SysUtils_Detach();
#ifndef DEDICATED

View File

@ -180,7 +180,7 @@ FORCEINLINE void CHostState::Init(void)
FORCEINLINE void CHostState::Setup(void) const
{
g_pHostState->LoadConfig();
g_pConVar->ClearHostNames();
g_pConVar->PurgeHostNames();
#ifdef DEDICATED
g_pRConServer->Init();
#else //
@ -190,11 +190,7 @@ FORCEINLINE void CHostState::Setup(void) const
std::thread think(&CHostState::Think, this);
think.detach();
*m_bRestrictServerCommands = true; // Restrict commands.
ConCommandBase* disconnect = g_pCVar->FindCommandBase("disconnect");
disconnect->AddFlags(FCVAR_SERVER_CAN_EXECUTE); // Make sure server is not restricted to this.
net_usesocketsforloopback->SetValue(1);
if (net_userandomkey->GetBool())
{
NET_GenerateKey();

View File

@ -1,3 +1,68 @@
//====== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "core/stdafx.h"
#include "tier1/cmd.h"
#include "tier1/cvar.h"
#include "engine/sys_dll.h"
#include "engine/sys_dll2.h"
#include "client/vengineclient_impl.h"
//-----------------------------------------------------------------------------
// Figure out if we're running a Valve mod or not.
//-----------------------------------------------------------------------------
static bool IsValveMod(const char* pModName)
{
return (_stricmp(pModName, "cstrike") == 0 ||
_stricmp(pModName, "dod") == 0 ||
_stricmp(pModName, "hl1mp") == 0 ||
_stricmp(pModName, "tf") == 0 ||
_stricmp(pModName, "hl2mp") == 0 ||
_stricmp(pModName, "csgo") == 0);
}
//-----------------------------------------------------------------------------
// Figure out if we're running a Respawn mod or not.
//-----------------------------------------------------------------------------
static bool IsRespawnMod(const char* pModName)
{
return (_stricmp(pModName, "r1") == 0 ||
_stricmp(pModName, "r2") == 0 ||
_stricmp(pModName, "r5") == 0);
}
//-----------------------------------------------------------------------------
// Initialization, shutdown of a mod.
//-----------------------------------------------------------------------------
bool CEngineAPI::ModInit(CEngineAPI* pEngineAPI, const char* pModName, const char* pGameDir)
{
g_pConCommand->InitShipped();
g_pConCommand->PurgeShipped();
g_pConVar->InitShipped();
g_pConVar->PurgeShipped();
bool results = CEngineAPI_ModInit(pEngineAPI, pModName, pGameDir);
if (!IsValveMod(pModName) && IsRespawnMod(pModName))
{
*m_bRestrictServerCommands = true; // Restrict commands.
ConCommandBase* disconnect = g_pCVar->FindCommandBase("disconnect");
disconnect->AddFlags(FCVAR_SERVER_CAN_EXECUTE); // Make sure server is not restricted to this.
}
return results;
}
///////////////////////////////////////////////////////////////////////////////
void SysDll2_Attach()
{
DetourAttach((LPVOID*)&CEngineAPI_ModInit, &CEngineAPI::ModInit);
}
void SysDll2_Detach()
{
DetourDetach((LPVOID*)&CEngineAPI_ModInit, &CEngineAPI::ModInit);
}

View File

@ -4,6 +4,7 @@
class CEngineAPI
{
public:
static bool ModInit(CEngineAPI* pEngineAPI, const char* pModName, const char* pGameDir);
// TODO [ AMOS ]:
};
@ -14,12 +15,18 @@ inline auto CEngineAPI_Connect = p_CEngineAPI_Connect.RCast<bool (*)(CEngineAPI*
inline CMemory p_PakFile_Init = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x44\x88\x44\x24\x00\x56\x57\x41\x54\x41\x56\x41\x57\x48\x83\xEC\x20"), "xxxx?xxxx?xxxx?xxxxxxxxxxxx");
inline auto PakFile_Init = p_PakFile_Init.RCast<void (*)(char* buffer, char* source, char vpk_file)>(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 44 88 44 24 ?? 56 57 41 54 41 56 41 57 48 83 EC 20*/
inline CMemory p_CEngineAPI_ModInit = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x57\x41\x54\x41\x55\x41\x56\x41\x57\x48\x81\xEC\x00\x00\x00\x00\x4D\x8B\xF0"), "xxxx?xxxx?xxxx?xxxxxxxxxxxx????xxx");
inline auto CEngineAPI_ModInit = p_CEngineAPI_ModInit.RCast<bool (*)(CEngineAPI* pEngineAPI, const char* pModName, const char* pGameDir)>(); /*48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 54 41 55 41 56 41 57 48 81 EC ? ? ? ? 4D 8B F0*/
inline CMemory p_CEngineAPI_MainLoop = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x55\x48\x81\xEC\x00\x00\x00\x00\x45\x33\xC9"), "xxxx?xxxx????xxx");
inline auto CEngineAPI_MainLoop = p_CEngineAPI_MainLoop.RCast<bool(*)(void)>(); /*48 89 5C 24 ? 55 48 81 EC ? ? ? ? 45 33 C9*/
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
inline CMemory p_PakFile_Init = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x44\x88\x44\x24\x00\x53\x55\x56\x57"), "xxxx?xxxx");
inline auto PakFile_Init = p_PakFile_Init.RCast<void (*)(char* buffer, char* source, char vpk_file)>(); /*44 88 44 24 ?? 53 55 56 57*/
inline CMemory p_CEngineAPI_ModInit = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x4C\x24\x00\x55\x56\x57\x41\x54\x41\x55\x41\x56\x41\x57\x48\x81\xEC\x00\x00\x00\x00\x4D\x8B\xF8"), "xxxx?xxxx?xxxxxxxxxxxxxx????xxx");
inline auto CEngineAPI_ModInit = p_CEngineAPI_ModInit.RCast<bool (*)(CEngineAPI* pEngineAPI, const char* pModName, const char* pGameDir)>(); /*48 89 5C 24 ? 48 89 4C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 81 EC ? ? ? ? 4D 8B F8*/
inline CMemory p_CEngineAPI_MainLoop = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\xE8\x00\x00\x00\x00\x48\x8B\x15\x00\x00\x00\x00\x84\xC0\xB9\x00\x00\x00\x00"), "x????xxx????xxx????").FollowNearCallSelf();
inline auto CEngineAPI_MainLoop = p_CEngineAPI_MainLoop.RCast<bool(*)(void)>(); /*E8 ? ? ? ? 48 8B 15 ? ? ? ? 84 C0 B9 ? ? ? ?*/
#endif
@ -30,12 +37,15 @@ inline CMemory g_pMapVPKCache = p_PakFile_Init.FindPatternSelf("4C 8D 35 ?? ?? ?
inline CMemory g_pMapVPKCache = p_PakFile_Init.FindPatternSelf("48 8D 1D ?? ?? ?? ?? 4C", CMemory::Direction::DOWN, 250).OffsetSelf(0x3).ResolveRelativeAddressSelf().GetPtr();
#endif
void SysDll2_Attach();
void SysDll2_Detach();
///////////////////////////////////////////////////////////////////////////////
class HSys_Dll2 : public IDetour
{
virtual void GetAdr(void) const
{
std::cout << "| FUN: CEngineAPI::Connect : 0x" << std::hex << std::uppercase << p_CEngineAPI_Connect.GetPtr() << std::setw(nPad) << " |" << std::endl;
std::cout << "| FUN: CEngineAPI::ModInit : 0x" << std::hex << std::uppercase << p_CEngineAPI_ModInit.GetPtr() << std::setw(nPad) << " |" << std::endl;
std::cout << "| FUN: CEngineAPI::MainLoop : 0x" << std::hex << std::uppercase << p_CEngineAPI_MainLoop.GetPtr() << std::setw(nPad) << " |" << std::endl;
std::cout << "| FUN: PakFile_Init : 0x" << std::hex << std::uppercase << p_PakFile_Init.GetPtr() << std::setw(nPad) << " |" << std::endl;
std::cout << "| VAR: g_pMapVPKCache : 0x" << std::hex << std::uppercase << g_pMapVPKCache.GetPtr() << std::setw(nPad) << " |" << std::endl;

View File

@ -12,17 +12,6 @@ inline void*(*Sys_LoadAssetHelper)(const CHAR* lpFileName, std::int64_t a2, LARG
inline CMemory p_Con_NPrintf = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x4C\x24\x00\x48\x89\x54\x24\x00\x4C\x89\x44\x24\x00\x4C\x89\x4C\x24\x00\xC3"), "xxxx?xxxx?xxxx?xxxx?x");
inline auto Con_NPrintf = p_Con_NPrintf.RCast<void (*)(int pos, const char* fmt, ...)>(); /*48 89 4C 24 ? 48 89 54 24 ? 4C 89 44 24 ? 4C 89 4C 24 ? C3*/
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
inline CMemory p_MemAlloc_Wrapper = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x20\x48\x8B\x05\x00\x00\x00\x00\x48\x8B\xD9\x48\x85\xC0\x75\x0C\xE8\x16"), "xxxxxxxxx????xxxxxxxxxx");
inline auto MemAlloc_Wrapper = p_MemAlloc_Wrapper.RCast<void* (*)(size_t)>(); /*40 53 48 83 EC 20 48 8B 05 ?? ?? ?? ?? 48 8B D9 48 85 C0 75 0C E8 16*/
#elif defined (GAMEDLL_S2)
inline CMemory p_MemAlloc_Wrapper = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x20\x48\x8B\x05\x00\x00\x00\x00\x48\x8B\xD9\x48\x85\xC0\x75\x0C\xE8\x00\x00\x00\x00\x48\x89\x05\x00\x00\x00\x00\x4C\x8B\x00\x48\x8B\xD3\x48\x8B\xC8\x48\x83\xC4\x20\x5B\x49\xFF\x60\x08"), "xxxxxxxxx????xxxxxxxxx????xxx????xxxxxxxxxxxxxxxxxx");
inline auto MemAlloc_Wrapper = p_MemAlloc_Wrapper.RCast<void* (*)(size_t)>(); /*40 53 48 83 EC 20 48 8B 05 ? ? ? ? 48 8B D9 48 85 C0 75 0C E8 ? ? ? ? 48 89 05 ? ? ? ? 4C 8B 00 48 8B D3 48 8B C8 48 83 C4 20 5B 49 FF 60 08 */
#elif defined (GAMEDLL_S3)
inline CMemory p_MemAlloc_Wrapper = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x20\x48\x8B\x05\x6B\x83\x25\x0D\x48\x8B\xD9"), "xxxxxxxxxxxxxxxx");
inline auto MemAlloc_Wrapper = p_MemAlloc_Wrapper.RCast<void* (*)(size_t)>(); /*40 53 48 83 EC 20 48 8B 05 6B 83 25 0D 48 8B D9*/
#endif
/* ==== ------- ========================================================================================================================================================= */
enum class eDLL_T : int
@ -82,7 +71,6 @@ class HSys_Utils : public IDetour
std::cout << "| FUN: Sys_Warning : 0x" << std::hex << std::uppercase << p_Warning.GetPtr() << std::setw(nPad) << " |" << std::endl;
std::cout << "| FUN: Sys_LoadAssetHelper : 0x" << std::hex << std::uppercase << p_Sys_LoadAssetHelper.GetPtr() << std::setw(nPad) << " |" << std::endl;
std::cout << "| FUN: Con_NPrintf : 0x" << std::hex << std::uppercase << p_Con_NPrintf.GetPtr() << std::setw(nPad) << " |" << std::endl;
std::cout << "| FUN: MemAlloc_Wrapper : 0x" << std::hex << std::uppercase << p_MemAlloc_Wrapper.GetPtr() << std::setw(nPad) << " |" << std::endl;
std::cout << "+----------------------------------------------------------------+" << std::endl;
}
virtual void GetFun(void) const { }

View File

@ -50,11 +50,8 @@ bool CModAppSystemGroup::Create(CModAppSystemGroup* pModAppSystemGroup)
#ifdef DEDICATED
pModAppSystemGroup->SetServerOnly();
*g_bDedicated = true;
g_pConCommand->PurgeShipped();
#endif // DEDICATED
g_pConCommand->Init();
g_pConCommand->InitShipped();
g_pConVar->InitShipped();
g_pFactory->GetFactoriesFromRegister();
for (auto& map : g_pCVar->DumpToMap())

View File

@ -70,7 +70,39 @@ struct CPUInformation
uint32_t m_nL3CacheSizeKb;
uint32_t m_nL3CacheDesc;
CPUInformation() : m_Size(0) {}
CPUInformation() : m_Size(0)
{
m_Size = 0;
m_nLogicalProcessors = 0;
m_nPhysicalProcessors = 0;
m_bRDTSC = false;
m_bCMOV = false;
m_bCMOV = false;
m_bFCMOV = false;
m_bSSE = false;
m_bSSE2 = false;
m_b3DNow = false;
m_bMMX = false;
m_bHT = false;
m_Speed = 0i64;
m_szProcessorID = nullptr;
m_szProcessorBrand = nullptr;
m_nModel = 0;
m_nFeatures[0] = 0;
m_nFeatures[1] = 0;
m_nFeatures[2] = 0;
m_nL1CacheSizeKb = 0;
m_nL1CacheDesc = 0;
m_nL2CacheSizeKb = 0;
m_nL2CacheDesc = 0;
m_nL3CacheSizeKb = 0;
m_nL3CacheDesc = 0;
}
};
#endif /* PLATFORM_H */

36
r5dev/tier0/tslist.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef TSLIST_H
#define TSLIST_H
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
inline CMemory p_MemAlloc_Wrapper = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x20\x48\x8B\x05\x00\x00\x00\x00\x48\x8B\xD9\x48\x85\xC0\x75\x0C\xE8\x16"), "xxxxxxxxx????xxxxxxxxxx");
inline auto MemAlloc_Wrapper = p_MemAlloc_Wrapper.RCast<void* (*)(size_t)>(); /*40 53 48 83 EC 20 48 8B 05 ?? ?? ?? ?? 48 8B D9 48 85 C0 75 0C E8 16*/
#elif defined (GAMEDLL_S2)
inline CMemory p_MemAlloc_Wrapper = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x20\x48\x8B\x05\x00\x00\x00\x00\x48\x8B\xD9\x48\x85\xC0\x75\x0C\xE8\x00\x00\x00\x00\x48\x89\x05\x00\x00\x00\x00\x4C\x8B\x00\x48\x8B\xD3\x48\x8B\xC8\x48\x83\xC4\x20\x5B\x49\xFF\x60\x08"), "xxxxxxxxx????xxxxxxxxx????xxx????xxxxxxxxxxxxxxxxxx");
inline auto MemAlloc_Wrapper = p_MemAlloc_Wrapper.RCast<void* (*)(size_t)>(); /*40 53 48 83 EC 20 48 8B 05 ? ? ? ? 48 8B D9 48 85 C0 75 0C E8 ? ? ? ? 48 89 05 ? ? ? ? 4C 8B 00 48 8B D3 48 8B C8 48 83 C4 20 5B 49 FF 60 08 */
#elif defined (GAMEDLL_S3)
inline CMemory p_MemAlloc_Wrapper = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x20\x48\x8B\x05\x6B\x83\x25\x0D\x48\x8B\xD9"), "xxxxxxxxxxxxxxxx");
inline auto MemAlloc_Wrapper = p_MemAlloc_Wrapper.RCast<void* (*)(size_t)>(); /*40 53 48 83 EC 20 48 8B 05 6B 83 25 0D 48 8B D9*/
#endif
inline CMemory p_CTSListBase_Wrapper = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x20\xBB\x00\x00\x00\x00\x33\xC0"), "xxxxxxx????xx");
inline auto CTSListBase_Wrapper = p_CTSListBase_Wrapper.RCast<void* (*)(void)>(); /*40 53 48 83 EC 20 BB ? ? ? ? 33 C0*/
///////////////////////////////////////////////////////////////////////////////
class HTSListBase : public IDetour
{
virtual void GetAdr(void) const
{
std::cout << "| FUN: MemAlloc_Wrapper : 0x" << std::hex << std::uppercase << p_MemAlloc_Wrapper.GetPtr() << std::setw(nPad) << " |" << std::endl;
std::cout << "| FUN: CTSListBase_Wrapper : 0x" << std::hex << std::uppercase << p_CTSListBase_Wrapper.GetPtr() << std::setw(nPad) << " |" << std::endl;
std::cout << "+----------------------------------------------------------------+" << std::endl;
}
virtual void GetFun(void) const { }
virtual void GetVar(void) const { }
virtual void GetCon(void) const { }
virtual void Attach(void) const { }
virtual void Detach(void) const { }
};
///////////////////////////////////////////////////////////////////////////////
REGISTER(HTSListBase);
#endif // TSLIST_H

View File

@ -5,12 +5,13 @@
//=============================================================================//
#include "core/stdafx.h"
#include "vstdlib/callback.h"
#include "tier0/tslist.h"
#include "tier1/IConVar.h"
#include "tier1/cvar.h"
#include "engine/sys_utils.h"
#include "engine/sys_dll2.h"
#include "mathlib/bits.h"
#include "vstdlib/callback.h"
//-----------------------------------------------------------------------------
// Purpose: construct/allocate
@ -167,6 +168,68 @@ void ConVar::InitShipped(void) const
mp_gamemode->SetCallback(&MP_GameMode_Changed_f);
}
//-----------------------------------------------------------------------------
// Purpose: unregister/disable unused ConVar's for dedicated.
//-----------------------------------------------------------------------------
void ConVar::PurgeShipped(void) const
{
const char* pszToPurge[] =
{
"bink_materials_enabled",
"communities_enabled",
"ime_enabled",
"origin_igo_mutes_sound_enabled",
"voice_enabled",
};
for (int i = 0; i < (&pszToPurge)[1] - pszToPurge; i++)
{
ConVar* pCVar = g_pCVar->FindVar(pszToPurge[i]);
if (pCVar)
{
pCVar->SetValue(0);
}
}
}
//-----------------------------------------------------------------------------
// Purpose: clear all hostname ConVar's.
//-----------------------------------------------------------------------------
void ConVar::PurgeHostNames(void) const
{
const char* pszHostNames[] =
{
"pin_telemetry_hostname",
"assetdownloads_hostname",
"users_hostname",
"persistence_hostname",
"speechtotexttoken_hostname",
"communities_hostname",
"persistenceDef_hostname",
"party_hostname",
"speechtotext_hostname",
"serverReports_hostname",
"subscription_hostname",
"steamlink_hostname",
"staticfile_hostname",
"matchmaking_hostname",
"skill_hostname",
"publication_hostname",
"stats_hostname"
};
for (int i = 0; i < (&pszHostNames)[1] - pszHostNames; i++)
{
ConVar* pCVar = g_pCVar->FindVar(pszHostNames[i]);
if (pCVar)
{
pCVar->ChangeStringValueUnsafe("0.0.0.0");
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Add's flags to ConVar.
// Input : nFlags -
@ -337,33 +400,8 @@ bool ConVar::HasMax(void) const
//-----------------------------------------------------------------------------
void ConVar::SetValue(int nValue)
{
if (nValue == m_Value.m_nValue)
{
return;
}
// Only valid for root ConVars.
assert(m_pParent == this);
float flValue = static_cast<float>(nValue);
// Check bounds.
if (ClampValue(flValue))
{
nValue = static_cast<int>(flValue);
}
// Redetermine value.
float flOldValue = m_Value.m_fValue;
m_Value.m_fValue = flValue;
m_Value.m_fValue = nValue;
if (!(m_nFlags & FCVAR_NEVER_AS_STRING))
{
char szTempValue[32];
snprintf(szTempValue, sizeof(szTempValue), "%d", m_Value.m_nValue);
ChangeStringValue(szTempValue, flOldValue);
}
ConVar* pCVar = reinterpret_cast<ConVar*>(m_pParent);
pCVar->InternalSetIntValue(nValue);
}
//-----------------------------------------------------------------------------
@ -372,28 +410,8 @@ void ConVar::SetValue(int nValue)
//-----------------------------------------------------------------------------
void ConVar::SetValue(float flValue)
{
if (flValue == m_Value.m_fValue)
{
return;
}
// Only valid for root ConVars.
assert(m_pParent == this);
// Check bounds.
ClampValue(flValue);
// Redetermine value.
float flOldValue = m_Value.m_fValue;
m_Value.m_fValue = flValue;
m_Value.m_nValue = static_cast<int>(m_Value.m_fValue);
if (!(m_nFlags & FCVAR_NEVER_AS_STRING))
{
char szTempValue[32];
snprintf(szTempValue, sizeof(szTempValue), "%f", m_Value.m_fValue);
ChangeStringValue(szTempValue, flOldValue);
}
ConVar* pCVar = reinterpret_cast<ConVar*>(m_pParent);
pCVar->InternalSetFloatValue(flValue);
}
//-----------------------------------------------------------------------------
@ -401,6 +419,26 @@ void ConVar::SetValue(float flValue)
// Input : *szValue -
//-----------------------------------------------------------------------------
void ConVar::SetValue(const char* pszValue)
{
ConVar* pCVar = reinterpret_cast<ConVar*>(m_pParent);
pCVar->InternalSetValue(pszValue);
}
//-----------------------------------------------------------------------------
// Purpose: sets the ConVar color value.
// Input : value -
//-----------------------------------------------------------------------------
void ConVar::SetValue(Color value)
{
ConVar* pCVar = reinterpret_cast<ConVar*>(m_pParent);
pCVar->InternalSetColorValue(value);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pszValue -
//-----------------------------------------------------------------------------
void ConVar::InternalSetValue(const char* pszValue)
{
if (strcmp(this->m_pParent->m_Value.m_pszString, pszValue) == 0)
{
@ -427,7 +465,7 @@ void ConVar::SetValue(const char* pszValue)
float flNewValue = static_cast<float>(atof(pszValue));
if (!IsFinite(flNewValue))
{
Warning(eDLL_T::ENGINE ,"Warning: ConVar '%s' = '%s' is infinite, clamping value.\n", GetBaseName(), pszValue);
Warning(eDLL_T::ENGINE, "Warning: ConVar '%s' = '%s' is infinite, clamping value.\n", GetBaseName(), pszValue);
flNewValue = FLT_MAX;
}
@ -449,32 +487,109 @@ void ConVar::SetValue(const char* pszValue)
}
//-----------------------------------------------------------------------------
// Purpose: sets the ConVar color value.
// Input : clValue -
// Purpose:
// Input : *nValue -
//-----------------------------------------------------------------------------
void ConVar::SetValue(Color clValue)
void ConVar::InternalSetIntValue(int nValue)
{
std::string svResult = "";
if (nValue == m_Value.m_nValue)
return;
for (int i = 0; i < 4; i++)
assert(m_pParent == this); // Only valid for root convars.
float fValue = static_cast<float>(nValue);
if (ClampValue(fValue))
{
if (!(clValue.GetValue(i) == 0 && svResult.size() == 0))
{
svResult += std::to_string(clValue.GetValue(i));
svResult.append(" ");
}
nValue = static_cast<int>(fValue);
}
this->m_pParent->m_Value.m_pszString = svResult.c_str();
// Redetermine value
float flOldValue = m_Value.m_fValue;
m_Value.m_fValue = fValue;
m_Value.m_nValue = nValue;
if (!(m_nFlags & FCVAR_NEVER_AS_STRING))
{
char szTempVal[32];
snprintf(szTempVal, sizeof(szTempVal), "%d", nValue);
ChangeStringValue(szTempVal, flOldValue);
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *flValue -
//-----------------------------------------------------------------------------
void ConVar::InternalSetFloatValue(float flValue)
{
if (flValue == m_Value.m_fValue)
return;
assert(m_pParent == this); // Only valid for root convars.
// Check bounds
ClampValue(flValue);
// Redetermine value
float flOldValue = m_Value.m_fValue;
m_Value.m_fValue = flValue;
m_Value.m_nValue = static_cast<int>(flValue);
if (!(m_nFlags & FCVAR_NEVER_AS_STRING))
{
char szTempVal[32];
snprintf(szTempVal, sizeof(szTempVal), "%f", flValue);
ChangeStringValue(szTempVal, flOldValue);
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *value -
//-----------------------------------------------------------------------------
void ConVar::InternalSetColorValue(Color value)
{
// Stuff color values into an int
int nValue = 0;
unsigned char* pColorElement = (reinterpret_cast<unsigned char*>(&nValue));
pColorElement[0] = value[0];
pColorElement[1] = value[1];
pColorElement[2] = value[2];
pColorElement[3] = value[3];
// Call the int internal set
InternalSetIntValue(nValue);
}
//-----------------------------------------------------------------------------
// Purpose: Reset to default value.
//-----------------------------------------------------------------------------
void ConVar::Revert(void)
{
this->SetValue(this->m_pszDefaultValue);
SetValue(m_pszDefaultValue);
}
//-----------------------------------------------------------------------------
// Purpose: Check whether to clamp and then perform clamp.
// Input : flValue -
// Output : Returns true if value changed.
//-----------------------------------------------------------------------------
bool ConVar::ClampValue(float& flValue)
{
if (m_bHasMin && (flValue < m_fMinVal))
{
flValue = m_fMinVal;
return true;
}
if (m_bHasMax && (flValue > m_fMaxVal))
{
flValue = m_fMaxVal;
return true;
}
return false;
}
//-----------------------------------------------------------------------------
@ -506,45 +621,6 @@ void ConVar::SetCallback(void* pCallback)
*m_Callback.m_ppCallback = *&pCallback;
}
//-----------------------------------------------------------------------------
// Purpose: changes the ConVar string value.
// Input : *pszTempVal - flOldValue
//-----------------------------------------------------------------------------
void ConVar::ChangeStringValue(const char* pszTempVal, float flOldValue)
{
assert(!(m_nFlags & FCVAR_NEVER_AS_STRING));
char* pszOldValue = reinterpret_cast<char*>(_malloca(m_Value.m_iStringLength));
if (pszOldValue != NULL)
{
memcpy(pszOldValue, m_Value.m_pszString, m_Value.m_iStringLength);
}
if (pszTempVal)
{
int len = strlen(pszTempVal) + 1;
if (len > m_Value.m_iStringLength)
{
if (m_Value.m_pszString)
{
delete[] m_Value.m_pszString;
}
m_Value.m_pszString = new char[len];
m_Value.m_iStringLength = len;
}
memcpy(const_cast<char*>(m_Value.m_pszString), pszTempVal, len);
}
else
{
m_Value.m_pszString = NULL;
}
pszOldValue = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: sets the ConVar color value from string.
// Input : *pszValue -
@ -592,25 +668,51 @@ bool ConVar::SetColorFromString(const char* pszValue)
}
//-----------------------------------------------------------------------------
// Purpose: Check whether to clamp and then perform clamp.
// Input : flValue -
// Output : Returns true if value changed.
// Purpose: changes the ConVar string value.
// Input : *pszTempVal - flOldValue
//-----------------------------------------------------------------------------
bool ConVar::ClampValue(float& flValue)
void ConVar::ChangeStringValue(const char* pszTempVal, float flOldValue)
{
if (m_bHasMin && (flValue < m_fMinVal))
assert(!(m_nFlags & FCVAR_NEVER_AS_STRING));
char* pszOldValue = reinterpret_cast<char*>(_malloca(m_Value.m_iStringLength));
if (pszOldValue != NULL)
{
flValue = m_fMinVal;
return true;
memcpy(pszOldValue, m_Value.m_pszString, m_Value.m_iStringLength);
}
if (m_bHasMax && (flValue > m_fMaxVal))
if (pszTempVal)
{
flValue = m_fMaxVal;
return true;
int len = strlen(pszTempVal) + 1;
if (len > m_Value.m_iStringLength)
{
if (m_Value.m_pszString)
{
delete[] m_Value.m_pszString;
}
m_Value.m_pszString = new char[len];
m_Value.m_iStringLength = len;
}
memcpy(const_cast<char*>(m_Value.m_pszString), pszTempVal, len);
}
else
{
m_Value.m_pszString = NULL;
}
return false;
pszOldValue = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: changes the ConVar string value (unsafe).
// Input : *pszTempVal - flOldValue
//-----------------------------------------------------------------------------
void ConVar::ChangeStringValueUnsafe(const char* pszNewValue)
{
m_Value.m_pszString = pszNewValue;
}
//-----------------------------------------------------------------------------
@ -672,44 +774,6 @@ bool ConVar::IsFlagSet(ConVar* pConVar, int nFlags)
return pConVar->HasFlags(nFlags) != 0;
}
//-----------------------------------------------------------------------------
// Purpose: clear all hostname ConVar's.
//-----------------------------------------------------------------------------
void ConVar::ClearHostNames(void)
{
const char* pszHostnameArray[] =
{
"pin_telemetry_hostname",
"assetdownloads_hostname",
"users_hostname",
"persistence_hostname",
"speechtotexttoken_hostname",
"communities_hostname",
"persistenceDef_hostname",
"party_hostname",
"speechtotext_hostname",
"serverReports_hostname",
"subscription_hostname",
"steamlink_hostname",
"staticfile_hostname",
"matchmaking_hostname",
"skill_hostname",
"publication_hostname",
"stats_hostname"
};
for (int i = 0; i < (&pszHostnameArray)[1] - pszHostnameArray; i++)
{
const char* pszName = pszHostnameArray[i];
ConVar* pCVar = g_pCVar->FindVar(pszName);
if (pCVar)
{
pCVar->m_Value.m_pszString = "0.0.0.0";
}
}
}
///////////////////////////////////////////////////////////////////////////////
void IConVar_Attach()
{

View File

@ -93,6 +93,9 @@ public:
void Init(void) const;
void InitShipped(void) const;
void PurgeShipped(void) const;
void PurgeHostNames(void) const;
void AddFlags(int nFlags);
void RemoveFlags(int nFlags);
@ -119,23 +122,26 @@ public:
void SetValue(const char* pszValue);
void SetValue(Color clValue);
void InternalSetValue(const char* pszValue);
void InternalSetIntValue(int nValue);
void InternalSetFloatValue(float flValue);
void InternalSetColorValue(Color value);
void Revert(void);
bool ClampValue(float& flValue);
const char* GetDefault(void) const;
void SetDefault(const char* pszDefault);
void SetCallback(void* pCallback);
bool SetColorFromString(const char* pszValue);
void ChangeStringValue(const char* pszTempValue, float flOldValue);
bool SetColorFromString(const char* pszValue);
bool ClampValue(float& value);
void ChangeStringValueUnsafe(const char* pszNewValue);
bool IsRegistered(void) const;
bool IsCommand(void) const;
static bool IsFlagSet(ConVar* pConVar, int nFlags);
void ClearHostNames(void);
struct CVValue_t
{
const char* m_pszString;

View File

@ -1,4 +1,5 @@
#include "core/stdafx.h"
#include "tier0/tslist.h"
#include "tier1/cmd.h"
#include "tier1/cvar.h"
#include "vstdlib/completion.h"

View File

@ -335,6 +335,7 @@
<ClInclude Include="..\tier0\fasttimer.h" />
<ClInclude Include="..\tier0\interface.h" />
<ClInclude Include="..\tier0\platform.h" />
<ClInclude Include="..\tier0\tslist.h" />
<ClInclude Include="..\tier1\bitbuf.h" />
<ClInclude Include="..\tier1\cmd.h" />
<ClInclude Include="..\tier1\cvar.h" />

View File

@ -1187,6 +1187,9 @@
<ClInclude Include="..\vstdlib\callback.h">
<Filter>sdk\vstdlib</Filter>
</ClInclude>
<ClInclude Include="..\tier0\tslist.h">
<Filter>sdk\tier0</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="..\shared\resource\lockedserver.png">

View File

@ -340,6 +340,7 @@
<ClInclude Include="..\tier0\fasttimer.h" />
<ClInclude Include="..\tier0\interface.h" />
<ClInclude Include="..\tier0\platform.h" />
<ClInclude Include="..\tier0\tslist.h" />
<ClInclude Include="..\tier1\bitbuf.h" />
<ClInclude Include="..\tier1\cmd.h" />
<ClInclude Include="..\tier1\cvar.h" />

View File

@ -858,6 +858,9 @@
<ClInclude Include="..\vstdlib\callback.h">
<Filter>sdk\vstdlib</Filter>
</ClInclude>
<ClInclude Include="..\tier0\tslist.h">
<Filter>sdk\tier0</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\common\opcodes.cpp">

View File

@ -354,6 +354,7 @@
<ClInclude Include="..\tier0\fasttimer.h" />
<ClInclude Include="..\tier0\interface.h" />
<ClInclude Include="..\tier0\platform.h" />
<ClInclude Include="..\tier0\tslist.h" />
<ClInclude Include="..\tier1\bitbuf.h" />
<ClInclude Include="..\tier1\cmd.h" />
<ClInclude Include="..\tier1\cvar.h" />

View File

@ -1250,6 +1250,9 @@
<ClInclude Include="..\vstdlib\callback.h">
<Filter>sdk\vstdlib</Filter>
</ClInclude>
<ClInclude Include="..\tier0\tslist.h">
<Filter>sdk\tier0</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="..\shared\resource\lockedserver.png">