r5sdk/r5dev/tier1/bitbuf.cpp
Kawe Mazidjatari 6feb41c285 Partial CNetChan class rebuild and implementation (see description)
* Adapt codebase to new class to reduce rune-like code.
* Fixed several bugs where the global CClient pointer was used instead of the instance in question to issue bans and display information about a certain client in CBanSystem and Pylon.
* Upgraded CBanSystem and Pylon to use IPv6 instead (including IPv4 mapped IPv6 addresses). This breaks all existing banlist files! All bans have to be re-issued or the existing file has to be updated to use IPv4 mapped IPv6 addresses and renamed to 'banlist.json', and moved to the root of the 'platform' folder.
2022-04-02 02:48:54 +02:00

75 lines
1.2 KiB
C++

//===========================================================================//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "core/stdafx.h"
#include "tier1/bitbuf.h"
inline int BitByte(int bits)
{
// return PAD_NUMBER( bits, 8 ) >> 3;
return (bits + 7) >> 3;
}
bool bf_write::IsOverflowed() const
{
return this->m_bOverflow;
}
int bf_write::GetNumBytesWritten() const
{
return BitByte(this->m_iCurBit);
}
int bf_write::GetNumBitsWritten() const
{
return this->m_iCurBit;
}
int bf_write::GetMaxNumBits() const
{
return this->m_nDataBits;
}
int bf_write::GetNumBitsLeft() const
{
return this->m_nDataBits - m_iCurBit;
}
int bf_write::GetNumBytesLeft() const
{
return this->GetNumBitsLeft() >> 3;
}
unsigned char* bf_write::GetData()
{
return this->m_pData;
}
const unsigned char* bf_write::GetData() const
{
return this->m_pData;
}
bool bf_write::CheckForOverflow(int nBits)
{
if (this->m_iCurBit + nBits > this->m_nDataBits)
{
this->SetOverflowFlag();
}
return this->m_bOverflow;
}
void bf_write::SetOverflowFlag()
{
if (this->m_bAssertOnOverflow)
{
Assert(false);
}
this->m_bOverflow = true;
}