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;
86 virtual bool Reload(char *error, size_t maxlength) =0;
87 virtual bool IsSameFile(const char* file) =0;
89 void Initialize(const char *filename, const char *path);
90 bool PerformAPICheck(char *error, size_t maxlength);
91 void CreateIdentity();
92 void DestroyIdentity();
94 IdentityToken_t *m_pIdentToken;
95 IExtensionInterface *m_pAPI;
100 List<IfaceInfo> m_Deps; /** Dependencies */
101 List<IfaceInfo> m_ChildDeps; /** Children who might depend on us */
102 List<SMInterface *> m_Interfaces;
103 List<String> m_Libraries;
104 unsigned int unload_code;
108 class CLocalExtension : public CExtension
111 CLocalExtension(const char *filename);
113 bool Load(char *error, size_t maxlength);
116 bool Reload(char *error, size_t maxlength);
118 bool IsSameFile(const char *file);
124 class CRemoteExtension : public CExtension
127 CRemoteExtension(IExtensionInterface *pAPI, const char *filename, const char *path);
129 bool Load(char *error, size_t maxlength);
132 bool Reload(char *error, size_t maxlength);
134 bool IsSameFile(const char *file);
137 class CExtensionManager :
138 public IExtensionManager,
139 public SMGlobalClass,
140 public IPluginsListener,
141 public IRootConsoleCommand
145 ~CExtensionManager();
146 public: //SMGlobalClass
147 void OnSourceModAllInitialized();
148 void OnSourceModShutdown();
149 public: //IExtensionManager
150 IExtension *LoadExtension(const char *path,
153 bool UnloadExtension(IExtension *pExt);
154 IExtension *FindExtensionByFile(const char *file);
155 IExtension *FindExtensionByName(const char *ext);
156 IExtension *LoadExternal(IExtensionInterface *pInterface,
157 const char *filepath,
158 const char *filename,
161 public: //IPluginsListener
162 void OnPluginDestroyed(IPlugin *plugin);
163 public: //IRootConsoleCommand
164 void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
166 IExtension *LoadAutoExtension(const char *path);
167 void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
168 void AddInterface(IExtension *pOwner, SMInterface *pInterface);
169 void BindChildPlugin(IExtension *pParent, CPlugin *pPlugin);
170 void MarkAllLoaded();
171 void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
173 void AddLibrary(IExtension *pSource, const char *library);
174 bool LibraryExists(const char *library);
175 void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
176 void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface);
178 CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
180 CNativeOwner *GetNativeOwner(IExtension *pExt)
182 CExtension *p = (CExtension *)pExt;
186 CExtension *FindByOrder(unsigned int num);
188 List<CExtension *> m_Libs;
191 extern CExtensionManager g_Extensions;
193 #endif //_INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_