3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
16 #define _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
18 #include <IExtensionSys.h>
19 #include <ILibrarySys.h>
21 #include <sh_string.h>
22 #include "sm_globals.h"
25 #include <IPluginSys.h>
26 #include <IRootConsoleMenu.h>
28 using namespace SourceMod;
29 using namespace SourceHook;
31 class CExtension : public IExtension
33 friend class CExtensionManager;
35 CExtension(const char *filename, char *error, size_t maxlen);
38 IExtensionInterface *GetAPI();
39 const char *GetFilename();
40 IdentityToken_t *GetIdentity();
42 ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface);
43 bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface);
44 void FreeDependencyIterator(ITERATOR *iter);
45 bool IsRunning(char *error, size_t maxlength);
47 void SetError(const char *error);
48 void AddDependency(IfaceInfo *pInfo);
49 void AddInterface(SMInterface *pInterface);
50 void AddPlugin(IPlugin *pPlugin);
51 void RemovePlugin(IPlugin *pPlugin);
54 bool Load(char *error, size_t maxlength);
56 IdentityToken_t *m_pIdentToken;
57 IExtensionInterface *m_pAPI;
62 List<IfaceInfo> m_Deps;
63 List<SMInterface *> m_Interfaces;
64 List<IPlugin *> m_Plugins;
65 List<const sp_nativeinfo_t *> m_Natives;
67 unsigned int unload_code;
71 class CExtensionManager :
72 public IExtensionManager,
74 public IPluginsListener,
75 public IRootConsoleCommand
77 public: //SMGlobalClass
78 void OnSourceModAllInitialized();
79 void OnSourceModShutdown();
80 public: //IExtensionManager
81 IExtension *LoadExtension(const char *path,
82 ExtensionLifetime lifetime,
85 bool UnloadExtension(IExtension *pExt);
86 IExtension *FindExtensionByFile(const char *file);
87 IExtension *FindExtensionByName(const char *ext);
88 public: //IPluginsListener
89 void OnPluginDestroyed(IPlugin *plugin);
90 public: //IRootConsoleCommand
91 void OnRootConsoleCommand(const char *cmd, unsigned int argcount);
93 IExtension *LoadAutoExtension(const char *path);
94 void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
95 void AddInterface(IExtension *pOwner, SMInterface *pInterface);
96 void BindChildPlugin(IExtension *pParent, IPlugin *pPlugin);
97 void AddNatives(IExtension *pOwner, const sp_nativeinfo_t *natives);
98 void BindAllNativesToPlugin(IPlugin *pPlugin);
100 void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
103 CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
106 CExtension *FindByOrder(unsigned int num);
108 List<CExtension *> m_Libs;
111 extern CExtensionManager g_Extensions;
113 #endif //_INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_