Identities are now dropped before extensions unload.
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 defined ORANGEBOX_BUILD
73 "extensions/auto.2.ep2/%s",
75 "extensions/auto.2.ep1/%s",
76 #endif //ORANGEBOX_BUILD
77 #else //METAMOD_PLAPI_VERSION
78 "extensions/auto.1.ep1/%s",
79 #endif //METAMOD_PLAPI_VERSION
82 /* Try the "normal" version */
83 if (!g_LibSys.IsPathFile(path))
85 g_SourceMod.BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "extensions/%s", filename);
88 Initialize(filename, path);
91 bool CRemoteExtension::Load(char *error, size_t maxlength)
93 if (!PerformAPICheck(error, maxlength))
99 if (!CExtension::Load(error, maxlength))
108 bool CLocalExtension::Load(char *error, size_t maxlength)
110 m_pLib = g_LibSys.OpenLibrary(m_Path.c_str(), error, maxlength);
117 typedef IExtensionInterface *(*GETAPI)();
118 GETAPI pfnGetAPI = NULL;
120 if ((pfnGetAPI=(GETAPI)m_pLib->GetSymbolAddress("GetSMExtAPI")) == NULL)
122 m_pLib->CloseLibrary();
124 snprintf(error, maxlength, "Unable to find extension entry point");
128 m_pAPI = pfnGetAPI();
130 /* Check pointer and version */
131 if (!PerformAPICheck(error, maxlength))
133 m_pLib->CloseLibrary();
140 if (m_pAPI->IsMetamodExtension())
143 m_PlId = g_pMMPlugins->Load(m_Path.c_str(), g_PLID, already, error, maxlength);
146 if (!CExtension::Load(error, maxlength))
148 if (m_pAPI->IsMetamodExtension())
153 g_pMMPlugins->Unload(m_PlId, true, dummy, sizeof(dummy));
157 m_pLib->CloseLibrary();
166 void CRemoteExtension::Unload()
170 void CLocalExtension::Unload()
172 if (m_pAPI != NULL && m_PlId)
174 char temp_buffer[255];
175 g_pMMPlugins->Unload(m_PlId, true, temp_buffer, sizeof(temp_buffer));
181 m_pLib->CloseLibrary();
186 bool CRemoteExtension::IsExternal()
191 bool CLocalExtension::IsExternal()
196 CExtension::~CExtension()
201 bool CExtension::PerformAPICheck(char *error, size_t maxlength)
205 snprintf(error, maxlength, "No IExtensionInterface instance provided");
209 if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION)
211 snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
218 bool CExtension::Load(char *error, size_t maxlength)
221 if (!m_pAPI->OnExtensionLoad(this, &g_ShareSys, error, maxlength, !g_SourceMod.IsMapLoading()))
228 /* Check if we're past load time */
229 if (!g_SourceMod.IsMapLoading())
231 m_pAPI->OnExtensionsAllLoaded();
238 void CExtension::CreateIdentity()
240 if (m_pIdentToken != NULL)
245 m_pIdentToken = g_ShareSys.CreateIdentity(g_ExtType, this);
248 void CExtension::DestroyIdentity()
250 if (m_pIdentToken == NULL)
255 g_ShareSys.DestroyIdentity(m_pIdentToken);
256 m_pIdentToken = NULL;
259 void CExtension::MarkAllLoaded()
261 assert(m_bFullyLoaded == false);
264 m_bFullyLoaded = true;
265 m_pAPI->OnExtensionsAllLoaded();
269 void CExtension::AddPlugin(CPlugin *pPlugin)
271 /* Unfortunately we have to do this :( */
272 if (m_Dependents.find(pPlugin) != m_Dependents.end())
274 m_Dependents.push_back(pPlugin);
278 void CExtension::SetError(const char *error)
280 m_Error.assign(error);
283 IExtensionInterface *CExtension::GetAPI()
288 const char *CExtension::GetFilename()
290 return m_File.c_str();
293 IdentityToken_t *CExtension::GetIdentity()
295 return m_pIdentToken;
298 bool CRemoteExtension::IsLoaded()
300 return (m_pAPI != NULL);
303 bool CLocalExtension::IsLoaded()
305 return (m_pLib != NULL);
308 void CExtension::AddDependency(const IfaceInfo *pInfo)
310 if (m_Deps.find(*pInfo) == m_Deps.end())
312 m_Deps.push_back(*pInfo);
316 bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2)
318 return (i1.iface == i2.iface) && (i1.owner == i2.owner);
321 void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
327 List<IfaceInfo>::iterator iter;
328 for (iter = m_ChildDeps.begin();
329 iter != m_ChildDeps.end();
332 IfaceInfo &other = (*iter);
339 m_ChildDeps.push_back(info);
342 ITERATOR *CExtension::FindFirstDependency(IExtension **pOwner, SMInterface **pInterface)
344 List<IfaceInfo>::iterator iter = m_Deps.begin();
346 if (iter == m_Deps.end())
353 *pOwner = (*iter).owner;
357 *pInterface = (*iter).iface;
360 List<IfaceInfo>::iterator *pIter = new List<IfaceInfo>::iterator(iter);
362 return (ITERATOR *)pIter;
365 bool CExtension::FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface)
367 List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
368 List<IfaceInfo>::iterator _iter;
370 if (_iter == m_Deps.end())
379 *pOwner = (*_iter).owner;
383 *pInterface = (*_iter).iface;
388 if (_iter == m_Deps.end())
396 void CExtension::FreeDependencyIterator(ITERATOR *iter)
398 List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
403 void CExtension::AddInterface(SMInterface *pInterface)
405 m_Interfaces.push_back(pInterface);
408 bool CExtension::IsRunning(char *error, size_t maxlength)
414 snprintf(error, maxlength, "%s", m_Error.c_str());
419 return m_pAPI->QueryRunning(error, maxlength);
422 void CExtension::AddLibrary(const char *library)
424 m_Libraries.push_back(library);
427 /*********************
428 * EXTENSION MANAGER *
429 *********************/
431 void CExtensionManager::OnSourceModAllInitialized()
433 g_ExtType = g_ShareSys.CreateIdentType("EXTENSION");
434 g_PluginSys.AddPluginsListener(this);
435 g_RootMenu.AddRootConsoleCommand("exts", "Manage extensions", this);
436 g_ShareSys.AddInterface(NULL, this);
439 void CExtensionManager::OnSourceModShutdown()
441 g_RootMenu.RemoveRootConsoleCommand("exts", this);
442 g_ShareSys.DestroyIdentType(g_ExtType);
445 void CExtensionManager::Shutdown()
447 List<CExtension *>::iterator iter;
449 while ((iter = m_Libs.begin()) != m_Libs.end())
451 UnloadExtension((*iter));
455 void CExtensionManager::TryAutoload()
457 char path[PLATFORM_MAX_PATH];
459 g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "extensions");
461 IDirectory *pDir = g_LibSys.OpenDirectory(path);
469 while (pDir->MoreFiles())
471 if (pDir->IsEntryDirectory())
477 lfile = pDir->GetEntryName();
479 if (len <= 9) /* size of ".autoload" */
485 if (strcmp(&lfile[len - 9], ".autoload") != 0)
491 char file[PLATFORM_MAX_PATH];
492 len = UTIL_Format(file, sizeof(file), "%s", lfile);
493 strcpy(&file[len - 9], ".ext." PLATFORM_LIB_EXT);
495 LoadAutoExtension(file);
501 IExtension *CExtensionManager::LoadAutoExtension(const char *path)
503 if (!strstr(path, "." PLATFORM_LIB_EXT))
505 char newpath[PLATFORM_MAX_PATH];
506 g_LibSys.PathFormat(newpath, sizeof(newpath), "%s.%s", path, PLATFORM_LIB_EXT);
507 return LoadAutoExtension(newpath);
510 IExtension *pAlready;
511 if ((pAlready=FindExtensionByFile(path)) != NULL)
517 CExtension *p = new CLocalExtension(path);
519 /* We put us in the list beforehand so extensions that check for each other
520 * won't recursively load each other.
524 if (!p->Load(error, sizeof(error)) || !p->IsLoaded())
526 g_Logger.LogError("[SM] Unable to load extension \"%s\": %s", path, error);
533 IExtension *CExtensionManager::FindExtensionByFile(const char *file)
535 List<CExtension *>::iterator iter;
538 /* Chomp off the path */
539 char lookup[PLATFORM_MAX_PATH];
540 g_LibSys.GetFileFromPath(lookup, sizeof(lookup), file);
542 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
545 char short_file[PLATFORM_MAX_PATH];
546 g_LibSys.GetFileFromPath(short_file, sizeof(short_file), pExt->GetFilename());
547 if (strcmp(lookup, short_file) == 0)
553 /* If we got no results, test if there was a platform extension.
556 if (!strstr(file, "." PLATFORM_LIB_EXT))
558 char path[PLATFORM_MAX_PATH];
559 UTIL_Format(path, sizeof(path), "%s.%s", file, PLATFORM_LIB_EXT);
560 return FindExtensionByFile(path);
566 IExtension *CExtensionManager::FindExtensionByName(const char *ext)
568 List<CExtension *>::iterator iter;
570 IExtensionInterface *pAPI;
573 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
576 if (!pExt->IsLoaded())
580 if ((pAPI = pExt->GetAPI()) == NULL)
584 name = pAPI->GetExtensionName();
589 if (strcmp(name, ext) == 0)
598 IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size_t maxlength)
600 IExtension *pAlready;
601 if ((pAlready=FindExtensionByFile(file)) != NULL)
606 CExtension *pExt = new CLocalExtension(file);
608 if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
615 /* :TODO: do QueryRunning check if the map is loaded */
617 m_Libs.push_back(pExt);
622 void CExtensionManager::BindDependency(IExtension *pRequester, IfaceInfo *pInfo)
624 CExtension *pExt = (CExtension *)pRequester;
625 CExtension *pOwner = (CExtension *)pInfo->owner;
627 pExt->AddDependency(pInfo);
629 IExtensionInterface *pAPI = pExt->GetAPI();
630 if (pAPI && !pAPI->QueryInterfaceDrop(pInfo->iface))
632 pOwner->AddChildDependent(pExt, pInfo->iface);
636 void CExtensionManager::AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface)
638 CExtension *pExt = (CExtension *)ext;
639 CExtension *pOwner = GetExtensionFromIdent(other);
643 info.iface = (SMInterface *)iface;
646 pExt->AddDependency(&info);
647 pOwner->AddChildDependent(pExt, (SMInterface *)iface);
650 void CExtensionManager::AddInterface(IExtension *pOwner, SMInterface *pInterface)
652 CExtension *pExt = (CExtension *)pOwner;
654 pExt->AddInterface(pInterface);
657 void CExtensionManager::BindChildPlugin( IExtension *pParent, CPlugin *pPlugin )
659 CExtension *pExt = (CExtension *)pParent;
661 pExt->AddPlugin(pPlugin);
664 void CExtensionManager::OnPluginDestroyed(IPlugin *plugin)
666 List<CExtension *>::iterator iter;
668 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
670 (*iter)->DropRefsTo((CPlugin *)plugin);
674 CExtension *CExtensionManager::FindByOrder(unsigned int num)
676 if (num < 1 || num > m_Libs.size())
681 List<CExtension *>::iterator iter = m_Libs.begin();
683 while (iter != m_Libs.end())
695 bool CExtensionManager::UnloadExtension(IExtension *_pExt)
702 CExtension *pExt = (CExtension *)_pExt;
704 if (m_Libs.find(pExt) == m_Libs.end())
709 /* First remove us from internal lists */
710 g_ShareSys.RemoveInterfaces(_pExt);
713 List<CExtension *> UnloadQueue;
715 /* Handle dependencies */
716 if (pExt->IsLoaded())
718 /* Unload any dependent plugins */
719 List<CPlugin *>::iterator p_iter = pExt->m_Dependents.begin();
720 while (p_iter != pExt->m_Dependents.end())
722 /* We have to manually unlink ourselves here, since we're no longer being managed */
723 g_PluginSys.UnloadPlugin((*p_iter));
724 p_iter = pExt->m_Dependents.erase(p_iter);
727 List<String>::iterator s_iter;
728 for (s_iter = pExt->m_Libraries.begin();
729 s_iter != pExt->m_Libraries.end();
732 g_PluginSys.OnLibraryAction((*s_iter).c_str(), false, true);
735 /* Notify and/or unload all dependencies */
736 List<CExtension *>::iterator c_iter;
738 IExtensionInterface *pAPI;
739 for (c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++)
742 if ((pAPI=pDep->GetAPI()) == NULL)
750 /* Now, get its dependency list */
751 bool dropped = false;
752 List<IfaceInfo>::iterator i_iter = pDep->m_Deps.begin();
753 while (i_iter != pDep->m_Deps.end())
755 if ((*i_iter).owner == _pExt)
757 if (!pAPI->QueryInterfaceDrop((*i_iter).iface))
762 UnloadQueue.push_back(pDep);
765 pAPI->NotifyInterfaceDrop((*i_iter).iface);
766 i_iter = pDep->m_Deps.erase(i_iter);
773 /* Flush out any back references to this plugin */
774 i_iter = pDep->m_ChildDeps.begin();
775 while (i_iter != pDep->m_ChildDeps.end())
777 if ((*i_iter).owner == pExt)
779 i_iter = pDep->m_ChildDeps.erase(i_iter);
788 /* Unbind our natives from Core */
789 pExt->DropEverything();
792 IdentityToken_t *pIdentity;
793 if ((pIdentity = pExt->GetIdentity()) != NULL)
795 SMGlobalClass *glob = SMGlobalClass::head;
798 glob->OnSourceModIdentityDropped(pIdentity);
799 glob = glob->m_pGlobalClassNext;
803 /* Tell it to unload */
804 if (pExt->IsLoaded())
806 IExtensionInterface *pAPI = pExt->GetAPI();
807 pAPI->OnExtensionUnload();
813 List<CExtension *>::iterator iter;
814 for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++)
816 /* NOTE: This is safe because the unload function backs out of anything not present */
817 UnloadExtension((*iter));
823 void CExtensionManager::MarkAllLoaded()
825 List<CExtension *>::iterator iter;
828 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
831 if (!pExt->IsLoaded())
835 if (pExt->m_bFullyLoaded)
839 pExt->MarkAllLoaded();
843 void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload)
845 /* This function doesn't really need to do anything now. We make sure the
846 * other extension is loaded, but handling of dependencies is really done
847 * by the interface fetcher.
849 if (required || autoload)
851 LoadAutoExtension(file);
855 void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
857 int argcount = command.ArgC();
860 const char *cmd = command.Arg(2);
861 if (strcmp(cmd, "list") == 0)
863 List<CExtension *>::iterator iter;
865 unsigned int num = 1;
866 switch (m_Libs.size())
870 g_RootMenu.ConsolePrint("[SM] Displaying 1 extension:");
875 g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
880 g_RootMenu.ConsolePrint("[SM] Displaying %d extensions:", m_Libs.size());
884 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++,num++)
887 if (pExt->IsLoaded())
890 if (!pExt->IsRunning(error, sizeof(error)))
892 g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), error);
896 IExtensionInterface *pAPI = pExt->GetAPI();
897 const char *name = pAPI->GetExtensionName();
898 const char *version = pAPI->GetExtensionVerString();
899 const char *descr = pAPI->GetExtensionDescription();
900 g_RootMenu.ConsolePrint("[%02d] %s (%s): %s", num, name, version, descr);
903 g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str());
908 else if (strcmp(cmd, "info") == 0)
912 g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
916 const char *sId = command.Arg(3);
917 unsigned int id = atoi(sId);
920 g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
924 if (m_Libs.size() == 0)
926 g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
930 if (id > m_Libs.size())
932 g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
936 List<CExtension *>::iterator iter = m_Libs.begin();
937 CExtension *pExt = NULL;
938 while (iter != m_Libs.end())
947 /* This should never happen */
950 g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
954 if (!pExt->IsLoaded())
956 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
957 g_RootMenu.ConsolePrint(" Loaded: No (%s)", pExt->m_Error.c_str());
962 if (!pExt->IsRunning(error, sizeof(error)))
964 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
965 g_RootMenu.ConsolePrint(" Loaded: Yes");
966 g_RootMenu.ConsolePrint(" Running: No (%s)", error);
970 IExtensionInterface *pAPI = pExt->GetAPI();
971 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
972 g_RootMenu.ConsolePrint(" Loaded: Yes (version %s)", pAPI->GetExtensionVerString());
973 g_RootMenu.ConsolePrint(" Name: %s (%s)", pAPI->GetExtensionName(), pAPI->GetExtensionDescription());
974 g_RootMenu.ConsolePrint(" Author: %s (%s)", pAPI->GetExtensionAuthor(), pAPI->GetExtensionURL());
975 g_RootMenu.ConsolePrint(" Binary info: API version %d (compiled %s)", pAPI->GetExtensionVersion(), pAPI->GetExtensionDateString());
977 if (pExt->IsExternal())
979 g_RootMenu.ConsolePrint(" Method: Loaded by Metamod:Source, attached to SourceMod");
981 else if (pAPI->IsMetamodExtension())
983 g_RootMenu.ConsolePrint(" Method: Loaded by SourceMod, attached to Metamod:Source");
987 g_RootMenu.ConsolePrint(" Method: Loaded by SourceMod");
993 else if (strcmp(cmd, "unload") == 0)
997 g_RootMenu.ConsolePrint("[SM] Usage: sm unload <#> [code]");
1001 const char *arg = command.Arg(3);
1002 unsigned int num = atoi(arg);
1003 CExtension *pExt = FindByOrder(num);
1007 g_RootMenu.ConsolePrint("[SM] Extension number %d was not found.", num);
1011 if (argcount > 4 && pExt->unload_code)
1013 const char *unload = command.Arg(4);
1014 if (pExt->unload_code == (unsigned)atoi(unload))
1016 char filename[PLATFORM_MAX_PATH];
1017 snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1018 UnloadExtension(pExt);
1019 g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
1023 g_RootMenu.ConsolePrint("[SM] Please try again, the correct unload code is \"%d\"", pExt->unload_code);
1028 if (!pExt->IsLoaded()
1029 || (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size()))
1031 char filename[PLATFORM_MAX_PATH];
1032 snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1033 UnloadExtension(pExt);
1034 g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
1039 List<CPlugin *> plugins;
1040 if (pExt->m_ChildDeps.size())
1042 g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename());
1043 List<CExtension *>::iterator iter;
1045 /* Get list of all extensions */
1046 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
1048 List<IfaceInfo>::iterator i_iter;
1050 if (!pOther->IsLoaded() || pOther == pExt)
1054 /* Get their dependencies */
1055 for (i_iter=pOther->m_Deps.begin();
1056 i_iter!=pOther->m_Deps.end();
1059 /* Is this dependency to us? */
1060 if ((*i_iter).owner != pExt)
1064 /* Will our dependent care? */
1065 if (!pExt->GetAPI()->QueryInterfaceDrop((*i_iter).iface))
1067 g_RootMenu.ConsolePrint(" -> %s", pExt->GetFilename());
1068 /* Add to plugin unload list */
1069 List<CPlugin *>::iterator p_iter;
1070 for (p_iter=pOther->m_Dependents.begin();
1071 p_iter!=pOther->m_Dependents.end();
1074 if (plugins.find((*p_iter)) == plugins.end())
1076 plugins.push_back((*p_iter));
1083 if (pExt->m_Dependents.size())
1085 g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename());
1086 List<CPlugin *>::iterator iter;
1088 for (iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++)
1091 if (plugins.find(pPlugin) == plugins.end())
1093 plugins.push_back(pPlugin);
1096 for (iter = plugins.begin(); iter != plugins.end(); iter++)
1099 g_RootMenu.ConsolePrint(" -> %s", pPlugin->GetFilename());
1102 srand(static_cast<int>(time(NULL)));
1103 pExt->unload_code = (rand() % 877) + 123; //123 to 999
1104 g_RootMenu.ConsolePrint("[SM] To verify unloading %s, please use the following: ", pExt->GetFilename());
1105 g_RootMenu.ConsolePrint("[SM] sm exts unload %d %d", num, pExt->unload_code);
1112 g_RootMenu.ConsolePrint("SourceMod Extensions Menu:");
1113 g_RootMenu.DrawGenericOption("info", "Extra extension information");
1114 g_RootMenu.DrawGenericOption("list", "List extensions");
1115 g_RootMenu.DrawGenericOption("unload", "Unload an extension");
1118 CExtension *CExtensionManager::GetExtensionFromIdent(IdentityToken_t *ptr)
1120 if (ptr->type == g_ExtType)
1122 return (CExtension *)(ptr->ptr);
1128 CExtensionManager::CExtensionManager()
1132 CExtensionManager::~CExtensionManager()
1136 void CExtensionManager::AddLibrary(IExtension *pSource, const char *library)
1138 CExtension *pExt = (CExtension *)pSource;
1139 pExt->AddLibrary(library);
1140 g_PluginSys.OnLibraryAction(library, false, false);
1143 bool CExtensionManager::LibraryExists(const char *library)
1147 for (List<CExtension *>::iterator iter = m_Libs.begin();
1148 iter != m_Libs.end();
1152 for (List<String>::iterator s_iter = pExt->m_Libraries.begin();
1153 s_iter != pExt->m_Libraries.end();
1156 if ((*s_iter).compare(library) == 0)
1166 IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface,
1167 const char *filepath,
1168 const char *filename,
1172 IExtension *pAlready;
1173 if ((pAlready=FindExtensionByFile(filename)) != NULL)
1178 CExtension *pExt = new CRemoteExtension(pInterface, filename, filepath);
1180 if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
1187 m_Libs.push_back(pExt);
1192 void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
1194 IExtensionInterface *pAPI;
1195 List<CExtension *>::iterator iter;
1197 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
1199 if ((pAPI = (*iter)->GetAPI()) == NULL)
1203 if (pAPI->GetExtensionVersion() > 3)
1205 pAPI->OnCoreMapStart(pEdictList, edictCount, clientMax);