start removing catvars
This commit is contained in:
parent
2ff8251432
commit
36f26e7b34
@ -52,6 +52,7 @@ add_subdirectory(hooks)
|
||||
add_subdirectory(reclasses)
|
||||
add_subdirectory(sdk)
|
||||
add_subdirectory(online)
|
||||
add_subdirectory(settings)
|
||||
|
||||
if(EnableVisuals)
|
||||
add_subdirectory(visual)
|
||||
|
@ -16,36 +16,6 @@ class ConVar;
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
// Catvar types
|
||||
enum CatVar_t
|
||||
{
|
||||
CV_SWITCH,
|
||||
CV_INT,
|
||||
CV_FLOAT,
|
||||
CV_STRING,
|
||||
CV_ENUM,
|
||||
CV_KEY
|
||||
};
|
||||
|
||||
// TODO reverse
|
||||
// Enum Something
|
||||
class CatEnum
|
||||
{
|
||||
public:
|
||||
CatEnum(std::vector<std::string> values, int min = 0);
|
||||
std::string Name(int value);
|
||||
|
||||
public:
|
||||
const std::vector<std::string> value_names;
|
||||
int min_value;
|
||||
int max_value;
|
||||
int size;
|
||||
};
|
||||
namespace hacks::tf2::global
|
||||
{
|
||||
void runcfg();
|
||||
}
|
||||
// TODO reverse, no idea how catcommands are handled
|
||||
class CatCommand
|
||||
{
|
||||
public:
|
||||
@ -66,133 +36,6 @@ public:
|
||||
ConCommand *cmd{ nullptr };
|
||||
};
|
||||
|
||||
class CatVar
|
||||
{
|
||||
public: // TODo, unknown reverse
|
||||
CatVar(CatVar_t type, std::string name, std::string defaults,
|
||||
std::string desc_short, std::string desc_long = "no description");
|
||||
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(CatEnum &cat_enum, std::string name, std::string defaults,
|
||||
std::string desc_short, std::string desc_long);
|
||||
|
||||
inline operator bool() const
|
||||
{
|
||||
if (this && convar_parent && convar_parent->IsRegistered() &&
|
||||
this->registered)
|
||||
return !!convar_parent->m_nValue;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
inline operator int() const
|
||||
{
|
||||
return convar_parent->m_nValue;
|
||||
}
|
||||
inline 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) 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;
|
||||
void OnRegister(RegisterCallbackFn fn);
|
||||
void InstallChangeCallback(FnChangeCallback_t callback);
|
||||
|
||||
[[deprecated]] inline bool GetBool() const
|
||||
{
|
||||
return this->operator bool();
|
||||
}
|
||||
[[deprecated]] inline int GetInt() const
|
||||
{
|
||||
return this->operator int();
|
||||
}
|
||||
[[deprecated]] inline float GetFloat() const
|
||||
{
|
||||
return this->operator float();
|
||||
};
|
||||
inline const char *GetString() const
|
||||
{
|
||||
return convar_parent->GetString();
|
||||
}
|
||||
[[deprecated]] 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)
|
||||
{
|
||||
this->operator=(value);
|
||||
}
|
||||
|
||||
inline bool KeyDown()
|
||||
{
|
||||
return g_IInputSystem->IsButtonDown(
|
||||
static_cast<ButtonCode_t>(static_cast<int>(*this)));
|
||||
}
|
||||
|
||||
inline const std::string &GetBase() const
|
||||
{
|
||||
return current_base;
|
||||
}
|
||||
|
||||
// Storage for the catvar
|
||||
public:
|
||||
const CatVar_t type;
|
||||
const std::string name;
|
||||
const std::string defaults{ "0" };
|
||||
const std::string desc_short{ "" };
|
||||
const std::string desc_long{ "" };
|
||||
CatEnum *enum_type{ nullptr };
|
||||
|
||||
std::string current_base{ "0" };
|
||||
|
||||
bool restricted{ false };
|
||||
float min{ 0.0f };
|
||||
float max{ 0.0f };
|
||||
|
||||
std::vector<RegisterCallbackFn> callbacks{};
|
||||
bool registered{ false };
|
||||
|
||||
ConVar *convar{ nullptr };
|
||||
ConVar *convar_parent{ nullptr };
|
||||
|
||||
int id{ 0 };
|
||||
static int last_id;
|
||||
};
|
||||
|
||||
// TODO, find out what this formatting does "std::vector<ClassName*?>&
|
||||
// ArrayName()?"
|
||||
|
||||
// needed for registration
|
||||
std::vector<CatVar *> ®istrationArray();
|
||||
std::vector<CatCommand *> &commandRegistrationArray();
|
||||
// List to store catvars
|
||||
std::vector<CatVar *> &CatVarList();
|
||||
|
||||
// Setup commands probs needed at int
|
||||
void RegisterCatCommands();
|
||||
void RegisterCatVars();
|
||||
int GetRebasedCatVarCount();
|
||||
|
@ -21,8 +21,7 @@ extern const std::vector<std::string> builtin_nonecore;
|
||||
extern const std::vector<std::string> builtin_lmaobox;
|
||||
extern const std::vector<std::string> builtin_lithium;
|
||||
|
||||
extern CatVar spam_source;
|
||||
|
||||
bool isActive();
|
||||
void Init();
|
||||
void CreateMove();
|
||||
void Reload();
|
||||
|
82
include/settings/Bool.hpp
Normal file
82
include/settings/Bool.hpp
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
Created on 01.07.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Settings.hpp"
|
||||
#include "Manager.hpp"
|
||||
|
||||
namespace settings
|
||||
{
|
||||
|
||||
template<>
|
||||
class Variable<bool>: public VariableBase<bool>
|
||||
{
|
||||
public:
|
||||
~Variable() override = default;
|
||||
|
||||
Variable() = default;
|
||||
|
||||
explicit Variable(bool v)
|
||||
{
|
||||
setInternal(v);
|
||||
}
|
||||
|
||||
VariableType getType() override
|
||||
{
|
||||
return VariableType::BOOL;
|
||||
}
|
||||
|
||||
void fromString(const std::string& string) override
|
||||
{
|
||||
if (string == "0" || string == "false")
|
||||
setInternal(false);
|
||||
else if (string == "1" || string == "true")
|
||||
setInternal(true);
|
||||
}
|
||||
|
||||
Variable<bool>& operator=(const std::string& string)
|
||||
{
|
||||
fromString(string);
|
||||
}
|
||||
|
||||
const std::string &toString() override
|
||||
{
|
||||
return string;
|
||||
}
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
Variable<bool>& operator=(bool next)
|
||||
{
|
||||
setInternal(next);
|
||||
}
|
||||
|
||||
const bool &operator*() override
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
void flip()
|
||||
{
|
||||
setInternal(!value);
|
||||
}
|
||||
|
||||
protected:
|
||||
void setInternal(bool next)
|
||||
{
|
||||
if (next == value)
|
||||
return;
|
||||
fireCallbacks(next);
|
||||
value = next;
|
||||
string = value ? "true" : "false";
|
||||
}
|
||||
|
||||
bool value{ false };
|
||||
std::string string{ "false" };
|
||||
};
|
||||
|
||||
}
|
17
include/settings/CMakeLists.txt
Normal file
17
include/settings/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
target_sources(cathook PRIVATE
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Bool.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Float.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Int.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Key.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Manager.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Registered.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Settings.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/SettingsIO.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/String.hpp")
|
||||
|
||||
if (EnableVisuals)
|
||||
target_sources(cathook PRIVATE
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Rgba.hpp")
|
||||
endif()
|
||||
|
||||
target_include_directories(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}")
|
55
include/settings/Float.hpp
Normal file
55
include/settings/Float.hpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
Created on 01.07.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Settings.hpp"
|
||||
|
||||
namespace settings
|
||||
{
|
||||
|
||||
template<>
|
||||
class Variable<float>: public ArithmeticVariable<float>
|
||||
{
|
||||
public:
|
||||
~Variable<float>() override = default;
|
||||
|
||||
VariableType getType() override
|
||||
{
|
||||
return VariableType::FLOAT;
|
||||
}
|
||||
|
||||
void fromString(const std::string &string) override
|
||||
{
|
||||
errno = 0;
|
||||
auto next = std::strtof(string.c_str(), nullptr);
|
||||
if (next == 0.0f && errno)
|
||||
return;
|
||||
set(next);
|
||||
}
|
||||
|
||||
Variable<float>& operator=(const std::string& string)
|
||||
{
|
||||
fromString(string);
|
||||
}
|
||||
|
||||
Variable<float>& operator=(const float& next)
|
||||
{
|
||||
set(next);
|
||||
}
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return value != 0.0f;
|
||||
}
|
||||
protected:
|
||||
void updateString() override
|
||||
{
|
||||
char str[32];
|
||||
snprintf(str, 31, "%.2f", value);
|
||||
string = str;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
48
include/settings/Int.hpp
Normal file
48
include/settings/Int.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Created on 01.07.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Settings.hpp"
|
||||
|
||||
namespace settings
|
||||
{
|
||||
|
||||
template<>
|
||||
class Variable<int>: public ArithmeticVariable<int>
|
||||
{
|
||||
public:
|
||||
~Variable() override = default;
|
||||
|
||||
VariableType getType() override
|
||||
{
|
||||
return VariableType::INT;
|
||||
}
|
||||
|
||||
void fromString(const std::string& string) override
|
||||
{
|
||||
errno = 0;
|
||||
auto result = std::strtol(string.c_str(), nullptr, 10);
|
||||
if (result == 0 && errno)
|
||||
return;
|
||||
set(result);
|
||||
}
|
||||
|
||||
Variable<int>& operator=(const std::string& string)
|
||||
{
|
||||
fromString(string);
|
||||
}
|
||||
|
||||
Variable<int>& operator=(const int& next)
|
||||
{
|
||||
set(next);
|
||||
}
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return value != 0;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
143
include/settings/Key.hpp
Normal file
143
include/settings/Key.hpp
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
Created on 01.07.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_keycode.h>
|
||||
#include <SDL2/SDL_system.h>
|
||||
#include <SDL2/SDL_mouse.h>
|
||||
#include "Settings.hpp"
|
||||
|
||||
namespace settings
|
||||
{
|
||||
|
||||
struct Key
|
||||
{
|
||||
int mouse{ 0 };
|
||||
SDL_Scancode scan{ static_cast<SDL_Scancode>(0) };
|
||||
};
|
||||
|
||||
template<>
|
||||
class Variable<Key>: public VariableBase<Key>
|
||||
{
|
||||
public:
|
||||
~Variable() override = default;
|
||||
|
||||
VariableType getType() override
|
||||
{
|
||||
return VariableType::KEY;
|
||||
}
|
||||
|
||||
// Valid inputs: "Mouse1", "Mouse5", "Key 6", "Key 10", "Key 2", "Space".
|
||||
void fromString(const std::string& string) override
|
||||
{
|
||||
if (string == "<null>")
|
||||
{
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
Key key{};
|
||||
if (string.find("Mouse") != std::string::npos)
|
||||
{
|
||||
key.mouse = std::strtol(string.c_str() + 5, nullptr, 10);
|
||||
}
|
||||
else if (string.find("Key ") != std::string::npos)
|
||||
{
|
||||
key.scan = static_cast<SDL_Scancode>(std::strtol(string.c_str() + 4,
|
||||
nullptr, 10));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto code = SDL_GetKeyFromName(string.c_str());
|
||||
if (code != SDLK_UNKNOWN)
|
||||
key.scan = SDL_GetScancodeFromKey(code);
|
||||
}
|
||||
|
||||
setInternal(key);
|
||||
}
|
||||
|
||||
Variable& operator=(const std::string& string)
|
||||
{
|
||||
fromString(string);
|
||||
}
|
||||
|
||||
Variable& reset()
|
||||
{
|
||||
setInternal(Key{});
|
||||
}
|
||||
|
||||
Variable& key(SDL_Scancode key)
|
||||
{
|
||||
Key k{};
|
||||
k.scan = key;
|
||||
setInternal(k);
|
||||
}
|
||||
|
||||
Variable& mouse(int mouse_key)
|
||||
{
|
||||
Key k{};
|
||||
k.mouse = mouse_key;
|
||||
setInternal(k);
|
||||
}
|
||||
|
||||
const Key &operator*() override
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
const std::string &toString() override
|
||||
{
|
||||
return string;
|
||||
}
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return value.mouse || value.scan;
|
||||
}
|
||||
|
||||
bool isKeyDown() const
|
||||
{
|
||||
if (value.mouse)
|
||||
{
|
||||
auto flag = SDL_GetMouseState(nullptr, nullptr);
|
||||
if (flag & SDL_BUTTON(value.mouse))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto keys = SDL_GetKeyboardState(nullptr);
|
||||
if (keys[value.scan])
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
void setInternal(Key next)
|
||||
{
|
||||
if (next.mouse)
|
||||
string = "Mouse" + std::to_string(next.mouse);
|
||||
else
|
||||
{
|
||||
if (next.scan == static_cast<SDL_Scancode>(0))
|
||||
string = "<null>";
|
||||
else
|
||||
{
|
||||
const char *s = SDL_GetKeyName(SDL_GetKeyFromScancode(next.scan));
|
||||
if (!s || *s == 0)
|
||||
string = "Key " + std::to_string(next.scan);
|
||||
else
|
||||
string = s;
|
||||
}
|
||||
}
|
||||
value = next;
|
||||
fireCallbacks(next);
|
||||
}
|
||||
|
||||
std::string string{};
|
||||
Key value{};
|
||||
};
|
||||
|
||||
}
|
49
include/settings/Manager.hpp
Normal file
49
include/settings/Manager.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Created on 02.07.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "Settings.hpp"
|
||||
|
||||
/*
|
||||
* Default value = value when variable was registered
|
||||
*
|
||||
* Manager needs to be able to:
|
||||
* - Save config
|
||||
* - Load config
|
||||
* - Get value by name
|
||||
* - Set value by name
|
||||
* - Reset variable to defaults
|
||||
* - Reset everything to defaults
|
||||
* - Rebase config (hmmm)
|
||||
*/
|
||||
|
||||
namespace settings
|
||||
{
|
||||
|
||||
class Manager
|
||||
{
|
||||
public:
|
||||
struct VariableDescriptor
|
||||
{
|
||||
explicit VariableDescriptor(IVariable& variable);
|
||||
|
||||
bool isChanged();
|
||||
|
||||
IVariable& variable;
|
||||
std::string defaults{};
|
||||
VariableType type{};
|
||||
};
|
||||
|
||||
static Manager& instance();
|
||||
public:
|
||||
void add(IVariable& me, std::string name);
|
||||
IVariable *lookup(const std::string& string);
|
||||
|
||||
std::unordered_map<std::string, VariableDescriptor> registered{};
|
||||
};
|
||||
|
||||
}
|
45
include/settings/Registered.hpp
Normal file
45
include/settings/Registered.hpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Created on 02.07.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Settings.hpp"
|
||||
|
||||
namespace settings
|
||||
{
|
||||
|
||||
void registerVariable(IVariable& variable, std::string name);
|
||||
|
||||
template<typename T>
|
||||
class RegisteredVariableProxy: public Variable<T>
|
||||
{
|
||||
public:
|
||||
using Variable<T>::operator=;
|
||||
|
||||
explicit RegisteredVariableProxy(std::string name)
|
||||
{
|
||||
registerVariable(*this, name);
|
||||
}
|
||||
|
||||
RegisteredVariableProxy(std::string name, std::string value)
|
||||
{
|
||||
this->fromString(value);
|
||||
registerVariable(*this, name);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using RVariable = RegisteredVariableProxy<T>;
|
||||
|
||||
using Bool = RegisteredVariableProxy<bool>;
|
||||
using Int = RegisteredVariableProxy<int>;
|
||||
using Float = RegisteredVariableProxy<float>;
|
||||
using String = RegisteredVariableProxy<std::string>;
|
||||
using Button = RegisteredVariableProxy<Key>;
|
||||
|
||||
#if ENABLE_VISUALS
|
||||
using Rgba = RegisteredVariableProxy<glez::rgba>;
|
||||
#endif
|
||||
|
||||
}
|
88
include/settings/Rgba.hpp
Normal file
88
include/settings/Rgba.hpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
Created on 01.07.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Settings.hpp"
|
||||
|
||||
constexpr uint8_t hexToInt(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
return 10 + c - 'a';
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
return 10 + c - 'A';
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace settings
|
||||
{
|
||||
|
||||
template<>
|
||||
class Variable<glez::rgba>: public VariableBase<glez::rgba>
|
||||
{
|
||||
public:
|
||||
~Variable<glez::rgba>() override = default;
|
||||
|
||||
VariableType getType() override
|
||||
{
|
||||
return VariableType::COLOR;
|
||||
}
|
||||
|
||||
void fromString(const std::string& string) override
|
||||
{
|
||||
uint8_t rgba[4] = { 0, 0, 0, 255 };
|
||||
|
||||
for (int i = 0; i < string.length() && i < 8; ++i)
|
||||
{
|
||||
if (!(i % 2))
|
||||
rgba[i / 2] = 0;
|
||||
rgba[i / 2] |= (hexToInt(string[i]) << ((i % 2) ? 0 : 4));
|
||||
}
|
||||
|
||||
glez::rgba next{};
|
||||
next.r = float(rgba[0]) / 255.f;
|
||||
next.g = float(rgba[1]) / 255.f;
|
||||
next.b = float(rgba[2]) / 255.f;
|
||||
next.a = float(rgba[3]) / 255.f;
|
||||
setInternal(next);
|
||||
}
|
||||
|
||||
Variable<glez::rgba>& operator=(const glez::rgba& rgba)
|
||||
{
|
||||
setInternal(rgba);
|
||||
}
|
||||
|
||||
Variable<glez::rgba>& operator=(const std::string& string)
|
||||
{
|
||||
fromString(string);
|
||||
}
|
||||
|
||||
const std::string &toString() override
|
||||
{
|
||||
return string;
|
||||
}
|
||||
const glez::rgba &operator*() override
|
||||
{
|
||||
return value;
|
||||
}
|
||||
protected:
|
||||
void setInternal(glez::rgba next)
|
||||
{
|
||||
fireCallbacks(next);
|
||||
value = next;
|
||||
uint8_t rgba_int[4] = { uint8_t(next.r * 255.f), uint8_t(next.g * 255.f), uint8_t(next.b * 255.f), uint8_t(next.a * 255.f) };
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
string[i * 2] = "0123456789abcdef"[(rgba_int[i] >> 4u) & 0xF];
|
||||
string[i * 2 + 1] = "0123456789abcdef"[rgba_int[i] & 0xF];
|
||||
}
|
||||
}
|
||||
|
||||
glez::rgba value{};
|
||||
std::string string{ "00000000" };
|
||||
};
|
||||
|
||||
}
|
146
include/settings/Settings.hpp
Normal file
146
include/settings/Settings.hpp
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
Created on 25.06.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <glez/color.hpp>
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/*
|
||||
|
||||
Value types:
|
||||
- bool
|
||||
- int
|
||||
- float
|
||||
- string
|
||||
- rgba
|
||||
|
||||
Interface:
|
||||
from/to String
|
||||
get, set
|
||||
on change callback
|
||||
|
||||
increment / decrement
|
||||
|
||||
set max string length
|
||||
|
||||
set default value
|
||||
reset to default
|
||||
|
||||
*/
|
||||
|
||||
namespace settings
|
||||
{
|
||||
|
||||
enum class VariableType
|
||||
{
|
||||
BOOL,
|
||||
INT,
|
||||
FLOAT,
|
||||
STRING,
|
||||
COLOR,
|
||||
KEY
|
||||
};
|
||||
|
||||
class IVariable
|
||||
{
|
||||
public:
|
||||
virtual ~IVariable() = default;
|
||||
|
||||
// Faster than checking with dynamic_cast
|
||||
virtual VariableType getType() = 0;
|
||||
virtual void fromString(const std::string& string) = 0;
|
||||
// Const reference because every variable will cache the string value instead of generating it every call
|
||||
virtual const std::string& toString() = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class VariableBase: public IVariable
|
||||
{
|
||||
public:
|
||||
using type = T;
|
||||
|
||||
~VariableBase() override = default;
|
||||
|
||||
virtual const T& operator*() = 0;
|
||||
|
||||
void installChangeCallback(std::function<void(VariableBase<T>& var, T after)> callback)
|
||||
{
|
||||
callbacks.push_back(callback);
|
||||
}
|
||||
protected:
|
||||
void fireCallbacks(T next)
|
||||
{
|
||||
for (auto& c: callbacks)
|
||||
c(*this, next);
|
||||
}
|
||||
|
||||
std::vector<std::function<void(VariableBase<T>&, T)>> callbacks{};
|
||||
T default_value{};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Variable
|
||||
{
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class ArithmeticVariable: public VariableBase<T>
|
||||
{
|
||||
public:
|
||||
~ArithmeticVariable<T>() override = default;
|
||||
|
||||
explicit operator T() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
const std::string &toString() override
|
||||
{
|
||||
return string;
|
||||
}
|
||||
const T &operator*() override
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
//T min{ std::numeric_limits<T>::min() };
|
||||
//T max{ std::numeric_limits<T>::max() };
|
||||
|
||||
virtual void set(T next)
|
||||
{
|
||||
//if (next < min) next = min;
|
||||
//if (next > max) next = max;
|
||||
if (next != value)
|
||||
{
|
||||
this->fireCallbacks(next);
|
||||
value = next;
|
||||
this->updateString();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
T value{};
|
||||
std::string string{};
|
||||
|
||||
virtual void updateString()
|
||||
{
|
||||
string = std::to_string(value);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include "Bool.hpp"
|
||||
#include "Float.hpp"
|
||||
#include "Int.hpp"
|
||||
#include "String.hpp"
|
||||
#include "Key.hpp"
|
||||
#include "Registered.hpp"
|
||||
|
||||
#if ENABLE_VISUALS
|
||||
#include "Rgba.hpp"
|
||||
#endif
|
55
include/settings/SettingsIO.hpp
Normal file
55
include/settings/SettingsIO.hpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
Created on 27.07.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include "Manager.hpp"
|
||||
|
||||
namespace settings
|
||||
{
|
||||
|
||||
class SettingsReader
|
||||
{
|
||||
public:
|
||||
explicit SettingsReader(Manager& manager);
|
||||
|
||||
bool loadFrom(std::string path);
|
||||
protected:
|
||||
void pushChar(char c);
|
||||
void finishString(bool complete);
|
||||
void onReadKeyValue(std::string key, std::string value);
|
||||
bool reading_key{ true };
|
||||
|
||||
bool escape{ false };
|
||||
bool quote{ false };
|
||||
bool comment{ false };
|
||||
bool was_non_space{ false };
|
||||
|
||||
std::string temporary_spaces{};
|
||||
std::string oss{};
|
||||
std::string stored_key{};
|
||||
std::ifstream stream{};
|
||||
Manager& manager;
|
||||
};
|
||||
|
||||
class SettingsWriter
|
||||
{
|
||||
public:
|
||||
explicit SettingsWriter(Manager& manager);
|
||||
|
||||
bool saveTo(std::string path, bool only_changed);
|
||||
|
||||
protected:
|
||||
void write(std::string name, IVariable *variable);
|
||||
void writeEscaped(std::string str);
|
||||
|
||||
bool only_changed{ false };
|
||||
std::ofstream stream{};
|
||||
Manager& manager;
|
||||
};
|
||||
|
||||
}
|
54
include/settings/String.hpp
Normal file
54
include/settings/String.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Created on 01.07.18.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Settings.hpp"
|
||||
|
||||
namespace settings
|
||||
{
|
||||
|
||||
template<>
|
||||
class Variable<std::string>: public VariableBase<std::string>
|
||||
{
|
||||
public:
|
||||
~Variable() override = default;
|
||||
|
||||
VariableType getType() override
|
||||
{
|
||||
return VariableType::STRING;
|
||||
}
|
||||
|
||||
void fromString(const std::string& string) override
|
||||
{
|
||||
fireCallbacks(string);
|
||||
value = string;
|
||||
}
|
||||
|
||||
const std::string &toString() override
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
Variable<std::string>& operator=(const std::string& string)
|
||||
{
|
||||
fireCallbacks(std::string(string));
|
||||
value = string;
|
||||
}
|
||||
|
||||
const std::string &operator*() override
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return !value.empty();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string value{};
|
||||
};
|
||||
|
||||
}
|
@ -13,6 +13,9 @@
|
||||
|
||||
#include <thread>
|
||||
#include <queue>
|
||||
#include <settings/Bool.hpp>
|
||||
|
||||
static settings::Bool bptf_enable{ "backpack-tf.enable", "false" };
|
||||
|
||||
namespace backpacktf
|
||||
{
|
||||
@ -21,14 +24,11 @@ std::unordered_map<unsigned, backpack_data_s> cache{};
|
||||
std::queue<backpack_data_s *> pending_queue{};
|
||||
std::mutex queue_mutex{};
|
||||
std::mutex cache_mutex{};
|
||||
bool thread_running{ true };
|
||||
|
||||
std::string api_key_s = "";
|
||||
bool valid_api_key = false;
|
||||
|
||||
static CatVar
|
||||
enable_bptf(CV_SWITCH, "bptf_enable", "0", "Enable backpack.tf",
|
||||
"Enable backpack.tf integration\nYou have to set your API "
|
||||
"key in cat_bptf_key");
|
||||
CatCommand api_key("bptf_key", "Set API Key", [](const CCommand &args) {
|
||||
api_key_s = args.ArgS();
|
||||
logging::Info("API key changed!");
|
||||
@ -49,7 +49,7 @@ void store_data(unsigned id, float value, bool no_value, bool outdated_value);
|
||||
void processing_thread()
|
||||
{
|
||||
logging::Info("[bp.tf] Starting the thread");
|
||||
while (true)
|
||||
while (thread_running)
|
||||
{
|
||||
if (enabled())
|
||||
{
|
||||
@ -188,7 +188,7 @@ void request_data(unsigned id)
|
||||
|
||||
bool enabled()
|
||||
{
|
||||
return enable_bptf && valid_api_key;
|
||||
return bptf_enable && valid_api_key;
|
||||
}
|
||||
|
||||
backpack_data_s &access_data(unsigned id)
|
||||
@ -235,5 +235,6 @@ std::thread &GetBackpackTFThread()
|
||||
void init()
|
||||
{
|
||||
GetBackpackTFThread();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,15 @@
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#include <hacks/Spam.hpp>
|
||||
#include <settings/Bool.hpp>
|
||||
|
||||
static settings::Bool enable{ "chat-log.enable", "false" };
|
||||
static settings::Bool no_spam{ "chat-log.no-spam", "true" };
|
||||
static settings::Bool no_ipc{ "chat-log.no-ipc","true" };
|
||||
|
||||
namespace chatlog
|
||||
{
|
||||
|
||||
static CatVar enabled(CV_SWITCH, "chat_log", "0", "Chat log",
|
||||
"Log chat to file");
|
||||
static CatVar dont_log_spam(CV_SWITCH, "chat_log_nospam", "1", "No Spam",
|
||||
"Don't log your messages if spam is active");
|
||||
static CatVar dont_log_ipc(CV_SWITCH, "chat_log_noipc", "1", "No IPC",
|
||||
"Don't log messages sent by bots");
|
||||
|
||||
class csv_stream
|
||||
{
|
||||
public:
|
||||
@ -107,17 +105,17 @@ csv_stream &logger()
|
||||
|
||||
void LogMessage(int eid, std::string message)
|
||||
{
|
||||
if (!enabled)
|
||||
if (!enable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (dont_log_spam && hacks::shared::spam::spam_source and
|
||||
if (no_spam && hacks::shared::spam::spam_source and
|
||||
eid == g_IEngine->GetLocalPlayer())
|
||||
return;
|
||||
player_info_s info;
|
||||
if (not g_IEngine->GetPlayerInfo(eid, &info))
|
||||
return;
|
||||
if (dont_log_ipc &&
|
||||
if (no_ipc &&
|
||||
playerlist::AccessData(info.friendsID).state ==
|
||||
playerlist::k_EState::IPC)
|
||||
return;
|
||||
|
@ -5,160 +5,9 @@
|
||||
* Author: nullifiedcat
|
||||
*/
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
int CatVar::last_id{ 0 };
|
||||
|
||||
int rebased_count{ 0 };
|
||||
|
||||
int GetRebasedCatVarCount()
|
||||
{
|
||||
return rebased_count;
|
||||
}
|
||||
enum torun
|
||||
{
|
||||
rebase = 0,
|
||||
resetbase,
|
||||
save,
|
||||
save_complete
|
||||
};
|
||||
int torun = -1;
|
||||
std::string Args[3];
|
||||
namespace hacks::tf2::global
|
||||
{
|
||||
void runcfg()
|
||||
{
|
||||
if (torun == -1)
|
||||
return;
|
||||
if (torun == rebase)
|
||||
{
|
||||
for (auto &cv : CatVarList())
|
||||
{
|
||||
std::string value(cv->GetString());
|
||||
if (value != cv->defaults)
|
||||
{
|
||||
cv->current_base = value;
|
||||
rebased_count++;
|
||||
}
|
||||
}
|
||||
logging::Info("Successfully rebased %d variables", rebased_count);
|
||||
}
|
||||
else if (torun == resetbase)
|
||||
{
|
||||
for (auto &cv : CatVarList())
|
||||
{
|
||||
cv->current_base = cv->defaults;
|
||||
}
|
||||
rebased_count = 0;
|
||||
}
|
||||
else if (torun == save)
|
||||
{
|
||||
std::string filename("lastcfg");
|
||||
if (Args[0] != "")
|
||||
{
|
||||
filename = Args[0];
|
||||
Args[0] = "";
|
||||
}
|
||||
std::string path = format("tf/cfg/cat_", filename, ".cfg");
|
||||
logging::Info("Saving settings to %s", path.c_str());
|
||||
if (GetRebasedCatVarCount())
|
||||
{
|
||||
logging::Info("[Warning] %d CatVars are rebased!",
|
||||
GetRebasedCatVarCount());
|
||||
}
|
||||
std::ofstream file(path, std::ios::out);
|
||||
if (file.bad())
|
||||
{
|
||||
logging::Info("Couldn't open the file!");
|
||||
torun = -1;
|
||||
return;
|
||||
}
|
||||
for (const auto &i : CatVarList())
|
||||
{
|
||||
if (!i)
|
||||
continue;
|
||||
if (!i->GetString())
|
||||
continue;
|
||||
if (i->GetBase() != std::string(i->GetString()))
|
||||
{
|
||||
file << CON_PREFIX << i->name << " \"" << i->GetString()
|
||||
<< "\"\n";
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
else if (torun == save_complete)
|
||||
{
|
||||
std::string filename("lastcfg");
|
||||
if (Args[0] != "")
|
||||
{
|
||||
filename = Args[0];
|
||||
Args[0] = "";
|
||||
}
|
||||
std::string path = format("tf/cfg/cat_", filename, ".cfg");
|
||||
logging::Info("Saving settings to %s", path.c_str());
|
||||
if (GetRebasedCatVarCount())
|
||||
{
|
||||
logging::Info("[Warning] %d CatVars are rebased!",
|
||||
GetRebasedCatVarCount());
|
||||
}
|
||||
std::ofstream file(path, std::ios::out);
|
||||
if (file.bad())
|
||||
{
|
||||
logging::Info("Couldn't open the file!");
|
||||
return;
|
||||
}
|
||||
file << "exec cat_defaults\n";
|
||||
for (const auto &i : CatVarList())
|
||||
{
|
||||
if (!i)
|
||||
continue;
|
||||
if (!i->GetString())
|
||||
continue;
|
||||
if (i->GetBase() != std::string(i->GetString()))
|
||||
{
|
||||
file << CON_PREFIX << i->name << " \"" << i->GetString()
|
||||
<< "\"\n";
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
torun = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static CatCommand cfg_rebase("cfg_setbase", "Rebase config",
|
||||
[]() { torun = rebase; });
|
||||
|
||||
static CatCommand cfg_resetbase("cfg_resetbase", "Reset config base",
|
||||
[]() { torun = resetbase; });
|
||||
|
||||
static CatCommand save_settings("save", "Save settings (optional filename)",
|
||||
[](const CCommand &args) {
|
||||
if (args.ArgC() > 1)
|
||||
{
|
||||
Args[0] = std::string(args.Arg(1));
|
||||
}
|
||||
torun = save;
|
||||
});
|
||||
|
||||
static CatCommand
|
||||
save_settings_complete("save_complete",
|
||||
"Save all settings (optional filename)",
|
||||
[](const CCommand &args) {
|
||||
if (args.ArgC() > 1)
|
||||
{
|
||||
Args[0] = std::string(args.Arg(1));
|
||||
}
|
||||
torun = save_complete;
|
||||
});
|
||||
|
||||
// Prevent initialization errors.
|
||||
std::vector<CatVar *> ®istrationArray()
|
||||
{
|
||||
static std::vector<CatVar *> vector;
|
||||
return vector;
|
||||
}
|
||||
#include <core/cvwrapper.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <common.hpp>
|
||||
|
||||
std::vector<CatCommand *> &commandRegistrationArray()
|
||||
{
|
||||
@ -212,108 +61,4 @@ void RegisterCatCommands()
|
||||
cmd->Register();
|
||||
commandRegistrationArray().pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
registrationArray().push_back(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), restricted(true)
|
||||
{
|
||||
max = max_val;
|
||||
registrationArray().push_back(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), restricted(true)
|
||||
{
|
||||
min = min_val;
|
||||
max = max_val;
|
||||
registrationArray().push_back(this);
|
||||
}
|
||||
|
||||
CatVar::CatVar(CatEnum &cat_enum, std::string _name, std::string _defaults,
|
||||
std::string _desc_short, std::string _desc_long)
|
||||
: type(CV_ENUM), name(_name), defaults(_defaults), desc_short(_desc_short),
|
||||
desc_long(_desc_long), enum_type(&cat_enum), restricted(true)
|
||||
{
|
||||
min = cat_enum.min_value;
|
||||
max = cat_enum.max_value;
|
||||
registrationArray().push_back(this);
|
||||
}
|
||||
|
||||
void CatVar::OnRegister(CatVar::RegisterCallbackFn fn)
|
||||
{
|
||||
if (registered)
|
||||
fn(this);
|
||||
else
|
||||
callbacks.push_back(fn);
|
||||
}
|
||||
|
||||
void CatVar::Register()
|
||||
{
|
||||
CatVarList().push_back(this);
|
||||
id = last_id++;
|
||||
convar = CreateConVar(CON_PREFIX + name, defaults, desc_short);
|
||||
convar_parent = convar->m_pParent;
|
||||
current_base = defaults;
|
||||
while (!callbacks.empty())
|
||||
{
|
||||
callbacks.back()(this);
|
||||
callbacks.pop_back();
|
||||
}
|
||||
registered = true;
|
||||
}
|
||||
|
||||
// TODO, reverse
|
||||
void CatVar::InstallChangeCallback(FnChangeCallback_t callback)
|
||||
{
|
||||
OnRegister([callback](CatVar *var) {
|
||||
var->convar_parent->InstallChangeCallback(callback);
|
||||
});
|
||||
}
|
||||
|
||||
// Used during int to setup catvars
|
||||
void RegisterCatVars()
|
||||
{
|
||||
while (registrationArray().size())
|
||||
{
|
||||
CatVar *var = registrationArray().back();
|
||||
var->Register();
|
||||
registrationArray().pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
// Use when creating a CatEnum for use in a CatVar
|
||||
CatEnum::CatEnum(std::vector<std::string> values, int min) : value_names(values)
|
||||
{
|
||||
min_value = min;
|
||||
max_value = min + int(values.size()) - 1;
|
||||
size = int(values.size());
|
||||
}
|
||||
|
||||
// use to get a name from a CatEnum
|
||||
std::string CatEnum::Name(int value)
|
||||
{
|
||||
if (value >= min_value && value < max_value)
|
||||
{
|
||||
return value_names.at(unsigned(value) - unsigned(min_value));
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
std::vector<CatVar *> &CatVarList()
|
||||
{
|
||||
static std::vector<CatVar *> object{};
|
||||
return object;
|
||||
}
|
||||
}
|
@ -5,16 +5,14 @@
|
||||
* Author: nullifiedcat
|
||||
*/
|
||||
|
||||
#include <settings/Bool.hpp>
|
||||
#include "common.hpp"
|
||||
|
||||
static CatVar crit_info(CV_SWITCH, "crit_info", "0", "Show crit info");
|
||||
static CatVar crit_key(CV_KEY, "crit_key", "0", "Crit Key");
|
||||
static CatVar crit_melee(CV_SWITCH, "crit_melee", "0", "Melee crits");
|
||||
static CatVar crit_legiter(
|
||||
CV_SWITCH, "crit_force_gameplay", "0", "Don't hinder gameplay",
|
||||
"Attempt to crit when possible but do not hinder normal gameplay");
|
||||
static CatVar crit_experimental(CV_SWITCH, "crit_experimental", "0",
|
||||
"Experimental crithack");
|
||||
static settings::Bool crit_info{ "crit.info", "false" };
|
||||
static settings::Button crit_key{ "crit.key", "<null>" };
|
||||
static settings::Bool crit_melee{ "crit.melee", "false" };
|
||||
static settings::Bool crit_legiter{ "crit.force-gameplay", "false" };
|
||||
static settings::Bool crit_experimental{ "crit.experimental", "false" };
|
||||
|
||||
std::unordered_map<int, int> command_number_mod{};
|
||||
|
||||
@ -172,8 +170,8 @@ void create_move()
|
||||
if (!re::C_TFWeaponBase::AreRandomCritsEnabled(weapon))
|
||||
return;
|
||||
unfuck_bucket(weapon);
|
||||
if ((g_pUserCmd->buttons & IN_ATTACK) && crit_key.KeyDown() &&
|
||||
g_pUserCmd->command_number && crit_key)
|
||||
if ((g_pUserCmd->buttons & IN_ATTACK) && crit_key && crit_key.isKeyDown() &&
|
||||
g_pUserCmd->command_number)
|
||||
{
|
||||
force_crit(weapon);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "common.hpp"
|
||||
|
||||
#include <time.h>
|
||||
#include <settings/Float.hpp>
|
||||
|
||||
bool IsProjectileACrit(CachedEntity *ent)
|
||||
{
|
||||
@ -44,10 +45,9 @@ CachedEntity::~CachedEntity()
|
||||
{
|
||||
}
|
||||
|
||||
static CatVar ve_window(CV_FLOAT, "debug_ve_window", "0", "VE Window");
|
||||
static CatVar ve_smooth(CV_SWITCH, "debug_ve_smooth", "1", "VE Smoothing");
|
||||
static CatVar ve_averager_size(CV_INT, "debug_ve_averaging", "8",
|
||||
"VE Averaging");
|
||||
static settings::Float ve_window{ "debug.ve.window", "0" };
|
||||
static settings::Bool ve_smooth{ "debug.ve.smooth", "true" };
|
||||
static settings::Int ve_averager_size{ "debug.ve.averaging", "0" };
|
||||
|
||||
void CachedEntity::Update()
|
||||
{
|
||||
@ -76,8 +76,8 @@ void CachedEntity::Update()
|
||||
g_IEngine->GetPlayerInfo(m_IDX, &player_info);
|
||||
}
|
||||
|
||||
static CatVar fast_vischeck(CV_SWITCH, "fast_vischeck", "0", "Fast VisCheck",
|
||||
"VisCheck only certain player hitboxes");
|
||||
// FIXME maybe disable this by default
|
||||
static settings::Bool fast_vischeck{ "debug.fast-vischeck", "true" };
|
||||
|
||||
bool CachedEntity::IsVisible()
|
||||
{
|
||||
|
@ -5,6 +5,7 @@
|
||||
* Author: nullifiedcat
|
||||
*/
|
||||
|
||||
#include <settings/Int.hpp>
|
||||
#include "common.hpp"
|
||||
|
||||
namespace hitbox_cache
|
||||
@ -105,11 +106,7 @@ bool EntityHitboxCache::VisibilityCheck(int id)
|
||||
return m_VisCheck[id];
|
||||
}
|
||||
|
||||
static CatEnum setupbones_time_enum({ "ZERO", "CURTIME", "LP SERVERTIME",
|
||||
"SIMTIME" });
|
||||
static CatVar setupbones_time(
|
||||
setupbones_time_enum, "setupbones_time", "3", "Setupbones",
|
||||
"Defines setupbones 4th argument, change it if your aimbot misses, idk!!");
|
||||
static settings::Int setupbones_time{ "source.setupbones-time", "3" };
|
||||
|
||||
std::mutex setupbones_mutex;
|
||||
|
||||
|
@ -6,34 +6,21 @@
|
||||
*/
|
||||
|
||||
#include <hacks/Spam.hpp>
|
||||
#include <settings/Bool.hpp>
|
||||
#include "common.hpp"
|
||||
#include "MiscTemporary.hpp"
|
||||
|
||||
static settings::Int spam_source{ "spam.source", "0" };
|
||||
static settings::Bool random_order{ "spam.random", "0" };
|
||||
static settings::String filename{ "spam.filename", "spam.txt" };
|
||||
static settings::Int spam_delay{ "spam.delay", "800" };
|
||||
static settings::Int voicecommand_spam{ "spam.voicecommand", "0" };
|
||||
static settings::Bool teamname_spam{ "spam.teamname","0" };
|
||||
|
||||
namespace hacks::shared::spam
|
||||
{
|
||||
static CatEnum spam_enum({ "DISABLED", "CUSTOM", "DEFAULT", "LENNYFACES",
|
||||
"BLANKS", "NULLCORE", "LMAOBOX", "LITHIUM" });
|
||||
CatVar spam_source(spam_enum, "spam", "0", "Chat Spam",
|
||||
"Defines source of spam lines. CUSTOM spam file must be set "
|
||||
"in cat_spam_file and loaded with cat_spam_reload (Use "
|
||||
"console!)");
|
||||
static CatVar random_order(CV_SWITCH, "spam_random", "0", "Random Order");
|
||||
static CatVar
|
||||
filename(CV_STRING, "spam_file", "spam.txt", "Spam file",
|
||||
"Spam file name. Each line should be no longer than 100 "
|
||||
"characters, file must be located in cathook data folder");
|
||||
CatCommand reload("spam_reload", "Reload spam file", Reload);
|
||||
static CatVar spam_delay(CV_INT, "spam_delay", "800", "Spam delay",
|
||||
"Delay between spam messages (in ms)", 0.0f, 8000.0f);
|
||||
|
||||
static CatEnum voicecommand_enum({ "DISABLED", "RANDOM", "MEDIC", "THANKS",
|
||||
"NICE SHOT", "CHEERS", "JEERS" });
|
||||
static CatVar voicecommand_spam(voicecommand_enum, "spam_voicecommand", "0",
|
||||
"Voice Command Spam",
|
||||
"Spams tf voice commands");
|
||||
|
||||
static CatVar teamname_spam(CV_SWITCH, "spam_teamname", "0", "Teamname Spam",
|
||||
"Spam changes the tournament name");
|
||||
static CatCommand reload("spam_reload", "Reload spam file", Reload);
|
||||
|
||||
static int last_index;
|
||||
|
||||
@ -226,10 +213,9 @@ int QueryPlayer(Query query)
|
||||
|
||||
void Init()
|
||||
{
|
||||
filename.InstallChangeCallback(
|
||||
[](IConVar *var, const char *pszOV, float flOV) {
|
||||
file.TryLoad(std::string(filename.GetString()));
|
||||
});
|
||||
filename.installChangeCallback([](settings::VariableBase<std::string>& var, std::string after) {
|
||||
file.TryLoad(after);
|
||||
});
|
||||
}
|
||||
|
||||
bool SubstituteQueries(std::string &input)
|
||||
@ -268,8 +254,6 @@ bool FormatSpamMessage(std::string &message)
|
||||
|
||||
void CreateMove()
|
||||
{
|
||||
if (!DelayTimer.check((int) delay * 1000))
|
||||
return;
|
||||
IF_GAME(IsTF2())
|
||||
{
|
||||
// Spam changes the tournament name in casual and compeditive gamemodes
|
||||
@ -439,4 +423,9 @@ const std::vector<std::string> builtin_lithium = {
|
||||
"SAVE YOUR MONEY AND GET LITHIUMCHEAT! IT IS FREE!",
|
||||
"GOT ROLLED BY LITHIUM? HEY, THAT MEANS IT'S TIME TO GET LITHIUMCHEAT!!"
|
||||
};
|
||||
|
||||
bool isActive()
|
||||
{
|
||||
return bool(spam_source);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user