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"
|
|
|
|
#include <am-vector.h>
|
2015-01-19 18:17:41 +00:00
|
|
|
#include <am-inlinelist.h>
|
|
|
|
#include <sm_namehashset.h>
|
2015-01-16 23:32:08 +00:00
|
|
|
|
2015-01-16 21:27:24 +00:00
|
|
|
class CDetour;
|
|
|
|
|
2015-01-21 19:42:41 +00:00
|
|
|
struct Forward
|
|
|
|
{
|
|
|
|
enum fwdstate
|
|
|
|
{
|
|
|
|
FSTATE_INVALID = 0,
|
|
|
|
FSTATE_OK,
|
|
|
|
FSTATE_STOP,
|
|
|
|
};
|
|
|
|
|
|
|
|
Forward(int id_, const char* handler) : id(id_), state(FSTATE_OK), callback(handler) {};
|
|
|
|
Forward() : id(-1) , state(FSTATE_INVALID) {};
|
|
|
|
|
|
|
|
~Forward()
|
|
|
|
{
|
|
|
|
unregisterSPForward(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int id;
|
|
|
|
fwdstate state;
|
|
|
|
ke::AString callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CvarPlugin
|
|
|
|
{
|
|
|
|
CvarPlugin(int id, Forward* fwd) : pluginId(id), forward(fwd) {};
|
|
|
|
CvarPlugin(int id) : pluginId(id), forward(new Forward()) {};
|
|
|
|
|
|
|
|
int pluginId;
|
|
|
|
ke::AutoPtr<Forward> forward;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef ke::Vector<CvarPlugin*> CvarsHook;
|
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
struct CvarInfo : public ke::InlineListNode<CvarInfo>
|
2015-01-16 23:32:08 +00:00
|
|
|
{
|
2015-01-22 23:58:57 +00:00
|
|
|
CvarInfo(const char* name_, const char* helpText, bool hasMin_, float min_, bool hasMax_, float max_,
|
|
|
|
const char* plugin_, int pluginId_)
|
|
|
|
:
|
|
|
|
name(name_), description(helpText), hasMin(hasMin_), minVal(min_), hasMax(hasMax_), maxVal(max_),
|
|
|
|
plugin(plugin_), pluginId(pluginId_) {};
|
|
|
|
|
|
|
|
CvarInfo(const char* name_)
|
|
|
|
:
|
|
|
|
name(name_), defaultval(""), description(""), hasMin(false), minVal(0), hasMax(false), maxVal(0),
|
|
|
|
plugin(""), pluginId(-1), amxmodx(false) {};
|
|
|
|
|
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;
|
|
|
|
bool hasMin;
|
|
|
|
bool hasMax;
|
|
|
|
float minVal;
|
|
|
|
float maxVal;
|
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
ke::AString plugin;
|
|
|
|
int pluginId;
|
2015-01-22 23:58:57 +00:00
|
|
|
|
2015-01-21 19:42:41 +00:00
|
|
|
CvarsHook hooks;
|
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();
|
2015-01-21 19:42:41 +00:00
|
|
|
|
2015-01-22 23:58:57 +00:00
|
|
|
cvar_t* CreateCvar(const char* name, const char* value, const char* plugin, int pluginId,
|
|
|
|
int flags = 0, const char* helpText = "",
|
|
|
|
bool hasMin = false, float min = 0,
|
|
|
|
bool hasMax = false, float max = 0);
|
2015-01-19 18:17:41 +00:00
|
|
|
cvar_t* FindCvar(const char* name);
|
|
|
|
CvarInfo* FindCvar(size_t index);
|
2015-01-21 19:42:41 +00:00
|
|
|
bool CacheLookup(const char* name, CvarInfo** info);
|
|
|
|
|
|
|
|
Forward* HookCvarChange(cvar_t* var, AMX* amx, cell param, const char** callback);
|
|
|
|
|
2015-01-19 18:17:41 +00:00
|
|
|
size_t GetRegCvarsCount();
|
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;
|
|
|
|
};
|
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
|