Update KeyValues src with latest tf2 change (#348)

This commit is contained in:
Benoist 2025-10-26 17:27:11 +01:00 committed by GitHub
commit 65219f131f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 6 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -39,6 +39,7 @@ class CUtlBuffer;
class Color; class Color;
typedef void * FileHandle_t; typedef void * FileHandle_t;
class CKeyValuesGrowableStringTable; class CKeyValuesGrowableStringTable;
class IKeyValuesSystem;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: Simple recursive data access class // Purpose: Simple recursive data access class
@ -117,9 +118,12 @@ public:
// gets the name as a unique int // gets the name as a unique int
int GetNameSymbol() const { return m_iKeyName; } int GetNameSymbol() const { return m_iKeyName; }
bool IsUsingLocalStorage() const;
// File access. Set UsesEscapeSequences true, if resource file/buffer uses Escape Sequences (eg \n, \t) // File access. Set UsesEscapeSequences true, if resource file/buffer uses Escape Sequences (eg \n, \t)
void UsesEscapeSequences(bool state); // default false void UsesEscapeSequences(bool state); // default false
void UsesConditionals(bool state); // default true void UsesConditionals(bool state); // default true
bool LoadFromFile( IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL, bool refreshCache = false ); bool LoadFromFile( IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL, bool refreshCache = false );
bool SaveToFile( IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL, bool sortKeys = false, bool bAllowEmptyString = false, bool bCacheResult = false ); bool SaveToFile( IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL, bool sortKeys = false, bool bAllowEmptyString = false, bool bCacheResult = false );
@ -330,12 +334,14 @@ private:
char m_iDataType; char m_iDataType;
char m_bHasEscapeSequences; // true, if while parsing this KeyValue, Escape Sequences are used (default false) char m_bHasEscapeSequences; // true, if while parsing this KeyValue, Escape Sequences are used (default false)
char m_bEvaluateConditionals; // true, if while parsing this KeyValue, conditionals blocks are evaluated (default true) char m_bEvaluateConditionals; // true, if while parsing this KeyValue, conditionals blocks are evaluated (default true)
char unused[1]; char m_bLocalStorage;
KeyValues *m_pPeer; // pointer to next key in list KeyValues *m_pPeer; // pointer to next key in list
KeyValues *m_pSub; // pointer to Start of a new sub key list KeyValues *m_pSub; // pointer to Start of a new sub key list
KeyValues *m_pChain;// Search here if it's not in our list KeyValues *m_pChain;// Search here if it's not in our list
CKeyValuesGrowableStringTable* m_pStringTable;
private: private:
// Statics to implement the optional growable string table // Statics to implement the optional growable string table
// Function pointers that will determine which mode we are in // Function pointers that will determine which mode we are in

View File

@ -461,9 +461,9 @@ void KeyValues::Init()
m_bHasEscapeSequences = false; m_bHasEscapeSequences = false;
m_bEvaluateConditionals = true; m_bEvaluateConditionals = true;
m_bLocalStorage = false;
// for future proof m_pStringTable = NULL;
memset( unused, 0, sizeof(unused) );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -528,7 +528,10 @@ void KeyValues::ChainKeyValue( KeyValues* pChain )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const char *KeyValues::GetName( void ) const const char *KeyValues::GetName( void ) const
{ {
return s_pfGetStringForSymbol( m_iKeyName ); if ( m_bLocalStorage )
return m_pStringTable->GetStringForSymbol( m_iKeyName );
else
return s_pfGetStringForSymbol( m_iKeyName );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -1001,7 +1004,9 @@ KeyValues *KeyValues::FindKey(const char *keyName, bool bCreate)
} }
// lookup the symbol for the search string // lookup the symbol for the search string
HKeySymbol iSearchStr = s_pfGetSymbolForString( searchStr, bCreate ); HKeySymbol iSearchStr = m_bLocalStorage
? m_pStringTable->GetSymbolForString( searchStr, bCreate )
: s_pfGetSymbolForString( searchStr, bCreate );
if ( iSearchStr == INVALID_KEY_SYMBOL ) if ( iSearchStr == INVALID_KEY_SYMBOL )
{ {
@ -1730,7 +1735,18 @@ void KeyValues::SetFloat( const char *keyName, float value )
void KeyValues::SetName( const char * setName ) void KeyValues::SetName( const char * setName )
{ {
m_iKeyName = s_pfGetSymbolForString( setName, true ); if ( m_bLocalStorage )
m_iKeyName = m_pStringTable->GetSymbolForString( setName );
else
m_iKeyName = s_pfGetSymbolForString( setName, true );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool KeyValues::IsUsingLocalStorage() const
{
return m_bLocalStorage != 0;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------