Merge.
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",
77 "extensions/auto.2.ep1/%s",
78 #endif //SOURCE_ENGINE == SE_LEFT4DEAD
79 #else //METAMOD_PLAPI_VERSION
80 "extensions/auto.1.ep1/%s",
81 #endif //METAMOD_PLAPI_VERSION
84 /* Try the "normal" version */
85 if (!g_LibSys.IsPathFile(path))
87 g_SourceMod.BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "extensions/%s", filename);
90 Initialize(filename, path);
93 bool CRemoteExtension::Load(char *error, size_t maxlength)
95 if (!PerformAPICheck(error, maxlength))
101 if (!CExtension::Load(error, maxlength))
110 bool CLocalExtension::Load(char *error, size_t maxlength)
112 m_pLib = g_LibSys.OpenLibrary(m_Path.c_str(), error, maxlength);
119 typedef IExtensionInterface *(*GETAPI)();
120 GETAPI pfnGetAPI = NULL;
122 if ((pfnGetAPI=(GETAPI)m_pLib->GetSymbolAddress("GetSMExtAPI")) == NULL)
124 m_pLib->CloseLibrary();
126 snprintf(error, maxlength, "Unable to find extension entry point");
130 m_pAPI = pfnGetAPI();
132 /* Check pointer and version */
133 if (!PerformAPICheck(error, maxlength))
135 m_pLib->CloseLibrary();
142 if (m_pAPI->IsMetamodExtension())
145 m_PlId = g_pMMPlugins->Load(m_Path.c_str(), g_PLID, already, error, maxlength);
148 if (!CExtension::Load(error, maxlength))
150 if (m_pAPI->IsMetamodExtension())
155 g_pMMPlugins->Unload(m_PlId, true, dummy, sizeof(dummy));
159 m_pLib->CloseLibrary();
168 void CRemoteExtension::Unload()
172 void CLocalExtension::Unload()
174 if (m_pAPI != NULL && m_PlId)
176 char temp_buffer[255];
177 g_pMMPlugins->Unload(m_PlId, true, temp_buffer, sizeof(temp_buffer));
183 m_pLib->CloseLibrary();
188 bool CRemoteExtension::IsExternal()
193 bool CLocalExtension::IsExternal()
198 CExtension::~CExtension()
203 bool CExtension::PerformAPICheck(char *error, size_t maxlength)
207 snprintf(error, maxlength, "No IExtensionInterface instance provided");
211 if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION)
213 snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
220 bool CExtension::Load(char *error, size_t maxlength)
223 if (!m_pAPI->OnExtensionLoad(this, &g_ShareSys, error, maxlength, !g_SourceMod.IsMapLoading()))
230 /* Check if we're past load time */
231 if (!g_SourceMod.IsMapLoading())
233 m_pAPI->OnExtensionsAllLoaded();
240 void CExtension::CreateIdentity()
242 if (m_pIdentToken != NULL)
247 m_pIdentToken = g_ShareSys.CreateIdentity(g_ExtType, this);
250 void CExtension::DestroyIdentity()
252 if (m_pIdentToken == NULL)
257 g_ShareSys.DestroyIdentity(m_pIdentToken);
258 m_pIdentToken = NULL;
261 void CExtension::MarkAllLoaded()
263 assert(m_bFullyLoaded == false);
266 m_bFullyLoaded = true;
267 m_pAPI->OnExtensionsAllLoaded();
271 void CExtension::AddPlugin(CPlugin *pPlugin)
273 /* Unfortunately we have to do this :( */
274 if (m_Dependents.find(pPlugin) != m_Dependents.end())
276 m_Dependents.push_back(pPlugin);
280 void CExtension::SetError(const char *error)
282 m_Error.assign(error);
285 IExtensionInterface *CExtension::GetAPI()
290 const char *CExtension::GetFilename()
292 return m_File.c_str();
295 IdentityToken_t *CExtension::GetIdentity()
297 return m_pIdentToken;
300 bool CRemoteExtension::IsLoaded()
302 return (m_pAPI != NULL);
305 bool CLocalExtension::IsLoaded()
307 return (m_pLib != NULL);
310 void CExtension::AddDependency(const IfaceInfo *pInfo)
312 if (m_Deps.find(*pInfo) == m_Deps.end())
314 m_Deps.push_back(*pInfo);
318 bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2)
320 return (i1.iface == i2.iface) && (i1.owner == i2.owner);
323 void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
329 List<IfaceInfo>::iterator iter;
330 for (iter = m_ChildDeps.begin();
331 iter != m_ChildDeps.end();
334 IfaceInfo &other = (*iter);
341 m_ChildDeps.push_back(info);
344 ITERATOR *CExtension::FindFirstDependency(IExtension **pOwner, SMInterface **pInterface)
346 List<IfaceInfo>::iterator iter = m_Deps.begin();
348 if (iter == m_Deps.end())
355 *pOwner = (*iter).owner;
359 *pInterface = (*iter).iface;
362 List<IfaceInfo>::iterator *pIter = new List<IfaceInfo>::iterator(iter);
364 return (ITERATOR *)pIter;
367 bool CExtension::FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface)
369 List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
370 List<IfaceInfo>::iterator _iter;
372 if (_iter == m_Deps.end())
381 *pOwner = (*_iter).owner;
385 *pInterface = (*_iter).iface;
390 if (_iter == m_Deps.end())
398 void CExtension::FreeDependencyIterator(ITERATOR *iter)
400 List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
405 void CExtension::AddInterface(SMInterface *pInterface)
407 m_Interfaces.push_back(pInterface);
410 bool CExtension::IsRunning(char *error, size_t maxlength)
416 snprintf(error, maxlength, "%s", m_Error.c_str());
421 return m_pAPI->QueryRunning(error, maxlength);
424 void CExtension::AddLibrary(const char *library)
426 m_Libraries.push_back(library);
429 /*********************
430 * EXTENSION MANAGER *
431 *********************/
433 void CExtensionManager::OnSourceModAllInitialized()
435 g_ExtType = g_ShareSys.CreateIdentType("EXTENSION");
436 g_PluginSys.AddPluginsListener(this);
437 g_RootMenu.AddRootConsoleCommand("exts", "Manage extensions", this);
438 g_ShareSys.AddInterface(NULL, this);
441 void CExtensionManager::OnSourceModShutdown()
443 g_RootMenu.RemoveRootConsoleCommand("exts", this);
444 g_ShareSys.DestroyIdentType(g_ExtType);
447 void CExtensionManager::Shutdown()
449 List<CExtension *>::iterator iter;
451 while ((iter = m_Libs.begin()) != m_Libs.end())
453 UnloadExtension((*iter));
457 void CExtensionManager::TryAutoload()
459 char path[PLATFORM_MAX_PATH];
461 g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "extensions");
463 IDirectory *pDir = g_LibSys.OpenDirectory(path);
471 while (pDir->MoreFiles())
473 if (pDir->IsEntryDirectory())
479 lfile = pDir->GetEntryName();
481 if (len <= 9) /* size of ".autoload" */
487 if (strcmp(&lfile[len - 9], ".autoload") != 0)
493 char file[PLATFORM_MAX_PATH];
494 len = UTIL_Format(file, sizeof(file), "%s", lfile);
495 strcpy(&file[len - 9], ".ext." PLATFORM_LIB_EXT);
497 LoadAutoExtension(file);
503 IExtension *CExtensionManager::LoadAutoExtension(const char *path)
505 if (!strstr(path, "." PLATFORM_LIB_EXT))
507 char newpath[PLATFORM_MAX_PATH];
508 g_LibSys.PathFormat(newpath, sizeof(newpath), "%s.%s", path, PLATFORM_LIB_EXT);
509 return LoadAutoExtension(newpath);
512 IExtension *pAlready;
513 if ((pAlready=FindExtensionByFile(path)) != NULL)
519 CExtension *p = new CLocalExtension(path);
521 /* We put us in the list beforehand so extensions that check for each other
522 * won't recursively load each other.
526 if (!p->Load(error, sizeof(error)) || !p->IsLoaded())
528 g_Logger.LogError("[SM] Unable to load extension \"%s\": %s", path, error);
535 IExtension *CExtensionManager::FindExtensionByFile(const char *file)
537 List<CExtension *>::iterator iter;
540 /* Chomp off the path */
541 char lookup[PLATFORM_MAX_PATH];
542 g_LibSys.GetFileFromPath(lookup, sizeof(lookup), file);
544 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
547 char short_file[PLATFORM_MAX_PATH];
548 g_LibSys.GetFileFromPath(short_file, sizeof(short_file), pExt->GetFilename());
549 if (strcmp(lookup, short_file) == 0)
555 /* If we got no results, test if there was a platform extension.
558 if (!strstr(file, "." PLATFORM_LIB_EXT))
560 char path[PLATFORM_MAX_PATH];
561 UTIL_Format(path, sizeof(path), "%s.%s", file, PLATFORM_LIB_EXT);
562 return FindExtensionByFile(path);
568 IExtension *CExtensionManager::FindExtensionByName(const char *ext)
570 List<CExtension *>::iterator iter;
572 IExtensionInterface *pAPI;
575 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
578 if (!pExt->IsLoaded())
582 if ((pAPI = pExt->GetAPI()) == NULL)
586 name = pAPI->GetExtensionName();
591 if (strcmp(name, ext) == 0)
600 IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size_t maxlength)
602 IExtension *pAlready;
603 if ((pAlready=FindExtensionByFile(file)) != NULL)
608 CExtension *pExt = new CLocalExtension(file);
610 if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
617 /* :TODO: do QueryRunning check if the map is loaded */
619 m_Libs.push_back(pExt);
624 void CExtensionManager::BindDependency(IExtension *pRequester, IfaceInfo *pInfo)
626 CExtension *pExt = (CExtension *)pRequester;
627 CExtension *pOwner = (CExtension *)pInfo->owner;
629 pExt->AddDependency(pInfo);
631 IExtensionInterface *pAPI = pExt->GetAPI();
632 if (pAPI && !pAPI->QueryInterfaceDrop(pInfo->iface))
634 pOwner->AddChildDependent(pExt, pInfo->iface);
638 void CExtensionManager::AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface)
640 CExtension *pExt = (CExtension *)ext;
641 CExtension *pOwner = GetExtensionFromIdent(other);
645 info.iface = (SMInterface *)iface;
648 pExt->AddDependency(&info);
649 pOwner->AddChildDependent(pExt, (SMInterface *)iface);
652 void CExtensionManager::AddInterface(IExtension *pOwner, SMInterface *pInterface)
654 CExtension *pExt = (CExtension *)pOwner;
656 pExt->AddInterface(pInterface);
659 void CExtensionManager::BindChildPlugin( IExtension *pParent, CPlugin *pPlugin )
661 CExtension *pExt = (CExtension *)pParent;
663 pExt->AddPlugin(pPlugin);
666 void CExtensionManager::OnPluginDestroyed(IPlugin *plugin)
668 List<CExtension *>::iterator iter;
670 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
672 (*iter)->DropRefsTo((CPlugin *)plugin);
676 CExtension *CExtensionManager::FindByOrder(unsigned int num)
678 if (num < 1 || num > m_Libs.size())
683 List<CExtension *>::iterator iter = m_Libs.begin();
685 while (iter != m_Libs.end())
697 bool CExtensionManager::UnloadExtension(IExtension *_pExt)
704 CExtension *pExt = (CExtension *)_pExt;
706 if (m_Libs.find(pExt) == m_Libs.end())
711 /* First remove us from internal lists */
712 g_ShareSys.RemoveInterfaces(_pExt);
715 List<CExtension *> UnloadQueue;
717 /* Handle dependencies */
718 if (pExt->IsLoaded())
720 /* Unload any dependent plugins */
721 List<CPlugin *>::iterator p_iter = pExt->m_Dependents.begin();
722 while (p_iter != pExt->m_Dependents.end())
724 /* We have to manually unlink ourselves here, since we're no longer being managed */
725 g_PluginSys.UnloadPlugin((*p_iter));
726 p_iter = pExt->m_Dependents.erase(p_iter);
729 List<String>::iterator s_iter;
730 for (s_iter = pExt->m_Libraries.begin();
731 s_iter != pExt->m_Libraries.end();
734 g_PluginSys.OnLibraryAction((*s_iter).c_str(), false, true);
737 /* Notify and/or unload all dependencies */
738 List<CExtension *>::iterator c_iter;
740 IExtensionInterface *pAPI;
741 for (c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++)
744 if ((pAPI=pDep->GetAPI()) == NULL)
752 /* Now, get its dependency list */
753 bool dropped = false;
754 List<IfaceInfo>::iterator i_iter = pDep->m_Deps.begin();
755 while (i_iter != pDep->m_Deps.end())
757 if ((*i_iter).owner == _pExt)
759 if (!pAPI->QueryInterfaceDrop((*i_iter).iface))
764 UnloadQueue.push_back(pDep);
767 pAPI->NotifyInterfaceDrop((*i_iter).iface);
768 i_iter = pDep->m_Deps.erase(i_iter);
775 /* Flush out any back references to this plugin */
776 i_iter = pDep->m_ChildDeps.begin();
777 while (i_iter != pDep->m_ChildDeps.end())
779 if ((*i_iter).owner == pExt)
781 i_iter = pDep->m_ChildDeps.erase(i_iter);
790 /* Unbind our natives from Core */
791 pExt->DropEverything();
794 IdentityToken_t *pIdentity;
795 if ((pIdentity = pExt->GetIdentity()) != NULL)
797 SMGlobalClass *glob = SMGlobalClass::head;
800 glob->OnSourceModIdentityDropped(pIdentity);
801 glob = glob->m_pGlobalClassNext;
805 /* Tell it to unload */
806 if (pExt->IsLoaded())
808 IExtensionInterface *pAPI = pExt->GetAPI();
809 pAPI->OnExtensionUnload();
815 List<CExtension *>::iterator iter;
816 for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++)
818 /* NOTE: This is safe because the unload function backs out of anything not present */
819 UnloadExtension((*iter));
825 void CExtensionManager::MarkAllLoaded()
827 List<CExtension *>::iterator iter;
830 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
833 if (!pExt->IsLoaded())
837 if (pExt->m_bFullyLoaded)
841 pExt->MarkAllLoaded();
845 void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload)
847 /* This function doesn't really need to do anything now. We make sure the
848 * other extension is loaded, but handling of dependencies is really done
849 * by the interface fetcher.
851 if (required || autoload)
853 LoadAutoExtension(file);
857 void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
859 int argcount = command.ArgC();
862 const char *cmd = command.Arg(2);
863 if (strcmp(cmd, "list") == 0)
865 List<CExtension *>::iterator iter;
867 unsigned int num = 1;
868 switch (m_Libs.size())
872 g_RootMenu.ConsolePrint("[SM] Displaying 1 extension:");
877 g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
882 g_RootMenu.ConsolePrint("[SM] Displaying %d extensions:", m_Libs.size());
886 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++,num++)
889 if (pExt->IsLoaded())
892 if (!pExt->IsRunning(error, sizeof(error)))
894 g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), error);
898 IExtensionInterface *pAPI = pExt->GetAPI();
899 const char *name = pAPI->GetExtensionName();
900 const char *version = pAPI->GetExtensionVerString();
901 const char *descr = pAPI->GetExtensionDescription();
902 g_RootMenu.ConsolePrint("[%02d] %s (%s): %s", num, name, version, descr);
905 g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str());
910 else if (strcmp(cmd, "info") == 0)
914 g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
918 const char *sId = command.Arg(3);
919 unsigned int id = atoi(sId);
922 g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
926 if (m_Libs.size() == 0)
928 g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
932 if (id > m_Libs.size())
934 g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
938 List<CExtension *>::iterator iter = m_Libs.begin();
939 CExtension *pExt = NULL;
940 while (iter != m_Libs.end())
949 /* This should never happen */
952 g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
956 if (!pExt->IsLoaded())
958 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
959 g_RootMenu.ConsolePrint(" Loaded: No (%s)", pExt->m_Error.c_str());
964 if (!pExt->IsRunning(error, sizeof(error)))
966 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
967 g_RootMenu.ConsolePrint(" Loaded: Yes");
968 g_RootMenu.ConsolePrint(" Running: No (%s)", error);
972 IExtensionInterface *pAPI = pExt->GetAPI();
973 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
974 g_RootMenu.ConsolePrint(" Loaded: Yes (version %s)", pAPI->GetExtensionVerString());
975 g_RootMenu.ConsolePrint(" Name: %s (%s)", pAPI->GetExtensionName(), pAPI->GetExtensionDescription());
976 g_RootMenu.ConsolePrint(" Author: %s (%s)", pAPI->GetExtensionAuthor(), pAPI->GetExtensionURL());
977 g_RootMenu.ConsolePrint(" Binary info: API version %d (compiled %s)", pAPI->GetExtensionVersion(), pAPI->GetExtensionDateString());
979 if (pExt->IsExternal())
981 g_RootMenu.ConsolePrint(" Method: Loaded by Metamod:Source, attached to SourceMod");
983 else if (pAPI->IsMetamodExtension())
985 g_RootMenu.ConsolePrint(" Method: Loaded by SourceMod, attached to Metamod:Source");
989 g_RootMenu.ConsolePrint(" Method: Loaded by SourceMod");
995 else if (strcmp(cmd, "unload") == 0)
999 g_RootMenu.ConsolePrint("[SM] Usage: sm unload <#> [code]");
1003 const char *arg = command.Arg(3);
1004 unsigned int num = atoi(arg);
1005 CExtension *pExt = FindByOrder(num);
1009 g_RootMenu.ConsolePrint("[SM] Extension number %d was not found.", num);
1013 if (argcount > 4 && pExt->unload_code)
1015 const char *unload = command.Arg(4);
1016 if (pExt->unload_code == (unsigned)atoi(unload))
1018 char filename[PLATFORM_MAX_PATH];
1019 snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1020 UnloadExtension(pExt);
1021 g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
1025 g_RootMenu.ConsolePrint("[SM] Please try again, the correct unload code is \"%d\"", pExt->unload_code);
1030 if (!pExt->IsLoaded()
1031 || (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size()))
1033 char filename[PLATFORM_MAX_PATH];
1034 snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1035 UnloadExtension(pExt);
1036 g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
1041 List<CPlugin *> plugins;
1042 if (pExt->m_ChildDeps.size())
1044 g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename());
1045 List<CExtension *>::iterator iter;
1047 /* Get list of all extensions */
1048 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
1050 List<IfaceInfo>::iterator i_iter;
1052 if (!pOther->IsLoaded() || pOther == pExt)
1056 /* Get their dependencies */
1057 for (i_iter=pOther->m_Deps.begin();
1058 i_iter!=pOther->m_Deps.end();
1061 /* Is this dependency to us? */
1062 if ((*i_iter).owner != pExt)
1066 /* Will our dependent care? */
1067 if (!pExt->GetAPI()->QueryInterfaceDrop((*i_iter).iface))
1069 g_RootMenu.ConsolePrint(" -> %s", pExt->GetFilename());
1070 /* Add to plugin unload list */
1071 List<CPlugin *>::iterator p_iter;
1072 for (p_iter=pOther->m_Dependents.begin();
1073 p_iter!=pOther->m_Dependents.end();
1076 if (plugins.find((*p_iter)) == plugins.end())
1078 plugins.push_back((*p_iter));
1085 if (pExt->m_Dependents.size())
1087 g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename());
1088 List<CPlugin *>::iterator iter;
1090 for (iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++)
1093 if (plugins.find(pPlugin) == plugins.end())
1095 plugins.push_back(pPlugin);
1098 for (iter = plugins.begin(); iter != plugins.end(); iter++)
1101 g_RootMenu.ConsolePrint(" -> %s", pPlugin->GetFilename());
1104 srand(static_cast<int>(time(NULL)));
1105 pExt->unload_code = (rand() % 877) + 123; //123 to 999
1106 g_RootMenu.ConsolePrint("[SM] To verify unloading %s, please use the following: ", pExt->GetFilename());
1107 g_RootMenu.ConsolePrint("[SM] sm exts unload %d %d", num, pExt->unload_code);
1114 g_RootMenu.ConsolePrint("SourceMod Extensions Menu:");
1115 g_RootMenu.DrawGenericOption("info", "Extra extension information");
1116 g_RootMenu.DrawGenericOption("list", "List extensions");
1117 g_RootMenu.DrawGenericOption("unload", "Unload an extension");
1120 CExtension *CExtensionManager::GetExtensionFromIdent(IdentityToken_t *ptr)
1122 if (ptr->type == g_ExtType)
1124 return (CExtension *)(ptr->ptr);
1130 CExtensionManager::CExtensionManager()
1134 CExtensionManager::~CExtensionManager()
1138 void CExtensionManager::AddLibrary(IExtension *pSource, const char *library)
1140 CExtension *pExt = (CExtension *)pSource;
1141 pExt->AddLibrary(library);
1142 g_PluginSys.OnLibraryAction(library, false, false);
1145 bool CExtensionManager::LibraryExists(const char *library)
1149 for (List<CExtension *>::iterator iter = m_Libs.begin();
1150 iter != m_Libs.end();
1154 for (List<String>::iterator s_iter = pExt->m_Libraries.begin();
1155 s_iter != pExt->m_Libraries.end();
1158 if ((*s_iter).compare(library) == 0)
1168 IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface,
1169 const char *filepath,
1170 const char *filename,
1174 IExtension *pAlready;
1175 if ((pAlready=FindExtensionByFile(filename)) != NULL)
1180 CExtension *pExt = new CRemoteExtension(pInterface, filename, filepath);
1182 if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
1189 m_Libs.push_back(pExt);
1194 void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
1196 IExtensionInterface *pAPI;
1197 List<CExtension *>::iterator iter;
1199 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
1201 if ((pAPI = (*iter)->GetAPI()) == NULL)
1205 if (pAPI->GetExtensionVersion() > 3)
1207 pAPI->OnCoreMapStart(pEdictList, edictCount, clientMax);