3 * =============================================================================
5 * Copyright (C) 2004-2007 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 CExtension::CExtension(const char *filename, char *error, size_t maxlength)
46 m_File.assign(filename);
51 m_FullyLoaded = false;
53 char path[PLATFORM_MAX_PATH];
55 /* First see if there is an engine specific build! */
56 g_SourceMod.BuildPath(Path_SM,
59 #if defined METAMOD_PLAPI_VERSION
60 #if defined ORANGEBOX_BUILD
61 "extensions/auto.2.ep2/%s",
63 "extensions/auto.2.ep1/%s",
64 #endif //ORANGEBOX_BUILD
65 #else //METAMOD_PLAPI_VERSION
66 "extensions/auto.1.ep1/%s",
67 #endif //METAMOD_PLAPI_VERSION
70 /* Try the "normal" version */
71 if (!g_LibSys.IsPathFile(path))
73 g_SourceMod.BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "extensions/%s", filename);
81 bool CExtension::Load(char *error, size_t maxlength)
83 m_pLib = g_LibSys.OpenLibrary(m_Path.c_str(), error, maxlength);
90 typedef IExtensionInterface *(*GETAPI)();
91 GETAPI pfnGetAPI = NULL;
93 if ((pfnGetAPI=(GETAPI)m_pLib->GetSymbolAddress("GetSMExtAPI")) == NULL)
95 m_pLib->CloseLibrary();
97 snprintf(error, maxlength, "Unable to find extension entry point");
101 m_pAPI = pfnGetAPI();
102 if (!m_pAPI || m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION)
104 m_pLib->CloseLibrary();
106 snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
110 if (m_pAPI->IsMetamodExtension())
113 m_PlId = g_pMMPlugins->Load(m_Path.c_str(), g_PLID, already, error, maxlength);
116 m_pIdentToken = g_ShareSys.CreateIdentity(g_ExtType, this);
118 if (!m_pAPI->OnExtensionLoad(this, &g_ShareSys, error, maxlength, !g_SourceMod.IsMapLoading()))
120 if (m_pAPI->IsMetamodExtension())
125 g_pMMPlugins->Unload(m_PlId, true, dummy, sizeof(dummy));
130 m_pLib->CloseLibrary();
132 g_ShareSys.DestroyIdentity(m_pIdentToken);
133 m_pIdentToken = NULL;
136 /* Check if we're past load time */
137 if (!g_SourceMod.IsMapLoading())
139 m_pAPI->OnExtensionsAllLoaded();
146 CExtension::~CExtension()
148 char temp_buffer[255];
154 g_pMMPlugins->Unload(m_PlId, true, temp_buffer, sizeof(temp_buffer));
160 g_ShareSys.DestroyIdentity(m_pIdentToken);
165 m_pLib->CloseLibrary();
169 void CExtension::MarkAllLoaded()
171 assert(m_FullyLoaded == false);
174 m_FullyLoaded = true;
175 m_pAPI->OnExtensionsAllLoaded();
179 void CExtension::AddPlugin(IPlugin *pPlugin)
181 /* Unfortunately we have to do this :( */
182 if (m_Plugins.find(pPlugin) != m_Plugins.end())
184 m_Plugins.push_back(pPlugin);
188 void CExtension::RemovePlugin(IPlugin *pPlugin)
190 m_Plugins.remove(pPlugin);
192 List<WeakNative>::iterator iter = m_WeakNatives.begin();
193 while (iter != m_WeakNatives.end())
195 if ((*iter).pl == pPlugin)
197 iter = m_WeakNatives.erase(iter);
204 void CExtension::SetError(const char *error)
206 m_Error.assign(error);
209 IExtensionInterface *CExtension::GetAPI()
214 const char *CExtension::GetFilename()
216 return m_File.c_str();
219 IdentityToken_t *CExtension::GetIdentity()
221 return m_pIdentToken;
224 bool CExtension::IsLoaded()
226 return (m_pLib != NULL);
229 void CExtension::AddDependency(IfaceInfo *pInfo)
231 if (m_Deps.find(*pInfo) == m_Deps.end())
233 m_Deps.push_back(*pInfo);
237 bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2)
239 return (i1.iface == i2.iface) && (i1.owner == i2.owner);
242 void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
248 List<IfaceInfo>::iterator iter;
249 for (iter = m_ChildDeps.begin();
250 iter != m_ChildDeps.end();
253 IfaceInfo &other = (*iter);
260 m_ChildDeps.push_back(info);
263 ITERATOR *CExtension::FindFirstDependency(IExtension **pOwner, SMInterface **pInterface)
265 List<IfaceInfo>::iterator iter = m_Deps.begin();
267 if (iter == m_Deps.end())
274 *pOwner = (*iter).owner;
278 *pInterface = (*iter).iface;
281 List<IfaceInfo>::iterator *pIter = new List<IfaceInfo>::iterator(iter);
283 return (ITERATOR *)pIter;
286 bool CExtension::FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface)
288 List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
289 List<IfaceInfo>::iterator _iter;
291 if (_iter == m_Deps.end())
300 *pOwner = (*_iter).owner;
304 *pInterface = (*_iter).iface;
309 if (_iter == m_Deps.end())
317 void CExtension::FreeDependencyIterator(ITERATOR *iter)
319 List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
324 void CExtension::AddInterface(SMInterface *pInterface)
326 m_Interfaces.push_back(pInterface);
329 bool CExtension::IsRunning(char *error, size_t maxlength)
335 snprintf(error, maxlength, "%s", m_Error.c_str());
340 return m_pAPI->QueryRunning(error, maxlength);
343 void CExtension::AddLibrary(const char *library)
345 m_Libraries.push_back(library);
348 /*********************
349 * EXTENSION MANAGER *
350 *********************/
352 void CExtensionManager::OnSourceModAllInitialized()
354 g_ExtType = g_ShareSys.CreateIdentType("EXTENSION");
355 g_PluginSys.AddPluginsListener(this);
356 g_RootMenu.AddRootConsoleCommand("exts", "Manage extensions", this);
357 g_ShareSys.AddInterface(NULL, this);
360 void CExtensionManager::OnSourceModShutdown()
362 g_RootMenu.RemoveRootConsoleCommand("exts", this);
363 g_ShareSys.DestroyIdentType(g_ExtType);
366 void CExtensionManager::Shutdown()
368 List<CExtension *>::iterator iter;
370 while ((iter = m_Libs.begin()) != m_Libs.end())
372 UnloadExtension((*iter));
376 void CExtensionManager::TryAutoload()
378 char path[PLATFORM_MAX_PATH];
380 g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "extensions");
382 IDirectory *pDir = g_LibSys.OpenDirectory(path);
390 while (pDir->MoreFiles())
392 if (pDir->IsEntryDirectory())
398 lfile = pDir->GetEntryName();
400 if (len <= 9) /* size of ".autoload" */
406 if (strcmp(&lfile[len - 9], ".autoload") != 0)
412 char file[PLATFORM_MAX_PATH];
413 len = UTIL_Format(file, sizeof(file), "%s", lfile);
414 strcpy(&file[len - 9], ".ext." PLATFORM_LIB_EXT);
416 LoadAutoExtension(file);
422 IExtension *CExtensionManager::LoadAutoExtension(const char *path)
424 if (!strstr(path, "." PLATFORM_LIB_EXT))
426 char newpath[PLATFORM_MAX_PATH];
427 g_LibSys.PathFormat(newpath, sizeof(newpath), "%s.%s", path, PLATFORM_LIB_EXT);
428 return LoadAutoExtension(newpath);
431 IExtension *pAlready;
432 if ((pAlready=FindExtensionByFile(path)) != NULL)
438 CExtension *p = new CExtension(path, error, sizeof(error));
440 /* We put us in the list beforehand so extensions that check for each other
441 * won't recursively load each other.
445 if (!p->Load(error, sizeof(error)) || !p->IsLoaded())
447 g_Logger.LogError("[SM] Unable to load extension \"%s\": %s", path, error);
454 IExtension *CExtensionManager::FindExtensionByFile(const char *file)
456 List<CExtension *>::iterator iter;
459 if (!strstr(file, "." PLATFORM_LIB_EXT))
461 char path[PLATFORM_MAX_PATH];
462 UTIL_Format(path, sizeof(path), "%s.%s", file, PLATFORM_LIB_EXT);
463 return FindExtensionByFile(path);
466 /* Chomp off the path */
467 char lookup[PLATFORM_MAX_PATH];
468 g_LibSys.GetFileFromPath(lookup, sizeof(lookup), file);
470 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
473 char short_file[PLATFORM_MAX_PATH];
474 g_LibSys.GetFileFromPath(short_file, sizeof(short_file), pExt->GetFilename());
475 if (strcmp(lookup, short_file) == 0)
484 IExtension *CExtensionManager::FindExtensionByName(const char *ext)
486 List<CExtension *>::iterator iter;
488 IExtensionInterface *pAPI;
491 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
494 if (!pExt->IsLoaded())
498 if ((pAPI = pExt->GetAPI()) == NULL)
502 name = pAPI->GetExtensionName();
507 if (strcmp(name, ext) == 0)
516 IExtension *CExtensionManager::LoadExtension(const char *file, ExtensionLifetime lifetime, char *error, size_t maxlength)
518 IExtension *pAlready;
519 if ((pAlready=FindExtensionByFile(file)) != NULL)
524 CExtension *pExt = new CExtension(file, error, maxlength);
526 /* :NOTE: lifetime is currently ignored */
528 if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
534 /* :TODO: do QueryRunning check if the map is loaded */
536 m_Libs.push_back(pExt);
541 void CExtensionManager::BindDependency(IExtension *pRequester, IfaceInfo *pInfo)
543 CExtension *pExt = (CExtension *)pRequester;
544 CExtension *pOwner = (CExtension *)pInfo->owner;
546 pExt->AddDependency(pInfo);
548 IExtensionInterface *pAPI = pExt->GetAPI();
549 if (pAPI && !pAPI->QueryInterfaceDrop(pInfo->iface))
551 pOwner->AddChildDependent(pExt, pInfo->iface);
555 void CExtensionManager::AddInterface(IExtension *pOwner, SMInterface *pInterface)
557 CExtension *pExt = (CExtension *)pOwner;
559 pExt->AddInterface(pInterface);
562 void CExtensionManager::BindChildPlugin(IExtension *pParent, IPlugin *pPlugin)
564 CExtension *pExt = (CExtension *)pParent;
566 pExt->AddPlugin(pPlugin);
569 void CExtensionManager::OnPluginDestroyed(IPlugin *plugin)
571 List<CExtension *>::iterator iter;
573 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
575 (*iter)->RemovePlugin(plugin);
579 CExtension *CExtensionManager::FindByOrder(unsigned int num)
581 if (num < 1 || num > m_Libs.size())
586 List<CExtension *>::iterator iter = m_Libs.begin();
588 while (iter != m_Libs.end())
600 void CExtensionManager::BindAllNativesToPlugin(IPlugin *pPlugin)
602 IPluginContext *pContext = pPlugin->GetBaseContext();
604 List<CExtension *> exts;
606 uint32_t natives = pContext->GetNativesNum();
608 sm_extnative_t *x_native;
609 for (uint32_t i=0; i<natives; i++)
611 /* Make sure the native is valid */
612 if (pContext->GetNativeByIndex(i, &native) != SP_ERROR_NONE)
616 /* Make sure the native is not already bound */
617 if (native->status == SP_NATIVE_BOUND)
621 /* See if we've got this native in our cache */
622 if ((x_native = m_ExtNatives.retrieve(native->name)) == NULL)
626 /* Try and bind it */
627 if (pContext->BindNativeToIndex(i, x_native->info->func) != SP_ERROR_NONE)
631 /* See if it's optional */
632 if (native->flags & SP_NTVFLAG_OPTIONAL)
634 WeakNative wkn = WeakNative((CPlugin *)pPlugin, i);
635 x_native->owner->m_WeakNatives.push_back(wkn);
637 else if (exts.find(x_native->owner) == exts.end())
639 exts.push_back(x_native->owner);
643 List<CExtension *>::iterator iter;
644 for (iter = exts.begin(); iter != exts.end(); iter++)
646 CExtension *pExt = (*iter);
647 if (pExt->m_Plugins.find(pPlugin) != pExt->m_Plugins.end())
651 pExt->m_Plugins.push_back(pPlugin);
655 bool CExtensionManager::UnloadExtension(IExtension *_pExt)
662 CExtension *pExt = (CExtension *)_pExt;
664 if (m_Libs.find(pExt) == m_Libs.end())
669 /* First remove us from internal lists */
670 g_ShareSys.RemoveInterfaces(_pExt);
673 List<CExtension *> UnloadQueue;
675 /* Handle dependencies */
676 if (pExt->IsLoaded())
678 /* Unload any dependent plugins */
679 List<IPlugin *>::iterator p_iter = pExt->m_Plugins.begin();
680 while (p_iter != pExt->m_Plugins.end())
682 /* We have to manually unlink ourselves here, since we're no longer being managed */
683 g_PluginSys.UnloadPlugin((*p_iter));
684 p_iter = pExt->m_Plugins.erase(p_iter);
687 List<String>::iterator s_iter;
688 for (s_iter = pExt->m_Libraries.begin();
689 s_iter != pExt->m_Libraries.end();
692 g_PluginSys.OnLibraryAction((*s_iter).c_str(), false, true);
695 /* Unbound weak natives */
696 List<WeakNative>::iterator wkn_iter;
697 for (wkn_iter=pExt->m_WeakNatives.begin(); wkn_iter!=pExt->m_WeakNatives.end(); wkn_iter++)
699 WeakNative & wkn = (*wkn_iter);
700 sp_context_t *ctx = wkn.pl->GetContext();
701 ctx->natives[wkn.idx].status = SP_NATIVE_UNBOUND;
704 /* Notify and/or unload all dependencies */
705 List<CExtension *>::iterator c_iter;
707 IExtensionInterface *pAPI;
708 for (c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++)
711 if ((pAPI=pDep->GetAPI()) == NULL)
719 /* Now, get its dependency list */
720 bool dropped = false;
721 List<IfaceInfo>::iterator i_iter = pDep->m_Deps.begin();
722 while (i_iter != pDep->m_Deps.end())
724 if ((*i_iter).owner == _pExt)
726 if (!pAPI->QueryInterfaceDrop((*i_iter).iface))
731 UnloadQueue.push_back(pDep);
734 pAPI->NotifyInterfaceDrop((*i_iter).iface);
735 i_iter = pDep->m_Deps.erase(i_iter);
742 /* Flush out any back references to this plugin */
743 i_iter = pDep->m_ChildDeps.begin();
744 while (i_iter != pDep->m_ChildDeps.end())
746 if ((*i_iter).owner == pExt)
748 i_iter = pDep->m_ChildDeps.erase(i_iter);
757 /* Unbind our natives from Core */
758 List<const sp_nativeinfo_t *>::iterator native_iter;
759 for (native_iter = pExt->m_Natives.begin();
760 native_iter != pExt->m_Natives.end();
763 const sp_nativeinfo_t *natives = (*native_iter);
764 sm_extnative_t *x_native;
765 for (unsigned int n = 0;
766 natives[n].name != NULL && natives[n].func != NULL;
769 x_native = m_ExtNatives.retrieve(natives[n].name);
770 if (x_native && x_native->owner == pExt)
772 m_ExtNatives.remove(natives[n].name);
777 /* Tell it to unload */
778 pAPI = pExt->GetAPI();
779 pAPI->OnExtensionUnload();
782 IdentityToken_t *pIdentity;
783 if ((pIdentity = pExt->GetIdentity()) != NULL)
785 SMGlobalClass *glob = SMGlobalClass::head;
788 glob->OnSourceModIdentityDropped(pIdentity);
789 glob = glob->m_pGlobalClassNext;
795 List<CExtension *>::iterator iter;
796 for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++)
798 /* NOTE: This is safe because the unload function backs out of anything not present */
799 UnloadExtension((*iter));
805 void CExtensionManager::AddNatives(IExtension *pOwner, const sp_nativeinfo_t *natives)
807 CExtension *pExt = (CExtension *)pOwner;
809 pExt->m_Natives.push_back(natives);
811 for (unsigned int i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
813 if (m_ExtNatives.retrieve(natives[i].name) != NULL)
817 sm_extnative_t x_native;
818 x_native.info = &natives[i];
819 x_native.owner = pExt;
820 m_ExtNatives.insert(natives[i].name, x_native);
824 void CExtensionManager::MarkAllLoaded()
826 List<CExtension *>::iterator iter;
829 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
832 if (!pExt->IsLoaded())
836 if (pExt->m_FullyLoaded)
840 pExt->MarkAllLoaded();
844 void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload)
846 /* This function doesn't really need to do anything now. We make sure the
847 * other extension is loaded, but handling of dependencies is really done
848 * by the interface fetcher.
850 if (required || autoload)
852 LoadAutoExtension(file);
856 void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
858 int argcount = command.ArgC();
861 const char *cmd = command.Arg(2);
862 if (strcmp(cmd, "list") == 0)
864 List<CExtension *>::iterator iter;
866 unsigned int num = 1;
867 switch (m_Libs.size())
871 g_RootMenu.ConsolePrint("[SM] Displaying 1 extension:");
876 g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
881 g_RootMenu.ConsolePrint("[SM] Displaying %d extensions:", m_Libs.size());
885 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++,num++)
888 if (pExt->IsLoaded())
891 if (!pExt->IsRunning(error, sizeof(error)))
893 g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), error);
895 IExtensionInterface *pAPI = pExt->GetAPI();
896 const char *name = pAPI->GetExtensionName();
897 const char *version = pAPI->GetExtensionVerString();
898 const char *descr = pAPI->GetExtensionDescription();
899 g_RootMenu.ConsolePrint("[%02d] %s (%s): %s", num, name, version, descr);
902 g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str());
906 } else if (strcmp(cmd, "info") == 0) {
909 g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
913 const char *sId = command.Arg(3);
914 unsigned int id = atoi(sId);
917 g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
921 if (m_Libs.size() == 0)
923 g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
927 if (id > m_Libs.size())
929 g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
933 List<CExtension *>::iterator iter = m_Libs.begin();
934 CExtension *pExt = NULL;
935 while (iter != m_Libs.end())
944 /* This should never happen */
947 g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
951 if (!pExt->IsLoaded())
953 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
954 g_RootMenu.ConsolePrint(" Loaded: No (%s)", pExt->m_Error.c_str());
957 if (!pExt->IsRunning(error, sizeof(error)))
959 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
960 g_RootMenu.ConsolePrint(" Loaded: Yes");
961 g_RootMenu.ConsolePrint(" Running: No (%s)", error);
963 IExtensionInterface *pAPI = pExt->GetAPI();
964 g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
965 g_RootMenu.ConsolePrint(" Loaded: Yes (version %s)", pAPI->GetExtensionVerString());
966 g_RootMenu.ConsolePrint(" Name: %s (%s)", pAPI->GetExtensionName(), pAPI->GetExtensionDescription());
967 g_RootMenu.ConsolePrint(" Author: %s (%s)", pAPI->GetExtensionAuthor(), pAPI->GetExtensionURL());
968 g_RootMenu.ConsolePrint(" Binary info: API version %d (compiled %s)", pAPI->GetExtensionVersion(), pAPI->GetExtensionDateString());
969 g_RootMenu.ConsolePrint(" Metamod enabled: %s", pAPI->IsMetamodExtension() ? "yes" : "no");
973 } else if (strcmp(cmd, "unload") == 0) {
976 g_RootMenu.ConsolePrint("[SM] Usage: sm unload <#> [code]");
980 const char *arg = command.Arg(3);
981 unsigned int num = atoi(arg);
982 CExtension *pExt = FindByOrder(num);
986 g_RootMenu.ConsolePrint("[SM] Extension number %d was not found.", num);
990 if (argcount > 4 && pExt->unload_code)
992 const char *unload = command.Arg(4);
993 if (pExt->unload_code == (unsigned)atoi(unload))
995 char filename[PLATFORM_MAX_PATH];
996 snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
997 UnloadExtension(pExt);
998 g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
1002 g_RootMenu.ConsolePrint("[SM] Please try again, the correct unload code is \"%d\"", pExt->unload_code);
1007 if (!pExt->IsLoaded()
1008 || (!pExt->m_ChildDeps.size() && !pExt->m_Plugins.size()))
1010 char filename[PLATFORM_MAX_PATH];
1011 snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1012 UnloadExtension(pExt);
1013 g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
1018 List<IPlugin *> plugins;
1019 if (pExt->m_ChildDeps.size())
1021 g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename());
1022 List<CExtension *>::iterator iter;
1024 /* Get list of all extensions */
1025 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
1027 List<IfaceInfo>::iterator i_iter;
1029 if (!pOther->IsLoaded() || pOther == pExt)
1033 /* Get their dependencies */
1034 for (i_iter=pOther->m_Deps.begin();
1035 i_iter!=pOther->m_Deps.end();
1038 /* Is this dependency to us? */
1039 if ((*i_iter).owner != pExt)
1043 /* Will our dependent care? */
1044 if (!pExt->GetAPI()->QueryInterfaceDrop((*i_iter).iface))
1046 g_RootMenu.ConsolePrint(" -> %s", pExt->GetFilename());
1047 /* Add to plugin unload list */
1048 List<IPlugin *>::iterator p_iter;
1049 for (p_iter=pOther->m_Plugins.begin();
1050 p_iter!=pOther->m_Plugins.end();
1053 if (plugins.find((*p_iter)) == plugins.end())
1055 plugins.push_back((*p_iter));
1062 if (pExt->m_Plugins.size())
1064 g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename());
1065 List<IPlugin *>::iterator iter;
1067 for (iter = pExt->m_Plugins.begin(); iter != pExt->m_Plugins.end(); iter++)
1070 if (plugins.find(pPlugin) == plugins.end())
1072 plugins.push_back(pPlugin);
1075 for (iter = plugins.begin(); iter != plugins.end(); iter++)
1078 g_RootMenu.ConsolePrint(" -> %s", pPlugin->GetFilename());
1081 srand(static_cast<int>(time(NULL)));
1082 pExt->unload_code = (rand() % 877) + 123; //123 to 999
1083 g_RootMenu.ConsolePrint("[SM] To verify unloading %s, please use the following: ", pExt->GetFilename());
1084 g_RootMenu.ConsolePrint("[SM] sm exts unload %d %d", num, pExt->unload_code);
1091 g_RootMenu.ConsolePrint("SourceMod Extensions Menu:");
1092 g_RootMenu.DrawGenericOption("info", "Extra extension information");
1093 g_RootMenu.DrawGenericOption("list", "List extensions");
1094 g_RootMenu.DrawGenericOption("unload", "Unload an extension");
1097 CExtension *CExtensionManager::GetExtensionFromIdent(IdentityToken_t *ptr)
1099 if (ptr->type == g_ExtType)
1101 return (CExtension *)(ptr->ptr);
1107 CExtensionManager::CExtensionManager()
1111 CExtensionManager::~CExtensionManager()
1115 void CExtensionManager::AddLibrary(IExtension *pSource, const char *library)
1117 CExtension *pExt = (CExtension *)pSource;
1118 pExt->AddLibrary(library);
1119 g_PluginSys.OnLibraryAction(library, false, false);
1122 bool CExtensionManager::LibraryExists(const char *library)
1126 for (List<CExtension *>::iterator iter = m_Libs.begin();
1127 iter != m_Libs.end();
1131 for (List<String>::iterator s_iter = pExt->m_Libraries.begin();
1132 s_iter != pExt->m_Libraries.end();
1135 if ((*s_iter).compare(library) == 0)