|
ds@457
|
1 |
/** |
|
ds@457
|
2 |
* =============================================================== |
|
ds@457
|
3 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
ds@457
|
4 |
* =============================================================== |
|
ds@457
|
5 |
* |
|
ds@457
|
6 |
* This file is not open source and may not be copied without explicit |
|
ds@457
|
7 |
* written permission of AlliedModders LLC. This file may not be redistributed |
|
ds@457
|
8 |
* in whole or significant part. |
|
ds@457
|
9 |
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php |
|
ds@457
|
10 |
* |
|
ds@457
|
11 |
* Version: $Id$ |
|
ds@457
|
12 |
*/ |
|
ds@457
|
13 |
|
|
ds@457
|
14 |
#ifndef _INCLUDE_SOURCEMOD_CCONVARMANAGER_H_ |
|
ds@457
|
15 |
#define _INCLUDE_SOURCEMOD_CCONVARMANAGER_H_ |
|
ds@457
|
16 |
|
|
ds@457
|
17 |
#include "sm_globals.h" |
|
ds@457
|
18 |
#include "sourcemm_api.h" |
|
ds@457
|
19 |
#include "HandleSys.h" |
|
ds@465
|
20 |
#include "ForwardSys.h" |
|
ds@457
|
21 |
#include "sm_trie.h" |
|
ds@465
|
22 |
#include <sh_list.h> |
|
ds@457
|
23 |
#include <IRootConsoleMenu.h> |
|
ds@457
|
24 |
|
|
ds@465
|
25 |
using namespace SourceHook; |
|
ds@465
|
26 |
|
|
ds@465
|
27 |
/** |
|
ds@465
|
28 |
* Holds SourceMod-specific information about a convar |
|
ds@465
|
29 |
*/ |
|
ds@465
|
30 |
struct ConVarInfo |
|
ds@465
|
31 |
{ |
|
ds@465
|
32 |
Handle_t handle; /**< Handle to convar */ |
|
ds@465
|
33 |
bool sourceMod; /**< Determines whether or not convar was created by a SourceMod plugin */ |
|
ds@465
|
34 |
IChangeableForward *changeForward; /**< Forward associated with convar */ |
|
ds@465
|
35 |
FnChangeCallback origCallback; /**< The original callback function */ |
|
ds@465
|
36 |
}; |
|
ds@465
|
37 |
|
|
ds@457
|
38 |
class CConVarManager : |
|
ds@457
|
39 |
public SMGlobalClass, |
|
ds@457
|
40 |
public IHandleTypeDispatch, |
|
ds@457
|
41 |
public IRootConsoleCommand |
|
ds@457
|
42 |
{ |
|
ds@457
|
43 |
public: |
|
ds@457
|
44 |
CConVarManager(); |
|
ds@457
|
45 |
~CConVarManager(); |
|
ds@457
|
46 |
public: // SMGlobalClass |
|
ds@457
|
47 |
void OnSourceModAllInitialized(); |
|
ds@457
|
48 |
void OnSourceModShutdown(); |
|
ds@457
|
49 |
public: // IHandleTypeDispatch |
|
ds@457
|
50 |
void OnHandleDestroy(HandleType_t type, void *object); |
|
ds@457
|
51 |
public: //IRootConsoleCommand |
|
ds@457
|
52 |
void OnRootConsoleCommand(const char *command, unsigned int argcount); |
|
ds@457
|
53 |
public: |
|
ds@465
|
54 |
/** |
|
ds@465
|
55 |
* Get the 'ConVar' handle type ID. |
|
ds@465
|
56 |
*/ |
|
ds@457
|
57 |
inline HandleType_t GetHandleType() |
|
ds@457
|
58 |
{ |
|
ds@457
|
59 |
return m_ConVarType; |
|
ds@457
|
60 |
} |
|
ds@465
|
61 |
|
|
ds@465
|
62 |
/** |
|
ds@465
|
63 |
* Get the convar lookup trie. |
|
ds@465
|
64 |
*/ |
|
ds@465
|
65 |
inline Trie *GetConVarCache() |
|
ds@465
|
66 |
{ |
|
ds@465
|
67 |
return m_ConVarCache; |
|
ds@465
|
68 |
} |
|
ds@457
|
69 |
public: |
|
ds@465
|
70 |
/** |
|
ds@465
|
71 |
* Create a convar and return a handle to it. |
|
ds@465
|
72 |
*/ |
|
ds@457
|
73 |
Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, const char *helpText, |
|
ds@457
|
74 |
int flags, bool hasMin, float min, bool hasMax, float max); |
|
ds@465
|
75 |
|
|
ds@465
|
76 |
/** |
|
ds@465
|
77 |
* Searches for a convar and returns a handle to it |
|
ds@465
|
78 |
*/ |
|
ds@457
|
79 |
Handle_t FindConVar(const char* name); |
|
ds@465
|
80 |
|
|
ds@465
|
81 |
/** |
|
ds@465
|
82 |
* Add a function to call when the specified convar changes. |
|
ds@465
|
83 |
*/ |
|
ds@465
|
84 |
void HookConVarChange(IPluginContext *pContext, ConVar *cvar, funcid_t funcid); |
|
ds@465
|
85 |
|
|
ds@465
|
86 |
/** |
|
ds@465
|
87 |
* Remove a function from the forward that will be called when the specified convar changes. |
|
ds@465
|
88 |
*/ |
|
ds@465
|
89 |
void UnhookConVarChange(IPluginContext *pContext, ConVar *cvar, funcid_t funcid); |
|
ds@465
|
90 |
private: |
|
ds@465
|
91 |
/** |
|
ds@465
|
92 |
* Static callback that Valve's ConVar class executes when the convar's value changes. |
|
ds@465
|
93 |
*/ |
|
ds@465
|
94 |
static void OnConVarChanged(ConVar *cvar, const char *oldValue); |
|
ds@457
|
95 |
private: |
|
ds@457
|
96 |
HandleType_t m_ConVarType; |
|
ds@465
|
97 |
List<ConVarInfo *> m_ConVars; |
|
ds@465
|
98 |
Trie *m_ConVarCache; |
|
ds@457
|
99 |
}; |
|
ds@457
|
100 |
|
|
ds@457
|
101 |
extern CConVarManager g_ConVarManager; |
|
ds@457
|
102 |
|
|
dvander@464
|
103 |
#endif // _INCLUDE_SOURCEMOD_CCONVARMANAGER_H_ |
|
dvander@464
|
104 |
|