[raknet] Implement/match BitStream constructor

This commit is contained in:
RD42
2024-08-24 23:36:08 +08:00
parent 3fc0a1ed5d
commit dd43644768
2 changed files with 42 additions and 1 deletions

View File

@ -123,6 +123,43 @@ BitStream::BitStream( unsigned char* _data, unsigned int lengthInBytes, bool _co
data = ( unsigned char* ) _data;
}
// SAMPSRV (adding this just as a tag for next RakNet upgrade)
BitStream::BitStream( char* _dataC, unsigned int lengthInBytes, bool _copyData )
{
unsigned char* _data = reinterpret_cast<unsigned char*>(_dataC);
numberOfBitsUsed = lengthInBytes << 3;
readOffset = 0;
copyData = _copyData;
numberOfBitsAllocated = lengthInBytes << 3;
if ( copyData )
{
if ( lengthInBytes > 0 )
{
if (lengthInBytes < BITSTREAM_STACK_ALLOCATION_SIZE)
{
data = ( unsigned char* ) stackData;
numberOfBitsAllocated = BITSTREAM_STACK_ALLOCATION_SIZE << 3;
}
else
{
data = ( unsigned char* ) malloc( lengthInBytes );
}
#ifdef _DEBUG
assert( data );
#endif
memcpy( data, _data, lengthInBytes );
}
else
data = 0;
}
else
data = ( unsigned char* ) _data;
}
// SAMPSRV end
// Use this if you pass a pointer copy to the constructor (_copyData==false) and want to overallocate to prevent reallocation
void BitStream::SetNumberOfBitsAllocated( const unsigned int lengthInBits )
{

View File

@ -67,7 +67,11 @@ namespace RakNet
/// \param[in] lengthInBytes Size of the \a _data.
/// \param[in] _copyData true or false to make a copy of \a _data or not.
BitStream( unsigned char* _data, unsigned int lengthInBytes, bool _copyData );
// SAMPSRV (adding this just as a tag for next RakNet upgrade)
BitStream( char* _dataC, unsigned int lengthInBytes, bool _copyData );
// SAMPSRV end
/// Destructor
~BitStream();