core/ConVarManager.h
branchrefac-jit
changeset 2284 026da5437111
parent 2192 7602d7fb60d9
child 2288 15c77b21589a
     1.1 --- a/core/ConVarManager.h	Fri Jul 11 06:51:21 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,165 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod
     1.8 - * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     1.9 - * =============================================================================
    1.10 - *
    1.11 - * This program is free software; you can redistribute it and/or modify it under
    1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 - * Free Software Foundation.
    1.14 - * 
    1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 - * details.
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License along with
    1.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 - *
    1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 - * or <http://www.sourcemod.net/license.php>.
    1.31 - *
    1.32 - * Version: $Id$
    1.33 - */
    1.34 -
    1.35 -#ifndef _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
    1.36 -#define _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
    1.37 -
    1.38 -#include "sm_globals.h"
    1.39 -#include "sourcemm_api.h"
    1.40 -#include <sh_list.h>
    1.41 -#include <IPluginSys.h>
    1.42 -#include <IForwardSys.h>
    1.43 -#include <IHandleSys.h>
    1.44 -#include <IRootConsoleMenu.h>
    1.45 -#include <compat_wrappers.h>
    1.46 -#include "concmd_cleaner.h"
    1.47 -
    1.48 -using namespace SourceHook;
    1.49 -
    1.50 -class IConVarChangeListener
    1.51 -{
    1.52 -public:
    1.53 -	virtual void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue) =0;
    1.54 -};
    1.55 -
    1.56 -/**
    1.57 - * Holds SourceMod-specific information about a convar
    1.58 - */
    1.59 -struct ConVarInfo
    1.60 -{
    1.61 -	Handle_t handle;					/**< Handle to self */
    1.62 -	bool sourceMod;						/**< Determines whether or not convar was created by a SourceMod plugin */
    1.63 -	IChangeableForward *pChangeForward;	/**< Forward associated with convar */
    1.64 -	ConVar *pVar;						/**< The actual convar */
    1.65 -	List<IConVarChangeListener *> changeListeners;
    1.66 -};
    1.67 -
    1.68 -/**
    1.69 - * Holds information about a client convar query
    1.70 - */
    1.71 -struct ConVarQuery
    1.72 -{
    1.73 -	QueryCvarCookie_t cookie;			/**< Cookie that identifies query */
    1.74 -	IPluginFunction *pCallback;			/**< Function that will be called when query is finished */
    1.75 -	cell_t value;						/**< Optional value passed to query function */
    1.76 -};
    1.77 -
    1.78 -class ConVarManager :
    1.79 -	public SMGlobalClass,
    1.80 -	public IHandleTypeDispatch,
    1.81 -	public IPluginsListener,
    1.82 -	public IRootConsoleCommand,
    1.83 -	public IConCommandTracker
    1.84 -{
    1.85 -public:
    1.86 -	ConVarManager();
    1.87 -	~ConVarManager();
    1.88 -public: // SMGlobalClass
    1.89 -	void OnSourceModStartup(bool late);
    1.90 -	void OnSourceModAllInitialized();
    1.91 -	void OnSourceModShutdown();
    1.92 -	void OnSourceModVSPReceived();
    1.93 -public: // IHandleTypeDispatch
    1.94 -	void OnHandleDestroy(HandleType_t type, void *object);
    1.95 -	bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
    1.96 -public: // IPluginsListener
    1.97 -	void OnPluginUnloaded(IPlugin *plugin);
    1.98 -public: //IRootConsoleCommand
    1.99 -	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
   1.100 -public: //IConCommandTracker
   1.101 -	void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
   1.102 -public:
   1.103 -	/**
   1.104 -	 * Create a convar and return a handle to it.
   1.105 -	 */
   1.106 -	Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal,
   1.107 -	                      const char *description, int flags, bool hasMin, float min, bool hasMax, float max);
   1.108 -
   1.109 -	/**
   1.110 -	 * Searches for a convar and returns a handle to it
   1.111 -	 */
   1.112 -	Handle_t FindConVar(const char* name);
   1.113 -
   1.114 -	/**
   1.115 -	 * Add a function to call when the specified convar changes.
   1.116 -	 */
   1.117 -	void HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
   1.118 -
   1.119 -	/**
   1.120 -	 * Remove a function from the forward that will be called when the specified convar changes.
   1.121 -	 */
   1.122 -	void UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
   1.123 -
   1.124 -	void AddConVarChangeListener(const char *name, IConVarChangeListener *pListener);
   1.125 -	void RemoveConVarChangeListener(const char *name, IConVarChangeListener *pListener);
   1.126 -
   1.127 -	/**
   1.128 -	 * Starts a query to find the value of a client convar.
   1.129 -	 */
   1.130 -	QueryCvarCookie_t QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback,
   1.131 -	                                    Handle_t hndl);
   1.132 -
   1.133 -	bool IsQueryingSupported();
   1.134 -
   1.135 -	HandleError ReadConVarHandle(Handle_t hndl, ConVar **pVar);
   1.136 -
   1.137 -private:
   1.138 -	/**
   1.139 -	 * Adds a convar to a plugin's list.
   1.140 -	 */
   1.141 -	static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar);
   1.142 -
   1.143 -	/**
   1.144 -	 * Static callback that Valve's ConVar object executes when the convar's value changes.
   1.145 -	 */
   1.146 -#if defined ORANGEBOX_BUILD
   1.147 -	static void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue);
   1.148 -#else
   1.149 -	static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
   1.150 -#endif
   1.151 -
   1.152 -	/**
   1.153 -	 * Callback for when StartQueryCvarValue() has finished.
   1.154 -	 */
   1.155 -	void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
   1.156 -	                              const char *cvarName, const char *cvarValue);
   1.157 -private:
   1.158 -	HandleType_t m_ConVarType;
   1.159 -	List<ConVarInfo *> m_ConVars;
   1.160 -	List<ConVarQuery> m_ConVarQueries;
   1.161 -	bool m_bIsDLLQueryHooked;
   1.162 -	bool m_bIsVSPQueryHooked;
   1.163 -};
   1.164 -
   1.165 -extern ConVarManager g_ConVarManager;
   1.166 -
   1.167 -#endif // _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
   1.168 -