core/logic/PluginSys.h
author Kyle Sanderson <kyle.leet@gmail.com>
Mon Aug 12 00:42:56 2013 +0100 (2013-08-12)
changeset 3994 4bc73bac0f4c
parent 3881 7ec742e7d629
child 4065 0f85577d23ee
permissions -rw-r--r--
Added helper stock to check if a command exists. (bug 5510, r=asherkin)
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
ds@3099
     5
 * Copyright (C) 2004-2010 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@370
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@370
    28
 *
dvander@370
    29
 * Version: $Id$
dvander@370
    30
 */
dvander@370
    31
dvander@173
    32
#ifndef _INCLUDE_SOURCEMOD_PLUGINSYSTEM_H_
dvander@173
    33
#define _INCLUDE_SOURCEMOD_PLUGINSYSTEM_H_
dvander@173
    34
dvander@211
    35
#include <time.h>
faluco@333
    36
#include <errno.h>
faluco@333
    37
#include <sys/stat.h>
dvander@173
    38
#include <IPluginSys.h>
dvander@220
    39
#include <IHandleSys.h>
ds@611
    40
#include <IForwardSys.h>
dvander@174
    41
#include <sh_list.h>
dvander@174
    42
#include <sh_stack.h>
faluco@389
    43
#include <sh_vector.h>
dvander@601
    44
#include <sh_string.h>
dvander@3872
    45
#include "common_logic.h"
dvander@3872
    46
#include <sm_trie_tpl.h>
dvander@309
    47
#include <IRootConsoleMenu.h>
dvander@2042
    48
#include "ITranslator.h"
asherkin@3601
    49
#include "IGameConfigs.h"
dvander@2086
    50
#include "NativeOwner.h"
dvander@2086
    51
#include "ShareSys.h"
dvander@173
    52
dvander@2547
    53
class CPlayer;
dvander@2547
    54
dvander@174
    55
using namespace SourceHook;
dvander@174
    56
dvander@209
    57
/**
dvander@209
    58
 * NOTES:
dvander@209
    59
 *
dvander@1923
    60
 * UPDATE 2008-03-11: These comments are horribly out of date.  They paint a good overall 
dvander@1923
    61
 * picture of how PluginSys works, but things like dependencies and fake natives have 
dvander@1923
    62
 * complicated things quite a bit.
dvander@1923
    63
 *
dvander@209
    64
 *  Currently this system needs a lot of work but it's good skeletally.  Plugin creation 
dvander@209
    65
 * is done without actually compiling anything.  This is done by Load functions in the 
dvander@209
    66
 * manager.  This will need a rewrite when we add context switching.
dvander@209
    67
 *
dvander@209
    68
 *  The plugin object itself has a few things to note.  The most important is that it stores
dvander@209
    69
 * a table of function objects.  The manager marshals allocation and freeing of these objects.
dvander@209
    70
 * The plugin object can be in erroneous states, they are:
dvander@209
    71
 *   Plugin_Error   --> Some error occurred any time during or after compilation.
dvander@209
    72
 *						This error can be cleared since the plugin itself is valid.
dvander@209
    73
 *						However, the state itself being set prevents any runtime action.
dvander@209
    74
 *   Plugin_BadLoad	--> The plugin failed to load entirely and nothing can be done to save it.
dvander@209
    75
 *
dvander@209
    76
 *  If a plugin fails to load externally, it is never added to the internal tracker.  However, 
dvander@209
    77
 * plugins that failed to load from the internal loading mechanism are always tracked.  This 
dvander@209
    78
 * allows users to see which automatically loaded plugins failed, and makes the interface a bit
dvander@209
    79
 * more flexible.
dvander@211
    80
 *
dvander@211
    81
 *  Once a plugin is compiled, it sets its own state to Plugin_Created.  This state is still invalid
dvander@211
    82
 * for execution.  SourceMod is a two pass system, and even though the second pass is not implemented
dvander@211
    83
 * yet, it is structured so Plugin_Created must be switched to Plugin_Running in the second pass.  When
dvander@211
    84
 * implemented, a Created plugin will be switched to Error in the second pass if it not loadable.
dvander@211
    85
 *
dvander@211
    86
 *  The two pass loading mechanism is described below.  Modules/natives are not implemented yet.
dvander@211
    87
 * PASS ONE: All loadable plugins are found and have the following steps performed:
dvander@211
    88
 *			 1.  Loading and compilation is attempted.
dvander@211
    89
 *			 2.  If successful, all natives from Core are added.
dvander@211
    90
 *			 3.  OnPluginLoad() is called.
dvander@211
    91
 *			 4.  If failed, any user natives are scrapped and the process halts here.
dvander@211
    92
 *			 5.  If successful, the plugin is ready for Pass 2.
dvander@211
    93
 * INTERMEDIATE:
dvander@211
    94
 *			 1.  All forced modules are loaded.
dvander@211
    95
 * PASS TWO: All loaded plugins are found and have these steps performed:
dvander@211
    96
 *			 1. Any modules referenced in the plugin that are not already loaded, are loaded.
dvander@211
    97
 *			 2. If any module fails to load and the plugin requires it, load fails and jump to step 6.
dvander@211
    98
 *			 3. If any natives are unresolved, check if they are found in the user-natives pool.
dvander@211
    99
 *			 4. If yes, load succeeds.  If not, natives are passed through a native acceptance filter.
dvander@211
   100
 *			 5. If the filter fails, the plugin is marked as failed.
dvander@211
   101
 *			 6. If the plugin has failed to load at this point, any dynamic natives it has added are scrapped.
dvander@211
   102
 *			    Furthermore, any plugin that referenced these natives must now have pass 2 re-ran.
dvander@211
   103
 * PASS THREE (not a real pass):
ds@426
   104
 *			 7. Once all plugins are deemed to be loaded, OnPluginStart() is called
dvander@209
   105
 */
