core/systems/PluginSys.h
author David Anderson <dvander@alliedmods.net>
Wed Mar 12 02:12:47 2008 +0000 (2008-03-12)
changeset 1923 dc25c22f8b1e
parent 1902 ce912ad912a5
child 1947 e73a1e51833b
permissions -rw-r--r--
updated comment at top of pluginsys header
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
dvander@1231
     5
 * Copyright (C) 2004-2007 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@173
    45
#include "sm_globals.h"
dvander@262
    46
#include "vm/sp_vm_basecontext.h"
dvander@203
    47
#include "PluginInfoDatabase.h"
dvander@211
    48
#include "sm_trie.h"
dvander@220
    49
#include "sourcemod.h"
dvander@309
    50
#include <IRootConsoleMenu.h>
faluco@1541
    51
#if defined ORANGEBOX_BUILD
faluco@1541
    52
#include "convar_sm_ob.h"
faluco@1541
    53
#else
ds@457
    54
#include "convar_sm.h"
faluco@1541
    55
#endif
dvander@173
    56
dvander@174
    57
using namespace SourceHook;
dvander@174
    58
dvander@209
    59
/**
dvander@209
    60
 * NOTES:
dvander@209
    61
 *
dvander@1923
    62
 * UPDATE 2008-03-11: These comments are horribly out of date.  They paint a good overall 
dvander@1923
    63
 * picture of how PluginSys works, but things like dependencies and fake natives have 
dvander@1923
    64
 * complicated things quite a bit.
dvander@1923
    65
 *
dvander@209
    66
 *  Currently this system needs a lot of work but it's good skeletally.  Plugin creation 
dvander@209
    67
 * is done without actually compiling anything.  This is done by Load functions in the 
dvander@209
    68
 * manager.  This will need a rewrite when we add context switching.
dvander@209
    69
 *
dvander@209
    70
 *  The plugin object itself has a few things to note.  The most important is that it stores
dvander@209
    71
 * a table of function objects.  The manager marshals allocation and freeing of these objects.
dvander@209
    72
 * The plugin object can be in erroneous states, they are:
dvander@209
    73
 *   Plugin_Error   --> Some error occurred any time during or after compilation.
dvander@209
    74
 *						This error can be cleared since the plugin itself is valid.
dvander@209
    75
 *						However, the state itself being set prevents any runtime action.
dvander@209
    76
 *   Plugin_BadLoad	--> The plugin failed to load entirely and nothing can be done to save it.
dvander@209
    77
 *
dvander@209
    78
 *  If a plugin fails to load externally, it is never added to the internal tracker.  However, 
dvander@209
    79
 * plugins that failed to load from the internal loading mechanism are always tracked.  This 
dvander@209
    80
 * allows users to see which automatically loaded plugins failed, and makes the interface a bit
dvander@209
    81
 * more flexible.
dvander@211
    82
 *
dvander@211
    83
 *  Once a plugin is compiled, it sets its own state to Plugin_Created.  This state is still invalid
dvander@211
    84
 * for execution.  SourceMod is a two pass system, and even though the second pass is not implemented
dvander@211
    85
 * yet, it is structured so Plugin_Created must be switched to Plugin_Running in the second pass.  When
dvander@211
    86
 * implemented, a Created plugin will be switched to Error in the second pass if it not loadable.
dvander@211
    87
 *
dvander@211
    88
 *  The two pass loading mechanism is described below.  Modules/natives are not implemented yet.
dvander@211
    89
 * PASS ONE: All loadable plugins are found and have the following steps performed:
dvander@211
    90
 *			 1.  Loading and compilation is attempted.
dvander@211
    91
 *			 2.  If successful, all natives from Core are added.
dvander@211
    92
 *			 3.  OnPluginLoad() is called.
dvander@211
    93
 *			 4.  If failed, any user natives are scrapped and the process halts here.
dvander@211
    94
 *			 5.  If successful, the plugin is ready for Pass 2.
dvander@211
    95
 * INTERMEDIATE:
dvander@211
    96
 *			 1.  All forced modules are loaded.
dvander@211
    97
 * PASS TWO: All loaded plugins are found and have these steps performed:
dvander@211
    98
 *			 1. Any modules referenced in the plugin that are not already loaded, are loaded.
dvander@211
    99
 *			 2. If any module fails to load and the plugin requires it, load fails and jump to step 6.
dvander@211
   100
 *			 3. If any natives are unresolved, check if they are found in the user-natives pool.
dvander@211
   101
 *			 4. If yes, load succeeds.  If not, natives are passed through a native acceptance filter.
dvander@211
   102
 *			 5. If the filter fails, the plugin is marked as failed.
dvander@211
   103
 *			 6. If the plugin has failed to load at this point, any dynamic natives it has added are scrapped.
dvander@211
   104
 *			    Furthermore, any plugin that referenced these natives must now have pass 2 re-ran.
dvander@211
   105
 * PASS THREE (not a real pass):
ds@426
   106
 *			 7. Once all plugins are deemed to be loaded, OnPluginStart() is called
dvander@209
   107
 */
