- Grunt::ServerLink: all CMD_GRUNT_* handlers, send helpers, features/strings, command table 0xB24D70, s_localeIds 0xAD3004, Pending::Remove (dead server-side link, docs/0x008CE200.md); ServerLink.h stub removed - PetAction type for CGPetInfo::m_actions / pet spell actions / cursor pet action, SetAutocast 0x5D32F0 - CParticleEmitter2 fields 0x98-0x11F moved into CParticleEmitter2::Params (ctor 0x979250) - fixed16(float), C3Vector::FlushDenormals, CGxuLightQueue + static 0xC7C074, CAaSphere(), CMapLowDetail(), C2Vector()/C4Plane() out of line, SpellHistory dtor, CGDynamicObject_C GetScale/GetRawFacing - DB record operator= (PetNameCache, CGPetition, DanceCache): fixes the shallow-copy double free in AddItem - ClientSetTimer(delay, handler, param) with its five callers, IOMd5Unit::Create without container, CDataStore::GetByte / Get(int32_t&), WDataStore::GetHeaderSpace, TSHashTable::Head, TSList::IsEmpty - CameraTurnPlayer calls CVehicleCamera_C::IsTransitioningFacing 0x5FAA10 (was IsHierarchyChasingFacing) - OFFSET additions: TSHashTable::Unlink, TInstanceId dtor, DBCACHEHASH dtor (+ ItemNameCache_C dtor), CDataStoreCache ctor, BitUnpacker/RunningAverageCalculator deleting dtors, CGTooltip::GetObjectType Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
120 lines
4.1 KiB
C++
120 lines
4.1 KiB
C++
#include "Engine/Source/ComSat/ComSatBitPacker.h"
|
|
#include <cstring>
|
|
|
|
// VERIFY: 09242d98 auto
|
|
// OFFSET: 0x00885730
|
|
ComSat::BitPacker::BitPacker(uint8_t* buffer, uint32_t bitLength) {
|
|
this->m_buffer = buffer;
|
|
this->m_bitLength = bitLength;
|
|
this->m_byteOffset = 0;
|
|
this->m_bitOffset = 0;
|
|
}
|
|
|
|
// VERIFY: 4151e984 auto
|
|
// OFFSET: 0x00885760
|
|
ComSat::BitPacker::~BitPacker() {
|
|
}
|
|
|
|
// VERIFY: 2517a981 auto
|
|
// OFFSET: 0x008858E0
|
|
uint32_t ComSat::BitPacker::Finalize() {
|
|
if (this->m_bitOffset) {
|
|
this->m_buffer[this->m_byteOffset] &= (1 << this->m_bitOffset) - 1;
|
|
this->m_byteOffset++;
|
|
this->m_bitOffset = 0;
|
|
}
|
|
return this->m_byteOffset;
|
|
}
|
|
|
|
// VERIFY: c6ad9043 manual
|
|
// OFFSET: 0x00885770
|
|
bool ComSat::BitPacker::PackBits(const uint8_t* data, uint32_t bits) {
|
|
if (this->m_bitLength < bits + this->m_bitOffset + 8 * this->m_byteOffset) {
|
|
return false;
|
|
}
|
|
int32_t bytes = bits >> 3;
|
|
uint32_t remainder = bits & 7;
|
|
int32_t i;
|
|
if (this->m_bitOffset) {
|
|
for (i = 0; i < bytes; i++) {
|
|
this->m_buffer[this->m_byteOffset] &= (1 << this->m_bitOffset) - 1;
|
|
this->m_buffer[this->m_byteOffset] |= data[i] << this->m_bitOffset;
|
|
this->m_buffer[this->m_byteOffset + 1] &= -1 << this->m_bitOffset;
|
|
this->m_buffer[this->m_byteOffset + 1] |= data[i] >> (8 - this->m_bitOffset);
|
|
this->m_byteOffset++;
|
|
}
|
|
} else {
|
|
memcpy(&this->m_buffer[this->m_byteOffset], data, bytes);
|
|
this->m_byteOffset += bytes;
|
|
i = bytes;
|
|
}
|
|
if (remainder) {
|
|
uint8_t value = data[i] & ((1 << remainder) - 1);
|
|
this->m_buffer[this->m_byteOffset] &= (0xFF >> (8 - this->m_bitOffset)) | (-1 << (this->m_bitOffset + remainder));
|
|
this->m_buffer[this->m_byteOffset] |= value << this->m_bitOffset;
|
|
if (this->m_bitOffset + remainder >= 8) {
|
|
this->m_buffer[this->m_byteOffset + 1] &= -1 << this->m_bitOffset;
|
|
this->m_buffer[this->m_byteOffset + 1] |= value >> (8 - this->m_bitOffset);
|
|
this->m_byteOffset++;
|
|
this->m_bitOffset += remainder - 8;
|
|
return true;
|
|
}
|
|
this->m_bitOffset += remainder;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// VERIFY: 670e65cb auto
|
|
// OFFSET: 0x00885730
|
|
ComSat::BitUnpacker::BitUnpacker(const uint8_t* buffer, uint32_t bitLength) {
|
|
this->m_buffer = buffer;
|
|
this->m_bitLength = bitLength;
|
|
this->m_byteOffset = 0;
|
|
this->m_bitOffset = 0;
|
|
}
|
|
|
|
// VERIFY: aaf78467 auto
|
|
// OFFSET: [0x00885760, 0x00885AA0]
|
|
ComSat::BitUnpacker::~BitUnpacker() {
|
|
}
|
|
|
|
// VERIFY: 6ca95947 manual
|
|
// OFFSET: 0x00885910
|
|
bool ComSat::BitUnpacker::UnpackBits(uint8_t* data, uint32_t bits) {
|
|
if (this->m_bitLength < this->m_bitOffset + bits + 8 * this->m_byteOffset) {
|
|
return false;
|
|
}
|
|
int32_t bytes = bits >> 3;
|
|
int32_t remainder = bits & 7;
|
|
memset(data, 0, remainder ? bytes + 1 : bytes);
|
|
int32_t i;
|
|
if (this->m_bitOffset) {
|
|
for (i = 0; i < bytes; i++) {
|
|
data[i] = this->m_buffer[this->m_byteOffset] >> this->m_bitOffset;
|
|
data[i] |= (((1 << this->m_bitOffset) - 1) & this->m_buffer[this->m_byteOffset++ + 1]) << (8 - this->m_bitOffset);
|
|
}
|
|
} else {
|
|
memcpy(data, &this->m_buffer[this->m_byteOffset], bytes);
|
|
this->m_byteOffset += bytes;
|
|
i = bytes;
|
|
}
|
|
if (remainder) {
|
|
if (!this->m_bitOffset) {
|
|
data[i] = ((1 << remainder) - 1) & this->m_buffer[this->m_byteOffset];
|
|
this->m_bitOffset = remainder;
|
|
return true;
|
|
}
|
|
if (remainder > static_cast<int32_t>(8 - this->m_bitOffset)) {
|
|
data[i] = this->m_buffer[this->m_byteOffset] >> this->m_bitOffset;
|
|
this->m_byteOffset++;
|
|
int32_t bitOffset = remainder + this->m_bitOffset - 8;
|
|
data[i] |= (((1 << bitOffset) - 1) & this->m_buffer[this->m_byteOffset]) << (8 - this->m_bitOffset);
|
|
this->m_bitOffset = bitOffset;
|
|
return true;
|
|
}
|
|
data[i] = ((1 << remainder) - 1) & (this->m_buffer[this->m_byteOffset] >> this->m_bitOffset);
|
|
this->m_bitOffset = (remainder + this->m_bitOffset) & 7;
|
|
}
|
|
return true;
|
|
}
|