1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/ShareSys.h Sun Nov 16 16:06:18 2008 -0800
1.3 @@ -0,0 +1,150 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod
1.8 + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
1.9 + * =============================================================================
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify it under
1.12 + * the terms of the GNU General Public License, version 3.0, as published by the
1.13 + * Free Software Foundation.
1.14 + *
1.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 + * details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License along with
1.21 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 + *
1.23 + * As a special exception, AlliedModders LLC gives you permission to link the
1.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 + * by the Valve Corporation. You must obey the GNU General Public License in
1.27 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 + * this exception to all derivative works. AlliedModders LLC defines further
1.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 + * or <http://www.sourcemod.net/license.php>.
1.31 + *
1.32 + * Version: $Id$
1.33 + */
1.34 +
1.35 +#ifndef _INCLUDE_SOURCEMOD_SHARESYSTEM_H_
1.36 +#define _INCLUDE_SOURCEMOD_SHARESYSTEM_H_
1.37 +
1.38 +#include <IShareSys.h>
1.39 +#include <IHandleSys.h>
1.40 +#include <sh_list.h>
1.41 +#include <sm_trie_tpl.h>
1.42 +#include "sm_globals.h"
1.43 +#include "sourcemod.h"
1.44 +
1.45 +using namespace SourceHook;
1.46 +
1.47 +namespace SourceMod
1.48 +{
1.49 + struct IdentityToken_t
1.50 + {
1.51 + Handle_t ident;
1.52 + void *ptr;
1.53 + IdentityType_t type;
1.54 + };
1.55 +};
1.56 +
1.57 +struct IfaceInfo
1.58 +{
1.59 + bool operator ==(const IfaceInfo &info)
1.60 + {
1.61 + return (info.iface == iface && info.owner == owner);
1.62 + }
1.63 + SMInterface *iface;
1.64 + IExtension *owner;
1.65 +};
1.66 +
1.67 +class CNativeOwner;
1.68 +class CPlugin;
1.69 +struct NativeEntry;
1.70 +
1.71 +struct ReplaceNative
1.72 +{
1.73 + CNativeOwner *owner;
1.74 + SPVM_NATIVE_FUNC func;
1.75 +};
1.76 +
1.77 +struct FakeNative
1.78 +{
1.79 + char name[64];
1.80 + IPluginContext *ctx;
1.81 + IPluginFunction *call;
1.82 +};
1.83 +
1.84 +struct NativeEntry
1.85 +{
1.86 + CNativeOwner *owner;
1.87 + SPVM_NATIVE_FUNC func;
1.88 + const char *name;
1.89 + ReplaceNative replacement;
1.90 + FakeNative *fake;
1.91 +};
1.92 +
1.93 +class ShareSystem :
1.94 + public IShareSys,
1.95 + public SMGlobalClass,
1.96 + public IHandleTypeDispatch
1.97 +{
1.98 + friend class CNativeOwner;
1.99 +public:
1.100 + ShareSystem();
1.101 +public: //IShareSys
1.102 + bool AddInterface(IExtension *myself, SMInterface *pIface);
1.103 + bool RequestInterface(const char *iface_name,
1.104 + unsigned int iface_vers,
1.105 + IExtension *myself,
1.106 + SMInterface **pIface);
1.107 + void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives);
1.108 + IdentityType_t CreateIdentType(const char *name);
1.109 + IdentityType_t FindIdentType(const char *name);
1.110 + IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr);
1.111 + void DestroyIdentType(IdentityType_t type);
1.112 + void DestroyIdentity(IdentityToken_t *identity);
1.113 + void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload);
1.114 + void RegisterLibrary(IExtension *myself, const char *name);
1.115 + void OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives);
1.116 +public: //SMGlobalClass
1.117 + /* Pre-empt in case anything tries to register idents early */
1.118 + void Initialize();
1.119 + void OnSourceModShutdown();
1.120 +public: //IHandleTypeDispatch
1.121 + void OnHandleDestroy(HandleType_t type, void *object);
1.122 +public:
1.123 + IdentityToken_t *CreateCoreIdentity();
1.124 + void RemoveInterfaces(IExtension *pExtension);
1.125 +public:
1.126 + inline IdentityToken_t *GetIdentRoot()
1.127 + {
1.128 + return &m_IdentRoot;
1.129 + }
1.130 +public:
1.131 + void BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly);
1.132 + void BindNativeToPlugin(CPlugin *pPlugin, NativeEntry *pEntry);
1.133 + NativeEntry *AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func);
1.134 +private:
1.135 + NativeEntry *AddNativeToCache(CNativeOwner *pOwner, const sp_nativeinfo_t *ntv);
1.136 + void ClearNativeFromCache(CNativeOwner *pOwner, const char *name);
1.137 + NativeEntry *FindNative(const char *name);
1.138 + void BindNativeToPlugin(CPlugin *pPlugin,
1.139 + sp_native_t *ntv,
1.140 + uint32_t index,
1.141 + NativeEntry *pEntry);
1.142 +private:
1.143 + List<IfaceInfo> m_Interfaces;
1.144 + HandleType_t m_TypeRoot;
1.145 + IdentityToken_t m_IdentRoot;
1.146 + HandleType_t m_IfaceType;
1.147 + IdentityType_t m_CoreType;
1.148 + KTrie<NativeEntry *> m_NtvCache;
1.149 +};
1.150 +
1.151 +extern ShareSystem g_ShareSys;
1.152 +
1.153 +#endif //_INCLUDE_SOURCEMOD_SHARESYSTEM_H_