dvander@209
   108
dvander@174
   109
#define SM_CONTEXTVAR_MYSELF	0
dvander@174
   110
dvander@173
   111
struct ContextPair
dvander@173
   112
{
dvander@209
   113
	ContextPair() : base(NULL), ctx(NULL), co(NULL)
dvander@173
   114
	{
dvander@173
   115
	};
dvander@262
   116
	BaseContext *base;
dvander@173
   117
	sp_context_t *ctx;
dvander@209
   118
	ICompilation *co;
dvander@209
   119
	IVirtualMachine *vm;
dvander@173
   120
};
dvander@173
   121
dvander@605
   122
struct FakeNative
dvander@605
   123
{
dvander@605
   124
	IPluginContext *ctx;
dvander@605
   125
	IPluginFunction *call;
dvander@605
   126
	String name;
dvander@605
   127
	SPVM_NATIVE_FUNC func;
dvander@605
   128
};
dvander@605
   129
faluco@383
   130
enum LoadRes
faluco@383
   131
{
faluco@383
   132
	LoadRes_Successful,
faluco@383
   133
	LoadRes_AlreadyLoaded,
dvander@1436
   134
	LoadRes_Failure,
dvander@1436
   135
	LoadRes_NeverLoad
faluco@383
   136
};
faluco@383
   137
dvander@978
   138
struct AutoConfig
dvander@978
   139
{
dvander@978
   140
	String autocfg;
dvander@978
   141
	String folder;
dvander@978
   142
	bool create;
dvander@978
   143
};
dvander@978
   144
faluco@1112
   145
class CPlugin;
faluco@1112
   146
struct WeakNative
faluco@1112
   147
{
faluco@1112
   148
	WeakNative(CPlugin *plugin, uint32_t index)
faluco@1112
   149
	{
faluco@1112
   150
		pl = plugin;
faluco@1112
   151
		idx = index;
faluco@1112
   152
	}
faluco@1112
   153
	CPlugin *pl;
faluco@1112
   154
	uint32_t idx;
faluco@1112
   155
};
faluco@1112
   156
dvander@173
   157
