core/metamod.h
author Nicholas Hastings <skamonkey@gmail.com>
Wed May 21 17:26:09 2014 -0400 (2014-05-21)
changeset 917 95639ee45d3d
parent 887 e30d4a37f5e5
permissions -rw-r--r--
Trigger build for hl2sdk-l4d changes.
     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 
    42 using namespace SourceMM;
    43 
    44 /**
    45  * Versioning
    46  *   increase api_major when API breaks
    47  *   increase api_minor when new functions are added (non-breaking)
    48  */
    49 #define SOURCEMM_VERSION	SVN_FILE_VERSION_STRING
    50 #define SOURCEMM_DATE		__DATE__
    51 #define METAMOD_API_MAJOR	2		/* increase this on a breaking change */
    52 #define METAMOD_API_MINOR	0		/* increase this on a non-breaking API change */
    53 
    54 class MetamodSource : public ISmmAPI
    55 {
    56 public:
    57 	void LogMsg(ISmmPlugin *pl, const char *msg, ...);
    58 	CreateInterfaceFn GetEngineFactory(bool syn=true);
    59 	CreateInterfaceFn GetPhysicsFactory(bool syn=true);
    60 	CreateInterfaceFn GetFileSystemFactory(bool syn=true);
    61 	CreateInterfaceFn GetServerFactory(bool syn=true);
    62 	CGlobalVars *GetCGlobals();
    63 	void SetLastMetaReturn(META_RES res);
    64 	META_RES GetLastMetaReturn();
    65 	IConCommandBaseAccessor *GetCvarBaseAccessor();
    66 	bool RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand);
    67 	void UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand);
    68 	void ConPrint(const char *str);
    69 	void ConPrintf(const char *fmt, ...);
    70 	bool RemotePrintingAvailable();
    71 	void GetApiVersions(int &major, int &minor, int &plvers, int &plmin);
    72 	void GetShVersions(int &shvers, int &shimpl);
    73 	void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener);
    74 	void *MetaFactory(const char *iface, int *ret, PluginId *id);
    75 	int FormatIface(char iface[], unsigned int maxlength);
    76 	void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret);
    77 	const char *GetBaseDir();
    78 	size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);
    79 #if SOURCE_ENGINE == SE_DOTA
    80 	// Shim
    81 	void ClientConPrintf(int clientIndex, const char *fmt, ...);
    82 #endif
    83 	void ClientConPrintf(edict_t *client, const char *fmt, ...);
    84 	void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1);
    85 	void EnableVSPListener();
    86 	int GetGameDLLVersion();
    87 	int GetUserMessageCount();
    88 	int FindUserMessage(const char *name, int *size=NULL);
    89 	const char *GetUserMessage(int index, int *size=NULL);
    90 	int GetVSPVersion();
    91 	int GetSourceEngineBuild();
    92 	IServerPluginCallbacks *GetVSPInfo(int *pVersion);
    93 	size_t Format(char *buffer, size_t maxlength, const char *format, ...);
    94 	size_t FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap);
    95 public:
    96 	bool IsLoadedAsGameDLL();
    97 	const char *GetGameBinaryPath();
    98 	const char *GetPluginsFile();
    99 	const char *GetVDFDir();
   100 	void UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand);
   101 	void NotifyVSPListening(IServerPluginCallbacks *callbacks, int version);
   102 	void SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded);
   103 	void SetVSPListener(const char *path);
   104 	size_t GetFullPluginPath(const char *plugin, char *buffer, size_t len);
   105 };
   106 
   107 bool
   108 mm_DetectGameInformation();
   109 
   110 void
   111 mm_LogMessage(const char *msg, ...);
   112 
   113 int
   114 mm_LoadPlugins(const char *filepath, const char *vdfpath);
   115 
   116 void
   117 mm_InitializeForLoad();
   118 
   119 void
   120 mm_InitializeGlobals(CreateInterfaceFn engineFactory, 
   121 					 CreateInterfaceFn physicsFactory,
   122 					 CreateInterfaceFn filesystemFactory,
   123 					 CGlobalVars *pGlobals);
   124 void
   125 mm_StartupMetamod(bool is_vsp_load);
   126 
   127 void
   128 mm_UnloadMetamod();
   129 
   130 bool
   131 mm_IsVspBridged();
   132 
   133 bool
   134 mm_IsVspLoadComplete();
   135 
   136 extern MetamodSource g_Metamod;
   137 extern SourceHook::Impl::CSourceHookImpl g_SourceHook;
   138 
   139 #endif //_INCLUDE_SOURCEMM_H
   140