dvander@209
   106
faluco@383
   107
enum LoadRes
faluco@383
   108
{
faluco@383
   109
	LoadRes_Successful,
faluco@383
   110
	LoadRes_AlreadyLoaded,
dvander@1436
   111
	LoadRes_Failure,
fyrenmoo@2675
   112
	LoadRes_SilentFailure,
dvander@1436
   113
	LoadRes_NeverLoad
faluco@383
   114
};
faluco@383
   115
fyrenmoo@2675
   116
enum APLRes
fyrenmoo@2675
   117
{
fyrenmoo@2675
   118
	APLRes_Success,
fyrenmoo@2675
   119
	APLRes_Failure,
fyrenmoo@2675
   120
	APLRes_SilentFailure
fyrenmoo@2675
   121
};
fyrenmoo@2675
   122
dvander@2086
   123
class CPlugin : 
dvander@3872
   124
	public SMPlugin,
dvander@2086
   125
	public CNativeOwner
dvander@173
   126
{
dvander@174
   127
	friend class CPluginManager;
dvander@176
   128
	friend class CFunction;
dvander@173
   129
public:
dvander@209
   130
	CPlugin(const char *file);
dvander@209
   131
	~CPlugin();
dvander@209
   132
public:
faluco@641
   133
	PluginType GetType();
faluco@641
   134
	SourcePawn::IPluginContext *GetBaseContext();
faluco@641
   135
	sp_context_t *GetContext();
dvander@2193
   136
	void *GetPluginStructure();
faluco@641
   137
	const char *GetFilename();
faluco@641
   138
	bool IsDebugging();
faluco@641
   139
	PluginStatus GetStatus();
fyrenmoo@2675
   140
	bool IsSilentlyFailed();
fyrenmoo@2675
   141
	void SetSilentlyFailed(bool sf);
dvander@2193
   142
	const sm_plugininfo_t *GetPublicInfo();
faluco@641
   143
	bool SetPauseState(bool paused);
faluco@641
   144
	unsigned int GetSerial();
faluco@641
   145
	IdentityToken_t *GetIdentity();
dvander@1766
   146
	unsigned int CalcMemUsage();
faluco@641
   147
	bool SetProperty(const char *prop, void *ptr);
faluco@641
   148
	bool GetProperty(const char *prop, void **ptr, bool remove=false);
dvander@2086
   149
	void DropEverything();
dvander@2193
   150
	SourcePawn::IPluginRuntime *GetRuntime();
dvander@3872
   151
	CNativeOwner *ToNativeOwner() {
dvander@3872
   152
		return this;
dvander@3872
   153
	}
dvander@173
   154
public:
dvander@209
   155
	/**
dvander@209
   156
	 * Creates a plugin object with default values.
dvander@209
   157
	 *   If an error buffer is specified, and an error occurs, the error will be copied to the buffer
dvander@209
   158
	 * and NULL will be returned.
dvander@209
   159
	 *   If an error buffer is not specified, the error will be copied to an internal buffer and 
dvander@209
   160
	 * a valid (but error-stated) CPlugin will be returned.
dvander@209
   161
	 */
dvander@209
   162
	static CPlugin *CreatePlugin(const char *file, char *error, size_t maxlength);
dvander@209
   163
public:
dvander@229
   164
dvander@209
   165
	/**
dvander@209
   166
	 * Sets an error state on the plugin
dvander@209
   167
	 */
dvander@209
   168
	void SetErrorState(PluginStatus status, const char *error_fmt, ...);
dvander@211
   169
dvander@211
   170
	/**
dvander@229
   171
	 * Initializes the plugin's identity information
dvander@229
   172
	 */
dvander@229
   173
	void InitIdentity();
dvander@229
   174
dvander@229
   175
	/**
dvander@211
   176
	 * Calls the OnPluginLoad function, and sets any failed states if necessary.
dvander@211
   177
	 * NOTE: Valid pre-states are: Plugin_Created
dvander@282
   178
	 * NOTE: If validated, plugin state is changed to Plugin_Loaded
dvander@211
   179
	 *
dvander@211
   180
	 * If the error buffer is NULL, the error message is cached locally.
dvander@211
   181
	 */
fyrenmoo@2675
   182
	APLRes Call_AskPluginLoad(char *error, size_t maxlength);
dvander@211
   183
dvander@211
   184
	/**
ds@426
   185
	 * Calls the OnPluginStart function.
dvander@211
   186
	 * NOTE: Valid pre-states are: Plugin_Created
dvander@282
   187
	 * NOTE: Post-state will be Plugin_Running
dvander@211
   188
	 */
ds@426
   189
	void Call_OnPluginStart();
dvander@282
   190
dvander@282
   191
	/**
ds@426
   192
	 * Calls the OnPluginEnd function.
dvander@282
   193
	 */
ds@426
   194
	void Call_OnPluginEnd();
faluco@290
   195
faluco@290
   196
	/**
faluco@1221
   197
	 * Calls the OnAllPluginsLoaded function.
faluco@1221
   198
	 */
faluco@1221
   199
	void Call_OnAllPluginsLoaded();
faluco@1221
   200
faluco@1221
   201
	/**
dvander@315
   202
	 * Returns true if a plugin is usable.
dvander@315
   203
	 */
dvander@615
   204
	bool IsRunnable();
faluco@389
   205
faluco@389
   206
	/**
dvander@2042
   207
	 * Get languages info.
dvander@536
   208
	 */
dvander@2042
   209
	IPhraseCollection *GetPhrases();
dvander@211
   210
public:
faluco@333
   211
	/**
dvander@536
   212
	 * Returns the modification time during last plugin load.
dvander@536
   213
	 */
dvander@615
   214
	time_t GetTimeStamp();
faluco@333
   215
faluco@333
   216
	/**
dvander@536
   217
	 * Returns the current modification time of the plugin file.
dvander@536
   218
	 */
faluco@333
   219
	time_t GetFileTimeStamp();
dvander@282
   220
dvander@282
   221
	/** 
dvander@282
   222
	 * Returns true if the plugin was running, but is now invalid.
dvander@282
   223
	 */
dvander@282
   224
	bool WasRunning();
dvander@536
   225
dvander@536
   226
	Handle_t GetMyHandle();
dvander@978
   227
dvander@2086
   228
	bool AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func);
