core/systems/ExtensionSys.cpp
branchrefac-jit
changeset 2284 026da5437111
parent 2192 7602d7fb60d9
child 2288 15c77b21589a
     1.1 --- a/core/systems/ExtensionSys.cpp	Fri Jul 11 06:51:21 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,1205 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod
     1.8 - * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     1.9 - * =============================================================================
    1.10 - *
    1.11 - * This program is free software; you can redistribute it and/or modify it under
    1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 - * Free Software Foundation.
    1.14 - * 
    1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 - * details.
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License along with
    1.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 - *
    1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 - * or <http://www.sourcemod.net/license.php>.
    1.31 - *
    1.32 - * Version: $Id$
    1.33 - */
    1.34 -
    1.35 -#include <stdlib.h>
    1.36 -#include "ExtensionSys.h"
    1.37 -#include "LibrarySys.h"
    1.38 -#include "ShareSys.h"
    1.39 -#include "Logger.h"
    1.40 -#include "sourcemm_api.h"
    1.41 -#include "sm_srvcmds.h"
    1.42 -#include "sm_stringutil.h"
    1.43 -
    1.44 -CExtensionManager g_Extensions;
    1.45 -IdentityType_t g_ExtType;
    1.46 -
    1.47 -void CExtension::Initialize(const char *filename, const char *path)
    1.48 -{
    1.49 -	m_pAPI = NULL;
    1.50 -	m_pIdentToken = NULL;
    1.51 -	unload_code = 0;
    1.52 -	m_bFullyLoaded = false;
    1.53 -	m_File.assign(filename);
    1.54 -	m_Path.assign(path);
    1.55 -}
    1.56 -
    1.57 -CRemoteExtension::CRemoteExtension(IExtensionInterface *pAPI, const char *filename, const char *path)
    1.58 -{
    1.59 -	Initialize(filename, path);
    1.60 -	m_pAPI = pAPI;
    1.61 -}
    1.62 -
    1.63 -CLocalExtension::CLocalExtension(const char *filename)
    1.64 -{
    1.65 -	m_PlId = 0;
    1.66 -	m_pLib = NULL;
    1.67 -
    1.68 -	char path[PLATFORM_MAX_PATH];
    1.69 -
    1.70 -	/* First see if there is an engine specific build! */
    1.71 -	g_SourceMod.BuildPath(Path_SM, 
    1.72 -		path, 
    1.73 -		PLATFORM_MAX_PATH, 
    1.74 -#if defined METAMOD_PLAPI_VERSION
    1.75 -#if defined ORANGEBOX_BUILD
    1.76 -		"extensions/auto.2.ep2/%s",
    1.77 -#else
    1.78 -		"extensions/auto.2.ep1/%s",
    1.79 -#endif //ORANGEBOX_BUILD
    1.80 -#else  //METAMOD_PLAPI_VERSION
    1.81 -		"extensions/auto.1.ep1/%s",
    1.82 -#endif //METAMOD_PLAPI_VERSION
    1.83 -		filename);
    1.84 -
    1.85 -	/* Try the "normal" version */
    1.86 -	if (!g_LibSys.IsPathFile(path))
    1.87 -	{
    1.88 -		g_SourceMod.BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "extensions/%s", filename);
    1.89 -	}
    1.90 -
    1.91 -	Initialize(filename, path);
    1.92 -}
    1.93 -
    1.94 -bool CRemoteExtension::Load(char *error, size_t maxlength)
    1.95 -{
    1.96 -	if (!PerformAPICheck(error, maxlength))
    1.97 -	{
    1.98 -		m_pAPI = NULL;
    1.99 -		return false;
   1.100 -	}
   1.101 -
   1.102 -	if (!CExtension::Load(error, maxlength))
   1.103 -	{
   1.104 -		m_pAPI = NULL;
   1.105 -		return false;
   1.106 -	}
   1.107 -
   1.108 -	return true;
   1.109 -}
   1.110 -
   1.111 -bool CLocalExtension::Load(char *error, size_t maxlength)
   1.112 -{
   1.113 -	m_pLib = g_LibSys.OpenLibrary(m_Path.c_str(), error, maxlength);
   1.114 -
   1.115 -	if (m_pLib == NULL)
   1.116 -	{
   1.117 -		return false;
   1.118 -	}
   1.119 -
   1.120 -	typedef IExtensionInterface *(*GETAPI)();
   1.121 -	GETAPI pfnGetAPI = NULL;
   1.122 -
   1.123 -	if ((pfnGetAPI=(GETAPI)m_pLib->GetSymbolAddress("GetSMExtAPI")) == NULL)
   1.124 -	{
   1.125 -		m_pLib->CloseLibrary();
   1.126 -		m_pLib = NULL;
   1.127 -		snprintf(error, maxlength, "Unable to find extension entry point");
   1.128 -		return false;
   1.129 -	}
   1.130 -
   1.131 -	m_pAPI = pfnGetAPI();
   1.132 -
   1.133 -	/* Check pointer and version */
   1.134 -	if (!PerformAPICheck(error, maxlength))
   1.135 -	{
   1.136 -		m_pLib->CloseLibrary();
   1.137 -		m_pLib = NULL;
   1.138 -		m_pAPI = NULL;
   1.139 -		return false;
   1.140 -	}
   1.141 -
   1.142 -	/* Load as MM:S */
   1.143 -	if (m_pAPI->IsMetamodExtension())
   1.144 -	{
   1.145 -		bool already;
   1.146 -		m_PlId = g_pMMPlugins->Load(m_Path.c_str(), g_PLID, already, error, maxlength);
   1.147 -	}
   1.148 -
   1.149 -	if (!CExtension::Load(error, maxlength))
   1.150 -	{
   1.151 -		if (m_pAPI->IsMetamodExtension())
   1.152 -		{
   1.153 -			if (m_PlId)
   1.154 -			{
   1.155 -				char dummy[255];
   1.156 -				g_pMMPlugins->Unload(m_PlId, true, dummy, sizeof(dummy));
   1.157 -				m_PlId = 0;
   1.158 -			}
   1.159 -		}
   1.160 -		m_pLib->CloseLibrary();
   1.161 -		m_pLib = NULL;
   1.162 -		m_pAPI = NULL;
   1.163 -		return false;
   1.164 -	}
   1.165 -
   1.166 -	return true;
   1.167 -}
   1.168 -
   1.169 -void CRemoteExtension::Unload()
   1.170 -{
   1.171 -}
   1.172 -
   1.173 -void CLocalExtension::Unload()
   1.174 -{
   1.175 -	if (m_pAPI != NULL && m_PlId)
   1.176 -	{
   1.177 -		char temp_buffer[255];
   1.178 -		g_pMMPlugins->Unload(m_PlId, true, temp_buffer, sizeof(temp_buffer));
   1.179 -		m_PlId = 0;
   1.180 -	}
   1.181 -
   1.182 -	if (m_pLib != NULL)
   1.183 -	{
   1.184 -		m_pLib->CloseLibrary();
   1.185 -		m_pLib = NULL;
   1.186 -	}
   1.187 -}
   1.188 -
   1.189 -bool CRemoteExtension::IsExternal()
   1.190 -{
   1.191 -	return true;
   1.192 -}
   1.193 -
   1.194 -bool CLocalExtension::IsExternal()
   1.195 -{
   1.196 -	return false;
   1.197 -}
   1.198 -
   1.199 -CExtension::~CExtension()
   1.200 -{
   1.201 -	DestroyIdentity();
   1.202 -}
   1.203 -
   1.204 -bool CExtension::PerformAPICheck(char *error, size_t maxlength)
   1.205 -{
   1.206 -	if (!m_pAPI)
   1.207 -	{
   1.208 -		snprintf(error, maxlength, "No IExtensionInterface instance provided");
   1.209 -		return false;
   1.210 -	}
   1.211 -	
   1.212 -	if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION)
   1.213 -	{
   1.214 -		snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
   1.215 -		return false;
   1.216 -	}
   1.217 -
   1.218 -	return true;
   1.219 -}
   1.220 -
   1.221 -bool CExtension::Load(char *error, size_t maxlength)
   1.222 -{
   1.223 -	CreateIdentity();
   1.224 -	if (!m_pAPI->OnExtensionLoad(this, &g_ShareSys, error, maxlength, !g_SourceMod.IsMapLoading()))
   1.225 -	{
   1.226 -		DestroyIdentity();
   1.227 -		return false;
   1.228 -	}
   1.229 -	else
   1.230 -	{
   1.231 -		/* Check if we're past load time */
   1.232 -		if (!g_SourceMod.IsMapLoading())
   1.233 -		{
   1.234 -			m_pAPI->OnExtensionsAllLoaded();
   1.235 -		}
   1.236 -	}
   1.237 -
   1.238 -	return true;
   1.239 -}
   1.240 -
   1.241 -void CExtension::CreateIdentity()
   1.242 -{
   1.243 -	if (m_pIdentToken != NULL)
   1.244 -	{
   1.245 -		return;
   1.246 -	}
   1.247 -
   1.248 -	m_pIdentToken = g_ShareSys.CreateIdentity(g_ExtType, this);
   1.249 -}
   1.250 -
   1.251 -void CExtension::DestroyIdentity()
   1.252 -{
   1.253 -	if (m_pIdentToken == NULL)
   1.254 -	{
   1.255 -		return;
   1.256 -	}
   1.257 -
   1.258 -	g_ShareSys.DestroyIdentity(m_pIdentToken);
   1.259 -	m_pIdentToken = NULL;
   1.260 -}
   1.261 -
   1.262 -void CExtension::MarkAllLoaded()
   1.263 -{
   1.264 -	assert(m_bFullyLoaded == false);
   1.265 -	if (!m_bFullyLoaded)
   1.266 -	{
   1.267 -		m_bFullyLoaded = true;
   1.268 -		m_pAPI->OnExtensionsAllLoaded();
   1.269 -	}
   1.270 -}
   1.271 -
   1.272 -void CExtension::AddPlugin(CPlugin *pPlugin)
   1.273 -{
   1.274 -	/* Unfortunately we have to do this :( */
   1.275 -	if (m_Dependents.find(pPlugin) != m_Dependents.end())
   1.276 -	{
   1.277 -		m_Dependents.push_back(pPlugin);
   1.278 -	}
   1.279 -}
   1.280 -
   1.281 -void CExtension::SetError(const char *error)
   1.282 -{
   1.283 -	m_Error.assign(error);
   1.284 -}
   1.285 -
   1.286 -IExtensionInterface *CExtension::GetAPI()
   1.287 -{
   1.288 -	return m_pAPI;
   1.289 -}
   1.290 -
   1.291 -const char *CExtension::GetFilename()
   1.292 -{
   1.293 -	return m_File.c_str();
   1.294 -}
   1.295 -
   1.296 -IdentityToken_t *CExtension::GetIdentity()
   1.297 -{
   1.298 -	return m_pIdentToken;
   1.299 -}
   1.300 -
   1.301 -bool CRemoteExtension::IsLoaded()
   1.302 -{
   1.303 -	return (m_pAPI != NULL);
   1.304 -}
   1.305 -
   1.306 -bool CLocalExtension::IsLoaded()
   1.307 -{
   1.308 -	return (m_pLib != NULL);
   1.309 -}
   1.310 -
   1.311 -void CExtension::AddDependency(const IfaceInfo *pInfo)
   1.312 -{
   1.313 -	if (m_Deps.find(*pInfo) == m_Deps.end())
   1.314 -	{
   1.315 -		m_Deps.push_back(*pInfo);
   1.316 -	}
   1.317 -}
   1.318 -
   1.319 -bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2)
   1.320 -{
   1.321 -	return (i1.iface == i2.iface) && (i1.owner == i2.owner);
   1.322 -}
   1.323 -
   1.324 -void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
   1.325 -{
   1.326 -	IfaceInfo info;
   1.327 -	info.iface = iface;
   1.328 -	info.owner = pOther;
   1.329 -
   1.330 -	List<IfaceInfo>::iterator iter;
   1.331 -	for (iter = m_ChildDeps.begin();
   1.332 -		 iter != m_ChildDeps.end();
   1.333 -		 iter++)
   1.334 -	{
   1.335 -		IfaceInfo &other = (*iter);
   1.336 -		if (other == info)
   1.337 -		{
   1.338 -			return;
   1.339 -		}
   1.340 -	}
   1.341 -
   1.342 -	m_ChildDeps.push_back(info);
   1.343 -}
   1.344 -
   1.345 -ITERATOR *CExtension::FindFirstDependency(IExtension **pOwner, SMInterface **pInterface)
   1.346 -{
   1.347 -	List<IfaceInfo>::iterator iter = m_Deps.begin();
   1.348 -
   1.349 -	if (iter == m_Deps.end())
   1.350 -	{
   1.351 -		return NULL;
   1.352 -	}
   1.353 -
   1.354 -	if (pOwner)
   1.355 -	{
   1.356 -		*pOwner = (*iter).owner;
   1.357 -	}
   1.358 -	if (pInterface)
   1.359 -	{
   1.360 -		*pInterface = (*iter).iface;
   1.361 -	}
   1.362 -
   1.363 -	List<IfaceInfo>::iterator *pIter = new List<IfaceInfo>::iterator(iter);
   1.364 -
   1.365 -	return (ITERATOR *)pIter;
   1.366 -}
   1.367 -
   1.368 -bool CExtension::FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface)
   1.369 -{
   1.370 -	List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
   1.371 -	List<IfaceInfo>::iterator _iter;
   1.372 -
   1.373 -	if (_iter == m_Deps.end())
   1.374 -	{
   1.375 -		return false;
   1.376 -	}
   1.377 -
   1.378 -	_iter++;
   1.379 -
   1.380 -	if (pOwner)
   1.381 -	{
   1.382 -		*pOwner = (*_iter).owner;
   1.383 -	}
   1.384 -	if (pInterface)
   1.385 -	{
   1.386 -		*pInterface = (*_iter).iface;
   1.387 -	}
   1.388 -
   1.389 -	*pIter = _iter;
   1.390 -
   1.391 -	if (_iter == m_Deps.end())
   1.392 -	{
   1.393 -		return false;
   1.394 -	}
   1.395 -
   1.396 -	return true;
   1.397 -}
   1.398 -
   1.399 -void CExtension::FreeDependencyIterator(ITERATOR *iter)
   1.400 -{
   1.401 -	List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
   1.402 -
   1.403 -	delete pIter;
   1.404 -}
   1.405 -
   1.406 -void CExtension::AddInterface(SMInterface *pInterface)
   1.407 -{
   1.408 -	m_Interfaces.push_back(pInterface);
   1.409 -}
   1.410 -
   1.411 -bool CExtension::IsRunning(char *error, size_t maxlength)
   1.412 -{
   1.413 -	if (!IsLoaded())
   1.414 -	{
   1.415 -		if (error)
   1.416 -		{
   1.417 -			snprintf(error, maxlength, "%s", m_Error.c_str());
   1.418 -		}
   1.419 -		return false;
   1.420 -	}
   1.421 -
   1.422 -	return m_pAPI->QueryRunning(error, maxlength);
   1.423 -}
   1.424 -
   1.425 -void CExtension::AddLibrary(const char *library)
   1.426 -{
   1.427 -	m_Libraries.push_back(library);
   1.428 -}
   1.429 -
   1.430 -/*********************
   1.431 - * EXTENSION MANAGER *
   1.432 - *********************/
   1.433 -
   1.434 -void CExtensionManager::OnSourceModAllInitialized()
   1.435 -{
   1.436 -	g_ExtType = g_ShareSys.CreateIdentType("EXTENSION");
   1.437 -	g_PluginSys.AddPluginsListener(this);
   1.438 -	g_RootMenu.AddRootConsoleCommand("exts", "Manage extensions", this);
   1.439 -	g_ShareSys.AddInterface(NULL, this);
   1.440 -}
   1.441 -
   1.442 -void CExtensionManager::OnSourceModShutdown()
   1.443 -{
   1.444 -	g_RootMenu.RemoveRootConsoleCommand("exts", this);
   1.445 -	g_ShareSys.DestroyIdentType(g_ExtType);
   1.446 -}
   1.447 -
   1.448 -void CExtensionManager::Shutdown()
   1.449 -{
   1.450 -	List<CExtension *>::iterator iter;
   1.451 -
   1.452 -	while ((iter = m_Libs.begin()) != m_Libs.end())
   1.453 -	{
   1.454 -		UnloadExtension((*iter));
   1.455 -	}
   1.456 -}
   1.457 -
   1.458 -void CExtensionManager::TryAutoload()
   1.459 -{
   1.460 -	char path[PLATFORM_MAX_PATH];
   1.461 -
   1.462 -	g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "extensions");
   1.463 -
   1.464 -	IDirectory *pDir = g_LibSys.OpenDirectory(path);
   1.465 -	if (!pDir)
   1.466 -	{
   1.467 -		return;
   1.468 -	}
   1.469 -
   1.470 -	const char *lfile;
   1.471 -	size_t len;
   1.472 -	while (pDir->MoreFiles())
   1.473 -	{
   1.474 -		if (pDir->IsEntryDirectory())
   1.475 -		{
   1.476 -			pDir->NextEntry();
   1.477 -			continue;
   1.478 -		}
   1.479 -
   1.480 -		lfile = pDir->GetEntryName();
   1.481 -		len = strlen(lfile);
   1.482 -		if (len <= 9) /* size of ".autoload" */
   1.483 -		{
   1.484 -			pDir->NextEntry();
   1.485 -			continue;
   1.486 -		}
   1.487 -
   1.488 -		if (strcmp(&lfile[len - 9], ".autoload") != 0)
   1.489 -		{
   1.490 -			pDir->NextEntry();
   1.491 -			continue;
   1.492 -		}
   1.493 -
   1.494 -		char file[PLATFORM_MAX_PATH];
   1.495 -		len = UTIL_Format(file, sizeof(file), "%s", lfile);
   1.496 -		strcpy(&file[len - 9], ".ext." PLATFORM_LIB_EXT);
   1.497 -
   1.498 -		LoadAutoExtension(file);
   1.499 -		
   1.500 -		pDir->NextEntry();
   1.501 -	}
   1.502 -}
   1.503 -
   1.504 -IExtension *CExtensionManager::LoadAutoExtension(const char *path)
   1.505 -{
   1.506 -	if (!strstr(path, "." PLATFORM_LIB_EXT))
   1.507 -	{
   1.508 -		char newpath[PLATFORM_MAX_PATH];
   1.509 -		g_LibSys.PathFormat(newpath, sizeof(newpath), "%s.%s", path, PLATFORM_LIB_EXT);
   1.510 -		return LoadAutoExtension(newpath);
   1.511 -	}
   1.512 -
   1.513 -	IExtension *pAlready;
   1.514 -	if ((pAlready=FindExtensionByFile(path)) != NULL)
   1.515 -	{
   1.516 -		return pAlready;
   1.517 -	}
   1.518 -
   1.519 -	char error[256];
   1.520 -	CExtension *p = new CLocalExtension(path);
   1.521 -
   1.522 -	/* We put us in the list beforehand so extensions that check for each other
   1.523 -	 * won't recursively load each other.
   1.524 -	 */
   1.525 -	m_Libs.push_back(p);
   1.526 -
   1.527 -	if (!p->Load(error, sizeof(error)) || !p->IsLoaded())
   1.528 -	{
   1.529 -		g_Logger.LogError("[SM] Unable to load extension \"%s\": %s", path, error);
   1.530 -		p->SetError(error);
   1.531 -	}
   1.532 -
   1.533 -	return p;
   1.534 -}
   1.535 -
   1.536 -IExtension *CExtensionManager::FindExtensionByFile(const char *file)
   1.537 -{
   1.538 -	List<CExtension *>::iterator iter;
   1.539 -	CExtension *pExt;
   1.540 -
   1.541 -	/* Chomp off the path */
   1.542 -	char lookup[PLATFORM_MAX_PATH];
   1.543 -	g_LibSys.GetFileFromPath(lookup, sizeof(lookup), file);
   1.544 -
   1.545 -	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   1.546 -	{
   1.547 -		pExt = (*iter);
   1.548 -		char short_file[PLATFORM_MAX_PATH];
   1.549 -		g_LibSys.GetFileFromPath(short_file, sizeof(short_file), pExt->GetFilename());
   1.550 -		if (strcmp(lookup, short_file) == 0)
   1.551 -		{
   1.552 -			return pExt;
   1.553 -		}
   1.554 -	}
   1.555 -
   1.556 -	/* If we got no results, test if there was a platform extension.
   1.557 -	 * If not, add one.
   1.558 -	 */
   1.559 -	if (!strstr(file, "." PLATFORM_LIB_EXT))
   1.560 -	{
   1.561 -		char path[PLATFORM_MAX_PATH];
   1.562 -		UTIL_Format(path, sizeof(path), "%s.%s", file, PLATFORM_LIB_EXT);
   1.563 -		return FindExtensionByFile(path);
   1.564 -	}
   1.565 -
   1.566 -	return NULL;
   1.567 -}
   1.568 -
   1.569 -IExtension *CExtensionManager::FindExtensionByName(const char *ext)
   1.570 -{
   1.571 -	List<CExtension *>::iterator iter;
   1.572 -	CExtension *pExt;
   1.573 -	IExtensionInterface *pAPI;
   1.574 -	const char *name;
   1.575 -
   1.576 -	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   1.577 -	{
   1.578 -		pExt = (*iter);
   1.579 -		if (!pExt->IsLoaded())
   1.580 -		{
   1.581 -			continue;
   1.582 -		}
   1.583 -		if ((pAPI = pExt->GetAPI()) == NULL)
   1.584 -		{
   1.585 -			continue;
   1.586 -		}
   1.587 -		name = pAPI->GetExtensionName();
   1.588 -		if (!name)
   1.589 -		{
   1.590 -			continue;
   1.591 -		}
   1.592 -		if (strcmp(name, ext) == 0)
   1.593 -		{
   1.594 -			return pExt;
   1.595 -		}
   1.596 -	}
   1.597 -
   1.598 -	return NULL;
   1.599 -}
   1.600 -
   1.601 -IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size_t maxlength)
   1.602 -{
   1.603 -	IExtension *pAlready;
   1.604 -	if ((pAlready=FindExtensionByFile(file)) != NULL)
   1.605 -	{
   1.606 -		return pAlready;
   1.607 -	}
   1.608 -
   1.609 -	CExtension *pExt = new CLocalExtension(file);
   1.610 -
   1.611 -	if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
   1.612 -	{
   1.613 -		pExt->Unload();
   1.614 -		delete pExt;
   1.615 -		return NULL;
   1.616 -	}
   1.617 -
   1.618 -	/* :TODO: do QueryRunning check if the map is loaded */
   1.619 -
   1.620 -	m_Libs.push_back(pExt);
   1.621 -
   1.622 -	return pExt;
   1.623 -}
   1.624 -
   1.625 -void CExtensionManager::BindDependency(IExtension *pRequester, IfaceInfo *pInfo)
   1.626 -{
   1.627 -	CExtension *pExt = (CExtension *)pRequester;
   1.628 -	CExtension *pOwner = (CExtension *)pInfo->owner;
   1.629 -
   1.630 -	pExt->AddDependency(pInfo);
   1.631 -
   1.632 -	IExtensionInterface *pAPI = pExt->GetAPI();
   1.633 -	if (pAPI && !pAPI->QueryInterfaceDrop(pInfo->iface))
   1.634 -	{
   1.635 -		pOwner->AddChildDependent(pExt, pInfo->iface);
   1.636 -	}
   1.637 -}
   1.638 -
   1.639 -void CExtensionManager::AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface)
   1.640 -{
   1.641 -	CExtension *pExt = (CExtension *)ext;
   1.642 -	CExtension *pOwner = GetExtensionFromIdent(other);
   1.643 -
   1.644 -	IfaceInfo info;
   1.645 -
   1.646 -	info.iface = (SMInterface *)iface;
   1.647 -	info.owner = pOwner;
   1.648 -
   1.649 -	pExt->AddDependency(&info);
   1.650 -	pOwner->AddChildDependent(pExt, (SMInterface *)iface);
   1.651 -}
   1.652 -
   1.653 -void CExtensionManager::AddInterface(IExtension *pOwner, SMInterface *pInterface)
   1.654 -{
   1.655 -	CExtension *pExt = (CExtension *)pOwner;
   1.656 -
   1.657 -	pExt->AddInterface(pInterface);
   1.658 -}
   1.659 -
   1.660 -void CExtensionManager::BindChildPlugin( IExtension *pParent, CPlugin *pPlugin )
   1.661 -{
   1.662 -	CExtension *pExt = (CExtension *)pParent;
   1.663 -
   1.664 -	pExt->AddPlugin(pPlugin);
   1.665 -}
   1.666 -
   1.667 -void CExtensionManager::OnPluginDestroyed(IPlugin *plugin)
   1.668 -{
   1.669 -	List<CExtension *>::iterator iter;
   1.670 -
   1.671 -	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   1.672 -	{
   1.673 -		(*iter)->DropRefsTo((CPlugin *)plugin);
   1.674 -	}
   1.675 -}
   1.676 -
   1.677 -CExtension *CExtensionManager::FindByOrder(unsigned int num)
   1.678 -{
   1.679 -	if (num < 1 || num > m_Libs.size())
   1.680 -	{
   1.681 -		return NULL;
   1.682 -	}
   1.683 -
   1.684 -	List<CExtension *>::iterator iter = m_Libs.begin();
   1.685 -
   1.686 -	while (iter != m_Libs.end())
   1.687 -	{
   1.688 -		if (--num == 0)
   1.689 -		{
   1.690 -			return (*iter);
   1.691 -		}
   1.692 -		iter++;
   1.693 -	}
   1.694 -
   1.695 -	return NULL;
   1.696 -}
   1.697 -
   1.698 -bool CExtensionManager::UnloadExtension(IExtension *_pExt)
   1.699 -{
   1.700 -	if (!_pExt)
   1.701 -	{
   1.702 -		return false;
   1.703 -	}
   1.704 -
   1.705 -	CExtension *pExt = (CExtension *)_pExt;
   1.706 -
   1.707 -	if (m_Libs.find(pExt) == m_Libs.end())
   1.708 -	{
   1.709 -		return false;
   1.710 -	}
   1.711 -
   1.712 -	/* First remove us from internal lists */
   1.713 -	g_ShareSys.RemoveInterfaces(_pExt);
   1.714 -	m_Libs.remove(pExt);
   1.715 -
   1.716 -	List<CExtension *> UnloadQueue;
   1.717 -
   1.718 -	/* Handle dependencies */
   1.719 -	if (pExt->IsLoaded())
   1.720 -	{
   1.721 -		/* Unload any dependent plugins */
   1.722 -		List<CPlugin *>::iterator p_iter = pExt->m_Dependents.begin();
   1.723 -		while (p_iter != pExt->m_Dependents.end())
   1.724 -		{
   1.725 -			/* We have to manually unlink ourselves here, since we're no longer being managed */
   1.726 -			g_PluginSys.UnloadPlugin((*p_iter));
   1.727 -			p_iter = pExt->m_Dependents.erase(p_iter);
   1.728 -		}
   1.729 -
   1.730 -		List<String>::iterator s_iter;
   1.731 -		for (s_iter = pExt->m_Libraries.begin();
   1.732 -			 s_iter != pExt->m_Libraries.end();
   1.733 -			 s_iter++)
   1.734 -		{
   1.735 -			g_PluginSys.OnLibraryAction((*s_iter).c_str(), false, true);
   1.736 -		}
   1.737 -
   1.738 -		/* Notify and/or unload all dependencies */
   1.739 -		List<CExtension *>::iterator c_iter;
   1.740 -		CExtension *pDep;
   1.741 -		IExtensionInterface *pAPI;
   1.742 -		for (c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++)
   1.743 -		{
   1.744 -			pDep = (*c_iter);
   1.745 -			if ((pAPI=pDep->GetAPI()) == NULL)
   1.746 -			{
   1.747 -				continue;
   1.748 -			}
   1.749 -			if (pDep == pExt)
   1.750 -			{
   1.751 -				continue;
   1.752 -			}
   1.753 -			/* Now, get its dependency list */
   1.754 -			bool dropped = false;
   1.755 -			List<IfaceInfo>::iterator i_iter = pDep->m_Deps.begin();
   1.756 -			while (i_iter != pDep->m_Deps.end())
   1.757 -			{
   1.758 -				if ((*i_iter).owner == _pExt)
   1.759 -				{
   1.760 -					if (!pAPI->QueryInterfaceDrop((*i_iter).iface))
   1.761 -					{
   1.762 -						if (!dropped)
   1.763 -						{
   1.764 -							dropped = true;
   1.765 -							UnloadQueue.push_back(pDep);
   1.766 -						}
   1.767 -					}
   1.768 -					pAPI->NotifyInterfaceDrop((*i_iter).iface);
   1.769 -					i_iter = pDep->m_Deps.erase(i_iter);
   1.770 -				}
   1.771 -				else
   1.772 -				{
   1.773 -					i_iter++;
   1.774 -				}
   1.775 -			}
   1.776 -			/* Flush out any back references to this plugin */
   1.777 -			i_iter = pDep->m_ChildDeps.begin();
   1.778 -			while (i_iter != pDep->m_ChildDeps.end())
   1.779 -			{
   1.780 -				if ((*i_iter).owner == pExt)
   1.781 -				{
   1.782 -					i_iter = pDep->m_ChildDeps.erase(i_iter);
   1.783 -				}
   1.784 -				else
   1.785 -				{
   1.786 -					i_iter++;
   1.787 -				}
   1.788 -			}
   1.789 -		}
   1.790 -
   1.791 -		/* Unbind our natives from Core */
   1.792 -		pExt->DropEverything();
   1.793 -
   1.794 -		/* Tell it to unload */
   1.795 -		pAPI = pExt->GetAPI();
   1.796 -		pAPI->OnExtensionUnload();
   1.797 -	}
   1.798 -
   1.799 -	IdentityToken_t *pIdentity;
   1.800 -	if ((pIdentity = pExt->GetIdentity()) != NULL)
   1.801 -	{
   1.802 -		SMGlobalClass *glob = SMGlobalClass::head;
   1.803 -		while (glob)
   1.804 -		{
   1.805 -			glob->OnSourceModIdentityDropped(pIdentity);
   1.806 -			glob = glob->m_pGlobalClassNext;
   1.807 -		}
   1.808 -	}
   1.809 -
   1.810 -	pExt->Unload();
   1.811 -	delete pExt;
   1.812 -
   1.813 -	List<CExtension *>::iterator iter;
   1.814 -	for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++)
   1.815 -	{
   1.816 -		/* NOTE: This is safe because the unload function backs out of anything not present */
   1.817 -		UnloadExtension((*iter));
   1.818 -	}
   1.819 -
   1.820 -	return true;
   1.821 -}
   1.822 -
   1.823 -void CExtensionManager::MarkAllLoaded()
   1.824 -{
   1.825 -	List<CExtension *>::iterator iter;
   1.826 -	CExtension *pExt;
   1.827 -
   1.828 -	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   1.829 -	{
   1.830 -		pExt = (*iter);
   1.831 -		if (!pExt->IsLoaded())
   1.832 -		{
   1.833 -			continue;
   1.834 -		}
   1.835 -		if (pExt->m_bFullyLoaded)
   1.836 -		{
   1.837 -			continue;
   1.838 -		}
   1.839 -		pExt->MarkAllLoaded();
   1.840 -	}
   1.841 -}
   1.842 -
   1.843 -void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload)
   1.844 -{
   1.845 -	/* This function doesn't really need to do anything now.  We make sure the 
   1.846 -	 * other extension is loaded, but handling of dependencies is really done 
   1.847 -	 * by the interface fetcher.
   1.848 -	 */
   1.849 -	if (required || autoload)
   1.850 -	{
   1.851 -		LoadAutoExtension(file);
   1.852 -	}
   1.853 -}
   1.854 -
   1.855 -void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
   1.856 -{
   1.857 -	int argcount = command.ArgC();
   1.858 -	if (argcount >= 3)
   1.859 -	{
   1.860 -		const char *cmd = command.Arg(2);
   1.861 -		if (strcmp(cmd, "list") == 0)
   1.862 -		{
   1.863 -			List<CExtension *>::iterator iter;
   1.864 -			CExtension *pExt;
   1.865 -			unsigned int num = 1;
   1.866 -			switch (m_Libs.size())
   1.867 -			{
   1.868 -			case 1:
   1.869 -				{
   1.870 -					g_RootMenu.ConsolePrint("[SM] Displaying 1 extension:");
   1.871 -					break;
   1.872 -				}
   1.873 -			case 0:
   1.874 -				{
   1.875 -					g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
   1.876 -					break;
   1.877 -				}
   1.878 -			default:
   1.879 -				{
   1.880 -					g_RootMenu.ConsolePrint("[SM] Displaying %d extensions:", m_Libs.size());
   1.881 -					break;
   1.882 -				}
   1.883 -			}
   1.884 -			for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++,num++)
   1.885 -			{
   1.886 -				pExt = (*iter);
   1.887 -				if (pExt->IsLoaded())
   1.888 -				{
   1.889 -					char error[255];
   1.890 -					if (!pExt->IsRunning(error, sizeof(error)))
   1.891 -					{
   1.892 -						g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), error);
   1.893 -					}
   1.894 -					else
   1.895 -					{
   1.896 -						IExtensionInterface *pAPI = pExt->GetAPI();
   1.897 -						const char *name = pAPI->GetExtensionName();
   1.898 -						const char *version = pAPI->GetExtensionVerString();
   1.899 -						const char *descr = pAPI->GetExtensionDescription();
   1.900 -						g_RootMenu.ConsolePrint("[%02d] %s (%s): %s", num, name, version, descr);
   1.901 -					}
   1.902 -				} else {
   1.903 -					g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str());
   1.904 -				}
   1.905 -			}
   1.906 -			return;
   1.907 -		}
   1.908 -		else if (strcmp(cmd, "info") == 0)
   1.909 -		{
   1.910 -			if (argcount < 4)
   1.911 -			{
   1.912 -				g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
   1.913 -				return;
   1.914 -			}
   1.915 -
   1.916 -			const char *sId = command.Arg(3);
   1.917 -			unsigned int id = atoi(sId);
   1.918 -			if (id <= 0)
   1.919 -			{
   1.920 -				g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
   1.921 -				return;
   1.922 -			}
   1.923 -
   1.924 -			if (m_Libs.size() == 0)
   1.925 -			{
   1.926 -				g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
   1.927 -				return;
   1.928 -			}
   1.929 -
   1.930 -			if (id > m_Libs.size())
   1.931 -			{
   1.932 -				g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
   1.933 -				return;
   1.934 -			}
   1.935 -
   1.936 -			List<CExtension *>::iterator iter = m_Libs.begin();
   1.937 -			CExtension *pExt = NULL;
   1.938 -			while (iter != m_Libs.end())
   1.939 -			{
   1.940 -				if (--id == 0)
   1.941 -				{
   1.942 -					pExt = (*iter);
   1.943 -					break;
   1.944 -				}
   1.945 -				iter++;
   1.946 -			}
   1.947 -			/* This should never happen */
   1.948 -			if (!pExt)
   1.949 -			{
   1.950 -				g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
   1.951 -				return;
   1.952 -			}
   1.953 -
   1.954 -			if (!pExt->IsLoaded())
   1.955 -			{
   1.956 -				g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
   1.957 -				g_RootMenu.ConsolePrint(" Loaded: No (%s)", pExt->m_Error.c_str());
   1.958 -			}
   1.959 -			else
   1.960 -			{
   1.961 -				char error[255];
   1.962 -				if (!pExt->IsRunning(error, sizeof(error)))
   1.963 -				{
   1.964 -					g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
   1.965 -					g_RootMenu.ConsolePrint(" Loaded: Yes");
   1.966 -					g_RootMenu.ConsolePrint(" Running: No (%s)", error);
   1.967 -				}
   1.968 -				else
   1.969 -				{
   1.970 -					IExtensionInterface *pAPI = pExt->GetAPI();
   1.971 -					g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
   1.972 -					g_RootMenu.ConsolePrint(" Loaded: Yes (version %s)", pAPI->GetExtensionVerString());
   1.973 -					g_RootMenu.ConsolePrint(" Name: %s (%s)", pAPI->GetExtensionName(), pAPI->GetExtensionDescription());
   1.974 -					g_RootMenu.ConsolePrint(" Author: %s (%s)", pAPI->GetExtensionAuthor(), pAPI->GetExtensionURL());
   1.975 -					g_RootMenu.ConsolePrint(" Binary info: API version %d (compiled %s)", pAPI->GetExtensionVersion(), pAPI->GetExtensionDateString());
   1.976 -
   1.977 -					if (pExt->IsExternal())
   1.978 -					{
   1.979 -						g_RootMenu.ConsolePrint(" Method: Loaded by Metamod:Source, attached to SourceMod");
   1.980 -					}
   1.981 -					else if (pAPI->IsMetamodExtension())
   1.982 -					{
   1.983 -						g_RootMenu.ConsolePrint(" Method: Loaded by SourceMod, attached to Metamod:Source");
   1.984 -					}
   1.985 -					else
   1.986 -					{
   1.987 -						g_RootMenu.ConsolePrint(" Method: Loaded by SourceMod");
   1.988 -					}
   1.989 -				}
   1.990 -			}
   1.991 -			return;
   1.992 -		}
   1.993 -		else if (strcmp(cmd, "unload") == 0)
   1.994 -		{
   1.995 -			if (argcount < 4)
   1.996 -			{
   1.997 -				g_RootMenu.ConsolePrint("[SM] Usage: sm unload <#> [code]");
   1.998 -				return;
   1.999 -			}
  1.1000 -
  1.1001 -			const char *arg = command.Arg(3);
  1.1002 -			unsigned int num = atoi(arg);
  1.1003 -			CExtension *pExt = FindByOrder(num);
  1.1004 -
  1.1005 -			if (!pExt)
  1.1006 -			{
  1.1007 -				g_RootMenu.ConsolePrint("[SM] Extension number %d was not found.", num);
  1.1008 -				return;
  1.1009 -			}
  1.1010 -
  1.1011 -			if (argcount > 4 && pExt->unload_code)
  1.1012 -			{
  1.1013 -				const char *unload = command.Arg(4);
  1.1014 -				if (pExt->unload_code == (unsigned)atoi(unload))
  1.1015 -				{
  1.1016 -					char filename[PLATFORM_MAX_PATH];
  1.1017 -					snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
  1.1018 -					UnloadExtension(pExt);
  1.1019 -					g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
  1.1020 -				}
  1.1021 -				else
  1.1022 -				{
  1.1023 -					g_RootMenu.ConsolePrint("[SM] Please try again, the correct unload code is \"%d\"", pExt->unload_code);
  1.1024 -				}
  1.1025 -				return;
  1.1026 -			}
  1.1027 -
  1.1028 -			if (!pExt->IsLoaded() 
  1.1029 -				|| (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size()))
  1.1030 -			{
  1.1031 -				char filename[PLATFORM_MAX_PATH];
  1.1032 -				snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
  1.1033 -				UnloadExtension(pExt);
  1.1034 -				g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
  1.1035 -				return;
  1.1036 -			}
  1.1037 -			else
  1.1038 -			{
  1.1039 -				List<CPlugin *> plugins;
  1.1040 -				if (pExt->m_ChildDeps.size())
  1.1041 -				{
  1.1042 -					g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename());
  1.1043 -					List<CExtension *>::iterator iter;
  1.1044 -					CExtension *pOther;
  1.1045 -					/* Get list of all extensions */
  1.1046 -					for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
  1.1047 -					{
  1.1048 -						List<IfaceInfo>::iterator i_iter;
  1.1049 -						pOther = (*iter);
  1.1050 -						if (!pOther->IsLoaded() || pOther == pExt)
  1.1051 -						{
  1.1052 -							continue;
  1.1053 -						}
  1.1054 -						/* Get their dependencies */
  1.1055 -						for (i_iter=pOther->m_Deps.begin();
  1.1056 -							 i_iter!=pOther->m_Deps.end();
  1.1057 -							 i_iter++)
  1.1058 -						{
  1.1059 -							/* Is this dependency to us? */
  1.1060 -							if ((*i_iter).owner != pExt)
  1.1061 -							{
  1.1062 -								continue;
  1.1063 -							}
  1.1064 -							/* Will our dependent care? */
  1.1065 -							if (!pExt->GetAPI()->QueryInterfaceDrop((*i_iter).iface))
  1.1066 -							{
  1.1067 -								g_RootMenu.ConsolePrint(" -> %s", pExt->GetFilename());
  1.1068 -								/* Add to plugin unload list */
  1.1069 -								List<CPlugin *>::iterator p_iter;
  1.1070 -								for (p_iter=pOther->m_Dependents.begin();
  1.1071 -									 p_iter!=pOther->m_Dependents.end();
  1.1072 -									 p_iter++)
  1.1073 -								{
  1.1074 -									if (plugins.find((*p_iter)) == plugins.end())
  1.1075 -									{
  1.1076 -										plugins.push_back((*p_iter));
  1.1077 -									}
  1.1078 -								}
  1.1079 -							}
  1.1080 -						}
  1.1081 -					}
  1.1082 -				}
  1.1083 -				if (pExt->m_Dependents.size())
  1.1084 -				{
  1.1085 -					g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename());
  1.1086 -					List<CPlugin *>::iterator iter;
  1.1087 -					CPlugin *pPlugin;
  1.1088 -					for (iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++)
  1.1089 -					{
  1.1090 -						pPlugin = (*iter);
  1.1091 -						if (plugins.find(pPlugin) == plugins.end())
  1.1092 -						{
  1.1093 -							plugins.push_back(pPlugin);
  1.1094 -						}
  1.1095 -					}
  1.1096 -					for (iter = plugins.begin(); iter != plugins.end(); iter++)
  1.1097 -					{
  1.1098 -						pPlugin = (*iter);
  1.1099 -						g_RootMenu.ConsolePrint(" -> %s", pPlugin->GetFilename());
  1.1100 -					}
  1.1101 -				}
  1.1102 -				srand(static_cast<int>(time(NULL)));
  1.1103 -				pExt->unload_code = (rand() % 877) + 123;	//123 to 999
  1.1104 -				g_RootMenu.ConsolePrint("[SM] To verify unloading %s, please use the following: ", pExt->GetFilename());
  1.1105 -				g_RootMenu.ConsolePrint("[SM] sm exts unload %d %d", num, pExt->unload_code);
  1.1106 -
  1.1107 -				return;
  1.1108 -			}
  1.1109 -		}
  1.1110 -	}
  1.1111 -
  1.1112 -	g_RootMenu.ConsolePrint("SourceMod Extensions Menu:");
  1.1113 -	g_RootMenu.DrawGenericOption("info", "Extra extension information");
  1.1114 -	g_RootMenu.DrawGenericOption("list", "List extensions");
  1.1115 -	g_RootMenu.DrawGenericOption("unload", "Unload an extension");
  1.1116 -}
  1.1117 -
  1.1118 -CExtension *CExtensionManager::GetExtensionFromIdent(IdentityToken_t *ptr)
  1.1119 -{
  1.1120 -	if (ptr->type == g_ExtType)
  1.1121 -	{
  1.1122 -		return (CExtension *)(ptr->ptr);
  1.1123 -	}
  1.1124 -
  1.1125 -	return NULL;
  1.1126 -}
  1.1127 -
  1.1128 -CExtensionManager::CExtensionManager()
  1.1129 -{
  1.1130 -}
  1.1131 -
  1.1132 -CExtensionManager::~CExtensionManager()
  1.1133 -{
  1.1134 -}
  1.1135 -
  1.1136 -void CExtensionManager::AddLibrary(IExtension *pSource, const char *library)
  1.1137 -{
  1.1138 -	CExtension *pExt = (CExtension *)pSource;
  1.1139 -	pExt->AddLibrary(library);
  1.1140 -	g_PluginSys.OnLibraryAction(library, false, false);
  1.1141 -}
  1.1142 -
  1.1143 -bool CExtensionManager::LibraryExists(const char *library)
  1.1144 -{
  1.1145 -	CExtension *pExt;
  1.1146 -
  1.1147 -	for (List<CExtension *>::iterator iter = m_Libs.begin();
  1.1148 -		 iter != m_Libs.end();
  1.1149 -		 iter++)
  1.1150 -	{
  1.1151 -		pExt = (*iter);
  1.1152 -		for (List<String>::iterator s_iter = pExt->m_Libraries.begin();
  1.1153 -			 s_iter != pExt->m_Libraries.end();
  1.1154 -			 s_iter++)
  1.1155 -		{
  1.1156 -			if ((*s_iter).compare(library) == 0)
  1.1157 -			{
  1.1158 -				return true;
  1.1159 -			}
  1.1160 -		}
  1.1161 -	}
  1.1162 -
  1.1163 -	return false;
  1.1164 -}
  1.1165 -
  1.1166 -IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface,
  1.1167 -											const char *filepath,
  1.1168 -											const char *filename,
  1.1169 -											char *error,
  1.1170 -											size_t maxlength)
  1.1171 -{
  1.1172 -	IExtension *pAlready;
  1.1173 -	if ((pAlready=FindExtensionByFile(filename)) != NULL)
  1.1174 -	{
  1.1175 -		return pAlready;
  1.1176 -	}
  1.1177 -
  1.1178 -	CExtension *pExt = new CRemoteExtension(pInterface, filename, filepath);
  1.1179 -
  1.1180 -	if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
  1.1181 -	{
  1.1182 -		pExt->Unload();
  1.1183 -		delete pExt;
  1.1184 -		return NULL;
  1.1185 -	}
  1.1186 -
  1.1187 -	m_Libs.push_back(pExt);
  1.1188 -
  1.1189 -	return pExt;
  1.1190 -}
  1.1191 -
  1.1192 -void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
  1.1193 -{
  1.1194 -	IExtensionInterface *pAPI;
  1.1195 -	List<CExtension *>::iterator iter;
  1.1196 -
  1.1197 -	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
  1.1198 -	{
  1.1199 -		if ((pAPI = (*iter)->GetAPI()) == NULL)
  1.1200 -		{
  1.1201 -			continue;
  1.1202 -		}
  1.1203 -		if (pAPI->GetExtensionVersion() > 3)
  1.1204 -		{
  1.1205 -			pAPI->OnCoreMapStart(pEdictList, edictCount, clientMax);
  1.1206 -		}
  1.1207 -	}
  1.1208 -}