class CPlugin : public IPlugin
dvander@173
   158
{
dvander@174
   159
	friend class CPluginManager;
dvander@176
   160
	friend class CFunction;
dvander@173
   161
public:
dvander@209
   162
	CPlugin(const char *file);
dvander@209
   163
	~CPlugin();
dvander@209
   164
public:
faluco@641
   165
	PluginType GetType();
faluco@641
   166
	SourcePawn::IPluginContext *GetBaseContext();
faluco@641
   167
	sp_context_t *GetContext();
faluco@641
   168
	const sm_plugininfo_t *GetPublicInfo();
faluco@641
   169
	const char *GetFilename();
faluco@641
   170
	bool IsDebugging();
faluco@641
   171
	PluginStatus GetStatus();
faluco@641
   172
	bool SetPauseState(bool paused);
faluco@641
   173
	unsigned int GetSerial();
faluco@641
   174
	const sp_plugin_t *GetPluginStructure();
faluco@641
   175
	IdentityToken_t *GetIdentity();
dvander@1766
   176
	unsigned int CalcMemUsage();
faluco@641
   177
	bool SetProperty(const char *prop, void *ptr);
faluco@641
   178
	bool GetProperty(const char *prop, void **ptr, bool remove=false);
dvander@173
   179
public:
dvander@209
   180
	/**
dvander@209
   181
	 * Creates a plugin object with default values.
dvander@209
   182
	 *   If an error buffer is specified, and an error occurs, the error will be copied to the buffer
dvander@209
   183
	 * and NULL will be returned.
dvander@209
   184
	 *   If an error buffer is not specified, the error will be copied to an internal buffer and 
dvander@209
   185
	 * a valid (but error-stated) CPlugin will be returned.
dvander@209
   186
	 */
dvander@209
   187
	static CPlugin *CreatePlugin(const char *file, char *error, size_t maxlength);
dvander@209
   188
public:
dvander@209
   189
	/**
dvander@209
   190
	 * Starts the initial compilation of a plugin.
dvander@209
   191
	 * Returns false if another compilation exists or there is a current context set.
dvander@209
   192
	 */
dvander@209
   193
	ICompilation *StartMyCompile(IVirtualMachine *vm);
dvander@209
   194
	/** 
dvander@209
   195
	 * Finalizes a compilation.  If error buffer is NULL, the error is saved locally.
dvander@209
   196
	 */
dvander@209
   197
	bool FinishMyCompile(char *error, size_t maxlength);
dvander@209
   198
	void CancelMyCompile();
dvander@229
   199
dvander@209
   200
	/**
dvander@209
   201
	 * Sets an error state on the plugin
dvander@209
   202
	 */
dvander@209
   203
	void SetErrorState(PluginStatus status, const char *error_fmt, ...);
dvander@211
   204
dvander@211
   205
	/**
dvander@229
   206
	 * Initializes the plugin's identity information
dvander@229
   207
	 */
dvander@229
   208
	void InitIdentity();
dvander@229
   209
dvander@229
   210
	/**
dvander@211
   211
	 * Calls the OnPluginLoad function, and sets any failed states if necessary.
dvander@211
   212
	 * NOTE: Valid pre-states are: Plugin_Created
dvander@282
   213
	 * NOTE: If validated, plugin state is changed to Plugin_Loaded
dvander@211
   214
	 *
dvander@211
   215
	 * If the error buffer is NULL, the error message is cached locally.
dvander@211
   216
	 */
dvander@211
   217
	bool Call_AskPluginLoad(char *error, size_t maxlength);
dvander@211
   218
dvander@211
   219
	/**
ds@426
   220
	 * Calls the OnPluginStart function.
dvander@211
   221
	 * NOTE: Valid pre-states are: Plugin_Created
dvander@282
   222
	 * NOTE: Post-state will be Plugin_Running
dvander@211
   223
	 */
ds@426
   224
	void Call_OnPluginStart();
dvander@282
   225
dvander@282
   226
	/**
ds@426
   227
	 * Calls the OnPluginEnd function.
dvander@282
   228
	 */
ds@426
   229
	void Call_OnPluginEnd();
faluco@290
   230
faluco@290
   231
	/**
faluco@1221
   232
	 * Calls the OnAllPluginsLoaded function.
faluco@1221
   233
	 */
faluco@1221
   234
	void Call_OnAllPluginsLoaded();
faluco@1221
   235
faluco@1221
   236
	/**
dvander@315
   237
	 * Toggles debug mode in the plugin
dvander@315
   238
	 */
dvander@309
   239
	bool ToggleDebugMode(bool debug, char *error, size_t maxlength);
faluco@290
   240
faluco@290
   241
	/**
dvander@315
   242
	 * Returns true if a plugin is usable.
dvander@315
   243
	 */
dvander@615
   244
	bool IsRunnable();
faluco@389
   245
faluco@389
   246
	/**
dvander@536
   247
	 * Adds a language file index to the plugin's list.
dvander@536
   248
	 */
faluco@389
   249
	void AddLangFile(unsigned int index);
faluco@389
   250
faluco@389
   251
	/**
dvander@536
   252
	 * Get language file count for this plugin.
dvander@536
   253
	 */
dvander@615
   254
	size_t GetLangFileCount();
faluco@389
   255
faluco@389
   256
	/**
dvander@536
   257
	 * Get language file index based on the vector index.
dvander@536
   258
	 */
dvander@615
   259
	unsigned int GetLangFileByIndex(unsigned int index);
dvander@211
   260
public:
faluco@333
   261
	/**
dvander@536
   262
	 * Returns the modification time during last plugin load.
dvander@536
   263
	 */
dvander@615
   264
	time_t GetTimeStamp();
faluco@333
   265
faluco@333
   266
	/**
dvander@536
   267
	 * Returns the current modification time of the plugin file.
dvander@536
   268
	 */
faluco@333
   269
	time_t GetFileTimeStamp();
dvander@282
   270
dvander@282
   271
	/** 
dvander@282
   272
	 * Returns true if the plugin was running, but is now invalid.
dvander@282
   273
	 */
dvander@282
   274
	bool WasRunning();
dvander@536
   275
dvander@536
   276
	Handle_t GetMyHandle();
dvander@978
   277
dvander@978
   278
	void AddConfig(bool autoCreate, const char *cfg, const char *folder);
dvander@978
   279
	unsigned int GetConfigCount();
dvander@978
   280
	AutoConfig *GetConfig(unsigned int i);
faluco@1112
   281
	inline void AddLibrary(const char *name)
faluco@1089
   282
	{
faluco@1112
   283
		m_Libraries.push_back(name);
faluco@1089
   284
	}
dvander@1124
   285
	void LibraryActions(bool dropping);
dvander@173
   286
protected:
dvander@173
   287
	void UpdateInfo();
faluco@333
   288
	void SetTimeStamp(time_t t);
dvander@605
   289
	void DependencyDropped(CPlugin *pOwner);
dvander@173
   290
private:
dvander@209
   291
	ContextPair m_ctx;
dvander@174
   292
	PluginType m_type;
ds@652
   293
	char m_filename[PLATFORM_MAX_PATH];
dvander@173
   294
	PluginStatus m_status;
dvander@173
   295
	unsigned int m_serial;
dvander@173
   296
	sm_plugininfo_t m_info;
dvander@173
   297
	sp_plugin_t *m_plugin;
dvander@209
   298
	char m_errormsg[256];
dvander@211
   299
	time_t m_LastAccess;
dvander@229
   300
	IdentityToken_t *m_ident;
dvander@220
   301
	Handle_t m_handle;
dvander@282
   302
	bool m_WasRunning;
faluco@389
   303
	CVector<unsigned int> m_PhraseFiles;
dvander@605
   304
	List<CPlugin *> m_dependents;
dvander@605
   305
	List<CPlugin *> m_dependsOn;
dvander@605
   306
	List<FakeNative *> m_fakeNatives;
dvander@1122
   307
	List<WeakNative> m_WeakNatives;
faluco@1112
   308
	List<String> m_RequiredLibs;
faluco@1112
   309
	List<String> m_Libraries;
dvander@486
   310
	Trie *m_pProps;
dvander@605
   311
	bool m_FakeNativesMissing;
faluco@1112
   312
	bool m_LibraryMissing;
dvander@978
   313
	CVector<AutoConfig *> m_configs;
dvander@1630
   314
	bool m_bGotAllLoaded;
dvander@601
   315
};
dvander@601
   316
