core/metamod.h
author Scott Ehlert <ds@alliedmods.net>
Mon Nov 17 00:57:17 2008 -0600 (2008-11-17)
changeset 557 0a8ad2b12708
parent 552 4b73ffd6e176
child 558 0ed2a4a6e31d
permissions -rw-r--r--
Added Windows support for loader, core, and core-legacy
     1 /**
     2  * vim: set ts=4 :
     3  * ======================================================
     4  * Metamod:Source
     5  * Copyright (C) 2004-2008 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  * Version: $Id$
    26  */
    27 
    28 #ifndef _INCLUDE_SOURCEMM_H
    29 #define _INCLUDE_SOURCEMM_H
    30 
    31 /**
    32  * @brief SourceMM main functionality for GameDLL interception
    33  * @file sourcemm.h
    34  */
    35 
    36 #include <string>
    37 #include <interface.h>
    38 #include <eiface.h>
    39 #include <sourcehook/sourcehook_impl.h>
    40 #include <sourcehook/sourcehook_hookmangen.h>
    41 #include <sourcehook/sourcehook.h>
    42 #include <ISmmPlugin.h>
    43 #include "metamod_provider.h"
    44 #include "svn_version.h"
    45 
    46 using namespace SourceMM;
    47 
    48 /**
    49  * Versioning
    50  *   increase api_major when API breaks
    51  *   increase api_minor when new functions are added (non-breaking)
    52  */
    53 #define SOURCEMM_VERSION	SVN_FILE_VERSION_STRING
    54 #define SOURCEMM_DATE		__DATE__
    55 #define METAMOD_API_MAJOR	2		/* increase this on a breaking change */
    56 #define METAMOD_API_MINOR	0		/* increase this on a non-breaking API change */
    57 
    58 class MetamodSource : public ISmmAPI
    59 {
    60 public:
    61 	void LogMsg(ISmmPlugin *pl, const char *msg, ...);
    62 	CreateInterfaceFn GetEngineFactory(bool syn=true);
    63 	CreateInterfaceFn GetPhysicsFactory(bool syn=true);
    64 	CreateInterfaceFn GetFileSystemFactory(bool syn=true);
    65 	CreateInterfaceFn GetServerFactory(bool syn=true);
    66 	CGlobalVars *GetCGlobals();
    67 	void SetLastMetaReturn(META_RES res);
    68 	META_RES GetLastMetaReturn();
    69 	IConCommandBaseAccessor *GetCvarBaseAccessor();
    70 	bool RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand);
    71 	void UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand);
    72 	void ConPrint(const char *str);
    73 	void ConPrintf(const char *fmt, ...);
    74 	bool RemotePrintingAvailable();
    75 	void GetApiVersions(int &major, int &minor, int &plvers, int &plmin);
    76 	void GetShVersions(int &shvers, int &shimpl);
    77 	void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener);
    78 	void *MetaFactory(const char *iface, int *ret, PluginId *id);
    79 	int FormatIface(char iface[], unsigned int maxlength);
    80 	void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret);
    81 	const char *GetBaseDir();
    82 	size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);
    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 	void UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand);
   100 	void NotifyVSPListening(IServerPluginCallbacks *callbacks);
   101 	void SetGameDLLInfo(CreateInterfaceFn serverFactory, int version);
   102 };
   103 
   104 bool
   105 mm_DetectGameInformation();
   106 
   107 void
   108 mm_LogMessage(const char *msg, ...);
   109 
   110 int
   111 mm_LoadPluginsFromFile(const char *_file);
   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 void
   128 mm_SetVspInfo(IServerPluginCallbacks *ispc, unsigned int version);
   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