1.1 --- a/sourcemm/ISmmAPI.h Thu Sep 27 20:43:03 2007 +0000
1.2 +++ b/sourcemm/ISmmAPI.h Fri Sep 28 21:31:02 2007 +0000
1.3 @@ -18,7 +18,7 @@
1.4
1.5 #include <interface.h>
1.6 #include <eiface.h>
1.7 -#include <sourcehook/sourcehook.h>
1.8 +#include <sourcehook.h>
1.9 #include "IPluginManager.h"
1.10
1.11 #if defined __GNUC__
2.1 --- a/sourcemm/ISmmPlugin.h Thu Sep 27 20:43:03 2007 +0000
2.2 +++ b/sourcemm/ISmmPlugin.h Fri Sep 28 21:31:02 2007 +0000
2.3 @@ -17,7 +17,7 @@
2.4 */
2.5
2.6 #include <interface.h>
2.7 -#include <sourcehook/sourcehook.h>
2.8 +#include <sourcehook.h>
2.9 #include "ISmmAPI.h"
2.10
2.11 #define PLAPI_VERSION 12
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/sourcemm/episode1/console.cpp Fri Sep 28 21:31:02 2007 +0000
3.3 @@ -0,0 +1,111 @@
3.4 +#include "console.h"
3.5 +#include "provider_ep1.h"
3.6 +
3.7 +using namespace SourceHook;
3.8 +
3.9 +SMConVarAccessor g_SMConVarAccessor;
3.10 +
3.11 +class CAlwaysRegisterableCommand : public ConCommandBase
3.12 +{
3.13 +public:
3.14 + CAlwaysRegisterableCommand()
3.15 + {
3.16 + Create("metamod_eternal", NULL, FCVAR_UNREGISTERED|FCVAR_GAMEDLL);
3.17 + }
3.18 + bool IsRegistered( void ) const
3.19 + {
3.20 + return false;
3.21 + }
3.22 + void BringToFront()
3.23 + {
3.24 + // First, let's try to find us!
3.25 + ConCommandBase *pPtr = icvar->GetCommands();
3.26 +
3.27 + if (pPtr == this)
3.28 + {
3.29 + // We are already at the beginning; Nothing to do
3.30 + return;
3.31 + }
3.32 +
3.33 + while (pPtr)
3.34 + {
3.35 + if (pPtr == this)
3.36 + {
3.37 + break;
3.38 + }
3.39 + ConCommandBase *pPrev = NULL;
3.40 + while (pPtr)
3.41 + {
3.42 + if (pPtr == this)
3.43 + {
3.44 + break;
3.45 + }
3.46 + pPrev = pPtr;
3.47 + pPtr = const_cast<ConCommandBase*>(pPtr->GetNext());
3.48 + }
3.49 + if (pPrev && pPtr == this)
3.50 + {
3.51 + pPrev->SetNext(m_pNext); // Remove us from the list
3.52 + }
3.53 + // Now, register us
3.54 + SetNext(NULL);
3.55 + icvar->RegisterConCommandBase(this);
3.56 + }
3.57 + }
3.58 +} s_EternalCommand;
3.59 +
3.60 +bool SMConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand)
3.61 +{
3.62 + m_RegisteredCommands.push_back(pCommand);
3.63 + pCommand->SetNext(NULL);
3.64 + icvar->RegisterConCommandBase(pCommand);
3.65 +
3.66 + return true;
3.67 +}
3.68 +
3.69 +bool SMConVarAccessor::Register(ConCommandBase *pCommand)
3.70 +{
3.71 + pCommand->SetNext(NULL);
3.72 + icvar->RegisterConCommandBase(pCommand);
3.73 +
3.74 + return true;
3.75 +}
3.76 +
3.77 +void SMConVarAccessor::MarkCommandsAsGameDLL()
3.78 +{
3.79 + for (List<ConCommandBase*>::iterator iter = m_RegisteredCommands.begin();
3.80 + iter != m_RegisteredCommands.end(); ++iter)
3.81 + {
3.82 + (*iter)->AddFlags(FCVAR_GAMEDLL);
3.83 + }
3.84 +}
3.85 +
3.86 +void SMConVarAccessor::Unregister(ConCommandBase *pCommand)
3.87 +{
3.88 + ConCommandBase *ptr = icvar->GetCommands();
3.89 +
3.90 + if (ptr == pCommand)
3.91 + {
3.92 + s_EternalCommand.BringToFront();
3.93 + s_EternalCommand.SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
3.94 + }
3.95 + else
3.96 + {
3.97 + /* Find us and unregister us */
3.98 + ConCommandBase *pPrev = NULL;
3.99 + while (ptr)
3.100 + {
3.101 + if (ptr == pCommand)
3.102 + {
3.103 + break;
3.104 + }
3.105 + pPrev = ptr;
3.106 + ptr = const_cast<ConCommandBase *>(ptr->GetNext());
3.107 + }
3.108 + if (pPrev && ptr == pCommand)
3.109 + {
3.110 + pPrev->SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
3.111 + }
3.112 + }
3.113 +}
3.114 +
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/sourcemm/episode1/console.h Fri Sep 28 21:31:02 2007 +0000
4.3 @@ -0,0 +1,24 @@
4.4 +#ifndef _INCLUDE_CONSOLE_MMS_H_
4.5 +#define _INCLUDE_CONSOLE_MMS_H_
4.6 +
4.7 +#include <interface.h>
4.8 +#include <eiface.h>
4.9 +#include "convar_smm.h"
4.10 +#include <sh_list.h>
4.11 +
4.12 +class SMConVarAccessor : public IConCommandBaseAccessor
4.13 +{
4.14 +public:
4.15 + bool RegisterConCommandBase(ConCommandBase *pCommand);
4.16 + bool Register(ConCommandBase *pCommand);
4.17 + void MarkCommandsAsGameDLL();
4.18 + void Unregister(ConCommandBase *pCommand);
4.19 + void UnregisterGameDLLCommands();
4.20 +private:
4.21 + SourceHook::List<ConCommandBase*> m_RegisteredCommands;
4.22 +};
4.23 +
4.24 +extern SMConVarAccessor g_SMConVarAccessor;
4.25 +
4.26 +#endif //_INCLUDE_CONSOLE_MMS_H_
4.27 +
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/sourcemm/episode1/convar_smm.h Fri Sep 28 21:31:02 2007 +0000
5.3 @@ -0,0 +1,523 @@
5.4 +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
5.5 +//
5.6 +// Purpose:
5.7 +//
5.8 +// $Workfile: $
5.9 +// $Date: 2007-02-08 04:19:19 -0500 (Thu, 08 Feb 2007) $
5.10 +//
5.11 +//-----------------------------------------------------------------------------
5.12 +// $NoKeywords: $
5.13 +//=============================================================================//
5.14 +
5.15 +#ifndef CONVAR_H
5.16 +#define CONVAR_H
5.17 +#if _WIN32
5.18 +#pragma once
5.19 +#endif
5.20 +
5.21 +#include "tier0/dbg.h"
5.22 +
5.23 +#ifdef _WIN32
5.24 +#define FORCEINLINE_CVAR FORCEINLINE
5.25 +#elif _LINUX
5.26 +#define FORCEINLINE_CVAR __inline__ FORCEINLINE
5.27 +#else
5.28 +#error "implement me"
5.29 +#endif
5.30 +
5.31 +// The default, no flags at all
5.32 +#define FCVAR_NONE 0
5.33 +
5.34 +// Command to ConVars and ConCommands
5.35 +// ConVar Systems
5.36 +#define FCVAR_UNREGISTERED (1<<0) // If this is set, don't add to linked list, etc.
5.37 +#define FCVAR_LAUNCHER (1<<1) // defined by launcher
5.38 +#define FCVAR_GAMEDLL (1<<2) // defined by the game DLL
5.39 +#define FCVAR_CLIENTDLL (1<<3) // defined by the client DLL
5.40 +#define FCVAR_MATERIAL_SYSTEM (1<<4) // Defined by the material system.
5.41 +#define FCVAR_DATACACHE (1<<19) // Defined by the datacache system.
5.42 +#define FCVAR_STUDIORENDER (1<<15) // Defined by the studiorender system.
5.43 +#define FCVAR_FILESYSTEM (1<<21) // Defined by the file system.
5.44 +#define FCVAR_PLUGIN (1<<18) // Defined by a 3rd party plugin.
5.45 +#define FCVAR_TOOLSYSTEM (1<<20) // Defined by an IToolSystem library
5.46 +#define FCVAR_SOUNDSYSTEM (1<<23) // Defined by the soundsystem library
5.47 +#define FCVAR_INPUTSYSTEM (1<<25) // Defined by the inputsystem dll
5.48 +#define FCVAR_NETWORKSYSTEM (1<<26) // Defined by the network system
5.49 +// NOTE!! if you add a cvar system, add it here too!!!!
5.50 +// the engine lacks a cvar flag, but needs it for xbox
5.51 +// an engine cvar is thus a cvar not marked with any other system
5.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))
5.53 +
5.54 +// ConVar only
5.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
5.56 +#define FCVAR_SPONLY (1<<6) // This cvar cannot be changed by clients connected to a multiplayer server.
5.57 +#define FCVAR_ARCHIVE (1<<7) // set to cause it to be saved to vars.rc
5.58 +#define FCVAR_NOTIFY (1<<8) // notifies players when changed
5.59 +#define FCVAR_USERINFO (1<<9) // changes the client's info string
5.60 +#define FCVAR_CHEAT (1<<14) // Only useable in singleplayer / debug / multiplayer & sv_cheats
5.61 +
5.62 +#define FCVAR_PRINTABLEONLY (1<<10) // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ).
5.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
5.64 +#define FCVAR_NEVER_AS_STRING (1<<12) // never try to print that cvar
5.65 +
5.66 +// It's a ConVar that's shared between the client and the server.
5.67 +// At signon, the values of all such ConVars are sent from the server to the client (skipped for local
5.68 +// client, of course )
5.69 +// If a change is requested it must come from the console (i.e., no remote client changes)
5.70 +// If a value is changed while a server is active, it's replicated to all connected clients
5.71 +#define FCVAR_REPLICATED (1<<13) // server setting enforced on clients, TODO rename to FCAR_SERVER at some time
5.72 +#define FCVAR_DEMO (1<<16) // record this cvar when starting a demo file
5.73 +#define FCVAR_DONTRECORD (1<<17) // don't record these command in demofiles
5.74 +
5.75 +#define FCVAR_NOT_CONNECTED (1<<22) // cvar cannot be changed by a client that is connected to a server
5.76 +
5.77 +#define FCVAR_ARCHIVE_XBOX (1<<24) // cvar written to config.cfg on the Xbox
5.78 +
5.79 +
5.80 +// #define FCVAR_AVAILABLE (1<<27)
5.81 +// #define FCVAR_AVAILABLE (1<<28)
5.82 +// #define FCVAR_AVAILABLE (1<<29)
5.83 +// #define FCVAR_AVAILABLE (1<<30)
5.84 +// #define FCVAR_AVAILABLE (1<<31)
5.85 +
5.86 +
5.87 +class ConVar;
5.88 +class ConCommand;
5.89 +class ConCommandBase;
5.90 +
5.91 +// Any executable that wants to use ConVars need to implement one of
5.92 +// these to hook up access to console variables.
5.93 +class IConCommandBaseAccessor
5.94 +{
5.95 +public:
5.96 + // Flags is a combination of FCVAR flags in cvar.h.
5.97 + // hOut is filled in with a handle to the variable.
5.98 + virtual bool RegisterConCommandBase( ConCommandBase *pVar )=0;
5.99 +};
5.100 +
5.101 +
5.102 +// You don't have to instantiate one of these, just call its
5.103 +// OneTimeInit function when your executable is initializing.
5.104 +class ConCommandBaseMgr
5.105 +{
5.106 +public:
5.107 + // Call this ONCE when the executable starts up.
5.108 + static void OneTimeInit( IConCommandBaseAccessor *pAccessor );
5.109 +#ifdef _XBOX
5.110 + static bool Fixup( ConCommandBase* pConCommandBase );
5.111 +#ifndef _RETAIL
5.112 + static void PublishCommands( bool bForce );
5.113 +#endif
5.114 +#endif
5.115 +};
5.116 +
5.117 +// Called when a ConVar changes value
5.118 +typedef void ( *FnChangeCallback )( ConVar *var, char const *pOldString );
5.119 +
5.120 +// Called when a ConCommand needs to execute
5.121 +typedef void ( *FnCommandCallback )( void );
5.122 +
5.123 +#define COMMAND_COMPLETION_MAXITEMS 64
5.124 +#define COMMAND_COMPLETION_ITEM_LENGTH 64
5.125 +
5.126 +// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
5.127 +typedef int ( *FnCommandCompletionCallback )( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
5.128 +
5.129 +//-----------------------------------------------------------------------------
5.130 +// Purpose: The base console invoked command/cvar interface
5.131 +//-----------------------------------------------------------------------------
5.132 +class ConCommandBase
5.133 +{
5.134 + friend class ConCommandBaseMgr;
5.135 + friend class CCvar;
5.136 + friend class ConVar;
5.137 + friend class ConCommand;
5.138 +
5.139 +public:
5.140 + ConCommandBase( void );
5.141 + ConCommandBase( char const *pName, char const *pHelpString = 0,
5.142 + int flags = 0 );
5.143 +
5.144 + virtual ~ConCommandBase( void );
5.145 +
5.146 + virtual bool IsCommand( void ) const;
5.147 +
5.148 + // Check flag
5.149 + virtual bool IsBitSet( int flag ) const;
5.150 + // Set flag
5.151 + virtual void AddFlags( int flags );
5.152 +
5.153 + // Return name of cvar
5.154 + virtual char const *GetName( void ) const;
5.155 +
5.156 + // Return help text for cvar
5.157 + virtual char const *GetHelpText( void ) const;
5.158 +
5.159 + // Deal with next pointer
5.160 + const ConCommandBase *GetNext( void ) const;
5.161 + void SetNext( ConCommandBase *next );
5.162 +
5.163 + virtual bool IsRegistered( void ) const;
5.164 +
5.165 + // Global methods
5.166 + static ConCommandBase const *GetCommands( void );
5.167 + static void AddToList( ConCommandBase *var );
5.168 + static void RemoveFlaggedCommands( int flag );
5.169 + static void RevertFlaggedCvars( int flag );
5.170 + static ConCommandBase const *FindCommand( char const *name );
5.171 +
5.172 +protected:
5.173 + virtual void Create( char const *pName, char const *pHelpString = 0,
5.174 + int flags = 0 );
5.175 +
5.176 + // Used internally by OneTimeInit to initialize.
5.177 + virtual void Init();
5.178 +
5.179 + // Internal copy routine ( uses new operator from correct module )
5.180 + char *CopyString( char const *from );
5.181 +
5.182 + // Next ConVar in chain
5.183 + ConCommandBase *m_pNext;
5.184 +
5.185 +private:
5.186 + // Has the cvar been added to the global list?
5.187 + bool m_bRegistered;
5.188 +
5.189 + // Static data
5.190 + char const *m_pszName;
5.191 + char const *m_pszHelpString;
5.192 +
5.193 + // ConVar flags
5.194 + int m_nFlags;
5.195 +
5.196 +protected:
5.197 +
5.198 + // ConVars add themselves to this list for the executable. Then ConVarMgr::Init() runs through
5.199 + // all the console variables and registers them.
5.200 + static ConCommandBase *s_pConCommandBases;
5.201 +
5.202 + // ConVars in this executable use this 'global' to access values.
5.203 + static IConCommandBaseAccessor *s_pAccessor;
5.204 +};
5.205 +
5.206 +//-----------------------------------------------------------------------------
5.207 +// Purpose: The console invoked command
5.208 +//-----------------------------------------------------------------------------
5.209 +class ConCommand : public ConCommandBase
5.210 +{
5.211 +friend class ConCommandBaseMgr;
5.212 +friend class CCvar;
5.213 +#ifdef _STATIC_LINKED
5.214 +friend class G_ConCommand;
5.215 +friend class C_ConCommand;
5.216 +friend class M_ConCommand;
5.217 +friend class S_ConCommand;
5.218 +friend class D_ConCommand;
5.219 +#endif
5.220 +
5.221 +public:
5.222 + typedef ConCommandBase BaseClass;
5.223 +
5.224 + ConCommand( void );
5.225 + ConCommand( char const *pName, FnCommandCallback callback,
5.226 + char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
5.227 +
5.228 + virtual ~ConCommand( void );
5.229 +
5.230 + virtual bool IsCommand( void ) const;
5.231 +
5.232 + virtual int AutoCompleteSuggest( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
5.233 +
5.234 + virtual bool CanAutoComplete( void );
5.235 +
5.236 + // Invoke the function
5.237 + virtual void Dispatch( void );
5.238 +private:
5.239 + virtual void Create( char const *pName, FnCommandCallback callback,
5.240 + char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
5.241 +
5.242 + // Call this function when executing the command
5.243 + FnCommandCallback m_fnCommandCallback;
5.244 +
5.245 + FnCommandCompletionCallback m_fnCompletionCallback;
5.246 + bool m_bHasCompletionCallback;
5.247 +public:
5.248 + FnCommandCallback GetCallback() { return m_fnCommandCallback; }
5.249 +};
5.250 +
5.251 +//-----------------------------------------------------------------------------
5.252 +// Purpose: A console variable
5.253 +//-----------------------------------------------------------------------------
5.254 +class ConVar : public ConCommandBase
5.255 +{
5.256 +friend class ConCommandBaseMgr;
5.257 +friend class CCvar;
5.258 +friend class CDefaultCvar;
5.259 +#ifdef _STATIC_LINKED
5.260 +friend class G_ConVar;
5.261 +friend class C_ConVar;
5.262 +friend class M_ConVar;
5.263 +friend class S_ConVar;
5.264 +friend class D_ConVar;
5.265 +#endif
5.266 +
5.267 +public:
5.268 + typedef ConCommandBase BaseClass;
5.269 +
5.270 + ConVar( char const *pName, char const *pDefaultValue, int flags = 0);
5.271 +
5.272 + ConVar( char const *pName, char const *pDefaultValue, int flags,
5.273 + char const *pHelpString );
5.274 + ConVar( char const *pName, char const *pDefaultValue, int flags,
5.275 + char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax );
5.276 + ConVar( char const *pName, char const *pDefaultValue, int flags,
5.277 + char const *pHelpString, FnChangeCallback callback );
5.278 + ConVar( char const *pName, char const *pDefaultValue, int flags,
5.279 + char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax,
5.280 + FnChangeCallback callback );
5.281 +
5.282 + virtual ~ConVar( void );
5.283 +
5.284 + virtual bool IsBitSet( int flag ) const;
5.285 + virtual char const* GetHelpText( void ) const;
5.286 + virtual bool IsRegistered( void ) const;
5.287 + virtual char const *GetName( void ) const;
5.288 + virtual void AddFlags( int flags );
5.289 + virtual bool IsCommand( void ) const;
5.290 +
5.291 + // Install a change callback (there shouldn't already be one....)
5.292 + void InstallChangeCallback( FnChangeCallback callback );
5.293 +
5.294 + // Retrieve value
5.295 + FORCEINLINE_CVAR float GetFloat( void ) const;
5.296 + FORCEINLINE_CVAR int GetInt( void ) const;
5.297 + FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); }
5.298 + FORCEINLINE_CVAR char const *GetString( void ) const;
5.299 +
5.300 + // Any function that allocates/frees memory needs to be virtual or else you'll have crashes
5.301 + // from alloc/free across dll/exe boundaries.
5.302 +
5.303 + // These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
5.304 + virtual void SetValue( char const *value );
5.305 + virtual void SetValue( float value );
5.306 + virtual void SetValue( int value );
5.307 +
5.308 + // Reset to default value
5.309 + void Revert( void );
5.310 +
5.311 + // True if it has a min/max setting
5.312 + bool GetMin( float& minVal ) const;
5.313 + bool GetMax( float& maxVal ) const;
5.314 + char const *GetDefault( void ) const;
5.315 +
5.316 + static void RevertAll( void );
5.317 +private:
5.318 + // Called by CCvar when the value of a var is changing.
5.319 + virtual void InternalSetValue(char const *value);
5.320 + // For CVARs marked FCVAR_NEVER_AS_STRING
5.321 + virtual void InternalSetFloatValue( float fNewValue );
5.322 + virtual void InternalSetIntValue( int nValue );
5.323 +
5.324 + virtual bool ClampValue( float& value );
5.325 + virtual void ChangeStringValue( char const *tempVal );
5.326 +
5.327 + virtual void Create( char const *pName, char const *pDefaultValue, int flags = 0,
5.328 + char const *pHelpString = 0, bool bMin = false, float fMin = 0.0,
5.329 + bool bMax = false, float fMax = false, FnChangeCallback callback = 0 );
5.330 +
5.331 + // Used internally by OneTimeInit to initialize.
5.332 + virtual void Init();
5.333 +
5.334 +private:
5.335 +
5.336 + // This either points to "this" or it points to the original declaration of a ConVar.
5.337 + // This allows ConVars to exist in separate modules, and they all use the first one to be declared.
5.338 + // m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
5.339 + ConVar *m_pParent;
5.340 +
5.341 + // Static data
5.342 + char const *m_pszDefaultValue;
5.343 +
5.344 + // Value
5.345 + // Dynamically allocated
5.346 + char *m_pszString;
5.347 + int m_StringLength;
5.348 +
5.349 + // Values
5.350 + float m_fValue;
5.351 + int m_nValue;
5.352 +
5.353 + // Min/Max values
5.354 + bool m_bHasMin;
5.355 + float m_fMinVal;
5.356 + bool m_bHasMax;
5.357 + float m_fMaxVal;
5.358 +
5.359 + // Call this function when ConVar changes
5.360 + FnChangeCallback m_fnChangeCallback;
5.361 +};
5.362 +
5.363 +
5.364 +//-----------------------------------------------------------------------------
5.365 +// Purpose: Return ConVar value as a float
5.366 +// Output : float
5.367 +//-----------------------------------------------------------------------------
5.368 +FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
5.369 +{
5.370 + return m_pParent->m_fValue;
5.371 +}
5.372 +
5.373 +//-----------------------------------------------------------------------------
5.374 +// Purpose: Return ConVar value as an int
5.375 +// Output : int
5.376 +//-----------------------------------------------------------------------------
5.377 +FORCEINLINE_CVAR int ConVar::GetInt( void ) const
5.378 +{
5.379 + return m_pParent->m_nValue;
5.380 +}
5.381 +
5.382 +
5.383 +//-----------------------------------------------------------------------------
5.384 +// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
5.385 +// Output : char const *
5.386 +//-----------------------------------------------------------------------------
5.387 +FORCEINLINE_CVAR char const *ConVar::GetString( void ) const
5.388 +{
5.389 + if ( m_nFlags & FCVAR_NEVER_AS_STRING )
5.390 + {
5.391 + return "FCVAR_NEVER_AS_STRING";
5.392 + }
5.393 +
5.394 + return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : "";
5.395 +}
5.396 +
5.397 +
5.398 +#ifdef _STATIC_LINKED
5.399 +// identifies subsystem via piggybacking constructors with flags
5.400 +class G_ConCommand : public ConCommand
5.401 +{
5.402 +public:
5.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) {}
5.404 +};
5.405 +
5.406 +class C_ConCommand : public ConCommand
5.407 +{
5.408 +public:
5.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) {}
5.410 +};
5.411 +
5.412 +class M_ConCommand : public ConCommand
5.413 +{
5.414 +public:
5.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) {}
5.416 +};
5.417 +
5.418 +class S_ConCommand : public ConCommand
5.419 +{
5.420 +public:
5.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) {}
5.422 +};
5.423 +
5.424 +class D_ConCommand : public ConCommand
5.425 +{
5.426 +public:
5.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) {}
5.428 +};
5.429 +
5.430 +typedef void ( *G_FnChangeCallback )( G_ConVar *var, char const *pOldString );
5.431 +typedef void ( *C_FnChangeCallback )( C_ConVar *var, char const *pOldString );
5.432 +typedef void ( *M_FnChangeCallback )( M_ConVar *var, char const *pOldString );
5.433 +typedef void ( *S_FnChangeCallback )( S_ConVar *var, char const *pOldString );
5.434 +typedef void ( *D_FnChangeCallback )( D_ConVar *var, char const *pOldString );
5.435 +
5.436 +class G_ConVar : public ConVar
5.437 +{
5.438 +public:
5.439 + G_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL) {}
5.440 + G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString ) {}
5.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) {}
5.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 ) {}
5.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 ) {}
5.444 +};
5.445 +
5.446 +class C_ConVar : public ConVar
5.447 +{
5.448 +public:
5.449 + C_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL) {}
5.450 + C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString ) {}
5.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) {}
5.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 ) {}
5.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 ) {}
5.454 +};
5.455 +
5.456 +class M_ConVar : public ConVar
5.457 +{
5.458 +public:
5.459 + M_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM) {}
5.460 + M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString ) {}
5.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) {}
5.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 ) {}
5.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 ) {}
5.464 +};
5.465 +
5.466 +class S_ConVar : public ConVar
5.467 +{
5.468 +public:
5.469 + S_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER) {}
5.470 + S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString ) {}
5.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) {}
5.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 ) {}
5.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 ) {}
5.474 +};
5.475 +
5.476 +class D_ConVar : public ConVar
5.477 +{
5.478 +public:
5.479 + D_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE) {}
5.480 + D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString ) {}
5.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) {}
5.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 ) {}
5.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 ) {}
5.484 +};
5.485 +
5.486 +// redirect these declarations to their specific subsystem
5.487 +#ifdef GAME_DLL
5.488 +#define ConCommand G_ConCommand
5.489 +#define ConVar G_ConVar
5.490 +#endif
5.491 +#ifdef CLIENT_DLL
5.492 +#define ConCommand C_ConCommand
5.493 +#define ConVar C_ConVar
5.494 +#endif
5.495 +#ifdef MATERIALSYSTEM_DLL
5.496 +#define ConCommand M_ConCommand
5.497 +#define ConVar M_ConVar
5.498 +#endif
5.499 +#ifdef STUDIORENDER_DLL
5.500 +#define ConCommand S_ConCommand
5.501 +#define ConVar S_ConVar
5.502 +#endif
5.503 +#ifdef DATACACHE_DLL
5.504 +#define ConCommand D_ConCommand
5.505 +#define ConVar D_ConVar
5.506 +#endif
5.507 +#endif // _STATIC_LINKED
5.508 +
5.509 +//-----------------------------------------------------------------------------
5.510 +// Purpose: Utility to quicky generate a simple console command
5.511 +//-----------------------------------------------------------------------------
5.512 +#define CON_COMMAND( name, description ) \
5.513 + static void name(); \
5.514 + static ConCommand name##_command( #name, name, description ); \
5.515 + static void name()
5.516 +
5.517 +//-----------------------------------------------------------------------------
5.518 +// Purpose: Utility to quicky generate a simple console command
5.519 +//-----------------------------------------------------------------------------
5.520 +#define CON_COMMAND_F( name, description, flags ) \
5.521 + static void name(); \
5.522 + static ConCommand name##_command( #name, name, description, flags ); \
5.523 + static void name()
5.524 +
5.525 +
5.526 +#endif // CONVAR_H
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/sourcemm/episode1/provider_ep1.cpp Fri Sep 28 21:31:02 2007 +0000
6.3 @@ -0,0 +1,553 @@
6.4 +#include <sourcehook.h>
6.5 +#include "convar_smm.h"
6.6 +#include <eiface.h>
6.7 +#include <tier0/icommandline.h>
6.8 +#include <tier1/utldict.h>
6.9 +#include <sh_vector.h>
6.10 +#include <sh_string.h>
6.11 +#include "../metamod_util.h"
6.12 +#include "provider_ep1.h"
6.13 +#include "console.h"
6.14 +#include "metamod_console.h"
6.15 +
6.16 +/* Types */
6.17 +typedef void (*CONPRINTF_FUNC)(const char *, ...);
6.18 +struct UsrMsgInfo
6.19 +{
6.20 + int size;
6.21 + String name;
6.22 +};
6.23 +/* Imports */
6.24 +#undef CommandLine
6.25 +DLL_IMPORT ICommandLine *CommandLine();
6.26 +/* Functions */
6.27 +CONPRINTF_FUNC ExtractRemotePrinter();
6.28 +bool CacheUserMessages();
6.29 +void ClientCommand(edict_t *pEdict);
6.30 +void _ServerCommand();
6.31 +/* Variables */
6.32 +bool usermsgs_extracted = false;
6.33 +CVector<UsrMsgInfo> usermsgs_list;
6.34 +CONPRINTF_FUNC echo_msg_func = NULL;
6.35 +ICvar *icvar = NULL;
6.36 +ISmmAPI *metamod_api = NULL;
6.37 +IVEngineServer *engine = NULL;
6.38 +IServerGameClients *gameclients = NULL;
6.39 +BaseProvider g_Ep1Provider;
6.40 +IMetamodSourceProvider *provider = &g_Ep1Provider;
6.41 +
6.42 +SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
6.43 +
6.44 +void BaseProvider::ConsolePrint(const char *str)
6.45 +{
6.46 + if (echo_msg_func != NULL)
6.47 + {
6.48 + echo_msg_func("%s", str);
6.49 + }
6.50 + else
6.51 + {
6.52 + Msg("%s", str);
6.53 + }
6.54 +}
6.55 +
6.56 +void BaseProvider::Notify_DLLInit_Pre(void *gamedll,
6.57 + CreateInterfaceFn engineFactory,
6.58 + CreateInterfaceFn serverFactory)
6.59 +{
6.60 + server = (IServerGameDLL *)gamedll;
6.61 + engine = (IVEngineServer *)((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL));
6.62 + if (!engine)
6.63 + {
6.64 + Error("Could not find IVEngineServer! Metamod cannot load.");
6.65 + return;
6.66 + }
6.67 + icvar = (ICvar *)((engineFactory)(VENGINE_CVAR_INTERFACE_VERSION, NULL));
6.68 + if (!icvar)
6.69 + {
6.70 + Error("Could not find ICvar! Metamod cannot load.");
6.71 + return;
6.72 + }
6.73 +
6.74 + if ((gameclients = (IServerGameClients *)(serverFactory("ServerGameClients003", NULL)))
6.75 + == NULL)
6.76 + {
6.77 + gameclients = (IServerGameClients *)(serverFactory("ServerGameClients004", NULL));
6.78 + }
6.79 +
6.80 + echo_msg_func = ExtractRemotePrinter();
6.81 + usermsgs_extracted = CacheUserMessages();
6.82 +
6.83 + if (gameclients)
6.84 + {
6.85 + SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, gameclients, ClientCommand, false);
6.86 + }
6.87 +
6.88 + ConCommandBaseMgr::OneTimeInit(&g_SMConVarAccessor);
6.89 +}
6.90 +
6.91 +bool BaseProvider::IsRemotePrintingAvailable()
6.92 +{
6.93 + return (echo_msg_func != NULL);
6.94 +}
6.95 +
6.96 +void BaseProvider::ClientConsolePrint(edict_t *client, const char *message)
6.97 +{
6.98 + engine->ClientPrintf(client, message);
6.99 +}
6.100 +
6.101 +void BaseProvider::ServerCommand(const char *cmd)
6.102 +{
6.103 + engine->ServerCommand(cmd);
6.104 +}
6.105 +
6.106 +const char *BaseProvider::GetConVarString(ConVar *convar)
6.107 +{
6.108 + return convar->GetString();
6.109 +}
6.110 +
6.111 +bool BaseProvider::IsConCommandBaseACommand(ConCommandBase *pCommand)
6.112 +{
6.113 + return pCommand->IsCommand();
6.114 +}
6.115 +
6.116 +
6.117 +bool BaseProvider::IsSourceEngineBuildCompatible(int build)
6.118 +{
6.119 + return (build == SOURCE_ENGINE_ORIGINAL
6.120 + || build == SOURCE_ENGINE_EPISODEONE);
6.121 +}
6.122 +
6.123 +const char *BaseProvider::GetCommandLineValue(const char *key, const char *defval)
6.124 +{
6.125 + if (key[0] == '-' || key[0] == '+')
6.126 + {
6.127 + return CommandLine()->ParmValue(key, defval);
6.128 + }
6.129 + else
6.130 + {
6.131 + const char *val;
6.132 + if ((val = icvar->GetCommandLineValue(key)) == NULL)
6.133 + {
6.134 + return defval;
6.135 + }
6.136 +
6.137 + return val;
6.138 + }
6.139 +}
6.140 +
6.141 +int BaseProvider::TryServerGameDLL(const char *iface)
6.142 +{
6.143 + if (strncmp(iface, "ServerGameDLL", 13) != 0)
6.144 + {
6.145 + return 0;
6.146 + }
6.147 +
6.148 + return atoi(&iface[13]);
6.149 +}
6.150 +
6.151 +bool BaseProvider::LogMessage(const char *buffer)
6.152 +{
6.153 + if (!engine)
6.154 + {
6.155 + return false;
6.156 + }
6.157 +
6.158 + engine->LogPrint(buffer);
6.159 +
6.160 + return true;
6.161 +}
6.162 +
6.163 +bool BaseProvider::GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo)
6.164 +{
6.165 + SourceHook::MemFuncInfo mfi = {true, -1, 0, 0};
6.166 +
6.167 + if (hook == ProvidedHook_LevelInit)
6.168 + {
6.169 + SourceHook::GetFuncInfo(&IServerGameDLL::LevelInit, mfi);
6.170 + }
6.171 + else if (hook == ProvidedHook_LevelShutdown)
6.172 + {
6.173 + SourceHook::GetFuncInfo(&IServerGameDLL::LevelShutdown, mfi);
6.174 + }
6.175 + else if (hook == ProvidedHook_GameInit)
6.176 + {
6.177 + SourceHook::GetFuncInfo(&IServerGameDLL::GameInit, mfi);
6.178 + }
6.179 + else if (hook == ProvidedHook_DLLShutdown)
6.180 + {
6.181 + SourceHook::GetFuncInfo(&IServerGameDLL::DLLShutdown, mfi);
6.182 + }
6.183 + else if (hook == ProvidedHook_DLLInit)
6.184 + {
6.185 + SourceHook::GetFuncInfo(&IServerGameDLL::DLLInit, mfi);
6.186 + }
6.187 +
6.188 + *pInfo = mfi;
6.189 +
6.190 + return (mfi.thisptroffs >= 0);
6.191 +}
6.192 +
6.193 +void BaseProvider::DisplayError(const char *fmt, ...)
6.194 +{
6.195 + va_list ap;
6.196 + char buffer[2048];
6.197 +
6.198 + va_start(ap, fmt);
6.199 + UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
6.200 + va_end(ap);
6.201 +
6.202 + Error(buffer);
6.203 +}
6.204 +
6.205 +void BaseProvider::DisplayWarning(const char *fmt, ...)
6.206 +{
6.207 + va_list ap;
6.208 + char buffer[2048];
6.209 +
6.210 + va_start(ap, fmt);
6.211 + UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
6.212 + va_end(ap);
6.213 +
6.214 + Warning(buffer);
6.215 +}
6.216 +
6.217 +IConCommandBaseAccessor *BaseProvider::GetConCommandBaseAccessor()
6.218 +{
6.219 + return &g_SMConVarAccessor;
6.220 +}
6.221 +
6.222 +bool BaseProvider::RegisterConCommandBase(ConCommandBase *pCommand)
6.223 +{
6.224 + return g_SMConVarAccessor.Register(pCommand);
6.225 +}
6.226 +
6.227 +void BaseProvider::UnregisterConCommandBase(ConCommandBase *pCommand)
6.228 +{
6.229 + return g_SMConVarAccessor.Unregister(pCommand);
6.230 +}
6.231 +
6.232 +int BaseProvider::GetUserMessageCount()
6.233 +{
6.234 + if (!usermsgs_extracted)
6.235 + {
6.236 + return -1;
6.237 + }
6.238 +
6.239 + return (int)usermsgs_list.size();
6.240 +}
6.241 +
6.242 +int BaseProvider::FindUserMessage(const char *name, int *size)
6.243 +{
6.244 + for (size_t i = 0; i < usermsgs_list.size(); i++)
6.245 + {
6.246 + if (usermsgs_list[i].name.compare(name) == 0)
6.247 + {
6.248 + if (size)
6.249 + {
6.250 + *size = usermsgs_list[i].size;
6.251 + }
6.252 + return (int)i;
6.253 + }
6.254 + }
6.255 +
6.256 + return -1;
6.257 +}
6.258 +
6.259 +const char *BaseProvider::GetUserMessage(int index, int *size)
6.260 +{
6.261 + if (!usermsgs_extracted || index < 0 || index >= (int)usermsgs_list.size())
6.262 + {
6.263 + return NULL;
6.264 + }
6.265 +
6.266 + if (size)
6.267 + {
6.268 + *size = usermsgs_list[index].size;
6.269 + }
6.270 +
6.271 + return usermsgs_list[index].name.c_str();
6.272 +}
6.273 +
6.274 +const char *BaseProvider::GetGameDescription()
6.275 +{
6.276 + return server->GetGameDescription();
6.277 +}
6.278 +
6.279 +ConVar *BaseProvider::CreateConVar(const char *name,
6.280 + const char *defval,
6.281 + const char *help,
6.282 + int flags)
6.283 +{
6.284 + int newflags = 0;
6.285 + if (flags & ConVarFlag_Notify)
6.286 + {
6.287 + newflags |= FCVAR_NOTIFY;
6.288 + }
6.289 + if (flags & ConVarFlag_Replicated)
6.290 + {
6.291 + newflags |= FCVAR_REPLICATED;
6.292 + }
6.293 + if (flags & ConVarFlag_SpOnly)
6.294 + {
6.295 + newflags |= FCVAR_SPONLY;
6.296 + }
6.297 +
6.298 + return new ConVar(name, defval, newflags, help);
6.299 +}
6.300 +
6.301 +IServerPluginCallbacks *BaseProvider::GetVSPCallbacks(const char *iface)
6.302 +{
6.303 + return NULL;
6.304 +}
6.305 +
6.306 +class GlobCommand : public IMetamodSourceCommandInfo
6.307 +{
6.308 +public:
6.309 + unsigned int GetArgCount()
6.310 + {
6.311 + return engine->Cmd_Argc() - 1;
6.312 + }
6.313 +
6.314 + const char *GetArg(unsigned int num)
6.315 + {
6.316 + return engine->Cmd_Argv(num);
6.317 + }
6.318 +
6.319 + const char *GetArgString()
6.320 + {
6.321 + return engine->Cmd_Args();
6.322 + }
6.323 +};
6.324 +
6.325 +CON_COMMAND(meta, "Metamod:Source control commands")
6.326 +{
6.327 + GlobCommand cmd;
6.328 + Command_Meta(&cmd);
6.329 +}
6.330 +
6.331 +void ClientCommand(edict_t *pEdict)
6.332 +{
6.333 + GlobCommand cmd;
6.334 +
6.335 + if (strcmp(cmd.GetArg(0), "meta") == 0)
6.336 + {
6.337 + Command_ClientMeta(pEdict, &cmd);
6.338 + }
6.339 +}
6.340 +
6.341 +//////////////////////////////////////////////////////////////////////////
6.342 +//THERE BE HAX HERE!!!! DON'T TELL ALFRED, BUT GABE WANTED IT THAT WAY. //
6.343 +// (note: you can find the offset by looking for the text //
6.344 +// "Echo text to console", you'll find the callback cmd pushed on the //
6.345 +// stack.) //
6.346 +//////////////////////////////////////////////////////////////////////////
6.347 +
6.348 +#define SIGLEN 8
6.349 +#define ENGINE486_SIG "\x55\x89\xE5\x53\x83\xEC\x14\xBB"
6.350 +#define ENGINE486_OFFS 40
6.351 +#define ENGINE686_SIG "\x53\x83\xEC\x08\xBB\x01\x00\x00"
6.352 +#define ENGINE686_OFFS 50
6.353 +#define ENGINEAMD_SIG "\x53\x51\xBB\x01\x00\x00\x00\x51"
6.354 +#define ENGINEAMD_OFFS 47
6.355 +#define ENGINEW32_SIG "\xA1\x2A\x2A\x2A\x2A\x56\xBE\x01"
6.356 +#define ENGINEW32_OFFS 38
6.357 +#define IA32_CALL 0xE8
6.358 +
6.359 +bool vcmp(const void *_addr1, const void *_addr2, size_t len)
6.360 +{
6.361 + unsigned char *addr1 = (unsigned char *)_addr1;
6.362 + unsigned char *addr2 = (unsigned char *)_addr2;
6.363 +
6.364 + for (size_t i=0; i<len; i++)
6.365 + {
6.366 + if (addr2[i] == '*')
6.367 + {
6.368 + continue;
6.369 + }
6.370 + if (addr1[i] != addr2[i])
6.371 + {
6.372 + return false;
6.373 + }
6.374 + }
6.375 +
6.376 + return true;
6.377 +}
6.378 +
6.379 +//Thanks to fysh for the idea of extracting info from "echo" and for
6.380 +// having the original offsets at hand!
6.381 +CONPRINTF_FUNC ExtractRemotePrinter()
6.382 +{
6.383 + ConCommandBase *pBase = icvar->GetCommands();
6.384 + unsigned char *ptr = NULL;
6.385 + FnCommandCallback callback = NULL;
6.386 + int offs = 0;
6.387 +
6.388 + while (pBase)
6.389 + {
6.390 + if (strcmp(pBase->GetName(), "echo") == 0)
6.391 + {
6.392 + callback = ((ConCommand *)pBase)->GetCallback();
6.393 + ptr = (unsigned char *)callback;
6.394 +#ifdef OS_LINUX
6.395 + if (vcmp(ptr, ENGINE486_SIG, SIGLEN))
6.396 + {
6.397 + offs = ENGINE486_OFFS;
6.398 + }
6.399 + else if (vcmp(ptr, ENGINE686_SIG, SIGLEN))
6.400 + {
6.401 + offs = ENGINE686_OFFS;
6.402 + }
6.403 + else if (vcmp(ptr, ENGINEAMD_SIG, SIGLEN))
6.404 + {
6.405 + offs = ENGINEAMD_OFFS;
6.406 + }
6.407 +#elif defined OS_WIN32 // Only one Windows engine binary so far...
6.408 + if (vcmp(ptr, ENGINEW32_SIG, SIGLEN))
6.409 + {
6.410 + offs = ENGINEW32_OFFS;
6.411 + }
6.412 +#endif
6.413 +
6.414 + if (!offs || ptr[offs - 1] != IA32_CALL)
6.415 + {
6.416 + return NULL;
6.417 + }
6.418 + //get the relative offset
6.419 + void *addr = *((void **)(ptr + offs));
6.420 + //add the base offset, to the ip (which is the address+offset + 4 bytes for next instruction)
6.421 + return (CONPRINTF_FUNC)((unsigned long)addr + (unsigned long)(ptr + offs) + 4);
6.422 + }
6.423 + pBase = const_cast<ConCommandBase *>(pBase->GetNext());
6.424 + }
6.425 +
6.426 + return NULL;
6.427 +}
6.428 +
6.429 +//////////////////////////////////////////////////////////////////////
6.430 +// EVEN MORE HACKS HERE! YOU HAVE BEEN WARNED! //
6.431 +// Signatures necessary in finding the pointer to the CUtlDict that //
6.432 +// stores user message information. //
6.433 +// IServerGameDLL::GetUserMessageInfo() normally crashes with bad //
6.434 +// message indices. This is our answer to it. Yuck! <:-( //
6.435 +//////////////////////////////////////////////////////////////////////
6.436 +#ifdef OS_WIN32
6.437 + /* General Windows sig */
6.438 + #define MSGCLASS_SIGLEN 7
6.439 + #define MSGCLASS_SIG "\x8B\x0D\x2A\x2A\x2A\x2A\x56"
6.440 + #define MSGCLASS_OFFS 2
6.441 +
6.442 + /* Dystopia Wimdows hack */
6.443 + #define MSGCLASS2_SIGLEN 16
6.444 + #define MSGCLASS2_SIG "\x56\x8B\x74\x24\x2A\x85\xF6\x7C\x2A\x3B\x35\x2A\x2A\x2A\x2A\x7D"
6.445 + #define MSGCLASS2_OFFS 11
6.446 +
6.447 + /* Windows frame pointer sig */
6.448 + #define MSGCLASS3_SIGLEN 18
6.449 + #define MSGCLASS3_SIG "\x55\x8B\xEC\x51\x89\x2A\x2A\x8B\x2A\x2A\x50\x8B\x0D\x2A\x2A\x2A\x2A\xE8"
6.450 + #define MSGCLASS3_OFFS 13
6.451 +#elif defined OS_LINUX
6.452 + /* No frame pointer sig */
6.453 + #define MSGCLASS_SIGLEN 14
6.454 + #define MSGCLASS_SIG "\x53\x83\xEC\x2A\x8B\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
6.455 + #define MSGCLASS_OFFS 9
6.456 +
6.457 + /* Frame pointer sig */
6.458 + #define MSGCLASS2_SIGLEN 16
6.459 + #define MSGCLASS2_SIG "\x55\x89\xE5\x53\x83\xEC\x2A\x8B\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
6.460 + #define MSGCLASS2_OFFS 11
6.461 +#endif
6.462 +
6.463 +struct UserMessage
6.464 +{
6.465 + int size;
6.466 + const char *name;
6.467 +};
6.468 +
6.469 +typedef CUtlDict<UserMessage *, int> UserMsgDict;
6.470 +
6.471 +/* This is the ugliest function in all of SourceMM */
6.472 +bool CacheUserMessages()
6.473 +{
6.474 + /* Get address of original GetUserMessageInfo() */
6.475 + char *vfunc = (char *)SH_GET_ORIG_VFNPTR_ENTRY(server, &IServerGameDLL::GetUserMessageInfo);
6.476 +
6.477 + /* Oh dear, we have a relative jump on our hands
6.478 + * PVK II on Windows made me do this, but I suppose it doesn't hurt to check this on Linux too...
6.479 + */
6.480 + if (*vfunc == '\xE9')
6.481 + {
6.482 + /* Get address from displacement...
6.483 + *
6.484 + * Add 5 because it's relative to next instruction:
6.485 + * Opcode <1 byte> + 32-bit displacement <4 bytes>
6.486 + */
6.487 + vfunc += *reinterpret_cast<int *>(vfunc + 1) + 5;
6.488 + }
6.489 +
6.490 + CUtlDict<UserMessage *, int> *dict = NULL;
6.491 +
6.492 + if (vcmp(vfunc, MSGCLASS_SIG, MSGCLASS_SIGLEN))
6.493 + {
6.494 + /* Get address of CUserMessages instance */
6.495 + char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS_OFFS);
6.496 +
6.497 + /* Get address of CUserMessages::m_UserMessages */
6.498 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
6.499 + }
6.500 + else if (vcmp(vfunc, MSGCLASS2_SIG, MSGCLASS2_SIGLEN))
6.501 + {
6.502 + #ifdef OS_WIN32
6.503 + /* If we get here, the code is possibly inlined like in Dystopia */
6.504 +
6.505 + /* Get the address of the CUtlRBTree */
6.506 + char *rbtree = *reinterpret_cast<char **>(vfunc + MSGCLASS2_OFFS);
6.507 +
6.508 + /* CUtlDict should be 8 bytes before the CUtlRBTree (hacktacular!) */
6.509 + dict = reinterpret_cast<UserMsgDict *>(rbtree - 8);
6.510 + #elif defined OS_LINUX
6.511 + /* Get address of CUserMessages instance */
6.512 + char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS2_OFFS);
6.513 +
6.514 + /* Get address of CUserMessages::m_UserMessages */
6.515 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
6.516 + #endif
6.517 + #ifdef OS_WIN32
6.518 + }
6.519 + else if (vcmp(vfunc, MSGCLASS3_SIG, MSGCLASS3_SIGLEN))
6.520 + {
6.521 + /* Get address of CUserMessages instance */
6.522 + char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS3_OFFS);
6.523 +
6.524 + /* Get address of CUserMessages::m_UserMessages */
6.525 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
6.526 + #endif
6.527 + }
6.528 +
6.529 + if (dict)
6.530 + {
6.531 + int msg_count = dict->Count();
6.532 +
6.533 + /* Ensure that count is within bounds of an unsigned byte, because that's what engine supports */
6.534 + if (msg_count < 0 || msg_count > 255)
6.535 + {
6.536 + return false;
6.537 + }
6.538 +
6.539 + UserMessage *msg;
6.540 + UsrMsgInfo u_msg;
6.541 +
6.542 + /* Cache messages in our CUtlDict */
6.543 + for (int i = 0; i < msg_count; i++)
6.544 + {
6.545 + msg = dict->Element(i);
6.546 + u_msg.name = msg->name;
6.547 + u_msg.size = msg->size;
6.548 + usermsgs_list.push_back(u_msg);
6.549 + }
6.550 +
6.551 + return true;
6.552 + }
6.553 +
6.554 + return false;
6.555 +}
6.556 +
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/sourcemm/episode1/provider_ep1.h Fri Sep 28 21:31:02 2007 +0000
7.3 @@ -0,0 +1,53 @@
7.4 +#ifndef _INCLUDE_METAMOD_SOURCE_BASE_PROVIDER_H_
7.5 +#define _INCLUDE_METAMOD_SOURCE_BASE_PROVIDER_H_
7.6 +
7.7 +#include <sourcehook.h>
7.8 +#include <sh_memfuncinfo.h>
7.9 +#include <iserverplugin.h>
7.10 +#include "ISmmAPI.h"
7.11 +#include "metamod_provider.h"
7.12 +#include "metamod_oslink.h"
7.13 +
7.14 +using namespace SourceMM;
7.15 +using namespace SourceHook;
7.16 +
7.17 +class BaseProvider : public IMetamodSourceProvider
7.18 +{
7.19 +public:
7.20 + virtual bool IsSourceEngineBuildCompatible(int build);
7.21 + virtual bool GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo);
7.22 + virtual bool LogMessage(const char *buffer);
7.23 + virtual const char *GetCommandLineValue(const char *key, const char *defval);
7.24 + virtual void ConsolePrint(const char *msg);
7.25 + virtual bool IsRemotePrintingAvailable();
7.26 + virtual void ClientConsolePrint(edict_t *client, const char *msg);
7.27 + virtual IServerPluginCallbacks *GetVSPCallbacks(const char *iface);
7.28 + virtual void DisplayError(const char *fmt, ...);
7.29 + virtual void DisplayWarning(const char *fmt, ...);
7.30 + virtual int TryServerGameDLL(const char *iface);
7.31 + virtual void Notify_DLLInit_Pre(void *gamedll,
7.32 + CreateInterfaceFn engineFactory,
7.33 + CreateInterfaceFn serverFactory);
7.34 + virtual void ServerCommand(const char *cmd);
7.35 + virtual ConVar *CreateConVar(const char *name,
7.36 + const char *defval,
7.37 + const char *help,
7.38 + int flags);
7.39 + virtual const char *GetConVarString(ConVar *convar);
7.40 + virtual const char *GetGameDescription();
7.41 + virtual IConCommandBaseAccessor *GetConCommandBaseAccessor();
7.42 + virtual bool RegisterConCommandBase(ConCommandBase *pCommand);
7.43 + virtual void UnregisterConCommandBase(ConCommandBase *pCommand);
7.44 + virtual bool IsConCommandBaseACommand(ConCommandBase *pCommand);
7.45 + virtual int GetUserMessageCount();
7.46 + virtual int FindUserMessage(const char *name, int *size=NULL);
7.47 + virtual const char *GetUserMessage(int index, int *size=NULL);
7.48 +};
7.49 +
7.50 +extern IVEngineServer *engine;
7.51 +extern IServerGameDLL *server;
7.52 +extern IServerGameClients *gameclients;
7.53 +extern ICvar *icvar;
7.54 +
7.55 +#endif //_INCLUDE_METAMOD_SOURCE_BASE_PROVIDER_H_
7.56 +
8.1 --- a/sourcemm/metamod.cpp Thu Sep 27 20:43:03 2007 +0000
8.2 +++ b/sourcemm/metamod.cpp Fri Sep 28 21:31:02 2007 +0000
8.3 @@ -33,7 +33,6 @@
8.4 * @brief Implementation of main SourceMM GameDLL functionality
8.5 * @file sourcemm.cpp
8.6 */
8.7 -IMetamodSourceProvider *provider = NULL;
8.8
8.9 SH_DECL_MANUALHOOK4(SGD_DLLInit, 0, 0, 0, bool, CreateInterfaceFn, CreateInterfaceFn, CreateInterfaceFn, CGlobalVars *);
8.10 SH_DECL_MANUALHOOK0(SGD_GameInit, 0, 0, 0, bool);
8.11 @@ -665,7 +664,7 @@
8.12
8.13 g_GameDllPatch = SH_GET_CALLCLASS(server);
8.14
8.15 - provider->Notify_DLLInit_Pre();
8.16 + provider->Notify_DLLInit_Pre(server, engineFactory, gamedll_info.factory);
8.17
8.18 metamod_version = provider->CreateConVar("metamod_version",
8.19 SOURCEMM_VERSION,
8.20 @@ -681,9 +680,6 @@
8.21 "Metamod:Source Plugins File",
8.22 ConVarFlag_SpOnly);
8.23
8.24 - provider->CreateCommand("meta", Command_Meta, "Metamod:Source Menu");
8.25 - provider->SetClientCommandHandler(Command_ClientMeta);
8.26 -
8.27 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
8.28 if (!pluginFile)
8.29 {
8.30 @@ -1151,11 +1147,37 @@
8.31 {
8.32 if (provider->IsConCommandBaseACommand(pCommand))
8.33 {
8.34 - g_PluginMngr.AddPluginCmd(plugin, pCommand);
8.35 + g_PluginMngr.RemovePluginCmd(plugin, pCommand);
8.36 }
8.37 else
8.38 {
8.39 - g_PluginMngr.AddPluginCvar(plugin, pCommand);
8.40 + g_PluginMngr.RemovePluginCvar(plugin, pCommand);
8.41 + }
8.42 +
8.43 + PluginIter iter;
8.44 + CPluginManager::CPlugin *pPlugin;
8.45 + List<IMetamodListener *>::iterator event;
8.46 + IMetamodListener *pML;
8.47 + CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
8.48 + for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
8.49 + {
8.50 + pPlugin = (*iter);
8.51 + if (pPlugin->m_Status < Pl_Paused)
8.52 + {
8.53 + continue;
8.54 + }
8.55 + /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
8.56 + if (pPlugin->m_API->GetApiVersion() < 12)
8.57 + {
8.58 + continue;
8.59 + }
8.60 + for (event=pPlugin->m_Events.begin();
8.61 + event!=pPlugin->m_Events.end();
8.62 + event++)
8.63 + {
8.64 + pML = (*event);
8.65 + pML->OnUnlinkConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
8.66 + }
8.67 }
8.68
8.69 return provider->UnregisterConCommandBase(pCommand);
9.1 --- a/sourcemm/metamod.h Thu Sep 27 20:43:03 2007 +0000
9.2 +++ b/sourcemm/metamod.h Fri Sep 28 21:31:02 2007 +0000
9.3 @@ -79,10 +79,7 @@
9.4 void LogMessage(const char *msg, ...);
9.5 int LoadPluginsFromFile(const char *_file);
9.6
9.7 -extern PluginId g_PLID;
9.8 -extern SourceHook::ISourceHook *g_SHPtr;
9.9 extern SourceHook::CSourceHookImpl g_SourceHook;
9.10 extern MetamodSource g_Metamod;
9.11 -extern IMetamodSourceProvider *provider;
9.12
9.13 #endif //_INCLUDE_SOURCEMM_H
10.1 --- a/sourcemm/metamod_console.cpp Thu Sep 27 20:43:03 2007 +0000
10.2 +++ b/sourcemm/metamod_console.cpp Fri Sep 28 21:31:02 2007 +0000
10.3 @@ -33,7 +33,7 @@
10.4 #define CONMSG g_Metamod.ConPrintf
10.5 #define CLIENT_CONMSG g_Metamod.ClientConPrintf
10.6
10.7 -bool Command_Meta(edict_t *pEdict, IMetamodSourceCommandInfo *info)
10.8 +bool Command_Meta(IMetamodSourceCommandInfo *info)
10.9 {
10.10 unsigned int args = info->GetArgCount();
10.11
11.1 --- a/sourcemm/metamod_console.h Thu Sep 27 20:43:03 2007 +0000
11.2 +++ b/sourcemm/metamod_console.h Fri Sep 28 21:31:02 2007 +0000
11.3 @@ -13,7 +13,7 @@
11.4
11.5 #include "metamod_provider.h"
11.6
11.7 -bool Command_Meta(edict_t *pEdict, IMetamodSourceCommandInfo *info);
11.8 +bool Command_Meta(IMetamodSourceCommandInfo *info);
11.9 bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info);
11.10
11.11 #endif //_INCLUDE_CONCOMMANDS_H
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/sourcemm/metamod_oslink.cpp Fri Sep 28 21:31:02 2007 +0000
12.3 @@ -0,0 +1,89 @@
12.4 +/* ======== SourceMM ========
12.5 + * Copyright (C) 2004-2007 Metamod:Source Development Team
12.6 + * No warranties of any kind
12.7 + *
12.8 + * License: zlib/libpng
12.9 + *
12.10 + * Author(s): David "BAILOPAN" Anderson
12.11 + * ============================
12.12 + */
12.13 +
12.14 +/**
12.15 + * @brief Implements OS-dependant functions from oslink.h
12.16 + * @file oslink.cpp
12.17 + */
12.18 +
12.19 +#include "metamod_oslink.h"
12.20 +#include <malloc.h>
12.21 +#ifdef __linux
12.22 +#include <errno.h>
12.23 +#include <stdio.h>
12.24 +#endif
12.25 +
12.26 +#if defined __WIN32__ || defined _WIN32 || defined WIN32
12.27 +const char *dlerror()
12.28 +{
12.29 + static char buf[1024];
12.30 + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
12.31 + NULL, GetLastError(),
12.32 + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
12.33 + (LPTSTR) &buf, 0, NULL);
12.34 + return buf;
12.35 +}
12.36 +#endif
12.37 +
12.38 +#if defined __linux__
12.39 +int GetLastError()
12.40 +{
12.41 + return errno;
12.42 +}
12.43 +
12.44 +extern "C" void __cxa_guard_acquire(void)
12.45 +{
12.46 +}
12.47 +
12.48 +extern "C" void __cxa_guard_release(void)
12.49 +{
12.50 +}
12.51 +#endif
12.52 +
12.53 +bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
12.54 +{
12.55 +#if defined WIN32 || defined _WIN32
12.56 + MEMORY_BASIC_INFORMATION mem;
12.57 + if (!VirtualQuery(pAddr, &mem, sizeof(mem)))
12.58 + return false;
12.59 + if (mem.AllocationBase == NULL)
12.60 + return false;
12.61 + HMODULE dll = (HMODULE)mem.AllocationBase;
12.62 + GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
12.63 +#elif defined __linux__
12.64 + Dl_info info;
12.65 + if (!dladdr(pAddr, &info))
12.66 + return false;
12.67 + if (!info.dli_fbase || !info.dli_fname)
12.68 + return false;
12.69 + const char *dllpath = info.dli_fname;
12.70 + snprintf(buffer, maxlength, "%s", dllpath);
12.71 +#endif
12.72 + return true;
12.73 +}
12.74 +
12.75 +#if defined __GNUC__ && (__GNUC__ == 3 || __GNUC__ == 4)
12.76 +void * operator new(size_t size) {
12.77 + return malloc(size);
12.78 +}
12.79 +
12.80 +void * operator new[](size_t size) {
12.81 + return malloc(size);
12.82 +}
12.83 +
12.84 +void operator delete(void * ptr) {
12.85 + free(ptr);
12.86 +}
12.87 +
12.88 +void operator delete[](void * ptr) {
12.89 + free(ptr);
12.90 +}
12.91 +#endif
12.92 +
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/sourcemm/metamod_oslink.h Fri Sep 28 21:31:02 2007 +0000
13.3 @@ -0,0 +1,91 @@
13.4 +/* ======== SourceMM ========
13.5 + * Copyright (C) 2004-2007 Metamod:Source Development Team
13.6 + * No warranties of any kind
13.7 + *
13.8 + * License: zlib/libpng
13.9 + *
13.10 + * Author(s): David "BAILOPAN" Anderson
13.11 + * ============================
13.12 + */
13.13 +
13.14 +#ifndef _INCLUDE_OSLINK_H
13.15 +#define _INCLUDE_OSLINK_H
13.16 +
13.17 +/**
13.18 + * @brief Defines OS-independent information
13.19 + * @file oslink.h
13.20 + */
13.21 +
13.22 +#if defined __WIN32__ || defined _WIN32 || defined WIN32
13.23 + #define WIN32_LEAN_AND_MEAN
13.24 + #define OS_WIN32
13.25 + #if defined _MSC_VER && _MSC_VER >= 1400
13.26 + #undef ARRAYSIZE
13.27 + #else
13.28 + #define mkdir(a) _mkdir(a)
13.29 + #endif
13.30 + #include <windows.h>
13.31 + #include <io.h>
13.32 + #include <direct.h>
13.33 + #define dlmount(x) LoadLibrary(x)
13.34 + #define dlsym(x, s) GetProcAddress(x, s)
13.35 + #define dlclose(x) FreeLibrary(x)
13.36 + const char* dlerror();
13.37 + #define abspath(x, s) _fullpath(x, s, sizeof(x))
13.38 + #define PATH_SEP_STR "\\"
13.39 + #define PATH_SEP_CHAR '\\'
13.40 + #define ALT_SEP_CHAR '/'
13.41 + #define PATH_SIZE MAX_PATH
13.42 + #define SERVER_DLL "server.dll"
13.43 +#elif defined __linux__
13.44 + #define OS_LINUX
13.45 + #include <dlfcn.h>
13.46 + #include <unistd.h>
13.47 + #include <sys/types.h>
13.48 + #include <dirent.h>
13.49 + typedef void* HINSTANCE;
13.50 + #define dlmount(x) dlopen(x,RTLD_NOW)
13.51 + #define abspath(x, s) realpath(s, x)
13.52 + #define PATH_SEP_STR "/"
13.53 + #define PATH_SEP_CHAR '/'
13.54 + #define ALT_SEP_CHAR '\\'
13.55 + #define PATH_SIZE PATH_MAX
13.56 + #define stricmp strcasecmp
13.57 + #define strnicmp strncasecmp
13.58 + #define SERVER_DLL "server_i486.so"
13.59 +#endif
13.60 +
13.61 +#if defined __linux__
13.62 + extern int errno;
13.63 + int GetLastError();
13.64 +#endif
13.65 +
13.66 +bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength);
13.67 +
13.68 +#if defined __WIN32__ || defined _WIN32 || defined WIN32
13.69 + #define SMM_API extern "C" __declspec(dllexport)
13.70 +#elif defined __GNUC__
13.71 + #if (__GNUC__ == 4)
13.72 + #define SMM_API extern "C" __attribute__ ((visibility("default")))
13.73 + #else
13.74 + #define SMM_API extern "C"
13.75 + #endif
13.76 +#endif
13.77 +
13.78 +#if defined __WIN32__ || defined _WIN32 || defined WIN32
13.79 + typedef __int64 int64_t;
13.80 + typedef unsigned __int64 uint64_t;
13.81 +#elif defined __GNUC__
13.82 +#include <stdint.h>
13.83 +#if !__GLIBC_HAVE_LONG_LONG
13.84 + typedef long long int64_t;
13.85 + typedef unsigned long long uint64_t;
13.86 +#endif
13.87 +#endif
13.88 +
13.89 +#ifndef __linux__
13.90 + #define snprintf _snprintf
13.91 + #define vsnprintf _vsnprintf
13.92 +#endif
13.93 +
13.94 +#endif //_INCLUDE_OSLINK_H
14.1 --- a/sourcemm/metamod_plugins.h Thu Sep 27 20:43:03 2007 +0000
14.2 +++ b/sourcemm/metamod_plugins.h Fri Sep 28 21:31:02 2007 +0000
14.3 @@ -21,7 +21,7 @@
14.4 #include <sh_list.h>
14.5 #include <sh_string.h>
14.6 #include "IPluginManager.h"
14.7 -#include "oslink.h"
14.8 +#include "metamod_oslink.h"
14.9
14.10 /**
14.11 * History of plugin versions: (M=min, C=current)
15.1 --- a/sourcemm/metamod_provider.h Thu Sep 27 20:43:03 2007 +0000
15.2 +++ b/sourcemm/metamod_provider.h Fri Sep 28 21:31:02 2007 +0000
15.3 @@ -1,10 +1,6 @@
15.4 #ifndef _INCLUDE_METAMOD_SOURCE_SUPPORT_H_
15.5 #define _INCLUDE_METAMOD_SOURCE_SUPPORT_H_
15.6
15.7 -#include <sourcehook/sourcehook.h>
15.8 -#include <sourcehook/sh_memfuncinfo.h>
15.9 -#include <iserverplugin.h>
15.10 -
15.11 namespace SourceMM
15.12 {
15.13 enum
15.14 @@ -55,8 +51,6 @@
15.15 virtual const char *GetArgString() =0;
15.16 };
15.17
15.18 - typedef bool (*METAMOD_COMMAND)(edict_t *pEdict, IMetamodSourceCommandInfo *info);
15.19 -
15.20 class IMetamodSourceProvider
15.21 {
15.22 public:
15.23 @@ -165,7 +159,9 @@
15.24 /**
15.25 * @brief Notifies the provider that the DLLInit pre-hook is almost done.
15.26 */
15.27 - virtual void Notify_DLLInit_Pre() =0;
15.28 + virtual void Notify_DLLInit_Pre(void *gamedll,
15.29 + CreateInterfaceFn engineFactory,
15.30 + CreateInterfaceFn serverFactory) =0;
15.31
15.32 /**
15.33 * @brief Wrapper around IVEngineServer::ServerCommand()
15.34 @@ -197,24 +193,6 @@
15.35 virtual const char *GetConVarString(ConVar *convar) =0;
15.36
15.37 /**
15.38 - * @brief Creates a console command.
15.39 - *
15.40 - * @param name Command name.
15.41 - * @param callback Callback pointer.
15.42 - * @param help Help text.
15.43 - */
15.44 - virtual void CreateCommand(const char *name,
15.45 - METAMOD_COMMAND callback,
15.46 - const char *help) =0;
15.47 -
15.48 - /**
15.49 - * @brief Sets the ClientCommand handler.
15.50 - *
15.51 - * @param callback Callback pointer.
15.52 - */
15.53 - virtual void SetClientCommandHandler(METAMOD_COMMAND callback) =0;
15.54 -
15.55 - /**
15.56 * @brief Retrieves the game description.
15.57 *
15.58 * @return Game description.
15.59 @@ -279,5 +257,9 @@
15.60 };
15.61 };
15.62
15.63 +extern PluginId g_PLID;
15.64 +extern SourceHook::ISourceHook *g_SHPtr;
15.65 +extern SourceMM::IMetamodSourceProvider *provider;
15.66 +
15.67 #endif //_INCLUDE_METAMOD_SOURCE_SUPPORT_H_
15.68
16.1 --- a/sourcemm/metamod_util.cpp Thu Sep 27 20:43:03 2007 +0000
16.2 +++ b/sourcemm/metamod_util.cpp Fri Sep 28 21:31:02 2007 +0000
16.3 @@ -12,7 +12,7 @@
16.4 #include <string.h>
16.5 #include <stdio.h>
16.6 #include "metamod_util.h"
16.7 -#include "oslink.h"
16.8 +#include "metamod_oslink.h"
16.9
16.10 /**
16.11 * @brief Utility functions
17.1 --- a/sourcemm/msvc8/sourcemm.sln Thu Sep 27 20:43:03 2007 +0000
17.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
17.3 @@ -1,20 +0,0 @@
17.4 -
17.5 -Microsoft Visual Studio Solution File, Format Version 9.00
17.6 -# Visual Studio 2005
17.7 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sourcemm", "sourcemm.vcproj", "{F7D47743-73B3-49B5-9D76-2333C5DFD565}"
17.8 -EndProject
17.9 -Global
17.10 - GlobalSection(SolutionConfigurationPlatforms) = preSolution
17.11 - Debug|Win32 = Debug|Win32
17.12 - Release|Win32 = Release|Win32
17.13 - EndGlobalSection
17.14 - GlobalSection(ProjectConfigurationPlatforms) = postSolution
17.15 - {F7D47743-73B3-49B5-9D76-2333C5DFD565}.Debug|Win32.ActiveCfg = Debug|Win32
17.16 - {F7D47743-73B3-49B5-9D76-2333C5DFD565}.Debug|Win32.Build.0 = Debug|Win32
17.17 - {F7D47743-73B3-49B5-9D76-2333C5DFD565}.Release|Win32.ActiveCfg = Release|Win32
17.18 - {F7D47743-73B3-49B5-9D76-2333C5DFD565}.Release|Win32.Build.0 = Release|Win32
17.19 - EndGlobalSection
17.20 - GlobalSection(SolutionProperties) = preSolution
17.21 - HideSolutionNode = FALSE
17.22 - EndGlobalSection
17.23 -EndGlobal
18.1 --- a/sourcemm/msvc8/sourcemm.vcproj Thu Sep 27 20:43:03 2007 +0000
18.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
18.3 @@ -1,336 +0,0 @@
18.4 -<?xml version="1.0" encoding="Windows-1252"?>
18.5 -<VisualStudioProject
18.6 - ProjectType="Visual C++"
18.7 - Version="8.00"
18.8 - Name="sourcemm"
18.9 - ProjectGUID="{F7D47743-73B3-49B5-9D76-2333C5DFD565}"
18.10 - RootNamespace="sourcemm"
18.11 - Keyword="Win32Proj"
18.12 - >
18.13 - <Platforms>
18.14 - <Platform
18.15 - Name="Win32"
18.16 - />
18.17 - </Platforms>
18.18 - <ToolFiles>
18.19 - </ToolFiles>
18.20 - <Configurations>
18.21 - <Configuration
18.22 - Name="Debug|Win32"
18.23 - OutputDirectory="Debug"
18.24 - IntermediateDirectory="Debug"
18.25 - ConfigurationType="2"
18.26 - InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
18.27 - CharacterSet="2"
18.28 - >
18.29 - <Tool
18.30 - Name="VCPreBuildEventTool"
18.31 - />
18.32 - <Tool
18.33 - Name="VCCustomBuildTool"
18.34 - />
18.35 - <Tool
18.36 - Name="VCXMLDataGeneratorTool"
18.37 - />
18.38 - <Tool
18.39 - Name="VCWebServiceProxyGeneratorTool"
18.40 - />
18.41 - <Tool
18.42 - Name="VCMIDLTool"
18.43 - />
18.44 - <Tool
18.45 - Name="VCCLCompilerTool"
18.46 - Optimization="0"
18.47 - AdditionalIncludeDirectories="..;..\..;..\..\sourcehook"
18.48 - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SOURCEMM_EXPORTS;_CRT_SECURE_NO_DEPRECATE"
18.49 - MinimalRebuild="true"
18.50 - BasicRuntimeChecks="3"
18.51 - RuntimeLibrary="1"
18.52 - RuntimeTypeInfo="false"
18.53 - UsePrecompiledHeader="0"
18.54 - WarningLevel="3"
18.55 - Detect64BitPortabilityProblems="false"
18.56 - DebugInformationFormat="4"
18.57 - />
18.58 - <Tool
18.59 - Name="VCManagedResourceCompilerTool"
18.60 - />
18.61 - <Tool
18.62 - Name="VCResourceCompilerTool"
18.63 - />
18.64 - <Tool
18.65 - Name="VCPreLinkEventTool"
18.66 - />
18.67 - <Tool
18.68 - Name="VCLinkerTool"
18.69 - OutputFile="$(OutDir)/server.dll"
18.70 - LinkIncremental="2"
18.71 - IgnoreDefaultLibraryNames="libc.lib;libcd.lib;libcmt.lib"
18.72 - GenerateDebugInformation="true"
18.73 - ProgramDatabaseFile="$(OutDir)/sourcemm.pdb"
18.74 - SubSystem="2"
18.75 - EnableCOMDATFolding="1"
18.76 - ImportLibrary="$(OutDir)/sourcemm.lib"
18.77 - TargetMachine="1"
18.78 - />
18.79 - <Tool
18.80 - Name="VCALinkTool"
18.81 - />
18.82 - <Tool
18.83 - Name="VCManifestTool"
18.84 - />
18.85 - <Tool
18.86 - Name="VCXDCMakeTool"
18.87 - />
18.88 - <Tool
18.89 - Name="VCBscMakeTool"
18.90 - />
18.91 - <Tool
18.92 - Name="VCFxCopTool"
18.93 - />
18.94 - <Tool
18.95 - Name="VCAppVerifierTool"
18.96 - />
18.97 - <Tool
18.98 - Name="VCWebDeploymentTool"
18.99 - />
18.100 - <Tool
18.101 - Name="VCPostBuildEventTool"
18.102 - />
18.103 - </Configuration>
18.104 - <Configuration
18.105 - Name="Release|Win32"
18.106 - OutputDirectory="Release"
18.107 - IntermediateDirectory="Release"
18.108 - ConfigurationType="2"
18.109 - InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
18.110 - CharacterSet="2"
18.111 - >
18.112 - <Tool
18.113 - Name="VCPreBuildEventTool"
18.114 - />
18.115 - <Tool
18.116 - Name="VCCustomBuildTool"
18.117 - />
18.118 - <Tool
18.119 - Name="VCXMLDataGeneratorTool"
18.120 - />
18.121 - <Tool
18.122 - Name="VCWebServiceProxyGeneratorTool"
18.123 - />
18.124 - <Tool
18.125 - Name="VCMIDLTool"
18.126 - />
18.127 - <Tool
18.128 - Name="VCCLCompilerTool"
18.129 - Optimization="3"
18.130 - FavorSizeOrSpeed="1"
18.131 - OmitFramePointers="true"
18.132 - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SOURCEMM_EXPORTS;_CRT_SECURE_NO_DEPRECATE"
18.133 - StringPooling="true"
18.134 - ExceptionHandling="1"
18.135 - RuntimeLibrary="0"
18.136 - BufferSecurityCheck="false"
18.137 - RuntimeTypeInfo="false"
18.138 - UsePrecompiledHeader="0"
18.139 - WarningLevel="3"
18.140 - Detect64BitPortabilityProblems="false"
18.141 - DebugInformationFormat="3"
18.142 - />
18.143 - <Tool
18.144 - Name="VCManagedResourceCompilerTool"
18.145 - />
18.146 - <Tool
18.147 - Name="VCResourceCompilerTool"
18.148 - />
18.149 - <Tool
18.150 - Name="VCPreLinkEventTool"
18.151 - />
18.152 - <Tool
18.153 - Name="VCLinkerTool"
18.154 - AdditionalDependencies="tier0.lib tier1.lib vstdlib.lib"
18.155 - OutputFile="$(OutDir)/server.dll"
18.156 - LinkIncremental="1"
18.157 - IgnoreDefaultLibraryNames="libc.lib;libcd.lib;libcmtd.lib"
18.158 - GenerateDebugInformation="true"
18.159 - SubSystem="2"
18.160 - OptimizeReferences="2"
18.161 - EnableCOMDATFolding="2"
18.162 - ImportLibrary="$(OutDir)/sourcemm.lib"
18.163 - TargetMachine="1"
18.164 - />
18.165 - <Tool
18.166 - Name="VCALinkTool"
18.167 - />
18.168 - <Tool
18.169 - Name="VCManifestTool"
18.170 - />
18.171 - <Tool
18.172 - Name="VCXDCMakeTool"
18.173 - />
18.174 - <Tool
18.175 - Name="VCBscMakeTool"
18.176 - />
18.177 - <Tool
18.178 - Name="VCFxCopTool"
18.179 - />
18.180 - <Tool
18.181 - Name="VCAppVerifierTool"
18.182 - />
18.183 - <Tool
18.184 - Name="VCWebDeploymentTool"
18.185 - />
18.186 - <Tool
18.187 - Name="VCPostBuildEventTool"
18.188 - />
18.189 - </Configuration>
18.190 - </Configurations>
18.191 - <References>
18.192 - </References>
18.193 - <Files>
18.194 - <Filter
18.195 - Name="Source Files"
18.196 - Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
18.197 - UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
18.198 - >
18.199 - <File
18.200 - RelativePath="..\metamod.cpp"
18.201 - >
18.202 - </File>
18.203 - <File
18.204 - RelativePath="..\metamod_console.cpp"
18.205 - >
18.206 - </File>
18.207 - <File
18.208 - RelativePath="..\metamod_plugins.cpp"
18.209 - >
18.210 - </File>
18.211 - <File
18.212 - RelativePath="..\metamod_util.cpp"
18.213 - >
18.214 - </File>
18.215 - <File
18.216 - RelativePath="..\oslink.cpp"
18.217 - >
18.218 - </File>
18.219 - </Filter>
18.220 - <Filter
18.221 - Name="Header Files"
18.222 - Filter="h;hpp;hxx;hm;inl;inc;xsd"
18.223 - UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
18.224 - >
18.225 - <File
18.226 - RelativePath="..\metamod.h"
18.227 - >
18.228 - </File>
18.229 - <File
18.230 - RelativePath="..\metamod_console.h"
18.231 - >
18.232 - </File>
18.233 - <File
18.234 - RelativePath="..\metamod_plugins.h"
18.235 - >
18.236 - </File>
18.237 - <File
18.238 - RelativePath="..\metamod_util.h"
18.239 - >
18.240 - </File>
18.241 - <File
18.242 - RelativePath="..\oslink.h"
18.243 - >
18.244 - </File>
18.245 - </Filter>
18.246 - <Filter
18.247 - Name="Resource Files"
18.248 - Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
18.249 - UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
18.250 - >
18.251 - <File
18.252 - RelativePath="..\version.rc"
18.253 - >
18.254 - </File>
18.255 - </Filter>
18.256 - <Filter
18.257 - Name="Interfaces"
18.258 - >
18.259 - <File
18.260 - RelativePath="..\IPluginManager.h"
18.261 - >
18.262 - </File>
18.263 - <File
18.264 - RelativePath="..\ISmmAPI.h"
18.265 - >
18.266 - </File>
18.267 - <File
18.268 - RelativePath="..\ISmmPlugin.h"
18.269 - >
18.270 - </File>
18.271 - <File
18.272 - RelativePath="..\metamod_provider.h"
18.273 - >
18.274 - </File>
18.275 - </Filter>
18.276 - <Filter
18.277 - Name="SourceHook"
18.278 - >
18.279 - <File
18.280 - RelativePath="..\..\sourcehook\sh_list.h"
18.281 - >
18.282 - </File>
18.283 - <File
18.284 - RelativePath="..\..\sourcehook\sh_stack.h"
18.285 - >
18.286 - </File>
18.287 - <File
18.288 - RelativePath="..\..\sourcehook\sh_string.h"
18.289 - >
18.290 - </File>
18.291 - <File
18.292 - RelativePath="..\..\sourcehook\sh_tinyhash.h"
18.293 - >
18.294 - </File>
18.295 - <File
18.296 - RelativePath="..\..\sourcehook\sh_vector.h"
18.297 - >
18.298 - </File>
18.299 - <Filter
18.300 - Name="Headers"
18.301 - >
18.302 - <File
18.303 - RelativePath="..\..\sourcehook\FastDelegate.h"
18.304 - >
18.305 - </File>
18.306 - <File
18.307 - RelativePath="..\..\sourcehook\sh_memfuncinfo.h"
18.308 - >
18.309 - </File>
18.310 - <File
18.311 - RelativePath="..\..\sourcehook\sh_memory.h"
18.312 - >
18.313 - </File>
18.314 - <File
18.315 - RelativePath="..\..\sourcehook\sourcehook.cpp"
18.316 - >
18.317 - </File>
18.318 - <File
18.319 - RelativePath="..\..\sourcehook\sourcehook.h"
18.320 - >
18.321 - </File>
18.322 - <File
18.323 - RelativePath="..\..\sourcehook\sourcehook_impl.h"
18.324 - >
18.325 - </File>
18.326 - </Filter>
18.327 - </Filter>
18.328 - <Filter
18.329 - Name="HL2SDK"
18.330 - >
18.331 - <File
18.332 - RelativePath="..\convar_smm.h"
18.333 - >
18.334 - </File>
18.335 - </Filter>
18.336 - </Files>
18.337 - <Globals>
18.338 - </Globals>
18.339 -</VisualStudioProject>
19.1 --- a/sourcemm/oslink.cpp Thu Sep 27 20:43:03 2007 +0000
19.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
19.3 @@ -1,89 +0,0 @@
19.4 -/* ======== SourceMM ========
19.5 - * Copyright (C) 2004-2007 Metamod:Source Development Team
19.6 - * No warranties of any kind
19.7 - *
19.8 - * License: zlib/libpng
19.9 - *
19.10 - * Author(s): David "BAILOPAN" Anderson
19.11 - * ============================
19.12 - */
19.13 -
19.14 -/**
19.15 - * @brief Implements OS-dependant functions from oslink.h
19.16 - * @file oslink.cpp
19.17 - */
19.18 -
19.19 -#include "oslink.h"
19.20 -#include <malloc.h>
19.21 -#ifdef __linux
19.22 -#include <errno.h>
19.23 -#include <stdio.h>
19.24 -#endif
19.25 -
19.26 -#if defined __WIN32__ || defined _WIN32 || defined WIN32
19.27 -const char *dlerror()
19.28 -{
19.29 - static char buf[1024];
19.30 - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
19.31 - NULL, GetLastError(),
19.32 - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
19.33 - (LPTSTR) &buf, 0, NULL);
19.34 - return buf;
19.35 -}
19.36 -#endif
19.37 -
19.38 -#if defined __linux__
19.39 -int GetLastError()
19.40 -{
19.41 - return errno;
19.42 -}
19.43 -
19.44 -extern "C" void __cxa_guard_acquire(void)
19.45 -{
19.46 -}
19.47 -
19.48 -extern "C" void __cxa_guard_release(void)
19.49 -{
19.50 -}
19.51 -#endif
19.52 -
19.53 -bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
19.54 -{
19.55 -#if defined WIN32 || defined _WIN32
19.56 - MEMORY_BASIC_INFORMATION mem;
19.57 - if (!VirtualQuery(pAddr, &mem, sizeof(mem)))
19.58 - return false;
19.59 - if (mem.AllocationBase == NULL)
19.60 - return false;
19.61 - HMODULE dll = (HMODULE)mem.AllocationBase;
19.62 - GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
19.63 -#elif defined __linux__
19.64 - Dl_info info;
19.65 - if (!dladdr(pAddr, &info))
19.66 - return false;
19.67 - if (!info.dli_fbase || !info.dli_fname)
19.68 - return false;
19.69 - const char *dllpath = info.dli_fname;
19.70 - snprintf(buffer, maxlength, "%s", dllpath);
19.71 -#endif
19.72 - return true;
19.73 -}
19.74 -
19.75 -#if defined __GNUC__ && (__GNUC__ == 3 || __GNUC__ == 4)
19.76 -void * operator new(size_t size) {
19.77 - return malloc(size);
19.78 -}
19.79 -
19.80 -void * operator new[](size_t size) {
19.81 - return malloc(size);
19.82 -}
19.83 -
19.84 -void operator delete(void * ptr) {
19.85 - free(ptr);
19.86 -}
19.87 -
19.88 -void operator delete[](void * ptr) {
19.89 - free(ptr);
19.90 -}
19.91 -#endif
19.92 -
20.1 --- a/sourcemm/oslink.h Thu Sep 27 20:43:03 2007 +0000
20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
20.3 @@ -1,91 +0,0 @@
20.4 -/* ======== SourceMM ========
20.5 - * Copyright (C) 2004-2007 Metamod:Source Development Team
20.6 - * No warranties of any kind
20.7 - *
20.8 - * License: zlib/libpng
20.9 - *
20.10 - * Author(s): David "BAILOPAN" Anderson
20.11 - * ============================
20.12 - */
20.13 -
20.14 -#ifndef _INCLUDE_OSLINK_H
20.15 -#define _INCLUDE_OSLINK_H
20.16 -
20.17 -/**
20.18 - * @brief Defines OS-independent information
20.19 - * @file oslink.h
20.20 - */
20.21 -
20.22 -#if defined __WIN32__ || defined _WIN32 || defined WIN32
20.23 - #define WIN32_LEAN_AND_MEAN
20.24 - #define OS_WIN32
20.25 - #if defined _MSC_VER && _MSC_VER >= 1400
20.26 - #undef ARRAYSIZE
20.27 - #else
20.28 - #define mkdir(a) _mkdir(a)
20.29 - #endif
20.30 - #include <windows.h>
20.31 - #include <io.h>
20.32 - #include <direct.h>
20.33 - #define dlmount(x) LoadLibrary(x)
20.34 - #define dlsym(x, s) GetProcAddress(x, s)
20.35 - #define dlclose(x) FreeLibrary(x)
20.36 - const char* dlerror();
20.37 - #define abspath(x, s) _fullpath(x, s, sizeof(x))
20.38 - #define PATH_SEP_STR "\\"
20.39 - #define PATH_SEP_CHAR '\\'
20.40 - #define ALT_SEP_CHAR '/'
20.41 - #define PATH_SIZE MAX_PATH
20.42 - #define SERVER_DLL "server.dll"
20.43 -#elif defined __linux__
20.44 - #define OS_LINUX
20.45 - #include <dlfcn.h>
20.46 - #include <unistd.h>
20.47 - #include <sys/types.h>
20.48 - #include <dirent.h>
20.49 - typedef void* HINSTANCE;
20.50 - #define dlmount(x) dlopen(x,RTLD_NOW)
20.51 - #define abspath(x, s) realpath(s, x)
20.52 - #define PATH_SEP_STR "/"
20.53 - #define PATH_SEP_CHAR '/'
20.54 - #define ALT_SEP_CHAR '\\'
20.55 - #define PATH_SIZE PATH_MAX
20.56 - #define stricmp strcasecmp
20.57 - #define strnicmp strncasecmp
20.58 - #define SERVER_DLL "server_i486.so"
20.59 -#endif
20.60 -
20.61 -#if defined __linux__
20.62 - extern int errno;
20.63 - int GetLastError();
20.64 -#endif
20.65 -
20.66 -bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength);
20.67 -
20.68 -#if defined __WIN32__ || defined _WIN32 || defined WIN32
20.69 - #define SMM_API extern "C" __declspec(dllexport)
20.70 -#elif defined __GNUC__
20.71 - #if (__GNUC__ == 4)
20.72 - #define SMM_API extern "C" __attribute__ ((visibility("default")))
20.73 - #else
20.74 - #define SMM_API extern "C"
20.75 - #endif
20.76 -#endif
20.77 -
20.78 -#if defined __WIN32__ || defined _WIN32 || defined WIN32
20.79 - typedef __int64 int64_t;
20.80 - typedef unsigned __int64 uint64_t;
20.81 -#elif defined __GNUC__
20.82 -#include <stdint.h>
20.83 -#if !__GLIBC_HAVE_LONG_LONG
20.84 - typedef long long int64_t;
20.85 - typedef unsigned long long uint64_t;
20.86 -#endif
20.87 -#endif
20.88 -
20.89 -#ifndef __linux__
20.90 - #define snprintf _snprintf
20.91 - #define vsnprintf _vsnprintf
20.92 -#endif
20.93 -
20.94 -#endif //_INCLUDE_OSLINK_H