dvander@978
   229
	void AddConfig(bool autoCreate, const char *cfg, const char *folder);
dvander@3879
   230
	size_t GetConfigCount();
dvander@3879
   231
	AutoConfig *GetConfig(size_t i);
faluco@1112
   232
	inline void AddLibrary(const char *name)
faluco@1089
   233
	{
faluco@1112
   234
		m_Libraries.push_back(name);
faluco@1089
   235
	}
asherkin@3703
   236
	void LibraryActions(LibraryAction action);
dvander@2342
   237
	void SyncMaxClients(int max_clients);
dvander@173
   238
protected:
dvander@2342
   239
	bool UpdateInfo();
faluco@333
   240
	void SetTimeStamp(time_t t);
dvander@605
   241
	void DependencyDropped(CPlugin *pOwner);
dvander@173
   242
private:
dvander@174
   243
	PluginType m_type;
ds@652
   244
	char m_filename[PLATFORM_MAX_PATH];
dvander@173
   245
	PluginStatus m_status;
fyrenmoo@2675
   246
	bool m_bSilentlyFailed;
dvander@173
   247
	unsigned int m_serial;
dvander@173
   248
	sm_plugininfo_t m_info;
dvander@209
   249
	char m_errormsg[256];
dvander@211
   250
	time_t m_LastAccess;