dvander@220
   317
class CPluginManager : 
dvander@220
   318
	public IPluginManager,
dvander@220
   319
	public SMGlobalClass,
dvander@309
   320
	public IHandleTypeDispatch,
dvander@309
   321
	public IRootConsoleCommand
dvander@174
   322
{
dvander@176
   323
	friend class CPlugin;
dvander@174
   324
public:
dvander@174
   325
	CPluginManager();
dvander@176
   326
	~CPluginManager();
dvander@174
   327
public:
dvander@203
   328
	/* Implements iterator class */
dvander@174
   329
	class CPluginIterator : public IPluginIterator
dvander@174
   330
	{
dvander@174
   331
	public:
dvander@213
   332
		CPluginIterator(List<CPlugin *> *mylist);
dvander@174
   333
		virtual ~CPluginIterator();
dvander@174
   334
		virtual bool MorePlugins();
dvander@174
   335
		virtual IPlugin *GetPlugin();
dvander@174
   336
		virtual void NextPlugin();
dvander@282
   337
		void Release();
dvander@174
   338
	public:
dvander@174
   339
		void Reset();
dvander@174
   340
	private:
dvander@213
   341
		List<CPlugin *> *mylist;
dvander@213
   342
		List<CPlugin *>::iterator current;
dvander@174
   343
	};
dvander@174
   344
	friend class CPluginManager::CPluginIterator;
dvander@203
   345
public: //IPluginManager
dvander@282
   346
	IPlugin *LoadPlugin(const char *path, 
dvander@174
   347
								bool debug,
dvander@174
   348
								PluginType type,
dvander@174
   349
								char error[],
ds@755
   350
								size_t maxlength,
faluco@383
   351
								bool *wasloaded);
dvander@282
   352
	bool UnloadPlugin(IPlugin *plugin);
dvander@282
   353
	IPlugin *FindPluginByContext(const sp_context_t *ctx);
dvander@282
   354
	unsigned int GetPluginCount();
dvander@282
   355
	IPluginIterator *GetPluginIterator();
dvander@282
   356
	void AddPluginsListener(IPluginsListener *listener);
dvander@282
   357
	void RemovePluginsListener(IPluginsListener *listener);
dvander@220
   358
public: //SMGlobalClass
dvander@282
   359
	void OnSourceModAllInitialized();
dvander@282
   360
	void OnSourceModShutdown();
dvander@220
   361
public: //IHandleTypeDispatch
dvander@282
   362
	void OnHandleDestroy(HandleType_t type, void *object);
dvander@1766
   363
	bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
dvander@309
   364
public: //IRootConsoleCommand
faluco@1541
   365
	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
dvander@190
   366
public:
dvander@203
   367
	/**
dvander@211
   368
	 * Loads all plugins not yet loaded
dvander@203
   369
	 */
dvander@211
   370
	void LoadAll_FirstPass(const char *config, const char *basedir);
dvander@211
   371
dvander@211
   372
	/**
dvander@211
   373
	 * Runs the second loading pass for all plugins
dvander@211
   374
	 */
dvander@211
   375
	void LoadAll_SecondPass();
dvander@203
   376
dvander@203
   377
	/**
dvander@203
   378
	 * Tests a plugin file mask against a local folder.
dvander@203
   379
	 * The alias is searched backwards from localdir - i.e., given this input:
dvander@203
   380
	 *   csdm/ban        csdm/ban
dvander@203
   381
	 *   ban             csdm/ban
dvander@203
   382
	 *   csdm/ban        optional/csdm/ban
dvander@203
   383
	 * All of these will return true for an alias match.  
dvander@203
   384
	 * Wildcards are allowed in the filename.
dvander@203
   385
	 */
dvander@209
   386
	bool TestAliasMatch(const char *alias, const char *localdir);
dvander@211
   387
dvander@211
   388
	/** 
dvander@211
   389
	 * Returns whether anything loaded will be a late load.
dvander@211
   390
	 */
faluco@290
   391
	bool IsLateLoadTime() const;
dvander@233
   392
dvander@233
   393
	/**
dvander@233
   394
	 * Adds natives from core into the native pool.
dvander@233
   395
	 */
dvander@233
   396
	void RegisterNativesFromCore(sp_nativeinfo_t *natives);
dvander@247
   397
dvander@247
   398
	/**
dvander@247
   399
	 * Converts a Handle to an IPlugin if possible.
dvander@247
   400
	 */
dvander@247
   401
	IPlugin *PluginFromHandle(Handle_t handle, HandleError *err);
faluco@290
   402
faluco@290
   403
	/**
dvander@309
   404
	 * Finds a plugin based on its index. (starts on index 1)
dvander@309
   405
	 */
faluco@290
   406
	CPlugin *GetPluginByOrder(int num);
dvander@309
   407
dvander@1638
   408
	int GetOrderOfPlugin(IPlugin *pl);
dvander@1638
   409
ds@457
   410
	/** 
ds@457
   411
	 * Internal version of FindPluginByContext()
ds@457
   412
	 */
ds@457
   413
	inline CPlugin *GetPluginByCtx(const sp_context_t *ctx)
ds@457
   414
	{
ds@457
   415
		return reinterpret_cast<CPlugin *>(ctx->user[SM_CONTEXTVAR_MYSELF]);
ds@457
   416
	}
ds@457
   417
dvander@309
   418
	/**
dvander@309
   419
	 * Gets status text for a status code 
dvander@309
   420
	 */
dvander@309
   421
	const char *GetStatusText(PluginStatus status);
dvander@315
   422
faluco@333
   423
	/**
faluco@333
   424
	* Reload or update plugins on level shutdown.
faluco@333
   425
	*/
faluco@333
   426
	void ReloadOrUnloadPlugins();
faluco@333
   427
ds@611
   428
	/**
ds@611
   429
	 * Add public functions from all running or paused
ds@611
   430
	 * plugins to the specified forward if the names match.
ds@611
   431
	 */
ds@611
   432
	void AddFunctionsToForward(const char *name, IChangeableForward *pForward);
ds@611
   433
faluco@1221
   434
	/**
faluco@1221
   435
	 * Iterates through plugins to call OnAllPluginsLoaded.
faluco@1221
   436
	 */
faluco@1221
   437
	void AllPluginsLoaded();
faluco@1221
   438
dvander@900
   439
	CPlugin *GetPluginFromIdentity(IdentityToken_t *pToken);
dvander@900
   440
dvander@1018
   441
	void Shutdown();
dvander@1018
   442
dvander@1572
   443
	void OnLibraryAction(const char *lib, bool is_a_plugin, bool drop);
dvander@1124
   444
dvander@1124
   445
	bool LibraryExists(const char *lib);
faluco@1348
   446
faluco@1348
   447
	bool ReloadPlugin(CPlugin *pl);
dvander@1630
   448
dvander@1630
   449
	void UnloadAll();
dvander@1902
   450
dvander@1902
   451
	CPlugin *FindPluginByConsoleArg(const char *arg);
dvander@209
   452
private:
ds@755
   453
	LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);
