core/metamod.h
author Nicholas Hastings <skamonkey@gmail.com>
Mon Aug 20 14:40:23 2012 -0400 (2012-08-20)
changeset 793 cee5c14ef277
parent 778 faee01f77160
child 839 eab123e5ee23
permissions -rw-r--r--
Fixed incompatibility introduced by cset a1b97ab6e0b1 (bug 5369).
     1 /**
     2  * vim: set ts=4 sw=4 tw=99 noet :
     3  * ======================================================
     4  * Metamod:Source
     5  * Copyright (C) 2004-2010 AlliedModders LLC and authors.
     6  * All rights reserved.
     7  * ======================================================
     8  *
     9  * This software is provided 'as-is', without any express or implied warranty.
    10  * In no event will the authors be held liable for any damages arising from 
    11  * the use of this software.
    12  * 
    13  * Permission is granted to anyone to use this software for any purpose, 
    14  * including commercial applications, and to alter it and redistribute it 
    15  * freely, subject to the following restrictions:
    16  *
    17  * 1. The origin of this software must not be misrepresented; you must not 
    18  * claim that you wrote the original software. If you use this software in a 
    19  * product, an acknowledgment in the product documentation would be 
    20  * appreciated but is not required.
    21  * 2. Altered source versions must be plainly marked as such, and must not be
    22  * misrepresented as being the original software.
    23  * 3. This notice may not be removed or altered from any source distribution.
    24  */
    25 
    26 #ifndef _INCLUDE_SOURCEMM_H
    27 #define _INCLUDE_SOURCEMM_H
    28 
    29 /**
    30  * @brief SourceMM main functionality for GameDLL interception
    31  * @file sourcemm.h
    32  */
    33 
    34 #include <interface.h>
    35 #include <eiface.h>
    36 #include <sourcehook/sourcehook_impl.h>
    37 #include <sourcehook/sourcehook_hookmangen.h>
    38 #include <sourcehook/sourcehook.h>
    39 #include <ISmmPlugin.h>
    40 #include "metamod_provider.h"
    41 #include <metamod_version.h>
    42 
    43 using namespace SourceMM;
    44 
    45 /**
    46  * Versioning
    47  *   increase api_major when API breaks
    48  *   increase api_minor when new functions are added (non-breaking)
    49  */
    50 #define SOURCEMM_VERSION	SVN_FILE_VERSION_STRING
    51 #define SOURCEMM_DATE		__DATE__
    52 #define METAMOD_API_MAJOR	2		/* increase this on a breaking change */
    53 #define METAMOD_API_MINOR	0		/* increase this on a non-breaking API change */
    54 
    55 class MetamodSource : public ISmmAPI
    56 {
    57 public:
    58 	void LogMsg(ISmmPlugin *pl, const char *msg, ...);
    59 	CreateInterfaceFn GetEngineFactory(bool syn=true);
    60 	CreateInterfaceFn GetPhysicsFactory(bool syn=true);
    61 	CreateInterfaceFn GetFileSystemFactory(bool syn=true);
    62 	CreateInterfaceFn GetServerFactory(bool syn=true);
    63 	CGlobalVars *GetCGlobals();
    64 	void SetLastMetaReturn(META_RES res);
    65 	META_RES GetLastMetaReturn();
    66 	IConCommandBaseAccessor *GetCvarBaseAccessor();
    67 	bool RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand);
    68 	void UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand);
    69 	void ConPrint(const char *str);
    70 	void ConPrintf(const char *fmt, ...);
    71 	bool RemotePrintingAvailable();
    72 	void GetApiVersions(int &major, int &minor, int &plvers, int &plmin);
    73 	void GetShVersions(int &shvers, int &shimpl);
    74 	void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener);
    75 	void *MetaFactory(const char *iface, int *ret, PluginId *id);
    76 	int FormatIface(char iface[], unsigned int maxlength);
    77 	void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret);
    78 	const char *GetBaseDir();
    79 	size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);
    80 	void ClientConPrintf(edict_t *client, const char *fmt, ...);
    81 	void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1);
    82 	void EnableVSPListener();
    83 	int GetGameDLLVersion();
    84 	int GetUserMessageCount();
    85 	int FindUserMessage(const char *name, int *size=NULL);
    86 	const char *GetUserMessage(int index, int *size=NULL);
    87 	int GetVSPVersion();
    88 	int GetSourceEngineBuild();
    89 	IServerPluginCallbacks *GetVSPInfo(int *pVersion);
    90 	size_t Format(char *buffer, size_t maxlength, const char *format, ...);
    91 	size_t FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap);
    92 public:
    93 	bool IsLoadedAsGameDLL();
    94 	const char *GetGameBinaryPath();
    95 	const char *GetPluginsFile();
    96 	const char *GetVDFDir();
    97 	void UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand);
    98 	void NotifyVSPListening(IServerPluginCallbacks *callbacks, int version);
    99 	void SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded);
   100 	void SetVSPListener(const char *path);
   101 	size_t GetFullPluginPath(const char *plugin, char *buffer, size_t len);
   102 };
   103 
   104 bool
   105 mm_DetectGameInformation();
   106 
   107 void
   108 mm_LogMessage(const char *msg, ...);
   109 
   110 int
   111 mm_LoadPlugins(const char *filepath, const char *vdfpath);
   112 
   113 void
   114 mm_InitializeForLoad();
   115 
   116 void
   117 mm_InitializeGlobals(CreateInterfaceFn engineFactory, 
   118 					 CreateInterfaceFn physicsFactory,
   119 					 CreateInterfaceFn filesystemFactory,
   120 					 CGlobalVars *pGlobals);
   121 void
   122 mm_StartupMetamod(bool is_vsp_load);
   123 
   124 void
   125 mm_UnloadMetamod();
   126 
   127 bool
   128 mm_IsVspBridged();
   129 
   130 bool
   131 mm_IsVspLoadComplete();
   132 
   133 extern MetamodSource g_Metamod;
   134 extern SourceHook::Impl::CSourceHookImpl g_SourceHook;
   135 
   136 #endif //_INCLUDE_SOURCEMM_H
   137