ds@457: /** ds@457: * =============================================================== ds@457: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. ds@457: * =============================================================== ds@457: * ds@457: * This file is not open source and may not be copied without explicit ds@457: * written permission of AlliedModders LLC. This file may not be redistributed ds@457: * in whole or significant part. ds@457: * For information, see LICENSE.txt or http://www.sourcemod.net/license.php ds@457: * ds@457: * Version: $Id$ ds@457: */ ds@457: ds@457: #ifndef _INCLUDE_SOURCEMOD_CCONVARMANAGER_H_ ds@457: #define _INCLUDE_SOURCEMOD_CCONVARMANAGER_H_ ds@457: ds@457: #include "sm_globals.h" ds@457: #include "sourcemm_api.h" ds@457: #include "sm_trie.h" ds@465: #include ds@487: #include ds@487: #include ds@487: #include ds@457: #include ds@457: ds@465: using namespace SourceHook; ds@465: ds@465: /** ds@465: * Holds SourceMod-specific information about a convar ds@465: */ ds@465: struct ConVarInfo ds@465: { ds@465: Handle_t handle; /**< Handle to convar */ ds@465: bool sourceMod; /**< Determines whether or not convar was created by a SourceMod plugin */ ds@465: IChangeableForward *changeForward; /**< Forward associated with convar */ ds@465: FnChangeCallback origCallback; /**< The original callback function */ ds@465: }; ds@465: ds@457: class CConVarManager : ds@457: public SMGlobalClass, ds@457: public IHandleTypeDispatch, ds@487: public IPluginsListener, ds@457: public IRootConsoleCommand ds@457: { ds@457: public: ds@457: CConVarManager(); ds@457: ~CConVarManager(); ds@457: public: // SMGlobalClass ds@457: void OnSourceModAllInitialized(); ds@457: void OnSourceModShutdown(); ds@457: public: // IHandleTypeDispatch ds@457: void OnHandleDestroy(HandleType_t type, void *object); ds@487: public: // IPluginsListener ds@487: void OnPluginDestroyed(IPlugin *plugin); ds@457: public: //IRootConsoleCommand ds@457: void OnRootConsoleCommand(const char *command, unsigned int argcount); ds@457: public: ds@465: /** ds@465: * Get the 'ConVar' handle type ID. ds@465: */ ds@457: inline HandleType_t GetHandleType() ds@457: { ds@457: return m_ConVarType; ds@457: } ds@465: ds@465: /** ds@465: * Get the convar lookup trie. ds@465: */ ds@465: inline Trie *GetConVarCache() ds@465: { ds@465: return m_ConVarCache; ds@465: } ds@457: public: ds@465: /** ds@465: * Create a convar and return a handle to it. ds@465: */ ds@457: Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, const char *helpText, ds@457: int flags, bool hasMin, float min, bool hasMax, float max); ds@465: ds@465: /** ds@465: * Searches for a convar and returns a handle to it ds@465: */ ds@457: Handle_t FindConVar(const char* name); ds@465: ds@465: /** ds@465: * Add a function to call when the specified convar changes. ds@465: */ ds@465: void HookConVarChange(IPluginContext *pContext, ConVar *cvar, funcid_t funcid); ds@465: ds@465: /** ds@465: * Remove a function from the forward that will be called when the specified convar changes. ds@465: */ ds@465: void UnhookConVarChange(IPluginContext *pContext, ConVar *cvar, funcid_t funcid); ds@465: private: ds@465: /** ds@465: * Static callback that Valve's ConVar class executes when the convar's value changes. ds@465: */ ds@465: static void OnConVarChanged(ConVar *cvar, const char *oldValue); ds@457: private: ds@457: HandleType_t m_ConVarType; ds@465: List m_ConVars; ds@465: Trie *m_ConVarCache; ds@457: }; ds@457: ds@457: extern CConVarManager g_ConVarManager; ds@457: dvander@464: #endif // _INCLUDE_SOURCEMOD_CCONVARMANAGER_H_ dvander@464: