From 05a5907e059f87ab5d7ddbb612e94f3f92654cbc Mon Sep 17 00:00:00 2001 From: Poggu <45881722+Poggicek@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:41:15 +0200 Subject: [PATCH] Rename byteswap to cbyteswap (#140) Resolves include collision with protobuf dependency --- common/compiledcaptionswap.cpp | 4 +- common/studiobyteswap.h | 4 +- game/client/game_controls/teammenu.cpp | 4 +- game/server/baseflex.cpp | 4 +- interfaces/interfaces.vcxproj | 2 +- interfaces/interfaces.vcxproj.filters | 2 +- public/tier1/{byteswap.h => cbyteswap.h} | 536 +++++++++++------------ public/tier1/utlbuffer.h | 4 +- public/zip_utils.cpp | 2 +- tier1/{byteswap.cpp => cbyteswap.cpp} | 180 ++++---- tier1/tier1-2005.vcproj | 4 +- tier1/tier1.vcxproj | 4 +- tier1/tier1.vcxproj.filters | 4 +- 13 files changed, 377 insertions(+), 377 deletions(-) rename public/tier1/{byteswap.h => cbyteswap.h} (97%) rename tier1/{byteswap.cpp => cbyteswap.cpp} (93%) diff --git a/common/compiledcaptionswap.cpp b/common/compiledcaptionswap.cpp index a0ca331a..eb3d5212 100644 --- a/common/compiledcaptionswap.cpp +++ b/common/compiledcaptionswap.cpp @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: Swap a compiled caption file. // @@ -6,7 +6,7 @@ //=============================================================================// #include "utlbuffer.h" -#include "byteswap.h" +#include "cbyteswap.h" #include "filesystem.h" #include "tier2/fileutils.h" #include "captioncompiler.h" diff --git a/common/studiobyteswap.h b/common/studiobyteswap.h index 1e1efc3f..4563a59d 100644 --- a/common/studiobyteswap.h +++ b/common/studiobyteswap.h @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2006, Valve LLC, All rights reserved. ============ +//========= Copyright � 1996-2006, Valve LLC, All rights reserved. ============ // // Purpose: StudioMDL byteswapping functions. // @@ -11,7 +11,7 @@ #pragma once #endif -#include "byteswap.h" +#include "cbyteswap.h" struct studiohdr_t; class IPhysicsCollision; diff --git a/game/client/game_controls/teammenu.cpp b/game/client/game_controls/teammenu.cpp index a5d17240..d33ce764 100644 --- a/game/client/game_controls/teammenu.cpp +++ b/game/client/game_controls/teammenu.cpp @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: // @@ -27,7 +27,7 @@ #include #include // MAX_PATH define #include -#include "byteswap.h" +#include "cbyteswap.h" #include "vgui_int.h" // memdbgon must be the last include file in a .cpp file!!! diff --git a/game/server/baseflex.cpp b/game/server/baseflex.cpp index 1249939e..c2f50383 100644 --- a/game/server/baseflex.cpp +++ b/game/server/baseflex.cpp @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: // @@ -22,7 +22,7 @@ #include "sceneentity.h" #include "ai_baseactor.h" #include "datacache/imdlcache.h" -#include "tier1/byteswap.h" +#include "tier1/cbyteswap.h" #include "toolframework/itoolframework.h" #include "flexcycler.h" diff --git a/interfaces/interfaces.vcxproj b/interfaces/interfaces.vcxproj index e63d0453..83a59f55 100644 --- a/interfaces/interfaces.vcxproj +++ b/interfaces/interfaces.vcxproj @@ -233,7 +233,7 @@ - + diff --git a/interfaces/interfaces.vcxproj.filters b/interfaces/interfaces.vcxproj.filters index 2173ec6e..7fd27238 100644 --- a/interfaces/interfaces.vcxproj.filters +++ b/interfaces/interfaces.vcxproj.filters @@ -14,7 +14,7 @@ Header Files - + Header Files diff --git a/public/tier1/byteswap.h b/public/tier1/cbyteswap.h similarity index 97% rename from public/tier1/byteswap.h rename to public/tier1/cbyteswap.h index 54699620..3cac1238 100644 --- a/public/tier1/byteswap.h +++ b/public/tier1/cbyteswap.h @@ -1,268 +1,268 @@ -//========= Copyright © 1996-2006, Valve LLC, All rights reserved. ============ -// -// Purpose: Low level byte swapping routines. -// -// $NoKeywords: $ -//============================================================================= -#ifndef BYTESWAP_H -#define BYTESWAP_H -#if defined(_WIN32) -#pragma once -#endif - -#include "tier0/dbg.h" -#include "datamap.h" // needed for typedescription_t. note datamap.h is tier1 as well. - -class CByteswap -{ -public: - CByteswap() - { - // Default behavior sets the target endian to match the machine native endian (no swap). - SetTargetBigEndian( IsMachineBigEndian() ); - } - - //----------------------------------------------------------------------------- - // Write a single field. - //----------------------------------------------------------------------------- - void SwapFieldToTargetEndian( void* pOutputBuffer, void *pData, typedescription_t *pField ); - - //----------------------------------------------------------------------------- - // Write a block of fields. Works a bit like the saverestore code. - //----------------------------------------------------------------------------- - void SwapFieldsToTargetEndian( void *pOutputBuffer, void *pBaseData, datamap_t *pDataMap ); - - // Swaps fields for the templated type to the output buffer. - template inline void SwapFieldsToTargetEndian( T* pOutputBuffer, void *pBaseData, unsigned int objectCount = 1 ) - { - for ( unsigned int i = 0; i < objectCount; ++i, ++pOutputBuffer ) - { - SwapFieldsToTargetEndian( (void*)pOutputBuffer, pBaseData, &T::m_DataMap ); - pBaseData = (byte*)pBaseData + sizeof(T); - } - } - - // Swaps fields for the templated type in place. - template inline void SwapFieldsToTargetEndian( T* pOutputBuffer, unsigned int objectCount = 1 ) - { - SwapFieldsToTargetEndian( pOutputBuffer, (void*)pOutputBuffer, objectCount ); - } - - //----------------------------------------------------------------------------- - // True if the current machine is detected as big endian. - // (Endienness is effectively detected at compile time when optimizations are - // enabled) - //----------------------------------------------------------------------------- - static bool IsMachineBigEndian() - { - short nIsBigEndian = 1; - - // if we are big endian, the first byte will be a 0, if little endian, it will be a one. - return (bool)(0 == *(char *)&nIsBigEndian ); - } - - //----------------------------------------------------------------------------- - // Sets the target byte ordering we are swapping to or from. - // - // Braindead Endian Reference: - // x86 is LITTLE Endian - // PowerPC is BIG Endian - //----------------------------------------------------------------------------- - inline void SetTargetBigEndian( bool bigEndian ) - { - m_bBigEndian = bigEndian; - m_bSwapBytes = IsMachineBigEndian() != bigEndian; - } - - // Changes target endian - inline void FlipTargetEndian( void ) - { - m_bSwapBytes = !m_bSwapBytes; - m_bBigEndian = !m_bBigEndian; - } - - // Forces byte swapping state, regardless of endianess - inline void ActivateByteSwapping( bool bActivate ) - { - SetTargetBigEndian( IsMachineBigEndian() != bActivate ); - } - - //----------------------------------------------------------------------------- - // Returns true if the target machine is the same as this one in endianness. - // - // Used to determine when a byteswap needs to take place. - //----------------------------------------------------------------------------- - inline bool IsSwappingBytes( void ) // Are bytes being swapped? - { - return m_bSwapBytes; - } - - inline bool IsTargetBigEndian( void ) // What is the current target endian? - { - return m_bBigEndian; - } - - //----------------------------------------------------------------------------- - // IsByteSwapped() - // - // When supplied with a chunk of input data and a constant or magic number - // (in native format) determines the endienness of the current machine in - // relation to the given input data. - // - // Returns: - // 1 if input is the same as nativeConstant. - // 0 if input is byteswapped relative to nativeConstant. - // -1 if input is not the same as nativeConstant and not byteswapped either. - // - // ( This is useful for detecting byteswapping in magic numbers in structure - // headers for example. ) - //----------------------------------------------------------------------------- - template inline int SourceIsNativeEndian( T input, T nativeConstant ) - { - // If it's the same, it isn't byteswapped: - if( input == nativeConstant ) - return 1; - - int output; - LowLevelByteSwap( &output, &input ); - if( output == nativeConstant ) - return 0; - - Assert( 0 ); // if we get here, input is neither a swapped nor unswapped version of nativeConstant. - return -1; - } - - //----------------------------------------------------------------------------- - // Swaps an input buffer full of type T into the given output buffer. - // - // Swaps [count] items from the inputBuffer to the outputBuffer. - // If inputBuffer is omitted or NULL, then it is assumed to be the same as - // outputBuffer - effectively swapping the contents of the buffer in place. - //----------------------------------------------------------------------------- - template inline void SwapBuffer( T* outputBuffer, T* inputBuffer = NULL, int count = 1 ) - { - Assert( count >= 0 ); - Assert( outputBuffer ); - - // Fail gracefully in release: - if( count <=0 || !outputBuffer ) - return; - - // Optimization for the case when we are swapping in place. - if( inputBuffer == NULL ) - { - inputBuffer = outputBuffer; - } - - // Swap everything in the buffer: - for( int i = 0; i < count; i++ ) - { - LowLevelByteSwap( &outputBuffer[i], &inputBuffer[i] ); - } - } - - //----------------------------------------------------------------------------- - // Swaps an input buffer full of type T into the given output buffer. - // - // Swaps [count] items from the inputBuffer to the outputBuffer. - // If inputBuffer is omitted or NULL, then it is assumed to be the same as - // outputBuffer - effectively swapping the contents of the buffer in place. - //----------------------------------------------------------------------------- - template inline void SwapBufferToTargetEndian( T* outputBuffer, T* inputBuffer = NULL, int count = 1 ) - { - Assert( count >= 0 ); - Assert( outputBuffer ); - - // Fail gracefully in release: - if( count <=0 || !outputBuffer ) - return; - - // Optimization for the case when we are swapping in place. - if( inputBuffer == NULL ) - { - inputBuffer = outputBuffer; - } - - // Are we already the correct endienness? ( or are we swapping 1 byte items? ) - if( !m_bSwapBytes || ( sizeof(T) == 1 ) ) - { - // If we were just going to swap in place then return. - if( !inputBuffer ) - return; - - // Otherwise copy the inputBuffer to the outputBuffer: - if ( outputBuffer != inputBuffer ) - memcpy( outputBuffer, inputBuffer, count * sizeof( T ) ); - return; - - } - - // Swap everything in the buffer: - for( int i = 0; i < count; i++ ) - { - LowLevelByteSwap( &outputBuffer[i], &inputBuffer[i] ); - } - } - -private: - //----------------------------------------------------------------------------- - // The lowest level byte swapping workhorse of doom. output always contains the - // swapped version of input. ( Doesn't compare machine to target endianness ) - //----------------------------------------------------------------------------- - template static void LowLevelByteSwap( T *output, T *input ) - { - T temp = *output; -#if defined( _X360 ) - // Intrinsics need the source type to be fixed-point - DWORD* word = (DWORD*)input; - switch( sizeof(T) ) - { - case 8: - { - __storewordbytereverse( *(word+1), 0, &temp ); - __storewordbytereverse( *(word+0), 4, &temp ); - } - break; - - case 4: - __storewordbytereverse( *word, 0, &temp ); - break; - - case 2: - __storeshortbytereverse( *input, 0, &temp ); - break; - - case 1: - Q_memcpy( &temp, input, 1 ); - break; - - default: - Assert( "Invalid size in CByteswap::LowLevelByteSwap" && 0 ); - } -#else - for( size_t i = 0; i < sizeof(T); i++ ) - { - ((unsigned char* )&temp)[i] = ((unsigned char*)input)[sizeof(T)-(i+1)]; - } -#endif - Q_memcpy( output, &temp, sizeof(T) ); - } - -#if defined( _X360 ) - // specialized for void * to get 360 XDK compile working despite changelist 281331 - //----------------------------------------------------------------------------- - // The lowest level byte swapping workhorse of doom. output always contains the - // swapped version of input. ( Doesn't compare machine to target endianness ) - //----------------------------------------------------------------------------- - template<> static void LowLevelByteSwap( void **output, void **input ) - { - AssertMsgOnce( sizeof(void *) == sizeof(unsigned int) , "void *'s on this platform are not four bytes!" ); - __storewordbytereverse( *reinterpret_cast(input), 0, output ); - } -#endif - - unsigned int m_bSwapBytes : 1; - unsigned int m_bBigEndian : 1; -}; - -#endif /* !BYTESWAP_H */ +//========= Copyright © 1996-2006, Valve LLC, All rights reserved. ============ +// +// Purpose: Low level byte swapping routines. +// +// $NoKeywords: $ +//============================================================================= +#ifndef BYTESWAP_H +#define BYTESWAP_H +#if defined(_WIN32) +#pragma once +#endif + +#include "tier0/dbg.h" +#include "datamap.h" // needed for typedescription_t. note datamap.h is tier1 as well. + +class CByteswap +{ +public: + CByteswap() + { + // Default behavior sets the target endian to match the machine native endian (no swap). + SetTargetBigEndian( IsMachineBigEndian() ); + } + + //----------------------------------------------------------------------------- + // Write a single field. + //----------------------------------------------------------------------------- + void SwapFieldToTargetEndian( void* pOutputBuffer, void *pData, typedescription_t *pField ); + + //----------------------------------------------------------------------------- + // Write a block of fields. Works a bit like the saverestore code. + //----------------------------------------------------------------------------- + void SwapFieldsToTargetEndian( void *pOutputBuffer, void *pBaseData, datamap_t *pDataMap ); + + // Swaps fields for the templated type to the output buffer. + template inline void SwapFieldsToTargetEndian( T* pOutputBuffer, void *pBaseData, unsigned int objectCount = 1 ) + { + for ( unsigned int i = 0; i < objectCount; ++i, ++pOutputBuffer ) + { + SwapFieldsToTargetEndian( (void*)pOutputBuffer, pBaseData, &T::m_DataMap ); + pBaseData = (byte*)pBaseData + sizeof(T); + } + } + + // Swaps fields for the templated type in place. + template inline void SwapFieldsToTargetEndian( T* pOutputBuffer, unsigned int objectCount = 1 ) + { + SwapFieldsToTargetEndian( pOutputBuffer, (void*)pOutputBuffer, objectCount ); + } + + //----------------------------------------------------------------------------- + // True if the current machine is detected as big endian. + // (Endienness is effectively detected at compile time when optimizations are + // enabled) + //----------------------------------------------------------------------------- + static bool IsMachineBigEndian() + { + short nIsBigEndian = 1; + + // if we are big endian, the first byte will be a 0, if little endian, it will be a one. + return (bool)(0 == *(char *)&nIsBigEndian ); + } + + //----------------------------------------------------------------------------- + // Sets the target byte ordering we are swapping to or from. + // + // Braindead Endian Reference: + // x86 is LITTLE Endian + // PowerPC is BIG Endian + //----------------------------------------------------------------------------- + inline void SetTargetBigEndian( bool bigEndian ) + { + m_bBigEndian = bigEndian; + m_bSwapBytes = IsMachineBigEndian() != bigEndian; + } + + // Changes target endian + inline void FlipTargetEndian( void ) + { + m_bSwapBytes = !m_bSwapBytes; + m_bBigEndian = !m_bBigEndian; + } + + // Forces byte swapping state, regardless of endianess + inline void ActivateByteSwapping( bool bActivate ) + { + SetTargetBigEndian( IsMachineBigEndian() != bActivate ); + } + + //----------------------------------------------------------------------------- + // Returns true if the target machine is the same as this one in endianness. + // + // Used to determine when a byteswap needs to take place. + //----------------------------------------------------------------------------- + inline bool IsSwappingBytes( void ) // Are bytes being swapped? + { + return m_bSwapBytes; + } + + inline bool IsTargetBigEndian( void ) // What is the current target endian? + { + return m_bBigEndian; + } + + //----------------------------------------------------------------------------- + // IsByteSwapped() + // + // When supplied with a chunk of input data and a constant or magic number + // (in native format) determines the endienness of the current machine in + // relation to the given input data. + // + // Returns: + // 1 if input is the same as nativeConstant. + // 0 if input is byteswapped relative to nativeConstant. + // -1 if input is not the same as nativeConstant and not byteswapped either. + // + // ( This is useful for detecting byteswapping in magic numbers in structure + // headers for example. ) + //----------------------------------------------------------------------------- + template inline int SourceIsNativeEndian( T input, T nativeConstant ) + { + // If it's the same, it isn't byteswapped: + if( input == nativeConstant ) + return 1; + + int output; + LowLevelByteSwap( &output, &input ); + if( output == nativeConstant ) + return 0; + + Assert( 0 ); // if we get here, input is neither a swapped nor unswapped version of nativeConstant. + return -1; + } + + //----------------------------------------------------------------------------- + // Swaps an input buffer full of type T into the given output buffer. + // + // Swaps [count] items from the inputBuffer to the outputBuffer. + // If inputBuffer is omitted or NULL, then it is assumed to be the same as + // outputBuffer - effectively swapping the contents of the buffer in place. + //----------------------------------------------------------------------------- + template inline void SwapBuffer( T* outputBuffer, T* inputBuffer = NULL, int count = 1 ) + { + Assert( count >= 0 ); + Assert( outputBuffer ); + + // Fail gracefully in release: + if( count <=0 || !outputBuffer ) + return; + + // Optimization for the case when we are swapping in place. + if( inputBuffer == NULL ) + { + inputBuffer = outputBuffer; + } + + // Swap everything in the buffer: + for( int i = 0; i < count; i++ ) + { + LowLevelByteSwap( &outputBuffer[i], &inputBuffer[i] ); + } + } + + //----------------------------------------------------------------------------- + // Swaps an input buffer full of type T into the given output buffer. + // + // Swaps [count] items from the inputBuffer to the outputBuffer. + // If inputBuffer is omitted or NULL, then it is assumed to be the same as + // outputBuffer - effectively swapping the contents of the buffer in place. + //----------------------------------------------------------------------------- + template inline void SwapBufferToTargetEndian( T* outputBuffer, T* inputBuffer = NULL, int count = 1 ) + { + Assert( count >= 0 ); + Assert( outputBuffer ); + + // Fail gracefully in release: + if( count <=0 || !outputBuffer ) + return; + + // Optimization for the case when we are swapping in place. + if( inputBuffer == NULL ) + { + inputBuffer = outputBuffer; + } + + // Are we already the correct endienness? ( or are we swapping 1 byte items? ) + if( !m_bSwapBytes || ( sizeof(T) == 1 ) ) + { + // If we were just going to swap in place then return. + if( !inputBuffer ) + return; + + // Otherwise copy the inputBuffer to the outputBuffer: + if ( outputBuffer != inputBuffer ) + memcpy( outputBuffer, inputBuffer, count * sizeof( T ) ); + return; + + } + + // Swap everything in the buffer: + for( int i = 0; i < count; i++ ) + { + LowLevelByteSwap( &outputBuffer[i], &inputBuffer[i] ); + } + } + +private: + //----------------------------------------------------------------------------- + // The lowest level byte swapping workhorse of doom. output always contains the + // swapped version of input. ( Doesn't compare machine to target endianness ) + //----------------------------------------------------------------------------- + template static void LowLevelByteSwap( T *output, T *input ) + { + T temp = *output; +#if defined( _X360 ) + // Intrinsics need the source type to be fixed-point + DWORD* word = (DWORD*)input; + switch( sizeof(T) ) + { + case 8: + { + __storewordbytereverse( *(word+1), 0, &temp ); + __storewordbytereverse( *(word+0), 4, &temp ); + } + break; + + case 4: + __storewordbytereverse( *word, 0, &temp ); + break; + + case 2: + __storeshortbytereverse( *input, 0, &temp ); + break; + + case 1: + Q_memcpy( &temp, input, 1 ); + break; + + default: + Assert( "Invalid size in CByteswap::LowLevelByteSwap" && 0 ); + } +#else + for( size_t i = 0; i < sizeof(T); i++ ) + { + ((unsigned char* )&temp)[i] = ((unsigned char*)input)[sizeof(T)-(i+1)]; + } +#endif + Q_memcpy( output, &temp, sizeof(T) ); + } + +#if defined( _X360 ) + // specialized for void * to get 360 XDK compile working despite changelist 281331 + //----------------------------------------------------------------------------- + // The lowest level byte swapping workhorse of doom. output always contains the + // swapped version of input. ( Doesn't compare machine to target endianness ) + //----------------------------------------------------------------------------- + template<> static void LowLevelByteSwap( void **output, void **input ) + { + AssertMsgOnce( sizeof(void *) == sizeof(unsigned int) , "void *'s on this platform are not four bytes!" ); + __storewordbytereverse( *reinterpret_cast(input), 0, output ); + } +#endif + + unsigned int m_bSwapBytes : 1; + unsigned int m_bBigEndian : 1; +}; + +#endif /* !BYTESWAP_H */ diff --git a/public/tier1/utlbuffer.h b/public/tier1/utlbuffer.h index 75767809..6d6544d8 100644 --- a/public/tier1/utlbuffer.h +++ b/public/tier1/utlbuffer.h @@ -1,4 +1,4 @@ -//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======// +//====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======// // // Purpose: // @@ -17,7 +17,7 @@ #include "unitlib/unitlib.h" // just here for tests - remove before checking in!!! #include "tier1/utlmemory.h" -#include "tier1/byteswap.h" +#include "tier1/cbyteswap.h" #include "tier1/bufferstring.h" #include diff --git a/public/zip_utils.cpp b/public/zip_utils.cpp index 321ce88b..f37d4c0e 100644 --- a/public/zip_utils.cpp +++ b/public/zip_utils.cpp @@ -17,7 +17,7 @@ #include "zip_utils.h" #include "zip_uncompressed.h" #include "checksum_crc.h" -#include "byteswap.h" +#include "cbyteswap.h" #include "utlstring.h" // NOTE: This has to be the last file included! diff --git a/tier1/byteswap.cpp b/tier1/cbyteswap.cpp similarity index 93% rename from tier1/byteswap.cpp rename to tier1/cbyteswap.cpp index 0c42a38d..c2071f8c 100644 --- a/tier1/byteswap.cpp +++ b/tier1/cbyteswap.cpp @@ -1,90 +1,90 @@ -//========= Copyright © 1996-2006, Valve LLC, All rights reserved. ============ -// -// Purpose: Low level byte swapping routines. -// -// $NoKeywords: $ -//============================================================================= - -#include "byteswap.h" - -//----------------------------------------------------------------------------- -// Copy a single field from the input buffer to the output buffer, swapping the bytes if necessary -//----------------------------------------------------------------------------- -void CByteswap::SwapFieldToTargetEndian( void* pOutputBuffer, void *pData, typedescription_t *pField ) -{ - switch ( pField->fieldType ) - { - case FIELD_CHARACTER: - SwapBufferToTargetEndian( (char*)pOutputBuffer, (char*)pData, pField->fieldSize ); - break; - - case FIELD_BOOLEAN: - SwapBufferToTargetEndian( (bool*)pOutputBuffer, (bool*)pData, pField->fieldSize ); - break; - - case FIELD_SHORT: - SwapBufferToTargetEndian( (short*)pOutputBuffer, (short*)pData, pField->fieldSize ); - break; - - case FIELD_FLOAT: - SwapBufferToTargetEndian( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize ); - break; - - case FIELD_INTEGER: - SwapBufferToTargetEndian( (int*)pOutputBuffer, (int*)pData, pField->fieldSize ); - break; - - case FIELD_VECTOR: - SwapBufferToTargetEndian( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 3 ); - break; - - case FIELD_VECTOR2D: - SwapBufferToTargetEndian( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 2 ); - break; - - case FIELD_QUATERNION: - SwapBufferToTargetEndian( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 4 ); - break; - - case FIELD_EMBEDDED: - { - typedescription_t *pEmbed = pField->td->dataDesc; - for ( int i = 0; i < pField->fieldSize; ++i ) - { - SwapFieldsToTargetEndian( (byte*)pOutputBuffer + pEmbed->fieldOffset, - (byte*)pData + pEmbed->fieldOffset, - pField->td ); - - pOutputBuffer = (byte*)pOutputBuffer + pField->fieldSizeInBytes; - pData = (byte*)pData + pField->fieldSizeInBytes; - } - } - break; - - default: - Assert(0); - } -} - -//----------------------------------------------------------------------------- -// Write a block of fields. Works a bit like the saverestore code. -//----------------------------------------------------------------------------- -void CByteswap::SwapFieldsToTargetEndian( void *pOutputBuffer, void *pBaseData, datamap_t *pDataMap ) -{ - // deal with base class first - if ( pDataMap->baseMap ) - { - SwapFieldsToTargetEndian( pOutputBuffer, pBaseData, pDataMap->baseMap ); - } - - typedescription_t *pFields = pDataMap->dataDesc; - int fieldCount = pDataMap->dataNumFields; - for ( int i = 0; i < fieldCount; ++i ) - { - typedescription_t *pField = &pFields[i]; - SwapFieldToTargetEndian( (BYTE*)pOutputBuffer + pField->fieldOffset, - (BYTE*)pBaseData + pField->fieldOffset, - pField ); - } -} - +//========= Copyright � 1996-2006, Valve LLC, All rights reserved. ============ +// +// Purpose: Low level byte swapping routines. +// +// $NoKeywords: $ +//============================================================================= + +#include "cbyteswap.h" + +//----------------------------------------------------------------------------- +// Copy a single field from the input buffer to the output buffer, swapping the bytes if necessary +//----------------------------------------------------------------------------- +void CByteswap::SwapFieldToTargetEndian( void* pOutputBuffer, void *pData, typedescription_t *pField ) +{ + switch ( pField->fieldType ) + { + case FIELD_CHARACTER: + SwapBufferToTargetEndian( (char*)pOutputBuffer, (char*)pData, pField->fieldSize ); + break; + + case FIELD_BOOLEAN: + SwapBufferToTargetEndian( (bool*)pOutputBuffer, (bool*)pData, pField->fieldSize ); + break; + + case FIELD_SHORT: + SwapBufferToTargetEndian( (short*)pOutputBuffer, (short*)pData, pField->fieldSize ); + break; + + case FIELD_FLOAT: + SwapBufferToTargetEndian( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize ); + break; + + case FIELD_INTEGER: + SwapBufferToTargetEndian( (int*)pOutputBuffer, (int*)pData, pField->fieldSize ); + break; + + case FIELD_VECTOR: + SwapBufferToTargetEndian( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 3 ); + break; + + case FIELD_VECTOR2D: + SwapBufferToTargetEndian( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 2 ); + break; + + case FIELD_QUATERNION: + SwapBufferToTargetEndian( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 4 ); + break; + + case FIELD_EMBEDDED: + { + typedescription_t *pEmbed = pField->td->dataDesc; + for ( int i = 0; i < pField->fieldSize; ++i ) + { + SwapFieldsToTargetEndian( (byte*)pOutputBuffer + pEmbed->fieldOffset, + (byte*)pData + pEmbed->fieldOffset, + pField->td ); + + pOutputBuffer = (byte*)pOutputBuffer + pField->fieldSizeInBytes; + pData = (byte*)pData + pField->fieldSizeInBytes; + } + } + break; + + default: + Assert(0); + } +} + +//----------------------------------------------------------------------------- +// Write a block of fields. Works a bit like the saverestore code. +//----------------------------------------------------------------------------- +void CByteswap::SwapFieldsToTargetEndian( void *pOutputBuffer, void *pBaseData, datamap_t *pDataMap ) +{ + // deal with base class first + if ( pDataMap->baseMap ) + { + SwapFieldsToTargetEndian( pOutputBuffer, pBaseData, pDataMap->baseMap ); + } + + typedescription_t *pFields = pDataMap->dataDesc; + int fieldCount = pDataMap->dataNumFields; + for ( int i = 0; i < fieldCount; ++i ) + { + typedescription_t *pField = &pFields[i]; + SwapFieldToTargetEndian( (BYTE*)pOutputBuffer + pField->fieldOffset, + (BYTE*)pBaseData + pField->fieldOffset, + pField ); + } +} + diff --git a/tier1/tier1-2005.vcproj b/tier1/tier1-2005.vcproj index 34cff4df..a1c9d413 100644 --- a/tier1/tier1-2005.vcproj +++ b/tier1/tier1-2005.vcproj @@ -217,7 +217,7 @@ > - + @@ -346,7 +346,7 @@ - + diff --git a/tier1/tier1.vcxproj.filters b/tier1/tier1.vcxproj.filters index efea681b..997c4320 100644 --- a/tier1/tier1.vcxproj.filters +++ b/tier1/tier1.vcxproj.filters @@ -14,7 +14,7 @@ Source Files - + Source Files @@ -76,7 +76,7 @@ Header Files - + Header Files