2008-03-30 09:00:22 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
|
|
|
* SourceMod
|
|
|
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
|
|
|
|
#define _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
|
|
|
|
|
|
|
|
#include <IExtensionSys.h>
|
|
|
|
#include <ILibrarySys.h>
|
|
|
|
#include <sh_list.h>
|
|
|
|
#include <sh_string.h>
|
2013-03-29 19:37:29 +01:00
|
|
|
#include "common_logic.h"
|
2008-03-30 09:00:22 +02:00
|
|
|
#include <IPluginSys.h>
|
|
|
|
#include <IRootConsoleMenu.h>
|
2008-05-26 09:51:11 +02:00
|
|
|
#include "NativeOwner.h"
|
2013-03-29 19:37:29 +01:00
|
|
|
#include "ShareSys.h"
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2012-05-27 02:51:08 +02:00
|
|
|
class CPlayer;
|
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
using namespace SourceMod;
|
|
|
|
using namespace SourceHook;
|
|
|
|
|
|
|
|
class CExtension;
|
|
|
|
|
|
|
|
struct sm_extnative_t
|
|
|
|
{
|
|
|
|
CExtension *owner;
|
|
|
|
const sp_nativeinfo_t *info;
|
|
|
|
};
|
|
|
|
|
2008-05-26 09:51:11 +02:00
|
|
|
class CExtension :
|
|
|
|
public IExtension,
|
|
|
|
public CNativeOwner
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
friend class CExtensionManager;
|
|
|
|
public:
|
|
|
|
virtual ~CExtension();
|
|
|
|
public: //IExtension
|
|
|
|
IExtensionInterface *GetAPI();
|
|
|
|
const char *GetFilename();
|
2011-10-12 04:51:24 +02:00
|
|
|
const char *GetPath() const;
|
2008-03-30 09:00:22 +02:00
|
|
|
IdentityToken_t *GetIdentity();
|
|
|
|
ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface);
|
|
|
|
bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface);
|
|
|
|
void FreeDependencyIterator(ITERATOR *iter);
|
|
|
|
bool IsRunning(char *error, size_t maxlength);
|
|
|
|
public:
|
|
|
|
void SetError(const char *error);
|
2008-07-01 08:12:16 +02:00
|
|
|
void AddDependency(const IfaceInfo *pInfo);
|
2008-03-30 09:00:22 +02:00
|
|
|
void AddChildDependent(CExtension *pOther, SMInterface *iface);
|
|
|
|
void AddInterface(SMInterface *pInterface);
|
2008-05-26 09:51:11 +02:00
|
|
|
void AddPlugin(CPlugin *pPlugin);
|
2008-03-30 09:00:22 +02:00
|
|
|
void MarkAllLoaded();
|
|
|
|
void AddLibrary(const char *library);
|
|
|
|
public:
|
|
|
|
virtual bool Load(char *error, size_t maxlength);
|
|
|
|
virtual bool IsLoaded() =0;
|
|
|
|
virtual void Unload() =0;
|
2009-08-23 23:11:42 +02:00
|
|
|
virtual bool Reload(char *error, size_t maxlength) =0;
|
2009-08-30 09:03:58 +02:00
|
|
|
virtual bool IsSameFile(const char* file) =0;
|
2008-03-30 09:00:22 +02:00
|
|
|
protected:
|
|
|
|
void Initialize(const char *filename, const char *path);
|
|
|
|
bool PerformAPICheck(char *error, size_t maxlength);
|
|
|
|
void CreateIdentity();
|
|
|
|
void DestroyIdentity();
|
|
|
|
protected:
|
|
|
|
IdentityToken_t *m_pIdentToken;
|
|
|
|
IExtensionInterface *m_pAPI;
|
|
|
|
String m_File;
|
2009-08-30 09:03:58 +02:00
|
|
|
String m_RealFile;
|
2008-03-30 09:00:22 +02:00
|
|
|
String m_Path;
|
|
|
|
String m_Error;
|
|
|
|
List<IfaceInfo> m_Deps; /** Dependencies */
|
|
|
|
List<IfaceInfo> m_ChildDeps; /** Children who might depend on us */
|
|
|
|
List<SMInterface *> m_Interfaces;
|
|
|
|
List<String> m_Libraries;
|
|
|
|
unsigned int unload_code;
|
|
|
|
bool m_bFullyLoaded;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CLocalExtension : public CExtension
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CLocalExtension(const char *filename);
|
|
|
|
public:
|
|
|
|
bool Load(char *error, size_t maxlength);
|
|
|
|
bool IsLoaded();
|
|
|
|
void Unload();
|
2009-08-23 23:11:42 +02:00
|
|
|
bool Reload(char *error, size_t maxlength);
|
2008-03-30 09:00:22 +02:00
|
|
|
bool IsExternal();
|
2009-08-30 09:03:58 +02:00
|
|
|
bool IsSameFile(const char *file);
|
2008-03-30 09:00:22 +02:00
|
|
|
private:
|
2013-03-29 19:37:29 +01:00
|
|
|
int m_PlId;
|
2008-03-30 09:00:22 +02:00
|
|
|
ILibrary *m_pLib;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CRemoteExtension : public CExtension
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CRemoteExtension(IExtensionInterface *pAPI, const char *filename, const char *path);
|
|
|
|
public:
|
|
|
|
bool Load(char *error, size_t maxlength);
|
|
|
|
bool IsLoaded();
|
|
|
|
void Unload();
|
2009-08-23 23:11:42 +02:00
|
|
|
bool Reload(char *error, size_t maxlength);
|
2008-03-30 09:00:22 +02:00
|
|
|
bool IsExternal();
|
2009-08-30 09:03:58 +02:00
|
|
|
bool IsSameFile(const char *file);
|
2008-03-30 09:00:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CExtensionManager :
|
2013-03-29 19:37:29 +01:00
|
|
|
public IExtensionSys,
|
2008-03-30 09:00:22 +02:00
|
|
|
public SMGlobalClass,
|
2013-04-01 07:03:57 +02:00
|
|
|
public IPluginsListener,
|
|
|
|
public IRootConsoleCommand
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CExtensionManager();
|
|
|
|
~CExtensionManager();
|
|
|
|
public: //SMGlobalClass
|
|
|
|
void OnSourceModAllInitialized();
|
|
|
|
void OnSourceModShutdown();
|
|
|
|
public: //IExtensionManager
|
|
|
|
IExtension *LoadExtension(const char *path,
|
|
|
|
char *error,
|
|
|
|
size_t maxlength);
|
|
|
|
bool UnloadExtension(IExtension *pExt);
|
|
|
|
IExtension *FindExtensionByFile(const char *file);
|
|
|
|
IExtension *FindExtensionByName(const char *ext);
|
|
|
|
IExtension *LoadExternal(IExtensionInterface *pInterface,
|
|
|
|
const char *filepath,
|
|
|
|
const char *filename,
|
|
|
|
char *error,
|
|
|
|
size_t maxlength);
|
|
|
|
public: //IPluginsListener
|
|
|
|
void OnPluginDestroyed(IPlugin *plugin);
|
|
|
|
public: //IRootConsoleCommand
|
2015-08-28 04:59:04 +02:00
|
|
|
void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
|
2008-03-30 09:00:22 +02:00
|
|
|
public:
|
2013-08-24 06:12:21 +02:00
|
|
|
IExtension *LoadAutoExtension(const char *path, bool bErrorOnMissing=true);
|
2008-03-30 09:00:22 +02:00
|
|
|
void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
|
|
|
|
void AddInterface(IExtension *pOwner, SMInterface *pInterface);
|
2013-03-29 19:37:29 +01:00
|
|
|
void BindChildPlugin(IExtension *pParent, SMPlugin *pPlugin);
|
2008-03-30 09:00:22 +02:00
|
|
|
void MarkAllLoaded();
|
|
|
|
void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
|
|
|
|
void TryAutoload();
|
|
|
|
void AddLibrary(IExtension *pSource, const char *library);
|
|
|
|
bool LibraryExists(const char *library);
|
2008-04-12 03:35:45 +02:00
|
|
|
void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
|
2014-08-08 07:01:47 +02:00
|
|
|
void CallOnCoreMapEnd();
|
2008-07-01 08:12:16 +02:00
|
|
|
void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface);
|
2013-03-31 22:30:22 +02:00
|
|
|
const CVector<IExtension *> *ListExtensions();
|
|
|
|
void FreeExtensionList(const CVector<IExtension *> *list);
|
2008-03-30 09:00:22 +02:00
|
|
|
public:
|
|
|
|
CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
|
|
|
|
void Shutdown();
|
2008-05-26 09:51:11 +02:00
|
|
|
CNativeOwner *GetNativeOwner(IExtension *pExt)
|
|
|
|
{
|
|
|
|
CExtension *p = (CExtension *)pExt;
|
|
|
|
return p;
|
|
|
|
}
|
2008-03-30 09:00:22 +02:00
|
|
|
private:
|
|
|
|
CExtension *FindByOrder(unsigned int num);
|
|
|
|
private:
|
|
|
|
List<CExtension *> m_Libs;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern CExtensionManager g_Extensions;
|
|
|
|
|
|
|
|
#endif //_INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
|