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

KeyValues & ICommandLine fixes after 7/2/24 CS2 update (#201)

Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
This commit is contained in:
Mooshua
2024-02-07 01:55:45 -08:00
committed by GitHub
parent ae57ae168d
commit fdc4954f22
4 changed files with 51 additions and 34 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
@ -12,6 +12,7 @@
#include "tier0/platform.h"
class CBufferString;
//-----------------------------------------------------------------------------
// Purpose: Interface to engine command line
@ -21,12 +22,11 @@ abstract_class ICommandLine
public:
virtual void CreateCmdLine( const char *commandline ) = 0;
virtual void CreateCmdLine( int argc, char **argv ) = 0;
virtual const char *GetCmdLine( void ) const = 0;
virtual void CreateCmdLinePrependAppName( const char *commandline ) = 0;
// Check whether a particular parameter exists
virtual const char *CheckParm( const char *psz, const char **ppszValue = 0 ) const = 0;
virtual bool HasParm( const char *psz ) const = 0;
virtual void AppendParm( const char *pszParm, const char *pszValues ) = 0;
// Gets at particular parameters
virtual int ParmCount() const = 0;
@ -37,14 +37,16 @@ public:
virtual const char *ParmValue( const char *psz, const char *pDefaultVal = 0 ) const = 0;
virtual int ParmValue( const char *psz, int nDefaultVal ) const = 0;
virtual float ParmValue( const char *psz, float flDefaultVal ) const = 0;
virtual bool ParmValue( const char *psz, const char *pDefaultVal, char *pszOut, unsigned int size ) = 0;
virtual bool ParmValue( const char *psz, const char *pDefaultVal, CBufferString *bufOut ) = 0;
virtual const char *ParmValueByIndex( int nIndex, const char *pDefaultVal ) const = 0;
virtual void CreateCmdLinePrependAppName( const char *commandline ) = 0;
virtual const char **GetParms() const = 0;
virtual const char *GetCmdLine( void ) const = 0;
virtual void AppendParm( const char *pszParm, const char *pszValues ) = 0;
virtual bool IsWellInitialized( void ) const = 0;
// Returns true if there's atleast one parm available
virtual bool HasParms( void ) const = 0;
virtual const char *GetUnkString() = 0;
};
//-----------------------------------------------------------------------------

View File

