1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2026-10-10 03:43:06 +08:00

Apply the complete KeyValues changes for TF2

This commit is contained in:
Kenzzer
2026-10-02 15:10:27 +00:00
parent 9c2efb1dee
commit 631a7b6c0c
2 changed files with 45 additions and 10 deletions
+3 -1
View File
@@ -270,9 +270,11 @@ public:
private:
KeyValues( KeyValues& ); // prevent copy constructor being used
KeyValues( const char *setName, CKeyValuesGrowableStringTable *pLocalStringTable );
// prevent delete being called except through deleteThis()
~KeyValues();
KeyValues *CreateChild( const char *keyName ) const;
/// Create a child key, given that we know which child is currently the last child.
@@ -334,7 +336,7 @@ private:
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_bIsUsingLocalStringTable; // true if this node uses a per-instance growable string table
char m_bIsUsingLocalStringTable2;
char m_bOwnsLocalStringTable; // true if this node owns and must delete the per-instance string table
KeyValues *m_pPeer; // pointer to next key in list
KeyValues *m_pSub; // pointer to Start of a new sub key list
+42 -9
View File
@@ -383,6 +383,7 @@ const char *KeyValues::GetStringForSymbolGrowable( int symbol )
//-----------------------------------------------------------------------------
KeyValues::KeyValues( const char *setName ) :
m_bIsUsingLocalStringTable( false ),
m_bOwnsLocalStringTable( false ),
m_pLocalStringTable( NULL )
{
TRACK_KV_ADD( this, setName );
@@ -396,6 +397,7 @@ KeyValues::KeyValues( const char *setName ) :
//-----------------------------------------------------------------------------
KeyValues::KeyValues( const char *setName, bool bUsesLocalStorage ) :
m_bIsUsingLocalStringTable( false ),
m_bOwnsLocalStringTable( false ),
m_pLocalStringTable( NULL )
{
TRACK_KV_ADD( this, setName );
@@ -405,16 +407,31 @@ KeyValues::KeyValues( const char *setName, bool bUsesLocalStorage ) :
{
m_pLocalStringTable = new CKeyValuesGrowableStringTable( 256 );
m_bIsUsingLocalStringTable = true;
m_bIsUsingLocalStringTable2 = true;
m_bOwnsLocalStringTable = true;
}
SetName( setName );
}
//-----------------------------------------------------------------------------
// Purpose: Constructor for child nodes sharing a per-instance string table
//-----------------------------------------------------------------------------
KeyValues::KeyValues( const char *setName, CKeyValuesGrowableStringTable *pLocalStringTable ) :
m_bIsUsingLocalStringTable( pLocalStringTable != NULL ),
m_bOwnsLocalStringTable( false ),
m_pLocalStringTable( pLocalStringTable )
{
TRACK_KV_ADD( this, setName );
Init();
SetName( setName );
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
KeyValues::KeyValues( const char *setName, const char *firstKey, const char *firstValue ) :
m_bIsUsingLocalStringTable( false ),
m_bOwnsLocalStringTable( false ),
m_pLocalStringTable( NULL )
{
TRACK_KV_ADD( this, setName );
@@ -429,6 +446,7 @@ KeyValues::KeyValues( const char *setName, const char *firstKey, const char *fir
//-----------------------------------------------------------------------------
KeyValues::KeyValues( const char *setName, const char *firstKey, const wchar_t *firstValue ) :
m_bIsUsingLocalStringTable( false ),
m_bOwnsLocalStringTable( false ),
m_pLocalStringTable( NULL )
{
TRACK_KV_ADD( this, setName );
@@ -443,6 +461,7 @@ KeyValues::KeyValues( const char *setName, const char *firstKey, const wchar_t *
//-----------------------------------------------------------------------------
KeyValues::KeyValues( const char *setName, const char *firstKey, int firstValue ) :
m_bIsUsingLocalStringTable( false ),
m_bOwnsLocalStringTable( false ),
m_pLocalStringTable( NULL )
{
TRACK_KV_ADD( this, setName );
@@ -457,6 +476,7 @@ KeyValues::KeyValues( const char *setName, const char *firstKey, int firstValue
//-----------------------------------------------------------------------------
KeyValues::KeyValues( const char *setName, const char *firstKey, const char *firstValue, const char *secondKey, const char *secondValue ) :
m_bIsUsingLocalStringTable( false ),
m_bOwnsLocalStringTable( false ),
m_pLocalStringTable( NULL )
{
TRACK_KV_ADD( this, setName );
@@ -472,6 +492,7 @@ KeyValues::KeyValues( const char *setName, const char *firstKey, const char *fir
//-----------------------------------------------------------------------------
KeyValues::KeyValues( const char *setName, const char *firstKey, int firstValue, const char *secondKey, int secondValue ) :
m_bIsUsingLocalStringTable( false ),
m_bOwnsLocalStringTable( false ),
m_pLocalStringTable( NULL )
{
TRACK_KV_ADD( this, setName );
@@ -510,7 +531,7 @@ KeyValues::~KeyValues()
TRACK_KV_REMOVE( this );
RemoveEverything();
if ( m_bIsUsingLocalStringTable )
if ( m_bOwnsLocalStringTable )
{
delete m_pLocalStringTable;
m_pLocalStringTable = NULL;
@@ -577,6 +598,18 @@ const char *KeyValues::GetName( void ) const
return s_pfGetStringForSymbol( m_iKeyName );
}
//-----------------------------------------------------------------------------
// Purpose: Create a child that shares this node's local string table, if any
//-----------------------------------------------------------------------------
KeyValues *KeyValues::CreateChild( const char *keyName ) const
{
if ( m_bIsUsingLocalStringTable )
{
return new KeyValues( keyName, m_pLocalStringTable );
}
return new KeyValues( keyName );
}
//-----------------------------------------------------------------------------
// Purpose: Read a single token from buffer (0 terminated)
//-----------------------------------------------------------------------------
@@ -1082,7 +1115,7 @@ KeyValues *KeyValues::FindKey(const char *keyName, bool bCreate)
if (bCreate)
{
// we need to create a new key
dat = new KeyValues( searchStr );
dat = CreateChild( searchStr );
// Assert(dat != NULL);
dat->UsesEscapeSequences( m_bHasEscapeSequences != 0 ); // use same format as parent
@@ -1162,7 +1195,7 @@ KeyValues* KeyValues::CreateKey( const char *keyName )
KeyValues* KeyValues::CreateKeyUsingKnownLastChild( const char *keyName, KeyValues *pLastChild )
{
// Create a new key
KeyValues* dat = new KeyValues( keyName );
KeyValues* dat = CreateChild( keyName );
dat->UsesEscapeSequences( m_bHasEscapeSequences != 0 ); // use same format as parent does
dat->UsesConditionals( m_bEvaluateConditionals != 0 );
@@ -1833,13 +1866,13 @@ void KeyValues::CopyKeyValuesFromRecursive( const KeyValues& rootSrc )
// Add children to the queue to process later.
if (cs.src->m_pSub) {
cs.dst->m_pSub = localDst = new KeyValues( NULL );
cs.dst->m_pSub = localDst = cs.dst->CreateChild( NULL );
nodeQ.Insert({ localDst, cs.src->m_pSub });
}
// Process siblings until we hit the end of the line.
if (cs.src->m_pPeer) {
cs.dst->m_pPeer = new KeyValues( NULL );
cs.dst->m_pPeer = cs.dst->CreateChild( NULL );
}
else {
cs.dst->m_pPeer = NULL;
@@ -2360,7 +2393,7 @@ bool KeyValues::LoadFromBuffer( char const *resourceName, CUtlBuffer &buf, IBase
if ( !pCurrentKey )
{
pCurrentKey = new KeyValues( s );
pCurrentKey = CreateChild( s );
Assert( pCurrentKey );
pCurrentKey->UsesEscapeSequences( m_bHasEscapeSequences != 0 ); // same format has parent use
@@ -2807,7 +2840,7 @@ bool KeyValues::ReadAsBinary( CUtlBuffer &buffer, int nStackDepth )
{
case TYPE_NONE:
{
dat->m_pSub = new KeyValues("");
dat->m_pSub = dat->CreateChild( "" );
if ( !dat->m_pSub->ReadAsBinary( buffer, nStackDepth + 1 ) )
return false;
break;
@@ -2881,7 +2914,7 @@ bool KeyValues::ReadAsBinary( CUtlBuffer &buffer, int nStackDepth )
break;
// new peer follows
dat->m_pPeer = new KeyValues("");
dat->m_pPeer = dat->CreateChild( "" );
dat = dat->m_pPeer;
}