|
ds@580
|
1 |
/** |
|
ds@653
|
2 |
* vim: set ts=4 : |
|
ds@653
|
3 |
* =============================================================== |
|
ds@653
|
4 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
ds@653
|
5 |
* =============================================================== |
|
ds@653
|
6 |
* |
|
ds@653
|
7 |
* This file is not open source and may not be copied without explicit |
|
ds@653
|
8 |
* written permission of AlliedModders LLC. This file may not be redistributed |
|
ds@653
|
9 |
* in whole or significant part. |
|
ds@653
|
10 |
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php |
|
ds@653
|
11 |
* |
|
ds@653
|
12 |
* Version: $Id$ |
|
ds@653
|
13 |
*/ |
|
ds@580
|
14 |
|
|
ds@580
|
15 |
#include "ConVarManager.h" |
|
ds@696
|
16 |
#include "HalfLife2.h" |
|
ds@580
|
17 |
#include "PluginSys.h" |
|
ds@580
|
18 |
#include "ForwardSys.h" |
|
ds@580
|
19 |
#include "HandleSys.h" |
|
ds@580
|
20 |
#include "sm_srvcmds.h" |
|
ds@580
|
21 |
#include "sm_stringutil.h" |
|
ds@580
|
22 |
#include <sh_vector.h> |
|
ds@580
|
23 |
|
|
ds@580
|
24 |
ConVarManager g_ConVarManager; |
|
ds@580
|
25 |
|
|
ds@696
|
26 |
SH_DECL_HOOK5_void(IServerGameDLL, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); |
|
ds@696
|
27 |
SH_DECL_HOOK5_void(IServerPluginCallbacks, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); |
|
ds@696
|
28 |
|
|
ds@582
|
29 |
const ParamType CONVARCHANGE_PARAMS[] = {Param_Cell, Param_String, Param_String}; |
|
ds@582
|
30 |
typedef List<const ConVar *> ConVarList; |
|
ds@582
|
31 |
|
|
ds@696
|
32 |
ConVarManager::ConVarManager() : m_ConVarType(0), m_VSPIface(NULL), m_CanQueryConVars(false) |
|
ds@580
|
33 |
{ |
|
ds@582
|
34 |
/* Create a convar lookup trie */ |
|
ds@580
|
35 |
m_ConVarCache = sm_trie_create(); |
|
ds@580
|
36 |
} |
|
ds@580
|
37 |
|
|
ds@580
|
38 |
ConVarManager::~ConVarManager() |
|
ds@580
|
39 |
{ |
|
ds@580
|
40 |
List<ConVarInfo *>::iterator iter; |
|
ds@580
|
41 |
|
|
ds@582
|
42 |
/* Destroy our convar lookup trie */ |
|
ds@580
|
43 |
sm_trie_destroy(m_ConVarCache); |
|
ds@580
|
44 |
|
|
ds@582
|
45 |
/* Destroy all the ConVarInfo structures */ |
|
ds@580
|
46 |
for (iter = m_ConVars.begin(); iter != m_ConVars.end(); iter++) |
|
ds@580
|
47 |
{ |
|
ds@580
|
48 |
delete (*iter); |
|
ds@580
|
49 |
} |
|
ds@580
|
50 |
|
|
ds@580
|
51 |
m_ConVars.clear(); |
|
ds@580
|
52 |
} |
|
ds@580
|
53 |
|
|
ds@580
|
54 |
void ConVarManager::OnSourceModAllInitialized() |
|
ds@580
|
55 |
{ |
|
ds@696
|
56 |
/* Only valid with ServerGameDLL006 or greater */ |
|
ds@696
|
57 |
if (g_SMAPI->GetGameDLLVersion() >= 6) |
|
ds@696
|
58 |
{ |
|
ds@696
|
59 |
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false); |
|
ds@696
|
60 |
m_CanQueryConVars = true; |
|
ds@696
|
61 |
} |
|
ds@696
|
62 |
|
|
ds@580
|
63 |
HandleAccess sec; |
|
ds@580
|
64 |
|
|
ds@582
|
65 |
/* Set up access rights for the 'ConVar' handle type */ |
|
ds@580
|
66 |
sec.access[HandleAccess_Read] = 0; |
|
ds@580
|
67 |
sec.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; |
|
ds@580
|
68 |
sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; |
|
ds@580
|
69 |
|
|
ds@582
|
70 |
/* Create the 'ConVar' handle type */ |
|
ds@580
|
71 |
m_ConVarType = g_HandleSys.CreateType("ConVar", this, 0, NULL, &sec, g_pCoreIdent, NULL); |
|
ds@580
|
72 |
|
|
ds@582
|
73 |
/* Add the 'convars' option to the 'sm' console command */ |
|
ds@990
|
74 |
g_RootMenu.AddRootConsoleCommand("cvars", "View convars created by a plugin", this); |
|
ds@580
|
75 |
} |
|
ds@580
|
76 |
|
|
ds@580
|
77 |
void ConVarManager::OnSourceModShutdown() |
|
ds@580
|
78 |
{ |
|
ds@696
|
79 |
if (m_CanQueryConVars) |
|
ds@696
|
80 |
{ |
|
ds@696
|
81 |
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false); |
|
ds@696
|
82 |
SH_REMOVE_HOOK_MEMFUNC(IServerPluginCallbacks, OnQueryCvarValueFinished, m_VSPIface, this, &ConVarManager::OnQueryCvarValueFinished, false); |
|
ds@696
|
83 |
} |
|
ds@696
|
84 |
|
|
ds@580
|
85 |
IChangeableForward *fwd; |
|
ds@580
|
86 |
List<ConVarInfo *>::iterator i; |
|
ds@580
|
87 |
|
|
ds@582
|
88 |
/* Iterate list of ConVarInfo structures */ |
|
ds@580
|
89 |
for (i = m_ConVars.begin(); i != m_ConVars.end(); i++) |
|
ds@580
|
90 |
{ |
|
ds@696
|
91 |
fwd = (*i)->pChangeForward; |
|
ds@580
|
92 |
|
|
ds@582
|
93 |
/* Free any convar-change forwards that still exist */ |
|
ds@580
|
94 |
if (fwd) |
|
ds@580
|
95 |
{ |
|
ds@580
|
96 |
g_Forwards.ReleaseForward(fwd); |
|
ds@580
|
97 |
} |
|
ds@580
|
98 |
} |
|
ds@580
|
99 |
|
|
ds@582
|
100 |
/* Remove the 'convars' option from the 'sm' console command */ |
|
ds@990
|
101 |
g_RootMenu.RemoveRootConsoleCommand("cvars", this); |
|
ds@580
|
102 |
|
|
ds@582
|
103 |
/* Remove the 'ConVar' handle type */ |
|
ds@580
|
104 |
g_HandleSys.RemoveType(m_ConVarType, g_pCoreIdent); |
|
ds@580
|
105 |
} |
|
ds@580
|
106 |
|
|
ds@696
|
107 |
void ConVarManager::OnSourceModVSPReceived(IServerPluginCallbacks *iface) |
|
ds@696
|
108 |
{ |
|
ds@696
|
109 |
/* This will be called after OnSourceModAllInitialized(), so... |
|
ds@696
|
110 |
* |
|
ds@696
|
111 |
* If we haven't been able to hook the IServerGameDLL version at this point, |
|
ds@696
|
112 |
* then use hook IServerPluginCallbacks version from the engine. |
|
ds@696
|
113 |
*/ |
|
ds@696
|
114 |
|
|
ds@696
|
115 |
/* The Ship currently only supports ServerPluginCallbacks001, but we need 002 */ |
|
ds@696
|
116 |
if (g_IsOriginalEngine) |
|
ds@696
|
117 |
{ |
|
ds@696
|
118 |
return; |
|
ds@696
|
119 |
} |
|
ds@696
|
120 |
|
|
ds@696
|
121 |
if (!m_CanQueryConVars) |
|
ds@696
|
122 |
{ |
|
ds@696
|
123 |
m_VSPIface = iface; |
|
ds@696
|
124 |
|
|
ds@696
|
125 |
SH_ADD_HOOK_MEMFUNC(IServerPluginCallbacks, OnQueryCvarValueFinished, iface, this, &ConVarManager::OnQueryCvarValueFinished, false); |
|
ds@696
|
126 |
m_CanQueryConVars = true; |
|
ds@696
|
127 |
} |
|
ds@696
|
128 |
} |
|
ds@696
|
129 |
|
|
ds@582
|
130 |
void ConVarManager::OnPluginUnloaded(IPlugin *plugin) |
|
ds@580
|
131 |
{ |
|
ds@582
|
132 |
ConVarList *pConVarList; |
|
ds@580
|
133 |
|
|
ds@582
|
134 |
/* If plugin has a convar list, free its memory */ |
|
ds@582
|
135 |
if (plugin->GetProperty("ConVarList", (void **)&pConVarList, true)) |
|
ds@580
|
136 |
{ |
|
ds@582
|
137 |
delete pConVarList; |
|
ds@580
|
138 |
} |
|
ds@580
|
139 |
} |
|
ds@580
|
140 |
|
|
ds@580
|
141 |
void ConVarManager::OnHandleDestroy(HandleType_t type, void *object) |
|
ds@580
|
142 |
{ |
|
ds@580
|
143 |
ConVarInfo *info; |
|
ds@580
|
144 |
ConVar *pConVar = static_cast<ConVar *>(object); |
|
ds@580
|
145 |
|
|
ds@582
|
146 |
/* Find convar in lookup trie */ |
|
ds@580
|
147 |
sm_trie_retrieve(m_ConVarCache, pConVar->GetName(), reinterpret_cast<void **>(&info)); |
|
ds@580
|
148 |
|
|
ds@582
|
149 |
/* If convar was created by SourceMod plugin... */ |
|
ds@580
|
150 |
if (info->sourceMod) |
|
ds@580
|
151 |
{ |
|
ds@582
|
152 |
/* Delete string allocations */ |
|
ds@580
|
153 |
delete [] pConVar->GetName(); |
|
ds@580
|
154 |
delete [] pConVar->GetDefault(); |
|
ds@580
|
155 |
delete [] pConVar->GetHelpText(); |
|
ds@580
|
156 |
|
|
ds@582
|
157 |
/* Then unlink it from SourceMM */ |
|
ds@580
|
158 |
g_SMAPI->UnregisterConCmdBase(g_PLAPI, pConVar); |
|
ds@580
|
159 |
} |
|
ds@580
|
160 |
} |
|
ds@580
|
161 |
|
|
ds@580
|
162 |
void ConVarManager::OnRootConsoleCommand(const char *command, unsigned int argcount) |
|
ds@580
|
163 |
{ |
|
ds@580
|
164 |
if (argcount >= 3) |
|
ds@580
|
165 |
{ |
|
ds@582
|
166 |
/* Get plugin index that was passed */ |
|
ds@582
|
167 |
int id = atoi(g_RootMenu.GetArgument(2)); |
|
ds@580
|
168 |
|
|
ds@582
|
169 |
/* Get plugin object */ |
|
ds@582
|
170 |
CPlugin *plugin = g_PluginSys.GetPluginByOrder(id); |
|
ds@582
|
171 |
|
|
ds@582
|
172 |
if (!plugin) |
|
ds@580
|
173 |
{ |
|
ds@582
|
174 |
g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id); |
|
ds@580
|
175 |
return; |
|
ds@580
|
176 |
} |
|
ds@580
|
177 |
|
|
ds@582
|
178 |
/* Get plugin name */ |
|
ds@582
|
179 |
const sm_plugininfo_t *plinfo = plugin->GetPublicInfo(); |
|
ds@582
|
180 |
const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : plugin->GetFilename(); |
|
ds@580
|
181 |
|
|
ds@582
|
182 |
ConVarList *pConVarList; |
|
ds@582
|
183 |
ConVarList::iterator iter; |
|
ds@580
|
184 |
|
|
ds@582
|
185 |
/* If no convar list... */ |
|
ds@582
|
186 |
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) |
|
ds@580
|
187 |
{ |
|
ds@582
|
188 |
g_RootMenu.ConsolePrint("[SM] No convars found for: %s", plname); |
|
ds@580
|
189 |
return; |
|
ds@580
|
190 |
} |
|
ds@580
|
191 |
|
|
ds@582
|
192 |
g_RootMenu.ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname); |
|
ds@582
|
193 |
g_RootMenu.ConsolePrint(" %-32.31s %s", "[Name]", "[Value]"); |
|
ds@580
|
194 |
|
|
ds@582
|
195 |
/* Iterate convar list and display each one */ |
|
ds@582
|
196 |
for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) |
|
ds@580
|
197 |
{ |
|
ds@582
|
198 |
const ConVar *pConVar = (*iter); |
|
ds@582
|
199 |
g_RootMenu.ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString()); |
|
ds@580
|
200 |
} |
|
ds@580
|
201 |
|
|
ds@580
|
202 |
return; |
|
ds@580
|
203 |
} |
|
ds@580
|
204 |
|
|
ds@582
|
205 |
/* Display usage of subcommand */ |
|
ds@580
|
206 |
g_RootMenu.ConsolePrint("[SM] Usage: sm convars <plugin #>"); |
|
ds@580
|
207 |
} |
|
ds@580
|
208 |
|
|
ds@582
|
209 |
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
|
210 |
{ |
|
ds@580
|
211 |
ConVar *pConVar = NULL; |
|
ds@582
|
212 |
ConVarInfo *pInfo = NULL; |
|
ds@580
|
213 |
Handle_t hndl = 0; |
|
ds@580
|
214 |
|
|
ds@582
|
215 |
/* Find out if the convar exists already */ |
|
ds@580
|
216 |
pConVar = icvar->FindVar(name); |
|
ds@580
|
217 |
|
|
ds@582
|
218 |
/* If the convar already exists... */ |
|
ds@582
|
219 |
if (pConVar) |
|
ds@580
|
220 |
{ |
|
ds@759
|
221 |
/* Add convar to plugin's list */ |
|
ds@759
|
222 |
AddConVarToPluginList(pContext, pConVar); |
|
ds@759
|
223 |
|
|
ds@582
|
224 |
/* First find out if we already have a handle to it */ |
|
ds@582
|
225 |
if (sm_trie_retrieve(m_ConVarCache, name, (void **)&pInfo)) |
|
ds@580
|
226 |
{ |
|
ds@582
|
227 |
return pInfo->handle; |
|
ds@580
|
228 |
} else { |
|
ds@582
|
229 |
/* If we don't, then create a new handle from the convar */ |
|
ds@580
|
230 |
hndl = g_HandleSys.CreateHandle(m_ConVarType, pConVar, NULL, g_pCoreIdent, NULL); |
|
ds@580
|
231 |
|
|
ds@582
|
232 |
/* Create and initialize ConVarInfo structure */ |
|
ds@582
|
233 |
pInfo = new ConVarInfo(); |
|
ds@582
|
234 |
pInfo->handle = hndl; |
|
ds@582
|
235 |
pInfo->sourceMod = false; |
|
ds@696
|
236 |
pInfo->pChangeForward = NULL; |
|
ds@582
|
237 |
pInfo->origCallback = pConVar->GetCallback(); |
|
ds@580
|
238 |
|
|
ds@582
|
239 |
/* Insert struct into caches */ |
|
ds@582
|
240 |
m_ConVars.push_back(pInfo); |
|
ds@582
|
241 |
sm_trie_insert(m_ConVarCache, name, pInfo); |
|
ds@580
|
242 |
|
|
ds@580
|
243 |
return hndl; |
|
ds@580
|
244 |
} |
|
ds@580
|
245 |
} |
|
ds@580
|
246 |
|
|
ds@696
|
247 |
/* To prevent creating a convar that has the same name as a console command... ugh */ |
|
ds@580
|
248 |
ConCommandBase *pBase = icvar->GetCommands(); |
|
ds@580
|
249 |
|
|
ds@580
|
250 |
while (pBase) |
|
ds@580
|
251 |
{ |
|
ds@582
|
252 |
if (pBase->IsCommand() && strcmp(pBase->GetName(), name) == 0) |
|
ds@580
|
253 |
{ |
|
ds@582
|
254 |
return BAD_HANDLE; |
|
ds@580
|
255 |
} |
|
ds@580
|
256 |
|
|
ds@580
|
257 |
pBase = const_cast<ConCommandBase *>(pBase->GetNext()); |
|
ds@580
|
258 |
} |
|
ds@580
|
259 |
|
|
ds@582
|
260 |
/* Since an existing convar (or concmd with the same name) was not found , now we can finally create it */ |
|
ds@582
|
261 |
pConVar = new ConVar(sm_strdup(name), sm_strdup(defaultVal), flags, sm_strdup(description), hasMin, min, hasMax, max); |
|
ds@580
|
262 |
|
|
ds@582
|
263 |
/* Add convar to plugin's list */ |
|
ds@582
|
264 |
AddConVarToPluginList(pContext, pConVar); |
|
ds@580
|
265 |
|
|
ds@582
|
266 |
/* Create a handle from the new convar */ |
|
ds@580
|
267 |
hndl = g_HandleSys.CreateHandle(m_ConVarType, pConVar, NULL, g_pCoreIdent, NULL); |
|
ds@580
|
268 |
|
|
ds@582
|
269 |
/* Create and initialize ConVarInfo structure */ |
|
ds@582
|
270 |
pInfo = new ConVarInfo(); |
|
ds@582
|
271 |
pInfo->handle = hndl; |
|
ds@582
|
272 |
pInfo->sourceMod = true; |
|
ds@696
|
273 |
pInfo->pChangeForward = NULL; |
|
ds@582
|
274 |
pInfo->origCallback = NULL; |
|
ds@580
|
275 |
|
|
ds@582
|
276 |
/* Insert struct into caches */ |
|
ds@582
|
277 |
m_ConVars.push_back(pInfo); |
|
ds@582
|
278 |
sm_trie_insert(m_ConVarCache, name, pInfo); |
|
ds@580
|
279 |
|
|
ds@580
|
280 |
return hndl; |
|
ds@580
|
281 |
} |
|
ds@580
|
282 |
|
|
ds@580
|
283 |
Handle_t ConVarManager::FindConVar(const char *name) |
|
ds@580
|
284 |
{ |
|
ds@580
|
285 |
ConVar *pConVar = NULL; |
|
ds@582
|
286 |
ConVarInfo *pInfo; |
|
ds@582
|
287 |
Handle_t hndl; |
|
ds@580
|
288 |
|
|
ds@582
|
289 |
/* Search for convar */ |
|
ds@580
|
290 |
pConVar = icvar->FindVar(name); |
|
ds@580
|
291 |
|
|
ds@582
|
292 |
/* If it doesn't exist, then return an invalid handle */ |
|
ds@582
|
293 |
if (!pConVar) |
|
ds@580
|
294 |
{ |
|
ds@580
|
295 |
return BAD_HANDLE; |
|
ds@580
|
296 |
} |
|
ds@580
|
297 |
|
|
ds@582
|
298 |
/* At this point, the convar exists. So, find out if we already have a handle */ |
|
ds@582
|
299 |
if (sm_trie_retrieve(m_ConVarCache, name, (void **)&pInfo)) |
|
ds@580
|
300 |
{ |
|
ds@582
|
301 |
return pInfo->handle; |
|
ds@580
|
302 |
} |
|
ds@580
|
303 |
|
|
ds@582
|
304 |
/* If we don't have a handle, then create a new one */ |
|
ds@580
|
305 |
hndl = g_HandleSys.CreateHandle(m_ConVarType, pConVar, NULL, g_pCoreIdent, NULL); |
|
ds@580
|
306 |
|
|
ds@729
|
307 |
/* Create and initialize ConVarInfo structure */ |
|
ds@582
|
308 |
pInfo = new ConVarInfo(); |
|
ds@582
|
309 |
pInfo->handle = hndl; |
|
ds@582
|
310 |
pInfo->sourceMod = false; |
|
ds@696
|
311 |
pInfo->pChangeForward = NULL; |
|
ds@582
|
312 |
pInfo->origCallback = pConVar->GetCallback(); |
|
ds@580
|
313 |
|
|
ds@582
|
314 |
/* Insert struct into our caches */ |
|
ds@582
|
315 |
m_ConVars.push_back(pInfo); |
|
ds@582
|
316 |
sm_trie_insert(m_ConVarCache, name, pInfo); |
|
ds@580
|
317 |
|
|
ds@580
|
318 |
return hndl; |
|
ds@580
|
319 |
} |
|
ds@580
|
320 |
|
|
ds@582
|
321 |
void ConVarManager::HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction) |
|
ds@580
|
322 |
{ |
|
ds@582
|
323 |
ConVarInfo *pInfo; |
|
ds@582
|
324 |
IChangeableForward *pForward; |
|
ds@580
|
325 |
|
|
ds@582
|
326 |
/* Find the convar in the lookup trie */ |
|
ds@582
|
327 |
if (sm_trie_retrieve(m_ConVarCache, pConVar->GetName(), (void **)&pInfo)) |
|
ds@580
|
328 |
{ |
|
ds@582
|
329 |
/* Get the forward */ |
|
ds@696
|
330 |
pForward = pInfo->pChangeForward; |
|
ds@580
|
331 |
|
|
ds@582
|
332 |
/* If forward does not exist, create it */ |
|
ds@582
|
333 |
if (!pForward) |
|
ds@582
|
334 |
{ |
|
ds@582
|
335 |
pForward = g_Forwards.CreateForwardEx(NULL, ET_Ignore, 3, CONVARCHANGE_PARAMS); |
|
ds@696
|
336 |
pInfo->pChangeForward = pForward; |
|
ds@580
|
337 |
|
|
ds@582
|
338 |
/* Install our own callback */ |
|
ds@580
|
339 |
pConVar->InstallChangeCallback(OnConVarChanged); |
|
ds@580
|
340 |
} |
|
ds@582
|
341 |
|
|
ds@582
|
342 |
/* Add function to forward's list */ |
|
ds@582
|
343 |
pForward->AddFunction(pFunction); |
|
ds@580
|
344 |
} |
|
ds@580
|
345 |
} |
|
ds@580
|
346 |
|
|
ds@582
|
347 |
void ConVarManager::UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction) |
|
ds@580
|
348 |
{ |
|
ds@582
|
349 |
ConVarInfo *pInfo; |
|
ds@582
|
350 |
IChangeableForward *pForward; |
|
ds@582
|
351 |
IPluginContext *pContext = pFunction->GetParentContext(); |
|
ds@580
|
352 |
|
|
ds@582
|
353 |
/* Find the convar in the lookup trie */ |
|
ds@582
|
354 |
if (sm_trie_retrieve(m_ConVarCache, pConVar->GetName(), (void **)&pInfo)) |
|
ds@580
|
355 |
{ |
|
ds@582
|
356 |
/* Get the forward */ |
|
ds@696
|
357 |
pForward = pInfo->pChangeForward; |
|
ds@580
|
358 |
|
|
ds@582
|
359 |
/* If the forward doesn't exist, we can't unhook anything */ |
|
ds@582
|
360 |
if (!pForward) |
|
ds@580
|
361 |
{ |
|
ds@580
|
362 |
pContext->ThrowNativeError("Convar \"%s\" has no active hook", pConVar->GetName()); |
|
ds@580
|
363 |
return; |
|
ds@580
|
364 |
} |
|
ds@580
|
365 |
|
|
ds@582
|
366 |
/* Remove the function from the forward's list */ |
|
ds@582
|
367 |
if (!pForward->RemoveFunction(pFunction)) |
|
ds@580
|
368 |
{ |
|
ds@580
|
369 |
pContext->ThrowNativeError("Invalid hook callback specified for convar \"%s\"", pConVar->GetName()); |
|
ds@580
|
370 |
return; |
|
ds@580
|
371 |
} |
|
ds@580
|
372 |
|
|
ds@582
|
373 |
/* If the forward now has 0 functions in it... */ |
|
ds@582
|
374 |
if (pForward->GetFunctionCount() == 0) |
|
ds@580
|
375 |
{ |
|
ds@582
|
376 |
/* Free this forward */ |
|
ds@582
|
377 |
g_Forwards.ReleaseForward(pForward); |
|
ds@696
|
378 |
pInfo->pChangeForward = NULL; |
|
ds@582
|
379 |
|
|
ds@582
|
380 |
/* Put back the original convar callback */ |
|
ds@582
|
381 |
pConVar->InstallChangeCallback(pInfo->origCallback); |
|
ds@582
|
382 |
} |
|
ds@582
|
383 |
} |
|
ds@582
|
384 |
} |
|
ds@582
|
385 |
|
|
ds@696
|
386 |
QueryCvarCookie_t ConVarManager::QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback, Handle_t hndl) |
|
ds@696
|
387 |
{ |
|
ds@696
|
388 |
QueryCvarCookie_t cookie; |
|
ds@696
|
389 |
|
|
ds@696
|
390 |
/* Call StartQueryCvarValue() in either the IVEngineServer or IServerPluginHelpers depending on situation */ |
|
ds@696
|
391 |
if (!m_VSPIface) |
|
ds@696
|
392 |
{ |
|
ds@696
|
393 |
cookie = engine->StartQueryCvarValue(pPlayer, name); |
|
ds@696
|
394 |
} else { |
|
ds@696
|
395 |
cookie = serverpluginhelpers->StartQueryCvarValue(pPlayer, name); |
|
ds@696
|
396 |
} |
|
ds@696
|
397 |
|
|
ds@696
|
398 |
ConVarQuery query = {cookie, pCallback, hndl}; |
|
ds@696
|
399 |
m_ConVarQueries.push_back(query); |
|
ds@696
|
400 |
|
|
ds@696
|
401 |
return cookie; |
|
ds@696
|
402 |
} |
|
ds@696
|
403 |
|
|
ds@582
|
404 |
void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar) |
|
ds@582
|
405 |
{ |
|
ds@582
|
406 |
ConVarList *pConVarList; |
|
ds@582
|
407 |
ConVarList::iterator iter; |
|
ds@582
|
408 |
bool inserted = false; |
|
ds@582
|
409 |
const char *orig = pConVar->GetName(); |
|
ds@582
|
410 |
|
|
ds@582
|
411 |
IPlugin *plugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); |
|
ds@580
|
412 |
|
|
ds@582
|
413 |
/* Check plugin for an existing convar list */ |
|
ds@582
|
414 |
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) |
|
ds@582
|
415 |
{ |
|
ds@582
|
416 |
pConVarList = new ConVarList(); |
|
ds@582
|
417 |
plugin->SetProperty("ConVarList", pConVarList); |
|
ds@867
|
418 |
} else if (pConVarList->find(pConVar) != pConVarList->end()) { |
|
ds@867
|
419 |
/* If convar is already in list, then don't add it */ |
|
ds@867
|
420 |
return; |
|
ds@582
|
421 |
} |
|
ds@582
|
422 |
|
|
ds@582
|
423 |
/* Insert convar into list which is sorted alphabetically */ |
|
ds@582
|
424 |
for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) |
|
ds@582
|
425 |
{ |
|
ds@582
|
426 |
if (strcmp(orig, (*iter)->GetName()) < 0) |
|
ds@582
|
427 |
{ |
|
ds@582
|
428 |
pConVarList->insert(iter, pConVar); |
|
ds@582
|
429 |
inserted = true; |
|
ds@582
|
430 |
break; |
|
ds@580
|
431 |
} |
|
ds@580
|
432 |
} |
|
ds@582
|
433 |
|
|
ds@582
|
434 |
if (!inserted) |
|
ds@582
|
435 |
{ |
|
ds@582
|
436 |
pConVarList->push_back(pConVar); |
|
ds@582
|
437 |
} |
|
ds@580
|
438 |
} |
|
ds@580
|
439 |
|
|
ds@580
|
440 |
void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue) |
|
ds@580
|
441 |
{ |
|
ds@582
|
442 |
/* If the values are the same, exit early in order to not trigger callbacks */ |
|
ds@580
|
443 |
if (strcmp(pConVar->GetString(), oldValue) == 0) |
|
ds@580
|
444 |
{ |
|
ds@580
|
445 |
return; |
|
ds@580
|
446 |
} |
|
ds@580
|
447 |
|
|
ds@582
|
448 |
Trie *pCache = g_ConVarManager.GetConVarCache(); |
|
ds@582
|
449 |
ConVarInfo *pInfo; |
|
ds@580
|
450 |
|
|
ds@582
|
451 |
/* Find the convar in the lookup trie */ |
|
ds@582
|
452 |
sm_trie_retrieve(pCache, pConVar->GetName(), (void **)&pInfo); |
|
ds@580
|
453 |
|
|
ds@582
|
454 |
FnChangeCallback origCallback = pInfo->origCallback; |
|
ds@696
|
455 |
IChangeableForward *pForward = pInfo->pChangeForward; |
|
ds@580
|
456 |
|
|
ds@582
|
457 |
/* If there was a change callback installed previously, call it */ |
|
ds@580
|
458 |
if (origCallback) |
|
ds@580
|
459 |
{ |
|
ds@580
|
460 |
origCallback(pConVar, oldValue); |
|
ds@580
|
461 |
} |
|
ds@580
|
462 |
|
|
ds@582
|
463 |
/* Now call forwards in plugins that have hooked this */ |
|
ds@582
|
464 |
pForward->PushCell(pInfo->handle); |
|
ds@582
|
465 |
pForward->PushString(oldValue); |
|
ds@582
|
466 |
pForward->PushString(pConVar->GetString()); |
|
ds@582
|
467 |
pForward->Execute(NULL); |
|
ds@580
|
468 |
} |
|
ds@627
|
469 |
|
|
ds@696
|
470 |
void ConVarManager::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue) |
|
ds@696
|
471 |
{ |
|
ds@696
|
472 |
IPluginFunction *pCallback = NULL; |
|
ds@696
|
473 |
cell_t value = 0; |
|
ds@696
|
474 |
List<ConVarQuery>::iterator iter; |
|
ds@696
|
475 |
|
|
ds@696
|
476 |
for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end(); iter++) |
|
ds@696
|
477 |
{ |
|
ds@696
|
478 |
ConVarQuery &query = (*iter); |
|
ds@696
|
479 |
|
|
ds@696
|
480 |
if (query.cookie == cookie) |
|
ds@696
|
481 |
{ |
|
ds@696
|
482 |
pCallback = query.pCallback; |
|
ds@696
|
483 |
value = query.value; |
|
ds@696
|
484 |
|
|
ds@696
|
485 |
break; |
|
ds@696
|
486 |
} |
|
ds@696
|
487 |
} |
|
ds@696
|
488 |
|
|
ds@696
|
489 |
if (pCallback) |
|
ds@696
|
490 |
{ |
|
ds@696
|
491 |
cell_t ret; |
|
ds@696
|
492 |
|
|
ds@696
|
493 |
pCallback->PushCell(cookie); |
|
ds@696
|
494 |
pCallback->PushCell(engine->IndexOfEdict(pPlayer)); |
|
ds@696
|
495 |
pCallback->PushCell(result); |
|
ds@696
|
496 |
pCallback->PushString(cvarName); |
|
ds@696
|
497 |
|
|
ds@696
|
498 |
if (result == eQueryCvarValueStatus_ValueIntact) |
|
ds@696
|
499 |
{ |
|
ds@696
|
500 |
pCallback->PushString(cvarValue); |
|
ds@696
|
501 |
} else { |
|
ds@696
|
502 |
pCallback->PushString("\0"); |
|
ds@696
|
503 |
} |
|
ds@696
|
504 |
|
|
ds@696
|
505 |
pCallback->PushCell(value); |
|
ds@696
|
506 |
pCallback->Execute(&ret); |
|
ds@696
|
507 |
|
|
ds@696
|
508 |
m_ConVarQueries.erase(iter); |
|
ds@696
|
509 |
} |
|
ds@696
|
510 |
} |
|
ds@696
|
511 |
|
|
ds@696
|
512 |
|
|
ds@627
|
513 |
static int s_YamagramState = 0; |
|
ds@627
|
514 |
|
|
ds@627
|
515 |
void _YamagramPrinterTwoPointOhOh(int yamagram) |
|
ds@627
|
516 |
{ |
|
ds@627
|
517 |
switch (yamagram) |
|
ds@627
|
518 |
{ |
|
ds@627
|
519 |
case 0: |
|
ds@627
|
520 |
g_RootMenu.ConsolePrint("Answer the following questions correctly and Gaben may not eat you after all."); |
|
ds@627
|
521 |
g_RootMenu.ConsolePrint("You will be given one hint in the form of my patented yamagrams."); |
|
ds@627
|
522 |
g_RootMenu.ConsolePrint("Type sm_nana to see the last question."); |
|
ds@627
|
523 |
g_RootMenu.ConsolePrint("Type sm_nana <answer> to attempt an answer of the question."); |
|
ds@627
|
524 |
g_RootMenu.ConsolePrint("-------------------------------"); |
|
ds@627
|
525 |
_YamagramPrinterTwoPointOhOh(1); |
|
ds@627
|
526 |
return; |
|
ds@627
|
527 |
case 1: |
|
ds@627
|
528 |
g_RootMenu.ConsolePrint("Question Ichi (1)"); |
|
ds@627
|
529 |
g_RootMenu.ConsolePrint("One can turn into a cow by doing what action?"); |
|
ds@627
|
530 |
g_RootMenu.ConsolePrint("Hint: AGE SANS GRIT"); |
|
ds@627
|
531 |
break; |
|
ds@627
|
532 |
case 2: |
|
ds@627
|
533 |
g_RootMenu.ConsolePrint("Question Ni (2)"); |
|
ds@627
|
534 |
g_RootMenu.ConsolePrint("What kind of hat should you wear when using the Internet?"); |
|
ds@627
|
535 |
g_RootMenu.ConsolePrint("Hint: BRR MOOSE"); |
|
ds@627
|
536 |
break; |
|
ds@627
|
537 |
case 3: |
|
ds@627
|
538 |
g_RootMenu.ConsolePrint("Question San (3)"); |
|
ds@627
|
539 |
g_RootMenu.ConsolePrint("Who is the lead developer of SourceMod?"); |
|
ds@627
|
540 |
g_RootMenu.ConsolePrint("Hint: VEAL BANDANA DID RIP SOON"); |
|
ds@627
|
541 |
break; |
|
ds@627
|
542 |
case 4: |
|
ds@627
|
543 |
g_RootMenu.ConsolePrint("Question Yon (4)"); |
|
ds@627
|
544 |
g_RootMenu.ConsolePrint("A terrible translation of 'SVN Revision' to Japanese romaji might be ..."); |
|
ds@627
|
545 |
g_RootMenu.ConsolePrint("Hint: I TAKE IN AN AIR OK"); |
|
ds@627
|
546 |
break; |
|
ds@627
|
547 |
case 5: |
|
ds@627
|
548 |
g_RootMenu.ConsolePrint("Question Go (5)"); |
|
ds@627
|
549 |
g_RootMenu.ConsolePrint("What is a fundamental concept in the game of Go?"); |
|
ds@628
|
550 |
g_RootMenu.ConsolePrint("Hint: AD LADEN THIEF"); |
|
ds@627
|
551 |
break; |
|
ds@627
|
552 |
case 6: |
|
ds@627
|
553 |
g_RootMenu.ConsolePrint("Question Roku (6)"); |
|
ds@627
|
554 |
g_RootMenu.ConsolePrint("Why am I asking all these strange questions?"); |
|
ds@627
|
555 |
g_RootMenu.ConsolePrint("Hint: CHUBBY TITAN EATS EWE WAGE DATA"); |
|
ds@627
|
556 |
break; |
|
ds@627
|
557 |
case 7: |
|
ds@627
|
558 |
g_RootMenu.ConsolePrint("Question Nana (7)"); |
|
ds@627
|
559 |
g_RootMenu.ConsolePrint("What is my name?"); |
|
ds@627
|
560 |
g_RootMenu.ConsolePrint("Hint: AD MODE LAG US"); |
|
ds@627
|
561 |
break; |
|
ds@627
|
562 |
default: |
|
ds@627
|
563 |
break; |
|
ds@627
|
564 |
} |
|
ds@627
|
565 |
|
|
ds@627
|
566 |
s_YamagramState = yamagram; |
|
ds@627
|
567 |
} |
|
ds@627
|
568 |
|
|
ds@627
|
569 |
void _IntExt_CallYamagrams() |
|
ds@627
|
570 |
{ |
|
ds@627
|
571 |
bool correct = false; |
|
ds@627
|
572 |
const char *arg = engine->Cmd_Args(); |
|
ds@627
|
573 |
|
|
ds@627
|
574 |
if (!arg || arg[0] == '\0') |
|
ds@627
|
575 |
{ |
|
ds@627
|
576 |
_YamagramPrinterTwoPointOhOh(s_YamagramState); |
|
ds@627
|
577 |
return; |
|
ds@627
|
578 |
} |
|
ds@627
|
579 |
|
|
ds@627
|
580 |
switch (s_YamagramState) |
|
ds@627
|
581 |
{ |
|
ds@627
|
582 |
case 1: |
|
ds@627
|
583 |
correct = !strcasecmp(arg, "eating grass"); |
|
ds@627
|
584 |
break; |
|
ds@627
|
585 |
case 2: |
|
ds@627
|
586 |
correct = !strcasecmp(arg, "sombrero"); |
|
ds@627
|
587 |
break; |
|
ds@627
|
588 |
case 3: |
|
ds@627
|
589 |
correct = !strcasecmp(arg, "david bailopan anderson"); |
|
ds@627
|
590 |
break; |
|
ds@627
|
591 |
case 4: |
|
ds@627
|
592 |
correct = !strcasecmp(arg, "kaitei no kairan"); |
|
ds@627
|
593 |
break; |
|
ds@627
|
594 |
case 5: |
|
ds@628
|
595 |
correct = !strcasecmp(arg, "life and death"); |
|
ds@627
|
596 |
break; |
|
ds@627
|
597 |
case 6: |
|
ds@627
|
598 |
correct = !strcasecmp(arg, "because gabe wanted it that way"); |
|
ds@627
|
599 |
if (correct) |
|
ds@627
|
600 |
{ |
|
ds@627
|
601 |
g_RootMenu.ConsolePrint("Congratulations, you have answered 6 of my questions."); |
|
ds@627
|
602 |
g_RootMenu.ConsolePrint("However, I have one final question for you. It wouldn't be nana without it."); |
|
ds@627
|
603 |
g_RootMenu.ConsolePrint("-------------------------------"); |
|
ds@627
|
604 |
_YamagramPrinterTwoPointOhOh(7); |
|
ds@627
|
605 |
return; |
|
ds@627
|
606 |
} |
|
ds@627
|
607 |
break; |
|
ds@627
|
608 |
case 7: |
|
ds@627
|
609 |
correct = !strcasecmp(arg, "damaged soul"); |
|
ds@627
|
610 |
if (correct) |
|
ds@627
|
611 |
{ |
|
ds@627
|
612 |
g_RootMenu.ConsolePrint("You don't know how lucky you are to still be alive!"); |
|
ds@627
|
613 |
g_RootMenu.ConsolePrint("Congratulations. You have answered all 7 questions correctly."); |
|
ds@627
|
614 |
g_RootMenu.ConsolePrint("The SourceMod Dev Team will be at your door with anti-Gaben grenades"); |
|
ds@627
|
615 |
g_RootMenu.ConsolePrint("within seconds. You will also be provided with a rocket launcher,"); |
|
ds@627
|
616 |
g_RootMenu.ConsolePrint("just in case Alfred decides to strike you with a blitzkrieg in retaliation."); |
|
ds@627
|
617 |
|
|
ds@627
|
618 |
s_YamagramState = 0; |
|
ds@627
|
619 |
return; |
|
ds@627
|
620 |
} |
|
ds@627
|
621 |
break; |
|
ds@627
|
622 |
default: |
|
ds@627
|
623 |
break; |
|
ds@627
|
624 |
} |
|
ds@627
|
625 |
|
|
ds@627
|
626 |
if (s_YamagramState > 0) |
|
ds@627
|
627 |
{ |
|
ds@627
|
628 |
if (correct) |
|
ds@627
|
629 |
{ |
|
ds@627
|
630 |
g_RootMenu.ConsolePrint("Correct! You are one step closer to avoiding the deadly jaws of Gaben."); |
|
ds@627
|
631 |
g_RootMenu.ConsolePrint("-------------------------------"); |
|
ds@627
|
632 |
s_YamagramState++; |
|
ds@627
|
633 |
} else { |
|
ds@627
|
634 |
g_RootMenu.ConsolePrint("Wrong! You better be more careful. Gaben may be at your door at any minute."); |
|
ds@627
|
635 |
return; |
|
ds@627
|
636 |
} |
|
ds@627
|
637 |
} |
|
ds@627
|
638 |
|
|
ds@627
|
639 |
_YamagramPrinterTwoPointOhOh(s_YamagramState); |
|
ds@627
|
640 |
} |
|
ds@627
|
641 |
|
|
ds@627
|
642 |
void _IntExt_EnableYamagrams() |
|
ds@627
|
643 |
{ |
|
ds@627
|
644 |
static ConCommand *pCmd = NULL; |
|
ds@627
|
645 |
if (!pCmd) |
|
ds@627
|
646 |
{ |
|
ds@627
|
647 |
pCmd = new ConCommand("sm_nana", _IntExt_CallYamagrams, "Try these yamagrams!", FCVAR_GAMEDLL); |
|
ds@627
|
648 |
g_RootMenu.ConsolePrint("[SM] Warning: Gaben has been alerted of your actions. You may be eaten."); |
|
ds@627
|
649 |
} else { |
|
ds@627
|
650 |
g_RootMenu.ConsolePrint("[SM] Gaben has already been alerted of your actions..."); |
|
ds@627
|
651 |
} |
|
ds@627
|
652 |
} |
|
ds@627
|
653 |
|
|
ds@627
|
654 |
void _IntExt_OnHostnameChanged(ConVar *pConVar, char const *oldValue) |
|
ds@627
|
655 |
{ |
|
ds@627
|
656 |
if (strcmp(oldValue, "Good morning, DS-san.") == 0 |
|
ds@627
|
657 |
&& strcmp(pConVar->GetString(), "Good night, talking desk lamp.") == 0) |
|
ds@627
|
658 |
{ |
|
ds@627
|
659 |
_IntExt_EnableYamagrams(); |
|
ds@627
|
660 |
} |
|
ds@627
|
661 |
} |