@ -85,6 +85,12 @@ public:
TYPE_NUMTYPES,
};
protected:
// AMNOTE: Valve scrapped the public-facing version of these,
// so we have to expose as protected for the scaffolds below in KeyValues.
char const *Internal_GetString( const char *defaultValue, char *szBuf, size_t maxlen );
const wchar_t *Internal_GetWString( const wchar_t *defaultValue, wchar_t *szBuf, size_t maxlen );
private:
IKeyValuesSystem *KVSystem() const;
@ -119,8 +125,6 @@ private:
float Internal_GetFloat() const;
int Internal_GetInt() const;
uint64 Internal_GetUint64() const;
char const *Internal_GetString( const char *defaultValue, char *szBuf, size_t maxlen );
const wchar_t *Internal_GetWString( const wchar_t *defaultValue, wchar_t *szBuf, size_t maxlen );
void *Internal_GetPtr() const;
void Internal_SetColor( Color value );
@ -254,9 +258,9 @@ public:
// Find a keyValue, create it if it is not found.
// Set bCreate to true to create the key if it doesn't already exist (which ensures a valid pointer will be returned)
KeyValues *FindKey( const char *keyName, bool bCreate );
KeyValues *FindKey( const char *keyName, bool bCreate = false );
const KeyValues *FindKey( const char *keyName ) const;
KeyValues *FindKey( HKeySymbol keySymbol ) const;
KeyValues *FindKey( HKeySymbol keySymbol );
KeyValues *FindKeyAndParent( const char *keyName, KeyValues **pParent, bool );
bool FindAndDeleteSubKey( const char *keyName );
@ -281,9 +285,9 @@ public:
// NOTE: GetFirstSubKey/GetNextKey will iterate keys AND values. Use the functions
// below if you want to iterate over just the keys or just the values.
//
KeyValues *GetFirstSubKey() const; // returns the first subkey in the list
KeyValues *FindLastSubKey() const;
KeyValues *GetNextKey() const; // returns the next subkey
KeyValues *GetFirstSubKey(); // returns the first subkey in the list
KeyValues *FindLastSubKey();
KeyValues *GetNextKey(); // returns the next subkey
void SetNextKey( KeyValues *pDat );
//
@ -299,11 +303,11 @@ public:
// {
// Msg( "Int value: %d\n", pValue->GetInt() ); // Assuming pValue->GetDataType() == TYPE_INT...
// }
KeyValues *GetFirstTrueSubKey() const;
KeyValues *GetNextTrueSubKey() const;
KeyValues *GetFirstTrueSubKey();
KeyValues *GetNextTrueSubKey();
KeyValues *GetFirstValue() const; // When you get a value back, you can use GetX and pass in NULL to get the value.
KeyValues *GetNextValue() const;
KeyValues *GetFirstValue(); // When you get a value back, you can use GetX and pass in NULL to get the value.
KeyValues *GetNextValue();
// Data access
@ -318,15 +322,15 @@ public:
bool IsEmpty( const char *keyName = NULL ) const;
// Data access
int GetInt( HKeySymbol keySymbol, int defaultValue = 0 ) const;
uint64 GetUint64( HKeySymbol keySymbol, uint64 defaultValue = 0 ) const;
float GetFloat( HKeySymbol keySymbol, float defaultValue = 0.0f ) const;
int GetInt( HKeySymbol keySymbol, int defaultValue = 0 );
uint64 GetUint64( HKeySymbol keySymbol, uint64 defaultValue = 0 );
float GetFloat( HKeySymbol keySymbol, float defaultValue = 0.0f );
const char *GetString( HKeySymbol keySymbol, const char *defaultValue = "", char *pszOut = NULL, size_t maxlen = 0 );
const wchar_t *GetWString( HKeySymbol keySymbol, const wchar_t *defaultValue = L"", wchar_t *pszOut = NULL, size_t maxlen = 0 );
void *GetPtr( HKeySymbol keySymbol, void *defaultValue = (void *)0 ) const;
Color GetColor( HKeySymbol keySymbol, const Color &defaultColor = Color( 0, 0, 0, 0 ) ) const;
bool GetBool( HKeySymbol keySymbol, bool defaultValue = false ) const { return GetInt( keySymbol, defaultValue ? 1 : 0 ) ? true : false; }
bool IsEmpty( HKeySymbol keySymbol ) const;
void *GetPtr( HKeySymbol keySymbol, void *defaultValue = (void *)0 );
Color GetColor( HKeySymbol keySymbol, const Color &defaultColor = Color( 0, 0, 0, 0 ) );
bool GetBool( HKeySymbol keySymbol, bool defaultValue = false ) { return GetInt( keySymbol, defaultValue ? 1 : 0 ) ? true : false; }
bool IsEmpty( HKeySymbol keySymbol );
// Key writing
void SetWString( const char *keyName, const wchar_t *value );
@ -353,7 +357,7 @@ public:
KeyValues &operator=( KeyValues &src );
void RecursiveSaveToFile( CUtlBuffer &buf, int indentLevel, bool bSortKeys = false, bool bAllowEmptyString = false );
void RecursiveSaveToFile( CUtlBuffer &buf, int indentLevel, bool bSortKeys = false, bool bAllowEmptyString = false ) const;
void RecursiveSaveToLocalizationFile( IFileSystem *filesystem, void *buf, int indentLevel, bool bAllowEmptyString = false );
bool WriteAsBinary( CUtlBuffer &buffer );
@ -375,7 +379,7 @@ public:
int Count( void ) const;
KeyValues *Element( int nIndex ) const;
KeyValues *Element( int nIndex );
CKeyValues_Data::types_t GetDataType( const char *keyName = NULL ) const;
@ -441,19 +445,19 @@ struct KeyValuesUnpackStructure
//-----------------------------------------------------------------------------
// inline methods
//-----------------------------------------------------------------------------
inline int KeyValues::GetInt( HKeySymbol keySymbol, int defaultValue ) const
inline int KeyValues::GetInt( HKeySymbol keySymbol, int defaultValue )
{
KeyValues *dat = FindKey( keySymbol );
return dat ? dat->GetInt( (const char *)NULL, defaultValue ) : defaultValue;
}
inline uint64 KeyValues::GetUint64( HKeySymbol keySymbol, uint64 defaultValue ) const
inline uint64 KeyValues::GetUint64( HKeySymbol keySymbol, uint64 defaultValue )
{
KeyValues *dat = FindKey( keySymbol );
return dat ? dat->GetUint64( (const char *)NULL, defaultValue ) : defaultValue;
}
inline float KeyValues::GetFloat( HKeySymbol keySymbol, float defaultValue ) const
inline float KeyValues::GetFloat( HKeySymbol keySymbol, float defaultValue )
{
KeyValues *dat = FindKey( keySymbol );
return dat ? dat->GetFloat( (const char *)NULL, defaultValue ) : defaultValue;
@ -471,24 +475,35 @@ inline const wchar_t *KeyValues::GetWString( HKeySymbol keySymbol, const wchar_t
return dat ? dat->GetWString( (const char *)NULL, defaultValue, pszOut, maxlen ) : defaultValue;
}
inline void *KeyValues::GetPtr( HKeySymbol keySymbol, void *defaultValue ) const
inline void *KeyValues::GetPtr( HKeySymbol keySymbol, void *defaultValue )
{
KeyValues *dat = FindKey( keySymbol );
return dat ? dat->GetPtr( (const char *)NULL, defaultValue ) : defaultValue;
}
inline Color KeyValues::GetColor( HKeySymbol keySymbol, const Color &defaultColor ) const
inline Color KeyValues::GetColor( HKeySymbol keySymbol, const Color &defaultColor )
{
KeyValues *dat = FindKey( keySymbol );
return dat ? dat->GetColor( (const char *)NULL, defaultColor ) : defaultColor;
}
inline bool KeyValues::IsEmpty( HKeySymbol keySymbol ) const
inline bool KeyValues::IsEmpty( HKeySymbol keySymbol )
{
KeyValues *dat = FindKey( keySymbol );
return dat ? dat->IsEmpty() : true;
}
inline const char *KeyValues::GetString( const char *keyName, const char *defaultValue, char *pszOut, size_t maxlen )
{
KeyValues *dat = FindKey( keyName );
return dat ? dat->Internal_GetString( defaultValue, pszOut, maxlen ) : defaultValue;
}
inline const wchar_t *KeyValues::GetWString( const char *keyName, const wchar_t *defaultValue, wchar_t *pszOut, size_t maxlen )
{
KeyValues *dat = FindKey( keyName );
return dat ? dat->Internal_GetWString( defaultValue, pszOut, maxlen ) : defaultValue;
}
//
// KeyValuesDumpContext and generic implementations