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