1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 20:16:10 +08:00

Update ICvar interface

This commit is contained in:
GAMMACASE
2025-05-12 20:31:06 +03:00
parent abde277182
commit bd6fe1a547
3 changed files with 50 additions and 7 deletions

View File

@ -18,6 +18,7 @@
#include "tier0/memalloc.h"
#include "convar.h"
#include <cstdint>
#include <functional>
// Shorthand helper to iterate registered convars
// Example usage:
@ -42,10 +43,12 @@
struct ConVarSnapshot_t;
class KeyValues;
typedef std::function<void( FnGenericChangeCallbackProvider_t, FnGenericChangeCallback_t )> FnCvarCallbacksReader_t;
//-----------------------------------------------------------------------------
// Called when a ConVar changes value
//-----------------------------------------------------------------------------
typedef void(*FnChangeCallbackGlobal_t)(ConVarRefAbstract* ref, CSplitScreenSlot nSlot, const char *pNewValue, const char *pOldValue);
typedef void(*FnChangeCallbackGlobal_t)(ConVarRefAbstract* ref, CSplitScreenSlot nSlot, const char *pNewValue, const char *pOldValue, void *__unk01);
//-----------------------------------------------------------------------------
// ConVar & ConCommand creation listener callbacks
@ -67,7 +70,10 @@ public:
virtual ConVarRef FindConVar( const char *name, bool allow_defensive = false ) = 0;
virtual ConVarRef FindFirstConVar() = 0;
virtual ConVarRef FindNextConVar( ConVarRef prev ) = 0;
virtual void CallChangeCallback( ConVarRef cvar, const CSplitScreenSlot nSlot, const CVValue_t* pNewValue, const CVValue_t* pOldValue ) = 0;
virtual void CallChangeCallback( ConVarRef cvar, const CSplitScreenSlot nSlot, const CVValue_t* pNewValue, const CVValue_t* pOldValue, void *__unk01 = nullptr ) = 0;
// Would call cb for every change callback defined for this cvar
virtual void IterateConVarCallbacks( ConVarRef cvar, FnCvarCallbacksReader_t cb ) = 0;
// allow_defensive - Allows finding commands with FCVAR_DEFENSIVE flag
virtual ConCommandRef FindConCommand( const char *name, bool allow_defensive = false ) = 0;
@ -78,7 +84,7 @@ public:
// 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( ConVarRefAbstract* ref, CSplitScreenSlot nSlot, const char* newValue, const char* oldValue ) = 0;
virtual void CallGlobalChangeCallbacks( ConVarRefAbstract* ref, CSplitScreenSlot nSlot, const char* newValue, const char* oldValue, void *__unk01 = nullptr ) = 0;
// Reverts cvars to default values which contain a specific flag,
// cvars with a flag FCVAR_COMMANDLINE_ENFORCED would be skipped
@ -107,6 +113,12 @@ public:
// that have FCVAR_DEFENSIVE set
virtual void StripDevelopmentFlags() = 0;
// Returns total bytesize needed to store all the FCVAR_USERINFO cvar values
virtual int GetTotalUserInfoCvarsByteSize() = 0;
// Copies default values of all cvars which have FCVAR_USERINFO flag to the buffer in a byte range from->to
// if copy_or_cleanup is true, if false would cleanup the buffer
virtual void CopyUserInfoCvarDefaults( uint8* buffer, int from, int to, bool copy_or_cleanup ) = 0;
// Register, unregister vars
virtual void RegisterConVar( const ConVarCreation_t& setup, uint64 nAdditionalFlags, ConVarRef* pCvarRef, ConVarData** pCvarData ) = 0;
// Unregisters convar change callback, but leaves the convar in the lists,
@ -126,7 +138,7 @@ public:
virtual ConCommandData* GetConCommandData( ConCommandRef cmd ) = 0;
// Queues up value (creates a copy of it) to be set when convar is ready to be edited
virtual void QueueThreadSetValue( ConVarRefAbstract* ref, CSplitScreenSlot nSlot, CVValue_t* value ) = 0;
virtual void QueueThreadSetValue( ConVarRefAbstract* ref, CSplitScreenSlot nSlot, void* __unk01, CVValue_t* value ) = 0;
};
#include "memdbgon.h"
@ -185,6 +197,7 @@ public:
struct CConVarChangeCallbackNode_t
{
FnGenericChangeCallbackProvider_t m_pProviderCallBack;
FnGenericChangeCallback_t m_pCallback;
// Register index of cvar which change cb comes from
@ -205,6 +218,7 @@ public:
{
ConVarRefAbstract *m_ConVar;
CSplitScreenSlot m_Slot;
void *m_unk001;
CVValue_t *m_Value;
};
@ -236,6 +250,11 @@ public:
CUtlVector<QueuedConVarSet_t> m_SetValueQueue;
CUtlVector<ConVarRef> m_SetToDefaultValueQueue;
bool m_LockDefaultValueInit;
int m_UserInfoCvarsTotalByteSize;
CConCommandMemberAccessor<CCvar> m_FindCmd;
CConCommandMemberAccessor<CCvar> m_DumpChannelsCmd;
CConCommandMemberAccessor<CCvar> m_LogLevelCmd;

View File

@ -607,7 +607,16 @@ private:
void Destroy( );
};
template <typename T>
class CConVar;
template <typename T>
using FnTypedChangeCallback_t = void (*)(CConVar<T> *cvar, CSplitScreenSlot nSlot, const T *pNewValue, const T *pOldValue);
template <typename T>
using FnTypedChangeCallbackProvider_t = void(*)(CConVar<T> *cvar, CSplitScreenSlot slot, const T *pNewValue, const T *pOldValue, void *__unk01, FnTypedChangeCallback_t<T> cb);
using FnGenericChangeCallback_t = void(*)(ConVarRefAbstract *ref, CSplitScreenSlot nSlot, const CVValue_t *pNewValue, const CVValue_t *pOldValue);
using FnGenericChangeCallbackProvider_t = void(*)(ConVarRefAbstract *ref, CSplitScreenSlot nSlot, const CVValue_t *pNewValue, const CVValue_t *pOldValue, void *__unk01, FnGenericChangeCallback_t cb);
struct ConVarValueInfo_t
{
@ -644,6 +653,19 @@ struct ConVarValueInfo_t
*reinterpret_cast<T *>(m_maxValue) = max;
}
template <typename T>
void SetCallback( FnTypedChangeCallback_t<T> cb )
{
if(cb)
{
m_fnProviderCallBack = []( ConVarRefAbstract *ref, CSplitScreenSlot nSlot, const CVValue_t *pNewValue, const CVValue_t *pOldValue, void *__unk01, FnGenericChangeCallback_t cb ) {
reinterpret_cast<FnTypedChangeCallback_t<T>>(cb)(reinterpret_cast<CConVar<T> *>(ref), nSlot, reinterpret_cast<const T *>(pNewValue), reinterpret_cast<const T *>(pOldValue));
};
m_fnCallBack = reinterpret_cast<FnGenericChangeCallback_t>(cb);
}
}
int32 m_Version;
bool m_bHasDefault;
@ -858,6 +880,7 @@ public:
int GetGameInfoFlags() const { return m_GameInfoFlags; }
int GetCallbackIndex() const { return m_iCallbackIndex; }
int GetUserInfoByteIndex() const { return m_UserInfoByteIndex; }
int GetMaxSplitScreenSlots() const;
@ -945,10 +968,11 @@ private:
unsigned int m_iCallbackIndex;
int m_GameInfoFlags;
int m_UserInfoByteIndex;
// At convar registration this is trimmed to better match convar type being used
// or if it was initialized as EConVarType_Invalid it would be of this size
uint8 m_Values[sizeof( CVValue_t ) * MAX_SPLITSCREEN_CLIENTS];
alignas( CVValue_t ) uint8 m_Values[sizeof( CVValue_t ) * MAX_SPLITSCREEN_CLIENTS];
};
static ConVarData *GetInvalidConVarData( EConVarType type )

View File

@ -590,7 +590,7 @@ void ConVarRefAbstract::QueueSetValueInternal( CSplitScreenSlot slot, CVValue_t
TypeTraits()->Clamp( value, m_ConVarData->MinValue(), m_ConVarData->MaxValue() );
if(!m_ConVarData->IsEqual( slot, value ))
g_pCVar->QueueThreadSetValue( this, slot, value );
g_pCVar->QueueThreadSetValue( this, slot, nullptr, value );
}
void ConVarRefAbstract::SetValueInternal( CSplitScreenSlot slot, CVValue_t *value )