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-08-09 17:18:07 +02:00
|
|
|
#include "public/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-08-13 12:39:57 +02:00
|
|
|
|
2022-08-13 20:21:32 +02:00
|
|
|
bool IsFlagSet(int nFlags) const { return IsFlagSetInternal(this, nFlags); };
|
|
|
|
static bool IsFlagSetInternal(const 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-09-12 23:59:32 +02:00
|
|
|
inline CMemory p_ConVar_IsFlagSet;
|
|
|
|
inline auto v_ConVar_IsFlagSet = p_ConVar_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_Register;
|
2022-09-12 23:59:32 +02:00
|
|
|
inline auto v_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)>();
|
|
|
|
|
|
|
|
inline CMemory p_ConVar_PrintDescription;
|
|
|
|
inline auto v_ConVar_PrintDescription = p_ConVar_PrintDescription.RCast<void* (*)(ConCommandBase* pVar)>();
|
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-08-13 12:39:57 +02:00
|
|
|
void ConVar_PrintDescription(ConCommandBase* pVar);
|
|
|
|
|
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-09-12 23:59:32 +02:00
|
|
|
spdlog::debug("| FUN: ConVar::IsFlagSet : {:#18x} |\n", p_ConVar_IsFlagSet.GetPtr());
|
2022-08-04 11:06:56 +02:00
|
|
|
spdlog::debug("| FUN: ConVar::Register : {:#18x} |\n", p_ConVar_Register.GetPtr());
|
2022-09-12 23:59:32 +02:00
|
|
|
spdlog::debug("| FUN: ConVar_PrintDescription : {:#18x} |\n", p_ConVar_PrintDescription.GetPtr());
|
2022-08-15 22:29:16 +02:00
|
|
|
spdlog::debug("| VAR: g_pConVarVFTable : {:#18x} |\n", g_pConVarVFTable.GetPtr());
|
|
|
|
spdlog::debug("| VAR: g_pIConVarVFTable : {:#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
|
|
|
|
{
|
2022-09-12 23:59:32 +02:00
|
|
|
p_ConVar_IsFlagSet = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x8B\x41\x48\x85\x50\x38"), "xxxxxxx");
|
2022-04-18 03:35:08 +02:00
|
|
|
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
|
2022-08-09 03:02:00 +02:00
|
|
|
p_ConVar_Register = g_GameDll.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?");
|
2022-04-18 03:35:08 +02:00
|
|
|
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
|
2022-08-09 03:02:00 +02:00
|
|
|
p_ConVar_Register = 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\x40\xF3\x0F\x10\x84\x24\x00\x00\x00\x00"), "xxxx?xxxx?xxxx?xxxxxxxxxx????");
|
2022-04-18 03:35:08 +02:00
|
|
|
#endif
|
2022-09-12 23:59:32 +02:00
|
|
|
p_ConVar_PrintDescription = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\xB8\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x48\x2B\xE0\x48\x8B\x01\x48\x89\x9C\x24\x00\x00\x00\x00"), "x????x????xxxxxxxxxx????");
|
|
|
|
|
|
|
|
v_ConVar_IsFlagSet = p_ConVar_IsFlagSet.RCast<bool (*)(ConVar*, int)>(); /*48 8B 41 48 85 50 38*/
|
|
|
|
v_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 ? ? ? ?*/
|
|
|
|
v_ConVar_PrintDescription = p_ConVar_PrintDescription.RCast<void* (*)(ConCommandBase*)>(); /*B8 ? ? ? ? E8 ? ? ? ? 48 2B E0 48 8B 01 48 89 9C 24 ? ? ? ?*/
|
2022-04-18 03:35:08 +02:00
|
|
|
}
|
2022-08-15 22:29:16 +02:00
|
|
|
virtual void GetVar(void) const { }
|
|
|
|
virtual void GetCon(void) const
|
2022-04-18 03:35:08 +02:00
|
|
|
{
|
2022-08-15 22:29:16 +02:00
|
|
|
g_pConVarVFTable = g_GameDll.GetVirtualMethodTable(".?AVConVar@@", 0);
|
|
|
|
g_pIConVarVFTable = g_GameDll.GetVirtualMethodTable(".?AVConVar@@", 1);
|
2022-04-18 03:35:08 +02:00
|
|
|
}
|
2022-04-11 01:44:30 +02:00
|
|
|
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);
|