2021-12-25 22:36:38 +01:00
# pragma once
2022-04-09 16:16:40 +02:00
# include "tier1/cmd.h"
2022-01-09 16:14:17 +01:00
# include "mathlib/color.h"
2022-07-25 19:35:08 +02:00
# include "public/include/iconvar.h"
2022-08-04 11:06:56 +02:00
# include "tier1/utlvector.h"
2021-12-28 02:23:13 +01:00
2022-02-21 12:06:05 +01:00
//-----------------------------------------------------------------------------
// Purpose: A console variable
//-----------------------------------------------------------------------------
2022-02-23 15:56:03 +01:00
class ConVar : public ConCommandBase
2021-12-25 22:36:38 +01:00
{
public :
2022-08-08 01:40:28 +02:00
static ConVar * Create ( const char * pszName , const char * pszDefaultValue , int nFlags , const char * pszHelpString ,
2022-07-25 19:35:08 +02:00
bool bMin , float fMin , bool bMax , float fMax , FnChangeCallback_t pCallback , const char * pszUsageString ) ;
2022-08-08 01:40:28 +02:00
ConVar ( void ) ;
2022-01-09 16:14:17 +01:00
~ ConVar ( void ) ;
2022-02-17 18:00:29 +01:00
void Init ( void ) const ;
2022-04-14 19:18:59 +02:00
void InitShipped ( void ) const ;
2022-01-09 16:14:17 +01:00
2022-04-15 04:02:33 +02:00
void PurgeShipped ( void ) const ;
void PurgeHostNames ( void ) const ;
2022-01-09 16:14:17 +01:00
void AddFlags ( int nFlags ) ;
void RemoveFlags ( int nFlags ) ;
2022-02-23 00:18:46 +01:00
const char * GetBaseName ( void ) const ;
const char * GetHelpText ( void ) const ;
const char * GetUsageText ( void ) const ;
2022-01-09 16:14:17 +01:00
2022-02-06 19:15:34 +01:00
bool GetBool ( void ) const ;
float GetFloat ( void ) const ;
2022-03-27 11:42:24 +02:00
double GetDouble ( void ) const ;
2022-02-06 19:15:34 +01:00
int GetInt ( void ) const ;
2022-06-09 02:22:01 +02:00
int64_t GetInt64 ( void ) const ;
size_t GetSizeT ( void ) const ;
2022-02-06 19:15:34 +01:00
Color GetColor ( void ) const ;
const char * GetString ( void ) const ;
2022-01-09 16:14:17 +01:00
2022-02-06 19:15:34 +01:00
bool GetMin ( float & flMinValue ) const ;
bool GetMax ( float & flMaxValue ) const ;
float GetMinValue ( void ) const ;
float GetMaxValue ( void ) const ;
bool HasMin ( void ) const ;
bool HasMax ( void ) const ;
2022-01-09 16:14:17 +01:00
void SetValue ( int nValue ) ;
void SetValue ( float flValue ) ;
void SetValue ( const char * pszValue ) ;
void SetValue ( Color clValue ) ;
2022-04-15 04:02:33 +02:00
void InternalSetValue ( const char * pszValue ) ;
void InternalSetIntValue ( int nValue ) ;
void InternalSetFloatValue ( float flValue ) ;
void InternalSetColorValue ( Color value ) ;
2022-01-09 16:14:17 +01:00
void Revert ( void ) ;
2022-04-15 04:02:33 +02:00
bool ClampValue ( float & flValue ) ;
2022-01-09 16:14:17 +01:00
2022-02-06 19:15:34 +01:00
const char * GetDefault ( void ) const ;
2022-01-09 16:14:17 +01:00
void SetDefault ( const char * pszDefault ) ;
2022-04-15 04:02:33 +02:00
bool SetColorFromString ( const char * pszValue ) ;
2022-04-14 19:18:59 +02:00
2022-07-31 17:07:35 +02:00
void ChangeStringValue ( const char * pszTempValue ) ;
2022-04-15 04:02:33 +02:00
void ChangeStringValueUnsafe ( const char * pszNewValue ) ;
2022-01-09 16:14:17 +01:00
2022-08-04 11:06:56 +02:00
void InstallChangeCallback ( FnChangeCallback_t callback , bool bInvoke ) ;
void RemoveChangeCallback ( FnChangeCallback_t callback ) ;
2022-02-23 00:18:46 +01:00
bool IsRegistered ( void ) const ;
bool IsCommand ( void ) const ;
2022-01-09 16:14:17 +01:00
static bool IsFlagSet ( ConVar * pConVar , int nFlags ) ;
2022-02-23 00:18:46 +01:00
2022-02-21 17:56:31 +01:00
struct CVValue_t
{
2022-08-04 00:21:48 +02:00
char * m_pszString ;
size_t m_iStringLength ;
float m_fValue ;
int m_nValue ;
2022-02-21 17:56:31 +01:00
} ;
2022-07-25 19:35:08 +02:00
IConVar * m_pIConVarVFTable { } ; //0x0040
2022-01-09 16:14:17 +01:00
ConVar * m_pParent { } ; //0x0048
const char * m_pszDefaultValue { } ; //0x0050
2022-02-21 17:56:31 +01:00
CVValue_t m_Value { } ; //0c0058
2022-01-09 16:14:17 +01:00
bool m_bHasMin { } ; //0x0070
2022-02-21 17:56:31 +01:00
float m_fMinVal { } ; //0x0074
2022-01-09 16:14:17 +01:00
bool m_bHasMax { } ; //0x0078
2022-02-21 17:56:31 +01:00
float m_fMaxVal { } ; //0x007C
2022-08-04 11:06:56 +02:00
CUtlVector < FnChangeCallback_t > m_fnChangeCallbacks ; //0x0080
2021-12-25 22:36:38 +01:00
} ; //Size: 0x00A0
2022-08-04 11:06:56 +02:00
static_assert ( sizeof ( ConVar ) = = 0xA0 ) ;
2021-12-25 22:36:38 +01:00
2022-04-09 02:18:57 +02:00
/* ==== ICONVAR ========================================================================================================================================================= */
2022-04-18 03:35:08 +02:00
inline CMemory p_IConVar_IsFlagSet ;
inline auto IConVar_IsFlagSet = p_IConVar_IsFlagSet . RCast < bool ( * ) ( ConVar * pConVar , int nFlag ) > ( ) ;
2021-12-25 22:36:38 +01:00
2022-04-18 03:35:08 +02:00
inline CMemory p_ConVar_SetInfo ;
inline auto ConVar_SetInfo = p_ConVar_SetInfo . RCast < void * ( * ) ( ConVar * thisptr , int a2 , int a3 , int a4 , void * a5 ) > ( ) ;
inline CMemory p_ConVar_Register ;
2022-07-25 19:35:08 +02:00
inline auto ConVar_Register = p_ConVar_Register . RCast < void * ( * ) ( ConVar * thisptr , const char * szName , const char * szDefaultValue , int nFlags , const char * szHelpString , bool bMin , float fMin , bool bMax , float fMax , FnChangeCallback_t pCallback , const char * pszUsageString ) > ( ) ;
2021-12-25 22:36:38 +01:00
2022-07-25 19:35:08 +02:00
inline CMemory g_pConVarVFTable ;
inline CMemory g_pIConVarVFTable ;
2021-12-25 22:36:38 +01:00
///////////////////////////////////////////////////////////////////////////////
void IConVar_Attach ( ) ;
void IConVar_Detach ( ) ;
2022-01-09 16:14:17 +01:00
extern ConVar * g_pConVar ;
2021-12-25 22:36:38 +01:00
///////////////////////////////////////////////////////////////////////////////
2022-05-13 14:53:25 +02:00
class VConVar : public IDetour
2021-12-25 22:36:38 +01:00
{
2022-04-11 01:44:30 +02:00
virtual void GetAdr ( void ) const
2021-12-25 22:36:38 +01:00
{
2022-08-04 11:06:56 +02:00
spdlog : : debug ( " | FUN: ConVar::IsFlagSet : {:#18x} | \n " , p_IConVar_IsFlagSet . GetPtr ( ) ) ;
spdlog : : debug ( " | FUN: ConVar::SetInfo : {:#18x} | \n " , p_ConVar_SetInfo . GetPtr ( ) ) ;
spdlog : : debug ( " | FUN: ConVar::Register : {:#18x} | \n " , p_ConVar_Register . GetPtr ( ) ) ;
2022-07-25 19:35:08 +02:00
spdlog : : debug ( " | VAR: g_pConVarVtable : {:#18x} | \n " , g_pConVarVFTable . GetPtr ( ) ) ;
spdlog : : debug ( " | VAR: g_pIConVarVtable : {:#18x} | \n " , g_pIConVarVFTable . GetPtr ( ) ) ;
2022-05-13 14:53:25 +02:00
spdlog : : debug ( " +----------------------------------------------------------------+ \n " ) ;
2021-12-25 22:36:38 +01:00
}
2022-04-18 03:35:08 +02:00
virtual void GetFun ( void ) const
{
p_IConVar_IsFlagSet = g_mGameDll . FindPatternSIMD ( reinterpret_cast < rsig_t > ( " \x48 \x8B \x41 \x48 \x85 \x50 \x38 " ) , " xxxxxxx " ) ;
p_ConVar_SetInfo = g_mGameDll . FindPatternSIMD ( reinterpret_cast < rsig_t > ( " \x40 \x53 \x48 \x83 \xEC \x60 \x48 \x8B \xD9 \xC6 \x41 \x10 \x00 \x33 \xC9 \x48 \x8D \x05 \x00 \x00 \x00 \x00 \x48 \x89 \x4C \x24 \x00 \x0F \x57 \xC0 \x48 \x89 \x4C \x24 \x00 \x48 \x89 \x03 \x48 \x8D \x05 \x00 \x00 \x00 \x00 \x48 \x89 \x43 \x40 " ) , " xxxxxxxxxxxxxxxxxx????xxxx?xxxxxxx?xxxxxx????xxxx " ) ;
# if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
p_ConVar_Register = g_mGameDll . FindPatternSIMD ( reinterpret_cast < rsig_t > ( " \x48 \x89 \x5C \x24 \x00 \x48 \x89 \x6C \x24 \x00 \x48 \x89 \x74 \x24 \x00 \x48 \x89 \x7C \x24 \x00 \x41 \x56 \x48 \x83 \xEC \x30 \xF3 \x0F \x10 \x44 \x24 \x00 " ) , " xxxx?xxxx?xxxx?xxxx?xxxxxxxxxxx? " ) ;
# elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
p_ConVar_Register = g_mGameDll . FindPatternSIMD ( reinterpret_cast < rsig_t > ( " \x48 \x89 \x5C \x24 \x00 \x48 \x89 \x6C \x24 \x00 \x48 \x89 \x74 \x24 \x00 \x57 \x48 \x83 \xEC \x40 \xF3 \x0F \x10 \x84 \x24 \x00 \x00 \x00 \x00 " ) , " xxxx?xxxx?xxxx?xxxxxxxxxx???? " ) ;
# endif
IConVar_IsFlagSet = p_IConVar_IsFlagSet . RCast < bool ( * ) ( ConVar * , int ) > ( ) ; /*48 8B 41 48 85 50 38*/
ConVar_SetInfo = p_ConVar_SetInfo . RCast < void * ( * ) ( ConVar * , int , int , int , void * ) > ( ) ; /*40 53 48 83 EC 60 48 8B D9 C6 41 10 00 33 C9 48 8D 05 ? ? ? ? 48 89 4C 24 ? 0F 57 C0 48 89 4C 24 ? 48 89 03 48 8D 05 ? ? ? ? 48 89 43 40*/
2022-07-25 19:35:08 +02:00
ConVar_Register = p_ConVar_Register . RCast < void * ( * ) ( ConVar * , const char * , const char * , int , const char * , bool , float , bool , float , FnChangeCallback_t , const char * ) > ( ) ; /*48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC 40 F3 0F 10 84 24 ? ? ? ?*/
2022-04-18 03:35:08 +02:00
}
virtual void GetVar ( void ) const
{
2022-07-25 19:35:08 +02:00
g_pConVarVFTable = p_ConVar_SetInfo . Offset ( 0x00 ) . FindPatternSelf ( " 48 8D 05 " , CMemory : : Direction : : DOWN , 100 ) . ResolveRelativeAddressSelf ( 0x3 , 0x7 ) . GetPtr ( ) ; // Get vtable ptr for ConVar table.
g_pIConVarVFTable = p_ConVar_SetInfo . Offset ( 0x16 ) . FindPatternSelf ( " 48 8D 05 " , CMemory : : Direction : : DOWN , 100 ) . ResolveRelativeAddressSelf ( 0x3 , 0x7 ) . GetPtr ( ) ; // Get vtable ptr for ICvar table.
2022-04-18 03:35:08 +02:00
}
2022-04-11 01:44:30 +02:00
virtual void GetCon ( void ) const { }
virtual void Attach ( void ) const { }
virtual void Detach ( void ) const { }
2021-12-25 22:36:38 +01:00
} ;
///////////////////////////////////////////////////////////////////////////////
2022-05-13 14:53:25 +02:00
REGISTER ( VConVar ) ;