Compare commits

...

1 Commits

Author SHA1 Message Date
coah
429f44ce37 cleanup(CXStreamingUncompression): name remaining RL/LZ/Huffman fields
Follows #678 (outData/outDataLen). Renames length/flags/hdrLen and
Huffman wordBuffer/wordBits.
2026-10-02 00:44:32 +00:00
2 changed files with 54 additions and 54 deletions

View File

@@ -19,21 +19,21 @@ typedef struct CXUncompContextRL {
u8* outData; // 0x00 u8* outData; // 0x00
int outDataLen; // 0x04 int outDataLen; // 0x04
u32 size; // 0x08 u32 size; // 0x08
u16 length; // 0x0C u16 length; // 0x0C
u8 unk_0x0e; // 0x0E u8 flags; // 0x0E
u8 unk_0x0f; // 0x0F u8 hdrLen; // 0x0F
} CXUncompContextRL; } CXUncompContextRL;
typedef struct CXUncompContextLZ { typedef struct CXUncompContextLZ {
u8* outData; // 0x00 u8* outData; // 0x00
int outDataLen; // 0x04 int outDataLen; // 0x04
u32 size; // 0x08 u32 size; // 0x08
int length; // 0x0C int length; // 0x0C
u8 unk_0x10; // 0x10 u8 lengthBytesLeft; // 0x10
u8 unk_0x11; // 0x11 u8 flags; // 0x11
u8 unk_0x12; // 0x12 u8 flagsLeft; // 0x12
u8 unk_0x13; // 0x13 u8 hdrLen; // 0x13
u8 unk_0x14; // 0x14 u8 lzType; // 0x14
u8 padding[3]; u8 padding[3];
} CXUncompContextLZ; } CXUncompContextLZ;
@@ -52,10 +52,10 @@ typedef struct CXUncompContextHuffman {
u32 size; // 0x08 u32 size; // 0x08
CXHuffmanDecodeTableEntry* decodeTable; // 0x0C CXHuffmanDecodeTableEntry* decodeTable; // 0x0C
u32 bits; // 0x10 u32 bits; // 0x10
u32 unk_0x14; // 0x14 u32 wordBuffer; // 0x14
s16 decodeTableSize; // 0x18 s16 decodeTableSize; // 0x18
u8 bitsLeft; // 0x1A u8 bitsLeft; // 0x1A
u8 unk_0x1b; // 0x1B u8 wordBits; // 0x1B
u8 depth; // 0x1C u8 depth; // 0x1C
u8 hdrLen; // 0x1D u8 hdrLen; // 0x1D
u8 padding[2]; // 0x1E u8 padding[2]; // 0x1E

View File

@@ -7,21 +7,21 @@ static inline CXHuffmanDecodeTableEntry* GetNextNode(CXHuffmanDecodeTableEntry*,
void CXInitUncompContextRL(CXUncompContextRL* context, u8* data) { void CXInitUncompContextRL(CXUncompContextRL* context, u8* data) {
context->outData = data; context->outData = data;
context->outDataLen = 0; context->outDataLen = 0;
context->unk_0x0e = 0; context->flags = 0;
context->length = 0; context->length = 0;
context->unk_0x0f = 8; context->hdrLen = 8;
context->size = 0; context->size = 0;
} }
void CXInitUncompContextLZ(CXUncompContextLZ* context, u8* data) { void CXInitUncompContextLZ(CXUncompContextLZ* context, u8* data) {
context->outData = data; context->outData = data;
context->outDataLen = 0; context->outDataLen = 0;
context->unk_0x11 = 0; context->flags = 0;
context->unk_0x12 = 0; context->flagsLeft = 0;
context->length = 0; context->length = 0;
context->unk_0x10 = 3; context->lengthBytesLeft = 3;
context->unk_0x13 = 8; context->hdrLen = 8;
context->unk_0x14 = 0; context->lzType = 0;
context->size = 0; context->size = 0;
} }
@@ -31,8 +31,8 @@ void CXInitUncompContextHuffman(CXUncompContextHuffman* context, u8* data) {
context->depth = 0; context->depth = 0;
context->decodeTableSize = -1; context->decodeTableSize = -1;
context->decodeTable = context->decodeTableData; context->decodeTable = context->decodeTableData;
context->unk_0x14 = 0; context->wordBuffer = 0;
context->unk_0x1b = 0; context->wordBits = 0;
context->bits = 0; context->bits = 0;
context->bitsLeft = 0; context->bitsLeft = 0;
context->hdrLen = 8; context->hdrLen = 8;
@@ -42,9 +42,9 @@ void CXInitUncompContextHuffman(CXUncompContextHuffman* context, u8* data) {
CXStreamingResult CXReadUncompRL(CXUncompContextRL* context, const void* src, u32 size) { CXStreamingResult CXReadUncompRL(CXUncompContextRL* context, const void* src, u32 size) {
const u8* pSrc = src; const u8* pSrc = src;
if (context->unk_0x0f) { if (context->hdrLen) {
int a; int a;
if (context->unk_0x0f == 8) { if (context->hdrLen == 8) {
if ((*pSrc & CX_COMPRESSION_TYPE_MASK) != CX_COMPRESSION_TYPE_RUN_LENGTH) { if ((*pSrc & CX_COMPRESSION_TYPE_MASK) != CX_COMPRESSION_TYPE_RUN_LENGTH) {
return CX_STREAMING_ERR_BAD_FILE_TYPE; return CX_STREAMING_ERR_BAD_FILE_TYPE;
} }
@@ -54,18 +54,18 @@ CXStreamingResult CXReadUncompRL(CXUncompContextRL* context, const void* src, u3
} }
} }
a = CXiReadHeader(&context->unk_0x0f, &context->outDataLen, pSrc, size, context->size); a = CXiReadHeader(&context->hdrLen, &context->outDataLen, pSrc, size, context->size);
pSrc += a; pSrc += a;
size -= a; size -= a;
if (!size) { if (!size) {
return !context->unk_0x0f ? context->outDataLen : CX_STREAMING_ERR_BAD_FILE_TYPE; return !context->hdrLen ? context->outDataLen : CX_STREAMING_ERR_BAD_FILE_TYPE;
} }
} }
while (context->outDataLen > 0) { while (context->outDataLen > 0) {
if (!(context->unk_0x0e & 0x80)) { if (!(context->flags & 0x80)) {
while (context->length) { while (context->length) {
*context->outData++ = *pSrc++; *context->outData++ = *pSrc++;
@@ -93,11 +93,11 @@ CXStreamingResult CXReadUncompRL(CXUncompContextRL* context, const void* src, u3
} }
} }
context->unk_0x0e = *pSrc++; context->flags = *pSrc++;
size--; size--;
context->length = context->unk_0x0e & 0x7f; context->length = context->flags & 0x7f;
if (context->unk_0x0e & 0x80) { if (context->flags & 0x80) {
context->length += 3; context->length += 3;
} else { } else {
context->length += 1; context->length += 1;
@@ -160,39 +160,39 @@ static int CXiReadHeader(u8* pHdrLen, int* pOutLen, const u8* pSrc, int srcSize,
CXStreamingResult CXReadUncompLZ(CXUncompContextLZ* context, const void* src, u32 size) { CXStreamingResult CXReadUncompLZ(CXUncompContextLZ* context, const void* src, u32 size) {
const u8* pSrc = src; const u8* pSrc = src;
if (context->unk_0x13) { if (context->hdrLen) {
int a; int a;
if (context->unk_0x13 == 8) { if (context->hdrLen == 8) {
if ((*pSrc & CX_COMPRESSION_TYPE_MASK) != CX_COMPRESSION_TYPE_LZ) { if ((*pSrc & CX_COMPRESSION_TYPE_MASK) != CX_COMPRESSION_TYPE_LZ) {
return CX_STREAMING_ERR_BAD_FILE_TYPE; return CX_STREAMING_ERR_BAD_FILE_TYPE;
} }
context->unk_0x14 = *pSrc & 0x0F; context->lzType = *pSrc & 0x0F;
if (context->unk_0x14 != 0 && context->unk_0x14 != 1) { if (context->lzType != 0 && context->lzType != 1) {
return CX_STREAMING_ERR_BAD_FILE_TYPE; return CX_STREAMING_ERR_BAD_FILE_TYPE;
} }
} }
a = CXiReadHeader(&context->unk_0x13, &context->outDataLen, pSrc, size, context->size); a = CXiReadHeader(&context->hdrLen, &context->outDataLen, pSrc, size, context->size);
pSrc += a; pSrc += a;
size -= a; size -= a;
if (!size) { if (!size) {
return !context->unk_0x13 ? context->outDataLen : CX_STREAMING_ERR_BAD_FILE_TYPE; return !context->hdrLen ? context->outDataLen : CX_STREAMING_ERR_BAD_FILE_TYPE;
} }
} }
while (context->outDataLen > 0) { while (context->outDataLen > 0) {
while (context->unk_0x12) { while (context->flagsLeft) {
s32 a; s32 a;
if (!size) { if (!size) {
return context->outDataLen; return context->outDataLen;
} }
if (!(context->unk_0x11 & 0x80)) { if (!(context->flags & 0x80)) {
*context->outData++ = *pSrc++; *context->outData++ = *pSrc++;
context->outDataLen--; context->outDataLen--;
@@ -201,15 +201,15 @@ CXStreamingResult CXReadUncompLZ(CXUncompContextLZ* context, const void* src, u3
goto there; goto there;
} }
while (context->unk_0x10) { while (context->lengthBytesLeft) {
context->unk_0x10--; context->lengthBytesLeft--;
if (!context->unk_0x14) { if (!context->lzType) {
context->length = *pSrc++; context->length = *pSrc++;
context->length += 0x30; context->length += 0x30;
context->unk_0x10 = 0; context->lengthBytesLeft = 0;
} else { } else {
switch (context->unk_0x10) { switch (context->lengthBytesLeft) {
case 2: { case 2: {
context->length = *pSrc++; context->length = *pSrc++;
@@ -219,10 +219,10 @@ CXStreamingResult CXReadUncompLZ(CXUncompContextLZ* context, const void* src, u3
} else if (context->length >> 4 == 0) { } else if (context->length >> 4 == 0) {
context->length = (context->length & 0x0F) << 8; context->length = (context->length & 0x0F) << 8;
context->length += 0x110; context->length += 0x110;
context->unk_0x10 = 1; context->lengthBytesLeft = 1;
} else { } else {
context->length += 0x10; context->length += 0x10;
context->unk_0x10 = 0; context->lengthBytesLeft = 0;
} }
break; break;
@@ -249,7 +249,7 @@ CXStreamingResult CXReadUncompLZ(CXUncompContextLZ* context, const void* src, u3
a = (a | *pSrc++) + 1; a = (a | *pSrc++) + 1;
size--; size--;
context->unk_0x10 = 3; context->lengthBytesLeft = 3;
if (context->length > context->outDataLen) { if (context->length > context->outDataLen) {
if (!context->size) { if (!context->size) {
@@ -271,16 +271,16 @@ CXStreamingResult CXReadUncompLZ(CXUncompContextLZ* context, const void* src, u3
goto out; goto out;
} }
context->unk_0x11 <<= 1; context->flags <<= 1;
context->unk_0x12--; context->flagsLeft--;
} }
if (!size) { if (!size) {
return context->outDataLen; return context->outDataLen;
} }
context->unk_0x11 = *pSrc++; context->flags = *pSrc++;
context->unk_0x12 = 8; context->flagsLeft = 8;
size--; size--;
} }
@@ -369,16 +369,16 @@ CXStreamingResult CXReadUncompHuffman(CXUncompContextHuffman* context, const voi
continue; continue;
} }
context->unk_0x14 >>= context->depth; context->wordBuffer >>= context->depth;
context->unk_0x14 |= context->decodeTable->raw << (32 - context->depth); context->wordBuffer |= context->decodeTable->raw << (32 - context->depth);
context->decodeTable = context->decodeTableData + 1; context->decodeTable = context->decodeTableData + 1;
context->unk_0x1b += context->depth; context->wordBits += context->depth;
if (context->unk_0x1b == 32) { if (context->wordBits == 32) {
*context->outData = CXiConvertEndian32_(context->unk_0x14); *context->outData = CXiConvertEndian32_(context->wordBuffer);
context->outData++; context->outData++;
context->outDataLen -= 4; context->outDataLen -= 4;
context->unk_0x1b = 0; context->wordBits = 0;
if (context->outDataLen <= 0) { if (context->outDataLen <= 0) {
goto out; goto out;