From 467d57059aa7b8bfa24e8eb440cc8863cbe924a0 Mon Sep 17 00:00:00 2001 From: Nick Hastings Date: Sun, 6 May 2018 12:59:33 -0400 Subject: [PATCH] Out with the old ConVar accessibility hacks, in with the new. --- core/AMBuilder | 2 + core/CoreConfig.cpp | 7 +- core/convar_sm.h | 551 --------------------- core/convar_sm_bms.h | 729 ---------------------------- core/convar_sm_l4d.h | 718 --------------------------- core/convar_sm_ob.h | 709 --------------------------- core/convar_sm_swarm.h | 1042 ---------------------------------------- core/logic_bridge.cpp | 15 +- core/sm_convar.h | 38 ++ core/smn_console.cpp | 18 +- core/sourcemm_api.h | 15 +- 11 files changed, 56 insertions(+), 3788 deletions(-) delete mode 100644 core/convar_sm.h delete mode 100644 core/convar_sm_bms.h delete mode 100644 core/convar_sm_l4d.h delete mode 100644 core/convar_sm_ob.h delete mode 100644 core/convar_sm_swarm.h create mode 100644 core/sm_convar.h diff --git a/core/AMBuilder b/core/AMBuilder index 81442eb4..9cdad724 100644 --- a/core/AMBuilder +++ b/core/AMBuilder @@ -64,6 +64,8 @@ for sdk_name in SM.sdks: os.path.join(sdk.path, 'public', 'game', 'shared', 'csgo', 'protobuf') ] + if compiler.like('msvc'): + compiler.defines += ['_XKEYCHECK_H'] if builder.target.platform == 'linux': compiler.postlink += ['-lpthread', '-lrt'] diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp index 766edbf0..c1fb80f1 100644 --- a/core/CoreConfig.cpp +++ b/core/CoreConfig.cpp @@ -412,8 +412,11 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create) for (iter = convars->begin(); iter != convars->end(); iter++) { const ConVar *cvar = (*iter); - - if ((cvar->GetFlags() & FCVAR_DONTRECORD) == FCVAR_DONTRECORD) +#if SOURCE_ENGINE >= SE_ORANGEBOX + if (cvar->IsFlagSet(FCVAR_DONTRECORD)) +#else + if (cvar->IsBitSet(FCVAR_DONTRECORD)) +#endif { continue; } diff --git a/core/convar_sm.h b/core/convar_sm.h deleted file mode 100644 index 0981bb3d..00000000 --- a/core/convar_sm.h +++ /dev/null @@ -1,551 +0,0 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $Workfile: $ -// $Date: 2006-08-13 06:34:30 -0500 (Sun, 13 Aug 2006) $ -// -//----------------------------------------------------------------------------- -// $NoKeywords: $ -//=============================================================================// - -#ifndef CONVAR_H -#define CONVAR_H -#if _WIN32 -#pragma once -#endif - -#include "tier0/dbg.h" - -#ifdef _WIN32 -#define FORCEINLINE_CVAR FORCEINLINE -#elif _LINUX -#define FORCEINLINE_CVAR __inline__ FORCEINLINE -#else -#error "implement me" -#endif - -// The default, no flags at all -#define FCVAR_NONE 0 - -// Command to ConVars and ConCommands -// ConVar Systems -#define FCVAR_UNREGISTERED (1<<0) // If this is set, don't add to linked list, etc. -#define FCVAR_LAUNCHER (1<<1) // defined by launcher -#define FCVAR_GAMEDLL (1<<2) // defined by the game DLL -#define FCVAR_CLIENTDLL (1<<3) // defined by the client DLL -#define FCVAR_MATERIAL_SYSTEM (1<<4) // Defined by the material system. -#define FCVAR_DATACACHE (1<<19) // Defined by the datacache system. -#define FCVAR_STUDIORENDER (1<<15) // Defined by the studiorender system. -#define FCVAR_FILESYSTEM (1<<21) // Defined by the file system. -#define FCVAR_PLUGIN (1<<18) // Defined by a 3rd party plugin. -#define FCVAR_TOOLSYSTEM (1<<20) // Defined by an IToolSystem library -#define FCVAR_SOUNDSYSTEM (1<<23) // Defined by the soundsystem library -#define FCVAR_INPUTSYSTEM (1<<25) // Defined by the inputsystem dll -#define FCVAR_NETWORKSYSTEM (1<<26) // Defined by the network system -// NOTE!! if you add a cvar system, add it here too!!!! -// the engine lacks a cvar flag, but needs it for xbox -// an engine cvar is thus a cvar not marked with any other system -#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)) - -// ConVar only -#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 -#define FCVAR_SPONLY (1<<6) // This cvar cannot be changed by clients connected to a multiplayer server. -#define FCVAR_ARCHIVE (1<<7) // set to cause it to be saved to vars.rc -#define FCVAR_NOTIFY (1<<8) // notifies players when changed -#define FCVAR_USERINFO (1<<9) // changes the client's info string -#define FCVAR_CHEAT (1<<14) // Only useable in singleplayer / debug / multiplayer & sv_cheats - -#define FCVAR_PRINTABLEONLY (1<<10) // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ). -#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 -#define FCVAR_NEVER_AS_STRING (1<<12) // never try to print that cvar - -// It's a ConVar that's shared between the client and the server. -// At signon, the values of all such ConVars are sent from the server to the client (skipped for local -// client, of course ) -// If a change is requested it must come from the console (i.e., no remote client changes) -// If a value is changed while a server is active, it's replicated to all connected clients -#define FCVAR_REPLICATED (1<<13) // server setting enforced on clients, TODO rename to FCAR_SERVER at some time -#define FCVAR_DEMO (1<<16) // record this cvar when starting a demo file -#define FCVAR_DONTRECORD (1<<17) // don't record these command in demofiles - -#define FCVAR_NOT_CONNECTED (1<<22) // cvar cannot be changed by a client that is connected to a server - -#define FCVAR_ARCHIVE_XBOX (1<<24) // cvar written to config.cfg on the Xbox - - -// #define FCVAR_AVAILABLE (1<<27) -// #define FCVAR_AVAILABLE (1<<28) -// #define FCVAR_AVAILABLE (1<<29) -// #define FCVAR_AVAILABLE (1<<30) -// #define FCVAR_AVAILABLE (1<<31) - - -class ConVar; -class ConCommand; -class ConCommandBase; - -// Any executable that wants to use ConVars need to implement one of -// these to hook up access to console variables. -class IConCommandBaseAccessor -{ -public: - // Flags is a combination of FCVAR flags in cvar.h. - // hOut is filled in with a handle to the variable. - virtual bool RegisterConCommandBase( ConCommandBase *pVar )=0; -}; - - -// You don't have to instantiate one of these, just call its -// OneTimeInit function when your executable is initializing. -class ConCommandBaseMgr -{ -public: - // Call this ONCE when the executable starts up. - static void OneTimeInit( IConCommandBaseAccessor *pAccessor ); -#ifdef _XBOX - static bool Fixup( ConCommandBase* pConCommandBase ); -#ifndef _RETAIL - static void PublishCommands( bool bForce ); -#endif -#endif -}; - -// Called when a ConVar changes value -typedef void ( *FnChangeCallback )( ConVar *var, char const *pOldString ); - -// Called when a ConCommand needs to execute -typedef void ( *FnCommandCallback )( void ); - -#define COMMAND_COMPLETION_MAXITEMS 64 -#define COMMAND_COMPLETION_ITEM_LENGTH 64 - -// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings -typedef int ( *FnCommandCompletionCallback )( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ); - -//----------------------------------------------------------------------------- -// Purpose: The base console invoked command/cvar interface -//----------------------------------------------------------------------------- -class ConCommandBase -{ - friend class ConCommandBaseMgr; - friend class CCvar; - friend class ConVar; - friend class ConCommand; - -public: - ConCommandBase( void ); - ConCommandBase( char const *pName, char const *pHelpString = 0, - int flags = 0 ); - - virtual ~ConCommandBase( void ); - - virtual bool IsCommand( void ) const; - - // Check flag - virtual bool IsBitSet( int flag ) const; - // Set flag - virtual void AddFlags( int flags ); - - // Return name of cvar - virtual char const *GetName( void ) const; - - // Return help text for cvar - virtual char const *GetHelpText( void ) const; - - // Deal with next pointer - const ConCommandBase *GetNext( void ) const; - void SetNext( ConCommandBase *next ); - - virtual bool IsRegistered( void ) const; - - // Global methods - static ConCommandBase const *GetCommands( void ); - static void AddToList( ConCommandBase *var ); - static void RemoveFlaggedCommands( int flag ); - static void RevertFlaggedCvars( int flag ); - static ConCommandBase const *FindCommand( char const *name ); - -protected: - virtual void Create( char const *pName, char const *pHelpString = 0, - int flags = 0 ); - - // Used internally by OneTimeInit to initialize. - virtual void Init(); - - // Internal copy routine ( uses new operator from correct module ) - char *CopyString( char const *from ); - - // Next ConVar in chain - ConCommandBase *m_pNext; - -private: - // Has the cvar been added to the global list? - bool m_bRegistered; - - // Static data - char const *m_pszName; - char const *m_pszHelpString; - - // ConVar flags - int m_nFlags; - -protected: - - // ConVars add themselves to this list for the executable. Then ConVarMgr::Init() runs through - // all the console variables and registers them. - static ConCommandBase *s_pConCommandBases; - - // ConVars in this executable use this 'global' to access values. - static IConCommandBaseAccessor *s_pAccessor; - -public: // Hackalicous - inline int GetFlags() const - { - return m_nFlags; - } - inline void SetFlags(int flags) - { - m_nFlags = flags; - } -}; - -//----------------------------------------------------------------------------- -// Purpose: The console invoked command -//----------------------------------------------------------------------------- -class ConCommand : public ConCommandBase -{ -friend class ConCommandBaseMgr; -friend class CCvar; -#ifdef _STATIC_LINKED -friend class G_ConCommand; -friend class C_ConCommand; -friend class M_ConCommand; -friend class S_ConCommand; -friend class D_ConCommand; -#endif - -public: - typedef ConCommandBase BaseClass; - - ConCommand( void ); - ConCommand( char const *pName, FnCommandCallback callback, - char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); - - virtual ~ConCommand( void ); - - virtual bool IsCommand( void ) const; - - virtual int AutoCompleteSuggest( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ); - - virtual bool CanAutoComplete( void ); - - // Invoke the function - virtual void Dispatch( void ); -private: - virtual void Create( char const *pName, FnCommandCallback callback, - char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); - - // Call this function when executing the command - FnCommandCallback m_fnCommandCallback; - - FnCommandCompletionCallback m_fnCompletionCallback; - bool m_bHasCompletionCallback; -public: // Hackalicous - inline FnCommandCallback GetCallback() const - { - return m_fnCommandCallback; - } -}; - -//----------------------------------------------------------------------------- -// Purpose: A console variable -//----------------------------------------------------------------------------- -class ConVar : public ConCommandBase -{ -friend class ConCommandBaseMgr; -friend class CCvar; -friend class CDefaultCvar; -#ifdef _STATIC_LINKED -friend class G_ConVar; -friend class C_ConVar; -friend class M_ConVar; -friend class S_ConVar; -friend class D_ConVar; -#endif - -public: - typedef ConCommandBase BaseClass; - - ConVar( char const *pName, char const *pDefaultValue, int flags = 0); - - ConVar( char const *pName, char const *pDefaultValue, int flags, - char const *pHelpString ); - ConVar( char const *pName, char const *pDefaultValue, int flags, - char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ); - ConVar( char const *pName, char const *pDefaultValue, int flags, - char const *pHelpString, FnChangeCallback callback ); - ConVar( char const *pName, char const *pDefaultValue, int flags, - char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, - FnChangeCallback callback ); - - virtual ~ConVar( void ); - - virtual bool IsBitSet( int flag ) const; - virtual char const* GetHelpText( void ) const; - virtual bool IsRegistered( void ) const; - virtual char const *GetName( void ) const; - virtual void AddFlags( int flags ); - virtual bool IsCommand( void ) const; - - // Install a change callback (there shouldn't already be one....) - void InstallChangeCallback( FnChangeCallback callback ); - - // Retrieve value - FORCEINLINE_CVAR float GetFloat( void ) const; - FORCEINLINE_CVAR int GetInt( void ) const; - FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); } - FORCEINLINE_CVAR char const *GetString( void ) const; - - // Any function that allocates/frees memory needs to be virtual or else you'll have crashes - // from alloc/free across dll/exe boundaries. - - // These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue). - virtual void SetValue( char const *value ); - virtual void SetValue( float value ); - virtual void SetValue( int value ); - - // Reset to default value - void Revert( void ); - - // True if it has a min/max setting - bool GetMin( float& minVal ) const; - bool GetMax( float& maxVal ) const; - char const *GetDefault( void ) const; - - static void RevertAll( void ); -private: - // Called by CCvar when the value of a var is changing. - virtual void InternalSetValue(char const *value); - // For CVARs marked FCVAR_NEVER_AS_STRING - virtual void InternalSetFloatValue( float fNewValue ); - virtual void InternalSetIntValue( int nValue ); - - virtual bool ClampValue( float& value ); - virtual void ChangeStringValue( char const *tempVal ); - - virtual void Create( char const *pName, char const *pDefaultValue, int flags = 0, - char const *pHelpString = 0, bool bMin = false, float fMin = 0.0, - bool bMax = false, float fMax = false, FnChangeCallback callback = 0 ); - - // Used internally by OneTimeInit to initialize. - virtual void Init(); - -private: - - // This either points to "this" or it points to the original declaration of a ConVar. - // This allows ConVars to exist in separate modules, and they all use the first one to be declared. - // m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar). - ConVar *m_pParent; - - // Static data - char const *m_pszDefaultValue; - - // Value - // Dynamically allocated - char *m_pszString; - int m_StringLength; - - // Values - float m_fValue; - int m_nValue; - - // Min/Max values - bool m_bHasMin; - float m_fMinVal; - bool m_bHasMax; - float m_fMaxVal; - - // Call this function when ConVar changes - FnChangeCallback m_fnChangeCallback; -public: // Hackalicous - inline FnChangeCallback GetCallback() const - { - return m_fnChangeCallback; - } - inline void SetMin(bool set, float min=0.0) - { - m_bHasMin = set; - m_fMinVal = min; - } - inline void SetMax(bool set, float max=0.0) - { - m_bHasMax = set; - m_fMaxVal = max; - } -}; - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a float -// Output : float -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR float ConVar::GetFloat( void ) const -{ - return m_pParent->m_fValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -// Output : int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR int ConVar::GetInt( void ) const -{ - return m_pParent->m_nValue; -} - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. -// Output : char const * -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR char const *ConVar::GetString( void ) const -{ - if ( m_nFlags & FCVAR_NEVER_AS_STRING ) - { - return "FCVAR_NEVER_AS_STRING"; - } - - return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : ""; -} - - -#ifdef _STATIC_LINKED -// identifies subsystem via piggybacking constructors with flags -class G_ConCommand : public ConCommand -{ -public: - 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) {} -}; - -class C_ConCommand : public ConCommand -{ -public: - 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) {} -}; - -class M_ConCommand : public ConCommand -{ -public: - 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) {} -}; - -class S_ConCommand : public ConCommand -{ -public: - 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) {} -}; - -class D_ConCommand : public ConCommand -{ -public: - 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) {} -}; - -typedef void ( *G_FnChangeCallback )( G_ConVar *var, char const *pOldString ); -typedef void ( *C_FnChangeCallback )( C_ConVar *var, char const *pOldString ); -typedef void ( *M_FnChangeCallback )( M_ConVar *var, char const *pOldString ); -typedef void ( *S_FnChangeCallback )( S_ConVar *var, char const *pOldString ); -typedef void ( *D_FnChangeCallback )( D_ConVar *var, char const *pOldString ); - -class G_ConVar : public ConVar -{ -public: - G_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL) {} - G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString ) {} - 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) {} - 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 ) {} - 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 ) {} -}; - -class C_ConVar : public ConVar -{ -public: - C_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL) {} - C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString ) {} - 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) {} - 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 ) {} - 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 ) {} -}; - -class M_ConVar : public ConVar -{ -public: - M_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM) {} - M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString ) {} - 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) {} - 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 ) {} - 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 ) {} -}; - -class S_ConVar : public ConVar -{ -public: - S_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER) {} - S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString ) {} - 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) {} - 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 ) {} - 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 ) {} -}; - -class D_ConVar : public ConVar -{ -public: - D_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE) {} - D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString ) {} - 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) {} - 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 ) {} - 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 ) {} -}; - -// redirect these declarations to their specific subsystem -#ifdef GAME_DLL -#define ConCommand G_ConCommand -#define ConVar G_ConVar -#endif -#ifdef CLIENT_DLL -#define ConCommand C_ConCommand -#define ConVar C_ConVar -#endif -#ifdef MATERIALSYSTEM_DLL -#define ConCommand M_ConCommand -#define ConVar M_ConVar -#endif -#ifdef STUDIORENDER_DLL -#define ConCommand S_ConCommand -#define ConVar S_ConVar -#endif -#ifdef DATACACHE_DLL -#define ConCommand D_ConCommand -#define ConVar D_ConVar -#endif -#endif // _STATIC_LINKED - -//----------------------------------------------------------------------------- -// Purpose: Utility to quicky generate a simple console command -//----------------------------------------------------------------------------- -#define CON_COMMAND( name, description ) \ - static void name(); \ - static ConCommand name##_command( #name, name, description ); \ - static void name() - -//----------------------------------------------------------------------------- -// Purpose: Utility to quicky generate a simple console command -//----------------------------------------------------------------------------- -#define CON_COMMAND_F( name, description, flags ) \ - static void name(); \ - static ConCommand name##_command( #name, name, description, flags ); \ - static void name() - - -#endif // CONVAR_H diff --git a/core/convar_sm_bms.h b/core/convar_sm_bms.h deleted file mode 100644 index 1d2b63ff..00000000 --- a/core/convar_sm_bms.h +++ /dev/null @@ -1,729 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $Workfile: $ -// $Date: $ -// -//----------------------------------------------------------------------------- -// $NoKeywords: $ -//===========================================================================// - -#ifndef CONVAR_H -#define CONVAR_H - -#if _WIN32 -#pragma once -#endif - -#include "tier0/dbg.h" -#include "tier1/iconvar.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" -#include "icvar.h" - -#ifdef _WIN32 -#define FORCEINLINE_CVAR FORCEINLINE -#elif POSIX -#define FORCEINLINE_CVAR inline -#else -#error "implement me" -#endif - - -//----------------------------------------------------------------------------- -// Forward declarations -//----------------------------------------------------------------------------- -class ConVar; -class CCommand; -class ConCommand; -class ConCommandBase; -struct characterset_t; - - - -//----------------------------------------------------------------------------- -// Any executable that wants to use ConVars need to implement one of -// these to hook up access to console variables. -//----------------------------------------------------------------------------- -class IConCommandBaseAccessor -{ -public: - // Flags is a combination of FCVAR flags in cvar.h. - // hOut is filled in with a handle to the variable. - virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0; -}; - - -//----------------------------------------------------------------------------- -// Helper method for console development -//----------------------------------------------------------------------------- -#if defined( _X360 ) && !defined( _RETAIL ) -void ConVar_PublishToVXConsole(); -#endif - - -//----------------------------------------------------------------------------- -// Called when a ConCommand needs to execute -//----------------------------------------------------------------------------- -typedef void ( *FnCommandCallbackVoid_t )( void ); -typedef void ( *FnCommandCallback_t )( const CCommand &command ); - -#define COMMAND_COMPLETION_MAXITEMS 64 -#define COMMAND_COMPLETION_ITEM_LENGTH 64 - -//----------------------------------------------------------------------------- -// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings -//----------------------------------------------------------------------------- -typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ); - - -//----------------------------------------------------------------------------- -// Interface version -//----------------------------------------------------------------------------- -class ICommandCallback -{ -public: - virtual void CommandCallback( const CCommand &command ) = 0; -}; - -class ICommandCompletionCallback -{ -public: - virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0; -}; - -//----------------------------------------------------------------------------- -// Purpose: The base console invoked command/cvar interface -//----------------------------------------------------------------------------- -class ConCommandBase -{ - friend class CCvar; - friend class ConVar; - friend class ConCommand; - friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor ); - friend void ConVar_PublishToVXConsole(); - - // FIXME: Remove when ConVar changes are done - friend class CDefaultCvar; - -public: - ConCommandBase( void ); - ConCommandBase( const char *pName, const char *pHelpString = 0, - int flags = 0 ); - - virtual ~ConCommandBase( void ); - - virtual bool IsCommand( void ) const; - - // Check flag - virtual bool IsFlagSet( int flag ) const; - // Set flag - virtual void AddFlags( int flags ); - - // Return name of cvar - virtual const char *GetName( void ) const; - - // Return help text for cvar - virtual const char *GetHelpText( void ) const; - - // Deal with next pointer - const ConCommandBase *GetNext( void ) const; - ConCommandBase *GetNext( void ); - - inline void SetNext(ConCommandBase *pBase) - { - m_pNext = pBase; - } - - virtual bool IsRegistered( void ) const; - - // Returns the DLL identifier - virtual CVarDLLIdentifier_t GetDLLIdentifier() const; - -protected: - virtual void CreateBase( const char *pName, const char *pHelpString = 0, - int flags = 0 ); - - // Used internally by OneTimeInit to initialize/shutdown - virtual void Init(); - void Shutdown(); - - // Internal copy routine ( uses new operator from correct module ) - char *CopyString( const char *from ); - -private: - // Next ConVar in chain - // Prior to register, it points to the next convar in the DLL. - // Once registered, though, m_pNext is reset to point to the next - // convar in the global list - ConCommandBase *m_pNext; - - // Has the cvar been added to the global list? - bool m_bRegistered; - - // Static data - const char *m_pszName; - const char *m_pszHelpString; - - // ConVar flags - int m_nFlags; - -protected: - // ConVars add themselves to this list for the executable. - // Then ConVar_Register runs through all the console variables - // and registers them into a global list stored in vstdlib.dll - static ConCommandBase *s_pConCommandBases; - - // ConVars in this executable use this 'global' to access values. - static IConCommandBaseAccessor *s_pAccessor; -public: // Hackalicous - inline int GetFlags() const - { - return m_nFlags; - } - inline void SetFlags(int flags) - { - m_nFlags = flags; - } -}; - - -//----------------------------------------------------------------------------- -// Command tokenizer -//----------------------------------------------------------------------------- -class CCommand -{ -public: - CCommand(); - CCommand( int nArgC, const char **ppArgV ); - bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL ); - void Reset(); - - int ArgC() const; - const char **ArgV() const; - const char *ArgS() const; // All args that occur after the 0th arg, in string form - const char *GetCommandString() const; // The entire command in string form, including the 0th arg - const char *operator[]( int nIndex ) const; // Gets at arguments - const char *Arg( int nIndex ) const; // Gets at arguments - - // Helper functions to parse arguments to commands. - const char* FindArg( const char *pName ) const; - int FindArgInt( const char *pName, int nDefaultVal ) const; - - static int MaxCommandLength(); - static characterset_t* DefaultBreakSet(); - -private: - enum - { - COMMAND_MAX_ARGC = 64, - COMMAND_MAX_LENGTH = 512, - }; - - int m_nArgc; - int m_nArgv0Size; - char m_pArgSBuffer[ COMMAND_MAX_LENGTH ]; - char m_pArgvBuffer[ COMMAND_MAX_LENGTH ]; - const char* m_ppArgv[ COMMAND_MAX_ARGC ]; -}; - -inline int CCommand::MaxCommandLength() -{ - return COMMAND_MAX_LENGTH - 1; -} - -inline int CCommand::ArgC() const -{ - return m_nArgc; -} - -inline const char **CCommand::ArgV() const -{ - return m_nArgc ? (const char**)m_ppArgv : NULL; -} - -inline const char *CCommand::ArgS() const -{ - return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : ""; -} - -inline const char *CCommand::GetCommandString() const -{ - return m_nArgc ? m_pArgSBuffer : ""; -} - -inline const char *CCommand::Arg( int nIndex ) const -{ - // FIXME: Many command handlers appear to not be particularly careful - // about checking for valid argc range. For now, we're going to - // do the extra check and return an empty string if it's out of range - if ( nIndex < 0 || nIndex >= m_nArgc ) - return ""; - return m_ppArgv[nIndex]; -} - -inline const char *CCommand::operator[]( int nIndex ) const -{ - return Arg( nIndex ); -} - - -//----------------------------------------------------------------------------- -// Purpose: The console invoked command -//----------------------------------------------------------------------------- -class ConCommand : public ConCommandBase -{ -friend class CCvar; - -public: - typedef ConCommandBase BaseClass; - - ConCommand( const char *pName, FnCommandCallbackVoid_t callback, - const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); - ConCommand( const char *pName, FnCommandCallback_t callback, - const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); - ConCommand( const char *pName, ICommandCallback *pCallback, - const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 ); - - virtual ~ConCommand( void ); - - virtual bool IsCommand( void ) const; - - virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands ); - - virtual bool CanAutoComplete( void ); - - // Invoke the function - virtual void Dispatch( const CCommand &command ); - -private: - // NOTE: To maintain backward compat, we have to be very careful: - // All public virtual methods must appear in the same order always - // since engine code will be calling into this code, which *does not match* - // in the mod code; it's using slightly different, but compatible versions - // of this class. Also: Be very careful about adding new fields to this class. - // Those fields will not exist in the version of this class that is instanced - // in mod code. - - // Call this function when executing the command - union - { - FnCommandCallbackVoid_t m_fnCommandCallbackV1; - FnCommandCallback_t m_fnCommandCallback; - ICommandCallback *m_pCommandCallback; - }; - - union - { - FnCommandCompletionCallback m_fnCompletionCallback; - ICommandCompletionCallback *m_pCommandCompletionCallback; - }; - - bool m_bHasCompletionCallback : 1; - bool m_bUsingNewCommandCallback : 1; - bool m_bUsingCommandCallbackInterface : 1; -public: // Hackalicous - inline FnCommandCallback_t GetCallback() const - { - return m_fnCommandCallback; - } -}; - - -//----------------------------------------------------------------------------- -// Purpose: A console variable -//----------------------------------------------------------------------------- -class ConVar : public ConCommandBase, public IConVar -{ -friend class CCvar; -friend class ConVarRef; - -public: - typedef ConCommandBase BaseClass; - - ConVar( const char *pName, const char *pDefaultValue, int flags = 0); - - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, FnChangeCallback_t callback ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, - FnChangeCallback_t callback ); - - virtual ~ConVar( void ); - - virtual bool IsFlagSet( int flag ) const; - virtual const char* GetHelpText( void ) const; - virtual bool IsRegistered( void ) const; - virtual const char *GetName( void ) const; - virtual void AddFlags( int flags ); - virtual bool IsCommand( void ) const; - - // Install a change callback (there shouldn't already be one....) - void InstallChangeCallback( FnChangeCallback_t callback ); - - // Retrieve value - virtual float GetFloat( void ) const; - virtual int GetInt( void ) const; - virtual Vector GetVector( void ) const; - FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); } - FORCEINLINE_CVAR char const *GetString( void ) const; - - // Any function that allocates/frees memory needs to be virtual or else you'll have crashes - // from alloc/free across dll/exe boundaries. - - // These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue). - virtual void SetValue( const char *value ); - virtual void SetValue( float value ); - virtual void SetValue( int value ); - virtual void SetValue( const Vector &value ); - - // Reset to default value - void Revert( void ); - - // True if it has a min/max setting - bool GetMin( float& minVal ) const; - bool GetMax( float& maxVal ) const; - const char *GetDefault( void ) const; - void SetDefault( const char *pszDefault ); - -private: - // Called by CCvar when the value of a var is changing. - virtual void InternalSetValue(const char *value); - // For CVARs marked FCVAR_NEVER_AS_STRING - virtual void InternalSetFloatValue( float fNewValue, bool bForce = false ); - virtual void InternalSetIntValue( int nValue ); - virtual void InternalSetVectorValue( const Vector &vecValue ); - - virtual bool ClampValue( float& value ); - virtual void ChangeStringValue( const char *tempVal, float flOldValue ); - - virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0, - const char *pHelpString = 0, bool bMin = false, float fMin = 0.0, - bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 ); - - // Used internally by OneTimeInit to initialize. - virtual void Init(); - -private: - - // This either points to "this" or it points to the original declaration of a ConVar. - // This allows ConVars to exist in separate modules, and they all use the first one to be declared. - // m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar). - ConVar *m_pParent; - - // Static data - const char *m_pszDefaultValue; - - // Value - // Dynamically allocated - char *m_pszString; - int m_StringLength; - - // Values - float m_fValue; - int m_nValue; - Vector m_vecValue; - - // Min/Max values - bool m_bHasMin; - float m_fMinVal; - bool m_bHasMax; - float m_fMaxVal; - - bool m_bHasCompMin; - float m_fCompMinVal; - bool m_bHasCompMax; - float m_fCompMaxVal; - bool m_bCompetitiveRestrictions; - - - // Call this function when ConVar changes - FnChangeCallback_t m_fnChangeCallback; -public: // Hackalicous - inline FnChangeCallback_t GetCallback() const - { - return m_fnChangeCallback; - } - inline void SetMin(bool set, float min=0.0) - { - m_bHasMin = set; - m_fMinVal = min; - } - inline void SetMax(bool set, float max=0.0) - { - m_bHasMax = set; - m_fMaxVal = max; - } -}; - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a float -// Output : float -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR float ConVar::GetFloat( void ) const -{ - return m_pParent->m_fValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -// Output : int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR int ConVar::GetInt( void ) const -{ - return m_pParent->m_nValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -// Output : int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR Vector ConVar::GetVector(void) const -{ - return m_pParent->m_vecValue; -} - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. -// Output : const char * -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR const char *ConVar::GetString( void ) const -{ - if ( m_nFlags & FCVAR_NEVER_AS_STRING ) - return "FCVAR_NEVER_AS_STRING"; - - return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : ""; -} - - -//----------------------------------------------------------------------------- -// Used to read/write convars that already exist (replaces the FindVar method) -//----------------------------------------------------------------------------- -class ConVarRef -{ -public: - ConVarRef( const char *pName ); - ConVarRef( const char *pName, bool bIgnoreMissing ); - ConVarRef( IConVar *pConVar ); - - void Init( const char *pName, bool bIgnoreMissing ); - bool IsValid() const; - bool IsFlagSet( int nFlags ) const; - IConVar *GetLinkedConVar(); - - // Get/Set value - float GetFloat( void ) const; - int GetInt( void ) const; - bool GetBool() const { return !!GetInt(); } - const char *GetString( void ) const; - - void SetValue( const char *pValue ); - void SetValue( float flValue ); - void SetValue( int nValue ); - void SetValue( bool bValue ); - - const char *GetName() const; - - const char *GetDefault() const; - -private: - // High-speed method to read convar data - IConVar *m_pConVar; - ConVar *m_pConVarState; -}; - - -//----------------------------------------------------------------------------- -// Did we find an existing convar of that name? -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const -{ - return ( m_pConVar->IsFlagSet( nFlags ) != 0 ); -} - -FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar() -{ - return m_pConVar; -} - -FORCEINLINE_CVAR const char *ConVarRef::GetName() const -{ - return m_pConVar->GetName(); -} - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a float -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const -{ - return m_pConVarState->m_fValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const -{ - return m_pConVarState->m_nValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const -{ - Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) ); - return m_pConVarState->m_pszString; -} - - -FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue ) -{ - m_pConVar->SetValue( pValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue ) -{ - m_pConVar->SetValue( flValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue ) -{ - m_pConVar->SetValue( nValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue ) -{ - m_pConVar->SetValue( bValue ? 1 : 0 ); -} - -FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const -{ - return m_pConVarState->m_pszDefaultValue; -} - - -//----------------------------------------------------------------------------- -// Called by the framework to register ConCommands with the ICVar -//----------------------------------------------------------------------------- -void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL ); -void ConVar_Unregister( ); - - -//----------------------------------------------------------------------------- -// Utility methods -//----------------------------------------------------------------------------- -void ConVar_PrintFlags( const ConCommandBase *var ); -void ConVar_PrintDescription( const ConCommandBase *pVar ); - - -//----------------------------------------------------------------------------- -// Purpose: Utility class to quickly allow ConCommands to call member methods -//----------------------------------------------------------------------------- -#ifdef _WIN32 -#pragma warning (disable : 4355 ) -#endif - -template< class T > -class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback -{ - typedef ConCommand BaseClass; - typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command ); - typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands ); - -public: - CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0, - int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) : - BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL ) - { - m_pOwner = pOwner; - m_Func = callback; - m_CompletionFunc = completionFunc; - } - - ~CConCommandMemberAccessor() - { - Shutdown(); - } - - void SetOwner( T* pOwner ) - { - m_pOwner = pOwner; - } - - virtual void CommandCallback( const CCommand &command ) - { - Assert( m_pOwner && m_Func ); - (m_pOwner->*m_Func)( command ); - } - - virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) - { - Assert( m_pOwner && m_CompletionFunc ); - return (m_pOwner->*m_CompletionFunc)( pPartial, commands ); - } - -private: - T* m_pOwner; - FnMemberCommandCallback_t m_Func; - FnMemberCommandCompletionCallback_t m_CompletionFunc; -}; - -#ifdef _WIN32 -#pragma warning ( default : 4355 ) -#endif - -//----------------------------------------------------------------------------- -// Purpose: Utility macros to quicky generate a simple console command -//----------------------------------------------------------------------------- -#define CON_COMMAND( name, description ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description ); \ - static void name( const CCommand &args ) - -#define CON_COMMAND_F( name, description, flags ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description, flags ); \ - static void name( const CCommand &args ) - -#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description, flags, completion ); \ - static void name( const CCommand &args ) - -#define CON_COMMAND_EXTERN( name, _funcname, description ) \ - void _funcname( const CCommand &args ); \ - static ConCommand name##_command( #name, _funcname, description ); \ - void _funcname( const CCommand &args ) - -#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \ - void _funcname( const CCommand &args ); \ - static ConCommand name##_command( #name, _funcname, description, flags ); \ - void _funcname( const CCommand &args ) - -#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \ - void _funcname( const CCommand &args ); \ - friend class CCommandMemberInitializer_##_funcname; \ - class CCommandMemberInitializer_##_funcname \ - { \ - public: \ - CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \ - { \ - m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \ - } \ - private: \ - CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \ - }; \ - \ - CCommandMemberInitializer_##_funcname m_##_funcname##_register; \ - - -#endif // CONVAR_H diff --git a/core/convar_sm_l4d.h b/core/convar_sm_l4d.h deleted file mode 100644 index 7e535e55..00000000 --- a/core/convar_sm_l4d.h +++ /dev/null @@ -1,718 +0,0 @@ -//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======// -// -// Purpose: -// -// $Workfile: $ -// $Date: $ -// -//----------------------------------------------------------------------------- -// $NoKeywords: $ -//===========================================================================// - -#ifndef CONVAR_H -#define CONVAR_H - -#if _WIN32 -#pragma once -#endif - -#include "tier0/dbg.h" -#include "tier1/iconvar.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" -#include "icvar.h" - -#ifdef _WIN32 -#define FORCEINLINE_CVAR FORCEINLINE -#elif defined _LINUX || defined __APPLE__ -#define FORCEINLINE_CVAR inline -#else -#error "implement me" -#endif - - -//----------------------------------------------------------------------------- -// Forward declarations -//----------------------------------------------------------------------------- -class ConVar; -class CCommand; -class ConCommand; -class ConCommandBase; -struct characterset_t; - - - -//----------------------------------------------------------------------------- -// Any executable that wants to use ConVars need to implement one of -// these to hook up access to console variables. -//----------------------------------------------------------------------------- -class IConCommandBaseAccessor -{ -public: - // Flags is a combination of FCVAR flags in cvar.h. - // hOut is filled in with a handle to the variable. - virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0; -}; - - -//----------------------------------------------------------------------------- -// Helper method for console development -//----------------------------------------------------------------------------- -#if defined( _X360 ) && !defined( _RETAIL ) -void ConVar_PublishToVXConsole(); -#endif - - -//----------------------------------------------------------------------------- -// Called when a ConCommand needs to execute -//----------------------------------------------------------------------------- -typedef void ( *FnCommandCallbackV1_t )( void ); -typedef void ( *FnCommandCallback_t )( const CCommand &command ); - -#define COMMAND_COMPLETION_MAXITEMS 64 -#define COMMAND_COMPLETION_ITEM_LENGTH 64 - -//----------------------------------------------------------------------------- -// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings -//----------------------------------------------------------------------------- -typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ); - - -//----------------------------------------------------------------------------- -// Interface version -//----------------------------------------------------------------------------- -class ICommandCallback -{ -public: - virtual void CommandCallback( const CCommand &command ) = 0; -}; - -class ICommandCompletionCallback -{ -public: - virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0; -}; - -//----------------------------------------------------------------------------- -// Purpose: The base console invoked command/cvar interface -//----------------------------------------------------------------------------- -class ConCommandBase -{ - friend class CCvar; - friend class ConVar; - friend class ConCommand; - friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor ); - friend void ConVar_PublishToVXConsole(); - - // FIXME: Remove when ConVar changes are done - friend class CDefaultCvar; - -public: - ConCommandBase( void ); - ConCommandBase( const char *pName, const char *pHelpString = 0, - int flags = 0 ); - - virtual ~ConCommandBase( void ); - - virtual bool IsCommand( void ) const; - - // Check flag - virtual bool IsFlagSet( int flag ) const; - // Set flag - virtual void AddFlags( int flags ); - // Remove flag - virtual void RemoveFlags( int flags ); - // Get flags - virtual int GetFlags( void ) const; - - // Return name of cvar - virtual const char *GetName( void ) const; - - // Return help text for cvar - virtual const char *GetHelpText( void ) const; - - // Deal with next pointer - const ConCommandBase *GetNext( void ) const; - ConCommandBase *GetNext( void ); - - inline void SetNext(ConCommandBase *pBase) - { - m_pNext = pBase; - } - - virtual bool IsRegistered( void ) const; - - // Returns the DLL identifier - virtual CVarDLLIdentifier_t GetDLLIdentifier() const; - -protected: - virtual void Create( const char *pName, const char *pHelpString = 0, - int flags = 0 ); - - // Used internally by OneTimeInit to initialize/shutdown - virtual void Init(); - void Shutdown(); - - // Internal copy routine ( uses new operator from correct module ) - char *CopyString( const char *from ); - -private: - // Next ConVar in chain - // Prior to register, it points to the next convar in the DLL. - // Once registered, though, m_pNext is reset to point to the next - // convar in the global list - ConCommandBase *m_pNext; - - // Has the cvar been added to the global list? - bool m_bRegistered; - - // Static data - const char *m_pszName; - const char *m_pszHelpString; - - // ConVar flags - int m_nFlags; - -protected: - // ConVars add themselves to this list for the executable. - // Then ConVar_Register runs through all the console variables - // and registers them into a global list stored in vstdlib.dll - static ConCommandBase *s_pConCommandBases; - - // ConVars in this executable use this 'global' to access values. - static IConCommandBaseAccessor *s_pAccessor; -public: - inline void SetFlags(int flags) - { - m_nFlags = flags; - } -}; - - -//----------------------------------------------------------------------------- -// Command tokenizer -//----------------------------------------------------------------------------- -class CCommand -{ -public: - CCommand(); - CCommand( int nArgC, const char **ppArgV ); - bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL ); - void Reset(); - - int ArgC() const; - const char **ArgV() const; - const char *ArgS() const; // All args that occur after the 0th arg, in string form - const char *GetCommandString() const; // The entire command in string form, including the 0th arg - const char *operator[]( int nIndex ) const; // Gets at arguments - const char *Arg( int nIndex ) const; // Gets at arguments - - // Helper functions to parse arguments to commands. - const char* FindArg( const char *pName ) const; - int FindArgInt( const char *pName, int nDefaultVal ) const; - - static int MaxCommandLength(); - static characterset_t* DefaultBreakSet(); - -private: - enum - { - COMMAND_MAX_ARGC = 64, - COMMAND_MAX_LENGTH = 512, - }; - - int m_nArgc; - int m_nArgv0Size; - char m_pArgSBuffer[ COMMAND_MAX_LENGTH ]; - char m_pArgvBuffer[ COMMAND_MAX_LENGTH ]; - const char* m_ppArgv[ COMMAND_MAX_ARGC ]; -}; - -inline int CCommand::MaxCommandLength() -{ - return COMMAND_MAX_LENGTH - 1; -} - -inline int CCommand::ArgC() const -{ - return m_nArgc; -} - -inline const char **CCommand::ArgV() const -{ - return m_nArgc ? (const char**)m_ppArgv : NULL; -} - -inline const char *CCommand::ArgS() const -{ - return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : ""; -} - -inline const char *CCommand::GetCommandString() const -{ - return m_nArgc ? m_pArgSBuffer : ""; -} - -inline const char *CCommand::Arg( int nIndex ) const -{ - // FIXME: Many command handlers appear to not be particularly careful - // about checking for valid argc range. For now, we're going to - // do the extra check and return an empty string if it's out of range - if ( nIndex < 0 || nIndex >= m_nArgc ) - return ""; - return m_ppArgv[nIndex]; -} - -inline const char *CCommand::operator[]( int nIndex ) const -{ - return Arg( nIndex ); -} - - -//----------------------------------------------------------------------------- -// Purpose: The console invoked command -//----------------------------------------------------------------------------- -class ConCommand : public ConCommandBase -{ -friend class CCvar; - -public: - typedef ConCommandBase BaseClass; - - ConCommand( const char *pName, FnCommandCallbackV1_t callback, - const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); - ConCommand( const char *pName, FnCommandCallback_t callback, - const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); - ConCommand( const char *pName, ICommandCallback *pCallback, - const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 ); - - virtual ~ConCommand( void ); - - virtual bool IsCommand( void ) const; - - virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands ); - - virtual bool CanAutoComplete( void ); - - // Invoke the function - virtual void Dispatch( const CCommand &command ); - -private: - // NOTE: To maintain backward compat, we have to be very careful: - // All public virtual methods must appear in the same order always - // since engine code will be calling into this code, which *does not match* - // in the mod code; it's using slightly different, but compatible versions - // of this class. Also: Be very careful about adding new fields to this class. - // Those fields will not exist in the version of this class that is instanced - // in mod code. - - // Call this function when executing the command - union - { - FnCommandCallbackV1_t m_fnCommandCallbackV1; - FnCommandCallback_t m_fnCommandCallback; - ICommandCallback *m_pCommandCallback; - }; - - union - { - FnCommandCompletionCallback m_fnCompletionCallback; - ICommandCompletionCallback *m_pCommandCompletionCallback; - }; - - bool m_bHasCompletionCallback : 1; - bool m_bUsingNewCommandCallback : 1; - bool m_bUsingCommandCallbackInterface : 1; -public: - inline FnCommandCallback_t GetCallback() const - { - return m_fnCommandCallback; - } -}; - - -//----------------------------------------------------------------------------- -// Purpose: A console variable -//----------------------------------------------------------------------------- -class ConVar : public ConCommandBase, public IConVar -{ -friend class CCvar; -friend class ConVarRef; - -public: - typedef ConCommandBase BaseClass; - - ConVar( const char *pName, const char *pDefaultValue, int flags = 0); - - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, FnChangeCallback_t callback ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, - FnChangeCallback_t callback ); - - virtual ~ConVar( void ); - - virtual bool IsCommand( void ) const; - virtual bool IsFlagSet( int flag ) const; - virtual void AddFlags( int flags ); - virtual int GetFlags( void ) const; - virtual const char *GetName( void ) const; - virtual const char* GetHelpText( void ) const; - virtual bool IsRegistered( void ) const; - - // Install a change callback (there shouldn't already be one....) - void InstallChangeCallback( FnChangeCallback_t callback ); - - // Retrieve value - FORCEINLINE_CVAR float GetFloat( void ) const; - FORCEINLINE_CVAR int GetInt( void ) const; - FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); } - FORCEINLINE_CVAR char const *GetString( void ) const; - - // Used internally by OneTimeInit to initialize. - virtual void Init(); - - virtual const char *GetBaseName( void ) const; - virtual int GetSplitScreenPlayerSlot ( void ) const; - - // Any function that allocates/frees memory needs to be virtual or else you'll have crashes - // from alloc/free across dll/exe boundaries. - - // These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue). - virtual void SetValue( const char *value ); - virtual void SetValue( float value ); - virtual void SetValue( int value ); -#if SOURCE_ENGINE >= SE_NUCLEARDAWN - virtual void SetValue( Color value ); -#endif - - // Reset to default value - void Revert( void ); - - // True if it has a min/max setting - bool GetMin( float& minVal ) const; - bool GetMax( float& maxVal ) const; - const char *GetDefault( void ) const; - -private: - // Called by CCvar when the value of a var is changing. - virtual void InternalSetValue(const char *value); - // For CVARs marked FCVAR_NEVER_AS_STRING - virtual void InternalSetFloatValue( float fNewValue ); - virtual void InternalSetIntValue( int nValue ); -#if SOURCE_ENGINE >= SE_LEFT4DEAD2 - virtual void InternalSetColorValue( Color value ); -#endif - - virtual bool ClampValue( float& value ); - virtual void ChangeStringValue( const char *tempVal, float flOldValue ); - - virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0, - const char *pHelpString = 0, bool bMin = false, float fMin = 0.0, - bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 ); - -private: - - // This either points to "this" or it points to the original declaration of a ConVar. - // This allows ConVars to exist in separate modules, and they all use the first one to be declared. - // m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar). - ConVar *m_pParent; - - // Static data - const char *m_pszDefaultValue; - - // Value - // Dynamically allocated - char *m_pszString; - int m_StringLength; - - // Values - float m_fValue; - int m_nValue; - - // Min/Max values - bool m_bHasMin; - float m_fMinVal; - bool m_bHasMax; - float m_fMaxVal; - - // Call this function when ConVar changes - FnChangeCallback_t m_fnChangeCallback; -public: - inline FnChangeCallback_t GetCallback() const - { - return m_fnChangeCallback; - } - inline void SetMin(bool set, float min=0.0) - { - m_bHasMin = set; - m_fMinVal = min; - } - inline void SetMax(bool set, float max=0.0) - { - m_bHasMax = set; - m_fMaxVal = max; - } -}; - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a float -// Output : float -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR float ConVar::GetFloat( void ) const -{ - return m_pParent->m_fValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -// Output : int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR int ConVar::GetInt( void ) const -{ - return m_pParent->m_nValue; -} - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. -// Output : const char * -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR const char *ConVar::GetString( void ) const -{ - if ( m_nFlags & FCVAR_NEVER_AS_STRING ) - return "FCVAR_NEVER_AS_STRING"; - - return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : ""; -} - - -//----------------------------------------------------------------------------- -// Used to read/write convars that already exist (replaces the FindVar method) -//----------------------------------------------------------------------------- -class ConVarRef -{ -public: - ConVarRef( const char *pName ); - ConVarRef( const char *pName, bool bIgnoreMissing ); - ConVarRef( IConVar *pConVar ); - - void Init( const char *pName, bool bIgnoreMissing ); - bool IsValid() const; - bool IsFlagSet( int nFlags ) const; - IConVar *GetLinkedConVar(); - - // Get/Set value - float GetFloat( void ) const; - int GetInt( void ) const; - bool GetBool() const { return !!GetInt(); } - const char *GetString( void ) const; - - void SetValue( const char *pValue ); - void SetValue( float flValue ); - void SetValue( int nValue ); - void SetValue( bool bValue ); - - const char *GetName() const; - - const char *GetDefault() const; - -private: - // High-speed method to read convar data - IConVar *m_pConVar; - ConVar *m_pConVarState; -}; - - -//----------------------------------------------------------------------------- -// Did we find an existing convar of that name? -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const -{ - return ( m_pConVar->IsFlagSet( nFlags ) != 0 ); -} - -FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar() -{ - return m_pConVar; -} - -FORCEINLINE_CVAR const char *ConVarRef::GetName() const -{ - return m_pConVar->GetName(); -} - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a float -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const -{ - return m_pConVarState->m_fValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const -{ - return m_pConVarState->m_nValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const -{ - Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) ); - return m_pConVarState->m_pszString; -} - - -FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue ) -{ - m_pConVar->SetValue( pValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue ) -{ - m_pConVar->SetValue( flValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue ) -{ - m_pConVar->SetValue( nValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue ) -{ - m_pConVar->SetValue( bValue ? 1 : 0 ); -} - -FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const -{ - return m_pConVarState->m_pszDefaultValue; -} - - -//----------------------------------------------------------------------------- -// Called by the framework to register ConCommands with the ICVar -//----------------------------------------------------------------------------- -void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL ); -void ConVar_Unregister( ); - - -//----------------------------------------------------------------------------- -// Utility methods -//----------------------------------------------------------------------------- -void ConVar_PrintFlags( const ConCommandBase *var ); -void ConVar_PrintDescription( const ConCommandBase *pVar ); - - -//----------------------------------------------------------------------------- -// Purpose: Utility class to quickly allow ConCommands to call member methods -//----------------------------------------------------------------------------- -#ifdef _MSC_VER -#pragma warning (disable : 4355 ) -#endif - -template< class T > -class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback -{ - typedef ConCommand BaseClass; - typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command ); - typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands ); - -public: - CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0, - int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) : - BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL ) - { - m_pOwner = pOwner; - m_Func = callback; - m_CompletionFunc = completionFunc; - } - - ~CConCommandMemberAccessor() - { - Shutdown(); - } - - void SetOwner( T* pOwner ) - { - m_pOwner = pOwner; - } - - virtual void CommandCallback( const CCommand &command ) - { - Assert( m_pOwner && m_Func ); - (m_pOwner->*m_Func)( command ); - } - - virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) - { - Assert( m_pOwner && m_CompletionFunc ); - return (m_pOwner->*m_CompletionFunc)( pPartial, commands ); - } - -private: - T* m_pOwner; - FnMemberCommandCallback_t m_Func; - FnMemberCommandCompletionCallback_t m_CompletionFunc; -}; - -#ifdef _MSC_VER -#pragma warning ( default : 4355 ) -#endif - -//----------------------------------------------------------------------------- -// Purpose: Utility macros to quicky generate a simple console command -//----------------------------------------------------------------------------- -#define CON_COMMAND( name, description ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description ); \ - static void name( const CCommand &args ) - -#define CON_COMMAND_F( name, description, flags ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description, flags ); \ - static void name( const CCommand &args ) - -#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description, flags, completion ); \ - static void name( const CCommand &args ) - -#define CON_COMMAND_EXTERN( name, _funcname, description ) \ - void _funcname( const CCommand &args ); \ - static ConCommand name##_command( #name, _funcname, description ); \ - void _funcname( const CCommand &args ) - -#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \ - void _funcname( const CCommand &args ); \ - static ConCommand name##_command( #name, _funcname, description, flags ); \ - void _funcname( const CCommand &args ) - -#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \ - void _funcname( const CCommand &args ); \ - friend class CCommandMemberInitializer_##_funcname; \ - class CCommandMemberInitializer_##_funcname \ - { \ - public: \ - CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \ - { \ - m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \ - } \ - private: \ - CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \ - }; \ - \ - CCommandMemberInitializer_##_funcname m_##_funcname##_register; \ - - -#endif // CONVAR_H diff --git a/core/convar_sm_ob.h b/core/convar_sm_ob.h deleted file mode 100644 index 1f04fa58..00000000 --- a/core/convar_sm_ob.h +++ /dev/null @@ -1,709 +0,0 @@ -//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======// -// -// Purpose: -// -// $Workfile: $ -// $Date: $ -// -//----------------------------------------------------------------------------- -// $NoKeywords: $ -//===========================================================================// - -#ifndef CONVAR_H -#define CONVAR_H - -#if _WIN32 -#pragma once -#endif - -#include "tier0/dbg.h" -#include "tier1/iconvar.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" -#include "icvar.h" - -#ifdef _WIN32 -#define FORCEINLINE_CVAR FORCEINLINE -#elif defined _LINUX || defined __APPLE__ -#define FORCEINLINE_CVAR inline -#else -#error "implement me" -#endif - - -//----------------------------------------------------------------------------- -// Forward declarations -//----------------------------------------------------------------------------- -class ConVar; -class CCommand; -class ConCommand; -class ConCommandBase; -struct characterset_t; - - - -//----------------------------------------------------------------------------- -// Any executable that wants to use ConVars need to implement one of -// these to hook up access to console variables. -//----------------------------------------------------------------------------- -class IConCommandBaseAccessor -{ -public: - // Flags is a combination of FCVAR flags in cvar.h. - // hOut is filled in with a handle to the variable. - virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0; -}; - - -//----------------------------------------------------------------------------- -// Helper method for console development -//----------------------------------------------------------------------------- -#if defined( _X360 ) && !defined( _RETAIL ) -void ConVar_PublishToVXConsole(); -#endif - - -//----------------------------------------------------------------------------- -// Called when a ConCommand needs to execute -//----------------------------------------------------------------------------- -typedef void ( *FnCommandCallbackV1_t )( void ); -typedef void ( *FnCommandCallback_t )( const CCommand &command ); - -#define COMMAND_COMPLETION_MAXITEMS 64 -#define COMMAND_COMPLETION_ITEM_LENGTH 64 - -//----------------------------------------------------------------------------- -// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings -//----------------------------------------------------------------------------- -typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ); - - -//----------------------------------------------------------------------------- -// Interface version -//----------------------------------------------------------------------------- -class ICommandCallback -{ -public: - virtual void CommandCallback( const CCommand &command ) = 0; -}; - -class ICommandCompletionCallback -{ -public: - virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0; -}; - -//----------------------------------------------------------------------------- -// Purpose: The base console invoked command/cvar interface -//----------------------------------------------------------------------------- -class ConCommandBase -{ - friend class CCvar; - friend class ConVar; - friend class ConCommand; - friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor ); - friend void ConVar_PublishToVXConsole(); - - // FIXME: Remove when ConVar changes are done - friend class CDefaultCvar; - -public: - ConCommandBase( void ); - ConCommandBase( const char *pName, const char *pHelpString = 0, - int flags = 0 ); - - virtual ~ConCommandBase( void ); - - virtual bool IsCommand( void ) const; - - // Check flag - virtual bool IsFlagSet( int flag ) const; - // Set flag - virtual void AddFlags( int flags ); - - // Return name of cvar - virtual const char *GetName( void ) const; - - // Return help text for cvar - virtual const char *GetHelpText( void ) const; - - // Deal with next pointer - const ConCommandBase *GetNext( void ) const; - ConCommandBase *GetNext( void ); - - void SetNext(ConCommandBase *pBase) - { - m_pNext = pBase; - } - - virtual bool IsRegistered( void ) const; - - // Returns the DLL identifier - virtual CVarDLLIdentifier_t GetDLLIdentifier() const; - -protected: - virtual void Create( const char *pName, const char *pHelpString = 0, - int flags = 0 ); - - // Used internally by OneTimeInit to initialize/shutdown - virtual void Init(); - void Shutdown(); - - // Internal copy routine ( uses new operator from correct module ) - char *CopyString( const char *from ); - -private: - // Next ConVar in chain - // Prior to register, it points to the next convar in the DLL. - // Once registered, though, m_pNext is reset to point to the next - // convar in the global list - ConCommandBase *m_pNext; - - // Has the cvar been added to the global list? - bool m_bRegistered; - - // Static data - const char *m_pszName; - const char *m_pszHelpString; - - // ConVar flags - int m_nFlags; - -protected: - // ConVars add themselves to this list for the executable. - // Then ConVar_Register runs through all the console variables - // and registers them into a global list stored in vstdlib.dll - static ConCommandBase *s_pConCommandBases; - - // ConVars in this executable use this 'global' to access values. - static IConCommandBaseAccessor *s_pAccessor; -public: // Hackalicous - inline int GetFlags() const - { - return m_nFlags; - } - inline void SetFlags(int flags) - { - m_nFlags = flags; - } -}; - - -//----------------------------------------------------------------------------- -// Command tokenizer -//----------------------------------------------------------------------------- -class CCommand -{ -public: - CCommand(); - CCommand( int nArgC, const char **ppArgV ); - bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL ); - void Reset(); - - int ArgC() const; - const char **ArgV() const; - const char *ArgS() const; // All args that occur after the 0th arg, in string form - const char *GetCommandString() const; // The entire command in string form, including the 0th arg - const char *operator[]( int nIndex ) const; // Gets at arguments - const char *Arg( int nIndex ) const; // Gets at arguments - - // Helper functions to parse arguments to commands. - const char* FindArg( const char *pName ) const; - int FindArgInt( const char *pName, int nDefaultVal ) const; - - static int MaxCommandLength(); - static characterset_t* DefaultBreakSet(); - -private: - enum - { - COMMAND_MAX_ARGC = 64, - COMMAND_MAX_LENGTH = 512, - }; - - int m_nArgc; - int m_nArgv0Size; - char m_pArgSBuffer[ COMMAND_MAX_LENGTH ]; - char m_pArgvBuffer[ COMMAND_MAX_LENGTH ]; - const char* m_ppArgv[ COMMAND_MAX_ARGC ]; -}; - -inline int CCommand::MaxCommandLength() -{ - return COMMAND_MAX_LENGTH - 1; -} - -inline int CCommand::ArgC() const -{ - return m_nArgc; -} - -inline const char **CCommand::ArgV() const -{ - return m_nArgc ? (const char**)m_ppArgv : NULL; -} - -inline const char *CCommand::ArgS() const -{ - return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : ""; -} - -inline const char *CCommand::GetCommandString() const -{ - return m_nArgc ? m_pArgSBuffer : ""; -} - -inline const char *CCommand::Arg( int nIndex ) const -{ - // FIXME: Many command handlers appear to not be particularly careful - // about checking for valid argc range. For now, we're going to - // do the extra check and return an empty string if it's out of range - if ( nIndex < 0 || nIndex >= m_nArgc ) - return ""; - return m_ppArgv[nIndex]; -} - -inline const char *CCommand::operator[]( int nIndex ) const -{ - return Arg( nIndex ); -} - - -//----------------------------------------------------------------------------- -// Purpose: The console invoked command -//----------------------------------------------------------------------------- -class ConCommand : public ConCommandBase -{ -friend class CCvar; - -public: - typedef ConCommandBase BaseClass; - - ConCommand( const char *pName, FnCommandCallbackV1_t callback, - const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); - ConCommand( const char *pName, FnCommandCallback_t callback, - const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); - ConCommand( const char *pName, ICommandCallback *pCallback, - const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 ); - - virtual ~ConCommand( void ); - - virtual bool IsCommand( void ) const; - - virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands ); - - virtual bool CanAutoComplete( void ); - - // Invoke the function - virtual void Dispatch( const CCommand &command ); - -private: - // NOTE: To maintain backward compat, we have to be very careful: - // All public virtual methods must appear in the same order always - // since engine code will be calling into this code, which *does not match* - // in the mod code; it's using slightly different, but compatible versions - // of this class. Also: Be very careful about adding new fields to this class. - // Those fields will not exist in the version of this class that is instanced - // in mod code. - - // Call this function when executing the command - union - { - FnCommandCallbackV1_t m_fnCommandCallbackV1; - FnCommandCallback_t m_fnCommandCallback; - ICommandCallback *m_pCommandCallback; - }; - - union - { - FnCommandCompletionCallback m_fnCompletionCallback; - ICommandCompletionCallback *m_pCommandCompletionCallback; - }; - - bool m_bHasCompletionCallback : 1; - bool m_bUsingNewCommandCallback : 1; - bool m_bUsingCommandCallbackInterface : 1; -public: // Hackalicous - inline FnCommandCallback_t GetCallback() const - { - return m_fnCommandCallback; - } -}; - - -//----------------------------------------------------------------------------- -// Purpose: A console variable -//----------------------------------------------------------------------------- -class ConVar : public ConCommandBase, public IConVar -{ -friend class CCvar; -friend class ConVarRef; - -public: - typedef ConCommandBase BaseClass; - - ConVar( const char *pName, const char *pDefaultValue, int flags = 0); - - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, FnChangeCallback_t callback ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, - FnChangeCallback_t callback ); - - virtual ~ConVar( void ); - - virtual bool IsFlagSet( int flag ) const; - virtual const char* GetHelpText( void ) const; - virtual bool IsRegistered( void ) const; - virtual const char *GetName( void ) const; - virtual void AddFlags( int flags ); - virtual bool IsCommand( void ) const; - - // Install a change callback (there shouldn't already be one....) - void InstallChangeCallback( FnChangeCallback_t callback ); - - // Retrieve value - FORCEINLINE_CVAR float GetFloat( void ) const; - FORCEINLINE_CVAR int GetInt( void ) const; - FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); } - FORCEINLINE_CVAR char const *GetString( void ) const; - - // Any function that allocates/frees memory needs to be virtual or else you'll have crashes - // from alloc/free across dll/exe boundaries. - - // These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue). - virtual void SetValue( const char *value ); - virtual void SetValue( float value ); - virtual void SetValue( int value ); - - // Reset to default value - void Revert( void ); - - // True if it has a min/max setting - bool GetMin( float& minVal ) const; - bool GetMax( float& maxVal ) const; - const char *GetDefault( void ) const; - -private: - // Called by CCvar when the value of a var is changing. - virtual void InternalSetValue(const char *value); - // For CVARs marked FCVAR_NEVER_AS_STRING - virtual void InternalSetFloatValue( float fNewValue ); - virtual void InternalSetIntValue( int nValue ); - - virtual bool ClampValue( float& value ); - virtual void ChangeStringValue( const char *tempVal, float flOldValue ); - - virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0, - const char *pHelpString = 0, bool bMin = false, float fMin = 0.0, - bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 ); - - // Used internally by OneTimeInit to initialize. - virtual void Init(); - -private: - - // This either points to "this" or it points to the original declaration of a ConVar. - // This allows ConVars to exist in separate modules, and they all use the first one to be declared. - // m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar). - ConVar *m_pParent; - - // Static data - const char *m_pszDefaultValue; - - // Value - // Dynamically allocated - char *m_pszString; - int m_StringLength; - - // Values - float m_fValue; - int m_nValue; - - // Min/Max values - bool m_bHasMin; - float m_fMinVal; - bool m_bHasMax; - float m_fMaxVal; - - // Call this function when ConVar changes - FnChangeCallback_t m_fnChangeCallback; -public: // Hackalicous - inline FnChangeCallback_t GetCallback() const - { - return m_fnChangeCallback; - } - inline void SetMin(bool set, float min=0.0) - { - m_bHasMin = set; - m_fMinVal = min; - } - inline void SetMax(bool set, float max=0.0) - { - m_bHasMax = set; - m_fMaxVal = max; - } -}; - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a float -// Output : float -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR float ConVar::GetFloat( void ) const -{ - return m_pParent->m_fValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -// Output : int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR int ConVar::GetInt( void ) const -{ - return m_pParent->m_nValue; -} - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. -// Output : const char * -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR const char *ConVar::GetString( void ) const -{ - if ( m_nFlags & FCVAR_NEVER_AS_STRING ) - return "FCVAR_NEVER_AS_STRING"; - - return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : ""; -} - - -//----------------------------------------------------------------------------- -// Used to read/write convars that already exist (replaces the FindVar method) -//----------------------------------------------------------------------------- -class ConVarRef -{ -public: - ConVarRef( const char *pName ); - ConVarRef( const char *pName, bool bIgnoreMissing ); - ConVarRef( IConVar *pConVar ); - - void Init( const char *pName, bool bIgnoreMissing ); - bool IsValid() const; - bool IsFlagSet( int nFlags ) const; - IConVar *GetLinkedConVar(); - - // Get/Set value - float GetFloat( void ) const; - int GetInt( void ) const; - bool GetBool() const { return !!GetInt(); } - const char *GetString( void ) const; - - void SetValue( const char *pValue ); - void SetValue( float flValue ); - void SetValue( int nValue ); - void SetValue( bool bValue ); - - const char *GetName() const; - - const char *GetDefault() const; - -private: - // High-speed method to read convar data - IConVar *m_pConVar; - ConVar *m_pConVarState; -}; - - -//----------------------------------------------------------------------------- -// Did we find an existing convar of that name? -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const -{ - return ( m_pConVar->IsFlagSet( nFlags ) != 0 ); -} - -FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar() -{ - return m_pConVar; -} - -FORCEINLINE_CVAR const char *ConVarRef::GetName() const -{ - return m_pConVar->GetName(); -} - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a float -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const -{ - return m_pConVarState->m_fValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const -{ - return m_pConVarState->m_nValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const -{ - Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) ); - return m_pConVarState->m_pszString; -} - - -FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue ) -{ - m_pConVar->SetValue( pValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue ) -{ - m_pConVar->SetValue( flValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue ) -{ - m_pConVar->SetValue( nValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue ) -{ - m_pConVar->SetValue( bValue ? 1 : 0 ); -} - -FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const -{ - return m_pConVarState->m_pszDefaultValue; -} - - -//----------------------------------------------------------------------------- -// Called by the framework to register ConCommands with the ICVar -//----------------------------------------------------------------------------- -void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL ); -void ConVar_Unregister( ); - - -//----------------------------------------------------------------------------- -// Utility methods -//----------------------------------------------------------------------------- -void ConVar_PrintFlags( const ConCommandBase *var ); -void ConVar_PrintDescription( const ConCommandBase *pVar ); - - -//----------------------------------------------------------------------------- -// Purpose: Utility class to quickly allow ConCommands to call member methods -//----------------------------------------------------------------------------- -#if defined _MSC_VER -#pragma warning (disable : 4355 ) -#endif - -template< class T > -class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback -{ - typedef ConCommand BaseClass; - typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command ); - typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands ); - -public: - CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0, - int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) : - BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL ) - { - m_pOwner = pOwner; - m_Func = callback; - m_CompletionFunc = completionFunc; - } - - ~CConCommandMemberAccessor() - { - Shutdown(); - } - - void SetOwner( T* pOwner ) - { - m_pOwner = pOwner; - } - - virtual void CommandCallback( const CCommand &command ) - { - Assert( m_pOwner && m_Func ); - (m_pOwner->*m_Func)( command ); - } - - virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) - { - Assert( m_pOwner && m_CompletionFunc ); - return (m_pOwner->*m_CompletionFunc)( pPartial, commands ); - } - -private: - T* m_pOwner; - FnMemberCommandCallback_t m_Func; - FnMemberCommandCompletionCallback_t m_CompletionFunc; -}; - -#if defined _MSC_VER -#pragma warning ( default : 4355 ) -#endif - - -//----------------------------------------------------------------------------- -// Purpose: Utility macros to quicky generate a simple console command -//----------------------------------------------------------------------------- -#define CON_COMMAND( name, description ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description ); \ - static void name( const CCommand &args ) - -#define CON_COMMAND_F( name, description, flags ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description, flags ); \ - static void name( const CCommand &args ) - -#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description, flags, completion ); \ - static void name( const CCommand &args ) - -#define CON_COMMAND_EXTERN( name, _funcname, description ) \ - void _funcname( const CCommand &args ); \ - static ConCommand name##_command( #name, _funcname, description ); \ - void _funcname( const CCommand &args ) - -#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \ - void _funcname( const CCommand &args ); \ - static ConCommand name##_command( #name, _funcname, description, flags ); \ - void _funcname( const CCommand &args ) - -#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \ - void _funcname( const CCommand &args ); \ - friend class CCommandMemberInitializer_##_funcname; \ - class CCommandMemberInitializer_##_funcname \ - { \ - public: \ - CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \ - { \ - m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \ - } \ - private: \ - CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \ - }; \ - \ - CCommandMemberInitializer_##_funcname m_##_funcname##_register; \ - - -#endif // CONVAR_H diff --git a/core/convar_sm_swarm.h b/core/convar_sm_swarm.h deleted file mode 100644 index ab0653d6..00000000 --- a/core/convar_sm_swarm.h +++ /dev/null @@ -1,1042 +0,0 @@ -//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======// -// -// Purpose: -// -// $Workfile: $ -// $Date: $ -// -//----------------------------------------------------------------------------- -// $NoKeywords: $ -//===========================================================================// - -#ifndef CONVAR_H -#define CONVAR_H - -#if _WIN32 -#pragma once -#endif - -#include "tier0/dbg.h" -#include "tier1/iconvar.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" -#include "Color.h" -#include "icvar.h" - -#ifdef _WIN32 -#define FORCEINLINE_CVAR FORCEINLINE -#elif POSIX -#define FORCEINLINE_CVAR inline -#else -#error "implement me" -#endif - - -//----------------------------------------------------------------------------- -// Uncomment me to test for threading issues for material system convars -// NOTE: You want to disable all threading when you do this -// +host_thread_mode 0 +r_threaded_particles 0 +sv_parallel_packentities 0 +sv_disable_querycache 0 -//----------------------------------------------------------------------------- -//#define CONVAR_TEST_MATERIAL_THREAD_CONVARS 1 - - -//----------------------------------------------------------------------------- -// Forward declarations -//----------------------------------------------------------------------------- -class ConVar; -class CCommand; -class ConCommand; -class ConCommandBase; -struct characterset_t; - - - -//----------------------------------------------------------------------------- -// Any executable that wants to use ConVars need to implement one of -// these to hook up access to console variables. -//----------------------------------------------------------------------------- -class IConCommandBaseAccessor -{ -public: - // Flags is a combination of FCVAR flags in cvar.h. - // hOut is filled in with a handle to the variable. - virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0; -}; - - -//----------------------------------------------------------------------------- -// Helper method for console development -//----------------------------------------------------------------------------- -#if defined( _X360 ) -void ConVar_PublishToVXConsole(); -#endif - - -//----------------------------------------------------------------------------- -// Called when a ConCommand needs to execute -//----------------------------------------------------------------------------- -typedef void ( *FnCommandCallbackV1_t )( void ); -typedef void ( *FnCommandCallback_t )( const CCommand &command ); - -#define COMMAND_COMPLETION_MAXITEMS 64 -#define COMMAND_COMPLETION_ITEM_LENGTH 64 - -//----------------------------------------------------------------------------- -// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings -//----------------------------------------------------------------------------- -typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ); - - -//----------------------------------------------------------------------------- -// Interface version -//----------------------------------------------------------------------------- -class ICommandCallback -{ -public: - virtual void CommandCallback( const CCommand &command ) = 0; -}; - -class ICommandCompletionCallback -{ -public: - virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0; -}; - -//----------------------------------------------------------------------------- -// Purpose: The base console invoked command/cvar interface -//----------------------------------------------------------------------------- -class ConCommandBase -{ - friend class CCvar; - friend class ConVar; - friend class ConCommand; - friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor ); - friend void ConVar_PublishToVXConsole(); - - // FIXME: Remove when ConVar changes are done - friend class CDefaultCvar; - -public: - ConCommandBase( void ); - ConCommandBase( const char *pName, const char *pHelpString = 0, - int flags = 0 ); - - virtual ~ConCommandBase( void ); - - virtual bool IsCommand( void ) const; - - // Check flag - virtual bool IsFlagSet( int flag ) const; - // Set flag - virtual void AddFlags( int flags ); - // Clear flag - virtual void RemoveFlags( int flags ); - - virtual int GetFlags() const; - - // Return name of cvar - virtual const char *GetName( void ) const; - - // Return help text for cvar - virtual const char *GetHelpText( void ) const; - - // Deal with next pointer - const ConCommandBase *GetNext( void ) const; - ConCommandBase *GetNext( void ); - - virtual bool IsRegistered( void ) const; - - // Returns the DLL identifier - virtual CVarDLLIdentifier_t GetDLLIdentifier() const; - -protected: - virtual void Create( const char *pName, const char *pHelpString = 0, - int flags = 0 ); - - // Used internally by OneTimeInit to initialize/shutdown - virtual void Init(); - void Shutdown(); - - // Internal copy routine ( uses new operator from correct module ) - char *CopyString( const char *from ); - -private: - // Next ConVar in chain - // Prior to register, it points to the next convar in the DLL. - // Once registered, though, m_pNext is reset to point to the next - // convar in the global list - ConCommandBase *m_pNext; - - // Has the cvar been added to the global list? - bool m_bRegistered; - - // Static data - const char *m_pszName; - const char *m_pszHelpString; - - // ConVar flags - int m_nFlags; - -protected: - // ConVars add themselves to this list for the executable. - // Then ConVar_Register runs through all the console variables - // and registers them into a global list stored in vstdlib.dll - static ConCommandBase *s_pConCommandBases; - - // ConVars in this executable use this 'global' to access values. - static IConCommandBaseAccessor *s_pAccessor; -public: - inline void SetFlags(int flags) - { - m_nFlags = flags; - } -}; - - -//----------------------------------------------------------------------------- -// Command tokenizer -//----------------------------------------------------------------------------- -class CCommand -{ -public: - CCommand(); - CCommand( int nArgC, const char **ppArgV ); - bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL ); - void Reset(); - - int ArgC() const; - const char **ArgV() const; - const char *ArgS() const; // All args that occur after the 0th arg, in string form - const char *GetCommandString() const; // The entire command in string form, including the 0th arg - const char *operator[]( int nIndex ) const; // Gets at arguments - const char *Arg( int nIndex ) const; // Gets at arguments - - // Helper functions to parse arguments to commands. - const char* FindArg( const char *pName ) const; - int FindArgInt( const char *pName, int nDefaultVal ) const; - - static int MaxCommandLength(); - static characterset_t* DefaultBreakSet(); - -private: - enum - { - COMMAND_MAX_ARGC = 64, - COMMAND_MAX_LENGTH = 512, - }; - - int m_nArgc; - int m_nArgv0Size; - char m_pArgSBuffer[ COMMAND_MAX_LENGTH ]; - char m_pArgvBuffer[ COMMAND_MAX_LENGTH ]; - const char* m_ppArgv[ COMMAND_MAX_ARGC ]; -}; - -inline int CCommand::MaxCommandLength() -{ - return COMMAND_MAX_LENGTH - 1; -} - -inline int CCommand::ArgC() const -{ - return m_nArgc; -} - -inline const char **CCommand::ArgV() const -{ - return m_nArgc ? (const char**)m_ppArgv : NULL; -} - -inline const char *CCommand::ArgS() const -{ - return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : ""; -} - -inline const char *CCommand::GetCommandString() const -{ - return m_nArgc ? m_pArgSBuffer : ""; -} - -inline const char *CCommand::Arg( int nIndex ) const -{ - // FIXME: Many command handlers appear to not be particularly careful - // about checking for valid argc range. For now, we're going to - // do the extra check and return an empty string if it's out of range - if ( nIndex < 0 || nIndex >= m_nArgc ) - return ""; - return m_ppArgv[nIndex]; -} - -inline const char *CCommand::operator[]( int nIndex ) const -{ - return Arg( nIndex ); -} - - -//----------------------------------------------------------------------------- -// Purpose: The console invoked command -//----------------------------------------------------------------------------- -class ConCommand : public ConCommandBase -{ -friend class CCvar; - -public: - typedef ConCommandBase BaseClass; - - ConCommand( const char *pName, FnCommandCallbackV1_t callback, - const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); - ConCommand( const char *pName, FnCommandCallback_t callback, - const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); - ConCommand( const char *pName, ICommandCallback *pCallback, - const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 ); - - virtual ~ConCommand( void ); - - virtual bool IsCommand( void ) const; - - virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands ); - - virtual bool CanAutoComplete( void ); - - // Invoke the function - virtual void Dispatch( const CCommand &command ); - -private: - // NOTE: To maintain backward compat, we have to be very careful: - // All public virtual methods must appear in the same order always - // since engine code will be calling into this code, which *does not match* - // in the mod code; it's using slightly different, but compatible versions - // of this class. Also: Be very careful about adding new fields to this class. - // Those fields will not exist in the version of this class that is instanced - // in mod code. - - // Call this function when executing the command - union - { - FnCommandCallbackV1_t m_fnCommandCallbackV1; - FnCommandCallback_t m_fnCommandCallback; - ICommandCallback *m_pCommandCallback; - }; - - union - { - FnCommandCompletionCallback m_fnCompletionCallback; - ICommandCompletionCallback *m_pCommandCompletionCallback; - }; - - bool m_bHasCompletionCallback : 1; - bool m_bUsingNewCommandCallback : 1; - bool m_bUsingCommandCallbackInterface : 1; -public: - inline FnCommandCallback_t GetCallback() const - { - return m_fnCommandCallback; - } -}; - - -//----------------------------------------------------------------------------- -// Purpose: A console variable -//----------------------------------------------------------------------------- -class ConVar : public ConCommandBase, public IConVar -{ -friend class CCvar; -friend class ConVarRef; -friend class SplitScreenConVarRef; - -public: - typedef ConCommandBase BaseClass; - - ConVar( const char *pName, const char *pDefaultValue, int flags = 0); - - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, FnChangeCallback_t callback ); - ConVar( const char *pName, const char *pDefaultValue, int flags, - const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, - FnChangeCallback_t callback ); - - virtual ~ConVar( void ); - - virtual bool IsFlagSet( int flag ) const; - virtual const char* GetHelpText( void ) const; - virtual bool IsRegistered( void ) const; - virtual const char *GetName( void ) const; - // Return name of command (usually == GetName(), except in case of FCVAR_SS_ADDED vars - virtual const char *GetBaseName( void ) const; - virtual int GetSplitScreenPlayerSlot() const; - - virtual void AddFlags( int flags ); - virtual int GetFlags() const; - virtual bool IsCommand( void ) const; - - // Install a change callback (there shouldn't already be one....) - void InstallChangeCallback( FnChangeCallback_t callback, bool bInvoke = true ); - void RemoveChangeCallback( FnChangeCallback_t callbackToRemove ); - - int GetChangeCallbackCount() const { return m_pParent->m_fnChangeCallbacks.Count(); } - FnChangeCallback_t GetChangeCallback( int slot ) const { return m_pParent->m_fnChangeCallbacks[ slot ]; } - - // Retrieve value -#if SOURCE_ENGINE >= SE_INSURGENCY - virtual float GetFloat( void ) const; - virtual int GetInt( void ) const; -#else - FORCEINLINE_CVAR float GetFloat( void ) const; - FORCEINLINE_CVAR int GetInt( void ) const; -#endif - - FORCEINLINE_CVAR Color GetColor( void ) const; - FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); } - FORCEINLINE_CVAR char const *GetString( void ) const; - - // Compiler driven selection for template use - template T Get( void ) const; - template T Get( T * ) const; - - // Any function that allocates/frees memory needs to be virtual or else you'll have crashes - // from alloc/free across dll/exe boundaries. - - // These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue). - virtual void SetValue( const char *value ); - virtual void SetValue( float value ); - virtual void SetValue( int value ); - virtual void SetValue( Color value ); - - // Reset to default value - void Revert( void ); - - // True if it has a min/max setting - bool HasMin() const; - bool HasMax() const; - - bool GetMin( float& minVal ) const; - bool GetMax( float& maxVal ) const; - - float GetMinValue() const; - float GetMaxValue() const; - - const char *GetDefault( void ) const; - - // Value - struct CVValue_t - { - char *m_pszString; - int m_StringLength; - - // Values - float m_fValue; - int m_nValue; - }; - - FORCEINLINE_CVAR CVValue_t &GetRawValue() - { - return m_Value; - } - FORCEINLINE_CVAR const CVValue_t &GetRawValue() const - { - return m_Value; - } - -private: - bool InternalSetColorFromString( const char *value ); - // Called by CCvar when the value of a var is changing. - virtual void InternalSetValue(const char *value); - // For CVARs marked FCVAR_NEVER_AS_STRING - virtual void InternalSetFloatValue( float fNewValue ); - virtual void InternalSetIntValue( int nValue ); - virtual void InternalSetColorValue( Color value ); - - virtual bool ClampValue( float& value ); - virtual void ChangeStringValue( const char *tempVal, float flOldValue ); - - virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0, - const char *pHelpString = 0, bool bMin = false, float fMin = 0.0, - bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 ); - - // Used internally by OneTimeInit to initialize. - virtual void Init(); - - - -protected: - - // This either points to "this" or it points to the original declaration of a ConVar. - // This allows ConVars to exist in separate modules, and they all use the first one to be declared. - // m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar). - ConVar *m_pParent; - - // Static data - const char *m_pszDefaultValue; - - CVValue_t m_Value; - - // Min/Max values - bool m_bHasMin; - float m_fMinVal; - bool m_bHasMax; - float m_fMaxVal; - - // Call this function when ConVar changes - CUtlVector< FnChangeCallback_t > m_fnChangeCallbacks; -public: - inline void SetMin(bool set, float min=0.0) - { - m_bHasMin = set; - m_fMinVal = min; - } - inline void SetMax(bool set, float max=0.0) - { - m_bHasMax = set; - m_fMaxVal = max; - } -}; - - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a float -// Output : float -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR float ConVar::GetFloat( void ) const -{ -#ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS - Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) ); -#endif - return m_pParent->m_Value.m_fValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -// Output : int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR int ConVar::GetInt( void ) const -{ -#ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS - Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) ); -#endif - return m_pParent->m_Value.m_nValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a color -// Output : Color -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR Color ConVar::GetColor( void ) const -{ -#ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS - Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) ); -#endif - unsigned char *pColorElement = ((unsigned char *)&m_pParent->m_Value.m_nValue); - return Color( pColorElement[0], pColorElement[1], pColorElement[2], pColorElement[3] ); -} - - -//----------------------------------------------------------------------------- - -template <> FORCEINLINE_CVAR float ConVar::Get( void ) const { return GetFloat(); } -template <> FORCEINLINE_CVAR int ConVar::Get( void ) const { return GetInt(); } -template <> FORCEINLINE_CVAR bool ConVar::Get( void ) const { return GetBool(); } -template <> FORCEINLINE_CVAR const char * ConVar::Get( void ) const { return GetString(); } -template <> FORCEINLINE_CVAR float ConVar::Get( float *p ) const { return ( *p = GetFloat() ); } -template <> FORCEINLINE_CVAR int ConVar::Get( int *p ) const { return ( *p = GetInt() ); } -template <> FORCEINLINE_CVAR bool ConVar::Get( bool *p ) const { return ( *p = GetBool() ); } -template <> FORCEINLINE_CVAR const char * ConVar::Get( char const **p ) const { return ( *p = GetString() ); } - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. -// Output : const char * -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR const char *ConVar::GetString( void ) const -{ -#ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS - Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) ); -#endif - if ( m_nFlags & FCVAR_NEVER_AS_STRING ) - return "FCVAR_NEVER_AS_STRING"; - - char const *str = m_pParent->m_Value.m_pszString; - return str ? str : ""; -} - -class CSplitScreenAddedConVar : public ConVar -{ - typedef ConVar BaseClass; -public: - CSplitScreenAddedConVar( int nSplitScreenSlot, const char *pName, const ConVar *pBaseVar ) : - BaseClass - ( - pName, - pBaseVar->GetDefault(), - // Keep basevar flags, except remove _SS and add _SS_ADDED instead - ( pBaseVar->GetFlags() & ~FCVAR_SS ) | FCVAR_SS_ADDED, - pBaseVar->GetHelpText(), - pBaseVar->HasMin(), - pBaseVar->GetMinValue(), - pBaseVar->HasMax(), - pBaseVar->GetMaxValue() - ), - m_pBaseVar( pBaseVar ), - m_nSplitScreenSlot( nSplitScreenSlot ) - { - for ( int i = 0; i < pBaseVar->GetChangeCallbackCount(); ++i ) - { - InstallChangeCallback( pBaseVar->GetChangeCallback( i ), false ); - } - Assert( nSplitScreenSlot >= 1 ); - Assert( nSplitScreenSlot < MAX_SPLITSCREEN_CLIENTS ); - Assert( m_pBaseVar ); - Assert( IsFlagSet( FCVAR_SS_ADDED ) ); - Assert( !IsFlagSet( FCVAR_SS ) ); - } - - const ConVar *GetBaseVar() const; - virtual const char *GetBaseName() const; - void SetSplitScreenPlayerSlot( int nSlot ); - virtual int GetSplitScreenPlayerSlot() const; - -protected: - - const ConVar *m_pBaseVar; - int m_nSplitScreenSlot; -}; - -FORCEINLINE_CVAR const ConVar *CSplitScreenAddedConVar::GetBaseVar() const -{ - Assert( m_pBaseVar ); - return m_pBaseVar; -} - -FORCEINLINE_CVAR const char *CSplitScreenAddedConVar::GetBaseName() const -{ - Assert( m_pBaseVar ); - return m_pBaseVar->GetName(); -} - -FORCEINLINE_CVAR void CSplitScreenAddedConVar::SetSplitScreenPlayerSlot( int nSlot ) -{ - m_nSplitScreenSlot = nSlot; -} - -FORCEINLINE_CVAR int CSplitScreenAddedConVar::GetSplitScreenPlayerSlot() const -{ - return m_nSplitScreenSlot; -} - -//----------------------------------------------------------------------------- -// Used to read/write convars that already exist (replaces the FindVar method) -//----------------------------------------------------------------------------- -class ConVarRef -{ -public: - ConVarRef( const char *pName ); - ConVarRef( const char *pName, bool bIgnoreMissing ); - ConVarRef( IConVar *pConVar ); - - void Init( const char *pName, bool bIgnoreMissing ); - bool IsValid() const; - bool IsFlagSet( int nFlags ) const; - IConVar *GetLinkedConVar(); - - // Get/Set value - float GetFloat( void ) const; - int GetInt( void ) const; - Color GetColor( void ) const; - bool GetBool() const { return !!GetInt(); } - const char *GetString( void ) const; - - void SetValue( const char *pValue ); - void SetValue( float flValue ); - void SetValue( int nValue ); - void SetValue( Color value ); - void SetValue( bool bValue ); - - const char *GetName() const; - - const char *GetDefault() const; - - const char *GetBaseName() const; - - int GetSplitScreenPlayerSlot() const; - -private: - // High-speed method to read convar data - IConVar *m_pConVar; - ConVar *m_pConVarState; -}; - - -//----------------------------------------------------------------------------- -// Did we find an existing convar of that name? -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const -{ - return ( m_pConVar->IsFlagSet( nFlags ) != 0 ); -} - -FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar() -{ - return m_pConVar; -} - -FORCEINLINE_CVAR const char *ConVarRef::GetName() const -{ - return m_pConVar->GetName(); -} - -FORCEINLINE_CVAR const char *ConVarRef::GetBaseName() const -{ - return m_pConVar->GetBaseName(); -} - -FORCEINLINE_CVAR int ConVarRef::GetSplitScreenPlayerSlot() const -{ - return m_pConVar->GetSplitScreenPlayerSlot(); -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a float -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const -{ - return m_pConVarState->m_Value.m_fValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const -{ - return m_pConVarState->m_Value.m_nValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a color -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR Color ConVarRef::GetColor( void ) const -{ - return m_pConVarState->GetColor(); -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const -{ - Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) ); - return m_pConVarState->m_Value.m_pszString; -} - - -FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue ) -{ - m_pConVar->SetValue( pValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue ) -{ - m_pConVar->SetValue( flValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue ) -{ - m_pConVar->SetValue( nValue ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( Color value ) -{ - m_pConVar->SetValue( value ); -} - -FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue ) -{ - m_pConVar->SetValue( bValue ? 1 : 0 ); -} - -FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const -{ - return m_pConVarState->m_pszDefaultValue; -} - -//----------------------------------------------------------------------------- -// Helper for referencing splitscreen convars (i.e., "name" and "name2") -//----------------------------------------------------------------------------- -class SplitScreenConVarRef -{ -public: - SplitScreenConVarRef( const char *pName ); - SplitScreenConVarRef( const char *pName, bool bIgnoreMissing ); - SplitScreenConVarRef( IConVar *pConVar ); - - void Init( const char *pName, bool bIgnoreMissing ); - bool IsValid() const; - bool IsFlagSet( int nFlags ) const; - - // Get/Set value - float GetFloat( int nSlot ) const; - int GetInt( int nSlot ) const; - Color GetColor( int nSlot ) const; - bool GetBool( int nSlot ) const { return !!GetInt( nSlot ); } - const char *GetString( int nSlot ) const; - - void SetValue( int nSlot, const char *pValue ); - void SetValue( int nSlot, float flValue ); - void SetValue( int nSlot, int nValue ); - void SetValue( int nSlot, Color value ); - void SetValue( int nSlot, bool bValue ); - - const char *GetName( int nSlot ) const; - - const char *GetDefault() const; - - const char *GetBaseName() const; - -private: - struct cv_t - { - IConVar *m_pConVar; - ConVar *m_pConVarState; - }; - - cv_t m_Info[ MAX_SPLITSCREEN_CLIENTS ]; -}; - -//----------------------------------------------------------------------------- -// Did we find an existing convar of that name? -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR bool SplitScreenConVarRef::IsFlagSet( int nFlags ) const -{ - return ( m_Info[ 0 ].m_pConVar->IsFlagSet( nFlags ) != 0 ); -} - -FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetName( int nSlot ) const -{ - return m_Info[ nSlot ].m_pConVar->GetName(); -} - -FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetBaseName() const -{ - return m_Info[ 0 ].m_pConVar->GetBaseName(); -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a float -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR float SplitScreenConVarRef::GetFloat( int nSlot ) const -{ - return m_Info[ nSlot ].m_pConVarState->m_Value.m_fValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR int SplitScreenConVarRef::GetInt( int nSlot ) const -{ - return m_Info[ nSlot ].m_pConVarState->m_Value.m_nValue; -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as an int -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR Color SplitScreenConVarRef::GetColor( int nSlot ) const -{ - return m_Info[ nSlot ].m_pConVarState->GetColor(); -} - -//----------------------------------------------------------------------------- -// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. -//----------------------------------------------------------------------------- -FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetString( int nSlot ) const -{ - Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) ); - return m_Info[ nSlot ].m_pConVarState->m_Value.m_pszString; -} - - -FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, const char *pValue ) -{ - m_Info[ nSlot ].m_pConVar->SetValue( pValue ); -} - -FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, float flValue ) -{ - m_Info[ nSlot ].m_pConVar->SetValue( flValue ); -} - -FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, int nValue ) -{ - m_Info[ nSlot ].m_pConVar->SetValue( nValue ); -} - -FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, Color value ) -{ - m_Info[ nSlot ].m_pConVar->SetValue( value ); -} - -FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, bool bValue ) -{ - m_Info[ nSlot ].m_pConVar->SetValue( bValue ? 1 : 0 ); -} - -FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetDefault() const -{ - return m_Info[ 0 ].m_pConVarState->m_pszDefaultValue; -} - -//----------------------------------------------------------------------------- -// Called by the framework to register ConCommands with the ICVar -//----------------------------------------------------------------------------- -void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL ); -void ConVar_Unregister( ); - - -//----------------------------------------------------------------------------- -// Utility methods -//----------------------------------------------------------------------------- -void ConVar_PrintDescription( const ConCommandBase *pVar ); - - -//----------------------------------------------------------------------------- -// Purpose: Utility class to quickly allow ConCommands to call member methods -//----------------------------------------------------------------------------- -#ifdef _WIN32 -#pragma warning (disable : 4355 ) -#endif - -template< class T > -class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback -{ - typedef ConCommand BaseClass; - typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command ); - typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands ); - -public: - CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0, - int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) : - BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL ) - { - m_pOwner = pOwner; - m_Func = callback; - m_CompletionFunc = completionFunc; - } - - ~CConCommandMemberAccessor() - { - Shutdown(); - } - - void SetOwner( T* pOwner ) - { - m_pOwner = pOwner; - } - - virtual void CommandCallback( const CCommand &command ) - { - Assert( m_pOwner && m_Func ); - (m_pOwner->*m_Func)( command ); - } - - virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) - { - Assert( m_pOwner && m_CompletionFunc ); - return (m_pOwner->*m_CompletionFunc)( pPartial, commands ); - } - -private: - T* m_pOwner; - FnMemberCommandCallback_t m_Func; - FnMemberCommandCompletionCallback_t m_CompletionFunc; -}; - -#ifdef _WIN32 -#pragma warning ( default : 4355 ) -#endif - - -//----------------------------------------------------------------------------- -// Purpose: Utility macros to quicky generate a simple console command -//----------------------------------------------------------------------------- -#define CON_COMMAND( name, description ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description ); \ - static void name( const CCommand &args ) - -#ifdef CLIENT_DLL - #define CON_COMMAND_SHARED( name, description ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command_client( #name "_client", name, description ); \ - static void name( const CCommand &args ) -#else - #define CON_COMMAND_SHARED( name, description ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description ); \ - static void name( const CCommand &args ) -#endif - - -#define CON_COMMAND_F( name, description, flags ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description, flags ); \ - static void name( const CCommand &args ) - -#ifdef CLIENT_DLL - #define CON_COMMAND_F_SHARED( name, description, flags ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command_client( #name "_client", name, description, flags ); \ - static void name( const CCommand &args ) -#else - #define CON_COMMAND_F_SHARED( name, description, flags ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description, flags ); \ - static void name( const CCommand &args ) -#endif - - -#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description, flags, completion ); \ - static void name( const CCommand &args ) - -#ifdef CLIENT_DLL - #define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command_client( #name "_client", name, description, flags, completion ); \ - static void name( const CCommand &args ) -#else - #define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \ - static void name( const CCommand &args ); \ - static ConCommand name##_command( #name, name, description, flags, completion ); \ - static void name( const CCommand &args ) -#endif - - -#define CON_COMMAND_EXTERN( name, _funcname, description ) \ - void _funcname( const CCommand &args ); \ - static ConCommand name##_command( #name, _funcname, description ); \ - void _funcname( const CCommand &args ) - -#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \ - void _funcname( const CCommand &args ); \ - static ConCommand name##_command( #name, _funcname, description, flags ); \ - void _funcname( const CCommand &args ) - -#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \ - void _funcname( const CCommand &args ); \ - friend class CCommandMemberInitializer_##_funcname; \ - class CCommandMemberInitializer_##_funcname \ - { \ - public: \ - CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \ - { \ - m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \ - } \ - private: \ - CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \ - }; \ - \ - CCommandMemberInitializer_##_funcname m_##_funcname##_register; \ - - -#endif // CONVAR_H diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp index e2fb3a71..990e3a30 100644 --- a/core/logic_bridge.cpp +++ b/core/logic_bridge.cpp @@ -45,20 +45,7 @@ #include "ConCmdManager.h" #include "IDBDriver.h" #include "provider.h" -// TODO: move this garbage to the actual SDKs behind SOURCEMOD_BUILD ifdef, -// or use gamedata -#if SOURCE_ENGINE == SE_BMS -#include "convar_sm_bms.h" -#elif SOURCE_ENGINE >= SE_ALIENSWARM -# include "convar_sm_swarm.h" -#elif SOURCE_ENGINE >= SE_LEFT4DEAD -# include "convar_sm_l4d.h" -#elif SOURCE_ENGINE >= SE_ORANGEBOX -# include "convar_sm_ob.h" -#else -# include "convar_sm.h" -#endif -// +#include "sm_convar.h" #include #include #include diff --git a/core/sm_convar.h b/core/sm_convar.h new file mode 100644 index 00000000..017edd8a --- /dev/null +++ b/core/sm_convar.h @@ -0,0 +1,38 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod + * Copyright (C) 2004-2018 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software + * by the Valve Corporation. You must obey the GNU General Public License in + * all respects for all other code used. Additionally, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ + +#pragma once + +#define protected public +#define private public +#include +#undef protected +#undef private diff --git a/core/smn_console.cpp b/core/smn_console.cpp index 0c5858a0..4ef8abdf 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -141,14 +141,14 @@ public: if (m_CmdFlags.retrieve(name, &pCmd)) { TrackConCommandBase(pCmd, this); - *flags = pCmd->GetFlags(); + *flags = pCmd->m_nFlags; return true; } else if ((pCmd=FindCommandBase(name))) { m_CmdFlags.insert(name, pCmd); TrackConCommandBase(pCmd, this); - *flags = pCmd->GetFlags(); + *flags = pCmd->m_nFlags; return true; } else @@ -161,14 +161,14 @@ public: ConCommandBase *pCmd; if (m_CmdFlags.retrieve(name, &pCmd)) { - pCmd->SetFlags(flags); + pCmd->m_nFlags = flags; TrackConCommandBase(pCmd, this); return true; } else if ((pCmd=FindCommandBase(name))) { m_CmdFlags.insert(name, pCmd); - pCmd->SetFlags(flags); + pCmd->m_nFlags = flags; TrackConCommandBase(pCmd, this); return true; } @@ -555,7 +555,7 @@ static cell_t sm_SetConVarFlags(IPluginContext *pContext, const cell_t *params) return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err); } - pConVar->SetFlags(params[2]); + pConVar->m_nFlags = params[2]; return 1; } @@ -609,10 +609,10 @@ static cell_t sm_SetConVarBounds(IPluginContext *pContext, const cell_t *params) switch (params[2]) { case ConVarBound_Upper: - pConVar->SetMax(params[3] ? true : false, sp_ctof(params[4])); + pConVar->m_fMaxVal = params[3] ? true : false, sp_ctof(params[4]); break; case ConVarBound_Lower: - pConVar->SetMin(params[3] ? true : false, sp_ctof(params[4])); + pConVar->m_fMinVal = params[3] ? true : false, sp_ctof(params[4]); break; default: return pContext->ThrowNativeError("Invalid ConVarBounds value %d"); @@ -1086,7 +1086,7 @@ static cell_t FindFirstConCommand(IPluginContext *pContext, const cell_t *params pContext->StringToLocalUTF8(params[1], params[2], pConCmd->GetName(), NULL); *pIsCmd = pConCmd->IsCommand() ? 1 : 0; - *pFlags = pConCmd->GetFlags(); + *pFlags = pConCmd->m_nFlags; if (params[6]) { @@ -1135,7 +1135,7 @@ static cell_t FindNextConCommand(IPluginContext *pContext, const cell_t *params) pContext->StringToLocalUTF8(params[2], params[3], pConCmd->GetName(), NULL); *pIsCmd = pConCmd->IsCommand() ? 1 : 0; - *pFlags = pConCmd->GetFlags(); + *pFlags = pConCmd->m_nFlags; if (params[7]) { diff --git a/core/sourcemm_api.h b/core/sourcemm_api.h index 652b948d..68372a10 100644 --- a/core/sourcemm_api.h +++ b/core/sourcemm_api.h @@ -32,20 +32,7 @@ #ifndef _INCLUDE_SOURCEMOD_MM_API_H_ #define _INCLUDE_SOURCEMOD_MM_API_H_ -// TODO: move this garbage to the actual SDKs behind SOURCEMOD_BUILD ifdef, -// or use gamedata -#if SOURCE_ENGINE == SE_BMS -#include "convar_sm_bms.h" -#elif SOURCE_ENGINE >= SE_ALIENSWARM -#include "convar_sm_swarm.h" -#elif SOURCE_ENGINE >= SE_LEFT4DEAD -#include "convar_sm_l4d.h" -#elif SOURCE_ENGINE >= SE_ORANGEBOX -#include "convar_sm_ob.h" -#else -#include "convar_sm.h" -#endif -// +#include "sm_convar.h" #include #include #include