core/metamod.h
author Asher Baker <asherkin@gmail.com>
Sun May 27 02:16:08 2012 +0100 (2012-05-27)
changeset 783 ba8cd35102b1
parent 714 966f819588a2
child 778 faee01f77160
permissions -rw-r--r--
Added META_NO_HL2SDK define to stop MM:S headers using the HL2SDK (bug 5079, r=dvander).
     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 <string>
    35 #include <interface.h>
    36 #include <eiface.h>
    37 #include <sourcehook/sourcehook_impl.h>
    38 #include <sourcehook/sourcehook_hookmangen.h>
    39 #include <sourcehook/sourcehook.h>
    40 #include <ISmmPlugin.h>
    41 #include "metamod_provider.h"
    42 #include <metamod_version.h>
    43 
    44 using namespace SourceMM;
    45 
    46 /**
    47  * Versioning
    48  *   increase api_major when API breaks
    49  *   increase api_minor when new functions are added (non-breaking)
    50  */
    51 #define SOURCEMM_VERSION	SVN_FILE_VERSION_STRING
    52 #define SOURCEMM_DATE		__DATE__
    53 #define METAMOD_API_MAJOR	2		/* increase this on a breaking change */
    54 #define METAMOD_API_MINOR	0		/* increase this on a non-breaking API change */
    55 
    56 class MetamodSource : public ISmmAPI
    57 {
    58 public:
    59 	void LogMsg(ISmmPlugin *pl, const char *msg, ...);
    60 	CreateInterfaceFn GetEngineFactory(bool syn=true);
    61 	CreateInterfaceFn GetPhysicsFactory(bool syn=true);
    62 	CreateInterfaceFn GetFileSystemFactory(bool syn=true);
    63 	CreateInterfaceFn GetServerFactory(bool syn=true);
    64 	CGlobalVars *GetCGlobals();
    65 	void SetLastMetaReturn(META_RES res);
    66 	META_RES GetLastMetaReturn();
    67 	IConCommandBaseAccessor *GetCvarBaseAccessor();
    68 	bool RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand);
    69 	void UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand);
    70 	void ConPrint(const char *str);
    71 	void ConPrintf(const char *fmt, ...);
    72 	bool RemotePrintingAvailable();
    73 	void GetApiVersions(int &major, int &minor, int &plvers, int &plmin);
    74 	void GetShVersions(int &shvers, int &shimpl);
    75 	void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener);
    76 	void *MetaFactory(const char *iface, int *ret, PluginId *id);
    77 	int FormatIface(char iface[], unsigned int maxlength);
    78 	void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret);
    79 	const char *GetBaseDir();
    80 	size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);
    81 	void ClientConPrintf(edict_t *client, const char *fmt, ...);
    82 	void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1);
    83 	void EnableVSPListener();
    84 	int GetGameDLLVersion();
    85 	int GetUserMessageCount();
    86 	int FindUserMessage(const char *name, int *size=NULL);
    87 	const char *GetUserMessage(int index, int *size=NULL);
    88 	int GetVSPVersion();
    89 	int GetSourceEngineBuild();
    90 	IServerPluginCallbacks *GetVSPInfo(int *pVersion);
    91 	size_t Format(char *buffer, size_t maxlength, const char *format, ...);
    92 	size_t FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap);
    93 public:
    94 	bool IsLoadedAsGameDLL();
    95 	const char *GetGameBinaryPath();
    96 	const char *GetPluginsFile();
    97 	const char *GetVDFDir();
    98 	void UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand);
    99 	void NotifyVSPListening(IServerPluginCallbacks *callbacks, int version);
   100 	void SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded);
   101 	void SetVSPListener(const char *path);
   102 	size_t GetFullPluginPath(const char *plugin, char *buffer, size_t len);
   103 };
   104 
   105 bool
   106 mm_DetectGameInformation();
   107 
   108 void
   109 mm_LogMessage(const char *msg, ...);
   110 
   111 int
   112 mm_LoadPlugins(const char *filepath, const char *vdfpath);
   113 
   114 void
   115 mm_InitializeForLoad();
   116 
   117 void
   118 mm_InitializeGlobals(CreateInterfaceFn engineFactory, 
   119 					 CreateInterfaceFn physicsFactory,
   120 					 CreateInterfaceFn filesystemFactory,
   121 					 CGlobalVars *pGlobals);
   122 void
   123 mm_StartupMetamod(bool is_vsp_load);
   124 
   125 void
   126 mm_UnloadMetamod();
   127 
   128 bool
   129 mm_IsVspBridged();
   130 
   131 bool
   132 mm_IsVspLoadComplete();
   133 
   134 extern MetamodSource g_Metamod;
   135 extern SourceHook::Impl::CSourceHookImpl g_SourceHook;
   136 
   137 #endif //_INCLUDE_SOURCEMM_H
   138