|
ds@580
|
1 |
/** |
|
ds@653
|
2 |
* vim: set ts=4 : |
|
ds@1330
|
3 |
* ============================================================================= |
|
dvander@1231
|
4 |
* SourceMod |
|
dvander@1231
|
5 |
* Copyright (C) 2004-2007 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@653
|
29 |
* Version: $Id$ |
|
ds@653
|
30 |
*/ |
|
ds@580
|
31 |
|
|
ds@580
|
32 |
#include "ConVarManager.h" |
|
ds@696
|
33 |
#include "HalfLife2.h" |
|
ds@580
|
34 |
#include "PluginSys.h" |
|
ds@580
|
35 |
#include "ForwardSys.h" |
|
ds@580
|
36 |
#include "HandleSys.h" |
|
ds@580
|
37 |
#include "sm_srvcmds.h" |
|
ds@580
|
38 |
#include "sm_stringutil.h" |
|
ds@580
|
39 |
#include <sh_vector.h> |
|
dvander@1582
|
40 |
#include <sm_trie_tpl.h> |
|
ds@580
|
41 |
|
|
ds@580
|
42 |
ConVarManager g_ConVarManager; |
|
ds@580
|
43 |
|
|
dvander@1770
|
44 |
#if !defined ORANGEBOX_BUILD |
|
dvander@1770
|
45 |
#define CallGlobalChangeCallbacks CallGlobalChangeCallback |
|
dvander@1770
|
46 |
#endif |
|
dvander@1770
|
47 |
|
|
dvander@1770
|
48 |
#if defined ORANGEBOX_BUILD |
|
dvander@1770
|
49 |
SH_DECL_HOOK3_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *, float); |
|
dvander@1770
|
50 |
#else |
|
dvander@1770
|
51 |
SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *); |
|
dvander@1770
|
52 |
#endif |
|
dvander@1770
|
53 |
|
|
ds@696
|
54 |
SH_DECL_HOOK5_void(IServerGameDLL, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); |
|
ds@696
|
55 |
SH_DECL_HOOK5_void(IServerPluginCallbacks, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); |
|
ds@696
|
56 |
|
|
ds@582
|
57 |
const ParamType CONVARCHANGE_PARAMS[] = {Param_Cell, Param_String, Param_String}; |
|
ds@582
|
58 |
typedef List<const ConVar *> ConVarList; |
|
dvander@1582
|
59 |
KTrie<ConVarInfo *> convar_cache; |
|
ds@582
|
60 |
|
|
dvander@1581
|
61 |
ConVarManager::ConVarManager() : m_ConVarType(0), m_bIsDLLQueryHooked(false), m_bIsVSPQueryHooked(false) |
|
ds@580
|
62 |
{ |
|
ds@580
|
63 |
} |
|
ds@580
|
64 |
|
|
ds@580
|
65 |
ConVarManager::~ConVarManager() |
|
ds@580
|
66 |
{ |
|
ds@580
|
67 |
} |
|
ds@580
|
68 |
|
|
dvander@1770
|
69 |
void ConVarManager::OnSourceModStartup(bool late) |
|
dvander@1770
|
70 |
{ |
|
dvander@1770
|
71 |
HandleAccess sec; |
|
dvander@1770
|
72 |
|
|
dvander@1770
|
73 |
/* Set up access rights for the 'ConVar' handle type */ |
|
dvander@1770
|
74 |
sec.access[HandleAccess_Read] = 0; |
|
dvander@1770
|
75 |
sec.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; |
|
dvander@1770
|
76 |
sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; |
|
dvander@1770
|
77 |
|
|
dvander@1770
|
78 |
/* Create the 'ConVar' handle type */ |
|
dvander@1770
|
79 |
m_ConVarType = g_HandleSys.CreateType("ConVar", this, 0, NULL, &sec, g_pCoreIdent, NULL); |
|
dvander@1770
|
80 |
} |
|
dvander@1770
|
81 |
|
|
ds@580
|
82 |
void ConVarManager::OnSourceModAllInitialized() |
|
ds@580
|
83 |
{ |
|
dvander@1581
|
84 |
/** |
|
dvander@1581
|
85 |
* Episode 2 has this function by default, but the older versions do not. |
|
dvander@1581
|
86 |
*/ |
|
dvander@1581
|
87 |
#if !defined ORANGEBOX_BUILD |
|
ds@696
|
88 |
if (g_SMAPI->GetGameDLLVersion() >= 6) |
|
ds@696
|
89 |
{ |
|
ds@696
|
90 |
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false); |
|
dvander@1581
|
91 |
m_bIsDLLQueryHooked = true; |
|
ds@696
|
92 |
} |
|
dvander@1759
|
93 |
#endif |
|
ds@696
|
94 |
|
|
dvander@1770
|
95 |
SH_ADD_HOOK_STATICFUNC(ICvar, CallGlobalChangeCallbacks, icvar, OnConVarChanged, false); |
|
ds@580
|
96 |
|
|
ds@582
|
97 |
/* Add the 'convars' option to the 'sm' console command */ |
|
ds@990
|
98 |
g_RootMenu.AddRootConsoleCommand("cvars", "View convars created by a plugin", this); |
|
ds@580
|
99 |
} |
|
ds@580
|
100 |
|
|
ds@580
|
101 |
void ConVarManager::OnSourceModShutdown() |
|
ds@580
|
102 |
{ |
|
dvander@1582
|
103 |
List<ConVarInfo *>::iterator iter = m_ConVars.begin(); |
|
dvander@1582
|
104 |
HandleSecurity sec(NULL, g_pCoreIdent); |
|
dvander@1582
|
105 |
|
|
dvander@1582
|
106 |
/* Iterate list of ConVarInfo structures, remove every one of them */ |
|
dvander@1582
|
107 |
while (iter != m_ConVars.end()) |
|
dvander@1582
|
108 |
{ |
|
dvander@1582
|
109 |
ConVarInfo *pInfo = (*iter); |
|
dvander@1582
|
110 |
|
|
dvander@1582
|
111 |
iter = m_ConVars.erase(iter); |
|
dvander@1582
|
112 |
|
|
dvander@1582
|
113 |
g_HandleSys.FreeHandle(pInfo->handle, &sec); |
|
dvander@1582
|
114 |
if (pInfo->pChangeForward != NULL) |
|
dvander@1582
|
115 |
{ |
|
dvander@1582
|
116 |
g_Forwards.ReleaseForward(pInfo->pChangeForward); |
|
dvander@1582
|
117 |
} |
|
dvander@1582
|
118 |
if (pInfo->sourceMod) |
|
dvander@1582
|
119 |
{ |
|
dvander@1582
|
120 |
/* If we created it, we won't be tracking it, therefore it is |
|
dvander@1582
|
121 |
* safe to remove everything in one go. |
|
dvander@1582
|
122 |
*/ |
|
dvander@1582
|
123 |
META_UNREGCVAR(pInfo->pVar); |
|
dvander@1582
|
124 |
delete [] pInfo->pVar->GetName(); |
|
dvander@1582
|
125 |
delete [] pInfo->pVar->GetHelpText(); |
|
dvander@1582
|
126 |
delete [] pInfo->pVar->GetDefault(); |
|
dvander@1582
|
127 |
delete pInfo->pVar; |
|
dvander@1582
|
128 |
} |
|
dvander@1582
|
129 |
else |
|
dvander@1582
|
130 |
{ |
|
dvander@1582
|
131 |
/* If we didn't create it, we might be tracking it. Also, |
|
dvander@1582
|
132 |
* it could be unreadable. |
|
dvander@1582
|
133 |
*/ |
|
dvander@1582
|
134 |
UntrackConCommandBase(pInfo->pVar, this); |
|
dvander@1582
|
135 |
} |
|
dvander@1582
|
136 |
|
|
dvander@1582
|
137 |
/* It's not safe to read the name here, so we simply delete the |
|
dvander@1582
|
138 |
* the info struct and clear the lookup cache at the end. |
|
dvander@1582
|
139 |
*/ |
|
dvander@1582
|
140 |
delete pInfo; |
|
dvander@1582
|
141 |
} |
|
dvander@1582
|
142 |
convar_cache.clear(); |
|
dvander@1582
|
143 |
|
|
dvander@1582
|
144 |
/* Unhook things */ |
|
dvander@1581
|
145 |
if (m_bIsDLLQueryHooked) |
|
ds@696
|
146 |
{ |
|
ds@696
|
147 |
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false); |
|
dvander@1581
|
148 |
m_bIsDLLQueryHooked = false; |
|
dvander@1581
|
149 |
} |
|
dvander@1581
|
150 |
else if (m_bIsVSPQueryHooked) |
|
dvander@1581
|
151 |
{ |
|
dvander@1581
|
152 |
SH_REMOVE_HOOK_MEMFUNC(IServerPluginCallbacks, OnQueryCvarValueFinished, vsp_interface, this, &ConVarManager::OnQueryCvarValueFinished, false); |
|
dvander@1581
|
153 |
m_bIsVSPQueryHooked = false; |
|
ds@696
|
154 |
} |
|
ds@696
|
155 |
|
|
dvander@1770
|
156 |
SH_REMOVE_HOOK_STATICFUNC(ICvar, CallGlobalChangeCallbacks, icvar, OnConVarChanged, false); |
|
dvander@1770
|
157 |
|
|
ds@582
|
158 |
/* Remove the 'convars' option from the 'sm' console command */ |
|
ds@990
|
159 |
g_RootMenu.RemoveRootConsoleCommand("cvars", this); |
|
ds@580
|
160 |
|
|
ds@582
|
161 |
/* Remove the 'ConVar' handle type */ |
|
ds@580
|
162 |
g_HandleSys.RemoveType(m_ConVarType, g_pCoreIdent); |
|
ds@580
|
163 |
} |
|
ds@580
|
164 |
|
|
dvander@1581
|
165 |
/** |
|
dvander@1581
|
166 |
* Orange Box will never use this. |
|
dvander@1581
|
167 |
*/ |
|
dvander@1581
|
168 |
void ConVarManager::OnSourceModVSPReceived() |
|
ds@696
|
169 |
{ |
|
dvander@1581
|
170 |
/** |
|
dvander@1581
|
171 |
* Don't bother if the DLL is already hooked. |
|
ds@696
|
172 |
*/ |
|
dvander@1581
|
173 |
if (m_bIsDLLQueryHooked) |
|
ds@696
|
174 |
{ |
|
ds@696
|
175 |
return; |
|
ds@696
|
176 |
} |
|
ds@696
|
177 |
|
|
dvander@1581
|
178 |
/* For later MM:S versions, use the updated API, since it's cleaner. */ |
|
dvander@1581
|
179 |
#if defined METAMOD_PLAPI_VERSION |
|
dvander@1581
|
180 |
int engine = g_SMAPI->GetSourceEngineBuild(); |
|
dvander@1581
|
181 |
if (engine == SOURCE_ENGINE_ORIGINAL || vsp_version < 2) |
|
ds@696
|
182 |
{ |
|
dvander@1581
|
183 |
return; |
|
dvander@1581
|
184 |
} |
|
dvander@1581
|
185 |
#else |
|
dvander@1581
|
186 |
if (g_HL2.IsOriginalEngine() || vsp_version < 2) |
|
dvander@1581
|
187 |
{ |
|
dvander@1581
|
188 |
return; |
|
dvander@1581
|
189 |
} |
|
dvander@1581
|
190 |
#endif |
|
ds@696
|
191 |
|
|
dvander@1581
|
192 |
SH_ADD_HOOK_MEMFUNC(IServerPluginCallbacks, OnQueryCvarValueFinished, vsp_interface, this, &ConVarManager::OnQueryCvarValueFinished, false); |
|
dvander@1581
|
193 |
m_bIsVSPQueryHooked = true; |
|
ds@696
|
194 |
} |
|
ds@696
|
195 |
|
|
dvander@1582
|
196 |
bool convar_cache_lookup(const char *name, ConVarInfo **pVar) |
|
ds@1145
|
197 |
{ |
|
dvander@1582
|
198 |
ConVarInfo **pLookup = convar_cache.retrieve(name); |
|
dvander@1582
|
199 |
if (pLookup != NULL) |
|
ds@1145
|
200 |
{ |
|
dvander@1582
|
201 |
*pVar = *pLookup; |
|
dvander@1582
|
202 |
return true; |
|
dvander@1582
|
203 |
} |
|
dvander@1582
|
204 |
else |
|
dvander@1582
|
205 |
{ |
|
dvander@1582
|
206 |
return false; |
|
ds@1145
|
207 |
} |
|
ds@1145
|
208 |
} |
|
ds@1145
|
209 |
|
|
dvander@1582
|
210 |
void ConVarManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe) |
|
dvander@1582
|
211 |
{ |
|
dvander@1582
|
212 |
/* Only check convars that have not been created by SourceMod's core */ |
|
dvander@1582
|
213 |
ConVarInfo *pInfo; |
|
dvander@1582
|
214 |
if (!convar_cache_lookup(name, &pInfo)) |
|
dvander@1582
|
215 |
{ |
|
dvander@1582
|
216 |
return; |
|
dvander@1582
|
217 |
} |
|
ds@1145
|
218 |
|
|
ds@1145
|
219 |
HandleSecurity sec(NULL, g_pCoreIdent); |
|
ds@1145
|
220 |
|
|
dvander@1582
|
221 |
/* Remove it from our cache */ |
|
dvander@1582
|
222 |
m_ConVars.remove(pInfo); |
|
dvander@1582
|
223 |
convar_cache.remove(name); |
|
dvander@1582
|
224 |
|
|
dvander@1582
|
225 |
/* Now make sure no plugins are referring to this pointer */ |
|
dvander@1582
|
226 |
IPluginIterator *pl_iter = g_PluginSys.GetPluginIterator(); |
|
dvander@1582
|
227 |
while (pl_iter->MorePlugins()) |
|
ds@1145
|
228 |
{ |
|
dvander@1582
|
229 |
IPlugin *pl = pl_iter->GetPlugin(); |
|
ds@1145
|
230 |
|
|
dvander@1582
|
231 |
ConVarList *pConVarList; |
|
dvander@1582
|
232 |
if (pl->GetProperty("ConVarList", (void **)&pConVarList, true) |
|
dvander@1582
|
233 |
&& pConVarList != NULL) |
|
ds@1145
|
234 |
{ |
|
dvander@1582
|
235 |
pConVarList->remove(pInfo->pVar); |
|
dvander@1582
|
236 |
} |
|
ds@1145
|
237 |
|
|
dvander@1582
|
238 |
pl_iter->NextPlugin(); |
|
ds@1145
|
239 |
} |
|
dvander@1582
|
240 |
|
|
dvander@1582
|
241 |
/* Free resources */ |
|
dvander@1582
|
242 |
g_HandleSys.FreeHandle(pInfo->handle, &sec); |
|
dvander@1582
|
243 |
delete pInfo; |
|
ds@1145
|
244 |
} |
|
ds@1145
|
245 |
|
|
ds@582
|
246 |
void ConVarManager::OnPluginUnloaded(IPlugin *plugin) |
|
ds@580
|
247 |
{ |
|
ds@582
|
248 |
ConVarList *pConVarList; |
|
ds@580
|
249 |
|
|
ds@582
|
250 |
/* If plugin has a convar list, free its memory */ |
|
ds@582
|
251 |
if (plugin->GetProperty("ConVarList", (void **)&pConVarList, true)) |
|
ds@580
|
252 |
{ |
|
ds@582
|
253 |
delete pConVarList; |
|
ds@580
|
254 |
} |
|
ds@580
|
255 |
} |
|
ds@580
|
256 |
|
|
ds@580
|
257 |
void ConVarManager::OnHandleDestroy(HandleType_t type, void *object) |
|
ds@580
|
258 |
{ |
|
ds@580
|
259 |
} |
|
ds@580
|
260 |
|
|
dvander@1766
|
261 |
bool ConVarManager::GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize) |
|
dvander@1766
|
262 |
{ |
|
dvander@1770
|
263 |
*pSize = sizeof(ConVar) + sizeof(ConVarInfo); |
|
dvander@1766
|
264 |
return true; |
|
dvander@1766
|
265 |
} |
|
dvander@1766
|
266 |
|
|
faluco@1541
|
267 |
void ConVarManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command) |
|
ds@580
|
268 |
{ |
|
faluco@1541
|
269 |
int argcount = command.ArgC(); |
|
ds@580
|
270 |
if (argcount >= 3) |
|
ds@580
|
271 |
{ |
|
ds@582
|
272 |
/* Get plugin index that was passed */ |
|
faluco@1541
|
273 |
int id = atoi(command.Arg(2)); |
|
ds@580
|
274 |
|
|
ds@582
|
275 |
/* Get plugin object */ |
|
ds@582
|
276 |
CPlugin *plugin = g_PluginSys.GetPluginByOrder(id); |
|
ds@582
|
277 |
|
|
ds@582
|
278 |
if (!plugin) |
|
ds@580
|
279 |
{ |
|
ds@582
|
280 |
g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id); |
|
ds@580
|
281 |
return; |
|
ds@580
|
282 |
} |
|
ds@580
|
283 |
|
|
ds@582
|
284 |
/* Get plugin name */ |
|
ds@582
|
285 |
const sm_plugininfo_t *plinfo = plugin->GetPublicInfo(); |
|
ds@582
|
286 |
const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : plugin->GetFilename(); |
|
ds@580
|
287 |
|
|
ds@582
|
288 |
ConVarList *pConVarList; |
|
ds@582
|
289 |
ConVarList::iterator iter; |
|
ds@580
|
290 |
|
|
ds@582
|
291 |
/* If no convar list... */ |
|
ds@582
|
292 |
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) |
|
ds@580
|
293 |
{ |
|
ds@582
|
294 |
g_RootMenu.ConsolePrint("[SM] No convars found for: %s", plname); |
|
ds@580
|
295 |
return; |
|
ds@580
|
296 |
} |
|
ds@580
|
297 |
|
|
ds@582
|
298 |
g_RootMenu.ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname); |
|
ds@582
|
299 |
g_RootMenu.ConsolePrint(" %-32.31s %s", "[Name]", "[Value]"); |
|
ds@580
|
300 |
|
|
ds@582
|
301 |
/* Iterate convar list and display each one */ |
|
ds@582
|
302 |
for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) |
|
ds@580
|
303 |
{ |
|
ds@582
|
304 |
const ConVar *pConVar = (*iter); |
|
ds@582
|
305 |
g_RootMenu.ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString()); |
|
ds@580
|
306 |
} |
|
ds@580
|
307 |
|
|
ds@580
|
308 |
return; |
|
ds@580
|
309 |
} |
|
ds@580
|
310 |
|
|
ds@582
|
311 |
/* Display usage of subcommand */ |
|
ds@580
|
312 |
g_RootMenu.ConsolePrint("[SM] Usage: sm convars <plugin #>"); |
|
ds@580
|
313 |
} |
|
ds@580
|
314 |
|
|
ds@582
|
315 |
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
|
316 |
{ |
|
ds@580
|
317 |
ConVar *pConVar = NULL; |
|
ds@582
|
318 |
ConVarInfo *pInfo = NULL; |
|
ds@580
|
319 |
Handle_t hndl = 0; |
|
ds@580
|
320 |
|
|
ds@582
|
321 |
/* Find out if the convar exists already */ |
|
ds@580
|
322 |
pConVar = icvar->FindVar(name); |
|
ds@580
|
323 |
|
|
ds@582
|
324 |
/* If the convar already exists... */ |
|
ds@582
|
325 |
if (pConVar) |
|
ds@580
|
326 |
{ |
|
ds@759
|
327 |
/* Add convar to plugin's list */ |
|
ds@759
|
328 |
AddConVarToPluginList(pContext, pConVar); |
|
ds@759
|
329 |
|
|
ds@582
|
330 |
/* First find out if we already have a handle to it */ |
|
dvander@1582
|
331 |
if (convar_cache_lookup(name, &pInfo)) |
|
ds@580
|
332 |
{ |
|
ds@582
|
333 |
return pInfo->handle; |
|
dvander@1581
|
334 |
} |
|
dvander@1581
|
335 |
else |
|
dvander@1581
|
336 |
{ |
|
ds@582
|
337 |
/* Create and initialize ConVarInfo structure */ |
|
ds@582
|
338 |
pInfo = new ConVarInfo(); |
|
ds@582
|
339 |
pInfo->sourceMod = false; |
|
ds@696
|
340 |
pInfo->pChangeForward = NULL; |
|
dvander@1582
|
341 |
pInfo->pVar = pConVar; |
|
dvander@1582
|
342 |
|
|
dvander@1582
|
343 |
/* If we don't, then create a new handle from the convar */ |
|
dvander@1582
|
344 |
hndl = g_HandleSys.CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL); |
|
dvander@1582
|
345 |
if (hndl == BAD_HANDLE) |
|
dvander@1582
|
346 |
{ |
|
dvander@1582
|
347 |
delete pInfo; |
|
dvander@1582
|
348 |
return BAD_HANDLE; |
|
dvander@1582
|
349 |
} |
|
dvander@1582
|
350 |
|
|
dvander@1582
|
351 |
pInfo->handle = hndl; |
|
ds@580
|
352 |
|
|
ds@582
|
353 |
/* Insert struct into caches */ |
|
ds@582
|
354 |
m_ConVars.push_back(pInfo); |
|
dvander@1582
|
355 |
convar_cache.insert(name, pInfo); |
|
dvander@1582
|
356 |
TrackConCommandBase(pConVar, this); |
|
ds@580
|
357 |
|
|
ds@580
|
358 |
return hndl; |
|
ds@580
|
359 |
} |
|
ds@580
|
360 |
} |
|
ds@580
|
361 |
|
|
ds@696
|
362 |
/* To prevent creating a convar that has the same name as a console command... ugh */ |
|
ds@580
|
363 |
ConCommandBase *pBase = icvar->GetCommands(); |
|
ds@580
|
364 |
|
|
ds@580
|
365 |
while (pBase) |
|
ds@580
|
366 |
{ |
|
ds@582
|
367 |
if (pBase->IsCommand() && strcmp(pBase->GetName(), name) == 0) |
|
ds@580
|
368 |
{ |
|
ds@582
|
369 |
return BAD_HANDLE; |
|
ds@580
|
370 |
} |
|
ds@580
|
371 |
|
|
ds@580
|
372 |
pBase = const_cast<ConCommandBase *>(pBase->GetNext()); |
|
ds@580
|
373 |
} |
|
ds@580
|
374 |
|
|
ds@582
|
375 |
/* Create and initialize ConVarInfo structure */ |
|
ds@582
|
376 |
pInfo = new ConVarInfo(); |
|
ds@582
|
377 |
pInfo->handle = hndl; |
|
ds@582
|
378 |
pInfo->sourceMod = true; |
|
ds@696
|
379 |
pInfo->pChangeForward = NULL; |
|
dvander@1582
|
380 |
|
|
dvander@1582
|
381 |
/* Create a handle from the new convar */ |
|
dvander@1582
|
382 |
hndl = g_HandleSys.CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL); |
|
dvander@1582
|
383 |
if (hndl == BAD_HANDLE) |
|
dvander@1582
|
384 |
{ |
|
dvander@1582
|
385 |
delete pInfo; |
|
dvander@1582
|
386 |
return BAD_HANDLE; |
|
dvander@1582
|
387 |
} |
|
dvander@1582
|
388 |
|
|
dvander@1582
|
389 |
pInfo->handle = hndl; |
|
dvander@1582
|
390 |
|
|
dvander@1582
|
391 |
/* Since an existing convar (or concmd with the same name) was not found , now we can finally create it */ |
|
dvander@1582
|
392 |
pConVar = new ConVar(sm_strdup(name), sm_strdup(defaultVal), flags, sm_strdup(description), hasMin, min, hasMax, max); |
|
dvander@1582
|
393 |
pInfo->pVar = pConVar; |
|
dvander@1582
|
394 |
|
|
dvander@1582
|
395 |
/* Add convar to plugin's list */ |
|
dvander@1582
|
396 |
AddConVarToPluginList(pContext, pConVar); |
|
ds@580
|
397 |
|
|
ds@582
|
398 |
/* Insert struct into caches */ |
|
ds@582
|
399 |
m_ConVars.push_back(pInfo); |
|
dvander@1582
|
400 |
convar_cache.insert(name, pInfo); |
|
ds@580
|
401 |
|
|
ds@580
|
402 |
return hndl; |
|
ds@580
|
403 |
} |
|
ds@580
|
404 |
|
|
ds@580
|
405 |
Handle_t ConVarManager::FindConVar(const char *name) |
|
ds@580
|
406 |
{ |
|
ds@580
|
407 |
ConVar *pConVar = NULL; |
|
ds@582
|
408 |
ConVarInfo *pInfo; |
|
ds@582
|
409 |
Handle_t hndl; |
|
ds@580
|
410 |
|
|
ds@582
|
411 |
/* Search for convar */ |
|
ds@580
|
412 |
pConVar = icvar->FindVar(name); |
|
ds@580
|
413 |
|
|
ds@582
|
414 |
/* If it doesn't exist, then return an invalid handle */ |
|
ds@582
|
415 |
if (!pConVar) |
|
ds@580
|
416 |
{ |
|
ds@580
|
417 |
return BAD_HANDLE; |
|
ds@580
|
418 |
} |
|
ds@580
|
419 |
|
|
ds@582
|
420 |
/* At this point, the convar exists. So, find out if we already have a handle */ |
|
dvander@1582
|
421 |
if (convar_cache_lookup(name, &pInfo)) |
|
ds@580
|
422 |
{ |
|
ds@582
|
423 |
return pInfo->handle; |
|
ds@580
|
424 |
} |
|
ds@580
|
425 |
|
|
ds@729
|
426 |
/* Create and initialize ConVarInfo structure */ |
|
ds@582
|
427 |
pInfo = new ConVarInfo(); |
|
ds@582
|
428 |
pInfo->sourceMod = false; |
|
ds@696
|
429 |
pInfo->pChangeForward = NULL; |
|
dvander@1582
|
430 |
pInfo->pVar = pConVar; |
|
dvander@1582
|
431 |
|
|
dvander@1582
|
432 |
/* If we don't have a handle, then create a new one */ |
|
dvander@1582
|
433 |
hndl = g_HandleSys.CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL); |
|
dvander@1582
|
434 |
if (hndl == BAD_HANDLE) |
|
dvander@1582
|
435 |
{ |
|
dvander@1582
|
436 |
delete pInfo; |
|
dvander@1582
|
437 |
return BAD_HANDLE; |
|
dvander@1582
|
438 |
} |
|
dvander@1582
|
439 |
|
|
dvander@1582
|
440 |
pInfo->handle = hndl; |
|
ds@580
|
441 |
|
|
ds@582
|
442 |
/* Insert struct into our caches */ |
|
ds@582
|
443 |
m_ConVars.push_back(pInfo); |
|
dvander@1582
|
444 |
convar_cache.insert(name, pInfo); |
|
dvander@1582
|
445 |
TrackConCommandBase(pConVar, this); |
|
ds@580
|
446 |
|
|
ds@580
|
447 |
return hndl; |
|
ds@580
|
448 |
} |
|
ds@580
|
449 |
|
|
dvander@1770
|
450 |
void ConVarManager::AddConVarChangeListener(const char *name, IConVarChangeListener *pListener) |
|
dvander@1770
|
451 |
{ |
|
dvander@1770
|
452 |
ConVarInfo *pInfo; |
|
dvander@1770
|
453 |
|
|
dvander@1770
|
454 |
if (FindConVar(name) == BAD_HANDLE) |
|
dvander@1770
|
455 |
{ |
|
dvander@1770
|
456 |
return; |
|
dvander@1770
|
457 |
} |
|
dvander@1770
|
458 |
|
|
dvander@1770
|
459 |
/* Find the convar in the lookup trie */ |
|
dvander@1770
|
460 |
if (convar_cache_lookup(name, &pInfo)) |
|
dvander@1770
|
461 |
{ |
|
dvander@1770
|
462 |
pInfo->changeListeners.push_back(pListener); |
|
dvander@1770
|
463 |
} |
|
dvander@1770
|
464 |
} |
|
dvander@1770
|
465 |
|
|
dvander@1770
|
466 |
void ConVarManager::RemoveConVarChangeListener(const char *name, IConVarChangeListener *pListener) |
|
dvander@1770
|
467 |
{ |
|
dvander@1770
|
468 |
ConVarInfo *pInfo; |
|
dvander@1770
|
469 |
|
|
dvander@1770
|
470 |
/* Find the convar in the lookup trie */ |
|
dvander@1770
|
471 |
if (convar_cache_lookup(name, &pInfo)) |
|
dvander@1770
|
472 |
{ |
|
dvander@1770
|
473 |
pInfo->changeListeners.remove(pListener); |
|
dvander@1770
|
474 |
} |
|
dvander@1770
|
475 |
} |
|
dvander@1770
|
476 |
|
|
ds@582
|
477 |
void ConVarManager::HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction) |
|
ds@580
|
478 |
{ |
|
ds@582
|
479 |
ConVarInfo *pInfo; |
|
ds@582
|
480 |
IChangeableForward *pForward; |
|
ds@580
|
481 |
|
|
ds@582
|
482 |
/* Find the convar in the lookup trie */ |
|
dvander@1582
|
483 |
if (convar_cache_lookup(pConVar->GetName(), &pInfo)) |
|
ds@580
|
484 |
{ |
|
ds@582
|
485 |
/* Get the forward */ |
|
ds@696
|
486 |
pForward = pInfo->pChangeForward; |
|
ds@580
|
487 |
|
|
ds@582
|
488 |
/* If forward does not exist, create it */ |
|
ds@582
|
489 |
if (!pForward) |
|
ds@582
|
490 |
{ |
|
ds@582
|
491 |
pForward = g_Forwards.CreateForwardEx(NULL, ET_Ignore, 3, CONVARCHANGE_PARAMS); |
|
ds@696
|
492 |
pInfo->pChangeForward = pForward; |
|
ds@580
|
493 |
} |
|
ds@582
|
494 |
|
|
ds@582
|
495 |
/* Add function to forward's list */ |
|
ds@582
|
496 |
pForward->AddFunction(pFunction); |
|
ds@580
|
497 |
} |
|
ds@580
|
498 |
} |
|
ds@580
|
499 |
|
|
ds@582
|
500 |
void ConVarManager::UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction) |
|
ds@580
|
501 |
{ |
|
ds@582
|
502 |
ConVarInfo *pInfo; |
|
ds@582
|
503 |
IChangeableForward *pForward; |
|
ds@582
|
504 |
IPluginContext *pContext = pFunction->GetParentContext(); |
|
ds@580
|
505 |
|
|
ds@582
|
506 |
/* Find the convar in the lookup trie */ |
|
dvander@1582
|
507 |
if (convar_cache_lookup(pConVar->GetName(), &pInfo)) |
|
ds@580
|
508 |
{ |
|
ds@582
|
509 |
/* Get the forward */ |
|
ds@696
|
510 |
pForward = pInfo->pChangeForward; |
|
ds@580
|
511 |
|
|
ds@582
|
512 |
/* If the forward doesn't exist, we can't unhook anything */ |
|
ds@582
|
513 |
if (!pForward) |
|
ds@580
|
514 |
{ |
|
ds@580
|
515 |
pContext->ThrowNativeError("Convar \"%s\" has no active hook", pConVar->GetName()); |
|
ds@580
|
516 |
return; |
|
ds@580
|
517 |
} |
|
ds@580
|
518 |
|
|
ds@582
|
519 |
/* Remove the function from the forward's list */ |
|
ds@582
|
520 |
if (!pForward->RemoveFunction(pFunction)) |
|
ds@580
|
521 |
{ |
|
ds@580
|
522 |
pContext->ThrowNativeError("Invalid hook callback specified for convar \"%s\"", pConVar->GetName()); |
|
ds@580
|
523 |
return; |
|
ds@580
|
524 |
} |
|
ds@580
|
525 |
|
|
ds@582
|
526 |
/* If the forward now has 0 functions in it... */ |
|
ds@582
|
527 |
if (pForward->GetFunctionCount() == 0) |
|
ds@580
|
528 |
{ |
|
ds@582
|
529 |
/* Free this forward */ |
|
ds@582
|
530 |
g_Forwards.ReleaseForward(pForward); |
|
ds@696
|
531 |
pInfo->pChangeForward = NULL; |
|
ds@582
|
532 |
} |
|
ds@582
|
533 |
} |
|
ds@582
|
534 |
} |
|
ds@582
|
535 |
|
|
ds@696
|
536 |
QueryCvarCookie_t ConVarManager::QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback, Handle_t hndl) |
|
ds@696
|
537 |
{ |
|
ds@696
|
538 |
QueryCvarCookie_t cookie; |
|
ds@696
|
539 |
|
|
ds@696
|
540 |
/* Call StartQueryCvarValue() in either the IVEngineServer or IServerPluginHelpers depending on situation */ |
|
dvander@1581
|
541 |
if (m_bIsDLLQueryHooked) |
|
ds@696
|
542 |
{ |
|
ds@696
|
543 |
cookie = engine->StartQueryCvarValue(pPlayer, name); |
|
dvander@1581
|
544 |
} |
|
dvander@1581
|
545 |
else if (m_bIsVSPQueryHooked) |
|
dvander@1581
|
546 |
{ |
|
ds@696
|
547 |
cookie = serverpluginhelpers->StartQueryCvarValue(pPlayer, name); |
|
ds@696
|
548 |
} |
|
dvander@1581
|
549 |
else |
|
dvander@1581
|
550 |
{ |
|
dvander@1581
|
551 |
return InvalidQueryCvarCookie; |
|
dvander@1581
|
552 |
} |
|
ds@696
|
553 |
|
|
ds@696
|
554 |
ConVarQuery query = {cookie, pCallback, hndl}; |
|
ds@696
|
555 |
m_ConVarQueries.push_back(query); |
|
ds@696
|
556 |
|
|
ds@696
|
557 |
return cookie; |
|
ds@696
|
558 |
} |
|
ds@696
|
559 |
|
|
ds@582
|
560 |
void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar) |
|
ds@582
|
561 |
{ |
|
ds@582
|
562 |
ConVarList *pConVarList; |
|
ds@582
|
563 |
ConVarList::iterator iter; |
|
ds@582
|
564 |
bool inserted = false; |
|
ds@582
|
565 |
const char *orig = pConVar->GetName(); |
|
ds@582
|
566 |
|
|
ds@582
|
567 |
IPlugin *plugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); |
|
ds@580
|
568 |
|
|
ds@582
|
569 |
/* Check plugin for an existing convar list */ |
|
ds@582
|
570 |
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) |
|
ds@582
|
571 |
{ |
|
ds@582
|
572 |
pConVarList = new ConVarList(); |
|
ds@582
|
573 |
plugin->SetProperty("ConVarList", pConVarList); |
|
dvander@1581
|
574 |
} |
|
dvander@1581
|
575 |
else if (pConVarList->find(pConVar) != pConVarList->end()) |
|
dvander@1581
|
576 |
{ |
|
ds@867
|
577 |
/* If convar is already in list, then don't add it */ |
|
ds@867
|
578 |
return; |
|
ds@582
|
579 |
} |
|
ds@582
|
580 |
|
|
ds@582
|
581 |
/* Insert convar into list which is sorted alphabetically */ |
|
ds@582
|
582 |
for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) |
|
ds@582
|
583 |
{ |
|
ds@582
|
584 |
if (strcmp(orig, (*iter)->GetName()) < 0) |
|
ds@582
|
585 |
{ |
|
ds@582
|
586 |
pConVarList->insert(iter, pConVar); |
|
ds@582
|
587 |
inserted = true; |
|
ds@582
|
588 |
break; |
|
ds@580
|
589 |
} |
|
ds@580
|
590 |
} |
|
ds@582
|
591 |
|
|
ds@582
|
592 |
if (!inserted) |
|
ds@582
|
593 |
{ |
|
ds@582
|
594 |
pConVarList->push_back(pConVar); |
|
ds@582
|
595 |
} |
|
ds@580
|
596 |
} |
|
ds@580
|
597 |
|
|
faluco@1541
|
598 |
#if defined ORANGEBOX_BUILD |
|
dvander@1770
|
599 |
void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue) |
|
faluco@1541
|
600 |
#else |
|
ds@580
|
601 |
void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue) |
|
faluco@1541
|
602 |
#endif |
|
ds@580
|
603 |
{ |
|
ds@582
|
604 |
/* If the values are the same, exit early in order to not trigger callbacks */ |
|
dvander@1544
|
605 |
if (strcmp(pConVar->GetString(), oldValue) == 0) |
|
ds@580
|
606 |
{ |
|
ds@580
|
607 |
return; |
|
ds@580
|
608 |
} |
|
ds@580
|
609 |
|
|
ds@582
|
610 |
ConVarInfo *pInfo; |
|
ds@580
|
611 |
|
|
ds@582
|
612 |
/* Find the convar in the lookup trie */ |
|
dvander@1582
|
613 |
if (!convar_cache_lookup(pConVar->GetName(), &pInfo)) |
|
dvander@1582
|
614 |
{ |
|
dvander@1582
|
615 |
return; |
|
dvander@1582
|
616 |
} |
|
ds@580
|
617 |
|
|
ds@696
|
618 |
IChangeableForward *pForward = pInfo->pChangeForward; |
|
ds@580
|
619 |
|
|
dvander@1770
|
620 |
if (pInfo->changeListeners.size() != 0) |
|
ds@580
|
621 |
{ |
|
dvander@1770
|
622 |
for (List<IConVarChangeListener *>::iterator i = pInfo->changeListeners.begin(); |
|
dvander@1770
|
623 |
i != pInfo->changeListeners.end(); |
|
dvander@1770
|
624 |
i++) |
|
dvander@1770
|
625 |
{ |
|
faluco@1541
|
626 |
#if defined ORANGEBOX_BUILD |
|
dvander@1770
|
627 |
(*i)->OnConVarChanged(pConVar, oldValue, flOldValue); |
|
faluco@1541
|
628 |
#else |
|
dvander@1770
|
629 |
(*i)->OnConVarChanged(pConVar, oldValue, atof(oldValue)); |
|
faluco@1541
|
630 |
#endif |
|
dvander@1770
|
631 |
} |
|
ds@580
|
632 |
} |
|
ds@580
|
633 |
|
|
dvander@1770
|
634 |
if (pForward != NULL) |
|
dvander@1770
|
635 |
{ |
|
dvander@1770
|
636 |
/* Now call forwards in plugins that have hooked this */ |
|
dvander@1770
|
637 |
pForward->PushCell(pInfo->handle); |
|
dvander@1770
|
638 |
pForward->PushString(oldValue); |
|
dvander@1770
|
639 |
pForward->PushString(pConVar->GetString()); |
|
dvander@1770
|
640 |
pForward->Execute(NULL); |
|
dvander@1770
|
641 |
} |
|
ds@580
|
642 |
} |
|
ds@627
|
643 |
|
|
dvander@1581
|
644 |
bool ConVarManager::IsQueryingSupported() |
|
dvander@1581
|
645 |
{ |
|
dvander@1581
|
646 |
return (m_bIsDLLQueryHooked || m_bIsVSPQueryHooked); |
|
dvander@1581
|
647 |
} |
|
dvander@1581
|
648 |
|
|
ds@696
|
649 |
void ConVarManager::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue) |
|
ds@696
|
650 |
{ |
|
ds@696
|
651 |
IPluginFunction *pCallback = NULL; |
|
ds@696
|
652 |
cell_t value = 0; |
|
ds@696
|
653 |
List<ConVarQuery>::iterator iter; |
|
ds@696
|
654 |
|
|
ds@696
|
655 |
for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end(); iter++) |
|
ds@696
|
656 |
{ |
|
ds@696
|
657 |
ConVarQuery &query = (*iter); |
|
ds@696
|
658 |
if (query.cookie == cookie) |
|
ds@696
|
659 |
{ |
|
ds@696
|
660 |
pCallback = query.pCallback; |
|
ds@696
|
661 |
value = query.value; |
|
ds@696
|
662 |
break; |
|
ds@696
|
663 |
} |
|
ds@696
|
664 |
} |
|
ds@696
|
665 |
|
|
ds@696
|
666 |
if (pCallback) |
|
ds@696
|
667 |
{ |
|
ds@696
|
668 |
cell_t ret; |
|
ds@696
|
669 |
|
|
ds@696
|
670 |
pCallback->PushCell(cookie); |
|
ds@696
|
671 |
pCallback->PushCell(engine->IndexOfEdict(pPlayer)); |
|
ds@696
|
672 |
pCallback->PushCell(result); |
|
ds@696
|
673 |
pCallback->PushString(cvarName); |
|
ds@696
|
674 |
|
|
ds@696
|
675 |
if (result == eQueryCvarValueStatus_ValueIntact) |
|
ds@696
|
676 |
{ |
|
ds@696
|
677 |
pCallback->PushString(cvarValue); |
|
dvander@1581
|
678 |
} |
|
dvander@1581
|
679 |
else |
|
dvander@1581
|
680 |
{ |
|
ds@696
|
681 |
pCallback->PushString("\0"); |
|
ds@696
|
682 |
} |
|
ds@696
|
683 |
|
|
ds@696
|
684 |
pCallback->PushCell(value); |
|
ds@696
|
685 |
pCallback->Execute(&ret); |
|
ds@696
|
686 |
|
|
ds@696
|
687 |
m_ConVarQueries.erase(iter); |
|
ds@696
|
688 |
} |
|
ds@696
|
689 |
} |
|
ds@696
|
690 |
|
|
dvander@1582
|
691 |
HandleError ConVarManager::ReadConVarHandle(Handle_t hndl, ConVar **pVar) |
|
dvander@1582
|
692 |
{ |
|
dvander@1582
|
693 |
ConVarInfo *pInfo; |
|
dvander@1582
|
694 |
HandleError error; |
|
dvander@1582
|
695 |
|
|
dvander@1582
|
696 |
if ((error = g_HandleSys.ReadHandle(hndl, m_ConVarType, NULL, (void **)&pInfo)) != HandleError_None) |
|
dvander@1582
|
697 |
{ |
|
dvander@1582
|
698 |
return error; |
|
dvander@1582
|
699 |
} |
|
dvander@1582
|
700 |
|
|
dvander@1582
|
701 |
if (pVar) |
|
dvander@1582
|
702 |
{ |
|
dvander@1582
|
703 |
*pVar = pInfo->pVar; |
|
dvander@1582
|
704 |
} |
|
dvander@1582
|
705 |
|
|
dvander@1582
|
706 |
return error; |
|
dvander@1582
|
707 |
} |
|
ds@696
|
708 |
|
|
ds@627
|
709 |
static int s_YamagramState = 0; |
|
ds@627
|
710 |
|
|
ds@627
|
711 |
void _YamagramPrinterTwoPointOhOh(int yamagram) |
|
ds@627
|
712 |
{ |
|
ds@627
|
713 |
switch (yamagram) |
|
ds@627
|
714 |
{ |
|
ds@627
|
715 |
case 0: |
|
ds@627
|
716 |
g_RootMenu.ConsolePrint("Answer the following questions correctly and Gaben may not eat you after all."); |
|
ds@627
|
717 |
g_RootMenu.ConsolePrint("You will be given one hint in the form of my patented yamagrams."); |
|
ds@627
|
718 |
g_RootMenu.ConsolePrint("Type sm_nana to see the last question."); |
|
ds@627
|
719 |
g_RootMenu.ConsolePrint("Type sm_nana <answer> to attempt an answer of the question."); |
|
ds@627
|
720 |
g_RootMenu.ConsolePrint("-------------------------------"); |
|
ds@627
|
721 |
_YamagramPrinterTwoPointOhOh(1); |
|
ds@627
|
722 |
return; |
|
ds@627
|
723 |
case 1: |
|
ds@627
|
724 |
g_RootMenu.ConsolePrint("Question Ichi (1)"); |
|
ds@627
|
725 |
g_RootMenu.ConsolePrint("One can turn into a cow by doing what action?"); |
|
ds@627
|
726 |
g_RootMenu.ConsolePrint("Hint: AGE SANS GRIT"); |
|
ds@627
|
727 |
break; |
|
ds@627
|
728 |
case 2: |
|
ds@627
|
729 |
g_RootMenu.ConsolePrint("Question Ni (2)"); |
|
ds@627
|
730 |
g_RootMenu.ConsolePrint("What kind of hat should you wear when using the Internet?"); |
|
ds@627
|
731 |
g_RootMenu.ConsolePrint("Hint: BRR MOOSE"); |
|
ds@627
|
732 |
break; |
|
ds@627
|
733 |
case 3: |
|
ds@627
|
734 |
g_RootMenu.ConsolePrint("Question San (3)"); |
|
ds@627
|
735 |
g_RootMenu.ConsolePrint("Who is the lead developer of SourceMod?"); |
|
ds@627
|
736 |
g_RootMenu.ConsolePrint("Hint: VEAL BANDANA DID RIP SOON"); |
|
ds@627
|
737 |
break; |
|
ds@627
|
738 |
case 4: |
|
ds@627
|
739 |
g_RootMenu.ConsolePrint("Question Yon (4)"); |
|
ds@627
|
740 |
g_RootMenu.ConsolePrint("A terrible translation of 'SVN Revision' to Japanese romaji might be ..."); |
|
ds@627
|
741 |
g_RootMenu.ConsolePrint("Hint: I TAKE IN AN AIR OK"); |
|
ds@627
|
742 |
break; |
|
ds@627
|
743 |
case 5: |
|
ds@627
|
744 |
g_RootMenu.ConsolePrint("Question Go (5)"); |
|
ds@627
|
745 |
g_RootMenu.ConsolePrint("What is a fundamental concept in the game of Go?"); |
|
ds@628
|
746 |
g_RootMenu.ConsolePrint("Hint: AD LADEN THIEF"); |
|
ds@627
|
747 |
break; |
|
ds@627
|
748 |
case 6: |
|
ds@627
|
749 |
g_RootMenu.ConsolePrint("Question Roku (6)"); |
|
ds@627
|
750 |
g_RootMenu.ConsolePrint("Why am I asking all these strange questions?"); |
|
ds@627
|
751 |
g_RootMenu.ConsolePrint("Hint: CHUBBY TITAN EATS EWE WAGE DATA"); |
|
ds@627
|
752 |
break; |
|
ds@627
|
753 |
case 7: |
|
ds@627
|
754 |
g_RootMenu.ConsolePrint("Question Nana (7)"); |
|
ds@627
|
755 |
g_RootMenu.ConsolePrint("What is my name?"); |
|
ds@627
|
756 |
g_RootMenu.ConsolePrint("Hint: AD MODE LAG US"); |
|
ds@627
|
757 |
break; |
|
ds@627
|
758 |
default: |
|
ds@627
|
759 |
break; |
|
ds@627
|
760 |
} |
|
ds@627
|
761 |
|
|
ds@627
|
762 |
s_YamagramState = yamagram; |
|
ds@627
|
763 |
} |
|
ds@627
|
764 |
|
|
faluco@1541
|
765 |
#if defined ORANGEBOX_BUILD |
|
faluco@1541
|
766 |
void _IntExt_CallYamagrams(const CCommand &cmd) |
|
faluco@1541
|
767 |
{ |
|
faluco@1541
|
768 |
#else |
|
ds@627
|
769 |
void _IntExt_CallYamagrams() |
|
ds@627
|
770 |
{ |
|
faluco@1541
|
771 |
CCommand cmd; |
|
faluco@1541
|
772 |
#endif |
|
ds@627
|
773 |
bool correct = false; |
|
faluco@1541
|
774 |
const char *arg = cmd.ArgS(); |
|
ds@627
|
775 |
|
|
ds@627
|
776 |
if (!arg || arg[0] == '\0') |
|
ds@627
|
777 |
{ |
|
ds@627
|
778 |
_YamagramPrinterTwoPointOhOh(s_YamagramState); |
|
ds@627
|
779 |
return; |
|
ds@627
|
780 |
} |
|
ds@627
|
781 |
|
|
ds@627
|
782 |
switch (s_YamagramState) |
|
ds@627
|
783 |
{ |
|
ds@627
|
784 |
case 1: |
|
ds@627
|
785 |
correct = !strcasecmp(arg, "eating grass"); |
|
ds@627
|
786 |
break; |
|
ds@627
|
787 |
case 2: |
|
ds@627
|
788 |
correct = !strcasecmp(arg, "sombrero"); |
|
ds@627
|
789 |
break; |
|
ds@627
|
790 |
case 3: |
|
ds@627
|
791 |
correct = !strcasecmp(arg, "david bailopan anderson"); |
|
ds@627
|
792 |
break; |
|
ds@627
|
793 |
case 4: |
|
ds@627
|
794 |
correct = !strcasecmp(arg, "kaitei no kairan"); |
|
ds@627
|
795 |
break; |
|
ds@627
|
796 |
case 5: |
|
ds@628
|
797 |
correct = !strcasecmp(arg, "life and death"); |
|
ds@627
|
798 |
break; |
|
ds@627
|
799 |
case 6: |
|
ds@627
|
800 |
correct = !strcasecmp(arg, "because gabe wanted it that way"); |
|
ds@627
|
801 |
if (correct) |
|
ds@627
|
802 |
{ |
|
ds@627
|
803 |
g_RootMenu.ConsolePrint("Congratulations, you have answered 6 of my questions."); |
|
ds@627
|
804 |
g_RootMenu.ConsolePrint("However, I have one final question for you. It wouldn't be nana without it."); |
|
ds@627
|
805 |
g_RootMenu.ConsolePrint("-------------------------------"); |
|
ds@627
|
806 |
_YamagramPrinterTwoPointOhOh(7); |
|
ds@627
|
807 |
return; |
|
ds@627
|
808 |
} |
|
ds@627
|
809 |
break; |
|
ds@627
|
810 |
case 7: |
|
ds@627
|
811 |
correct = !strcasecmp(arg, "damaged soul"); |
|
ds@627
|
812 |
if (correct) |
|
ds@627
|
813 |
{ |
|
ds@627
|
814 |
g_RootMenu.ConsolePrint("You don't know how lucky you are to still be alive!"); |
|
ds@627
|
815 |
g_RootMenu.ConsolePrint("Congratulations. You have answered all 7 questions correctly."); |
|
ds@627
|
816 |
g_RootMenu.ConsolePrint("The SourceMod Dev Team will be at your door with anti-Gaben grenades"); |
|
ds@627
|
817 |
g_RootMenu.ConsolePrint("within seconds. You will also be provided with a rocket launcher,"); |
|
ds@627
|
818 |
g_RootMenu.ConsolePrint("just in case Alfred decides to strike you with a blitzkrieg in retaliation."); |
|
ds@627
|
819 |
|
|
ds@627
|
820 |
s_YamagramState = 0; |
|
ds@627
|
821 |
return; |
|
ds@627
|
822 |
} |
|
ds@627
|
823 |
break; |
|
ds@627
|
824 |
default: |
|
ds@627
|
825 |
break; |
|
ds@627
|
826 |
} |
|
ds@627
|
827 |
|
|
ds@627
|
828 |
if (s_YamagramState > 0) |
|
ds@627
|
829 |
{ |
|
ds@627
|
830 |
if (correct) |
|
ds@627
|
831 |
{ |
|
ds@627
|
832 |
g_RootMenu.ConsolePrint("Correct! You are one step closer to avoiding the deadly jaws of Gaben."); |
|
ds@627
|
833 |
g_RootMenu.ConsolePrint("-------------------------------"); |
|
ds@627
|
834 |
s_YamagramState++; |
|
ds@627
|
835 |
} else { |
|
ds@627
|
836 |
g_RootMenu.ConsolePrint("Wrong! You better be more careful. Gaben may be at your door at any minute."); |
|
ds@627
|
837 |
return; |
|
ds@627
|
838 |
} |
|
ds@627
|
839 |
} |
|
ds@627
|
840 |
|
|
ds@627
|
841 |
_YamagramPrinterTwoPointOhOh(s_YamagramState); |
|
ds@627
|
842 |
} |
|
ds@627
|
843 |
|
|
ds@627
|
844 |
void _IntExt_EnableYamagrams() |
|
ds@627
|
845 |
{ |
|
ds@627
|
846 |
static ConCommand *pCmd = NULL; |
|
ds@627
|
847 |
if (!pCmd) |
|
ds@627
|
848 |
{ |
|
ds@627
|
849 |
pCmd = new ConCommand("sm_nana", _IntExt_CallYamagrams, "Try these yamagrams!", FCVAR_GAMEDLL); |
|
ds@627
|
850 |
g_RootMenu.ConsolePrint("[SM] Warning: Gaben has been alerted of your actions. You may be eaten."); |
|
ds@627
|
851 |
} else { |
|
ds@627
|
852 |
g_RootMenu.ConsolePrint("[SM] Gaben has already been alerted of your actions..."); |
|
ds@627
|
853 |
} |
|
ds@627
|
854 |
} |
|
ds@627
|
855 |
|
|
dvander@1770
|
856 |
void _IntExt_OnHostnameChanged(ConVar *pConVar, const char *oldValue, float flOldValue) |
|
ds@627
|
857 |
{ |
|
ds@627
|
858 |
if (strcmp(oldValue, "Good morning, DS-san.") == 0 |
|
dvander@1770
|
859 |
&& strcmp(pConVar->GetString(), "Good night, talking desk lamp.") == 0) |
|
ds@627
|
860 |
{ |
|
ds@627
|
861 |
_IntExt_EnableYamagrams(); |
|
ds@627
|
862 |
} |
|
ds@627
|
863 |
} |