iw4x-client/src/Components/Modules/Dvar.hpp

68 lines
1.8 KiB
C++
Raw Normal View History

2017-01-20 08:36:52 -05:00
#pragma once
2017-01-19 16:23:59 -05:00
namespace Components
{
class Dvar : public Component
{
public:
class Flag
{
public:
Flag(Game::DvarFlags flag) : val(flag) {}
Flag(unsigned __int16 flag) : Flag(static_cast<Game::DvarFlags>(flag)) {}
2017-01-19 16:23:59 -05:00
Game::DvarFlags val;
2017-01-19 16:23:59 -05:00
};
class Var
{
public:
Var() : dvar_(nullptr) {}
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)) {}
2018-12-17 08:29:18 -05:00
Var(const std::string& dvarName);
2017-01-19 16:23:59 -05:00
template<typename T> T get();
void set(const char* string);
2018-12-17 08:29:18 -05:00
void set(const std::string& string);
2017-01-19 16:23:59 -05:00
void set(int integer);
void set(float value);
void set(bool enabled);
2017-01-19 16:23:59 -05:00
void setRaw(int integer);
void setRaw(float value);
void setRaw(bool enabled);
2017-01-19 16:23:59 -05:00
private:
Game::dvar_t* dvar_;
2017-01-19 16:23:59 -05:00
};
Dvar();
~Dvar();
// Only strings and bools use this type of declaration
template<typename T> static Var Register(const char* dvarName, T value, Flag flag, const char* description);
template<typename T> static Var Register(const char* dvarName, T value, T min, T max, Flag flag, const char* description);
2017-01-19 16:23:59 -05:00
2021-10-03 16:23:26 -04:00
static void ResetDvarsValue();
2017-01-19 16:23:59 -05:00
private:
2021-12-04 13:34:19 -05:00
static const char* ArchiveDvarPath;
2017-01-19 16:23:59 -05:00
static Game::dvar_t* Dvar_RegisterName(const char* name, const char* defaultVal, unsigned __int16 flags, const char* description);
2022-02-03 06:44:35 -05:00
static void SetFromStringByNameExternal(const char* dvar, const char* value);
static void SetFromStringByNameSafeExternal(const char* dvar, const char* value);
2021-10-03 16:23:26 -04:00
static bool AreArchiveDvarsProtected();
2021-12-04 13:34:19 -05:00
static void SaveArchiveDvar(const Game::dvar_t* var);
static void DvarSetFromStringByNameStub(const char* dvarName, const char* value);
static void OnRegisterVariant(Game::dvar_t* dvar);
static void Dvar_RegisterVariant_Stub();
2017-01-19 16:23:59 -05:00
};
}