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>.
32 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
33 #define _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
35 #include <IExtensionSys.h>
36 #include <ILibrarySys.h>
38 #include <sh_string.h>
39 #include <sm_trie_tpl.h>
40 #include "sm_globals.h"
43 #include <IPluginSys.h>
44 #include <IRootConsoleMenu.h>
45 #include "PluginSys.h"
46 #include "NativeOwner.h"
48 using namespace SourceMod;
49 using namespace SourceHook;
56 const sp_nativeinfo_t *info;
63 friend class CExtensionManager;
65 virtual ~CExtension();
67 IExtensionInterface *GetAPI();
68 const char *GetFilename();
69 IdentityToken_t *GetIdentity();
70 ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface);
71 bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface);
72 void FreeDependencyIterator(ITERATOR *iter);
73 bool IsRunning(char *error, size_t maxlength);
75 void SetError(const char *error);
76 void AddDependency(const IfaceInfo *pInfo);
77 void AddChildDependent(CExtension *pOther, SMInterface *iface);
78 void AddInterface(SMInterface *pInterface);
79 void AddPlugin(CPlugin *pPlugin);
81 void AddLibrary(const char *library);
83 virtual bool Load(char *error, size_t maxlength);
84 virtual bool IsLoaded() =0;
85 virtual void Unload() =0;
87 void Initialize(const char *filename, const char *path);
88 bool PerformAPICheck(char *error, size_t maxlength);
89 void CreateIdentity();
90 void DestroyIdentity();
92 IdentityToken_t *m_pIdentToken;
93 IExtensionInterface *m_pAPI;
97 List<IfaceInfo> m_Deps; /** Dependencies */
98 List<IfaceInfo> m_ChildDeps; /** Children who might depend on us */
99 List<SMInterface *> m_Interfaces;
100 List<String> m_Libraries;
101 unsigned int unload_code;
105 class CLocalExtension : public CExtension
108 CLocalExtension(const char *filename);
110 bool Load(char *error, size_t maxlength);
119 class CRemoteExtension : public CExtension
122 CRemoteExtension(IExtensionInterface *pAPI, const char *filename, const char *path);
124 bool Load(char *error, size_t maxlength);
130 class CExtensionManager :
131 public IExtensionManager,
132 public SMGlobalClass,
133 public IPluginsListener,
134 public IRootConsoleCommand
138 ~CExtensionManager();
139 public: //SMGlobalClass
140 void OnSourceModAllInitialized();
141 void OnSourceModShutdown();
142 public: //IExtensionManager
143 IExtension *LoadExtension(const char *path,
146 bool UnloadExtension(IExtension *pExt);
147 IExtension *FindExtensionByFile(const char *file);
148 IExtension *FindExtensionByName(const char *ext);
149 IExtension *LoadExternal(IExtensionInterface *pInterface,
150 const char *filepath,
151 const char *filename,
154 public: //IPluginsListener
155 void OnPluginDestroyed(IPlugin *plugin);
156 public: //IRootConsoleCommand
157 void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
159 IExtension *LoadAutoExtension(const char *path);
160 void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
161 void AddInterface(IExtension *pOwner, SMInterface *pInterface);
162 void BindChildPlugin(IExtension *pParent, CPlugin *pPlugin);
163 void MarkAllLoaded();
164 void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
166 void AddLibrary(IExtension *pSource, const char *library);
167 bool LibraryExists(const char *library);
168 void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
169 void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface);
171 CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
173 CNativeOwner *GetNativeOwner(IExtension *pExt)
175 CExtension *p = (CExtension *)pExt;
179 CExtension *FindByOrder(unsigned int num);
181 List<CExtension *> m_Libs;
184 extern CExtensionManager g_Extensions;
186 #endif //_INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_