3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #ifndef _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
16 #define _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
18 #include "sm_globals.h"
19 #include "sourcemm_api.h"
22 #include <IPluginSys.h>
23 #include <IForwardSys.h>
24 #include <IHandleSys.h>
25 #include <IRootConsoleMenu.h>
27 using namespace SourceHook;
30 * Holds SourceMod-specific information about a convar
34 Handle_t handle; /**< Handle to convar */
35 bool sourceMod; /**< Determines whether or not convar was created by a SourceMod plugin */
36 IChangeableForward *changeForward; /**< Forward associated with convar */
37 FnChangeCallback origCallback; /**< The original callback function */
42 public IHandleTypeDispatch,
43 public IPluginsListener,
44 public IRootConsoleCommand
49 public: // SMGlobalClass
50 void OnSourceModAllInitialized();
51 void OnSourceModShutdown();
52 public: // IHandleTypeDispatch
53 void OnHandleDestroy(HandleType_t type, void *object);
54 public: // IPluginsListener
55 void OnPluginUnloaded(IPlugin *plugin);
56 public: //IRootConsoleCommand
57 void OnRootConsoleCommand(const char *command, unsigned int argcount);
60 * Get the 'ConVar' handle type ID.
62 inline HandleType_t GetHandleType()
68 * Get the convar lookup trie.
70 inline Trie *GetConVarCache()
76 * Create a convar and return a handle to it.
78 Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal,
79 const char *description, int flags, bool hasMin, float min, bool hasMax, float max);
82 * Searches for a convar and returns a handle to it
84 Handle_t FindConVar(const char* name);
87 * Add a function to call when the specified convar changes.
89 void HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
92 * Remove a function from the forward that will be called when the specified convar changes.
94 void UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
97 * Adds a convar to a plugin's list.
99 static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar);
102 * Static callback that Valve's ConVar class executes when the convar's value changes.
104 static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
106 HandleType_t m_ConVarType;
107 List<ConVarInfo *> m_ConVars;
111 extern ConVarManager g_ConVarManager;
113 #endif // _INCLUDE_SOURCEMOD_CONVARMANAGER_H_