ds@580: /** ds@653: * vim: set ts=4 : ds@653: * =============================================================== ds@653: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. ds@653: * =============================================================== ds@653: * ds@653: * This file is not open source and may not be copied without explicit ds@653: * written permission of AlliedModders LLC. This file may not be redistributed ds@653: * in whole or significant part. ds@653: * For information, see LICENSE.txt or http://www.sourcemod.net/license.php ds@653: * ds@653: * Version: $Id$ ds@653: */ ds@580: ds@580: #include "ConVarManager.h" ds@696: #include "HalfLife2.h" ds@580: #include "PluginSys.h" ds@580: #include "ForwardSys.h" ds@580: #include "HandleSys.h" ds@580: #include "sm_srvcmds.h" ds@580: #include "sm_stringutil.h" ds@580: #include ds@580: ds@580: ConVarManager g_ConVarManager; ds@580: ds@696: SH_DECL_HOOK5_void(IServerGameDLL, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); ds@696: SH_DECL_HOOK5_void(IServerPluginCallbacks, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); ds@696: ds@582: const ParamType CONVARCHANGE_PARAMS[] = {Param_Cell, Param_String, Param_String}; ds@582: typedef List ConVarList; ds@582: ds@696: ConVarManager::ConVarManager() : m_ConVarType(0), m_VSPIface(NULL), m_CanQueryConVars(false) ds@580: { ds@582: /* Create a convar lookup trie */ ds@580: m_ConVarCache = sm_trie_create(); ds@580: } ds@580: ds@580: ConVarManager::~ConVarManager() ds@580: { ds@580: List::iterator iter; ds@580: ds@582: /* Destroy our convar lookup trie */ ds@580: sm_trie_destroy(m_ConVarCache); ds@580: ds@582: /* Destroy all the ConVarInfo structures */ ds@580: for (iter = m_ConVars.begin(); iter != m_ConVars.end(); iter++) ds@580: { ds@580: delete (*iter); ds@580: } ds@580: ds@580: m_ConVars.clear(); ds@580: } ds@580: ds@580: void ConVarManager::OnSourceModAllInitialized() ds@580: { ds@696: /* Only valid with ServerGameDLL006 or greater */ ds@696: if (g_SMAPI->GetGameDLLVersion() >= 6) ds@696: { ds@696: SH_ADD_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false); ds@696: m_CanQueryConVars = true; ds@696: } ds@696: ds@580: HandleAccess sec; ds@580: ds@582: /* Set up access rights for the 'ConVar' handle type */ ds@580: sec.access[HandleAccess_Read] = 0; ds@580: sec.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; ds@580: sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; ds@580: ds@582: /* Create the 'ConVar' handle type */ ds@580: m_ConVarType = g_HandleSys.CreateType("ConVar", this, 0, NULL, &sec, g_pCoreIdent, NULL); ds@580: ds@582: /* Add the 'convars' option to the 'sm' console command */ ds@990: g_RootMenu.AddRootConsoleCommand("cvars", "View convars created by a plugin", this); ds@580: } ds@580: ds@580: void ConVarManager::OnSourceModShutdown() ds@580: { ds@696: if (m_CanQueryConVars) ds@696: { ds@696: SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false); ds@696: SH_REMOVE_HOOK_MEMFUNC(IServerPluginCallbacks, OnQueryCvarValueFinished, m_VSPIface, this, &ConVarManager::OnQueryCvarValueFinished, false); ds@696: } ds@696: ds@580: IChangeableForward *fwd; ds@580: List::iterator i; ds@580: ds@582: /* Iterate list of ConVarInfo structures */ ds@580: for (i = m_ConVars.begin(); i != m_ConVars.end(); i++) ds@580: { ds@696: fwd = (*i)->pChangeForward; ds@580: ds@582: /* Free any convar-change forwards that still exist */ ds@580: if (fwd) ds@580: { ds@580: g_Forwards.ReleaseForward(fwd); ds@580: } ds@580: } ds@580: ds@582: /* Remove the 'convars' option from the 'sm' console command */ ds@990: g_RootMenu.RemoveRootConsoleCommand("cvars", this); ds@580: ds@582: /* Remove the 'ConVar' handle type */ ds@580: g_HandleSys.RemoveType(m_ConVarType, g_pCoreIdent); ds@580: } ds@580: ds@696: void ConVarManager::OnSourceModVSPReceived(IServerPluginCallbacks *iface) ds@696: { ds@696: /* This will be called after OnSourceModAllInitialized(), so... ds@696: * ds@696: * If we haven't been able to hook the IServerGameDLL version at this point, ds@696: * then use hook IServerPluginCallbacks version from the engine. ds@696: */ ds@696: ds@696: /* The Ship currently only supports ServerPluginCallbacks001, but we need 002 */ ds@696: if (g_IsOriginalEngine) ds@696: { ds@696: return; ds@696: } ds@696: ds@696: if (!m_CanQueryConVars) ds@696: { ds@696: m_VSPIface = iface; ds@696: ds@696: SH_ADD_HOOK_MEMFUNC(IServerPluginCallbacks, OnQueryCvarValueFinished, iface, this, &ConVarManager::OnQueryCvarValueFinished, false); ds@696: m_CanQueryConVars = true; ds@696: } ds@696: } ds@696: ds@582: void ConVarManager::OnPluginUnloaded(IPlugin *plugin) ds@580: { ds@582: ConVarList *pConVarList; ds@580: ds@582: /* If plugin has a convar list, free its memory */ ds@582: if (plugin->GetProperty("ConVarList", (void **)&pConVarList, true)) ds@580: { ds@582: delete pConVarList; ds@580: } ds@580: } ds@580: ds@580: void ConVarManager::OnHandleDestroy(HandleType_t type, void *object) ds@580: { ds@580: ConVarInfo *info; ds@580: ConVar *pConVar = static_cast(object); ds@580: ds@582: /* Find convar in lookup trie */ ds@580: sm_trie_retrieve(m_ConVarCache, pConVar->GetName(), reinterpret_cast(&info)); ds@580: ds@582: /* If convar was created by SourceMod plugin... */ ds@580: if (info->sourceMod) ds@580: { ds@582: /* Delete string allocations */ ds@580: delete [] pConVar->GetName(); ds@580: delete [] pConVar->GetDefault(); ds@580: delete [] pConVar->GetHelpText(); ds@580: ds@582: /* Then unlink it from SourceMM */ ds@580: g_SMAPI->UnregisterConCmdBase(g_PLAPI, pConVar); ds@580: } ds@580: } ds@580: ds@580: void ConVarManager::OnRootConsoleCommand(const char *command, unsigned int argcount) ds@580: { ds@580: if (argcount >= 3) ds@580: { ds@582: /* Get plugin index that was passed */ ds@582: int id = atoi(g_RootMenu.GetArgument(2)); ds@580: ds@582: /* Get plugin object */ ds@582: CPlugin *plugin = g_PluginSys.GetPluginByOrder(id); ds@582: ds@582: if (!plugin) ds@580: { ds@582: g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id); ds@580: return; ds@580: } ds@580: ds@582: /* Get plugin name */ ds@582: const sm_plugininfo_t *plinfo = plugin->GetPublicInfo(); ds@582: const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : plugin->GetFilename(); ds@580: ds@582: ConVarList *pConVarList; ds@582: ConVarList::iterator iter; ds@580: ds@582: /* If no convar list... */ ds@582: if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) ds@580: { ds@582: g_RootMenu.ConsolePrint("[SM] No convars found for: %s", plname); ds@580: return; ds@580: } ds@580: ds@582: g_RootMenu.ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname); ds@582: g_RootMenu.ConsolePrint(" %-32.31s %s", "[Name]", "[Value]"); ds@580: ds@582: /* Iterate convar list and display each one */ ds@582: for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) ds@580: { ds@582: const ConVar *pConVar = (*iter); ds@582: g_RootMenu.ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString()); ds@580: } ds@580: ds@580: return; ds@580: } ds@580: ds@582: /* Display usage of subcommand */ ds@580: g_RootMenu.ConsolePrint("[SM] Usage: sm convars "); ds@580: } ds@580: ds@582: 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: { ds@580: ConVar *pConVar = NULL; ds@582: ConVarInfo *pInfo = NULL; ds@580: Handle_t hndl = 0; ds@580: ds@582: /* Find out if the convar exists already */ ds@580: pConVar = icvar->FindVar(name); ds@580: ds@582: /* If the convar already exists... */ ds@582: if (pConVar) ds@580: { ds@759: /* Add convar to plugin's list */ ds@759: AddConVarToPluginList(pContext, pConVar); ds@759: ds@582: /* First find out if we already have a handle to it */ ds@582: if (sm_trie_retrieve(m_ConVarCache, name, (void **)&pInfo)) ds@580: { ds@582: return pInfo->handle; ds@580: } else { ds@582: /* If we don't, then create a new handle from the convar */ ds@580: hndl = g_HandleSys.CreateHandle(m_ConVarType, pConVar, NULL, g_pCoreIdent, NULL); ds@580: ds@582: /* Create and initialize ConVarInfo structure */ ds@582: pInfo = new ConVarInfo(); ds@582: pInfo->handle = hndl; ds@582: pInfo->sourceMod = false; ds@696: pInfo->pChangeForward = NULL; ds@582: pInfo->origCallback = pConVar->GetCallback(); ds@580: ds@582: /* Insert struct into caches */ ds@582: m_ConVars.push_back(pInfo); ds@582: sm_trie_insert(m_ConVarCache, name, pInfo); ds@580: ds@580: return hndl; ds@580: } ds@580: } ds@580: ds@696: /* To prevent creating a convar that has the same name as a console command... ugh */ ds@580: ConCommandBase *pBase = icvar->GetCommands(); ds@580: ds@580: while (pBase) ds@580: { ds@582: if (pBase->IsCommand() && strcmp(pBase->GetName(), name) == 0) ds@580: { ds@582: return BAD_HANDLE; ds@580: } ds@580: ds@580: pBase = const_cast(pBase->GetNext()); ds@580: } ds@580: ds@582: /* Since an existing convar (or concmd with the same name) was not found , now we can finally create it */ ds@582: pConVar = new ConVar(sm_strdup(name), sm_strdup(defaultVal), flags, sm_strdup(description), hasMin, min, hasMax, max); ds@580: ds@582: /* Add convar to plugin's list */ ds@582: AddConVarToPluginList(pContext, pConVar); ds@580: ds@582: /* Create a handle from the new convar */ ds@580: hndl = g_HandleSys.CreateHandle(m_ConVarType, pConVar, NULL, g_pCoreIdent, NULL); ds@580: ds@582: /* Create and initialize ConVarInfo structure */ ds@582: pInfo = new ConVarInfo(); ds@582: pInfo->handle = hndl; ds@582: pInfo->sourceMod = true; ds@696: pInfo->pChangeForward = NULL; ds@582: pInfo->origCallback = NULL; ds@580: ds@582: /* Insert struct into caches */ ds@582: m_ConVars.push_back(pInfo); ds@582: sm_trie_insert(m_ConVarCache, name, pInfo); ds@580: ds@580: return hndl; ds@580: } ds@580: ds@580: Handle_t ConVarManager::FindConVar(const char *name) ds@580: { ds@580: ConVar *pConVar = NULL; ds@582: ConVarInfo *pInfo; ds@582: Handle_t hndl; ds@580: ds@582: /* Search for convar */ ds@580: pConVar = icvar->FindVar(name); ds@580: ds@582: /* If it doesn't exist, then return an invalid handle */ ds@582: if (!pConVar) ds@580: { ds@580: return BAD_HANDLE; ds@580: } ds@580: ds@582: /* At this point, the convar exists. So, find out if we already have a handle */ ds@582: if (sm_trie_retrieve(m_ConVarCache, name, (void **)&pInfo)) ds@580: { ds@582: return pInfo->handle; ds@580: } ds@580: ds@582: /* If we don't have a handle, then create a new one */ ds@580: hndl = g_HandleSys.CreateHandle(m_ConVarType, pConVar, NULL, g_pCoreIdent, NULL); ds@580: ds@729: /* Create and initialize ConVarInfo structure */ ds@582: pInfo = new ConVarInfo(); ds@582: pInfo->handle = hndl; ds@582: pInfo->sourceMod = false; ds@696: pInfo->pChangeForward = NULL; ds@582: pInfo->origCallback = pConVar->GetCallback(); ds@580: ds@582: /* Insert struct into our caches */ ds@582: m_ConVars.push_back(pInfo); ds@582: sm_trie_insert(m_ConVarCache, name, pInfo); ds@580: ds@580: return hndl; ds@580: } ds@580: ds@582: void ConVarManager::HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction) ds@580: { ds@582: ConVarInfo *pInfo; ds@582: IChangeableForward *pForward; ds@580: ds@582: /* Find the convar in the lookup trie */ ds@582: if (sm_trie_retrieve(m_ConVarCache, pConVar->GetName(), (void **)&pInfo)) ds@580: { ds@582: /* Get the forward */ ds@696: pForward = pInfo->pChangeForward; ds@580: ds@582: /* If forward does not exist, create it */ ds@582: if (!pForward) ds@582: { ds@582: pForward = g_Forwards.CreateForwardEx(NULL, ET_Ignore, 3, CONVARCHANGE_PARAMS); ds@696: pInfo->pChangeForward = pForward; ds@580: ds@582: /* Install our own callback */ ds@580: pConVar->InstallChangeCallback(OnConVarChanged); ds@580: } ds@582: ds@582: /* Add function to forward's list */ ds@582: pForward->AddFunction(pFunction); ds@580: } ds@580: } ds@580: ds@582: void ConVarManager::UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction) ds@580: { ds@582: ConVarInfo *pInfo; ds@582: IChangeableForward *pForward; ds@582: IPluginContext *pContext = pFunction->GetParentContext(); ds@580: ds@582: /* Find the convar in the lookup trie */ ds@582: if (sm_trie_retrieve(m_ConVarCache, pConVar->GetName(), (void **)&pInfo)) ds@580: { ds@582: /* Get the forward */ ds@696: pForward = pInfo->pChangeForward; ds@580: ds@582: /* If the forward doesn't exist, we can't unhook anything */ ds@582: if (!pForward) ds@580: { ds@580: pContext->ThrowNativeError("Convar \"%s\" has no active hook", pConVar->GetName()); ds@580: return; ds@580: } ds@580: ds@582: /* Remove the function from the forward's list */ ds@582: if (!pForward->RemoveFunction(pFunction)) ds@580: { ds@580: pContext->ThrowNativeError("Invalid hook callback specified for convar \"%s\"", pConVar->GetName()); ds@580: return; ds@580: } ds@580: ds@582: /* If the forward now has 0 functions in it... */ ds@582: if (pForward->GetFunctionCount() == 0) ds@580: { ds@582: /* Free this forward */ ds@582: g_Forwards.ReleaseForward(pForward); ds@696: pInfo->pChangeForward = NULL; ds@582: ds@582: /* Put back the original convar callback */ ds@582: pConVar->InstallChangeCallback(pInfo->origCallback); ds@582: } ds@582: } ds@582: } ds@582: ds@696: QueryCvarCookie_t ConVarManager::QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback, Handle_t hndl) ds@696: { ds@696: QueryCvarCookie_t cookie; ds@696: ds@696: /* Call StartQueryCvarValue() in either the IVEngineServer or IServerPluginHelpers depending on situation */ ds@696: if (!m_VSPIface) ds@696: { ds@696: cookie = engine->StartQueryCvarValue(pPlayer, name); ds@696: } else { ds@696: cookie = serverpluginhelpers->StartQueryCvarValue(pPlayer, name); ds@696: } ds@696: ds@696: ConVarQuery query = {cookie, pCallback, hndl}; ds@696: m_ConVarQueries.push_back(query); ds@696: ds@696: return cookie; ds@696: } ds@696: ds@582: void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar) ds@582: { ds@582: ConVarList *pConVarList; ds@582: ConVarList::iterator iter; ds@582: bool inserted = false; ds@582: const char *orig = pConVar->GetName(); ds@582: ds@582: IPlugin *plugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); ds@580: ds@582: /* Check plugin for an existing convar list */ ds@582: if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) ds@582: { ds@582: pConVarList = new ConVarList(); ds@582: plugin->SetProperty("ConVarList", pConVarList); ds@867: } else if (pConVarList->find(pConVar) != pConVarList->end()) { ds@867: /* If convar is already in list, then don't add it */ ds@867: return; ds@582: } ds@582: ds@582: /* Insert convar into list which is sorted alphabetically */ ds@582: for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) ds@582: { ds@582: if (strcmp(orig, (*iter)->GetName()) < 0) ds@582: { ds@582: pConVarList->insert(iter, pConVar); ds@582: inserted = true; ds@582: break; ds@580: } ds@580: } ds@582: ds@582: if (!inserted) ds@582: { ds@582: pConVarList->push_back(pConVar); ds@582: } ds@580: } ds@580: ds@580: void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue) ds@580: { ds@582: /* If the values are the same, exit early in order to not trigger callbacks */ ds@580: if (strcmp(pConVar->GetString(), oldValue) == 0) ds@580: { ds@580: return; ds@580: } ds@580: ds@582: Trie *pCache = g_ConVarManager.GetConVarCache(); ds@582: ConVarInfo *pInfo; ds@580: ds@582: /* Find the convar in the lookup trie */ ds@582: sm_trie_retrieve(pCache, pConVar->GetName(), (void **)&pInfo); ds@580: ds@582: FnChangeCallback origCallback = pInfo->origCallback; ds@696: IChangeableForward *pForward = pInfo->pChangeForward; ds@580: ds@582: /* If there was a change callback installed previously, call it */ ds@580: if (origCallback) ds@580: { ds@580: origCallback(pConVar, oldValue); ds@580: } ds@580: ds@582: /* Now call forwards in plugins that have hooked this */ ds@582: pForward->PushCell(pInfo->handle); ds@582: pForward->PushString(oldValue); ds@582: pForward->PushString(pConVar->GetString()); ds@582: pForward->Execute(NULL); ds@580: } ds@627: ds@696: void ConVarManager::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue) ds@696: { ds@696: IPluginFunction *pCallback = NULL; ds@696: cell_t value = 0; ds@696: List::iterator iter; ds@696: ds@696: for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end(); iter++) ds@696: { ds@696: ConVarQuery &query = (*iter); ds@696: ds@696: if (query.cookie == cookie) ds@696: { ds@696: pCallback = query.pCallback; ds@696: value = query.value; ds@696: ds@696: break; ds@696: } ds@696: } ds@696: ds@696: if (pCallback) ds@696: { ds@696: cell_t ret; ds@696: ds@696: pCallback->PushCell(cookie); ds@696: pCallback->PushCell(engine->IndexOfEdict(pPlayer)); ds@696: pCallback->PushCell(result); ds@696: pCallback->PushString(cvarName); ds@696: ds@696: if (result == eQueryCvarValueStatus_ValueIntact) ds@696: { ds@696: pCallback->PushString(cvarValue); ds@696: } else { ds@696: pCallback->PushString("\0"); ds@696: } ds@696: ds@696: pCallback->PushCell(value); ds@696: pCallback->Execute(&ret); ds@696: ds@696: m_ConVarQueries.erase(iter); ds@696: } ds@696: } ds@696: ds@696: ds@627: static int s_YamagramState = 0; ds@627: ds@627: void _YamagramPrinterTwoPointOhOh(int yamagram) ds@627: { ds@627: switch (yamagram) ds@627: { ds@627: case 0: ds@627: g_RootMenu.ConsolePrint("Answer the following questions correctly and Gaben may not eat you after all."); ds@627: g_RootMenu.ConsolePrint("You will be given one hint in the form of my patented yamagrams."); ds@627: g_RootMenu.ConsolePrint("Type sm_nana to see the last question."); ds@627: g_RootMenu.ConsolePrint("Type sm_nana to attempt an answer of the question."); ds@627: g_RootMenu.ConsolePrint("-------------------------------"); ds@627: _YamagramPrinterTwoPointOhOh(1); ds@627: return; ds@627: case 1: ds@627: g_RootMenu.ConsolePrint("Question Ichi (1)"); ds@627: g_RootMenu.ConsolePrint("One can turn into a cow by doing what action?"); ds@627: g_RootMenu.ConsolePrint("Hint: AGE SANS GRIT"); ds@627: break; ds@627: case 2: ds@627: g_RootMenu.ConsolePrint("Question Ni (2)"); ds@627: g_RootMenu.ConsolePrint("What kind of hat should you wear when using the Internet?"); ds@627: g_RootMenu.ConsolePrint("Hint: BRR MOOSE"); ds@627: break; ds@627: case 3: ds@627: g_RootMenu.ConsolePrint("Question San (3)"); ds@627: g_RootMenu.ConsolePrint("Who is the lead developer of SourceMod?"); ds@627: g_RootMenu.ConsolePrint("Hint: VEAL BANDANA DID RIP SOON"); ds@627: break; ds@627: case 4: ds@627: g_RootMenu.ConsolePrint("Question Yon (4)"); ds@627: g_RootMenu.ConsolePrint("A terrible translation of 'SVN Revision' to Japanese romaji might be ..."); ds@627: g_RootMenu.ConsolePrint("Hint: I TAKE IN AN AIR OK"); ds@627: break; ds@627: case 5: ds@627: g_RootMenu.ConsolePrint("Question Go (5)"); ds@627: g_RootMenu.ConsolePrint("What is a fundamental concept in the game of Go?"); ds@628: g_RootMenu.ConsolePrint("Hint: AD LADEN THIEF"); ds@627: break; ds@627: case 6: ds@627: g_RootMenu.ConsolePrint("Question Roku (6)"); ds@627: g_RootMenu.ConsolePrint("Why am I asking all these strange questions?"); ds@627: g_RootMenu.ConsolePrint("Hint: CHUBBY TITAN EATS EWE WAGE DATA"); ds@627: break; ds@627: case 7: ds@627: g_RootMenu.ConsolePrint("Question Nana (7)"); ds@627: g_RootMenu.ConsolePrint("What is my name?"); ds@627: g_RootMenu.ConsolePrint("Hint: AD MODE LAG US"); ds@627: break; ds@627: default: ds@627: break; ds@627: } ds@627: ds@627: s_YamagramState = yamagram; ds@627: } ds@627: ds@627: void _IntExt_CallYamagrams() ds@627: { ds@627: bool correct = false; ds@627: const char *arg = engine->Cmd_Args(); ds@627: ds@627: if (!arg || arg[0] == '\0') ds@627: { ds@627: _YamagramPrinterTwoPointOhOh(s_YamagramState); ds@627: return; ds@627: } ds@627: ds@627: switch (s_YamagramState) ds@627: { ds@627: case 1: ds@627: correct = !strcasecmp(arg, "eating grass"); ds@627: break; ds@627: case 2: ds@627: correct = !strcasecmp(arg, "sombrero"); ds@627: break; ds@627: case 3: ds@627: correct = !strcasecmp(arg, "david bailopan anderson"); ds@627: break; ds@627: case 4: ds@627: correct = !strcasecmp(arg, "kaitei no kairan"); ds@627: break; ds@627: case 5: ds@628: correct = !strcasecmp(arg, "life and death"); ds@627: break; ds@627: case 6: ds@627: correct = !strcasecmp(arg, "because gabe wanted it that way"); ds@627: if (correct) ds@627: { ds@627: g_RootMenu.ConsolePrint("Congratulations, you have answered 6 of my questions."); ds@627: g_RootMenu.ConsolePrint("However, I have one final question for you. It wouldn't be nana without it."); ds@627: g_RootMenu.ConsolePrint("-------------------------------"); ds@627: _YamagramPrinterTwoPointOhOh(7); ds@627: return; ds@627: } ds@627: break; ds@627: case 7: ds@627: correct = !strcasecmp(arg, "damaged soul"); ds@627: if (correct) ds@627: { ds@627: g_RootMenu.ConsolePrint("You don't know how lucky you are to still be alive!"); ds@627: g_RootMenu.ConsolePrint("Congratulations. You have answered all 7 questions correctly."); ds@627: g_RootMenu.ConsolePrint("The SourceMod Dev Team will be at your door with anti-Gaben grenades"); ds@627: g_RootMenu.ConsolePrint("within seconds. You will also be provided with a rocket launcher,"); ds@627: g_RootMenu.ConsolePrint("just in case Alfred decides to strike you with a blitzkrieg in retaliation."); ds@627: ds@627: s_YamagramState = 0; ds@627: return; ds@627: } ds@627: break; ds@627: default: ds@627: break; ds@627: } ds@627: ds@627: if (s_YamagramState > 0) ds@627: { ds@627: if (correct) ds@627: { ds@627: g_RootMenu.ConsolePrint("Correct! You are one step closer to avoiding the deadly jaws of Gaben."); ds@627: g_RootMenu.ConsolePrint("-------------------------------"); ds@627: s_YamagramState++; ds@627: } else { ds@627: g_RootMenu.ConsolePrint("Wrong! You better be more careful. Gaben may be at your door at any minute."); ds@627: return; ds@627: } ds@627: } ds@627: ds@627: _YamagramPrinterTwoPointOhOh(s_YamagramState); ds@627: } ds@627: ds@627: void _IntExt_EnableYamagrams() ds@627: { ds@627: static ConCommand *pCmd = NULL; ds@627: if (!pCmd) ds@627: { ds@627: pCmd = new ConCommand("sm_nana", _IntExt_CallYamagrams, "Try these yamagrams!", FCVAR_GAMEDLL); ds@627: g_RootMenu.ConsolePrint("[SM] Warning: Gaben has been alerted of your actions. You may be eaten."); ds@627: } else { ds@627: g_RootMenu.ConsolePrint("[SM] Gaben has already been alerted of your actions..."); ds@627: } ds@627: } ds@627: ds@627: void _IntExt_OnHostnameChanged(ConVar *pConVar, char const *oldValue) ds@627: { ds@627: if (strcmp(oldValue, "Good morning, DS-san.") == 0 ds@627: && strcmp(pConVar->GetString(), "Good night, talking desk lamp.") == 0) ds@627: { ds@627: _IntExt_EnableYamagrams(); ds@627: } ds@627: }