initial import of the provider layout for ep1 sourcemm-1.6.0
authorDavid Anderson <dvander@alliedmods.net>
Thu Sep 27 19:28:30 2007 +0000 (2007-09-27)
branchsourcemm-1.6.0
changeset 3571319b9ef1c8a
parent 356 bbcf8dcb2aa7
child 358 a4de8673bdbd
initial import of the provider layout for ep1
providers/Makefile.ep1
providers/episode1/console.cpp
providers/episode1/console.h
providers/episode1/convar_smm.h
providers/episode1/provider_ep1.cpp
providers/episode1/provider_ep1.h
providers/provider_util.cpp
providers/provider_util.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/providers/Makefile.ep1	Thu Sep 27 19:28:30 2007 +0000
     1.3 @@ -0,0 +1,70 @@
     1.4 +#(C)2004-2007 SourceMM Development Team
     1.5 +# Makefile written by David "BAILOPAN" Anderson
     1.6 +
     1.7 +HL2SDK = ../../../hl2sdk
     1.8 +SMM_ROOT = ..
     1.9 +SRCDS = ~/srcds
    1.10 +
    1.11 +### EDIT BELOW FOR OTHER PROJECTS ###
    1.12 +
    1.13 +OPT_FLAGS = -O2 -funroll-loops -s -pipe
    1.14 +GCC4_FLAGS = -fvisibility=hidden -fvisibility-inlines-hidden
    1.15 +DEBUG_FLAGS = -g -ggdb3
    1.16 +CPP = gcc-4.1
    1.17 +BINARY = provider_ep1_i486.so
    1.18 +
    1.19 +HL2PUB = $(HL2SDK)/public
    1.20 +HL2LIB = $(HL2SDK)/linux_sdk
    1.21 +
    1.22 +OBJECTS = provider_util.cpp episode1/provider_ep1.cpp episode1/console.cpp
    1.23 +
    1.24 +LINK = $(HL2LIB)/tier1_i486.a  vstdlib_i486.so tier0_i486.so -static-libgcc
    1.25 +
    1.26 +INCLUDE = -I. -I$(HL2PUB) -I$(HL2PUB)/dlls -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 \
    1.27 +          -I$(HL2PUB)/vstdlib -I$(HL2SDK)/tier1 -I$(SMM_ROOT) -I$(SMM_ROOT)/sourcehook \
    1.28 +		  -I$(SMM_ROOT)/sourcemm
    1.29 +
    1.30 +ifeq "$(DEBUG)" "true"
    1.31 +	BIN_DIR = Debug
    1.32 +	CFLAGS = $(DEBUG_FLAGS)
    1.33 +else
    1.34 +	BIN_DIR = Release
    1.35 +	CFLAGS = $(OPT_FLAGS)
    1.36 +endif
    1.37 +
    1.38 +GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1)
    1.39 +
    1.40 +CFLAGS += -D_LINUX -DNDEBUG -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Wno-non-virtual-dtor -Werror -fPIC -fno-exceptions -fno-rtti -msse
    1.41 +
    1.42 +ifeq "$(GCC_VERSION)" "4"
    1.43 +	CFLAGS += $(GCC4_FLAGS)
    1.44 +endif
    1.45 +
    1.46 +OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
    1.47 +
    1.48 +$(BIN_DIR)/%.o: %.cpp
    1.49 +	$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $<
    1.50 +
    1.51 +all:
    1.52 +	mkdir -p $(BIN_DIR)
    1.53 +	mkdir -p $(BIN_DIR)/episode1
    1.54 +	ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so
    1.55 +	ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so
    1.56 +	$(MAKE) -f Makefile.ep1 provider
    1.57 +	rm -rf $(BINARY)
    1.58 +
    1.59 +provider: $(OBJ_LINUX)
    1.60 +	$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
    1.61 +
    1.62 +debug:	
    1.63 +	$(MAKE) -f Makefile.ep1 all DEBUG=true
    1.64 +
    1.65 +default: all
    1.66 +
    1.67 +clean:
    1.68 +	rm -rf Release/episode1/*.o
    1.69 +	rm -rf Release/*.o
    1.70 +	rm -rf Release/$(BINARY)
    1.71 +	rm -rf Debug/episode1/*.o
    1.72 +	rm -rf Debug/*.o
    1.73 +	rm -rf Debug/$(BINARY)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/providers/episode1/console.cpp	Thu Sep 27 19:28:30 2007 +0000
     2.3 @@ -0,0 +1,111 @@
     2.4 +#include "console.h"
     2.5 +#include "provider_ep1.h"
     2.6 +
     2.7 +using namespace SourceHook;
     2.8 +
     2.9 +SMConVarAccessor g_SMConVarAccessor;
    2.10 +
    2.11 +class CAlwaysRegisterableCommand : public ConCommandBase
    2.12 +{
    2.13 +public:
    2.14 +	CAlwaysRegisterableCommand()
    2.15 +	{
    2.16 +		Create("metamod_eternal", NULL, FCVAR_UNREGISTERED|FCVAR_GAMEDLL);
    2.17 +	}
    2.18 +	bool IsRegistered( void ) const
    2.19 +	{
    2.20 +		return false;
    2.21 +	}
    2.22 +	void BringToFront()
    2.23 +	{
    2.24 +		// First, let's try to find us!
    2.25 +		ConCommandBase *pPtr = icvar->GetCommands();
    2.26 +	
    2.27 +		if (pPtr == this)
    2.28 +		{
    2.29 +			// We are already at the beginning; Nothing to do
    2.30 +			return;
    2.31 +		}
    2.32 +	
    2.33 +		while (pPtr)
    2.34 +		{
    2.35 +			if (pPtr == this)
    2.36 +			{
    2.37 +				break;
    2.38 +			}
    2.39 +			ConCommandBase *pPrev = NULL;
    2.40 +			while (pPtr)
    2.41 +			{
    2.42 +				if (pPtr == this)
    2.43 +				{
    2.44 +					break;
    2.45 +				}
    2.46 +				pPrev = pPtr;
    2.47 +				pPtr = const_cast<ConCommandBase*>(pPtr->GetNext());
    2.48 +			}
    2.49 +			if (pPrev && pPtr == this)
    2.50 +			{
    2.51 +				pPrev->SetNext(m_pNext);		// Remove us from the list
    2.52 +			}
    2.53 +			// Now, register us
    2.54 +			SetNext(NULL);
    2.55 +			icvar->RegisterConCommandBase(this);
    2.56 +		}	
    2.57 +	}
    2.58 +} s_EternalCommand;
    2.59 +
    2.60 +bool SMConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand)
    2.61 +{
    2.62 +	m_RegisteredCommands.push_back(pCommand);
    2.63 +	pCommand->SetNext(NULL);
    2.64 +	icvar->RegisterConCommandBase(pCommand);
    2.65 +
    2.66 +	return true;
    2.67 +}
    2.68 +
    2.69 +bool SMConVarAccessor::Register(ConCommandBase *pCommand)
    2.70 +{
    2.71 +	pCommand->SetNext(NULL);
    2.72 +	icvar->RegisterConCommandBase(pCommand);
    2.73 +
    2.74 +	return true;
    2.75 +}
    2.76 +
    2.77 +void SMConVarAccessor::MarkCommandsAsGameDLL()
    2.78 +{
    2.79 +	for (List<ConCommandBase*>::iterator iter = m_RegisteredCommands.begin();
    2.80 +		iter != m_RegisteredCommands.end(); ++iter)
    2.81 +	{
    2.82 +		(*iter)->AddFlags(FCVAR_GAMEDLL);
    2.83 +	}
    2.84 +}
    2.85 +
    2.86 +void SMConVarAccessor::Unregister(ConCommandBase *pCommand)
    2.87 +{
    2.88 +	ConCommandBase *ptr = icvar->GetCommands();
    2.89 +
    2.90 +	if (ptr == pCommand)
    2.91 +	{
    2.92 +		s_EternalCommand.BringToFront();
    2.93 +		s_EternalCommand.SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
    2.94 +	}
    2.95 +	else
    2.96 +	{
    2.97 +		/* Find us and unregister us */
    2.98 +		ConCommandBase *pPrev = NULL;
    2.99 +		while (ptr)
   2.100 +		{
   2.101 +			if (ptr == pCommand)
   2.102 +			{
   2.103 +				break;
   2.104 +			}
   2.105 +			pPrev = ptr;
   2.106 +			ptr = const_cast<ConCommandBase *>(ptr->GetNext());
   2.107 +		}
   2.108 +		if (pPrev && ptr == pCommand)
   2.109 +		{
   2.110 +			pPrev->SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
   2.111 +		}		
   2.112 +	}
   2.113 +}
   2.114 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/providers/episode1/console.h	Thu Sep 27 19:28:30 2007 +0000
     3.3 @@ -0,0 +1,24 @@
     3.4 +#ifndef _INCLUDE_CONSOLE_MMS_H_
     3.5 +#define _INCLUDE_CONSOLE_MMS_H_
     3.6 +
     3.7 +#include "convar_smm.h"
     3.8 +#include <interface.h>
     3.9 +#include <eiface.h>
    3.10 +#include <sh_list.h>
    3.11 +
    3.12 +class SMConVarAccessor : public IConCommandBaseAccessor
    3.13 +{
    3.14 +public:
    3.15 +	bool RegisterConCommandBase(ConCommandBase *pCommand);
    3.16 +	bool Register(ConCommandBase *pCommand);
    3.17 +	void MarkCommandsAsGameDLL();
    3.18 +	void Unregister(ConCommandBase *pCommand);
    3.19 +	void UnregisterGameDLLCommands();
    3.20 +private:
    3.21 +	SourceHook::List<ConCommandBase*> m_RegisteredCommands;
    3.22 +};
    3.23 +
    3.24 +extern SMConVarAccessor g_SMConVarAccessor;
    3.25 +
    3.26 +#endif //_INCLUDE_CONSOLE_MMS_H_
    3.27 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/providers/episode1/convar_smm.h	Thu Sep 27 19:28:30 2007 +0000
     4.3 @@ -0,0 +1,523 @@
     4.4 +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
     4.5 +//
     4.6 +// Purpose: 
     4.7 +//
     4.8 +// $Workfile:     $
     4.9 +// $Date: 2007-02-08 04:19:19 -0500 (Thu, 08 Feb 2007) $
    4.10 +//
    4.11 +//-----------------------------------------------------------------------------
    4.12 +// $NoKeywords: $
    4.13 +//=============================================================================//
    4.14 +
    4.15 +#ifndef CONVAR_H
    4.16 +#define CONVAR_H
    4.17 +#if _WIN32
    4.18 +#pragma once
    4.19 +#endif
    4.20 +
    4.21 +#include "tier0/dbg.h"
    4.22 +
    4.23 +#ifdef _WIN32
    4.24 +#define FORCEINLINE_CVAR FORCEINLINE
    4.25 +#elif _LINUX
    4.26 +#define FORCEINLINE_CVAR __inline__ FORCEINLINE
    4.27 +#else
    4.28 +#error "implement me"
    4.29 +#endif
    4.30 +
    4.31 +// The default, no flags at all
    4.32 +#define FCVAR_NONE				0 
    4.33 +
    4.34 +// Command to ConVars and ConCommands
    4.35 +// ConVar Systems
    4.36 +#define FCVAR_UNREGISTERED		(1<<0)	// If this is set, don't add to linked list, etc.
    4.37 +#define FCVAR_LAUNCHER			(1<<1)	// defined by launcher
    4.38 +#define FCVAR_GAMEDLL			(1<<2)	// defined by the game DLL
    4.39 +#define FCVAR_CLIENTDLL			(1<<3)  // defined by the client DLL
    4.40 +#define FCVAR_MATERIAL_SYSTEM	(1<<4)	// Defined by the material system.
    4.41 +#define FCVAR_DATACACHE			(1<<19)	// Defined by the datacache system.
    4.42 +#define FCVAR_STUDIORENDER		(1<<15)	// Defined by the studiorender system.
    4.43 +#define FCVAR_FILESYSTEM		(1<<21)	// Defined by the file system.
    4.44 +#define FCVAR_PLUGIN			(1<<18)	// Defined by a 3rd party plugin.
    4.45 +#define FCVAR_TOOLSYSTEM		(1<<20)	// Defined by an IToolSystem library
    4.46 +#define FCVAR_SOUNDSYSTEM		(1<<23)	// Defined by the soundsystem library
    4.47 +#define FCVAR_INPUTSYSTEM		(1<<25)	// Defined by the inputsystem dll
    4.48 +#define FCVAR_NETWORKSYSTEM		(1<<26) // Defined by the network system
    4.49 +// NOTE!! if you add a cvar system, add it here too!!!!
    4.50 +// the engine lacks a cvar flag, but needs it for xbox
    4.51 +// an engine cvar is thus a cvar not marked with any other system
    4.52 +#define FCVAR_NON_ENGINE		((FCVAR_LAUNCHER|FCVAR_GAMEDLL|FCVAR_CLIENTDLL|FCVAR_MATERIAL_SYSTEM|FCVAR_DATACACHE|FCVAR_STUDIORENDER|FCVAR_FILESYSTEM|FCVAR_PLUGIN|FCVAR_TOOLSYSTEM|FCVAR_SOUNDSYSTEM|FCVAR_INPUTSYSTEM|FCVAR_NETWORKSYSTEM))
    4.53 +
    4.54 +// ConVar only
    4.55 +#define FCVAR_PROTECTED			(1<<5)  // It's a server cvar, but we don't send the data since it's a password, etc.  Sends 1 if it's not bland/zero, 0 otherwise as value
    4.56 +#define FCVAR_SPONLY			(1<<6)  // This cvar cannot be changed by clients connected to a multiplayer server.
    4.57 +#define	FCVAR_ARCHIVE			(1<<7)	// set to cause it to be saved to vars.rc
    4.58 +#define	FCVAR_NOTIFY			(1<<8)	// notifies players when changed
    4.59 +#define	FCVAR_USERINFO			(1<<9)	// changes the client's info string
    4.60 +#define FCVAR_CHEAT				(1<<14) // Only useable in singleplayer / debug / multiplayer & sv_cheats
    4.61 +
    4.62 +#define FCVAR_PRINTABLEONLY		(1<<10)  // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ).
    4.63 +#define FCVAR_UNLOGGED			(1<<11)  // If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log
    4.64 +#define FCVAR_NEVER_AS_STRING	(1<<12)  // never try to print that cvar
    4.65 +
    4.66 +// It's a ConVar that's shared between the client and the server.
    4.67 +// At signon, the values of all such ConVars are sent from the server to the client (skipped for local
    4.68 +//  client, of course )
    4.69 +// If a change is requested it must come from the console (i.e., no remote client changes)
    4.70 +// If a value is changed while a server is active, it's replicated to all connected clients
    4.71 +#define FCVAR_REPLICATED		(1<<13)	// server setting enforced on clients, TODO rename to FCAR_SERVER at some time
    4.72 +#define FCVAR_DEMO				(1<<16)  // record this cvar when starting a demo file
    4.73 +#define FCVAR_DONTRECORD		(1<<17)  // don't record these command in demofiles
    4.74 +
    4.75 +#define FCVAR_NOT_CONNECTED		(1<<22)	// cvar cannot be changed by a client that is connected to a server
    4.76 +
    4.77 +#define FCVAR_ARCHIVE_XBOX		(1<<24) // cvar written to config.cfg on the Xbox
    4.78 +
    4.79 +
    4.80 +// #define FCVAR_AVAILABLE			(1<<27)
    4.81 +// #define FCVAR_AVAILABLE			(1<<28)
    4.82 +// #define FCVAR_AVAILABLE			(1<<29)
    4.83 +// #define FCVAR_AVAILABLE			(1<<30)
    4.84 +// #define FCVAR_AVAILABLE			(1<<31)
    4.85 +
    4.86 +
    4.87 +class ConVar;
    4.88 +class ConCommand;
    4.89 +class ConCommandBase;
    4.90 +
    4.91 +// Any executable that wants to use ConVars need to implement one of
    4.92 +// these to hook up access to console variables.
    4.93 +class IConCommandBaseAccessor
    4.94 +{
    4.95 +public:
    4.96 +	// Flags is a combination of FCVAR flags in cvar.h.
    4.97 +	// hOut is filled in with a handle to the variable.
    4.98 +	virtual bool RegisterConCommandBase( ConCommandBase *pVar )=0;
    4.99 +};
   4.100 +
   4.101 +
   4.102 +// You don't have to instantiate one of these, just call its 
   4.103 +// OneTimeInit function when your executable is initializing.
   4.104 +class ConCommandBaseMgr
   4.105 +{
   4.106 +public:
   4.107 +	// Call this ONCE when the executable starts up.
   4.108 +	static void	OneTimeInit( IConCommandBaseAccessor *pAccessor );
   4.109 +#ifdef _XBOX
   4.110 +	static bool Fixup( ConCommandBase* pConCommandBase );
   4.111 +#ifndef _RETAIL
   4.112 +	static void PublishCommands( bool bForce );
   4.113 +#endif
   4.114 +#endif
   4.115 +};
   4.116 +
   4.117 +// Called when a ConVar changes value
   4.118 +typedef void ( *FnChangeCallback )( ConVar *var, char const *pOldString );
   4.119 +
   4.120 +// Called when a ConCommand needs to execute
   4.121 +typedef void ( *FnCommandCallback )( void );
   4.122 +
   4.123 +#define COMMAND_COMPLETION_MAXITEMS		64
   4.124 +#define COMMAND_COMPLETION_ITEM_LENGTH	64
   4.125 +
   4.126 +// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
   4.127 +typedef int  ( *FnCommandCompletionCallback )( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
   4.128 +
   4.129 +//-----------------------------------------------------------------------------
   4.130 +// Purpose: The base console invoked command/cvar interface
   4.131 +//-----------------------------------------------------------------------------
   4.132 +class ConCommandBase
   4.133 +{
   4.134 +	friend class ConCommandBaseMgr;
   4.135 +	friend class CCvar;
   4.136 +	friend class ConVar;
   4.137 +	friend class ConCommand;
   4.138 +
   4.139 +public:
   4.140 +								ConCommandBase( void );
   4.141 +								ConCommandBase( char const *pName, char const *pHelpString = 0, 
   4.142 +									int flags = 0 );
   4.143 +
   4.144 +	virtual						~ConCommandBase( void );
   4.145 +
   4.146 +	virtual	bool				IsCommand( void ) const;
   4.147 +
   4.148 +	// Check flag
   4.149 +	virtual bool				IsBitSet( int flag ) const;
   4.150 +	// Set flag
   4.151 +	virtual void				AddFlags( int flags );
   4.152 +
   4.153 +	// Return name of cvar
   4.154 +	virtual char const			*GetName( void ) const;
   4.155 +
   4.156 +	// Return help text for cvar
   4.157 +	virtual char const			*GetHelpText( void ) const;
   4.158 +
   4.159 +	// Deal with next pointer
   4.160 +	const ConCommandBase		*GetNext( void ) const;
   4.161 +	void						SetNext( ConCommandBase *next );
   4.162 +	
   4.163 +	virtual bool				IsRegistered( void ) const;
   4.164 +
   4.165 +	// Global methods
   4.166 +	static ConCommandBase const	*GetCommands( void );
   4.167 +	static void					AddToList( ConCommandBase *var );
   4.168 +	static void					RemoveFlaggedCommands( int flag );
   4.169 +	static void					RevertFlaggedCvars( int flag );
   4.170 +	static ConCommandBase const	*FindCommand( char const *name );
   4.171 +
   4.172 +protected:
   4.173 +	virtual void				Create( char const *pName, char const *pHelpString = 0, 
   4.174 +									int flags = 0 );
   4.175 +
   4.176 +	// Used internally by OneTimeInit to initialize.
   4.177 +	virtual void				Init();
   4.178 +
   4.179 +	// Internal copy routine ( uses new operator from correct module )
   4.180 +	char						*CopyString( char const *from );
   4.181 +
   4.182 +	// Next ConVar in chain
   4.183 +	ConCommandBase				*m_pNext;
   4.184 +
   4.185 +private:
   4.186 +	// Has the cvar been added to the global list?
   4.187 +	bool						m_bRegistered;
   4.188 +
   4.189 +	// Static data
   4.190 +	char const 					*m_pszName;
   4.191 +	char const 					*m_pszHelpString;
   4.192 +	
   4.193 +	// ConVar flags
   4.194 +	int							m_nFlags;
   4.195 +
   4.196 +protected:
   4.197 +
   4.198 +	// ConVars add themselves to this list for the executable. Then ConVarMgr::Init() runs through 
   4.199 +	// all the console variables and registers them.
   4.200 +	static ConCommandBase		*s_pConCommandBases;
   4.201 +
   4.202 +	// ConVars in this executable use this 'global' to access values.
   4.203 +	static IConCommandBaseAccessor	*s_pAccessor;
   4.204 +};
   4.205 +
   4.206 +//-----------------------------------------------------------------------------
   4.207 +// Purpose: The console invoked command
   4.208 +//-----------------------------------------------------------------------------
   4.209 +class ConCommand : public ConCommandBase
   4.210 +{
   4.211 +friend class ConCommandBaseMgr;
   4.212 +friend class CCvar;
   4.213 +#ifdef _STATIC_LINKED
   4.214 +friend class G_ConCommand;
   4.215 +friend class C_ConCommand;
   4.216 +friend class M_ConCommand;
   4.217 +friend class S_ConCommand;
   4.218 +friend class D_ConCommand;
   4.219 +#endif
   4.220 +
   4.221 +public:
   4.222 +	typedef ConCommandBase BaseClass;
   4.223 +
   4.224 +								ConCommand( void );
   4.225 +								ConCommand( char const *pName, FnCommandCallback callback, 
   4.226 +									char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
   4.227 +
   4.228 +	virtual						~ConCommand( void );
   4.229 +
   4.230 +	virtual	bool				IsCommand( void ) const;
   4.231 +
   4.232 +	virtual int					AutoCompleteSuggest( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
   4.233 +
   4.234 +	virtual bool				CanAutoComplete( void );
   4.235 +
   4.236 +	// Invoke the function
   4.237 +	virtual void				Dispatch( void );
   4.238 +private:
   4.239 +	virtual void				Create( char const *pName, FnCommandCallback callback, 
   4.240 +									char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
   4.241 +
   4.242 +	// Call this function when executing the command
   4.243 +	FnCommandCallback			m_fnCommandCallback;
   4.244 +
   4.245 +	FnCommandCompletionCallback	m_fnCompletionCallback;
   4.246 +	bool						m_bHasCompletionCallback;
   4.247 +public:
   4.248 +	FnCommandCallback			GetCallback() { return m_fnCommandCallback; }
   4.249 +};
   4.250 +
   4.251 +//-----------------------------------------------------------------------------
   4.252 +// Purpose: A console variable
   4.253 +//-----------------------------------------------------------------------------
   4.254 +class ConVar : public ConCommandBase
   4.255 +{
   4.256 +friend class ConCommandBaseMgr;
   4.257 +friend class CCvar;
   4.258 +friend class CDefaultCvar;
   4.259 +#ifdef _STATIC_LINKED
   4.260 +friend class G_ConVar;
   4.261 +friend class C_ConVar;
   4.262 +friend class M_ConVar;
   4.263 +friend class S_ConVar;
   4.264 +friend class D_ConVar;
   4.265 +#endif
   4.266 +
   4.267 +public:
   4.268 +	typedef ConCommandBase BaseClass;
   4.269 +
   4.270 +								ConVar( char const *pName, char const *pDefaultValue, int flags = 0);
   4.271 +
   4.272 +								ConVar( char const *pName, char const *pDefaultValue, int flags, 
   4.273 +									char const *pHelpString );
   4.274 +								ConVar( char const *pName, char const *pDefaultValue, int flags, 
   4.275 +									char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax );
   4.276 +								ConVar( char const *pName, char const *pDefaultValue, int flags, 
   4.277 +									char const *pHelpString, FnChangeCallback callback );
   4.278 +								ConVar( char const *pName, char const *pDefaultValue, int flags, 
   4.279 +									char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax,
   4.280 +									FnChangeCallback callback );
   4.281 +
   4.282 +	virtual						~ConVar( void );
   4.283 +
   4.284 +	virtual bool				IsBitSet( int flag ) const;
   4.285 +	virtual char const*			GetHelpText( void ) const;
   4.286 +	virtual bool				IsRegistered( void ) const;
   4.287 +	virtual char const			*GetName( void ) const;
   4.288 +	virtual void				AddFlags( int flags );
   4.289 +	virtual	bool				IsCommand( void ) const;
   4.290 +
   4.291 +	// Install a change callback (there shouldn't already be one....)
   4.292 +	void InstallChangeCallback( FnChangeCallback callback );
   4.293 +
   4.294 +	// Retrieve value
   4.295 +	FORCEINLINE_CVAR float			GetFloat( void ) const;
   4.296 +	FORCEINLINE_CVAR int				GetInt( void ) const;
   4.297 +	FORCEINLINE_CVAR bool			GetBool() const {  return !!GetInt(); }
   4.298 +	FORCEINLINE_CVAR char const	   *GetString( void ) const;
   4.299 +
   4.300 +	// Any function that allocates/frees memory needs to be virtual or else you'll have crashes
   4.301 +	//  from alloc/free across dll/exe boundaries.
   4.302 +	
   4.303 +	// These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
   4.304 +	virtual void				SetValue( char const *value );
   4.305 +	virtual void				SetValue( float value );
   4.306 +	virtual void				SetValue( int value );
   4.307 +	
   4.308 +	// Reset to default value
   4.309 +	void						Revert( void );
   4.310 +
   4.311 +	// True if it has a min/max setting
   4.312 +	bool						GetMin( float& minVal ) const;
   4.313 +	bool						GetMax( float& maxVal ) const;
   4.314 +	char const					*GetDefault( void ) const;
   4.315 +
   4.316 +	static void					RevertAll( void );
   4.317 +private:
   4.318 +	// Called by CCvar when the value of a var is changing.
   4.319 +	virtual void				InternalSetValue(char const *value);
   4.320 +	// For CVARs marked FCVAR_NEVER_AS_STRING
   4.321 +	virtual void				InternalSetFloatValue( float fNewValue );
   4.322 +	virtual void				InternalSetIntValue( int nValue );
   4.323 +
   4.324 +	virtual bool				ClampValue( float& value );
   4.325 +	virtual void				ChangeStringValue( char const *tempVal );
   4.326 +
   4.327 +	virtual void				Create( char const *pName, char const *pDefaultValue, int flags = 0,
   4.328 +									char const *pHelpString = 0, bool bMin = false, float fMin = 0.0,
   4.329 +									bool bMax = false, float fMax = false, FnChangeCallback callback = 0 );
   4.330 +
   4.331 +	// Used internally by OneTimeInit to initialize.
   4.332 +	virtual void				Init();
   4.333 +
   4.334 +private:
   4.335 +
   4.336 +	// This either points to "this" or it points to the original declaration of a ConVar.
   4.337 +	// This allows ConVars to exist in separate modules, and they all use the first one to be declared.
   4.338 +	// m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
   4.339 +	ConVar						*m_pParent;
   4.340 +
   4.341 +	// Static data
   4.342 +	char const					*m_pszDefaultValue;
   4.343 +	
   4.344 +	// Value
   4.345 +	// Dynamically allocated
   4.346 +	char						*m_pszString;
   4.347 +	int							m_StringLength;
   4.348 +
   4.349 +	// Values
   4.350 +	float						m_fValue;
   4.351 +	int							m_nValue;
   4.352 +
   4.353 +	// Min/Max values
   4.354 +	bool						m_bHasMin;
   4.355 +	float						m_fMinVal;
   4.356 +	bool						m_bHasMax;
   4.357 +	float						m_fMaxVal;
   4.358 +	
   4.359 +	// Call this function when ConVar changes
   4.360 +	FnChangeCallback			m_fnChangeCallback;
   4.361 +};
   4.362 +
   4.363 +
   4.364 +//-----------------------------------------------------------------------------
   4.365 +// Purpose: Return ConVar value as a float
   4.366 +// Output : float
   4.367 +//-----------------------------------------------------------------------------
   4.368 +FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
   4.369 +{
   4.370 +	return m_pParent->m_fValue;
   4.371 +}
   4.372 +
   4.373 +//-----------------------------------------------------------------------------
   4.374 +// Purpose: Return ConVar value as an int
   4.375 +// Output : int
   4.376 +//-----------------------------------------------------------------------------
   4.377 +FORCEINLINE_CVAR int ConVar::GetInt( void ) const 
   4.378 +{
   4.379 +	return m_pParent->m_nValue;
   4.380 +}
   4.381 +
   4.382 +
   4.383 +//-----------------------------------------------------------------------------
   4.384 +// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
   4.385 +// Output : char const *
   4.386 +//-----------------------------------------------------------------------------
   4.387 +FORCEINLINE_CVAR char const *ConVar::GetString( void ) const 
   4.388 +{
   4.389 +	if ( m_nFlags & FCVAR_NEVER_AS_STRING )
   4.390 +	{
   4.391 +		return "FCVAR_NEVER_AS_STRING";
   4.392 +	}
   4.393 +
   4.394 +	return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : "";
   4.395 +}
   4.396 +
   4.397 +
   4.398 +#ifdef _STATIC_LINKED
   4.399 +// identifies subsystem via piggybacking constructors with flags
   4.400 +class G_ConCommand : public ConCommand
   4.401 +{
   4.402 +public:
   4.403 +	G_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) :	ConCommand(pName, callback, pHelpString, flags|FCVAR_GAMEDLL, completionFunc) {}
   4.404 +};
   4.405 +
   4.406 +class C_ConCommand : public ConCommand
   4.407 +{
   4.408 +public:
   4.409 +	C_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) :	ConCommand(pName, callback, pHelpString, flags|FCVAR_CLIENTDLL, completionFunc) {}
   4.410 +};
   4.411 +
   4.412 +class M_ConCommand : public ConCommand
   4.413 +{
   4.414 +public:
   4.415 +	M_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) :	ConCommand(pName, callback, pHelpString, flags|FCVAR_MATERIAL_SYSTEM, completionFunc) {}
   4.416 +};
   4.417 +
   4.418 +class S_ConCommand : public ConCommand
   4.419 +{
   4.420 +public:
   4.421 +	S_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) :	ConCommand(pName, callback, pHelpString, flags|FCVAR_STUDIORENDER, completionFunc) {}
   4.422 +};
   4.423 +
   4.424 +class D_ConCommand : public ConCommand
   4.425 +{
   4.426 +public:
   4.427 +	D_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) :	ConCommand(pName, callback, pHelpString, flags|FCVAR_DATACACHE, completionFunc) {}
   4.428 +};
   4.429 +
   4.430 +typedef void ( *G_FnChangeCallback )( G_ConVar *var, char const *pOldString );
   4.431 +typedef void ( *C_FnChangeCallback )( C_ConVar *var, char const *pOldString );
   4.432 +typedef void ( *M_FnChangeCallback )( M_ConVar *var, char const *pOldString );
   4.433 +typedef void ( *S_FnChangeCallback )( S_ConVar *var, char const *pOldString );
   4.434 +typedef void ( *D_FnChangeCallback )( D_ConVar *var, char const *pOldString );
   4.435 +
   4.436 +class G_ConVar : public ConVar
   4.437 +{
   4.438 +public:
   4.439 +	G_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL) {}
   4.440 +	G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString ) {}
   4.441 +	G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString, bMin, fMin, bMax, fMax) {}
   4.442 +	G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, G_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString, (FnChangeCallback)callback ) {}
   4.443 +	G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, G_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {}
   4.444 +};
   4.445 +
   4.446 +class C_ConVar : public ConVar
   4.447 +{
   4.448 +public:
   4.449 +	C_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL) {}
   4.450 +	C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString ) {}
   4.451 +	C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString, bMin, fMin, bMax, fMax) {}
   4.452 +	C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, C_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString, (FnChangeCallback)callback ) {}
   4.453 +	C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, C_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {}
   4.454 +};
   4.455 +
   4.456 +class M_ConVar : public ConVar
   4.457 +{
   4.458 +public:
   4.459 +	M_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM) {}
   4.460 +	M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString ) {}
   4.461 +	M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString, bMin, fMin, bMax, fMax) {}
   4.462 +	M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString, (FnChangeCallback)callback ) {}
   4.463 +	M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {}
   4.464 +};
   4.465 +
   4.466 +class S_ConVar : public ConVar
   4.467 +{
   4.468 +public:
   4.469 +	S_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER) {}
   4.470 +	S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString ) {}
   4.471 +	S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString, bMin, fMin, bMax, fMax) {}
   4.472 +	S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString, (FnChangeCallback)callback ) {}
   4.473 +	S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, S_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {}
   4.474 +};
   4.475 +
   4.476 +class D_ConVar : public ConVar
   4.477 +{
   4.478 +public:
   4.479 +	D_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE) {}
   4.480 +	D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString ) {}
   4.481 +	D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString, bMin, fMin, bMax, fMax) {}
   4.482 +	D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString, (FnChangeCallback)callback ) {}
   4.483 +	D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, D_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {}
   4.484 +};
   4.485 +
   4.486 +// redirect these declarations to their specific subsystem
   4.487 +#ifdef GAME_DLL
   4.488 +#define ConCommand	G_ConCommand
   4.489 +#define ConVar		G_ConVar
   4.490 +#endif
   4.491 +#ifdef CLIENT_DLL
   4.492 +#define ConCommand	C_ConCommand
   4.493 +#define ConVar		C_ConVar
   4.494 +#endif
   4.495 +#ifdef MATERIALSYSTEM_DLL
   4.496 +#define ConCommand	M_ConCommand
   4.497 +#define ConVar		M_ConVar
   4.498 +#endif
   4.499 +#ifdef STUDIORENDER_DLL
   4.500 +#define ConCommand	S_ConCommand
   4.501 +#define ConVar		S_ConVar
   4.502 +#endif
   4.503 +#ifdef DATACACHE_DLL
   4.504 +#define ConCommand	D_ConCommand
   4.505 +#define ConVar		D_ConVar
   4.506 +#endif
   4.507 +#endif // _STATIC_LINKED
   4.508 +
   4.509 +//-----------------------------------------------------------------------------
   4.510 +// Purpose: Utility to quicky generate a simple console command
   4.511 +//-----------------------------------------------------------------------------
   4.512 +#define CON_COMMAND( name, description ) \
   4.513 +   static void name(); \
   4.514 +   static ConCommand name##_command( #name, name, description ); \
   4.515 +   static void name()
   4.516 +
   4.517 +//-----------------------------------------------------------------------------
   4.518 +// Purpose: Utility to quicky generate a simple console command
   4.519 +//-----------------------------------------------------------------------------
   4.520 +#define CON_COMMAND_F( name, description, flags ) \
   4.521 +   static void name(); \
   4.522 +   static ConCommand name##_command( #name, name, description, flags ); \
   4.523 +   static void name()
   4.524 +
   4.525 +
   4.526 +#endif // CONVAR_H
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/providers/episode1/provider_ep1.cpp	Thu Sep 27 19:28:30 2007 +0000
     5.3 @@ -0,0 +1,264 @@
     5.4 +#include "convar_smm.h"
     5.5 +#include <eiface.h>
     5.6 +#include <tier0/icommandline.h>
     5.7 +#include <sourcehook/sourcehook.h>
     5.8 +#include "provider_util.h"
     5.9 +#include "provider_ep1.h"
    5.10 +#include "console.h"
    5.11 +
    5.12 +/* Types */
    5.13 +typedef void (*CONPRINTF_FUNC)(const char *, ...);
    5.14 +/* Imports */
    5.15 +#undef CommandLine
    5.16 +DLL_IMPORT ICommandLine *CommandLine();
    5.17 +/* Functions */
    5.18 +CONPRINTF_FUNC ExtractRemotePrinter();
    5.19 +/* Variables */
    5.20 +CONPRINTF_FUNC echo_msg_func = NULL;
    5.21 +IVEngineServer *engine = NULL;
    5.22 +IServerGameDLL *server = NULL;
    5.23 +ICvar *icvar = NULL;
    5.24 +
    5.25 +void BaseProvider::ConsolePrint(const char *str)
    5.26 +{
    5.27 +	if (echo_msg_func != NULL)
    5.28 +	{
    5.29 +		echo_msg_func("%s", str);
    5.30 +	}
    5.31 +	else
    5.32 +	{
    5.33 +		Msg("%s", str);
    5.34 +	}
    5.35 +}
    5.36 +
    5.37 +void BaseProvider::Notify_DLLInit_Pre()
    5.38 +{
    5.39 +	echo_msg_func = ExtractRemotePrinter();	
    5.40 +}
    5.41 +
    5.42 +bool BaseProvider::IsRemotePrintingAvailable()
    5.43 +{
    5.44 +	return (echo_msg_func != NULL);
    5.45 +}
    5.46 +
    5.47 +void BaseProvider::ClientConsolePrint(edict_t *client, const char *message)
    5.48 +{
    5.49 +	engine->ClientPrintf(client, message);
    5.50 +}
    5.51 +
    5.52 +void BaseProvider::ServerCommand(const char *cmd)
    5.53 +{
    5.54 +	engine->ServerCommand(cmd);
    5.55 +}
    5.56 +
    5.57 +const char *BaseProvider::GetConVarString(ConVar *convar)
    5.58 +{
    5.59 +	return convar->GetString();
    5.60 +}
    5.61 +
    5.62 +bool BaseProvider::IsConCommandBaseACommand(ConCommandBase *pCommand)
    5.63 +{
    5.64 +	return pCommand->IsCommand();
    5.65 +}
    5.66 +
    5.67 +
    5.68 +bool BaseProvider::IsSourceEngineBuildCompatible(int build)
    5.69 +{
    5.70 +	return (build == SOURCE_ENGINE_ORIGINAL
    5.71 +			|| build == SOURCE_ENGINE_EPISODEONE);
    5.72 +}
    5.73 +
    5.74 +const char *BaseProvider::GetCommandLineValue(const char *key, const char *defval)
    5.75 +{
    5.76 +	if (key[0] == '-' || key[0] == '+')
    5.77 +	{
    5.78 +		return CommandLine()->ParmValue(key, defval);
    5.79 +	}
    5.80 +	else
    5.81 +	{
    5.82 +		const char *val;
    5.83 +		if ((val = icvar->GetCommandLineValue(key)) == NULL)
    5.84 +		{
    5.85 +			return defval;
    5.86 +		}
    5.87 +
    5.88 +		return val;
    5.89 +	}
    5.90 +}
    5.91 +
    5.92 +int BaseProvider::TryServerGameDLL(const char *iface)
    5.93 +{
    5.94 +	if (strncmp(iface, "ServerGameDLL", 13) != 0)
    5.95 +	{
    5.96 +		return 0;
    5.97 +	}
    5.98 +
    5.99 +	return atoi(&iface[13]);
   5.100 +}
   5.101 +
   5.102 +bool BaseProvider::LogMessage(const char *buffer)
   5.103 +{
   5.104 +	if (!engine)
   5.105 +	{
   5.106 +		return false;
   5.107 +	}
   5.108 +
   5.109 +	engine->LogPrint(buffer);
   5.110 +
   5.111 +	return true;
   5.112 +}
   5.113 +
   5.114 +bool BaseProvider::GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo)
   5.115 +{
   5.116 +	SourceHook::MemFuncInfo mfi = {true, -1, 0, 0};
   5.117 +
   5.118 +	if (hook == ProvidedHook_LevelInit)
   5.119 +	{
   5.120 +		SourceHook::GetFuncInfo(&IServerGameDLL::LevelInit, mfi);
   5.121 +	}
   5.122 +	else if (hook == ProvidedHook_LevelShutdown)
   5.123 +	{
   5.124 +		SourceHook::GetFuncInfo(&IServerGameDLL::LevelShutdown, mfi);
   5.125 +	}
   5.126 +	else if (hook == ProvidedHook_GameInit)
   5.127 +	{
   5.128 +		SourceHook::GetFuncInfo(&IServerGameDLL::GameInit, mfi);
   5.129 +	}
   5.130 +	else if (hook == ProvidedHook_DLLShutdown)
   5.131 +	{
   5.132 +		SourceHook::GetFuncInfo(&IServerGameDLL::DLLShutdown, mfi);
   5.133 +	}
   5.134 +	else if (hook == ProvidedHook_DLLInit)
   5.135 +	{
   5.136 +		SourceHook::GetFuncInfo(&IServerGameDLL::DLLInit, mfi);
   5.137 +	}
   5.138 +
   5.139 +	*pInfo = mfi;
   5.140 +
   5.141 +	return (mfi.thisptroffs >= 0);
   5.142 +}
   5.143 +
   5.144 +void BaseProvider::DisplayError(const char *fmt, ...)
   5.145 +{
   5.146 +	va_list ap;
   5.147 +	char buffer[2048];
   5.148 +
   5.149 +	va_start(ap, fmt);
   5.150 +	UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
   5.151 +	va_end(ap);
   5.152 +
   5.153 +	Error(buffer);
   5.154 +}
   5.155 +
   5.156 +void BaseProvider::DisplayWarning(const char *fmt, ...)
   5.157 +{
   5.158 +	va_list ap;
   5.159 +	char buffer[2048];
   5.160 +
   5.161 +	va_start(ap, fmt);
   5.162 +	UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
   5.163 +	va_end(ap);
   5.164 +
   5.165 +	Warning(buffer);
   5.166 +}
   5.167 +
   5.168 +IConCommandBaseAccessor *BaseProvider::GetConCommandBaseAccessor()
   5.169 +{
   5.170 +	return &g_SMConVarAccessor;
   5.171 +}
   5.172 +
   5.173 +bool BaseProvider::RegisterConCommandBase(ConCommandBase *pCommand)
   5.174 +{
   5.175 +	return g_SMConVarAccessor.Register(pCommand);
   5.176 +}
   5.177 +
   5.178 +void BaseProvider::UnregisterConCommandBase(ConCommandBase *pCommand)
   5.179 +{
   5.180 +	return g_SMConVarAccessor.Unregister(pCommand);
   5.181 +}
   5.182 +
   5.183 +//////////////////////////////////////////////////////////////////////////
   5.184 +//THERE BE HAX HERE!!!! DON'T TELL ALFRED, BUT GABE WANTED IT THAT WAY. //
   5.185 +// (note: you can find the offset by looking for the text               //
   5.186 +//   "Echo text to console", you'll find the callback cmd pushed on the //
   5.187 +//   stack.)                                                            //
   5.188 +//////////////////////////////////////////////////////////////////////////
   5.189 +
   5.190 +#define SIGLEN			8
   5.191 +#define ENGINE486_SIG	"\x55\x89\xE5\x53\x83\xEC\x14\xBB"
   5.192 +#define ENGINE486_OFFS	40
   5.193 +#define ENGINE686_SIG	"\x53\x83\xEC\x08\xBB\x01\x00\x00"
   5.194 +#define ENGINE686_OFFS	50
   5.195 +#define	ENGINEAMD_SIG	"\x53\x51\xBB\x01\x00\x00\x00\x51"
   5.196 +#define	ENGINEAMD_OFFS	47
   5.197 +#define ENGINEW32_SIG	"\xA1\x2A\x2A\x2A\x2A\x56\xBE\x01"
   5.198 +#define ENGINEW32_OFFS	38
   5.199 +#define IA32_CALL		0xE8
   5.200 +
   5.201 +bool vcmp(const void *_addr1, const void *_addr2, size_t len)
   5.202 +{
   5.203 +	unsigned char *addr1 = (unsigned char *)_addr1;
   5.204 +	unsigned char *addr2 = (unsigned char *)_addr2;
   5.205 +
   5.206 +	for (size_t i=0; i<len; i++)
   5.207 +	{
   5.208 +		if (addr2[i] == '*')
   5.209 +			continue;
   5.210 +		if (addr1[i] != addr2[i])
   5.211 +			return false;
   5.212 +	}
   5.213 +
   5.214 +	return true;
   5.215 +}
   5.216 +
   5.217 +//Thanks to fysh for the idea of extracting info from "echo" and for
   5.218 +// having the original offsets at hand!
   5.219 +CONPRINTF_FUNC ExtractRemotePrinter()
   5.220 +{
   5.221 +	ConCommandBase *pBase = icvar->GetCommands();
   5.222 +	unsigned char *ptr = NULL;
   5.223 +	FnCommandCallback callback = NULL;
   5.224 +	int offs = 0;
   5.225 +
   5.226 +	while (pBase)
   5.227 +	{
   5.228 +		if ( strcmp(pBase->GetName(), "echo") == 0 )
   5.229 +		{
   5.230 +			callback = ((ConCommand *)pBase)->GetCallback();
   5.231 +			ptr = (unsigned char *)callback;
   5.232 +#ifdef OS_LINUX
   5.233 +			if (vcmp(ptr, ENGINE486_SIG, SIGLEN))
   5.234 +			{
   5.235 +				offs = ENGINE486_OFFS;
   5.236 +			}
   5.237 +			else if (vcmp(ptr, ENGINE686_SIG, SIGLEN))
   5.238 +			{
   5.239 +				offs = ENGINE686_OFFS;
   5.240 +			}
   5.241 +			else if (vcmp(ptr, ENGINEAMD_SIG, SIGLEN))
   5.242 +			{
   5.243 +				offs = ENGINEAMD_OFFS;
   5.244 +			}
   5.245 +#elif defined OS_WIN32 // Only one Windows engine binary so far...
   5.246 +			if (vcmp(ptr, ENGINEW32_SIG, SIGLEN))
   5.247 +			{
   5.248 +				offs = ENGINEW32_OFFS;
   5.249 +			}
   5.250 +#endif
   5.251 +
   5.252 +			if (!offs || ptr[offs - 1] != IA32_CALL)
   5.253 +			{
   5.254 +				return NULL;
   5.255 +			}
   5.256 +			//get the relative offset
   5.257 +			void *addr = *((void **)(ptr + offs));
   5.258 +			//add the base offset, to the ip (which is the address+offset + 4 bytes for next instruction)
   5.259 +			return (CONPRINTF_FUNC)((unsigned long)addr + (unsigned long)(ptr + offs) + 4);
   5.260 +		}
   5.261 +		pBase = const_cast<ConCommandBase *>(pBase->GetNext());
   5.262 +	}
   5.263 +
   5.264 +	return NULL;
   5.265 +}
   5.266 +
   5.267 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/providers/episode1/provider_ep1.h	Thu Sep 27 19:28:30 2007 +0000
     6.3 @@ -0,0 +1,49 @@
     6.4 +#ifndef _INCLUDE_METAMOD_SOURCE_BASE_PROVIDER_H_
     6.5 +#define _INCLUDE_METAMOD_SOURCE_BASE_PROVIDER_H_
     6.6 +
     6.7 +#include <metamod_provider.h>
     6.8 +#include <ISmmAPI.h>
     6.9 +
    6.10 +using namespace SourceMM;
    6.11 +
    6.12 +class BaseProvider : public IMetamodSourceProvider
    6.13 +{
    6.14 +public:
    6.15 +	virtual bool IsSourceEngineBuildCompatible(int build);
    6.16 +	virtual bool GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo);
    6.17 +	virtual bool LogMessage(const char *buffer);
    6.18 +	virtual const char *GetCommandLineValue(const char *key, const char *defval);
    6.19 +	virtual void ConsolePrint(const char *msg);
    6.20 +	virtual bool IsRemotePrintingAvailable();
    6.21 +	virtual void ClientConsolePrint(edict_t *client, const char *msg);
    6.22 +	virtual IServerPluginCallbacks *GetVSPCallbacks(const char *iface);
    6.23 +	virtual void DisplayError(const char *fmt, ...);
    6.24 +	virtual void DisplayWarning(const char *fmt, ...);
    6.25 +	virtual int TryServerGameDLL(const char *iface);
    6.26 +	virtual void Notify_DLLInit_Pre();
    6.27 +	virtual void ServerCommand(const char *cmd);
    6.28 +	virtual ConVar *CreateConVar(const char *name, 
    6.29 +		const char *defval, 
    6.30 +		const char *help,
    6.31 +		int flags);
    6.32 +	virtual const char *GetConVarString(ConVar *convar);
    6.33 +	virtual void CreateCommand(const char *name,
    6.34 +		METAMOD_COMMAND callback,
    6.35 +		const char *help);
    6.36 +	virtual void SetClientCommandHandler(METAMOD_COMMAND callback);
    6.37 +	virtual const char *GetGameDescription();
    6.38 +	virtual IConCommandBaseAccessor *GetConCommandBaseAccessor();
    6.39 +	virtual bool RegisterConCommandBase(ConCommandBase *pCommand);
    6.40 +	virtual void UnregisterConCommandBase(ConCommandBase *pCommand);
    6.41 +	virtual bool IsConCommandBaseACommand(ConCommandBase *pCommand);
    6.42 +	virtual int GetUserMessageCount();
    6.43 +	virtual int FindUserMessage(const char *name, int *size=NULL);
    6.44 +	virtual const char *GetUserMessage(int index, int *size=NULL);
    6.45 +};
    6.46 +
    6.47 +extern IVEngineServer *engine;
    6.48 +extern IServerGameDLL *server;
    6.49 +extern ICvar *icvar;
    6.50 +
    6.51 +#endif //_INCLUDE_METAMOD_SOURCE_BASE_PROVIDER_H_
    6.52 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/providers/provider_util.cpp	Thu Sep 27 19:28:30 2007 +0000
     7.3 @@ -0,0 +1,15 @@
     7.4 +#include "provider_util.h"
     7.5 +
     7.6 +size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list params)
     7.7 +{
     7.8 +	size_t len = vsnprintf(buffer, maxlength, fmt, params);
     7.9 +
    7.10 +	if (len >= maxlength)
    7.11 +	{
    7.12 +		len = maxlength - 1;
    7.13 +		buffer[len] = '\0';
    7.14 +	}
    7.15 +
    7.16 +	return len;
    7.17 +}
    7.18 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/providers/provider_util.h	Thu Sep 27 19:28:30 2007 +0000
     8.3 @@ -0,0 +1,11 @@
     8.4 +#ifndef _METAMOD_SOURCE_PROVIDER_UTIL_H_
     8.5 +#define _METAMOD_SOURCE_PROVIDER_UTIL_H_
     8.6 +
     8.7 +#include <stdio.h>
     8.8 +#include <string.h>
     8.9 +#include <stdarg.h>
    8.10 +
    8.11 +size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list params);
    8.12 +
    8.13 +#endif //_METAMOD_SOURCE_PROVIDER_UTIL_H_
    8.14 +