ds@580: /**
ds@653: * vim: set ts=4 :
ds@1330: * =============================================================================
dvander@1231: * SourceMod
ds@1947: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
ds@1330: * =============================================================================
ds@653: *
ds@1330: * This program is free software; you can redistribute it and/or modify it under
ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330: * Free Software Foundation.
dvander@1231: *
ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1330: * details.
dvander@1231: *
ds@1330: * You should have received a copy of the GNU General Public License along with
ds@1330: * this program. If not, see .
dvander@1231: *
ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1330: * this exception to all derivative works. AlliedModders LLC defines further
ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330: * or .
ds@653: *
ds@653: * Version: $Id$
ds@653: */
ds@580:
ds@580: #ifndef _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
ds@580: #define _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
ds@580:
ds@580: #include "sm_globals.h"
ds@580: #include "sourcemm_api.h"
ds@580: #include
ds@580: #include
ds@580: #include
ds@580: #include
ds@580: #include
dvander@1547: #include
dvander@1582: #include "concmd_cleaner.h"
ds@580:
ds@2583: #if SOURCE_ENGINE == SE_DARKMESSIAH
ds@2583: class EQueryCvarValueStatus;
ds@2583: typedef int QueryCvarCookie_t;
ds@2583: #endif
ds@2583:
ds@580: using namespace SourceHook;
ds@580:
dvander@1770: class IConVarChangeListener
dvander@1770: {
dvander@1770: public:
dvander@1770: virtual void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue) =0;
dvander@1770: };
dvander@1770:
ds@580: /**
ds@580: * Holds SourceMod-specific information about a convar
ds@580: */
ds@580: struct ConVarInfo
ds@580: {
dvander@1582: Handle_t handle; /**< Handle to self */
ds@580: bool sourceMod; /**< Determines whether or not convar was created by a SourceMod plugin */
ds@696: IChangeableForward *pChangeForward; /**< Forward associated with convar */
dvander@1582: ConVar *pVar; /**< The actual convar */
dvander@1770: List changeListeners;
ds@580: };
ds@580:
ds@696: /**
ds@696: * Holds information about a client convar query
ds@696: */
ds@696: struct ConVarQuery
ds@696: {
ds@696: QueryCvarCookie_t cookie; /**< Cookie that identifies query */
ds@696: IPluginFunction *pCallback; /**< Function that will be called when query is finished */
ds@696: cell_t value; /**< Optional value passed to query function */
ds@696: };
ds@696:
ds@580: class ConVarManager :
ds@580: public SMGlobalClass,
ds@580: public IHandleTypeDispatch,
ds@580: public IPluginsListener,
dvander@1582: public IRootConsoleCommand,
dvander@1582: public IConCommandTracker
ds@580: {
ds@580: public:
ds@580: ConVarManager();
ds@580: ~ConVarManager();
ds@580: public: // SMGlobalClass
dvander@1770: void OnSourceModStartup(bool late);
ds@580: void OnSourceModAllInitialized();
ds@580: void OnSourceModShutdown();
dvander@1581: void OnSourceModVSPReceived();
ds@580: public: // IHandleTypeDispatch
ds@580: void OnHandleDestroy(HandleType_t type, void *object);
dvander@1766: bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
ds@580: public: // IPluginsListener
ds@582: void OnPluginUnloaded(IPlugin *plugin);
ds@580: public: //IRootConsoleCommand
faluco@1541: void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
dvander@1582: public: //IConCommandTracker
dvander@1582: void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
ds@580: public:
ds@580: /**
ds@580: * Create a convar and return a handle to it.
ds@580: */
ds@582: Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal,
ds@582: const char *description, int flags, bool hasMin, float min, bool hasMax, float max);
ds@580:
ds@580: /**
ds@580: * Searches for a convar and returns a handle to it
ds@580: */
ds@580: Handle_t FindConVar(const char* name);
ds@580:
ds@580: /**
ds@580: * Add a function to call when the specified convar changes.
ds@580: */
ds@582: void HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
ds@580:
ds@580: /**
ds@580: * Remove a function from the forward that will be called when the specified convar changes.
ds@580: */
ds@582: void UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
ds@696:
dvander@1770: void AddConVarChangeListener(const char *name, IConVarChangeListener *pListener);
dvander@1770: void RemoveConVarChangeListener(const char *name, IConVarChangeListener *pListener);
dvander@1770:
ds@696: /**
ds@696: * Starts a query to find the value of a client convar.
ds@696: */
ds@696: QueryCvarCookie_t QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback,
ds@696: Handle_t hndl);
ds@1145:
dvander@1581: bool IsQueryingSupported();
dvander@1581:
dvander@1582: HandleError ReadConVarHandle(Handle_t hndl, ConVar **pVar);
dvander@1582:
ds@580: private:
ds@580: /**
ds@582: * Adds a convar to a plugin's list.
ds@582: */
ds@582: static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar);
ds@582:
ds@582: /**
ds@696: * Static callback that Valve's ConVar object executes when the convar's value changes.
ds@580: */
ds@2400: #if SOURCE_ENGINE >= SE_ORANGEBOX
dvander@1770: static void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue);
faluco@1541: #else
ds@580: static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
faluco@1541: #endif
ds@696:
ds@696: /**
ds@696: * Callback for when StartQueryCvarValue() has finished.
ds@696: */
skamonkey@3942: #if SOURCE_ENGINE == SE_DOTA
skamonkey@3942: void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, CEntityIndex player, EQueryCvarValueStatus result,
skamonkey@3942: const char *cvarName, const char *cvarValue);
skamonkey@3942: #elif SOURCE_ENGINE != SE_DARKMESSIAH
ds@696: void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
ds@696: const char *cvarName, const char *cvarValue);
ds@2583: #endif
ds@580: private:
ds@580: HandleType_t m_ConVarType;
ds@580: List m_ConVars;
ds@696: List m_ConVarQueries;
dvander@1581: bool m_bIsDLLQueryHooked;
dvander@1581: bool m_bIsVSPQueryHooked;
ds@580: };
ds@580:
ds@580: extern ConVarManager g_ConVarManager;
ds@580:
ds@580: #endif // _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
ds@580: