Ugh, fixed Linux build for real by removing stray underscores.
3 * =============================================================================
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>.
33 #include "ExtensionSys.h"
34 #include "LibrarySys.h"
37 #include "sourcemm_api.h"
38 #include "sm_srvcmds.h"
39 #include "sm_stringutil.h"
41 CExtensionManager g_Extensions;
42 IdentityType_t g_ExtType;
44 void CExtension::Initialize(const char *filename, const char *path)
49 m_bFullyLoaded = false;
50 m_File.assign(filename);
54 CRemoteExtension::CRemoteExtension(IExtensionInterface *pAPI, const char *filename, const char *path)
56 Initialize(filename, path);
60 CLocalExtension::CLocalExtension(const char *filename)
65 char path[PLATFORM_MAX_PATH];
67 /* First see if there is an engine specific build! */
68 g_SourceMod.BuildPath(Path_SM,
71 #if defined METAMOD_PLAPI_VERSION
72 #if SOURCE_ENGINE == SE_LEFT4DEAD
73 "extensions/auto.2.l4d/%s",
74 #elif SOURCE_ENGINE == SE_ORANGEBOX
75 "extensions/auto.2.ep2/%s",
76 #elif SOURCE_ENGINE == SE_DARKMESSIAH
77 "extensions/auto.2.darkm/%s",
79 "extensions/auto.2.ep1/%s",
80 #endif //SOURCE_ENGINE == SE_LEFT4DEAD
81 #else //METAMOD_PLAPI_VERSION
82 "extensions/auto.1.ep1/%s",
83 #endif //METAMOD_PLAPI_VERSION
86 /* Try the "normal" version */
87 if (!g_LibSys.IsPathFile(path))
89 g_SourceMod.BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "extensions/%s", filename);
92 Initialize(filename, path);
95 bool CRemoteExtension::Load(char *error, size_t maxlength)
97 if (!PerformAPICheck(error, maxlength))
103 if (!CExtension::Load(error, maxlength))
112 bool CLocalExtension::Load(char *error, size_t maxlength)
114 m_pLib = g_LibSys.OpenLibrary(m_Path.c_str(), error, maxlength);
121 typedef IExtensionInterface *(*GETAPI)();
122 GETAPI pfnGetAPI = NULL;
124 if ((pfnGetAPI=(GETAPI)m_pLib->GetSymbolAddress("GetSMExtAPI")) == NULL)
126 m_pLib->CloseLibrary();
128 snprintf(error, maxlength, "Unable to find extension entry point");
132 m_pAPI = pfnGetAPI();
134 /* Check pointer and version */
135 if (!PerformAPICheck(error, maxlength))
137 m_pLib->CloseLibrary();
144 if (m_pAPI->IsMetamodExtension())
147 m_PlId = g_pMMPlugins->Load(m_Path.c_str(), g_PLID, already, error, maxlength);
150 if (!CExtension::Load(error, maxlength))
152 if (m_pAPI->IsMetamodExtension())
157 g_pMMPlugins->Unload(m_PlId, true, dummy, sizeof(dummy));
161 m_pLib->CloseLibrary();
170 void CRemoteExtension::Unload()
174 void CLocalExtension::Unload()
176 if (m_pAPI != NULL && m_PlId)
178 char temp_buffer[255];
179 g_pMMPlugins->Unload(m_PlId, true, temp_buffer, sizeof(temp_buffer));
185 m_pLib->CloseLibrary();
190 bool CRemoteExtension::IsExternal()
195 bool CLocalExtension::IsExternal()
200 CExtension::~CExtension()
205 bool CExtension::PerformAPICheck(char *error, size_t maxlength)
209 snprintf(error, maxlength, "No IExtensionInterface instance provided");
213 if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION)
215 snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
222 bool CExtension::Load(char *error, size_t maxlength)
225 if (!m_pAPI->OnExtensionLoad(this, &g_ShareSys, error, maxlength, !g_SourceMod.IsMapLoading()))
232 /* Check if we're past load time */
233 if (!g_SourceMod.IsMapLoading())
235 m_pAPI->OnExtensionsAllLoaded();
242 void CExtension::CreateIdentity()
244 if (m_pIdentToken != NULL)
249 m_pIdentToken = g_ShareSys.CreateIdentity(g_ExtType, this);
252 void CExtension::DestroyIdentity()
254 if (m_pIdentToken == NULL)
259 g_ShareSys.DestroyIdentity(m_pIdentToken);
260 m_pIdentToken = NULL;
263 void CExtension::MarkAllLoaded()
265 assert(m_bFullyLoaded == false);
268 m_bFullyLoaded = true;
269 m_pAPI->OnExtensionsAllLoaded();
273 void CExtension::AddPlugin(CPlugin *pPlugin)
275 /* Unfortunately we have to do this :( */
276 if (m_Dependents.find(pPlugin) != m_Dependents.end())
278 m_Dependents.push_back(pPlugin);
282 void CExtension::SetError(const char *error)
284 m_Error.assign(error);
287 IExtensionInterface *CExtension::GetAPI()
292 const char *CExtension::GetFilename()
294 return m_File.c_str();
297 IdentityToken_t *CExtension::GetIdentity()
299 return m_pIdentToken;
302 bool CRemoteExtension::IsLoaded()
304 return (m_pAPI != NULL);
307 bool CLocalExtension::IsLoaded()
309 return (m_pLib != NULL);
312 void CExtension::AddDependency(const IfaceInfo *pInfo)
314 if (m_Deps.find(*pInfo) == m_Deps.end())
316 m_Deps.push_back(*pInfo);
320 bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2)
322 return (i1.iface == i2.iface) && (i1.owner == i2.owner);
325 void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
331 List<IfaceInfo>::iterator iter;
332 for (iter = m_ChildDeps.begin();
333 iter != m_ChildDeps.end();
336 IfaceInfo &other = (*iter);
343 m_ChildDeps.push_back(info);
346 ITERATOR *CExtension::FindFirstDependency(IExtension **pOwner, SMInterface **pInterface)
348 List<IfaceInfo>::iterator iter = m_Deps.begin();
350 if (iter == m_Deps.end())
357 *pOwner = (*iter).owner;
361 *pInterface = (*iter).iface;
364 List<IfaceInfo>::iterator *pIter = new List<IfaceInfo>::iterator(iter);
366 return (ITERATOR *)pIter;
369 bool CExtension::FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface)
371 List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
372 List<IfaceInfo>::iterator _iter;
374 if (_iter == m_Deps.end())
383 *pOwner = (*_iter).owner;
387 *pInterface = (*_iter).iface;
392 if (_iter == m_Deps.end())
400 void CExtension::FreeDependencyIterator(ITERATOR *iter)
402 List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
407 void CExtension::AddInterface(SMInterface *pInterface)
409 m_Interfaces.push_back(pInterface);
412 bool CExtension::IsRunning(char *error, size_t maxlength)
418 snprintf(error, maxlength, "%s", m_Error.c_str());
423 return m_pAPI->QueryRunning(error, maxlength);
426 void CExtension::AddLibrary(const char *library)
428 m_Libraries.push_back(library);
431 /*********************
432 * EXTENSION MANAGER *
433 *********************/
435 void CExtensionManager::OnSourceModAllInitialized()
437 g_ExtType = g_ShareSys.CreateIdentType("EXTENSION");
438 g_PluginSys.AddPluginsListener(this);
439 g_RootMenu.AddRootConsoleCommand("exts", "Manage extensions", this);
440 g_ShareSys.AddInterface(NULL, this);
443 void CExtensionManager::OnSourceModShutdown()
445 g_RootMenu.RemoveRootConsoleCommand("exts", this);
446 g_ShareSys.DestroyIdentType(g_ExtType);
449 void CExtensionManager::Shutdown()
451 List<CExtension *>::iterator iter;
453 while ((iter = m_Libs.begin()) != m_Libs.end())
455 UnloadExtension((*iter));
459 void CExtensionManager::TryAutoload()
461 char path[PLATFORM_MAX_PATH];
463 g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "extensions");
465 IDirectory *pDir = g_LibSys.OpenDirectory(path);
473 while (pDir->MoreFiles())
475 if (pDir->IsEntryDirectory())
481 lfile = pDir->GetEntryName();
483 if (len <= 9) /* size of ".autoload" */
489 if (strcmp(&lfile[len - 9], ".autoload") != 0)
495 char file[PLATFORM_MAX_PATH];
496 len = UTIL_Format(file, sizeof(file), "%s", lfile);
497 strcpy(&file[len - 9], ".ext." PLATFORM_LIB_EXT);
499 LoadAutoExtension(file);
505 IExtension *CExtensionManager::LoadAutoExtension(const char *path)
507 if (!strstr(path, "." PLATFORM_LIB_EXT))
509 char newpath[PLATFORM_MAX_PATH];
510 g_LibSys.PathFormat(newpath, sizeof(newpath), "%s.%s", path, PLATFORM_LIB_EXT);
511 return LoadAutoExtension(newpath);
514 IExtension *pAlready;
515 if ((pAlready=FindExtensionByFile(path)) != NULL)
521 CExtension *p = new CLocalExtension(path);
523 /* We put us in the list beforehand so extensions that check for each other
524 * won't recursively load each other.
528 if (!p->Load(error, sizeof(error)) || !p->IsLoaded())
530 g_Logger.LogError("[SM] Unable to load extension \"%s\": %s", path, error);
537 IExtension *CExtensionManager::FindExtensionByFile(const char *file)
539 List<CExtension *>::iterator iter;
542 /* Chomp off the path */
543 char lookup[PLATFORM_MAX_PATH];
544 g_LibSys.GetFileFromPath(lookup, sizeof(lookup), file);
546 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
549 char short_file[PLATFORM_MAX_PATH];
550 g_LibSys.GetFileFromPath(short_file, sizeof(short_file), pExt->GetFilename());
551 if (strcmp(lookup, short_file) == 0)
557 /* If we got no results, test if there was a platform extension.
560 if (!strstr(file, "." PLATFORM_LIB_EXT))
562 char path[PLATFORM_MAX_PATH];
563 UTIL_Format(path, sizeof(path), "%s.%s", file, PLATFORM_LIB_EXT);
564 return FindExtensionByFile(path);
570 IExtension *CExtensionManager::FindExtensionByName(const char *ext)
572 List<CExtension *>::iterator iter;
574 IExtensionInterface *pAPI;
577 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
580 if (!pExt->IsLoaded())
584 if ((pAPI = pExt->GetAPI()) == NULL)
588 name = pAPI->GetExtensionName();
593 if (strcmp(name, ext) == 0)
602 IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size_t maxlength)
604 IExtension *pAlready;
605 if ((pAlready=FindExtensionByFile(file)) != NULL)
610 CExtension *pExt = new CLocalExtension(file);
612 if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
619 /* :TODO: do QueryRunning check if the map is loaded */
621 m_Libs.push_back(pExt);
626 void CExtensionManager::BindDependency(IExtension *pRequester, IfaceInfo *pInfo)
628 CExtension *pExt = (CExtension *)pRequester;
629 CExtension *pOwner = (CExtension *)pInfo->owner;
631 pExt->AddDependency(pInfo);
633 IExtensionInterface *pAPI = pExt->GetAPI();
634 if (pAPI && !pAPI->QueryInterfaceDrop(pInfo->iface))
636 pOwner->AddChildDependent(pExt, pInfo->iface);
640 void CExtensionManager::AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface)
642 CExtension *pExt = (CExtension *)ext;
643 CExtension *pOwner = GetExtensionFromIdent(other);
647 info.iface = (SMInterface *)iface;
650 pExt->AddDependency(&info);
651 pOwner->AddChildDependent(pExt, (SMInterface *)iface);
654 void CExtensionManager::AddInterface(IExtension *pOwner, SMInterface *pInterface)
656 CExtension *pExt = (CExtension *)pOwner;
658 pExt->AddInterface(pInterface);
661 void CExtensionManager::BindChildPlugin( IExtension *pParent, CPlugin *pPlugin )
663 CExtension *pExt = (CExtension *)pParent;
665 pExt->AddPlugin(pPlugin);
668 void CExtensionManager::OnPluginDestroyed(IPlugin *plugin)
670 List<CExtension *>::iterator iter;
672 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
674 (*iter)->DropRefsTo((CPlugin *)plugin);
678 CExtension *CExtensionManager::FindByOrder(unsigned int num)
680 if (num < 1 || num > m_Libs.size())
685 List<CExtension *>::iterator iter = m_Libs.begin();
687 while (iter != m_Libs.end())
699 bool CExtensionManager::UnloadExtension(IExtension *_pExt)
706 CExtension *pExt = (CExtension *)_pExt;
708 if (m_Libs.find(pExt) == m_Libs.end())
713 /* First remove us from internal lists */
714 g_ShareSys.RemoveInterfaces(_pExt);
717 List<CExtension *> UnloadQueue;
719 /* Handle dependencies */
720 if (pExt->IsLoaded())
722 /* Unload any dependent plugins */
723 List<CPlugin *>::iterator p_iter = pExt->m_Dependents.begin();
724 while (p_iter != pExt->m_Dependents.end())
726 /* We have to manually unlink ourselves here, since we're no longer being managed */
727 g_PluginSys.UnloadPlugin((*p_iter));
728 p_iter = pExt->m_Dependents.erase(p_iter);
731 List<String>::iterator s_iter;
732 for (s_iter = pExt->m_Libraries.begin();
733 s_iter != pExt->m_Libraries.end();
736 g_PluginSys.OnLibraryAction((*s_iter).c_str(), false, true);
739 /* Notify and/or unload all dependencies */
740 List<CExtension *>::iterator c_iter;
742 IExtensionInterface *pAPI;
743 for (c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++)
746 if ((pAPI=pDep->GetAPI()) == NULL)
754 /* Now, get its dependency list */
755 bool dropped = false;
756 List<IfaceInfo>::iterator i_iter = pDep->m_Deps.begin();
757 while (i_iter != pDep->m_Deps.end())
759 if ((*i_iter).owner == _pExt)
761 if (!pAPI->QueryInterfaceDrop((*i_iter).iface))
766 UnloadQueue.push_back(pDep);
769 pAPI->NotifyInterfaceDrop((*i_iter).iface);
770 i_iter = pDep->m_Deps.erase(i_iter);
777 /* Flush out any back references to this plugin */
778 i_iter = pDep->m_ChildDeps.begin();
779 while (i_iter != pDep->m_ChildDeps.end())
781 if ((*i_iter).owner == pExt)
783 i_iter = pDep->m_ChildDeps.erase(i_iter);
792 /* Unbind our natives from Core */
793 pExt->DropEverything();
796 IdentityToken_t *pIdentity;
797 if ((pIdentity = pExt->GetIdentity()) != NULL)
799 SMGlobalClass *glob = SMGlobalClass::head;
802 glob->OnSourceModIdentityDropped(pIdentity);
803 glob = glob->m_pGlobalClassNext;
807 /* Tell it to unload */
808 if (pExt->IsLoaded())
810 IExtensionInterface *pAPI = pExt->GetAPI();
811 pAPI->OnExtensionUnload();
817 List<CExtension *>::iterator iter;
818 for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++)
820 /* NOTE: This is safe because the unload function backs out of anything not present */
821 UnloadExtension((*iter));
827 void CExtensionManager::MarkAllLoaded()
829 List<CExtension *>::iterator iter;
832 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
835 if (!pExt->IsLoaded())
839 if (pExt->m_bFullyLoaded)
843 pExt->MarkAllLoaded();
847 void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload)
849 /* This function doesn't really need to do anything now. We make sure the
850 * other extension is loaded, but handling of dependencies is really done
851 * by the interface fetcher.
853 if (required || autoload)
855 LoadAutoExtension(file);
859 void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
861 int argcount = command.ArgC();
864 const char *cmd = command.Arg(2);
865 if (strcmp(cmd, "list") == 0)
867 List<CExtension *>::iterator iter;
869 unsigned int num = 1;
870 switch (m_Libs.size())
874 g_RootMenu.ConsolePrint("[SM] Displaying 1 extension:");
879 g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
884 g_RootMenu.ConsolePrint("[SM] Displaying %d extensions:", m_Libs.size());
888 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++,num++)
891 if (pExt->IsLoaded())
894 if (!pExt->IsRunning(error, sizeof(error)))
896 g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), error);
900 IExtensionInterface *pAPI = pExt->GetAPI();
901 const char *name = pAPI->GetExtensionName();
902 const char *version = pAPI->GetExtensionVerString();
903 const char *descr = pAPI->GetExtensionDescription();
904 g_RootMenu.ConsolePrint("[%02d] %s (%s): %s", num, name, version, descr);
907 g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str());
912 else if (strcmp(cmd, "info") == 0)
916 g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
920 const char *sId = command.Arg(3);
921 unsigned int id = atoi(sId);
924 g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
928 if (m_Libs.size() == 0)
930 g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
934 if (id > m_Libs.size())
936 g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
940 List<CExtension *>::iterator iter = m_Libs.begin();
941 CExtension *pExt = NULL;
942 while (iter != m_Libs.end())
951 /* This should never happen */
954 g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
958 if (!pExt->IsLoaded())
960 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
961 g_RootMenu.ConsolePrint(" Loaded: No (%s)", pExt->m_Error.c_str());
966 if (!pExt->IsRunning(error, sizeof(error)))
968 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
969 g_RootMenu.ConsolePrint(" Loaded: Yes");
970 g_RootMenu.ConsolePrint(" Running: No (%s)", error);
974 IExtensionInterface *pAPI = pExt->GetAPI();
975 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
976 g_RootMenu.ConsolePrint(" Loaded: Yes (version %s)", pAPI->GetExtensionVerString());
977 g_RootMenu.ConsolePrint(" Name: %s (%s)", pAPI->GetExtensionName(), pAPI->GetExtensionDescription());
978 g_RootMenu.ConsolePrint(" Author: %s (%s)", pAPI->GetExtensionAuthor(), pAPI->GetExtensionURL());
979 g_RootMenu.ConsolePrint(" Binary info: API version %d (compiled %s)", pAPI->GetExtensionVersion(), pAPI->GetExtensionDateString());
981 if (pExt->IsExternal())
983 g_RootMenu.ConsolePrint(" Method: Loaded by Metamod:Source, attached to SourceMod");
985 else if (pAPI->IsMetamodExtension())
987 g_RootMenu.ConsolePrint(" Method: Loaded by SourceMod, attached to Metamod:Source");
991 g_RootMenu.ConsolePrint(" Method: Loaded by SourceMod");
997 else if (strcmp(cmd, "unload") == 0)
1001 g_RootMenu.ConsolePrint("[SM] Usage: sm unload <#> [code]");
1005 const char *arg = command.Arg(3);
1006 unsigned int num = atoi(arg);
1007 CExtension *pExt = FindByOrder(num);
1011 g_RootMenu.ConsolePrint("[SM] Extension number %d was not found.", num);
1015 if (argcount > 4 && pExt->unload_code)
1017 const char *unload = command.Arg(4);
1018 if (pExt->unload_code == (unsigned)atoi(unload))
1020 char filename[PLATFORM_MAX_PATH];
1021 snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1022 UnloadExtension(pExt);
1023 g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
1027 g_RootMenu.ConsolePrint("[SM] Please try again, the correct unload code is \"%d\"", pExt->unload_code);
1032 if (!pExt->IsLoaded()
1033 || (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size()))
1035 char filename[PLATFORM_MAX_PATH];
1036 snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1037 UnloadExtension(pExt);
1038 g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
1043 List<CPlugin *> plugins;
1044 if (pExt->m_ChildDeps.size())
1046 g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename());
1047 List<CExtension *>::iterator iter;
1049 /* Get list of all extensions */
1050 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
1052 List<IfaceInfo>::iterator i_iter;
1054 if (!pOther->IsLoaded() || pOther == pExt)
1058 /* Get their dependencies */
1059 for (i_iter=pOther->m_Deps.begin();
1060 i_iter!=pOther->m_Deps.end();
1063 /* Is this dependency to us? */
1064 if ((*i_iter).owner != pExt)
1068 /* Will our dependent care? */
1069 if (!pExt->GetAPI()->QueryInterfaceDrop((*i_iter).iface))
1071 g_RootMenu.ConsolePrint(" -> %s", pExt->GetFilename());
1072 /* Add to plugin unload list */
1073 List<CPlugin *>::iterator p_iter;
1074 for (p_iter=pOther->m_Dependents.begin();
1075 p_iter!=pOther->m_Dependents.end();
1078 if (plugins.find((*p_iter)) == plugins.end())
1080 plugins.push_back((*p_iter));
1087 if (pExt->m_Dependents.size())
1089 g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename());
1090 List<CPlugin *>::iterator iter;
1092 for (iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++)
1095 if (plugins.find(pPlugin) == plugins.end())
1097 plugins.push_back(pPlugin);
1100 for (iter = plugins.begin(); iter != plugins.end(); iter++)
1103 g_RootMenu.ConsolePrint(" -> %s", pPlugin->GetFilename());
1106 srand(static_cast<int>(time(NULL)));
1107 pExt->unload_code = (rand() % 877) + 123; //123 to 999
1108 g_RootMenu.ConsolePrint("[SM] To verify unloading %s, please use the following: ", pExt->GetFilename());
1109 g_RootMenu.ConsolePrint("[SM] sm exts unload %d %d", num, pExt->unload_code);
1116 g_RootMenu.ConsolePrint("SourceMod Extensions Menu:");
1117 g_RootMenu.DrawGenericOption("info", "Extra extension information");
1118 g_RootMenu.DrawGenericOption("list", "List extensions");
1119 g_RootMenu.DrawGenericOption("unload", "Unload an extension");
1122 CExtension *CExtensionManager::GetExtensionFromIdent(IdentityToken_t *ptr)
1124 if (ptr->type == g_ExtType)
1126 return (CExtension *)(ptr->ptr);
1132 CExtensionManager::CExtensionManager()
1136 CExtensionManager::~CExtensionManager()
1140 void CExtensionManager::AddLibrary(IExtension *pSource, const char *library)
1142 CExtension *pExt = (CExtension *)pSource;
1143 pExt->AddLibrary(library);
1144 g_PluginSys.OnLibraryAction(library, false, false);
1147 bool CExtensionManager::LibraryExists(const char *library)
1151 for (List<CExtension *>::iterator iter = m_Libs.begin();
1152 iter != m_Libs.end();
1156 for (List<String>::iterator s_iter = pExt->m_Libraries.begin();
1157 s_iter != pExt->m_Libraries.end();
1160 if ((*s_iter).compare(library) == 0)
1170 IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface,
1171 const char *filepath,
1172 const char *filename,
1176 IExtension *pAlready;
1177 if ((pAlready=FindExtensionByFile(filename)) != NULL)
1182 CExtension *pExt = new CRemoteExtension(pInterface, filename, filepath);
1184 if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
1191 m_Libs.push_back(pExt);
1196 void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
1198 IExtensionInterface *pAPI;
1199 List<CExtension *>::iterator iter;
1201 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
1203 if ((pAPI = (*iter)->GetAPI()) == NULL)
1207 if (pAPI->GetExtensionVersion() > 3)
1209 pAPI->OnCoreMapStart(pEdictList, edictCount, clientMax);