dvander@298
   454
dvander@298
   455
	void LoadAutoPlugin(const char *plugin);
dvander@298
   456
dvander@209
   457
	/**
dvander@209
   458
	 * Recursively loads all plugins in the given directory.
dvander@209
   459
	 */
dvander@209
   460
	void LoadPluginsFromDir(const char *basedir, const char *localdir);
dvander@209
   461
dvander@209
   462
	/**
dvander@211
   463
	 * Adds a plugin object.  This is wrapped by LoadPlugin functions.
dvander@211
   464
	 */
dvander@211
   465
	void AddPlugin(CPlugin *pPlugin);
dvander@211
   466
dvander@211
   467
	/**
dvander@211
   468
	 * Runs the second loading pass on a plugin.
dvander@209
   469
	 */
dvander@298
   470
	bool RunSecondPass(CPlugin *pPlugin, char *error, size_t maxlength);
dvander@211
   471
dvander@211
   472
	/**
dvander@211
   473
	 * Adds any globally registered natives to a plugin
dvander@211
   474
	 */
dvander@211
   475
	void AddCoreNativesToPlugin(CPlugin *pPlugin);
dvander@315
   476
dvander@315
   477
	/**
dvander@315
   478
	 * Runs an extension pass on a plugin.
dvander@315
   479
	 */