dvander@229
   251
	IdentityToken_t *m_ident;
dvander@220
   252
	Handle_t m_handle;
dvander@282
   253
	bool m_WasRunning;
dvander@2042
   254
	IPhraseCollection *m_pPhrases;
faluco@1112
   255
	List<String> m_RequiredLibs;
faluco@1112
   256
	List<String> m_Libraries;
dvander@3872
   257
	KTrie<void *> m_pProps;
dvander@605
   258
	bool m_FakeNativesMissing;
faluco@1112
   259
	bool m_LibraryMissing;
dvander@978
   260
	CVector<AutoConfig *> m_configs;
dvander@1630
   261
	bool m_bGotAllLoaded;
dvander@2105
   262
	int m_FileVersion;
dvander@2105
   263
	char m_DateTime[256];
dvander@2193
   264
	IPluginRuntime *m_pRuntime;
dvander@2193
   265
	IPluginContext *m_pContext;
dvander@2342
   266
	sp_pubvar_t *m_MaxClientsVar;
dvander@601
   267
};
dvander@601
   268
dvander@220
   269
class CPluginManager : 
dvander@3872
   270
	public IScriptManager,
dvander@220
   271
	public SMGlobalClass,
dvander@309
   272
	public IHandleTypeDispatch,
dvander@309
   273
	public IRootConsoleCommand
dvander@174
   274
{
dvander@176
   275
	friend class CPlugin;
dvander@174
   276
public:
dvander@174
   277
	CPluginManager();
dvander@176
   278
	~CPluginManager();
dvander@174
   279
public:
dvander@203
   280
	/* Implements iterator class */
dvander@174
   281
	class CPluginIterator : public IPluginIterator
dvander@174
   282
	{
dvander@174
   283
	public:
dvander@213
   284
		CPluginIterator(List<CPlugin *> *mylist);
dvander@174
   285
		virtual ~CPluginIterator();
dvander@174
   286
		virtual bool MorePlugins();
dvander@174
   287
		virtual IPlugin *GetPlugin();
dvander@174
   288
		virtual void NextPlugin();
dvander@282
   289
		void Release();
dvander@174
   290
	public:
dvander@174
   291
		void Reset();
dvander@174
   292
	private:
dvander@213
   293
		List<CPlugin *> *mylist;
dvander@213
   294
		List<CPlugin *>::iterator current;
dvander@174
   295
	};
dvander@174
   296
	friend class CPluginManager::CPluginIterator;
dvander@3872
   297
public: //IScriptManager
dvander@282
   298
	IPlugin *LoadPlugin(const char *path, 
dvander@174
   299
								bool debug,
dvander@174
   300
								PluginType type,
dvander@174
   301
								char error[],
ds@755
   302
								size_t maxlength,
faluco@383
   303
								bool *wasloaded);
dvander@282
   304
	bool UnloadPlugin(IPlugin *plugin);
dvander@282
   305
	IPlugin *FindPluginByContext(const sp_context_t *ctx);
dvander@282
   306
	unsigned int GetPluginCount();
dvander@282
   307
	IPluginIterator *GetPluginIterator();
dvander@282
   308
	void AddPluginsListener(IPluginsListener *listener);
dvander@282
   309
	void RemovePluginsListener(IPluginsListener *listener);
dvander@3872
   310
	void LoadAll(const char *config_path, const char *plugins_path);
dvander@3872
   311
	void RefreshAll();
dvander@3872
   312
	SMPlugin *FindPluginByOrder(unsigned num) {
dvander@3872
   313
		return GetPluginByOrder(num);
dvander@3872
   314
	}
dvander@3872
   315
	SMPlugin *FindPluginByIdentity(IdentityToken_t *ident) {
dvander@3872
   316
		return GetPluginFromIdentity(ident);
dvander@3872
   317
	}
dvander@3872
   318
	SMPlugin *FindPluginByContext(IPluginContext *ctx) {
dvander@3872
   319
		return GetPluginByCtx(ctx->GetContext());
dvander@3872
   320
	}
dvander@3872
   321
	SMPlugin *FindPluginByContext(sp_context_t *ctx) {
dvander@3872
   322
		return GetPluginByCtx(ctx);
dvander@3872
   323
	}
dvander@3872
   324
	SMPlugin *FindPluginByConsoleArg(const char *text);
dvander@3872
   325
	SMPlugin *FindPluginByHandle(Handle_t hndl, HandleError *errp) {
dvander@3872
   326
		return static_cast<SMPlugin *>(PluginFromHandle(hndl, errp));
dvander@3872
   327
	}
dvander@3881
   328
	const CVector<SMPlugin *> *ListPlugins();
dvander@3881
   329
	void FreePluginList(const CVector<SMPlugin *> *plugins);
dvander@220
   330
public: //SMGlobalClass
dvander@282
   331
	void OnSourceModAllInitialized();
dvander@282
   332
	void OnSourceModShutdown();
asherkin@3601
   333
	ConfigResult OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength);
