3 * ================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
33 #ifndef _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
34 #define _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
36 #include "sm_globals.h"
37 #include "sourcemm_api.h"
40 #include <IPluginSys.h>
41 #include <IForwardSys.h>
42 #include <IHandleSys.h>
43 #include <IRootConsoleMenu.h>
45 using namespace SourceHook;
48 * Holds SourceMod-specific information about a convar
52 Handle_t handle; /**< Handle to convar */
53 bool sourceMod; /**< Determines whether or not convar was created by a SourceMod plugin */
54 IChangeableForward *pChangeForward; /**< Forward associated with convar */
55 FnChangeCallback origCallback; /**< The original callback function */
56 #if PLAPI_VERSION < 12
57 const char *name; /**< Name of convar */
62 * Holds information about a client convar query
66 QueryCvarCookie_t cookie; /**< Cookie that identifies query */
67 IPluginFunction *pCallback; /**< Function that will be called when query is finished */
68 cell_t value; /**< Optional value passed to query function */
73 public IHandleTypeDispatch,
74 public IPluginsListener,
75 public IRootConsoleCommand
80 public: // SMGlobalClass
81 void OnSourceModAllInitialized();
82 void OnSourceModShutdown();
83 void OnSourceModVSPReceived(IServerPluginCallbacks *iface);
84 public: // IHandleTypeDispatch
85 void OnHandleDestroy(HandleType_t type, void *object);
86 public: // IPluginsListener
87 void OnPluginUnloaded(IPlugin *plugin);
88 public: //IRootConsoleCommand
89 void OnRootConsoleCommand(const char *command, unsigned int argcount);
92 * Get the 'ConVar' handle type ID.
94 inline HandleType_t GetHandleType()
100 * Get the convar lookup trie.
102 inline Trie *GetConVarCache()
104 return m_ConVarCache;
108 * Create a convar and return a handle to it.
110 Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal,
111 const char *description, int flags, bool hasMin, float min, bool hasMax, float max);
114 * Searches for a convar and returns a handle to it
116 Handle_t FindConVar(const char* name);
119 * Add a function to call when the specified convar changes.
121 void HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
124 * Remove a function from the forward that will be called when the specified convar changes.
126 void UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
129 * Starts a query to find the value of a client convar.
131 QueryCvarCookie_t QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback,
134 #if PLAPI_VERSION >= 12
136 * Called when Metamod:Source is about to remove convar
138 void OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand);
141 * Called when Metamod:Source has unloaded a plugin
143 void OnMetamodPluginUnloaded(PluginId id);
147 * Adds a convar to a plugin's list.
149 static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar);
152 * Static callback that Valve's ConVar object executes when the convar's value changes.
154 static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
157 * Callback for when StartQueryCvarValue() has finished.
159 void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
160 const char *cvarName, const char *cvarValue);
162 HandleType_t m_ConVarType;
163 List<ConVarInfo *> m_ConVars;
164 List<ConVarQuery> m_ConVarQueries;
166 IServerPluginCallbacks *m_VSPIface;
167 bool m_CanQueryConVars;
168 #if PLAPI_VERSION < 12
173 extern ConVarManager g_ConVarManager;
175 #endif // _INCLUDE_SOURCEMOD_CONVARMANAGER_H_