Make pr ready to be merged
This commit is contained in:
parent
bc68a05b8d
commit
53ebf0d91e
@ -5,42 +5,27 @@ namespace Components
|
|||||||
Utils::Signal<Scheduler::Callback> Dvar::RegistrationSignal;
|
Utils::Signal<Scheduler::Callback> Dvar::RegistrationSignal;
|
||||||
const char* Dvar::ArchiveDvarPath = "userraw/archivedvars.cfg";
|
const char* Dvar::ArchiveDvarPath = "userraw/archivedvars.cfg";
|
||||||
|
|
||||||
Dvar::Var::Var(const std::string& _dvarName) : Var()
|
Dvar::Var::Var(const std::string& dvarName) : Var()
|
||||||
{
|
{
|
||||||
this->dvar = Game::Dvar_FindVar(_dvarName.data());
|
this->dvar = Game::Dvar_FindVar(dvarName.data());
|
||||||
this->dvarName = _dvarName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dvar::Var::registerDvar()
|
|
||||||
{
|
|
||||||
assert(!this->dvarName.empty() && this->dvar == nullptr);
|
|
||||||
|
|
||||||
auto* var = Game::Dvar_FindVar(this->dvarName.data());
|
|
||||||
|
|
||||||
// If the dvar can't be found it will be registered as an empty string dvar
|
// If the dvar can't be found it will be registered as an empty string dvar
|
||||||
if (var == nullptr)
|
if (this->dvar == nullptr)
|
||||||
{
|
{
|
||||||
this->dvar = const_cast<Game::dvar_t*>(Game::Dvar_SetFromStringByNameFromSource(this->dvarName.data(), "",
|
this->dvar = const_cast<Game::dvar_t*>(Game::Dvar_SetFromStringByNameFromSource(dvarName.data(), "",
|
||||||
Game::DvarSetSource::DVAR_SOURCE_INTERNAL));
|
Game::DvarSetSource::DVAR_SOURCE_INTERNAL));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
this->dvar = var;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> Game::dvar_t* Dvar::Var::get()
|
template <> Game::dvar_t* Dvar::Var::get()
|
||||||
{
|
{
|
||||||
if (this->dvar == nullptr)
|
|
||||||
this->registerDvar();
|
|
||||||
|
|
||||||
return this->dvar;
|
return this->dvar;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> const char* Dvar::Var::get()
|
template <> const char* Dvar::Var::get()
|
||||||
{
|
{
|
||||||
if (this->dvar == nullptr)
|
if (this->dvar == nullptr)
|
||||||
this->registerDvar();
|
return "";
|
||||||
|
|
||||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING
|
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING
|
||||||
|| this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
|
|| this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
|
||||||
@ -55,7 +40,7 @@ namespace Components
|
|||||||
template <> int Dvar::Var::get()
|
template <> int Dvar::Var::get()
|
||||||
{
|
{
|
||||||
if (this->dvar == nullptr)
|
if (this->dvar == nullptr)
|
||||||
this->registerDvar();
|
return 0;
|
||||||
|
|
||||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT || this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
|
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT || this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
|
||||||
{
|
{
|
||||||
@ -68,20 +53,20 @@ namespace Components
|
|||||||
template <> unsigned int Dvar::Var::get()
|
template <> unsigned int Dvar::Var::get()
|
||||||
{
|
{
|
||||||
if (this->dvar == nullptr)
|
if (this->dvar == nullptr)
|
||||||
this->registerDvar();
|
return 0u;
|
||||||
|
|
||||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT)
|
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT)
|
||||||
{
|
{
|
||||||
return this->dvar->current.unsignedInt;
|
return this->dvar->current.unsignedInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0u;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> float Dvar::Var::get()
|
template <> float Dvar::Var::get()
|
||||||
{
|
{
|
||||||
if (this->dvar == nullptr)
|
if (this->dvar == nullptr)
|
||||||
this->registerDvar();
|
return 0.f;
|
||||||
|
|
||||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
|
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
|
||||||
{
|
{
|
||||||
@ -96,7 +81,7 @@ namespace Components
|
|||||||
static Game::vec4_t vector{ 0.f, 0.f, 0.f, 0.f };
|
static Game::vec4_t vector{ 0.f, 0.f, 0.f, 0.f };
|
||||||
|
|
||||||
if (this->dvar == nullptr)
|
if (this->dvar == nullptr)
|
||||||
this->registerDvar();
|
return vector;
|
||||||
|
|
||||||
if (this->dvar && (this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_2 || this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_3 || this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_4))
|
if (this->dvar && (this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_2 || this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_3 || this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_4))
|
||||||
{
|
{
|
||||||
@ -109,7 +94,7 @@ namespace Components
|
|||||||
template <> bool Dvar::Var::get()
|
template <> bool Dvar::Var::get()
|
||||||
{
|
{
|
||||||
if (this->dvar == nullptr)
|
if (this->dvar == nullptr)
|
||||||
this->registerDvar();
|
return false;
|
||||||
|
|
||||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
|
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
|
||||||
{
|
{
|
||||||
|
@ -18,12 +18,11 @@ namespace Components
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Var() : dvar(nullptr) {};
|
Var() : dvar(nullptr) {};
|
||||||
Var(const Var& obj) { this->dvar = obj.dvar; this->dvarName = obj.dvarName; };
|
Var(const Var& obj) { this->dvar = obj.dvar; };
|
||||||
Var(Game::dvar_t* _dvar) : dvar(_dvar), dvarName(_dvar->name) {};
|
Var(Game::dvar_t* _dvar) : dvar(_dvar) {};
|
||||||
Var(DWORD ppdvar) : Var(*reinterpret_cast<Game::dvar_t**>(ppdvar)) {};
|
Var(DWORD ppdvar) : Var(*reinterpret_cast<Game::dvar_t**>(ppdvar)) {};
|
||||||
Var(const std::string& dvarName);
|
Var(const std::string& dvarName);
|
||||||
|
|
||||||
void registerDvar();
|
|
||||||
template<typename T> T get();
|
template<typename T> T get();
|
||||||
|
|
||||||
void set(const char* string);
|
void set(const char* string);
|
||||||
@ -38,7 +37,6 @@ namespace Components
|
|||||||
void setRaw(bool enabled);
|
void setRaw(bool enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string dvarName;
|
|
||||||
Game::dvar_t* dvar;
|
Game::dvar_t* dvar;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -265,16 +265,16 @@ namespace Game
|
|||||||
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;
|
extern Dvar_SetStringByName_t Dvar_SetStringByName;
|
||||||
|
|
||||||
typedef void (__cdecl * Dvar_SetString_t)(dvar_t* cvar, const char* value);
|
typedef void (__cdecl * Dvar_SetString_t)(const dvar_t* cvar, const char* value);
|
||||||
extern Dvar_SetString_t Dvar_SetString;
|
extern Dvar_SetString_t Dvar_SetString;
|
||||||
|
|
||||||
typedef void (__cdecl * Dvar_SetBool_t)(dvar_t* cvar, bool enabled);
|
typedef void (__cdecl * Dvar_SetBool_t)(const dvar_t* cvar, bool enabled);
|
||||||
extern Dvar_SetBool_t Dvar_SetBool;
|
extern Dvar_SetBool_t Dvar_SetBool;
|
||||||
|
|
||||||
typedef void (__cdecl * Dvar_SetFloat_t)(dvar_t* cvar, float value);
|
typedef void (__cdecl * Dvar_SetFloat_t)(const dvar_t* cvar, float value);
|
||||||
extern Dvar_SetFloat_t Dvar_SetFloat;
|
extern Dvar_SetFloat_t Dvar_SetFloat;
|
||||||
|
|
||||||
typedef void (__cdecl * Dvar_SetInt_t)(dvar_t* cvar, int integer);
|
typedef void (__cdecl * Dvar_SetInt_t)(const dvar_t* cvar, int integer);
|
||||||
extern Dvar_SetInt_t Dvar_SetInt;
|
extern Dvar_SetInt_t Dvar_SetInt;
|
||||||
|
|
||||||
typedef void(__cdecl * Dvar_GetUnpackedColorByName_t)(const char* name, float* color);
|
typedef void(__cdecl * Dvar_GetUnpackedColorByName_t)(const char* name, float* color);
|
||||||
|
Loading…
Reference in New Issue
Block a user