dvander@2342
   334
	void OnSourceModMaxPlayersChanged(int newvalue);
dvander@220
   335
public: //IHandleTypeDispatch
dvander@282
   336
	void OnHandleDestroy(HandleType_t type, void *object);
dvander@1766
   337
	bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
dvander@309
   338
public: //IRootConsoleCommand
faluco@1541
   339
	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
dvander@190
   340
public:
dvander@203
   341
	/**
dvander@211
   342
	 * Loads all plugins not yet loaded
dvander@203
   343
	 */
dvander@211
   344
	void LoadAll_FirstPass(const char *config, const char *basedir);
dvander@211
   345
dvander@211
   346
	/**
dvander@211
   347
	 * Runs the second loading pass for all plugins
dvander@211
   348
	 */
dvander@211
   349
	void LoadAll_SecondPass();
dvander@203
   350
dvander@203
   351
	/**
dvander@203
   352
	 * Tests a plugin file mask against a local folder.
dvander@203
   353
	 * The alias is searched backwards from localdir - i.e., given this input:
dvander@203
   354
	 *   csdm/ban        csdm/ban
dvander@203
   355
	 *   ban             csdm/ban
dvander@203
   356
	 *   csdm/ban        optional/csdm/ban
dvander@203
   357
	 * All of these will return true for an alias match.  
dvander@203
   358
	 * Wildcards are allowed in the filename.
dvander@203
   359
	 */
dvander@209
   360
	bool TestAliasMatch(const char *alias, const char *localdir);
dvander@211
   361
dvander@211
   362
	/** 
dvander@211
   363
	 * Returns whether anything loaded will be a late load.
dvander@211
   364
	 */
faluco@290
   365
	bool IsLateLoadTime() const;
dvander@233
   366
dvander@233
   367
	/**
dvander@247
   368
	 * Converts a Handle to an IPlugin if possible.
dvander@247
   369
	 */
dvander@247
   370
	IPlugin *PluginFromHandle(Handle_t handle, HandleError *err);
faluco@290
   371
faluco@290
   372
	/**
dvander@309
   373
	 * Finds a plugin based on its index. (starts on index 1)
dvander@309
   374
	 */
faluco@290
   375
	CPlugin *GetPluginByOrder(int num);
dvander@309
   376
dvander@1638
   377
	int GetOrderOfPlugin(IPlugin *pl);
dvander@1638
   378
ds@457
   379
	/** 
ds@457
   380
	 * Internal version of FindPluginByContext()
ds@457
   381
	 */
dvander@2193
   382
	CPlugin *GetPluginByCtx(const sp_context_t *ctx);
ds@457
   383
dvander@309
   384
	/**
dvander@309
   385
	 * Gets status text for a status code 
dvander@309
   386
	 */
dvander@309
   387
	const char *GetStatusText(PluginStatus status);
dvander@315
   388
faluco@333
   389
	/**
ds@611
   390
	 * Add public functions from all running or paused
ds@611
   391
	 * plugins to the specified forward if the names match.
ds@611
   392
	 */
ds@611
   393
	void AddFunctionsToForward(const char *name, IChangeableForward *pForward);
ds@611
   394
faluco@1221
   395
	/**
faluco@1221
   396
	 * Iterates through plugins to call OnAllPluginsLoaded.
faluco@1221
   397
	 */
