2015-01-16 21:27:24 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
#ifndef CVARS_H
|
|
|
|
#define CVARS_H
|
|
|
|
|
2015-01-21 19:42:41 +00:00
|
|
|
#include "amxmodx.h"
|
2015-09-30 17:08:39 +00:00
|
|
|
#include <amtl/am-vector.h>
|
|
|
|
#include <amtl/am-inlinelist.h>
|
2015-01-19 18:17:41 +00:00
|
|
|
#include <sm_namehashset.h>
|
2016-01-21 22:50:07 +00:00
|
|
|
#include "CGameConfigs.h"
|
2015-01-16 23:32:08 +00:00
|
|
|
|
2015-01-16 21:27:24 +00:00
|
|
|
class CDetour;
|
|
|
|
|
2015-01-23 15:45:28 +00:00
|
|
|
enum CvarBounds
|
|
|
|
{
|
|
|
|
CvarBound_Upper = 0,
|
|
|
|
CvarBound_Lower
|
|
|
|
};
|
|
|
|
|
2015-01-27 00:49:57 +00:00
|
|
|
struct AutoForward
|
2015-01-21 19:42:41 +00:00
|
|
|
{
|
|
|
|
enum fwdstate
|
|
|
|
{
|
|
|
|
FSTATE_INVALID = 0,
|
|
|
|
FSTATE_OK,
|
|
|
|
FSTATE_STOP,
|
|
|
|
};
|
|
|
|
|
2015-01-27 00:49:57 +00:00
|
|
|
AutoForward(int id_, const char* handler) : id(id_), state(FSTATE_OK), callback(handler) {};
|
|
|
|
AutoForward() : id(-1) , state(FSTATE_INVALID) {};
|
2015-01-21 19:42:41 +00:00
|
|
|
|
2015-01-27 00:49:57 +00:00
|
|
|
~AutoForward()
|
2015-01-21 19:42:41 +00:00
|
|
|
{
|
|
|
|
unregisterSPForward(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int id;
|
|
|
|
fwdstate state;
|
|
|
|
ke::AString callback;
|
|
|
|
};
|
|
|
|
|
2015-01-24 20:28:43 +00:00
|
|
|
struct CvarHook
|
2015-01-21 19:42:41 +00:00
|
|
|
{
|
2015-01-27 00:49:57 +00:00
|
|
|
CvarHook(int id, AutoForward* fwd) : pluginId(id), forward(fwd) {};
|
|
|
|
CvarHook(int id) : pluginId(id), forward(new AutoForward()) {};
|
2015-01-21 19:42:41 +00:00
|
|
|
|
|
|
|
int pluginId;
|
2015-01-27 00:49:57 +00:00
|
|
|
ke::AutoPtr<AutoForward> forward;
|
2015-01-21 19:42:41 +00:00
|
|
|
};
|
|
|
|
|
2015-01-24 20:28:43 +00:00
|
|
|
struct CvarBind
|
|
|
|
{
|
|
|
|
enum CvarType
|
|
|
|
{
|
|
|
|
CvarType_Int,
|
|
|
|
CvarType_Float,
|
|
|
|
CvarType_String,
|
|
|
|
};
|
|
|
|
|
|
|
|
CvarBind(int id_, CvarType type_, cell* varAddress_, size_t varLength_)
|
|
|
|
:
|
2015-01-27 00:49:57 +00:00
|
|
|
pluginId(id_),
|
|
|
|
type(type_),
|
|
|
|
varAddress(varAddress_),
|
|
|
|
varLength(varLength_) {};
|
2015-01-24 20:28:43 +00:00
|
|
|
|
|
|
|
int pluginId;
|
|
|
|
CvarType type;
|
|
|
|
cell* varAddress;
|
|
|
|
size_t varLength;
|
|
|
|
};
|
|
|
|
|
2015-01-27 00:49:57 +00:00
|
|
|
struct CvarBound
|
|
|
|
{
|
|
|
|
CvarBound()
|
|
|
|
:
|
2015-01-27 15:27:26 +00:00
|
|
|
hasMin(false), minVal(0),
|
2015-02-19 14:21:00 +00:00
|
|
|
hasMax(false), maxVal(0),
|
|
|
|
minPluginId(-1),
|
|
|
|
maxPluginId(-1) {};
|
2015-01-27 00:49:57 +00:00
|
|
|
|
|
|
|
bool hasMin;
|
|
|
|
float minVal;
|
2015-01-27 15:27:26 +00:00
|
|
|
bool hasMax;
|
2015-01-27 00:49:57 +00:00
|
|
|
float maxVal;
|
|
|
|
int minPluginId;
|
|
|
|
int maxPluginId;
|
|
|
|
};
|
|
|
|
|
2015-01-24 20:28:43 +00:00
|
|
|
typedef ke::Vector<CvarHook*> CvarsHook;
|
2015-01-27 00:49:57 +00:00
|
|
|
typedef ke::Vector<CvarBind*> CvarsBind;
|
2015-01-21 19:42:41 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
struct CvarInfo : public ke::InlineListNode<CvarInfo>
|
2015-01-16 23:32:08 +00:00
|
|
|
{
|
2015-02-19 14:21:00 +00:00
|
|
|
CvarInfo(const char* name_, const char* helpText, const char* plugin_, int pluginId_)
|
2015-01-22 23:58:57 +00:00
|
|
|
:
|
2015-01-24 20:28:43 +00:00
|
|
|
name(name_), description(helpText),
|
2015-02-19 14:21:00 +00:00
|
|
|
plugin(plugin_), pluginId(pluginId_), bound() {};
|
2015-01-22 23:58:57 +00:00
|
|
|
|
|
|
|
CvarInfo(const char* name_)
|
|
|
|
:
|
2015-01-24 20:28:43 +00:00
|
|
|
name(name_), defaultval(""), description(""),
|
2015-01-27 15:27:26 +00:00
|
|
|
plugin(""), pluginId(-1), bound(), amxmodx(false) {};
|
2015-01-22 23:58:57 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
cvar_t* var;
|
|
|
|
ke::AString name;
|
|
|
|
ke::AString defaultval;
|
2015-01-22 23:58:57 +00:00
|
|
|
ke::AString description;
|
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
ke::AString plugin;
|
|
|
|
int pluginId;
|
2015-01-22 23:58:57 +00:00
|
|
|
|
2015-01-27 00:49:57 +00:00
|
|
|
CvarBound bound;
|
2015-01-24 20:28:43 +00:00
|
|
|
CvarsBind binds;
|
2015-01-21 19:42:41 +00:00
|
|
|
CvarsHook hooks;
|
2015-01-27 00:49:57 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
bool amxmodx;
|
|
|
|
|
|
|
|
static inline bool matches(const char *name, const CvarInfo* info)
|
2015-01-16 23:32:08 +00:00
|
|
|
{
|
2015-01-19 18:17:41 +00:00
|
|
|
return strcmp(name, info->var->name) == 0;
|
2015-01-16 23:32:08 +00:00
|
|
|
}
|
2015-01-19 18:17:41 +00:00
|
|
|
};
|
2015-01-16 23:32:08 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
typedef NameHashSet<CvarInfo*> CvarsCache;
|
|
|
|
typedef ke::InlineList<CvarInfo> CvarsList;
|
2015-01-16 23:40:25 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
class CvarManager
|
|
|
|
{
|
|
|
|
public:
|
2015-01-16 23:40:25 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
CvarManager();
|
|
|
|
~CvarManager();
|
2015-01-16 23:40:25 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
public:
|
2015-01-16 23:40:25 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
void CreateCvarHook();
|
2017-03-09 18:59:38 +00:00
|
|
|
void EnableHook();
|
|
|
|
void DisableHook();
|
|
|
|
void DestroyHook();
|
2015-01-21 19:42:41 +00:00
|
|
|
|
2015-02-19 14:21:00 +00:00
|
|
|
CvarInfo* CreateCvar(const char* name, const char* value, const char* plugin, int pluginId, int flags = 0, const char* helpText = "");
|
2015-01-23 15:45:28 +00:00
|
|
|
CvarInfo* FindCvar(const char* name);
|
2015-01-19 18:17:41 +00:00
|
|
|
CvarInfo* FindCvar(size_t index);
|
2015-01-21 19:42:41 +00:00
|
|
|
bool CacheLookup(const char* name, CvarInfo** info);
|
|
|
|
|
2015-01-27 00:49:57 +00:00
|
|
|
AutoForward* HookCvarChange(cvar_t* var, AMX* amx, cell param, const char** callback);
|
2015-01-28 22:51:43 +00:00
|
|
|
bool BindCvar(CvarInfo* info, CvarBind::CvarType type, AMX* amx, cell varofs, size_t varlen = 0);
|
2015-02-19 14:21:00 +00:00
|
|
|
void SetCvarMin(CvarInfo* info, bool set, float value, int pluginId);
|
|
|
|
void SetCvarMax(CvarInfo* info, bool set, float value, int pluginId);
|
2015-01-21 19:42:41 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
size_t GetRegCvarsCount();
|
2015-07-19 19:11:34 +00:00
|
|
|
CvarsList* GetCvarsList();
|
2015-01-21 19:42:41 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
void OnConsoleCommand();
|
2015-01-21 19:42:41 +00:00
|
|
|
void OnPluginUnloaded();
|
|
|
|
void OnAmxxShutdown();
|
2015-01-19 18:17:41 +00:00
|
|
|
|
|
|
|
private:
|
2015-01-16 23:32:08 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
CvarsCache m_Cache;
|
|
|
|
CvarsList m_Cvars;
|
|
|
|
size_t m_AmxmodxCvars;
|
|
|
|
CDetour* m_HookDetour;
|
2017-03-09 18:59:38 +00:00
|
|
|
bool m_ReHookEnabled;
|
2015-01-19 18:17:41 +00:00
|
|
|
};
|
2015-01-16 21:27:24 +00:00
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
extern CvarManager g_CvarManager;
|
2015-01-16 21:27:24 +00:00
|
|
|
|
|
|
|
#endif // CVARS_H
|