dvander@315
   480
	bool LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass, char *error, size_t maxlength);
faluco@430
   481
faluco@1112
   482
	/**
faluco@1112
   483
	* Manages required natives.
faluco@1112
   484
	*/
faluco@1112
   485
	bool FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size_t maxlength);
faluco@1112
   486
faluco@430
   487
	void _SetPauseState(CPlugin *pPlugin, bool pause);
dvander@174
   488
protected:
dvander@209
   489
	/**
dvander@209
   490
	 * Caching internal objects
dvander@209
   491
	 */
dvander@174
   492
	void ReleaseIterator(CPluginIterator *iter);
dvander@900
   493
public:
dvander@229
   494
	inline IdentityToken_t *GetIdentity()
dvander@229
   495
	{
dvander@229
   496
		return m_MyIdent;
dvander@229
   497
	}
dvander@601
   498
public:
dvander@601
   499
	bool AddFakeNative(IPluginFunction *pFunction, const char *name, SPVM_FAKENATIVE_FUNC func);
dvander@1689
   500
	SPVM_NATIVE_FUNC FindCoreNative(const char *name);
dvander@601
   501
private:
dvander@601
   502
	void AddFakeNativesToPlugin(CPlugin *pPlugin);
faluco@1112
   503
	void TryRefreshDependencies(CPlugin *pOther);
dvander@174
   504
private:
dvander@174
   505
	List<IPluginsListener *> m_listeners;
dvander@213
   506
	List<CPlugin *> m_plugins;
dvander@174
   507
	CStack<CPluginManager::CPluginIterator *> m_iters;
dvander@203
   508
	CPluginInfoDatabase m_PluginInfo;
dvander@211
   509
	Trie *m_LoadLookup;
dvander@211
   510
	bool m_AllPluginsLoaded;
dvander@229
   511
	IdentityToken_t *m_MyIdent;
dvander@1382
   512
	Trie *m_pCoreNatives;
dvander@601
   513
dvander@601
   514
	/* Dynamic native stuff */
dvander@601
   515
	List<FakeNative *> m_Natives;
dvander@601
   516
	Trie *m_pNativeLookup;
dvander@601
   517
dvander@1630
   518
	bool m_LoadingLocked;
dvander@174
   519
};
dvander@174
   520
dvander@211
   521
extern CPluginManager g_PluginSys;
dvander@174
   522
dvander@173
   523
#endif //_INCLUDE_SOURCEMOD_PLUGINSYSTEM_H_