dvander@370: /** ds@653: * vim: set ts=4 : ds@1330: * ============================================================================= dvander@1231: * SourceMod ds@1947: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. ds@1330: * ============================================================================= dvander@370: * ds@1330: * This program is free software; you can redistribute it and/or modify it under ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the ds@1330: * Free Software Foundation. dvander@1231: * ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1330: * details. dvander@1231: * ds@1330: * You should have received a copy of the GNU General Public License along with ds@1330: * this program. If not, see . dvander@1231: * ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1330: * this exception to all derivative works. AlliedModders LLC defines further ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1330: * or . dvander@370: * dvander@370: * Version: $Id$ dvander@370: */ dvander@370: dvander@229: #ifndef _INCLUDE_SOURCEMOD_SHARESYSTEM_H_ dvander@229: #define _INCLUDE_SOURCEMOD_SHARESYSTEM_H_ dvander@229: dvander@229: #include dvander@229: #include dvander@229: #include dvander@2086: #include dvander@229: #include "sm_globals.h" dvander@229: #include "sourcemod.h" dvander@229: dvander@229: using namespace SourceHook; dvander@229: dvander@229: namespace SourceMod dvander@229: { dvander@229: struct IdentityToken_t dvander@229: { dvander@229: Handle_t ident; dvander@868: void *ptr; dvander@868: IdentityType_t type; dvander@229: }; dvander@229: }; dvander@229: dvander@229: struct IfaceInfo dvander@229: { dvander@1456: bool operator ==(const IfaceInfo &info) dvander@1456: { dvander@1456: return (info.iface == iface && info.owner == owner); dvander@1456: } dvander@229: SMInterface *iface; dvander@304: IExtension *owner; dvander@229: }; dvander@229: dvander@2086: class CNativeOwner; dvander@2086: class CPlugin; dvander@2086: struct NativeEntry; dvander@2086: dvander@2086: struct ReplaceNative dvander@2086: { dvander@2086: CNativeOwner *owner; dvander@2086: SPVM_NATIVE_FUNC func; dvander@2086: }; dvander@2086: dvander@2086: struct FakeNative dvander@2086: { dvander@2086: char name[64]; dvander@2086: IPluginContext *ctx; dvander@2086: IPluginFunction *call; dvander@2086: }; dvander@2086: dvander@2086: struct NativeEntry dvander@2086: { dvander@2086: CNativeOwner *owner; dvander@2086: SPVM_NATIVE_FUNC func; dvander@2086: const char *name; dvander@2086: ReplaceNative replacement; dvander@2086: FakeNative *fake; dvander@2086: }; dvander@2086: dvander@2841: struct Capability dvander@2841: { dvander@2841: IExtension *ext; dvander@2841: IFeatureProvider *provider; dvander@2841: }; dvander@2841: dvander@2841: class ShareSystem : dvander@229: public IShareSys, dvander@229: public SMGlobalClass, dvander@229: public IHandleTypeDispatch dvander@229: { dvander@2086: friend class CNativeOwner; dvander@229: public: dvander@229: ShareSystem(); dvander@229: public: //IShareSys dvander@304: bool AddInterface(IExtension *myself, SMInterface *pIface); dvander@229: bool RequestInterface(const char *iface_name, dvander@229: unsigned int iface_vers, ds@741: IExtension *myself, dvander@229: SMInterface **pIface); dvander@312: void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives); dvander@229: IdentityType_t CreateIdentType(const char *name); dvander@229: IdentityType_t FindIdentType(const char *name); dvander@868: IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr); dvander@229: void DestroyIdentType(IdentityType_t type); dvander@229: void DestroyIdentity(IdentityToken_t *identity); dvander@324: void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload); dvander@1572: void RegisterLibrary(IExtension *myself, const char *name); dvander@1689: void OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives); dvander@2841: void AddCapabilityProvider(IExtension *myself, IFeatureProvider *provider, dvander@2841: const char *name); dvander@2841: void DropCapabilityProvider(IExtension *myself, IFeatureProvider *provider, dvander@2841: const char *name); dvander@229: public: //SMGlobalClass dvander@229: /* Pre-empt in case anything tries to register idents early */ dvander@1770: void Initialize(); dvander@229: void OnSourceModShutdown(); dvander@229: public: //IHandleTypeDispatch dvander@229: void OnHandleDestroy(HandleType_t type, void *object); dvander@229: public: dvander@229: IdentityToken_t *CreateCoreIdentity(); dvander@304: void RemoveInterfaces(IExtension *pExtension); dvander@2841: FeatureStatus TestFeature(IPluginRuntime *pRuntime, FeatureType feature, const char *name); dvander@2841: FeatureStatus TestNative(IPluginRuntime *pRuntime, const char *name); dvander@2841: FeatureStatus TestCap(const char *name); dvander@229: public: dvander@229: inline IdentityToken_t *GetIdentRoot() dvander@229: { dvander@229: return &m_IdentRoot; dvander@229: } dvander@2086: public: dvander@2086: void BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly); dvander@2086: void BindNativeToPlugin(CPlugin *pPlugin, NativeEntry *pEntry); dvander@2086: NativeEntry *AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func); dvander@2545: NativeEntry *FindNative(const char *name); dvander@2086: private: dvander@2086: NativeEntry *AddNativeToCache(CNativeOwner *pOwner, const sp_nativeinfo_t *ntv); dvander@2086: void ClearNativeFromCache(CNativeOwner *pOwner, const char *name); dvander@2086: void BindNativeToPlugin(CPlugin *pPlugin, dvander@2086: sp_native_t *ntv, dvander@2086: uint32_t index, dvander@2086: NativeEntry *pEntry); dvander@229: private: dvander@229: List m_Interfaces; dvander@229: HandleType_t m_TypeRoot; dvander@229: IdentityToken_t m_IdentRoot; dvander@229: HandleType_t m_IfaceType; dvander@229: IdentityType_t m_CoreType; dvander@2086: KTrie m_NtvCache; dvander@2841: KTrie m_caps; dvander@229: }; dvander@229: dvander@229: extern ShareSystem g_ShareSys; dvander@229: dvander@229: #endif //_INCLUDE_SOURCEMOD_SHARESYSTEM_H_