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