Added a load-block for incorrect mods to TF2 and cstrike extensions.
3 * =============================================================================
4 * SourceMod Team Fortress 2 Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "extension.h"
34 #include "RegNatives.h"
35 #include "iplayerinfo.h"
36 #include "sm_trie_tpl.h"
37 #include "criticals.h"
41 * @brief Implement extension code here.
46 IGameConfig *g_pGameConf = NULL;
48 IBinTools *g_pBinTools = NULL;
50 SMEXT_LINK(&g_TF2Tools);
54 CGlobalVars *gpGlobals = NULL;
56 sm_sendprop_info_t *playerSharedOffset;
58 extern sp_nativeinfo_t g_TFNatives[];
62 SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int , int);
64 bool TF2Tools::SDK_OnLoad(char *error, size_t maxlength, bool late)
66 if (strcmp(g_pSM->GetGameFolderName(), "tf") != 0)
68 snprintf(error, maxlength, "Cannot Load TF2 Extension on mods other than TF2");
72 ServerClass *sc = UTIL_FindServerClass("CTFPlayer");
75 snprintf(error, maxlength, "Could not find CTFPlayer server class");
79 playerSharedOffset = new sm_sendprop_info_t;
81 if (!UTIL_FindDataTable(sc->m_pTable, "DT_TFPlayerShared", playerSharedOffset, 0))
83 snprintf(error, maxlength, "Could not find DT_TFPlayerShared data table");
87 sharesys->AddDependency(myself, "bintools.ext", true, true);
90 if (!gameconfs->LoadGameConfigFile("sm-tf2.games", &g_pGameConf, conf_error, sizeof(conf_error)))
94 snprintf(error, maxlength, "Could not read sm-tf2.games.txt: %s", conf_error);
99 sharesys->AddNatives(myself, g_TFNatives);
100 sharesys->RegisterLibrary(myself, "tf2");
102 playerhelpers->RegisterCommandTargetProcessor(this);
104 spengine = g_pSM->GetScriptingEngine();
111 bool TF2Tools::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
113 GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
115 gpGlobals = ismm->GetCGlobals();
117 SH_ADD_HOOK(IServerGameDLL, ServerActivate, gamedll, SH_STATIC(OnServerActivate), true);
119 GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
121 GET_V_IFACE_CURRENT(GetServerFactory, gameents, IServerGameEnts, INTERFACEVERSION_SERVERGAMEENTS);
126 void TF2Tools::SDK_OnUnload()
128 SH_REMOVE_HOOK(IServerGameDLL, ServerActivate, gamedll, SH_STATIC(OnServerActivate), true);
130 g_RegNatives.UnregisterAll();
131 gameconfs->CloseGameConfigFile(g_pGameConf);
132 playerhelpers->UnregisterCommandTargetProcessor(this);
135 void TF2Tools::SDK_OnAllLoaded()
137 SM_GET_LATE_IFACE(BINTOOLS, g_pBinTools);
139 g_CriticalHitManager.Init();
142 bool TF2Tools::RegisterConCommandBase(ConCommandBase *pVar)
144 return g_SMAPI->RegisterConCommandBase(g_PLAPI, pVar);
148 bool TF2Tools::QueryRunning(char *error, size_t maxlength)
150 SM_CHECK_IFACE(BINTOOLS, g_pBinTools);
155 bool TF2Tools::QueryInterfaceDrop(SMInterface *pInterface)
157 if (pInterface == g_pBinTools)
162 return IExtensionInterface::QueryInterfaceDrop(pInterface);
165 void TF2Tools::NotifyInterfaceDrop(SMInterface *pInterface)
167 g_RegNatives.UnregisterAll();
170 void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
172 g_resourceEntity = FindResourceEntity();
176 bool TF2Tools::ProcessCommandTarget(cmd_target_info_t *info)
180 unsigned int team_index = 0;
181 IGamePlayer *pPlayer, *pAdmin;
183 if ((info->flags & COMMAND_FILTER_NO_MULTI) == COMMAND_FILTER_NO_MULTI)
190 if ((pAdmin = playerhelpers->GetGamePlayer(info->admin)) == NULL)
194 if (!pAdmin->IsInGame())
204 if (strcmp(info->pattern, "@red") == 0 )
208 else if (strcmp(info->pattern, "@blue") == 0)
217 info->num_targets = 0;
219 max_clients = playerhelpers->GetMaxClients();
221 i <= max_clients && (cell_t)info->num_targets < info->max_targets;
224 if ((pPlayer = playerhelpers->GetGamePlayer(i)) == NULL)
228 if (!pPlayer->IsInGame())
232 if ((pInfo = pPlayer->GetPlayerInfo()) == NULL)
236 if (pInfo->GetTeamIndex() != (int)team_index)
240 if (playerhelpers->FilterCommandTarget(pAdmin, pPlayer, info->flags)
241 != COMMAND_TARGET_VALID)
245 info->targets[info->num_targets] = i;
249 if (info->num_targets == 0)
251 info->reason = COMMAND_TARGET_EMPTY_FILTER;
255 info->reason = COMMAND_TARGET_VALID;
258 info->target_name_style = COMMAND_TARGETNAME_RAW;
261 UTIL_Format(info->target_name, info->target_name_maxlength, "Red Team");
263 else if (team_index == 3)
265 UTIL_Format(info->target_name, info->target_name_maxlength, "Blue Team");
271 int FindResourceEntity()
273 return FindEntityByNetClass(-1, "CTFPlayerResource");
277 int FindEntityByNetClass(int start, const char *classname)
281 for (int i = ((start != -1) ? start : 0); i < gpGlobals->maxEntities; i++)
283 current = engine->PEntityOfEntIndex(i);
289 IServerNetworkable *network = current->GetNetworkable();
296 ServerClass *sClass = network->GetServerClass();
297 const char *name = sClass->GetName();
300 if (strcmp(name, classname) == 0)
309 TFClassType ClassnameToType(const char *classname)
311 static KTrie<TFClassType> trie;
312 static bool filled = false;
316 trie.insert("scout", TFClass_Scout);
317 trie.insert("sniper", TFClass_Sniper);
318 trie.insert("soldier", TFClass_Soldier);
319 trie.insert("demoman", TFClass_DemoMan);
320 trie.insert("demo", TFClass_DemoMan);
321 trie.insert("medic", TFClass_Medic);
322 trie.insert("heavy", TFClass_Heavy);
323 trie.insert("hwg", TFClass_Heavy);
324 trie.insert("pyro", TFClass_Pyro);
325 trie.insert("spy", TFClass_Spy);
326 trie.insert("engineer", TFClass_Engineer);
327 trie.insert("engy", TFClass_Engineer);
334 if (!(value = trie.retrieve(classname)))
336 return TFClass_Unknown;
345 * A picture of a blue crab given to me as a gift and stored here for safe keeping
347 * http://www.democracycellproject.net/blog/archives/Clown%20car.jpg