From 3c33d8ab942f31a4623eba61b6c9ead7584eea60 Mon Sep 17 00:00:00 2001 From: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:40:46 +0300 Subject: [PATCH] Update ICvar & Cvar structs --- public/icvar.h | 13 +++++++++++++ public/tier1/convar.h | 44 ++++++++++++++++++++++++++++++++----------- tier1/convar.cpp | 2 +- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/public/icvar.h b/public/icvar.h index f449922e..c297b7d4 100644 --- a/public/icvar.h +++ b/public/icvar.h @@ -121,6 +121,10 @@ public: // if copy_or_cleanup is true, if false would cleanup the buffer virtual void CopyUserInfoCvarDefaults( ConVarUserInfoSet_t buffer, int from, int to, bool copy_or_cleanup ) = 0; + // Calls completion callbacks on cvars and concommands if they exist, successful would be true if so + // Cvars & Concommands needs to have FCVAR_VCONSOLE_FUZZY_MATCHING for successful to be true if callbacks are available + virtual void GetCompletionResults( const CCommand &command, CUtlVector< CUtlString > &completions, bool *successful = nullptr ) = 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, @@ -218,6 +222,14 @@ public: int m_ConVarIndex; }; + struct ConVarCompletionCallbackData_t + { + CompletionCallbackInfo_t m_pCallBack; + + // Register index of cvar which change cb comes from + int m_ConVarIndex; + }; + struct ConCommandCallbackInfoNode_t { ConCommandCallbackInfo_t m_CB; @@ -245,6 +257,7 @@ public: CUtlHashtable m_ConVarHashes; CUtlLinkedList m_ConVarChangeCBList; CUtlLinkedList m_ConVarFilterCBList; + CUtlLinkedList m_ConVarCompletionCBList; int m_ConVarCount; CUtlVector m_CvarCreationListeners; diff --git a/public/tier1/convar.h b/public/tier1/convar.h index 767bf771..8b3b00e0 100644 --- a/public/tier1/convar.h +++ b/public/tier1/convar.h @@ -443,21 +443,21 @@ struct ConCommandCallbackInfo_t bool m_bIsContextLess : 1; }; -struct ConCommandCompletionCallbackInfo_t +struct CompletionCallbackInfo_t { - ConCommandCompletionCallbackInfo_t() : + CompletionCallbackInfo_t() : m_fnCompletionCallback( nullptr ), m_bIsFunction( false ), m_bIsInterface( false ) {} - ConCommandCompletionCallbackInfo_t( FnCommandCompletionCallback cb ) : + CompletionCallbackInfo_t( FnCommandCompletionCallback cb ) : m_fnCompletionCallback( cb ), m_bIsFunction( cb ? true : false ), m_bIsInterface( false ) {} - ConCommandCompletionCallbackInfo_t( ICommandCompletionCallback *cb ) : + CompletionCallbackInfo_t( ICommandCompletionCallback *cb ) : m_pCommandCompletionCallback( cb ), m_bIsFunction( false ), m_bIsInterface( cb ? true : false ) @@ -490,7 +490,7 @@ struct ConCommandCompletionCallbackInfo_t struct ConCommandCreation_t : CVarCreationBase_t { ConCommandCallbackInfo_t m_CBInfo; - ConCommandCompletionCallbackInfo_t m_CompletionCBInfo; + CompletionCallbackInfo_t m_CompletionCBInfo; }; //----------------------------------------------------------------------------- @@ -520,7 +520,7 @@ public: const char* m_pszHelpString; uint64 m_nFlags; - ConCommandCompletionCallbackInfo_t m_CompletionCB; + CompletionCallbackInfo_t m_CompletionCB; // Register index of concommand which completion cb comes from int m_CompletionCBCmdIndex; @@ -591,7 +591,7 @@ public: ConCommand( const char *pName, ConCommandCallbackInfo_t callback, const char *pHelpString, uint64 flags = 0, - ConCommandCompletionCallbackInfo_t completionFunc = ConCommandCompletionCallbackInfo_t() ) + CompletionCallbackInfo_t completionFunc = CompletionCallbackInfo_t() ) : BaseClass() { Create( pName, callback, pHelpString, flags, completionFunc ); @@ -603,7 +603,7 @@ public: } private: - void Create( const char *pName, const ConCommandCallbackInfo_t &cb, const char *pHelpString, uint64 flags, const ConCommandCompletionCallbackInfo_t &completion_cb ); + void Create( const char *pName, const ConCommandCallbackInfo_t &cb, const char *pHelpString, uint64 flags, const CompletionCallbackInfo_t &completion_cb ); void Destroy( ); }; @@ -640,7 +640,8 @@ struct ConVarValueInfo_t m_fnCallBack( nullptr ), m_fnProviderFilterCallBack( nullptr ), m_fnFilterCallBack( nullptr ), - m_eVarType( type ) + m_eVarType( type ), + m_CompletionCallBack() {} template @@ -690,6 +691,11 @@ struct ConVarValueInfo_t } } + void SetCompletionCallback( const CompletionCallbackInfo_t &cb ) + { + m_CompletionCallBack = cb; + } + int32 m_Version; bool m_bHasDefault; @@ -710,6 +716,8 @@ public: FnGenericFilterCallback_t m_fnFilterCallBack; EConVarType m_eVarType; + + CompletionCallbackInfo_t m_CompletionCallBack; }; struct ConVarCreation_t : CVarCreationBase_t @@ -998,6 +1006,8 @@ private: unsigned int m_iCallbackIndex; // Index into a linked list of cvar filter callbacks unsigned int m_iFilterCBIndex; + // Index into a linked list of cvar completion callbacks + unsigned int m_iCompletionCBIndex; int m_GameInfoFlags; int m_UserInfoByteIndex; @@ -1267,7 +1277,7 @@ class CConVar : public CConVarRef public: typedef CConVarRef BaseClass; - CConVar( const char *name, uint64 flags, const char *help_string, const T &default_value, FnTypedChangeCallback_t cb = nullptr ) + CConVar( const char *name, uint64 flags, const char *help_string, const T &default_value, FnTypedChangeCallback_t cb = nullptr, const CompletionCallbackInfo_t &completion_cb = {} ) : BaseClass() { Assert( name ); @@ -1278,10 +1288,16 @@ public: value_info.SetDefaultValue( default_value ); value_info.SetCallback( cb ); + if(completion_cb.IsValid()) + { + value_info.SetCompletionCallback( completion_cb ); + flags |= FCVAR_VCONSOLE_FUZZY_MATCHING; + } + BaseClass::Register( name, flags, help_string, value_info ); } - CConVar( const char *name, uint64 flags, const char *help_string, const T &default_value, bool min, const T &minValue, bool max, const T &maxValue, FnTypedChangeCallback_t cb = nullptr, FnTypedFilterCallback_t filter_cb = nullptr ) + CConVar( const char *name, uint64 flags, const char *help_string, const T &default_value, bool min, const T &minValue, bool max, const T &maxValue, FnTypedChangeCallback_t cb = nullptr, FnTypedFilterCallback_t filter_cb = nullptr, const CompletionCallbackInfo_t &completion_cb = {} ) : BaseClass() { Assert( name ); @@ -1299,6 +1315,12 @@ public: value_info.SetCallback( cb ); value_info.SetFilterCallback( filter_cb ); + + if(completion_cb.IsValid()) + { + value_info.SetCompletionCallback( completion_cb ); + flags |= FCVAR_VCONSOLE_FUZZY_MATCHING; + } BaseClass::Register( name, flags, help_string, value_info ); } diff --git a/tier1/convar.cpp b/tier1/convar.cpp index caf64841..b884854d 100644 --- a/tier1/convar.cpp +++ b/tier1/convar.cpp @@ -461,7 +461,7 @@ void ConCommandRef::Dispatch( const CCommandContext &context, const CCommand &co g_pCVar->DispatchConCommand( *this, context, command ); } -void ConCommand::Create( const char* pName, const ConCommandCallbackInfo_t &cb, const char* pHelpString, uint64 flags, const ConCommandCompletionCallbackInfo_t &completion_cb ) +void ConCommand::Create( const char* pName, const ConCommandCallbackInfo_t &cb, const char* pHelpString, uint64 flags, const CompletionCallbackInfo_t &completion_cb ) { // Name should be static data Assert(pName);