sourcemm/metamod_plugins.cpp
branchhookman_autogen
changeset 531 0180319136ba
parent 479 b43ebc944319
child 532 9729de2d7551
     1.1 --- a/sourcemm/metamod_plugins.cpp	Sun Nov 25 01:22:41 2007 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,832 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * ======================================================
     1.7 - * Metamod:Source
     1.8 - * Copyright (C) 2004-2007 AlliedModders LLC and authors.
     1.9 - * All rights reserved.
    1.10 - * ======================================================
    1.11 - *
    1.12 - * This software is provided 'as-is', without any express or implied warranty.
    1.13 - * In no event will the authors be held liable for any damages arising from 
    1.14 - * the use of this software.
    1.15 - * 
    1.16 - * Permission is granted to anyone to use this software for any purpose, 
    1.17 - * including commercial applications, and to alter it and redistribute it 
    1.18 - * freely, subject to the following restrictions:
    1.19 - *
    1.20 - * 1. The origin of this software must not be misrepresented; you must not 
    1.21 - * claim that you wrote the original software. If you use this software in a 
    1.22 - * product, an acknowledgment in the product documentation would be 
    1.23 - * appreciated but is not required.
    1.24 - * 2. Altered source versions must be plainly marked as such, and must not be
    1.25 - * misrepresented as being the original software.
    1.26 - * 3. This notice may not be removed or altered from any source distribution.
    1.27 - *
    1.28 - * Version: $Id$
    1.29 - */
    1.30 -
    1.31 -#if defined _DEBUG
    1.32 -#define DEBUG2
    1.33 -#undef _DEBUG
    1.34 -#endif
    1.35 -#include "metamod.h"
    1.36 -#include "metamod_plugins.h"
    1.37 -#include "metamod_util.h"
    1.38 -#if defined DEBUG2
    1.39 -#undef DEBUG2
    1.40 -#define _DEBUG
    1.41 -#endif
    1.42 -
    1.43 -/** 
    1.44 - * @brief Implements functions from CPlugin.h
    1.45 - * @file CPlugin.cpp
    1.46 - */
    1.47 -
    1.48 -using namespace SourceMM;
    1.49 -
    1.50 -#define ITER_PLEVENT(evn, plid) \
    1.51 -	CPluginManager::CPlugin *_Xpl; \
    1.52 -	SourceHook::List<IMetamodListener *>::iterator event; \
    1.53 -	IMetamodListener *api; \
    1.54 -	for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
    1.55 -		_Xpl = (*iter); \
    1.56 -		if (_Xpl->m_Id == plid) \
    1.57 -			continue; \
    1.58 -		for (event=_Xpl->m_Events.begin(); event!=_Xpl->m_Events.end(); event++) { \
    1.59 -			api = (*event); \
    1.60 -			api->evn(plid); \
    1.61 -		} \
    1.62 -	}
    1.63 -
    1.64 -CPluginManager g_PluginMngr;
    1.65 -
    1.66 -MetamodVersionInfo GlobVersionInfo = 
    1.67 -{
    1.68 -	METAMOD_API_MAJOR,
    1.69 -	METAMOD_API_MINOR,
    1.70 -	SH_IFACE_VERSION,
    1.71 -	SH_IMPL_VERSION,
    1.72 -	PLAPI_MIN_VERSION,
    1.73 -	METAMOD_PLAPI_VERSION,
    1.74 -	SOURCE_ENGINE_UNKNOWN
    1.75 -};
    1.76 -
    1.77 -CPluginManager::CPluginManager()
    1.78 -{
    1.79 -	m_LastId = Pl_MinId;
    1.80 -	m_AllLoaded = false;
    1.81 -}
    1.82 -
    1.83 -CPluginManager::~CPluginManager()
    1.84 -{
    1.85 -	SourceHook::List<CNameAlias *>::iterator iter;
    1.86 -
    1.87 -	for (iter = m_Aliases.begin(); iter != m_Aliases.end(); iter++)
    1.88 -	{
    1.89 -		delete (*iter);
    1.90 -	}
    1.91 -
    1.92 -	m_Aliases.clear();
    1.93 -}
    1.94 -
    1.95 -const char *CPluginManager::LookupAlias(const char *alias)
    1.96 -{
    1.97 -	SourceHook::List<CNameAlias *>::iterator iter;
    1.98 -	CNameAlias *p;
    1.99 -
   1.100 -	for (iter = m_Aliases.begin(); iter != m_Aliases.end(); iter++)
   1.101 -	{
   1.102 -		p = (*iter);
   1.103 -		if (p->alias.compare(alias) == 0)
   1.104 -		{
   1.105 -			return p->value.c_str();
   1.106 -		}
   1.107 -	}
   1.108 -
   1.109 -	return NULL;
   1.110 -}
   1.111 -
   1.112 -SourceHook::List<CNameAlias *>::iterator CPluginManager::_alias_begin()
   1.113 -{
   1.114 -	return m_Aliases.begin();
   1.115 -}
   1.116 -
   1.117 -SourceHook::List<CNameAlias *>::iterator CPluginManager::_alias_end()
   1.118 -{
   1.119 -	return m_Aliases.end();
   1.120 -}
   1.121 -
   1.122 -void CPluginManager::SetAlias(const char *alias, const char *value)
   1.123 -{
   1.124 -	SourceHook::List<CNameAlias *>::iterator iter;
   1.125 -	CNameAlias *p;
   1.126 -
   1.127 -	for (iter = m_Aliases.begin(); iter != m_Aliases.end(); iter++)
   1.128 -	{
   1.129 -		p = (*iter);
   1.130 -		if (p->alias.compare(alias) == 0)
   1.131 -		{
   1.132 -			if (value[0] == '\0')
   1.133 -			{
   1.134 -				iter = m_Aliases.erase(iter);
   1.135 -				return;
   1.136 -			}
   1.137 -			else
   1.138 -			{
   1.139 -				p->value.assign(value);
   1.140 -				return;
   1.141 -			}
   1.142 -		}
   1.143 -	}
   1.144 -
   1.145 -	if (value[0] != '\0')
   1.146 -	{
   1.147 -		p = new CNameAlias;
   1.148 -	
   1.149 -		p->alias.assign(alias);
   1.150 -		p->value.assign(value);
   1.151 -	
   1.152 -		m_Aliases.push_back(p);
   1.153 -	}
   1.154 -}
   1.155 -
   1.156 -CPluginManager::CPlugin::CPlugin() : m_Id(0), m_Source(0), m_API(NULL), m_Lib(NULL), m_UnloadFn(NULL)
   1.157 -{
   1.158 -
   1.159 -}
   1.160 -
   1.161 -PluginId CPluginManager::Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen)
   1.162 -{
   1.163 -	already = false;
   1.164 -	//Check if we're about to reload an old plugin
   1.165 -	PluginIter i = m_Plugins.begin();
   1.166 -	while (i != m_Plugins.end())
   1.167 -	{
   1.168 -		if ((*i) && UTIL_PathCmp(file, (*i)->m_File.c_str()))
   1.169 -		{
   1.170 -			if ((*i)->m_Status < Pl_Paused)
   1.171 -			{
   1.172 -				//Attempt to load the plugin again
   1.173 -				already = true;
   1.174 -				i = m_Plugins.erase(i);
   1.175 -				continue;
   1.176 -			}
   1.177 -			else
   1.178 -			{
   1.179 -				//No need to load it
   1.180 -				already = true;
   1.181 -				return (*i)->m_Id;
   1.182 -			}
   1.183 -		}
   1.184 -		i++;
   1.185 -	}
   1.186 -
   1.187 -	CPlugin *pl = _Load(file, source, error, maxlen);
   1.188 -
   1.189 -	if (!pl)
   1.190 -	{
   1.191 -		return Pl_BadLoad;
   1.192 -	}
   1.193 -
   1.194 -	ITER_PLEVENT(OnPluginLoad, pl->m_Id);
   1.195 -
   1.196 -	return pl->m_Id;
   1.197 -}
   1.198 -
   1.199 -CPluginManager::CPlugin *CPluginManager::FindById(PluginId id)
   1.200 -{
   1.201 -	PluginIter i;
   1.202 -
   1.203 -	for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   1.204 -	{
   1.205 -		if ( (*i)->m_Id == id )\
   1.206 -		{
   1.207 -			return (*i);
   1.208 -		}
   1.209 -	}
   1.210 -
   1.211 -	return NULL;
   1.212 -}
   1.213 -
   1.214 -void CPluginManager::SetAllLoaded()
   1.215 -{
   1.216 -	m_AllLoaded = true;
   1.217 -	PluginIter i;
   1.218 -
   1.219 -	for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   1.220 -	{
   1.221 -		if ( (*i) && (*i)->m_Status == Pl_Running && (*i)->m_API )
   1.222 -		{
   1.223 -			//API 4 is when we added this callback
   1.224 -			//Min version is now 5, so we ignore this check
   1.225 -			//if ( (*i)->m_API->GetApiVersion() >= 004 )
   1.226 -			(*i)->m_API->AllPluginsLoaded();
   1.227 -		}
   1.228 -	}
   1.229 -}
   1.230 -
   1.231 -bool CPluginManager::Pause(PluginId id, char *error, size_t maxlen)
   1.232 -{
   1.233 -	CPlugin *pl = FindById(id);
   1.234 -	
   1.235 -	if (!pl)
   1.236 -	{
   1.237 -		UTIL_Format(error, maxlen, "Plugin id not found");
   1.238 -		return false;
   1.239 -	}
   1.240 -
   1.241 -	bool ret;
   1.242 -	
   1.243 -	if ((ret=_Pause(pl, error, maxlen)) == true)
   1.244 -	{
   1.245 -		ITER_PLEVENT(OnPluginPause, pl->m_Id);
   1.246 -	}
   1.247 -
   1.248 -	return ret;
   1.249 -}
   1.250 -
   1.251 -bool CPluginManager::Unpause(PluginId id, char *error, size_t maxlen)
   1.252 -{
   1.253 -	CPlugin *pl = FindById(id);
   1.254 -	
   1.255 -	if (!pl)
   1.256 -	{
   1.257 -		UTIL_Format(error, maxlen, "Plugin id not found");
   1.258 -		return false;
   1.259 -	}
   1.260 -
   1.261 -	bool ret;
   1.262 -	
   1.263 -	if ( (ret=_Unpause(pl, error, maxlen)) == true )
   1.264 -	{
   1.265 -		ITER_PLEVENT(OnPluginUnpause, pl->m_Id);
   1.266 -	}
   1.267 -
   1.268 -	return ret;
   1.269 -}
   1.270 -
   1.271 -bool CPluginManager::Unload(PluginId id, bool force, char *error, size_t maxlen)
   1.272 -{
   1.273 -	CPlugin *pl = FindById(id);
   1.274 -	
   1.275 -	if (!pl)
   1.276 -	{
   1.277 -		UTIL_Format(error, maxlen, "Plugin %d not found", id);
   1.278 -		return false;
   1.279 -	}
   1.280 -
   1.281 -	bool ret;
   1.282 -	PluginId old_id = pl->m_Id;
   1.283 -	if ( (ret=_Unload(pl, force, error, maxlen)) == true )
   1.284 -	{
   1.285 -		ITER_PLEVENT(OnPluginUnload, old_id);
   1.286 -	}
   1.287 -
   1.288 -	return ret;
   1.289 -}
   1.290 -
   1.291 -bool CPluginManager::Retry(PluginId id, char *error, size_t len)
   1.292 -{
   1.293 -	PluginIter i;
   1.294 -	char buffer[64];
   1.295 -	for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   1.296 -	{
   1.297 -		if ( (*i) && (*i)->m_Id == id )
   1.298 -		{
   1.299 -			if ( (*i)->m_Status >= Pl_Paused)
   1.300 -			{
   1.301 -				UTIL_Format(error, len, "Plugin %d is already running.", id);
   1.302 -				return false;
   1.303 -			}
   1.304 -			CPlugin *pl = _Load((*i)->m_File.c_str(), Pl_Console, error, len);
   1.305 -			if (!pl)
   1.306 -			{
   1.307 -				return false;
   1.308 -			}
   1.309 -			if (pl->m_Status >= Pl_Paused)
   1.310 -			{
   1.311 -				//Now it gets crazy... unload the original copy.
   1.312 -				_Unload( (*i), true, buffer, sizeof(buffer)-1 );
   1.313 -				
   1.314 -				//Set the new copy's id
   1.315 -				pl->m_Id = id;
   1.316 -
   1.317 -				//We just wasted an id... reclaim it
   1.318 -				m_LastId--;
   1.319 -				
   1.320 -				return true;
   1.321 -			}
   1.322 -			else
   1.323 -			{
   1.324 -				//don't really care about the buffer here
   1.325 -				_Unload(pl, true, buffer, sizeof(buffer)-1);
   1.326 -
   1.327 -				//We just wasted an id... reclaim it
   1.328 -				m_LastId--;
   1.329 -				return false;
   1.330 -			}
   1.331 -		}
   1.332 -	}
   1.333 -
   1.334 -	UTIL_Format(error, len, "Plugin %d not found,", id);
   1.335 -	return false;
   1.336 -}
   1.337 -
   1.338 -CPluginManager::CPlugin *CPluginManager::FindByAPI(ISmmPlugin *api)
   1.339 -{
   1.340 -	PluginIter i;
   1.341 -
   1.342 -	//don't find bad plugins!
   1.343 -	if (!api)
   1.344 -	{
   1.345 -		return NULL;
   1.346 -	}
   1.347 -
   1.348 -	for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   1.349 -	{
   1.350 -		if ((*i)->m_API == api)
   1.351 -		{
   1.352 -			return (*i);
   1.353 -		}
   1.354 -	}
   1.355 -
   1.356 -	return NULL;
   1.357 -}
   1.358 -
   1.359 -int CPluginManager::GetPluginCount()
   1.360 -{
   1.361 -	return (int)m_Plugins.size();
   1.362 -}
   1.363 -
   1.364 -const char *CPluginManager::GetStatusText(CPlugin *pl)
   1.365 -{
   1.366 -	switch (pl->m_Status)
   1.367 -	{
   1.368 -	case Pl_NotFound:
   1.369 -		return "NOFILE";
   1.370 -	case Pl_Error:
   1.371 -		return "ERROR";
   1.372 -	case Pl_Refused:
   1.373 -		return "FAILED";
   1.374 -	case Pl_Paused:
   1.375 -		return "PAUSED";
   1.376 -	case Pl_Running:
   1.377 -		{
   1.378 -			if (pl->m_API && pl->m_API->QueryRunning(NULL, 0))
   1.379 -			{
   1.380 -				return "STOPPED";
   1.381 -			} else {
   1.382 -				return "RUNNING";
   1.383 -			}
   1.384 -		}
   1.385 -	default:
   1.386 -		return "-";
   1.387 -	}
   1.388 -}
   1.389 -
   1.390 -CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source, char *error, size_t maxlen)
   1.391 -{
   1.392 -	FILE *fp;
   1.393 -	CPlugin *pl;
   1.394 -
   1.395 -	pl = new CPlugin();
   1.396 -	*error = '\0';
   1.397 -	
   1.398 -	//Add plugin to list
   1.399 -	pl->m_Id = m_LastId;
   1.400 -	pl->m_File.assign(file);
   1.401 -	m_Plugins.push_back(pl);
   1.402 -	m_LastId++;
   1.403 -
   1.404 -	//Check if the file even exists
   1.405 -	fp = fopen(file, "r");
   1.406 -	if (!fp)
   1.407 -	{
   1.408 -		if (error)
   1.409 -		{
   1.410 -			UTIL_Format(error, maxlen, "File not found: %s", file);
   1.411 -		}
   1.412 -		pl->m_Status = Pl_NotFound;
   1.413 -	}
   1.414 -
   1.415 -	if (fp)
   1.416 -	{
   1.417 -		fclose(fp);
   1.418 -		fp = NULL;
   1.419 -		
   1.420 -		//Load the file
   1.421 -		pl->m_Lib = dlmount(file);
   1.422 -		if (!pl->m_Lib)
   1.423 -		{
   1.424 -			if (error)
   1.425 -			{
   1.426 -				UTIL_Format(error, maxlen, "%s", dlerror());
   1.427 -			}
   1.428 -			pl->m_Status = Pl_Error;
   1.429 -		}
   1.430 -		else
   1.431 -		{
   1.432 -			pl->m_API = NULL;
   1.433 -			
   1.434 -			/**
   1.435 -			 * First, try the new "advanced" interface
   1.436 -			 */
   1.437 -			METAMOD_FN_LOAD fnLoad = (METAMOD_FN_LOAD)dlsym(pl->m_Lib, "CreateInterface_MMS");
   1.438 -			if (fnLoad != NULL)
   1.439 -			{
   1.440 -				if (GlobVersionInfo.source_engine == SOURCE_ENGINE_UNKNOWN)
   1.441 -				{
   1.442 -					GlobVersionInfo.source_engine = g_Metamod.GetSourceEngineBuild();
   1.443 -				}
   1.444 -
   1.445 -				/* Build path information */
   1.446 -				char file_path[256];
   1.447 -				size_t len = g_Metamod.PathFormat(file_path, sizeof(file_path), "%s", file);
   1.448 -
   1.449 -				for (size_t i = len - 1; i >= 0 && i < len; i--)
   1.450 -				{
   1.451 -					if (_IsPathSepChar(file_path[i]))
   1.452 -					{
   1.453 -						file_path[i] = '\0';
   1.454 -						break;
   1.455 -					}
   1.456 -				}
   1.457 -
   1.458 -				MetamodLoaderInfo info;
   1.459 -				info.pl_file = file;
   1.460 -				info.pl_path = file_path;
   1.461 -
   1.462 -				pl->m_API = fnLoad(&GlobVersionInfo, &info);
   1.463 -				pl->m_UnloadFn = (METAMOD_FN_UNLOAD)dlsym(pl->m_Lib, "UnloadInterface_MMS");
   1.464 -			}
   1.465 -
   1.466 -			/**
   1.467 -			 * If we didn't get anything, try the normal/simple interface.
   1.468 -			 */
   1.469 -			if (pl->m_API == NULL)
   1.470 -			{
   1.471 -				CreateInterfaceFn pfn = (CreateInterfaceFn)(dlsym(pl->m_Lib, PL_EXPOSURE_C));
   1.472 -				if (!pfn)
   1.473 -				{
   1.474 -					if (error)
   1.475 -					{
   1.476 -						UTIL_Format(error, maxlen, "Function %s not found", PL_EXPOSURE_C);
   1.477 -					}
   1.478 -					pl->m_Status = Pl_Error;
   1.479 -				}
   1.480 -				else
   1.481 -				{
   1.482 -					pl->m_API = static_cast<ISmmPlugin *>((pfn)(METAMOD_PLAPI_NAME, NULL));
   1.483 -
   1.484 -					if (!pl->m_API)
   1.485 -					{
   1.486 -						if (error)
   1.487 -						{
   1.488 -							UTIL_Format(error, maxlen, "Failed to get API");
   1.489 -						}
   1.490 -						pl->m_Status = Pl_Error;
   1.491 -					}
   1.492 -				}
   1.493 -			}
   1.494 -
   1.495 -			if (pl->m_API != NULL)
   1.496 -			{
   1.497 -				int api = pl->m_API->GetApiVersion();
   1.498 -				if (api < PLAPI_MIN_VERSION)
   1.499 -				{
   1.500 -					if (error)
   1.501 -					{
   1.502 -						if (api == 13)
   1.503 -						{
   1.504 -							UTIL_Format(error, maxlen, "Plugin uses experimental Metamod build, probably 1.6.x (%d < %d)", api, PLAPI_MIN_VERSION);
   1.505 -						}
   1.506 -						else if (api <= 12 && api >= 7)
   1.507 -						{
   1.508 -							UTIL_Format(error, maxlen, "Older Metamod version required, probably 1.4.x (%d < %d)", api, PLAPI_MIN_VERSION);
   1.509 -						}
   1.510 -						else
   1.511 -						{
   1.512 -							UTIL_Format(error, maxlen, "Older Metamod version required, probably 1.0 (%d < %d)", api, PLAPI_MIN_VERSION);
   1.513 -						}
   1.514 -					}
   1.515 -					pl->m_Status = Pl_Error;
   1.516 -				}
   1.517 -				else if (api > METAMOD_PLAPI_VERSION)
   1.518 -				{
   1.519 -					if (error)
   1.520 -					{
   1.521 -						UTIL_Format(error, maxlen, "Plugin requires newer Metamod version (%d > %d)", api, METAMOD_PLAPI_VERSION);
   1.522 -					}
   1.523 -					pl->m_Status = Pl_Error;
   1.524 -				}
   1.525 -				else
   1.526 -				{
   1.527 -					if (pl->m_API->Load(pl->m_Id, &g_Metamod, error, maxlen, m_AllLoaded))
   1.528 -					{
   1.529 -						pl->m_Status = Pl_Running;
   1.530 -						if (m_AllLoaded)
   1.531 -						{
   1.532 -							pl->m_API->AllPluginsLoaded();
   1.533 -						}
   1.534 -					}
   1.535 -					else
   1.536 -					{
   1.537 -						pl->m_Status = Pl_Refused;
   1.538 -					}
   1.539 -				}
   1.540 -			}
   1.541 -		}
   1.542 -	}
   1.543 -
   1.544 -	if (pl->m_Lib && (pl->m_Status < Pl_Paused))
   1.545 -	{
   1.546 -		pl->m_Events.clear();
   1.547 -		g_SourceHook.UnloadPlugin(pl->m_Id);
   1.548 -		UnregAllConCmds(pl);
   1.549 -
   1.550 -		if (pl->m_UnloadFn != NULL)
   1.551 -		{
   1.552 -			pl->m_UnloadFn();
   1.553 -		}
   1.554 -
   1.555 -		dlclose(pl->m_Lib);
   1.556 -		pl->m_Lib = NULL;
   1.557 -		pl->m_API = NULL;
   1.558 -	}
   1.559 -
   1.560 -	return pl;
   1.561 -}
   1.562 -
   1.563 -bool CPluginManager::_Unload(CPluginManager::CPlugin *pl, bool force, char *error, size_t maxlen)
   1.564 -{
   1.565 -	if (error)
   1.566 -	{
   1.567 -		*error = '\0';
   1.568 -	}
   1.569 -
   1.570 -	if (pl->m_API && pl->m_Lib)
   1.571 -	{
   1.572 -		//Note, we'll always tell the plugin it will be unloading...
   1.573 -		if (pl->m_API->Unload(error, maxlen) || force)
   1.574 -		{
   1.575 -			//Make sure to detach it from sourcehook!
   1.576 -			g_SourceHook.UnloadPlugin(pl->m_Id);
   1.577 -
   1.578 -			pl->m_Events.clear();
   1.579 -
   1.580 -			UnregAllConCmds(pl);
   1.581 -
   1.582 -			if (pl->m_UnloadFn != NULL)
   1.583 -			{
   1.584 -				pl->m_UnloadFn();
   1.585 -			}
   1.586 -
   1.587 -			//Clean up the DLL
   1.588 -			dlclose(pl->m_Lib);
   1.589 -			pl->m_Lib = NULL;
   1.590 -			pl->m_API = NULL;
   1.591 -
   1.592 -			//Remove the plugin from the list
   1.593 -			PluginIter i;
   1.594 -			for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   1.595 -			{
   1.596 -				if ( (*i)->m_Id == pl->m_Id )
   1.597 -				{
   1.598 -					i = m_Plugins.erase(i);
   1.599 -					break;
   1.600 -				}
   1.601 -			}
   1.602 -			//Free its memory
   1.603 -			delete pl;
   1.604 -
   1.605 -			return true;
   1.606 -		}
   1.607 -	} else {
   1.608 -		//The plugin is not valid, and let's just remove it from the list anyway
   1.609 -		PluginIter i;
   1.610 -		for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   1.611 -		{
   1.612 -			if ( (*i)->m_Id == pl->m_Id )
   1.613 -			{
   1.614 -				i = m_Plugins.erase(i);
   1.615 -				break;
   1.616 -			}
   1.617 -		}
   1.618 -		delete pl;
   1.619 -
   1.620 -		return true;
   1.621 -	}
   1.622 -
   1.623 -	return false;
   1.624 -}
   1.625 -
   1.626 -bool CPluginManager::_Pause(CPluginManager::CPlugin *pl, char *error, size_t maxlen)
   1.627 -{
   1.628 -	if (error)
   1.629 -	{
   1.630 -		*error = '\0';
   1.631 -	}
   1.632 -
   1.633 -	if (pl->m_Status != Pl_Running || !pl->m_API)
   1.634 -	{
   1.635 -		if (error)
   1.636 -		{
   1.637 -			UTIL_Format(error, maxlen, "Plugin cannot be paused");
   1.638 -		}
   1.639 -	}
   1.640 -	else
   1.641 -	{
   1.642 -		if (pl->m_API->Pause(error, maxlen))
   1.643 -		{
   1.644 -			g_SourceHook.PausePlugin(pl->m_Id);
   1.645 -			pl->m_Status = Pl_Paused;
   1.646 -
   1.647 -			return true;
   1.648 -		}
   1.649 -	}
   1.650 -
   1.651 -	return false;
   1.652 -}
   1.653 -
   1.654 -bool CPluginManager::_Unpause(CPluginManager::CPlugin *pl, char *error, size_t maxlen)
   1.655 -{
   1.656 -	if (error)
   1.657 -	{
   1.658 -		*error = '\0';
   1.659 -	}
   1.660 -
   1.661 -	if (pl->m_Status != Pl_Paused || !pl->m_API)
   1.662 -	{
   1.663 -		if (error)
   1.664 -		{
   1.665 -			UTIL_Format(error, maxlen, "Plugin cannot be unpaused");
   1.666 -		}
   1.667 -	}
   1.668 -	else
   1.669 -	{
   1.670 -		if (pl->m_API->Unpause(error, maxlen))
   1.671 -		{
   1.672 -			g_SourceHook.UnpausePlugin(pl->m_Id);
   1.673 -			pl->m_Status = Pl_Running;
   1.674 -
   1.675 -			return true;
   1.676 -		}
   1.677 -	}
   1.678 -
   1.679 -	return false;
   1.680 -}
   1.681 -
   1.682 -bool CPluginManager::UnloadAll()
   1.683 -{
   1.684 -	PluginIter i;
   1.685 -
   1.686 -	char error[128];
   1.687 -	bool status = true;
   1.688 -
   1.689 -	while ((i = m_Plugins.begin()) != m_Plugins.end())
   1.690 -	{
   1.691 -		if ( !_Unload( (*i), true, error, sizeof(error)) )
   1.692 -		{
   1.693 -			status = false;
   1.694 -		}
   1.695 -	}
   1.696 -
   1.697 -	return status;
   1.698 -}
   1.699 -
   1.700 -bool CPluginManager::Query(PluginId id, const char **file, Pl_Status *status, PluginId *source)
   1.701 -{
   1.702 -	CPlugin *pl = FindById(id);
   1.703 -
   1.704 -	if (!pl)
   1.705 -	{
   1.706 -		return false;
   1.707 -	}
   1.708 -
   1.709 -	if (file != NULL)
   1.710 -	{
   1.711 -		*file = pl->m_File.c_str();
   1.712 -	}
   1.713 -
   1.714 -	if (status != NULL)
   1.715 -	{
   1.716 -		*status = pl->m_Status;
   1.717 -	}
   1.718 -
   1.719 -	if (source != NULL)
   1.720 -	{
   1.721 -		*source = pl->m_Source;
   1.722 -	}
   1.723 -
   1.724 -	return true;
   1.725 -}
   1.726 -
   1.727 -bool CPluginManager::QueryRunning(PluginId id, char *error, size_t maxlength)
   1.728 -{
   1.729 -	CPlugin *pl = FindById(id);
   1.730 -
   1.731 -	if (!pl || !pl->m_API)
   1.732 -	{
   1.733 -		if (error)
   1.734 -		{
   1.735 -			UTIL_Format(error, maxlength, "Plugin not valid");
   1.736 -		}
   1.737 -		return false;
   1.738 -	}
   1.739 -
   1.740 -	return pl->m_API->QueryRunning(error, maxlength);
   1.741 -}
   1.742 -
   1.743 -bool CPluginManager::QueryHandle(PluginId id, void **handle)
   1.744 -{
   1.745 -	CPlugin *pl = FindById(id);
   1.746 -
   1.747 -	if (!pl)
   1.748 -	{
   1.749 -		return false;
   1.750 -	}
   1.751 -
   1.752 -	if (handle)
   1.753 -	{
   1.754 -		*handle = static_cast<void *>(pl->m_Lib);
   1.755 -	}
   1.756 -
   1.757 -	return true;
   1.758 -}
   1.759 -
   1.760 -PluginIter CPluginManager::_begin()
   1.761 -{
   1.762 -	return m_Plugins.begin();
   1.763 -}
   1.764 -
   1.765 -PluginIter CPluginManager::_end()
   1.766 -{
   1.767 -	return m_Plugins.end();
   1.768 -}
   1.769 -
   1.770 -void CPluginManager::AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar)
   1.771 -{
   1.772 -	CPlugin *pl = FindByAPI(api);
   1.773 -
   1.774 -	if (!pl)
   1.775 -	{
   1.776 -		return;
   1.777 -	}
   1.778 -
   1.779 -	pl->m_Cvars.push_back(pCvar);
   1.780 -}
   1.781 -
   1.782 -void CPluginManager::AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd)
   1.783 -{
   1.784 -	CPlugin *pl = FindByAPI(api);
   1.785 -
   1.786 -	if (!pl)
   1.787 -	{
   1.788 -		return;
   1.789 -	}
   1.790 -
   1.791 -	pl->m_Cmds.push_back(pCmd);
   1.792 -}
   1.793 -
   1.794 -void CPluginManager::RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar)
   1.795 -{
   1.796 -	CPlugin *pl = FindByAPI(api);
   1.797 -
   1.798 -	if (!pl)
   1.799 -	{
   1.800 -		return;
   1.801 -	}
   1.802 -
   1.803 -	pl->m_Cvars.remove(pCvar);
   1.804 -}
   1.805 -
   1.806 -void CPluginManager::RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd)
   1.807 -{
   1.808 -	CPlugin *pl = FindByAPI(api);
   1.809 -
   1.810 -	if (!pl)
   1.811 -	{
   1.812 -		return;
   1.813 -	}
   1.814 -
   1.815 -	pl->m_Cmds.remove(pCmd);
   1.816 -}
   1.817 -
   1.818 -void CPluginManager::UnregAllConCmds(CPlugin *pl)
   1.819 -{
   1.820 -	SourceHook::List<ConCommandBase *>::iterator i;
   1.821 -
   1.822 -	/* :TODO: */
   1.823 -	for (i=pl->m_Cvars.begin(); i!=pl->m_Cvars.end(); i++)
   1.824 -	{
   1.825 -		g_Metamod.UnregisterConCommandBase(pl->m_Id, (*i) );
   1.826 -	}
   1.827 -	pl->m_Cvars.clear();
   1.828 -
   1.829 -	for (i=pl->m_Cmds.begin(); i!=pl->m_Cmds.end(); i++)
   1.830 -	{
   1.831 -		g_Metamod.UnregisterConCommandBase(pl->m_Id, (*i) );
   1.832 -	}
   1.833 -	pl->m_Cmds.clear();
   1.834 -}
   1.835 -