Use game functions to safely change dvar value

This commit is contained in:
Diavolo 2021-09-01 23:19:44 +02:00
parent dded312064
commit 36a025e1d0
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
4 changed files with 24 additions and 12 deletions

View File

@ -86,7 +86,8 @@ namespace Components
}
void Dvar::Var::set(const char* string)
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING)
assert(this->dvar->type == Game::DVAR_TYPE_STRING);
if (this->dvar)
{
Game::Dvar_SetString(this->dvar, string);
}
@ -97,26 +98,26 @@ namespace Components
}
void Dvar::Var::set(int integer)
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_INT)
assert(this->dvar->type == Game::DVAR_TYPE_INT);
if (this->dvar)
{
this->dvar->current.integer = integer;
this->dvar->latched.integer = integer;
Game::Dvar_SetInt(this->dvar, integer);
}
}
void Dvar::Var::set(float value)
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
assert(this->dvar->type == Game::DVAR_TYPE_FLOAT);
if (this->dvar)
{
this->dvar->current.value = value;
this->dvar->latched.value = value;
Game::Dvar_SetFloat(this->dvar, value);
}
}
void Dvar::Var::set(bool enabled)
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
assert(this->dvar->type == Game::DVAR_TYPE_BOOL);
if (this->dvar)
{
this->dvar->current.enabled = enabled;
this->dvar->latched.enabled = enabled;
Game::Dvar_SetBool(this->dvar, enabled);
}
}

View File

@ -280,6 +280,9 @@ namespace Game
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);

View File

@ -247,6 +247,15 @@ namespace Game
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;

View File

@ -90,7 +90,6 @@ namespace Game
DVAR_FLAG_SERVERINFO = 0x400, //in the getstatus oob
DVAR_FLAG_WRITEPROTECTED = 0x800, //write protected
DVAR_FLAG_UNKNOWN1000 = 0x1000, //unknown
DVAR_FLAG_UNKNOWN1800 = 0x1800, //unknown
DVAR_FLAG_READONLY = 0x2000, //read only (same as 0x800?)
DVAR_FLAG_UNKNOWN4000 = 0x4000, //unknown
DVAR_FLAG_UNKNOWN8000 = 0x8000, //unknown
@ -2382,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;