Make pr ready to be merged

This commit is contained in:
FutureRave 2022-02-19 23:06:56 +00:00
parent bc68a05b8d
commit 53ebf0d91e
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
3 changed files with 17 additions and 34 deletions

View File

@ -5,42 +5,27 @@ namespace Components
Utils::Signal<Scheduler::Callback> Dvar::RegistrationSignal;
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->dvarName = _dvarName;
}
void Dvar::Var::registerDvar()
{
assert(!this->dvarName.empty() && this->dvar == nullptr);
auto* var = Game::Dvar_FindVar(this->dvarName.data());
this->dvar = Game::Dvar_FindVar(dvarName.data());
// 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));
}
else
{
this->dvar = var;
}
}
template <> Game::dvar_t* Dvar::Var::get()
{
if (this->dvar == nullptr)
this->registerDvar();
return this->dvar;
}
template <> const char* Dvar::Var::get()
{
if (this->dvar == nullptr)
this->registerDvar();
return "";
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING
|| this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
@ -55,7 +40,7 @@ namespace Components
template <> int Dvar::Var::get()
{
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)
{
@ -68,20 +53,20 @@ namespace Components
template <> unsigned int Dvar::Var::get()
{
if (this->dvar == nullptr)
this->registerDvar();
return 0u;
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT)
{
return this->dvar->current.unsignedInt;
}
return 0;
return 0u;
}
template <> float Dvar::Var::get()
{
if (this->dvar == nullptr)
this->registerDvar();
return 0.f;
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 };
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))
{
@ -109,7 +94,7 @@ namespace Components
template <> bool Dvar::Var::get()
{
if (this->dvar == nullptr)
this->registerDvar();
return false;
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
{

View File

@ -18,12 +18,11 @@ namespace Components
{
public:
Var() : dvar(nullptr) {};
Var(const Var& obj) { this->dvar = obj.dvar; this->dvarName = obj.dvarName; };
Var(Game::dvar_t* _dvar) : dvar(_dvar), dvarName(_dvar->name) {};
Var(const Var& obj) { this->dvar = obj.dvar; };
Var(Game::dvar_t* _dvar) : dvar(_dvar) {};
Var(DWORD ppdvar) : Var(*reinterpret_cast<Game::dvar_t**>(ppdvar)) {};
Var(const std::string& dvarName);
void registerDvar();
template<typename T> T get();
void set(const char* string);
@ -38,7 +37,6 @@ namespace Components
void setRaw(bool enabled);
private:
std::string dvarName;
Game::dvar_t* dvar;
};

View File

@ -265,16 +265,16 @@ namespace Game
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);
typedef void (__cdecl * Dvar_SetString_t)(const dvar_t* cvar, const char* value);
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;
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;
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;
typedef void(__cdecl * Dvar_GetUnpackedColorByName_t)(const char* name, float* color);