diff --git a/public/icvar.h b/public/icvar.h index 64daf0d52..41b127cc4 100644 --- a/public/icvar.h +++ b/public/icvar.h @@ -240,7 +240,8 @@ class CConVarBaseData inline bool HasMinValue( ) const { return m_minValue != nullptr; } inline bool HasMaxValue( ) const { return m_maxValue != nullptr; } - inline int GetTimesChanges( void ) const { return m_iTimesChanged; } + inline int GetTimesChanged( void ) const { return m_iTimesChanged; } + inline void SetTimesChanged( int val ) { m_iTimesChanged = val; } inline bool IsFlagSet( int64_t flag ) const { return ( flag & m_nFlags ) ? true : false; } inline void AddFlags( int64_t flags ) { m_nFlags |= flags; } @@ -463,7 +464,7 @@ abstract_class ICvar : public IAppSystem // Install a global change callback (to be called when any convar changes) virtual void InstallGlobalChangeCallback( FnChangeCallbackGlobal_t callback ) = 0; virtual void RemoveGlobalChangeCallback( FnChangeCallbackGlobal_t callback ) = 0; - virtual void CallGlobalChangeCallbacks( BaseConVar* ref, CSplitScreenSlot nSlot, const char* newValue, char* oldValue ) = 0; + virtual void CallGlobalChangeCallbacks( BaseConVar* ref, CSplitScreenSlot nSlot, const char* newValue, const char* oldValue ) = 0; // Reverts cvars which contain a specific flag virtual void RevertFlaggedConVars( int nFlag ) = 0; diff --git a/public/tier1/convar.h b/public/tier1/convar.h index 7895b3b2a..934da4a0b 100644 --- a/public/tier1/convar.h +++ b/public/tier1/convar.h @@ -523,10 +523,7 @@ class ConVar : public BaseConVar // Deep copy T oldValue = this->GetValue( ); - GetConVarData()->SetValue( newValue, index ); - - g_pCVar->CallChangeCallback( this->m_Handle, index, (const CVValue_t*)&newValue, (const CVValue_t*)&oldValue ); - g_pCVar->CallGlobalChangeCallbacks( this, index, szNewValue, szOldValue ); + this->UpdateValue( newValue, index, (const CVValue_t*)&newValue, (const CVValue_t*)&oldValue, szNewValue, szOldValue ); } inline void GetStringValue( char* dst, size_t len, const CSplitScreenSlot& index = 0 ) const { GetConVarData()->GetStringValue( dst, len, index ); } @@ -581,6 +578,15 @@ class ConVar : public BaseConVar SetupConVar(cvar); } + + inline void UpdateValue( const T& value, const CSplitScreenSlot& index, const CVValue_t* newValue, const CVValue_t* oldValue, const char* szNewValue, const char* szOldValue ) + { + GetConVarData()->SetValue( value, index ); + + GetConVarData()->SetTimesChanged( GetConVarData()->GetTimesChanged( ) + 1 ); + g_pCVar->CallChangeCallback( this->m_Handle, index, newValue, oldValue ); + g_pCVar->CallGlobalChangeCallbacks( this, index, szNewValue, szOldValue ); + } }; static_assert(sizeof(ConVar) == 0x10, "ConVar is of the wrong size!"); static_assert(sizeof(ConVar) == sizeof(ConVar), "Templated ConVar size varies!"); @@ -594,10 +600,7 @@ template<> inline void ConVar::SetValue( const char*const& val, con CConVarData::ValueToString( newValue, szNewValue, sizeof(szNewValue) ); GetConVarData()->GetStringValue( szOldValue, sizeof(szOldValue), index ); - GetConVarData()->SetValue( newValue, index ); - - g_pCVar->CallChangeCallback( this->m_Handle, index, (const CVValue_t*)&newValue, (const CVValue_t*)&szOldValue ); - g_pCVar->CallGlobalChangeCallbacks( this, index, szNewValue, szOldValue ); + this->UpdateValue( newValue, index, (const CVValue_t*)&newValue, (const CVValue_t*)&szOldValue, szNewValue, szOldValue ); } //-----------------------------------------------------------------------------