IMPRPOVED CatVar class
This commit is contained in:
parent
8eca92be62
commit
04868f1ee4
@ -10,18 +10,63 @@
|
||||
#include "common.h"
|
||||
#include "sdk.h"
|
||||
|
||||
CatVar::CatVar(CatVar_t type, std::string name, std::string value, std::string help, CatEnum* enum_type, std::string long_description, bool hasminmax, float maxv, float minv) {
|
||||
m_Type = type;
|
||||
m_pConVar = CreateConVar(CON_PREFIX + name, value, help);
|
||||
m_EnumType = enum_type;
|
||||
m_flMinValue = minv;
|
||||
m_flMaxValue = maxv;
|
||||
m_bHasMinmax = hasminmax;
|
||||
SetDescription(long_description);
|
||||
CatVar::CatVar(CatVar_t type, std::string name, std::string value, std::string help, CatEnum* enum_type, std::string long_description, bool hasminmax, float maxv, float minv)
|
||||
: type(type), name(name), defaults(value), desc_short(help), desc_long(long_description), enum_type(enum_type) {
|
||||
min = minv;
|
||||
max = maxv;
|
||||
restricted = hasminmax;
|
||||
g_UnregisteredCatVars.push(this);
|
||||
}
|
||||
|
||||
CatEnum::CatEnum(std::vector<std::string> values, int min) {
|
||||
m_values = values;
|
||||
CatVar::CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long)
|
||||
: type(type), name(name), defaults(defaults), desc_short(desc_short), desc_long(desc_long), enum_type(nullptr), restricted(false) {
|
||||
// For some reason, adding min(0.0f), max(0.0f) gives a compilation error.
|
||||
min = 0.0f;
|
||||
max = 0.0f;
|
||||
g_UnregisteredCatVars.push(this);
|
||||
}
|
||||
|
||||
CatVar::CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long, float max_val)
|
||||
: type(type), name(name), defaults(defaults), desc_short(desc_short), desc_long(desc_long), enum_type(nullptr), restricted(true) {
|
||||
min = 0.0f;
|
||||
max = max_val;
|
||||
g_UnregisteredCatVars.push(this);
|
||||
}
|
||||
|
||||
CatVar::CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long, float min_val, float max_val)
|
||||
: type(type), name(name), defaults(defaults), desc_short(desc_short), desc_long(desc_long), enum_type(nullptr), restricted(true) {
|
||||
min = min_val;
|
||||
max = max_val;
|
||||
g_UnregisteredCatVars.push(this);
|
||||
}
|
||||
|
||||
CatVar::CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long, CatEnum& cat_enum)
|
||||
: type(type), name(name), defaults(defaults), desc_short(desc_short), desc_long(desc_long), enum_type(&cat_enum), restricted(true) {
|
||||
min = cat_enum.Minimum();
|
||||
max = cat_enum.Maximum();
|
||||
g_UnregisteredCatVars.push(this);
|
||||
}
|
||||
|
||||
void CatVar::Register() {
|
||||
convar = CreateConVar(CON_PREFIX + name, defaults, desc_short);
|
||||
convar_parent = convar->m_pParent;
|
||||
while (!callbacks.empty()) {
|
||||
callbacks.top()(this);
|
||||
callbacks.pop();
|
||||
}
|
||||
registered = true;
|
||||
}
|
||||
|
||||
std::stack<CatVar*> g_UnregisteredCatVars;
|
||||
void RegisterCatVars() {
|
||||
while (g_UnregisteredCatVars.size()) {
|
||||
CatVar* var = g_UnregisteredCatVars.top();
|
||||
var->Register();
|
||||
g_UnregisteredCatVars.pop();
|
||||
}
|
||||
}
|
||||
|
||||
CatEnum::CatEnum(std::vector<std::string> values, int min) : m_values(values) {
|
||||
m_iMin = min;
|
||||
m_iMax = min + values.size() - 1;
|
||||
m_iLength = values.size();
|
||||
@ -34,11 +79,11 @@ std::string CatEnum::Name(int value) {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
int CatEnum::Maximum() {
|
||||
int CatEnum::Maximum() const {
|
||||
return m_iMax;
|
||||
}
|
||||
|
||||
int CatEnum::Minimum() {
|
||||
int CatEnum::Minimum() const {
|
||||
return m_iMin;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ class ConVar;
|
||||
#include "beforecheaders.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <stack>
|
||||
#include "aftercheaders.h"
|
||||
|
||||
@ -37,9 +38,9 @@ class CatEnum {
|
||||
public:
|
||||
CatEnum(std::vector<std::string> values, int min = 0);
|
||||
std::string Name(int value);
|
||||
int Maximum();
|
||||
int Minimum();
|
||||
std::vector<std::string> m_values;
|
||||
int Maximum() const ;
|
||||
int Minimum() const ;
|
||||
const std::vector<std::string> m_values;
|
||||
int m_iMin;
|
||||
int m_iMax;
|
||||
int m_iLength;
|
||||
@ -47,42 +48,55 @@ public:
|
||||
|
||||
class CatVar {
|
||||
public:
|
||||
[[deprecated]]
|
||||
CatVar(CatVar_t type, std::string name, std::string value, std::string help, CatEnum* enum_type = 0, std::string long_description = "no description", bool hasminmax = false, float max = 1.0f, float min = 0.0f);
|
||||
inline CatVar_t GetType() { return m_Type; }
|
||||
inline CatEnum* GetEnum() { return m_EnumType; }
|
||||
inline ConVar* GetConVar() { return m_pConVar; }
|
||||
inline void SetDescription(std::string description) { m_strDescription = description; }
|
||||
inline std::string Description() { return m_strDescription; }
|
||||
|
||||
CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long);
|
||||
CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long, float max_val);
|
||||
CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long, float min_val, float max_val);
|
||||
CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long, CatEnum& cat_enum);
|
||||
|
||||
inline explicit operator bool() const { return !!convar_parent->m_nValue; }
|
||||
inline explicit operator int() const { return convar_parent->m_nValue; }
|
||||
inline explicit operator float() const { return convar_parent->m_fValue; }
|
||||
inline void operator =(const int& value) { convar_parent->InternalSetIntValue(value); }
|
||||
inline void operator =(const float& value) { convar_parent->InternalSetFloatValue(value); }
|
||||
inline bool operator ==(const int& value) { return convar_parent->m_nValue == value; }
|
||||
inline bool operator ==(const float& value) { return convar_parent->m_fValue == value; }
|
||||
inline bool operator ==(const int& value) const { return convar_parent->m_nValue == value; }
|
||||
inline bool operator ==(const float& value) const { return convar_parent->m_fValue == value; }
|
||||
|
||||
void Register();
|
||||
typedef std::function<void(CatVar*)> RegisterCallbackFn;
|
||||
std::stack<RegisterCallbackFn> callbacks;
|
||||
inline void OnRegister(RegisterCallbackFn fn) {
|
||||
if (registered) fn(this);
|
||||
else callbacks.push(fn);
|
||||
}
|
||||
|
||||
[[deprecated]]
|
||||
inline bool GetBool() const { return m_pConVar->GetBool(); }
|
||||
inline bool GetBool() const { return this->operator bool(); }
|
||||
[[deprecated]]
|
||||
inline int GetInt() const { return m_pConVar->GetInt(); }
|
||||
inline int GetInt() const { return this->operator int(); }
|
||||
[[deprecated]]
|
||||
inline float GetFloat() const { return m_pConVar->GetFloat(); };
|
||||
inline const char* GetString() const { return m_pConVar->GetString(); }
|
||||
inline float GetFloat() const { return this->operator float(); };
|
||||
inline const char* GetString() const { return convar_parent->GetString(); }
|
||||
[[deprecated]]
|
||||
inline void SetValue(float value) { m_pConVar->SetValue(value); }
|
||||
inline void SetValue(std::string value) { m_pConVar->SetValue(value.c_str()); }
|
||||
inline void SetValue(float value) { this->operator =(value); }
|
||||
inline void SetValue(std::string value) { convar_parent->SetValue(value.c_str()); }
|
||||
[[deprecated]]
|
||||
inline void SetValue(int value) { m_pConVar->SetValue(value); }
|
||||
inline void SetValue(int value) { this->operator =(value); }
|
||||
|
||||
bool m_bHasMinmax;
|
||||
float m_flMaxValue;
|
||||
float m_flMinValue;
|
||||
bool restricted;
|
||||
float max;
|
||||
float min;
|
||||
bool registered;
|
||||
|
||||
std::string m_strDescription;
|
||||
CatEnum* m_EnumType;
|
||||
CatVar_t m_Type;
|
||||
ConVar* m_pConVar;
|
||||
const CatVar_t type;
|
||||
const std::string name;
|
||||
const std::string defaults;
|
||||
const std::string desc_short;
|
||||
const std::string desc_long;
|
||||
CatEnum* enum_type;
|
||||
ConVar* convar;
|
||||
ConVar* convar_parent;
|
||||
};
|
||||
|
||||
|
@ -41,7 +41,9 @@ void GlobalSettings::Init() {
|
||||
this->bNoVisuals = new CatVar(CV_SWITCH, "novisuals", "0", "Disable visuals", NULL, "Disable all visuals");
|
||||
this->bCleanScreenshots = new CatVar(CV_SWITCH, "clean_screenshot", "1", "Clean screenshots", NULL, "Clean screenshots");
|
||||
this->bDebugLog = new CatVar(CV_SWITCH, "log", "1", "Debug Log", NULL, "Disable this if you don't need cathook messages in your console");
|
||||
this->bThirdperson->m_pConVar->InstallChangeCallback(ThirdpersonCallback);
|
||||
this->bThirdperson->OnRegister([](CatVar* var) {
|
||||
var->convar->InstallChangeCallback(ThirdpersonCallback);
|
||||
});
|
||||
this->bFastOutline = new CatVar(CV_SWITCH, "fastoutline", "0", "Low quality outline", NULL, "Might increase performance when there is a lot of ESP text to draw");
|
||||
this->kRollSpeedhack = new CatVar(CV_KEY, "rollspeedhack", "0", "Roll Speedhack", NULL, "Roll speedhack key");
|
||||
bInvalid = true;
|
||||
|
@ -18,16 +18,16 @@
|
||||
#include "../common.h"
|
||||
#include "../sdk.h"
|
||||
|
||||
CCVarContainer::CCVarContainer(IWidget* parent, CatVar* var) : CBaseContainer(("cvc_" + std::string(var->m_pConVar->GetName())), parent) {
|
||||
CCVarContainer::CCVarContainer(IWidget* parent, CatVar* var) : CBaseContainer("cvc_" + var->name, parent) {
|
||||
m_pVar = var;
|
||||
m_pInput = 0;
|
||||
m_pLabel = new CTextLabel(GetName() + "_desc", this, std::string(var->m_pConVar->GetHelpText()));
|
||||
m_pLabel = new CTextLabel(GetName() + "_desc", this, var->desc_short);
|
||||
m_pControl = 0;
|
||||
if (var->Description().length()) {
|
||||
Props()->SetString("tooltip", var->Description().c_str());
|
||||
if (var->desc_short.length()) {
|
||||
Props()->SetString("tooltip", var->desc_short.c_str());
|
||||
}
|
||||
bool needsinput = false;
|
||||
switch (var->GetType()) {
|
||||
switch (var->type) {
|
||||
case CatVar_t::CV_SWITCH: {// Label, Checkbox
|
||||
CCheckbox* cb = new CCheckbox(GetName() + "_control", this, var->GetBool());
|
||||
cb->SetCallback([this](CCheckbox*, bool value) {
|
||||
@ -37,19 +37,19 @@ CCVarContainer::CCVarContainer(IWidget* parent, CatVar* var) : CBaseContainer(("
|
||||
} break;
|
||||
case CatVar_t::CV_ENUM: { // Most difficult thing, dropdown menu
|
||||
CDropdown* dd = new CDropdown(GetName() + "_control", this);
|
||||
for (int i = var->GetEnum()->Minimum(); i <= var->GetEnum()->Maximum(); i++) {
|
||||
dd->AddValue(var->GetEnum()->Name(i));
|
||||
for (int i = var->enum_type->Minimum(); i <= var->enum_type->Maximum(); i++) {
|
||||
dd->AddValue(var->enum_type->Name(i));
|
||||
}
|
||||
dd->SetCallback([this](CDropdown*, int value) {
|
||||
m_pVar->SetValue(value);
|
||||
});
|
||||
dd->Props()->SetInt("offset", var->GetEnum()->Minimum());
|
||||
dd->Props()->SetInt("offset", var->enum_type->Minimum());
|
||||
m_pControl = dd;
|
||||
} break;
|
||||
case CatVar_t::CV_FLOAT: {
|
||||
if (var->m_bHasMinmax) {
|
||||
if (var->restricted) {
|
||||
CSlider* sl = new CSlider(GetName() + "_control", this);
|
||||
sl->Setup(var->m_flMinValue, var->m_flMaxValue);
|
||||
sl->Setup(var->min, var->max);
|
||||
sl->SetValue(var->GetFloat());
|
||||
m_pControl = sl;
|
||||
sl->SetCallback([this](CSlider*, float oldv, float newv) {
|
||||
@ -59,9 +59,9 @@ CCVarContainer::CCVarContainer(IWidget* parent, CatVar* var) : CBaseContainer(("
|
||||
needsinput = true;
|
||||
} break;
|
||||
case CatVar_t::CV_INT: {
|
||||
if (var->m_bHasMinmax) {
|
||||
if (var->restricted) {
|
||||
CSlider* sl = new CSlider(GetName() + "_control", this);
|
||||
sl->Setup(var->m_flMinValue, var->m_flMaxValue);
|
||||
sl->Setup(var->min, var->max);
|
||||
sl->SetStep(1.0f);
|
||||
sl->SetValue(var->GetInt());
|
||||
sl->SetCallback([this](CSlider*, float oldv, float newv) {
|
||||
@ -88,7 +88,7 @@ CCVarContainer::CCVarContainer(IWidget* parent, CatVar* var) : CBaseContainer(("
|
||||
m_pInput = new CTextInput(GetName() + "_input", this);
|
||||
m_pInput->SetValue(std::string(var->GetString()));
|
||||
m_pInput->SetCallback([this](CTextInput*, std::string old, std::string newv) {
|
||||
if (m_pVar->GetType() == CV_STRING) {
|
||||
if (m_pVar->type == CV_STRING) {
|
||||
m_pVar->SetValue(newv);
|
||||
} else {
|
||||
try {
|
||||
@ -148,7 +148,7 @@ void CCVarContainer::Update() {
|
||||
if (!m_pInput->IsFocused()) m_pInput->SetValue(m_pVar->GetString());
|
||||
}
|
||||
if (m_pControl && !m_pControl->IsFocused()) {
|
||||
switch (m_pVar->GetType()) {
|
||||
switch (m_pVar->type) {
|
||||
case CatVar_t::CV_ENUM: {
|
||||
dynamic_cast<CDropdown*>(m_pControl)->SetValue(m_pVar->GetInt());
|
||||
} break;
|
||||
|
@ -39,7 +39,9 @@ CatGUI::~CatGUI() {
|
||||
void CatGUI::Setup() {
|
||||
m_pRootWindow = new RootWindow();
|
||||
m_pRootWindow->Setup();
|
||||
v_bGUIVisible->m_pConVar->InstallChangeCallback(GUIVisibleCallback);
|
||||
v_bGUIVisible->OnRegister([](CatVar* var) {
|
||||
var->convar->InstallChangeCallback(GUIVisibleCallback);
|
||||
});
|
||||
}
|
||||
|
||||
void CatGUI::ShowTooltip(std::string text) {
|
||||
|
@ -140,8 +140,8 @@ void hack::Initialize() {
|
||||
hack::InitHacks();
|
||||
g_Settings.Init();
|
||||
g_pGUI = new CatGUI();
|
||||
g_pGUI->Setup();
|
||||
EndConVars();
|
||||
g_pGUI->Setup();
|
||||
gNetvars.init();
|
||||
InitNetVars();
|
||||
g_pLocalPlayer = new LocalPlayer();
|
||||
|
@ -78,7 +78,7 @@ KillSay::~KillSay() {
|
||||
}
|
||||
|
||||
void KillSay::Reload() {
|
||||
m_TextFile->LoadFile(v_sFileName->m_pConVar->GetString());
|
||||
m_TextFile->LoadFile(v_sFileName->GetString());
|
||||
}
|
||||
|
||||
void CC_KillSay_ReloadFile(const CCommand& args) {
|
||||
|
@ -34,6 +34,7 @@ void BeginConVars() {
|
||||
}
|
||||
|
||||
void EndConVars() {
|
||||
RegisterCatVars();
|
||||
if (hConVarsFile) {
|
||||
fprintf(hConVarsFile, "\nexec cat_autoexec\n");
|
||||
fprintf(hConVarsFile, "cat_killsay_reload\ncat_spam_reload\n");
|
||||
|
@ -50,7 +50,7 @@ void Shutdown_hook(void* thisptr, const char* reason) {
|
||||
SEGV_BEGIN;
|
||||
if (g_Settings.bHackEnabled->GetBool()) {
|
||||
const char* new_reason = reason;
|
||||
if (g_Settings.sDisconnectMsg->m_pConVar->m_StringLength > 3) {
|
||||
if (g_Settings.sDisconnectMsg->convar->m_StringLength > 3) {
|
||||
new_reason = g_Settings.sDisconnectMsg->GetString();
|
||||
}
|
||||
((Shutdown_t*)hooks::hkNetChannel->GetMethod(hooks::offShutdown))(thisptr, new_reason);
|
||||
|
Reference in New Issue
Block a user