|
ds@580
|
1 |
/** |
|
ds@2825
|
2 |
* vim: set ts=4 sw=4 tw=99 noet : |
|
ds@1330
|
3 |
* ============================================================================= |
|
dvander@1231
|
4 |
* SourceMod |
|
ds@2825
|
5 |
* Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved. |
|
ds@1330
|
6 |
* ============================================================================= |
|
ds@653
|
7 |
* |
|
ds@1330
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1330
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1330
|
10 |
* Free Software Foundation. |
|
dvander@1231
|
11 |
* |
|
ds@1330
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1330
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1330
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1330
|
15 |
* details. |
|
dvander@1231
|
16 |
* |
|
ds@1330
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1330
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
dvander@1231
|
19 |
* |
|
ds@1330
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1330
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1330
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1330
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1330
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1330
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1330
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1330
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@653
|
28 |
*/ |
|
ds@580
|
29 |
|
|
ds@580
|
30 |
#include "ConVarManager.h" |
|
ds@696
|
31 |
#include "HalfLife2.h" |
|
ds@580
|
32 |
#include "ForwardSys.h" |
|
ds@580
|
33 |
#include "sm_srvcmds.h" |
|
ds@580
|
34 |
#include "sm_stringutil.h" |
|
ds@580
|
35 |
#include <sh_vector.h> |
|
dvander@1582
|
36 |
#include <sm_trie_tpl.h> |
|
dvander@3872
|
37 |
#include "logic_bridge.h" |
|
ds@580
|
38 |
|
|
ds@580
|
39 |
ConVarManager g_ConVarManager; |
|
ds@580
|
40 |
|
|
ds@2400
|
41 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
dvander@1770
|
42 |
SH_DECL_HOOK3_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *, float); |
|
dvander@1770
|
43 |
#else |
|
skamonkey@3820
|
44 |
SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallback, SH_NOATTRIB, false, ConVar *, const char *); |
|
dvander@1770
|
45 |
#endif |
|
dvander@1770
|
46 |
|
|
skamonkey@3942
|
47 |
#if SOURCE_ENGINE == SE_DOTA |
|
skamonkey@3942
|
48 |
SH_DECL_HOOK5_void(IServerGameDLL, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, CEntityIndex, EQueryCvarValueStatus, const char *, const char *); |
|
skamonkey@3942
|
49 |
SH_DECL_HOOK5_void(IServerPluginCallbacks, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, CEntityIndex, EQueryCvarValueStatus, const char *, const char *); |
|
skamonkey@3942
|
50 |
#elif SOURCE_ENGINE != SE_DARKMESSIAH |
|
ds@696
|
51 |
SH_DECL_HOOK5_void(IServerGameDLL, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); |
|
ds@696
|
52 |
SH_DECL_HOOK5_void(IServerPluginCallbacks, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); |
|
ds@2583
|
53 |
#endif |
|
ds@696
|
54 |
|
|
ds@582
|
55 |
const ParamType CONVARCHANGE_PARAMS[] = {Param_Cell, Param_String, Param_String}; |
|
ds@582
|
56 |
typedef List<const ConVar *> ConVarList; |
|
dvander@1582
|
57 |
KTrie<ConVarInfo *> convar_cache; |
|
ds@582
|
58 |
|
|
dvander@2890
|
59 |
class ConVarReentrancyGuard |
|
dvander@2890
|
60 |
{ |
|
dvander@2890
|
61 |
ConVar *cvar; |
|
dvander@2890
|
62 |
ConVarReentrancyGuard *up; |
|
dvander@2890
|
63 |
public: |
|
dvander@2890
|
64 |
static ConVarReentrancyGuard *chain; |
|
dvander@2890
|
65 |
|
|
dvander@2890
|
66 |
ConVarReentrancyGuard(ConVar *cvar) |
|
dvander@2890
|
67 |
: cvar(cvar), up(chain) |
|
dvander@2890
|
68 |
{ |
|
dvander@2890
|
69 |
chain = this; |
|
dvander@2890
|
70 |
} |
|
dvander@2890
|
71 |
|
|
dvander@2890
|
72 |
~ConVarReentrancyGuard() |
|
dvander@2890
|
73 |
{ |
|
dvander@2890
|
74 |
assert(chain == this); |
|
dvander@2890
|
75 |
chain = up; |
|
dvander@2890
|
76 |
} |
|
dvander@2890
|
77 |
|
|
dvander@2890
|
78 |
static bool IsCvarInChain(ConVar *cvar) |
|
dvander@2890
|
79 |
{ |
|
dvander@2890
|
80 |
ConVarReentrancyGuard *guard = chain; |
|
dvander@2890
|
81 |
while (guard != NULL) |
|
dvander@2890
|
82 |
{ |
|
dvander@2890
|
83 |
if (guard->cvar == cvar) |
|
dvander@2890
|
84 |
return true; |
|
dvander@2890
|
85 |
guard = guard->up; |
|
dvander@2890
|
86 |
} |
|
dvander@2890
|
87 |
return false; |
|
dvander@2890
|
88 |
} |
|
dvander@2890
|
89 |
}; |
|
dvander@2890
|
90 |
|
|
dvander@2890
|
91 |
ConVarReentrancyGuard *ConVarReentrancyGuard::chain = NULL; |
|
dvander@2890
|
92 |
|
|
dvander@1581
|
93 |
ConVarManager::ConVarManager() : m_ConVarType(0), m_bIsDLLQueryHooked(false), m_bIsVSPQueryHooked(false) |
|
ds@580
|
94 |
{ |
|
ds@580
|
95 |
} |
|
ds@580
|
96 |
|
|
ds@580
|
97 |
ConVarManager::~ConVarManager() |
|
ds@580
|
98 |
{ |
|
ds@580
|
99 |
} |
|
ds@580
|
100 |
|
|
dvander@1770
|
101 |
void ConVarManager::OnSourceModStartup(bool late) |
|
dvander@1770
|
102 |
{ |
|
dvander@1770
|
103 |
HandleAccess sec; |
|
dvander@1770
|
104 |
|
|
dvander@1770
|
105 |
/* Set up access rights for the 'ConVar' handle type */ |
|
dvander@1770
|
106 |
sec.access[HandleAccess_Read] = 0; |
|
dvander@1770
|
107 |
sec.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; |
|
dvander@1770
|
108 |
sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; |
|
dvander@1770
|
109 |
|
|
dvander@1770
|
110 |
/* Create the 'ConVar' handle type */ |
|
dvander@3872
|
111 |
m_ConVarType = handlesys->CreateType("ConVar", this, 0, NULL, &sec, g_pCoreIdent, NULL); |
|
dvander@1770
|
112 |
} |
|
dvander@1770
|
113 |
|
|
ds@580
|
114 |
void ConVarManager::OnSourceModAllInitialized() |
|
ds@580
|
115 |
{ |
|
dvander@1581
|
116 |
/** |
|
dvander@1581
|
117 |
* Episode 2 has this function by default, but the older versions do not. |
|
dvander@1581
|
118 |
*/ |
|
ds@2400
|
119 |
#if SOURCE_ENGINE == SE_EPISODEONE |
|
ds@696
|
120 |
if (g_SMAPI->GetGameDLLVersion() >= 6) |
|
ds@696
|
121 |
{ |
|
kyle@3819
|
122 |
SH_ADD_HOOK(IServerGameDLL, OnQueryCvarValueFinished, gamedll, SH_MEMBER(this, &ConVarManager::OnQueryCvarValueFinished), false); |
|
dvander@1581
|
123 |
m_bIsDLLQueryHooked = true; |
|
ds@696
|
124 |
} |
|
dvander@1759
|
125 |
#endif |
|
ds@696
|
126 |
|
|
skamonkey@3820
|
127 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
kyle@3819
|
128 |
SH_ADD_HOOK(ICvar, CallGlobalChangeCallbacks, icvar, SH_STATIC(OnConVarChanged), false); |
|
skamonkey@3820
|
129 |
#else |
|
skamonkey@3820
|
130 |
SH_ADD_HOOK(ICvar, CallGlobalChangeCallback, icvar, SH_STATIC(OnConVarChanged), false); |
|
skamonkey@3820
|
131 |
#endif |
|
ds@580
|
132 |
|
|
dvander@3872
|
133 |
scripts->AddPluginsListener(this); |
|
ds@2825
|
134 |
|
|
ds@582
|
135 |
/* Add the 'convars' option to the 'sm' console command */ |
|
ds@990
|
136 |
g_RootMenu.AddRootConsoleCommand("cvars", "View convars created by a plugin", this); |
|
ds@580
|
137 |
} |
|
ds@580
|
138 |
|
|
ds@580
|
139 |
void ConVarManager::OnSourceModShutdown() |
|
ds@580
|
140 |
{ |
|
dvander@1582
|
141 |
List<ConVarInfo *>::iterator iter = m_ConVars.begin(); |
|
dvander@1582
|
142 |
HandleSecurity sec(NULL, g_pCoreIdent); |
|
dvander@1582
|
143 |
|
|
dvander@1582
|
144 |
/* Iterate list of ConVarInfo structures, remove every one of them */ |
|
dvander@1582
|
145 |
while (iter != m_ConVars.end()) |
|
dvander@1582
|
146 |
{ |
|
dvander@1582
|
147 |
ConVarInfo *pInfo = (*iter); |
|
dvander@1582
|
148 |
|
|
dvander@1582
|
149 |
iter = m_ConVars.erase(iter); |
|
dvander@1582
|
150 |
|
|
dvander@3872
|
151 |
handlesys->FreeHandle(pInfo->handle, &sec); |
|
dvander@1582
|
152 |
if (pInfo->pChangeForward != NULL) |
|
dvander@1582
|
153 |
{ |
|
dvander@1582
|
154 |
g_Forwards.ReleaseForward(pInfo->pChangeForward); |
|
dvander@1582
|
155 |
} |
|
dvander@1582
|
156 |
if (pInfo->sourceMod) |
|
dvander@1582
|
157 |
{ |
|
dvander@1582
|
158 |
/* If we created it, we won't be tracking it, therefore it is |
|
dvander@1582
|
159 |
* safe to remove everything in one go. |
|
dvander@1582
|
160 |
*/ |
|
dvander@1582
|
161 |
META_UNREGCVAR(pInfo->pVar); |
|
dvander@1582
|
162 |
delete [] pInfo->pVar->GetName(); |
|
dvander@1582
|
163 |
delete [] pInfo->pVar->GetHelpText(); |
|
dvander@1582
|
164 |
delete [] pInfo->pVar->GetDefault(); |
|
dvander@1582
|
165 |
delete pInfo->pVar; |
|
dvander@1582
|
166 |
} |
|
dvander@1582
|
167 |
else |
|
dvander@1582
|
168 |
{ |
|
dvander@1582
|
169 |
/* If we didn't create it, we might be tracking it. Also, |
|
dvander@1582
|
170 |
* it could be unreadable. |
|
dvander@1582
|
171 |
*/ |
|
dvander@1582
|
172 |
UntrackConCommandBase(pInfo->pVar, this); |
|
dvander@1582
|
173 |
} |
|
dvander@1582
|
174 |
|
|
dvander@1582
|
175 |
/* It's not safe to read the name here, so we simply delete the |
|
dvander@1582
|
176 |
* the info struct and clear the lookup cache at the end. |
|
dvander@1582
|
177 |
*/ |
|
dvander@1582
|
178 |
delete pInfo; |
|
dvander@1582
|
179 |
} |
|
dvander@1582
|
180 |
convar_cache.clear(); |
|
dvander@1582
|
181 |
|
|
ds@2583
|
182 |
#if SOURCE_ENGINE != SE_DARKMESSIAH |
|
dvander@1582
|
183 |
/* Unhook things */ |
|
dvander@1581
|
184 |
if (m_bIsDLLQueryHooked) |
|
ds@696
|
185 |
{ |
|
kyle@3819
|
186 |
SH_REMOVE_HOOK(IServerGameDLL, OnQueryCvarValueFinished, gamedll, SH_MEMBER(this, &ConVarManager::OnQueryCvarValueFinished), false); |
|
dvander@1581
|
187 |
m_bIsDLLQueryHooked = false; |
|
dvander@1581
|
188 |
} |
|
dvander@1581
|
189 |
else if (m_bIsVSPQueryHooked) |
|
dvander@1581
|
190 |
{ |
|
skamonkey@3942
|
191 |
#if SOURCE_ENGINE != SE_DOTA |
|
kyle@3819
|
192 |
SH_REMOVE_HOOK(IServerPluginCallbacks, OnQueryCvarValueFinished, vsp_interface, SH_MEMBER(this, &ConVarManager::OnQueryCvarValueFinished), false); |
|
skamonkey@3942
|
193 |
#endif |
|
dvander@1581
|
194 |
m_bIsVSPQueryHooked = false; |
|
ds@696
|
195 |
} |
|
ds@2583
|
196 |
#endif |
|
ds@696
|
197 |
|
|
skamonkey@3820
|
198 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
kyle@3819
|
199 |
SH_REMOVE_HOOK(ICvar, CallGlobalChangeCallbacks, icvar, SH_STATIC(OnConVarChanged), false); |
|
skamonkey@3820
|
200 |
#else |
|
skamonkey@3820
|
201 |
SH_REMOVE_HOOK(ICvar, CallGlobalChangeCallback, icvar, SH_STATIC(OnConVarChanged), false); |
|
skamonkey@3820
|
202 |
#endif |
|
dvander@1770
|
203 |
|
|
ds@582
|
204 |
/* Remove the 'convars' option from the 'sm' console command */ |
|
ds@990
|
205 |
g_RootMenu.RemoveRootConsoleCommand("cvars", this); |
|
ds@580
|
206 |
|
|
dvander@3872
|
207 |
scripts->RemovePluginsListener(this); |
|
ds@2825
|
208 |
|
|
ds@582
|
209 |
/* Remove the 'ConVar' handle type */ |
|
dvander@3872
|
210 |
handlesys->RemoveType(m_ConVarType, g_pCoreIdent); |
|
ds@580
|
211 |
} |
|
ds@580
|
212 |
|
|
dvander@1581
|
213 |
/** |
|
dvander@1581
|
214 |
* Orange Box will never use this. |
|
dvander@1581
|
215 |
*/ |
|
dvander@1581
|
216 |
void ConVarManager::OnSourceModVSPReceived() |
|
ds@696
|
217 |
{ |
|
dvander@1581
|
218 |
/** |
|
dvander@1581
|
219 |
* Don't bother if the DLL is already hooked. |
|
ds@696
|
220 |
*/ |
|
dvander@1581
|
221 |
if (m_bIsDLLQueryHooked) |
|
ds@696
|
222 |
{ |
|
ds@696
|
223 |
return; |
|
ds@696
|
224 |
} |
|
ds@696
|
225 |
|
|
dvander@1581
|
226 |
/* For later MM:S versions, use the updated API, since it's cleaner. */ |
|
dvander@2846
|
227 |
#if defined METAMOD_PLAPI_VERSION || PLAPI_VERSION >= 11 |
|
dvander@1581
|
228 |
int engine = g_SMAPI->GetSourceEngineBuild(); |
|
dvander@1581
|
229 |
if (engine == SOURCE_ENGINE_ORIGINAL || vsp_version < 2) |
|
ds@696
|
230 |
{ |
|
dvander@1581
|
231 |
return; |
|
dvander@1581
|
232 |
} |
|
dvander@1581
|
233 |
#else |
|
dvander@1581
|
234 |
if (g_HL2.IsOriginalEngine() || vsp_version < 2) |
|
dvander@1581
|
235 |
{ |
|
dvander@1581
|
236 |
return; |
|
dvander@1581
|
237 |
} |
|
dvander@1581
|
238 |
#endif |
|
ds@696
|
239 |
|
|
skamonkey@3942
|
240 |
#if SOURCE_ENGINE != SE_DARKMESSIAH && SOURCE_ENGINE != SE_DOTA |
|
kyle@3819
|
241 |
SH_ADD_HOOK(IServerPluginCallbacks, OnQueryCvarValueFinished, vsp_interface, SH_MEMBER(this, &ConVarManager::OnQueryCvarValueFinished), false); |
|
dvander@1581
|
242 |
m_bIsVSPQueryHooked = true; |
|
ds@2583
|
243 |
#endif |
|
ds@696
|
244 |
} |
|
ds@696
|
245 |
|
|
dvander@1582
|
246 |
bool convar_cache_lookup(const char *name, ConVarInfo **pVar) |
|
ds@1145
|
247 |
{ |
|
dvander@1582
|
248 |
ConVarInfo **pLookup = convar_cache.retrieve(name); |
|
dvander@1582
|
249 |
if (pLookup != NULL) |
|
ds@1145
|
250 |
{ |
|
dvander@1582
|
251 |
*pVar = *pLookup; |
|
dvander@1582
|
252 |
return true; |
|
dvander@1582
|
253 |
} |
|
dvander@1582
|
254 |
else |
|
dvander@1582
|
255 |
{ |
|
dvander@1582
|
256 |
return false; |
|
ds@1145
|
257 |
} |
|
ds@1145
|
258 |
} |
|
ds@1145
|
259 |
|
|
dvander@1582
|
260 |
void ConVarManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe) |
|
dvander@1582
|
261 |
{ |
|
dvander@1582
|
262 |
/* Only check convars that have not been created by SourceMod's core */ |
|
dvander@1582
|
263 |
ConVarInfo *pInfo; |
|
dvander@1582
|
264 |
if (!convar_cache_lookup(name, &pInfo)) |
|
dvander@1582
|
265 |
{ |
|
dvander@1582
|
266 |
return; |
|
dvander@1582
|
267 |
} |
|
ds@1145
|
268 |
|
|
ds@1145
|
269 |
HandleSecurity sec(NULL, g_pCoreIdent); |
|
ds@1145
|
270 |
|
|
dvander@1582
|
271 |
/* Remove it from our cache */ |
|
dvander@1582
|
272 |
m_ConVars.remove(pInfo); |
|
dvander@1582
|
273 |
convar_cache.remove(name); |
|
dvander@1582
|
274 |
|
|
dvander@1582
|
275 |
/* Now make sure no plugins are referring to this pointer */ |
|
dvander@3872
|
276 |
IPluginIterator *pl_iter = scripts->GetPluginIterator(); |
|
dvander@1582
|
277 |
while (pl_iter->MorePlugins()) |
|
ds@1145
|
278 |
{ |
|
dvander@1582
|
279 |
IPlugin *pl = pl_iter->GetPlugin(); |
|
ds@1145
|
280 |
|
|
dvander@1582
|
281 |
ConVarList *pConVarList; |
|
dvander@1582
|
282 |
if (pl->GetProperty("ConVarList", (void **)&pConVarList, true) |
|
dvander@1582
|
283 |
&& pConVarList != NULL) |
|
ds@1145
|
284 |
{ |
|
dvander@1582
|
285 |
pConVarList->remove(pInfo->pVar); |
|
dvander@1582
|
286 |
} |
|
ds@1145
|
287 |
|
|
dvander@1582
|
288 |
pl_iter->NextPlugin(); |
|
ds@1145
|
289 |
} |
|
dvander@1582
|
290 |
|
|
dvander@1582
|
291 |
/* Free resources */ |
|
dvander@3872
|
292 |
handlesys->FreeHandle(pInfo->handle, &sec); |
|
dvander@1582
|
293 |
delete pInfo; |
|
ds@1145
|
294 |
} |
|
ds@1145
|
295 |
|
|
ds@582
|
296 |
void ConVarManager::OnPluginUnloaded(IPlugin *plugin) |
|
ds@580
|
297 |
{ |
|
ds@582
|
298 |
ConVarList *pConVarList; |
|
ds@2825
|
299 |
List<ConVarQuery>::iterator iter; |
|
ds@580
|
300 |
|
|
ds@582
|
301 |
/* If plugin has a convar list, free its memory */ |
|
ds@582
|
302 |
if (plugin->GetProperty("ConVarList", (void **)&pConVarList, true)) |
|
ds@580
|
303 |
{ |
|
ds@582
|
304 |
delete pConVarList; |
|
ds@580
|
305 |
} |
|
ds@2825
|
306 |
|
|
kyle@3995
|
307 |
const IPluginRuntime * pRuntime = plugin->GetRuntime(); |
|
kyle@3995
|
308 |
|
|
ds@2825
|
309 |
/* Remove convar queries for this plugin that haven't returned results yet */ |
|
kyle@3995
|
310 |
for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();) |
|
ds@2825
|
311 |
{ |
|
ds@2825
|
312 |
ConVarQuery &query = (*iter); |
|
kyle@3995
|
313 |
if (query.pCallback->GetParentRuntime() == pRuntime) |
|
ds@2825
|
314 |
{ |
|
kyle@3995
|
315 |
iter = m_ConVarQueries.erase(iter); |
|
kyle@3995
|
316 |
continue; |
|
ds@2825
|
317 |
} |
|
kyle@3995
|
318 |
|
|
kyle@3995
|
319 |
++iter; |
|
ds@2825
|
320 |
} |
|
ds@580
|
321 |
} |
|
ds@580
|
322 |
|
|
ds@580
|
323 |
void ConVarManager::OnHandleDestroy(HandleType_t type, void *object) |
|
ds@580
|
324 |
{ |
|
ds@580
|
325 |
} |
|
ds@580
|
326 |
|
|
dvander@1766
|
327 |
bool ConVarManager::GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize) |
|
dvander@1766
|
328 |
{ |
|
dvander@1770
|
329 |
*pSize = sizeof(ConVar) + sizeof(ConVarInfo); |
|
dvander@1766
|
330 |
return true; |
|
dvander@1766
|
331 |
} |
|
dvander@1766
|
332 |
|
|
faluco@1541
|
333 |
void ConVarManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command) |
|
ds@580
|
334 |
{ |
|
faluco@1541
|
335 |
int argcount = command.ArgC(); |
|
ds@580
|
336 |
if (argcount >= 3) |
|
ds@580
|
337 |
{ |
|
asherkin@3367
|
338 |
bool wantReset = false; |
|
asherkin@3367
|
339 |
|
|
ds@582
|
340 |
/* Get plugin index that was passed */ |
|
dvander@1902
|
341 |
const char *arg = command.Arg(2); |
|
asherkin@3367
|
342 |
if (argcount >= 4 && strcmp(arg, "reset") == 0) |
|
asherkin@3367
|
343 |
{ |
|
asherkin@3367
|
344 |
wantReset = true; |
|
asherkin@3367
|
345 |
arg = command.Arg(3); |
|
asherkin@3367
|
346 |
} |
|
ds@580
|
347 |
|
|
ds@582
|
348 |
/* Get plugin object */ |
|
dvander@3872
|
349 |
IPlugin *plugin = scripts->FindPluginByConsoleArg(arg); |
|
ds@582
|
350 |
|
|
ds@582
|
351 |
if (!plugin) |
|
ds@580
|
352 |
{ |
|
dvander@1902
|
353 |
g_RootMenu.ConsolePrint("[SM] Plugin \"%s\" was not found.", arg); |
|
ds@580
|
354 |
return; |
|
ds@580
|
355 |
} |
|
ds@580
|
356 |
|
|
ds@582
|
357 |
/* Get plugin name */ |
|
ds@582
|
358 |
const sm_plugininfo_t *plinfo = plugin->GetPublicInfo(); |
|
ds@582
|
359 |
const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : plugin->GetFilename(); |
|
ds@580
|
360 |
|
|
ds@582
|
361 |
ConVarList *pConVarList; |
|
ds@582
|
362 |
ConVarList::iterator iter; |
|
ds@580
|
363 |
|
|
ds@582
|
364 |
/* If no convar list... */ |
|
ds@582
|
365 |
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) |
|
ds@580
|
366 |
{ |
|
ds@582
|
367 |
g_RootMenu.ConsolePrint("[SM] No convars found for: %s", plname); |
|
ds@580
|
368 |
return; |
|
ds@580
|
369 |
} |
|
ds@580
|
370 |
|
|
asherkin@3367
|
371 |
if (!wantReset) |
|
asherkin@3367
|
372 |
{ |
|
asherkin@3367
|
373 |
g_RootMenu.ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname); |
|
asherkin@3367
|
374 |
g_RootMenu.ConsolePrint(" %-32.31s %s", "[Name]", "[Value]"); |
|
asherkin@3367
|
375 |
} |
|
asherkin@3367
|
376 |
|
|
asherkin@3367
|
377 |
/* Iterate convar list and display/reset each one */ |
|
ds@582
|
378 |
for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) |
|
ds@580
|
379 |
{ |
|
asherkin@3367
|
380 |
/*const */ConVar *pConVar = const_cast<ConVar *>(*iter); |
|
asherkin@3367
|
381 |
if (!wantReset) |
|
asherkin@3367
|
382 |
{ |
|
asherkin@3367
|
383 |
g_RootMenu.ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString()); |
|
asherkin@3367
|
384 |
} else { |
|
asherkin@3367
|
385 |
pConVar->Revert(); |
|
asherkin@3367
|
386 |
} |
|
asherkin@3367
|
387 |
} |
|
asherkin@3367
|
388 |
|
|
asherkin@3367
|
389 |
if (wantReset) |
|
asherkin@3367
|
390 |
{ |
|
asherkin@3367
|
391 |
g_RootMenu.ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname); |
|
ds@580
|
392 |
} |
|
ds@580
|
393 |
|
|
ds@580
|
394 |
return; |
|
ds@580
|
395 |
} |
|
ds@580
|
396 |
|
|
ds@582
|
397 |
/* Display usage of subcommand */ |
|
asherkin@3367
|
398 |
g_RootMenu.ConsolePrint("[SM] Usage: sm cvars [reset] <plugin #>"); |
|
ds@580
|
399 |
} |
|
ds@580
|
400 |
|
|
ds@582
|
401 |
Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, const char *description, int flags, bool hasMin, float min, bool hasMax, float max) |
|
ds@580
|
402 |
{ |
|
ds@580
|
403 |
ConVar *pConVar = NULL; |
|
ds@582
|
404 |
ConVarInfo *pInfo = NULL; |
|
ds@580
|
405 |
Handle_t hndl = 0; |
|
ds@580
|
406 |
|
|
ds@582
|
407 |
/* Find out if the convar exists already */ |
|
ds@580
|
408 |
pConVar = icvar->FindVar(name); |
|
ds@580
|
409 |
|
|
ds@582
|
410 |
/* If the convar already exists... */ |
|
ds@582
|
411 |
if (pConVar) |
|
ds@580
|
412 |
{ |
|
ds@759
|
413 |
/* Add convar to plugin's list */ |
|
ds@759
|
414 |
AddConVarToPluginList(pContext, pConVar); |
|
ds@759
|
415 |
|
|
ds@582
|
416 |
/* First find out if we already have a handle to it */ |
|
dvander@1582
|
417 |
if (convar_cache_lookup(name, &pInfo)) |
|
ds@580
|
418 |
{ |
|
ds@582
|
419 |
return pInfo->handle; |
|
dvander@1581
|
420 |
} |
|
dvander@1581
|
421 |
else |
|
dvander@1581
|
422 |
{ |
|
ds@582
|
423 |
/* Create and initialize ConVarInfo structure */ |
|
ds@582
|
424 |
pInfo = new ConVarInfo(); |
|
ds@582
|
425 |
pInfo->sourceMod = false; |
|
ds@696
|
426 |
pInfo->pChangeForward = NULL; |
|
dvander@1582
|
427 |
pInfo->pVar = pConVar; |
|
dvander@1582
|
428 |
|
|
dvander@1582
|
429 |
/* If we don't, then create a new handle from the convar */ |
|
dvander@3872
|
430 |
hndl = handlesys->CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL); |
|
dvander@1582
|
431 |
if (hndl == BAD_HANDLE) |
|
dvander@1582
|
432 |
{ |
|
dvander@1582
|
433 |
delete pInfo; |
|
dvander@1582
|
434 |
return BAD_HANDLE; |
|
dvander@1582
|
435 |
} |
|
dvander@1582
|
436 |
|
|
dvander@1582
|
437 |
pInfo->handle = hndl; |
|
ds@580
|
438 |
|
|
ds@582
|
439 |
/* Insert struct into caches */ |
|
ds@582
|
440 |
m_ConVars.push_back(pInfo); |
|
dvander@1582
|
441 |
convar_cache.insert(name, pInfo); |
|
dvander@1582
|
442 |
TrackConCommandBase(pConVar, this); |
|
ds@580
|
443 |
|
|
ds@580
|
444 |
return hndl; |
|
ds@580
|
445 |
} |
|
ds@580
|
446 |
} |
|
ds@580
|
447 |
|
|
ds@2400
|
448 |
/* Prevent creating a convar that has the same name as a console command */ |
|
ds@2400
|
449 |
if (FindCommand(name)) |
|
ds@580
|
450 |
{ |
|
ds@2400
|
451 |
return BAD_HANDLE; |
|
ds@580
|
452 |
} |
|
ds@580
|
453 |
|
|
ds@582
|
454 |
/* Create and initialize ConVarInfo structure */ |
|
ds@582
|
455 |
pInfo = new ConVarInfo(); |
|
ds@582
|
456 |
pInfo->handle = hndl; |
|
ds@582
|
457 |
pInfo->sourceMod = true; |
|
ds@696
|
458 |
pInfo->pChangeForward = NULL; |
|
dvander@1582
|
459 |
|
|
dvander@1582
|
460 |
/* Create a handle from the new convar */ |
|
dvander@3872
|
461 |
hndl = handlesys->CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL); |
|
dvander@1582
|
462 |
if (hndl == BAD_HANDLE) |
|
dvander@1582
|
463 |
{ |
|
dvander@1582
|
464 |
delete pInfo; |
|
dvander@1582
|
465 |
return BAD_HANDLE; |
|
dvander@1582
|
466 |
} |
|
dvander@1582
|
467 |
|
|
dvander@1582
|
468 |
pInfo->handle = hndl; |
|
dvander@1582
|
469 |
|
|
dvander@1582
|
470 |
/* Since an existing convar (or concmd with the same name) was not found , now we can finally create it */ |
|
dvander@1582
|
471 |
pConVar = new ConVar(sm_strdup(name), sm_strdup(defaultVal), flags, sm_strdup(description), hasMin, min, hasMax, max); |
|
dvander@1582
|
472 |
pInfo->pVar = pConVar; |
|
dvander@1582
|
473 |
|
|
dvander@1582
|
474 |
/* Add convar to plugin's list */ |
|
dvander@1582
|
475 |
AddConVarToPluginList(pContext, pConVar); |
|
ds@580
|
476 |
|
|
ds@582
|
477 |
/* Insert struct into caches */ |
|
ds@582
|
478 |
m_ConVars.push_back(pInfo); |
|
dvander@1582
|
479 |
convar_cache.insert(name, pInfo); |
|
ds@580
|
480 |
|
|
ds@580
|
481 |
return hndl; |
|
ds@580
|
482 |
} |
|
ds@580
|
483 |
|
|
ds@580
|
484 |
Handle_t ConVarManager::FindConVar(const char *name) |
|
ds@580
|
485 |
{ |
|
ds@580
|
486 |
ConVar *pConVar = NULL; |
|
ds@582
|
487 |
ConVarInfo *pInfo; |
|
ds@582
|
488 |
Handle_t hndl; |
|
ds@580
|
489 |
|
|
ds@582
|
490 |
/* Search for convar */ |
|
ds@580
|
491 |
pConVar = icvar->FindVar(name); |
|
ds@580
|
492 |
|
|
ds@582
|
493 |
/* If it doesn't exist, then return an invalid handle */ |
|
ds@582
|
494 |
if (!pConVar) |
|
ds@580
|
495 |
{ |
|
ds@580
|
496 |
return BAD_HANDLE; |
|
ds@580
|
497 |
} |
|
ds@580
|
498 |
|
|
ds@582
|
499 |
/* At this point, the convar exists. So, find out if we already have a handle */ |
|
dvander@1582
|
500 |
if (convar_cache_lookup(name, &pInfo)) |
|
ds@580
|
501 |
{ |
|
ds@582
|
502 |
return pInfo->handle; |
|
ds@580
|
503 |
} |
|
ds@580
|
504 |
|
|
ds@729
|
505 |
/* Create and initialize ConVarInfo structure */ |
|
ds@582
|
506 |
pInfo = new ConVarInfo(); |
|
ds@582
|
507 |
pInfo->sourceMod = false; |
|
ds@696
|
508 |
pInfo->pChangeForward = NULL; |
|
dvander@1582
|
509 |
pInfo->pVar = pConVar; |
|
dvander@1582
|
510 |
|
|
dvander@1582
|
511 |
/* If we don't have a handle, then create a new one */ |
|
dvander@3872
|
512 |
hndl = handlesys->CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL); |
|
dvander@1582
|
513 |
if (hndl == BAD_HANDLE) |
|
dvander@1582
|
514 |
{ |
|
dvander@1582
|
515 |
delete pInfo; |
|
dvander@1582
|
516 |
return BAD_HANDLE; |
|
dvander@1582
|
517 |
} |
|
dvander@1582
|
518 |
|
|
dvander@1582
|
519 |
pInfo->handle = hndl; |
|
ds@580
|
520 |
|
|
ds@582
|
521 |
/* Insert struct into our caches */ |
|
ds@582
|
522 |
m_ConVars.push_back(pInfo); |
|
dvander@1582
|
523 |
convar_cache.insert(name, pInfo); |
|
dvander@1582
|
524 |
TrackConCommandBase(pConVar, this); |
|
ds@580
|
525 |
|
|
ds@580
|
526 |
return hndl; |
|
ds@580
|
527 |
} |
|
ds@580
|
528 |
|
|
dvander@1770
|
529 |
void ConVarManager::AddConVarChangeListener(const char *name, IConVarChangeListener *pListener) |
|
dvander@1770
|
530 |
{ |
|
dvander@1770
|
531 |
ConVarInfo *pInfo; |
|
dvander@1770
|
532 |
|
|
dvander@1770
|
533 |
if (FindConVar(name) == BAD_HANDLE) |
|
dvander@1770
|
534 |
{ |
|
dvander@1770
|
535 |
return; |
|
dvander@1770
|
536 |
} |
|
dvander@1770
|
537 |
|
|
dvander@1770
|
538 |
/* Find the convar in the lookup trie */ |
|
dvander@1770
|
539 |
if (convar_cache_lookup(name, &pInfo)) |
|
dvander@1770
|
540 |
{ |
|
dvander@1770
|
541 |
pInfo->changeListeners.push_back(pListener); |
|
dvander@1770
|
542 |
} |
|
dvander@1770
|
543 |
} |
|
dvander@1770
|
544 |
|
|
dvander@1770
|
545 |
void ConVarManager::RemoveConVarChangeListener(const char *name, IConVarChangeListener *pListener) |
|
dvander@1770
|
546 |
{ |
|
dvander@1770
|
547 |
ConVarInfo *pInfo; |
|
dvander@1770
|
548 |
|
|
dvander@1770
|
549 |
/* Find the convar in the lookup trie */ |
|
dvander@1770
|
550 |
if (convar_cache_lookup(name, &pInfo)) |
|
dvander@1770
|
551 |
{ |
|
dvander@1770
|
552 |
pInfo->changeListeners.remove(pListener); |
|
dvander@1770
|
553 |
} |
|
dvander@1770
|
554 |
} |
|
dvander@1770
|
555 |
|
|
ds@582
|
556 |
void ConVarManager::HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction) |
|
ds@580
|
557 |
{ |
|
ds@582
|
558 |
ConVarInfo *pInfo; |
|
ds@582
|
559 |
IChangeableForward *pForward; |
|
ds@580
|
560 |
|
|
ds@582
|
561 |
/* Find the convar in the lookup trie */ |
|
dvander@1582
|
562 |
if (convar_cache_lookup(pConVar->GetName(), &pInfo)) |
|
ds@580
|
563 |
{ |
|
ds@582
|
564 |
/* Get the forward */ |
|
ds@696
|
565 |
pForward = pInfo->pChangeForward; |
|
ds@580
|
566 |
|
|
ds@582
|
567 |
/* If forward does not exist, create it */ |
|
ds@582
|
568 |
if (!pForward) |
|
ds@582
|
569 |
{ |
|
ds@582
|
570 |
pForward = g_Forwards.CreateForwardEx(NULL, ET_Ignore, 3, CONVARCHANGE_PARAMS); |
|
ds@696
|
571 |
pInfo->pChangeForward = pForward; |
|
ds@580
|
572 |
} |
|
ds@582
|
573 |
|
|
ds@582
|
574 |
/* Add function to forward's list */ |
|
ds@582
|
575 |
pForward->AddFunction(pFunction); |
|
ds@580
|
576 |
} |
|
ds@580
|
577 |
} |
|
ds@580
|
578 |
|
|
ds@582
|
579 |
void ConVarManager::UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction) |
|
ds@580
|
580 |
{ |
|
ds@582
|
581 |
ConVarInfo *pInfo; |
|
ds@582
|
582 |
IChangeableForward *pForward; |
|
ds@582
|
583 |
IPluginContext *pContext = pFunction->GetParentContext(); |
|
ds@580
|
584 |
|
|
ds@582
|
585 |
/* Find the convar in the lookup trie */ |
|
dvander@1582
|
586 |
if (convar_cache_lookup(pConVar->GetName(), &pInfo)) |
|
ds@580
|
587 |
{ |
|
ds@582
|
588 |
/* Get the forward */ |
|
ds@696
|
589 |
pForward = pInfo->pChangeForward; |
|
ds@580
|
590 |
|
|
ds@582
|
591 |
/* If the forward doesn't exist, we can't unhook anything */ |
|
ds@582
|
592 |
if (!pForward) |
|
ds@580
|
593 |
{ |
|
ds@580
|
594 |
pContext->ThrowNativeError("Convar \"%s\" has no active hook", pConVar->GetName()); |
|
ds@580
|
595 |
return; |
|
ds@580
|
596 |
} |
|
ds@580
|
597 |
|
|
ds@582
|
598 |
/* Remove the function from the forward's list */ |
|
ds@582
|
599 |
if (!pForward->RemoveFunction(pFunction)) |
|
ds@580
|
600 |
{ |
|
ds@580
|
601 |
pContext->ThrowNativeError("Invalid hook callback specified for convar \"%s\"", pConVar->GetName()); |
|
ds@580
|
602 |
return; |
|
ds@580
|
603 |
} |
|
ds@580
|
604 |
|
|
ds@582
|
605 |
/* If the forward now has 0 functions in it... */ |
|
dvander@2890
|
606 |
if (pForward->GetFunctionCount() == 0 && |
|
dvander@2890
|
607 |
!ConVarReentrancyGuard::IsCvarInChain(pConVar)) |
|
ds@580
|
608 |
{ |
|
ds@582
|
609 |
/* Free this forward */ |
|
ds@582
|
610 |
g_Forwards.ReleaseForward(pForward); |
|
ds@696
|
611 |
pInfo->pChangeForward = NULL; |
|
ds@582
|
612 |
} |
|
ds@582
|
613 |
} |
|
ds@582
|
614 |
} |
|
ds@582
|
615 |
|
|
ds@696
|
616 |
QueryCvarCookie_t ConVarManager::QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback, Handle_t hndl) |
|
ds@696
|
617 |
{ |
|
ds@2583
|
618 |
QueryCvarCookie_t cookie = 0; |
|
ds@696
|
619 |
|
|
ds@2583
|
620 |
#if SOURCE_ENGINE != SE_DARKMESSIAH |
|
ds@696
|
621 |
/* Call StartQueryCvarValue() in either the IVEngineServer or IServerPluginHelpers depending on situation */ |
|
dvander@1581
|
622 |
if (m_bIsDLLQueryHooked) |
|
ds@696
|
623 |
{ |
|
skamonkey@3913
|
624 |
#if SOURCE_ENGINE == SE_DOTA |
|
skamonkey@3942
|
625 |
cookie = engine->StartQueryCvarValue(CEntityIndex(IndexOfEdict(pPlayer)), name); |
|
skamonkey@3913
|
626 |
#else |
|
ds@696
|
627 |
cookie = engine->StartQueryCvarValue(pPlayer, name); |
|
skamonkey@3913
|
628 |
#endif |
|
dvander@1581
|
629 |
} |
|
skamonkey@3854
|
630 |
#if SOURCE_ENGINE != SE_DOTA |
|
dvander@1581
|
631 |
else if (m_bIsVSPQueryHooked) |
|
dvander@1581
|
632 |
{ |
|
ds@696
|
633 |
cookie = serverpluginhelpers->StartQueryCvarValue(pPlayer, name); |
|
ds@696
|
634 |
} |
|
skamonkey@3854
|
635 |
#endif |
|
dvander@1581
|
636 |
else |
|
dvander@1581
|
637 |
{ |
|
dvander@1581
|
638 |
return InvalidQueryCvarCookie; |
|
dvander@1581
|
639 |
} |
|
ds@696
|
640 |
|
|
ds@696
|
641 |
ConVarQuery query = {cookie, pCallback, hndl}; |
|
ds@696
|
642 |
m_ConVarQueries.push_back(query); |
|
ds@2583
|
643 |
#endif |
|
ds@696
|
644 |
|
|
ds@696
|
645 |
return cookie; |
|
ds@696
|
646 |
} |
|
ds@696
|
647 |
|
|
ds@582
|
648 |
void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar) |
|
ds@582
|
649 |
{ |
|
ds@582
|
650 |
ConVarList *pConVarList; |
|
ds@582
|
651 |
ConVarList::iterator iter; |
|
ds@582
|
652 |
bool inserted = false; |
|
ds@582
|
653 |
const char *orig = pConVar->GetName(); |
|
ds@582
|
654 |
|
|
dvander@3872
|
655 |
IPlugin *plugin = scripts->FindPluginByContext(pContext->GetContext()); |
|
ds@580
|
656 |
|
|
ds@582
|
657 |
/* Check plugin for an existing convar list */ |
|
ds@582
|
658 |
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) |
|
ds@582
|
659 |
{ |
|
ds@582
|
660 |
pConVarList = new ConVarList(); |
|
ds@582
|
661 |
plugin->SetProperty("ConVarList", pConVarList); |
|
dvander@1581
|
662 |
} |
|
dvander@1581
|
663 |
else if (pConVarList->find(pConVar) != pConVarList->end()) |
|
dvander@1581
|
664 |
{ |
|
ds@867
|
665 |
/* If convar is already in list, then don't add it */ |
|
ds@867
|
666 |
return; |
|
ds@582
|
667 |
} |
|
ds@582
|
668 |
|
|
ds@582
|
669 |
/* Insert convar into list which is sorted alphabetically */ |
|
ds@582
|
670 |
for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) |
|
ds@582
|
671 |
{ |
|
ds@582
|
672 |
if (strcmp(orig, (*iter)->GetName()) < 0) |
|
ds@582
|
673 |
{ |
|
ds@582
|
674 |
pConVarList->insert(iter, pConVar); |
|
ds@582
|
675 |
inserted = true; |
|
ds@582
|
676 |
break; |
|
ds@580
|
677 |
} |
|
ds@580
|
678 |
} |
|
ds@582
|
679 |
|
|
ds@582
|
680 |
if (!inserted) |
|
ds@582
|
681 |
{ |
|
ds@582
|
682 |
pConVarList->push_back(pConVar); |
|
ds@582
|
683 |
} |
|
ds@580
|
684 |
} |
|
ds@580
|
685 |
|
|
ds@2400
|
686 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
dvander@1770
|
687 |
void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue) |
|
faluco@1541
|
688 |
#else |
|
ds@580
|
689 |
void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue) |
|
faluco@1541
|
690 |
#endif |
|
ds@580
|
691 |
{ |
|
ds@582
|
692 |
/* If the values are the same, exit early in order to not trigger callbacks */ |
|
dvander@1544
|
693 |
if (strcmp(pConVar->GetString(), oldValue) == 0) |
|
ds@580
|
694 |
{ |
|
ds@580
|
695 |
return; |
|
ds@580
|
696 |
} |
|
ds@580
|
697 |
|
|
ds@582
|
698 |
ConVarInfo *pInfo; |
|
ds@580
|
699 |
|
|
ds@582
|
700 |
/* Find the convar in the lookup trie */ |
|
dvander@1582
|
701 |
if (!convar_cache_lookup(pConVar->GetName(), &pInfo)) |
|
dvander@1582
|
702 |
{ |
|
dvander@1582
|
703 |
return; |
|
dvander@1582
|
704 |
} |
|
ds@580
|
705 |
|
|
ds@696
|
706 |
IChangeableForward *pForward = pInfo->pChangeForward; |
|
ds@580
|
707 |
|
|
dvander@1770
|
708 |
if (pInfo->changeListeners.size() != 0) |
|
ds@580
|
709 |
{ |
|
dvander@1770
|
710 |
for (List<IConVarChangeListener *>::iterator i = pInfo->changeListeners.begin(); |
|
dvander@1770
|
711 |
i != pInfo->changeListeners.end(); |
|
dvander@1770
|
712 |
i++) |
|
dvander@1770
|
713 |
{ |
|
ds@2400
|
714 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
dvander@1770
|
715 |
(*i)->OnConVarChanged(pConVar, oldValue, flOldValue); |
|
faluco@1541
|
716 |
#else |
|
dvander@1770
|
717 |
(*i)->OnConVarChanged(pConVar, oldValue, atof(oldValue)); |
|
faluco@1541
|
718 |
#endif |
|
dvander@1770
|
719 |
} |
|
ds@580
|
720 |
} |
|
ds@580
|
721 |
|
|
dvander@1770
|
722 |
if (pForward != NULL) |
|
dvander@1770
|
723 |
{ |
|
dvander@2890
|
724 |
ConVarReentrancyGuard guard(pConVar); |
|
dvander@2890
|
725 |
|
|
dvander@1770
|
726 |
/* Now call forwards in plugins that have hooked this */ |
|
dvander@1770
|
727 |
pForward->PushCell(pInfo->handle); |
|
dvander@1770
|
728 |
pForward->PushString(oldValue); |
|
dvander@1770
|
729 |
pForward->PushString(pConVar->GetString()); |
|
dvander@1770
|
730 |
pForward->Execute(NULL); |
|
dvander@1770
|
731 |
} |
|
ds@580
|
732 |
} |
|
ds@627
|
733 |
|
|
dvander@1581
|
734 |
bool ConVarManager::IsQueryingSupported() |
|
dvander@1581
|
735 |
{ |
|
dvander@1581
|
736 |
return (m_bIsDLLQueryHooked || m_bIsVSPQueryHooked); |
|
dvander@1581
|
737 |
} |
|
dvander@1581
|
738 |
|
|
ds@2583
|
739 |
#if SOURCE_ENGINE != SE_DARKMESSIAH |
|
skamonkey@3942
|
740 |
#if SOURCE_ENGINE == SE_DOTA |
|
skamonkey@3942
|
741 |
void ConVarManager::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, CEntityIndex player, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue) |
|
skamonkey@3942
|
742 |
#else |
|
ds@696
|
743 |
void ConVarManager::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue) |
|
skamonkey@3942
|
744 |
#endif // SE_DOTA |
|
ds@696
|
745 |
{ |
|
ds@696
|
746 |
IPluginFunction *pCallback = NULL; |
|
ds@696
|
747 |
cell_t value = 0; |
|
ds@696
|
748 |
List<ConVarQuery>::iterator iter; |
|
ds@696
|
749 |
|
|
ds@696
|
750 |
for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end(); iter++) |
|
ds@696
|
751 |
{ |
|
ds@696
|
752 |
ConVarQuery &query = (*iter); |
|
ds@696
|
753 |
if (query.cookie == cookie) |
|
ds@696
|
754 |
{ |
|
ds@696
|
755 |
pCallback = query.pCallback; |
|
ds@696
|
756 |
value = query.value; |
|
ds@696
|
757 |
break; |
|
ds@696
|
758 |
} |
|
ds@696
|
759 |
} |
|
ds@696
|
760 |
|
|
ds@696
|
761 |
if (pCallback) |
|
ds@696
|
762 |
{ |
|
ds@696
|
763 |
cell_t ret; |
|
ds@696
|
764 |
|
|
ds@696
|
765 |
pCallback->PushCell(cookie); |
|
skamonkey@3942
|
766 |
#if SOURCE_ENGINE == SE_DOTA |
|
skamonkey@3942
|
767 |
pCallback->PushCell(player.Get()); |
|
skamonkey@3942
|
768 |
#else |
|
ds@2400
|
769 |
pCallback->PushCell(IndexOfEdict(pPlayer)); |
|
skamonkey@3942
|
770 |
#endif |
|
ds@696
|
771 |
pCallback->PushCell(result); |
|
ds@696
|
772 |
pCallback->PushString(cvarName); |
|
ds@696
|
773 |
|
|
ds@696
|
774 |
if (result == eQueryCvarValueStatus_ValueIntact) |
|
ds@696
|
775 |
{ |
|
ds@696
|
776 |
pCallback->PushString(cvarValue); |
|
dvander@1581
|
777 |
} |
|
dvander@1581
|
778 |
else |
|
dvander@1581
|
779 |
{ |
|
ds@696
|
780 |
pCallback->PushString("\0"); |
|
ds@696
|
781 |
} |
|
ds@696
|
782 |
|
|
ds@696
|
783 |
pCallback->PushCell(value); |
|
ds@696
|
784 |
pCallback->Execute(&ret); |
|
ds@696
|
785 |
|
|
ds@696
|
786 |
m_ConVarQueries.erase(iter); |
|
ds@696
|
787 |
} |
|
ds@696
|
788 |
} |
|
ds@2583
|
789 |
#endif |
|
ds@696
|
790 |
|
|
dvander@1582
|
791 |
HandleError ConVarManager::ReadConVarHandle(Handle_t hndl, ConVar **pVar) |
|
dvander@1582
|
792 |
{ |
|
dvander@1582
|
793 |
ConVarInfo *pInfo; |
|
dvander@1582
|
794 |
HandleError error; |
|
dvander@1582
|
795 |
|
|
dvander@3872
|
796 |
if ((error = handlesys->ReadHandle(hndl, m_ConVarType, NULL, (void **)&pInfo)) != HandleError_None) |
|
dvander@1582
|
797 |
{ |
|
dvander@1582
|
798 |
return error; |
|
dvander@1582
|
799 |
} |
|
dvander@1582
|
800 |
|
|
dvander@1582
|
801 |
if (pVar) |
|
dvander@1582
|
802 |
{ |
|
dvander@1582
|
803 |
*pVar = pInfo->pVar; |
|
dvander@1582
|
804 |
} |
|
dvander@1582
|
805 |
|
|
dvander@1582
|
806 |
return error; |
|
dvander@1582
|
807 |
} |