faluco@1221
   398
	void AllPluginsLoaded();
faluco@1221
   399
dvander@900
   400
	CPlugin *GetPluginFromIdentity(IdentityToken_t *pToken);
dvander@900
   401
dvander@1018
   402
	void Shutdown();
dvander@1018
   403
asherkin@3703
   404
	void OnLibraryAction(const char *lib, LibraryAction action);
dvander@1124
   405
dvander@1124
   406
	bool LibraryExists(const char *lib);
faluco@1348
   407
faluco@1348
   408
	bool ReloadPlugin(CPlugin *pl);
dvander@1630
   409
dvander@1630
   410
	void UnloadAll();
dvander@1902
   411
dvander@2342
   412
	void SyncMaxClients(int max_clients);
dvander@2547
   413
dvander@2547
   414
	void ListPluginsToClient(CPlayer *player, const CCommand &args);
dvander@209
   415
private:
ds@755
   416
	LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);
dvander@298
   417
dvander@298
   418
	void LoadAutoPlugin(const char *plugin);
dvander@298
   419
dvander@209
   420
	/**
dvander@209
   421
	 * Recursively loads all plugins in the given directory.
dvander@209
   422
	 */
dvander@209
   423
	void LoadPluginsFromDir(const char *basedir, const char *localdir);
dvander@209
   424
dvander@209
   425
	/**
dvander@211
   426
	 * Adds a plugin object.  This is wrapped by LoadPlugin functions.
dvander@211
   427
	 */
dvander@211
   428
	void AddPlugin(CPlugin *pPlugin);
dvander@211
   429
dvander@211
   430
	/**
dvander@211
   431
	 * Runs the second loading pass on a plugin.
dvander@209
   432
	 */
dvander@298
   433
	bool RunSecondPass(CPlugin *pPlugin, char *error, size_t maxlength);
dvander@211
   434
dvander@211
   435
	/**
dvander@315
   436
	 * Runs an extension pass on a plugin.
dvander@315
   437
	 */
dvander@315
   438
	bool LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass, char *error, size_t maxlength);
faluco@430
   439
faluco@1112
   440
	/**
faluco@1112
   441
	* Manages required natives.
faluco@1112
   442
	*/
faluco@1112
   443
	bool FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size_t maxlength);
faluco@1112
   444
faluco@430
   445
	void _SetPauseState(CPlugin *pPlugin, bool pause);
dvander@174
   446
protected:
dvander@209
   447
	/**
dvander@209
   448
	 * Caching internal objects
dvander@209
   449
	 */
dvander@174
   450
	void ReleaseIterator(CPluginIterator *iter);
dvander@900
   451
public:
dvander@229
   452
	inline IdentityToken_t *GetIdentity()
dvander@229
   453
	{
dvander@229
   454
		return m_MyIdent;
dvander@229
   455
	}
dvander@3872
   456
	IPluginManager *GetOldAPI();
dvander@601
   457
private:
faluco@1112
   458
	void TryRefreshDependencies(CPlugin *pOther);
dvander@174
   459
private:
dvander@174
   460
	List<IPluginsListener *> m_listeners;
dvander@213
   461
	List<CPlugin *> m_plugins;
dvander@174
   462
	CStack<CPluginManager::CPluginIterator *> m_iters;
dvander@3872
   463
	KTrie<CPlugin *> m_LoadLookup;
dvander@211
   464
	bool m_AllPluginsLoaded;
dvander@229
   465
	IdentityToken_t *m_MyIdent;
dvander@601
   466
dvander@601
   467
	/* Dynamic native stuff */
dvander@601
   468
	List<FakeNative *> m_Natives;
dvander@601
   469
dvander@1630
   470
	bool m_LoadingLocked;
asherkin@3601
   471
	
asherkin@3601
   472
	// Config
asherkin@3601
   473
	bool m_bBlockBadPlugins;
asherkin@3703
   474
	
asherkin@3703
   475
	// Forwards
asherkin@3703
   476
	IForward *m_pOnLibraryAdded;
asherkin@3703
   477
	IForward *m_pOnLibraryRemoved;
dvander@174
   478
};
dvander@174
   479
dvander@211
   480
extern CPluginManager g_PluginSys;
dvander@174
   481
dvander@173
   482
#endif //_INCLUDE_SOURCEMOD_PLUGINSYSTEM_H_
dvander@2906
   483