diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index dade1ca7..8df55851 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -218,7 +218,7 @@ namespace Components { if (!Dedicated::IsEnabled() && Dvar::Var("sv_dontrotate").get()) { - Dvar::Var("sv_dontrotate").setRaw(0); + Dvar::Var("sv_dontrotate").set(0); return; } diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index f342c658..ad28175c 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -20,6 +20,7 @@ namespace Components { return this->dvar; } + template <> char* Dvar::Var::get() { if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING && this->dvar->current.string) @@ -29,10 +30,12 @@ namespace Components return const_cast(""); } + template <> const char* Dvar::Var::get() { return this->get(); } + template <> int Dvar::Var::get() { if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_INT) @@ -42,10 +45,12 @@ namespace Components return 0; } + template <> unsigned int Dvar::Var::get() { return static_cast(this->get()); } + template <> float Dvar::Var::get() { if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT) @@ -55,6 +60,7 @@ namespace Components return 0; } + template <> float* Dvar::Var::get() { static float val[4] = { 0 }; @@ -66,6 +72,7 @@ namespace Components return val; } + template <> bool Dvar::Var::get() { if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL) @@ -75,6 +82,7 @@ namespace Components return false; } + template <> std::string Dvar::Var::get() { return this->get(); @@ -84,45 +92,45 @@ namespace Components { this->set(const_cast(string)); } + void Dvar::Var::set(const char* string) { - if (this->dvar && this->dvar->name) + assert(this->dvar->type == Game::DVAR_TYPE_STRING); + if (this->dvar) { - Game::Dvar_SetCommand(this->dvar->name, string); + Game::Dvar_SetString(this->dvar, string); } } + void Dvar::Var::set(const std::string& string) { this->set(string.data()); } + void Dvar::Var::set(int integer) { - if (this->dvar && this->dvar->name) + assert(this->dvar->type == Game::DVAR_TYPE_INT); + if (this->dvar) { - Game::Dvar_SetCommand(this->dvar->name, Utils::String::VA("%i", integer)); + Game::Dvar_SetInt(this->dvar, integer); } } + void Dvar::Var::set(float value) { - if (this->dvar && this->dvar->name) + assert(this->dvar->type == Game::DVAR_TYPE_FLOAT); + if (this->dvar) { - Game::Dvar_SetCommand(this->dvar->name, Utils::String::VA("%f", value)); + Game::Dvar_SetFloat(this->dvar, value); } } - void Dvar::Var::setRaw(int integer) + void Dvar::Var::set(bool enabled) { + assert(this->dvar->type == Game::DVAR_TYPE_BOOL); if (this->dvar) { - this->dvar->current.integer = integer; - } - } - - void Dvar::Var::setRaw(float value) - { - if (this->dvar) - { - this->dvar->current.value = value; + Game::Dvar_SetBool(this->dvar, enabled); } } @@ -130,14 +138,17 @@ namespace Components { return Game::Dvar_RegisterBool(name, value, flag.val, description); } + template<> static Dvar::Var Dvar::Register(const char* name, const char* value, Dvar::Flag flag, const char* description) { return Game::Dvar_RegisterString(name, value, flag.val, description); } + template<> static Dvar::Var Dvar::Register(const char* name, int value, int min, int max, Dvar::Flag flag, const char* description) { return Game::Dvar_RegisterInt(name, value, min, max, flag.val, description); } + template<> static Dvar::Var Dvar::Register(const char* name, float value, float min, float max, Dvar::Flag flag, const char* description) { return Game::Dvar_RegisterFloat(name, value, min, max, flag.val, description); diff --git a/src/Components/Modules/Dvar.hpp b/src/Components/Modules/Dvar.hpp index 4775b575..47cf8102 100644 --- a/src/Components/Modules/Dvar.hpp +++ b/src/Components/Modules/Dvar.hpp @@ -31,10 +31,7 @@ namespace Components void set(int integer); void set(float value); - - // TODO: Add others - void setRaw(int integer); - void setRaw(float value); + void set(bool enabled); private: Game::dvar_t* dvar; diff --git a/src/Components/Modules/IW4MVM.cpp b/src/Components/Modules/IW4MVM.cpp index 94fe685e..9b6b3fb8 100644 --- a/src/Components/Modules/IW4MVM.cpp +++ b/src/Components/Modules/IW4MVM.cpp @@ -22,7 +22,7 @@ namespace Components { if (!Game::CL_IsCgameInitialized()) { - Dvar::Var("com_timescale").setRaw(1.0f); + Dvar::Var("com_timescale").set(1.0f); } }); diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 5ed5ba11..ee36600a 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -560,7 +560,7 @@ namespace Components } hasDlc.push_back(hasAllMaps); - Dvar::Var(Utils::String::VA("isDlcInstalled_%d", pack.index)).setRaw(hasAllMaps ? 1 : 0); + Dvar::Var(Utils::String::VA("isDlcInstalled_%d", pack.index)).set(hasAllMaps ? 1 : 0); } // Must have all of dlc 3 to 5 or it causes issues @@ -571,7 +571,7 @@ namespace Components sentMessage = true; } - Dvar::Var("isDlcInstalled_All").setRaw(hasAllDlcs ? 1 : 0); + Dvar::Var("isDlcInstalled_All").set(hasAllDlcs ? 1 : 0); } bool Maps::IsCustomMap() diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 0ed7b3cc..34455097 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -276,6 +276,10 @@ namespace Game Dvar_SetFromStringByName_t Dvar_SetFromStringByName = Dvar_SetFromStringByName_t(0x4F52E0); Dvar_SetFromStringByNameFromSource_t Dvar_SetFromStringByNameFromSource = Dvar_SetFromStringByNameFromSource_t(0x4FC770); Dvar_SetStringByName_t Dvar_SetStringByName = Dvar_SetStringByName_t(0x44F060); + Dvar_SetString_t Dvar_SetString = Dvar_SetString_t(0x4A9580); + Dvar_SetBool_t Dvar_SetBool = Dvar_SetBool_t(0x4A9510); + Dvar_SetFloat_t Dvar_SetFloat = Dvar_SetFloat_t(0x40BB20); + Dvar_SetInt_t Dvar_SetInt = Dvar_SetInt_t(0x421DA0); SL_ConvertToString_t SL_ConvertToString = SL_ConvertToString_t(0x4EC1D0); SL_GetString_t SL_GetString = SL_GetString_t(0x4CDC10); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index eaf3d6d1..3536a4b7 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -235,15 +235,27 @@ namespace Game typedef dvar_t* (__cdecl * Dvar_RegisterColor_t)(const char* name, float r, float g, float b, float a, int flags, const char* description); extern Dvar_RegisterColor_t Dvar_RegisterColor; - typedef dvar_t*(__cdecl * Dvar_SetFromStringByName_t)(const char* cvar, const char* value); + typedef dvar_t* (__cdecl * Dvar_SetFromStringByName_t)(const char* cvar, const char* value); extern Dvar_SetFromStringByName_t Dvar_SetFromStringByName; - typedef dvar_t*(__cdecl * Dvar_SetFromStringByNameFromSource_t)(const char* cvar, const char* value, DvarSetSource source); + typedef dvar_t* (__cdecl * Dvar_SetFromStringByNameFromSource_t)(const char* cvar, const char* value, DvarSetSource source); extern Dvar_SetFromStringByNameFromSource_t Dvar_SetFromStringByNameFromSource; - typedef void(__cdecl * Dvar_SetStringByName_t)(const char* cvar, const char* value); + typedef void (__cdecl * Dvar_SetStringByName_t)(const char* cvar, const char* value); extern Dvar_SetStringByName_t Dvar_SetStringByName; + typedef void (__cdecl * Dvar_SetString_t)(dvar_t* cvar, const char* value); + extern Dvar_SetString_t Dvar_SetString; + + typedef void (__cdecl * Dvar_SetBool_t)(dvar_t* cvar, bool enabled); + extern Dvar_SetBool_t Dvar_SetBool; + + typedef void (__cdecl * Dvar_SetFloat_t)(dvar_t* cvar, float value); + extern Dvar_SetFloat_t Dvar_SetFloat; + + typedef void (__cdecl * Dvar_SetInt_t)(dvar_t* cvar, int integer); + extern Dvar_SetInt_t Dvar_SetInt; + typedef void(__cdecl * Dvar_GetUnpackedColorByName_t)(const char* name, float* color); extern Dvar_GetUnpackedColorByName_t Dvar_GetUnpackedColorByName; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index e64e5d09..afe5f26b 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -74,7 +74,7 @@ namespace Game ASSET_TYPE_INVALID = -1, }; - typedef enum + typedef enum : unsigned int { DVAR_FLAG_NONE = 0x0, //no flags DVAR_FLAG_SAVED = 0x1, //saves in config_mp.cfg for clients @@ -119,7 +119,7 @@ namespace Game DVAR_SOURCE_DEVGUI = 0x3, }; - typedef enum + typedef enum : char { DVAR_TYPE_BOOL = 0x0, DVAR_TYPE_FLOAT = 0x1, @@ -2381,7 +2381,7 @@ namespace Game const char *name; const char *description; unsigned int flags; - char type; + dvar_type type; bool modified; DvarValue current; DvarValue latched; @@ -4215,6 +4215,25 @@ namespace Game char ipx[10]; }; + struct netchan_t + { + int outgoingSequence; + int sock; + int dropped; + int incomingSequence; + netadr_t remoteAddress; + int qport; + int fragmentSequence; + int fragmentLength; + uint8_t* fragmentBuffer; + int fragmentBufferSize; + int unsentFragments; + int unsentFragmentStart; + int unsentLength; + uint8_t* unsentBuffer; + int unsentBufferSize; + }; + struct FxEditorElemAtlas { int behavior; @@ -4624,47 +4643,56 @@ namespace Game // 0 clientstate_t state; // 4 - char _pad[4]; + char __pad0[4]; // 8 int deltaMessage; // 12 - char __pad[12]; + char __pad1[12]; // 24 int outgoingSequence; // 28 - char pad[12]; + char __pad2[12]; // 40 netadr_t addr; // 60 - char pad1[1568]; + char __pad3[1568]; // 1628 char connectInfoString[1024]; // 2652 - char pad2[133192]; + char __pad4[132096]; + // 134748 + int reliableSequence; + // 134752 + int reliableAcknowledge; + // 134756 + int reliableSent; + // 134760 + char __pad5[1084]; // 135844 char name[16]; // 135860 - char pad3[12]; + char __pad6[12]; // 135872 int snapNum; // 135876 - int pad4; + int __pad7; // 135880 short ping; // 135882 - //char pad5[142390]; - char pad5[133158]; + char __pad8[133158]; // 269040 int isBot; // 269044 - char pad6[9228]; + char __pad9[9228]; // 278272 unsigned __int64 steamid; // 278280 - char pad7[403592]; + char __pad10[403592]; } client_t; #pragma pack(pop) + static_assert(sizeof(client_t) == 681872); + struct CModelAllocData { void* mainArray;