core-legacy/CSmmAPI.h
author Scott Ehlert <ds@alliedmods.net>
Thu Dec 10 00:59:50 2009 -0600 (2009-12-10)
changeset 689 4065ba5e9155
parent 667 938f7325d919
child 714 966f819588a2
permissions -rw-r--r--
Rewrote user message caching code to always use IServerGameDLL::GetUserMessageInfo (bug 4117, r=dvander).

Games where the above function can crash are handled by detouring tier0's Error() function and jumping back to our own code. So in theory this should work on all games now.
     1 /* ======== SourceMM ========
     2  * Copyright (C) 2004-2009 Metamod:Source Development Team
     3  * No warranties of any kind
     4  *
     5  * License: zlib/libpng
     6  *
     7  * Author(s): David "BAILOPAN" Anderson
     8  * ============================
     9  */
    10 
    11 #ifndef _INCLUDE_CSMM_API_H
    12 #define _INCLUDE_CSMM_API_H
    13 
    14 /**
    15  * @brief Header for CSmmAPI implementation
    16  * @file CSmmAPI.h
    17  */
    18 
    19 #include "ISmmAPI.h"
    20 
    21 typedef void (*CONPRINTF_FUNC)(const char *, ...);
    22 
    23 namespace SourceMM
    24 {
    25 	class CSmmAPI : public ISmmAPI
    26 	{
    27 	public:
    28 		CSmmAPI();
    29 	public:
    30 		void LogMsg(ISmmPlugin *pl, const char *msg, ...);
    31 	public:
    32 		CreateInterfaceFn engineFactory(bool syn=true);
    33 		CreateInterfaceFn physicsFactory(bool syn=true);
    34 		CreateInterfaceFn fileSystemFactory(bool syn=true);
    35 		CreateInterfaceFn serverFactory(bool syn=true);
    36 		CGlobalVars *pGlobals();
    37 		void SetLastMetaReturn(META_RES res);
    38 		META_RES GetLastMetaReturn();
    39 		IConCommandBaseAccessor *GetCvarBaseAccessor();
    40 		bool RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand);
    41 		void UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand);
    42 		void ConPrint(const char *fmt);
    43 		void ConPrintf(const char *fmt, ...);
    44 		bool RemotePrintingAvailable()
    45 		{
    46 			return CmdCacheSuccessful();
    47 		}
    48 		virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin);
    49 		virtual void GetShVersions(int &shvers, int &shimpl);
    50 		virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener);
    51 		virtual void *MetaFactory(const char *iface, int *ret, PluginId *id);
    52 		virtual int FormatIface(char buffer[], unsigned int maxlength);
    53 		virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret);
    54 		virtual const char *GetBaseDir();
    55 		virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...);
    56 		virtual IServerPluginCallbacks *GetVSPInfo(int *pVersion);
    57 		void ClientConPrintf(edict_t *client, const char *fmt, ...);
    58 		void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1);
    59 		void EnableVSPListener();
    60 		int GetGameDLLVersion();
    61 		int GetUserMessageCount();
    62 		int FindUserMessage(const char *name, int *size=NULL);
    63 		const char *GetUserMessage(int index, int *size=NULL);
    64 		int GetSourceEngineBuild();
    65 	public:
    66 		bool CacheCmds();
    67 		bool CmdCacheSuccessful();
    68 		void LoadAsVSP();
    69 		bool VSPEnabled()
    70 		{
    71 			return m_VSP;
    72 		}
    73 		void CacheUserMessages();
    74 	private:
    75 		META_RES m_Res;
    76 		CONPRINTF_FUNC m_ConPrintf;
    77 		bool m_CmdCache;
    78 		bool m_VSP;
    79 	};
    80 };
    81 
    82 extern SourceMM::CSmmAPI g_SmmAPI;
    83 
    84 #define	CONMSG			g_SmmAPI.ConPrintf
    85 #define CLIENT_CONMSG	g_SmmAPI.ClientConPrintf
    86 
    87 #endif //_INCLUDE_CSMM_API_H