Skip to content

Commit

Permalink
eggDecomp/eggStreamDecomp Ok
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-thomas774 committed Sep 28, 2024
1 parent 942e8fd commit 7a51afc
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ColumnLimit: 120
ContinuationIndentWidth: 4
IncludeBlocks: Regroup
IndentAccessModifiers: False
IndentCaseLabels: False
IndentCaseLabels: True
IndentGotoLabels: True
IndentWidth: 4
InsertBraces: True
Expand Down
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def nw4rLib(lib_name, objects, extra_cflags=[]):
Object(Matching, "egg/core/eggArchive.cpp"),
Object(Matching, "egg/core/eggDvdFile.cpp"),
Object(NonMatching, "egg/core/eggDvdRipper.cpp"),
Object(NonMatching, "egg/core/eggStream.cpp"),
Object(Matching, "egg/core/eggStream.cpp"),
Object(Matching, "egg/core/eggAllocator.cpp"),
Object(Matching, "egg/core/eggHeap.cpp"),
Object(Matching, "egg/core/eggExpHeap.cpp"),
Expand Down
4 changes: 2 additions & 2 deletions include/egg/core/eggController.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CoreController {

public:
/* 0x004 */ s32 mChannelID;
/* 0x008 */ u32 mButtonHeld; // these fields may need a slight amount of work
/* 0x008 */ u32 mButtonHeld;
/* 0x00C */ u32 mButtonTriggered;
/* 0x010 */ u32 mButtonReleased;
/* 0x014 */ u32 field_0x14;
Expand All @@ -107,7 +107,7 @@ class CoreController {
/* 0xf48 */ ControllerRumbleMgr *mRumbleMgr;
/* 0xf4c */ Matrix34f mPostureMatrix;
/* 0xf7c */ Matrix34f mPostureMatrixPrev;
/* 0xfac */ TBitFlag<u8> mAccelFlags;
/* 0xfac */ TBitFlag<u8> mAccelFlags; // May not be TBitFlag?
/* 0xfb0 */ s32 mMaxAccelFrameTime;
/* 0xfb4 */ s32 mAccelFrameTime[3];
/* 0xfc0 */ f32 mMaxAccelDiff;
Expand Down
13 changes: 6 additions & 7 deletions include/egg/core/eggDecomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <common.h>


// NOTE: I put StreamDecomp stuff here. im unsure of the correct place

namespace EGG {
Expand Down Expand Up @@ -69,16 +68,16 @@ struct UncompContextSZS {
/* 80494e30 */ void initUncompContext(void *pDest);
/* 80494e60 */ static s32
readHeader(u8 *pHeaderLen, s32 *pUncompSize, const u8 *src, u32 maxCompLen, s32 maxUncompSize);
/* 80494f60 */ s32 readUncomp(const void *pSrc, u32 len);
/* 80494f60 */ s32 readUncomp(const void *pSrca, u32 len);

/* 0x00 */ u8 *mpDest;
/* 0x04 */ s32 mUncompSize;
/* 0x08 */ s32 mMaxUncompSize;
/* 0x0C */ u8 _x0C;
/* 0x0D */ u8 _x0D;
/* 0x0E */ u8 _x0E;
/* 0x0F */ u8 mChunkType;
/* 0x10 */ u16 _x10;
/* 0x0C */ u8 mGroupHead;
/* 0x0D */ u8 mSecondByte;
/* 0x0E */ u8 mFirstByte;
/* 0x0F */ u8 mState;
/* 0x10 */ u16 mCopySrc;
/* 0x12 */ u8 mHeaderLen;
};

Expand Down
95 changes: 64 additions & 31 deletions src/egg/core/eggStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ void UncompContextSZS::initUncompContext(void *pDest) {
mUncompSize = 0;
mHeaderLen = 0x10;
mMaxUncompSize = 0;
_x0C = 0;
_x0D = 0;
_x0E = 0;
mChunkType = 0;
_x10 = 0;
mGroupHead = 0;
mSecondByte = 0;
mFirstByte = 0;
mState = 0;
mCopySrc = 0;
}

s32 UncompContextSZS::readHeader(u8 *pHeaderLen, s32 *pUncompSize, const u8 *src, u32 maxCompLen, s32 maxUncompSize) {
Expand Down Expand Up @@ -111,12 +111,12 @@ s32 UncompContextSZS::readHeader(u8 *pHeaderLen, s32 *pUncompSize, const u8 *src
return read_amount;
}

s32 UncompContextSZS::readUncomp(const void *pSrc, u32 len) {
// TODO
s32 UncompContextSZS::readUncomp(const void *pSrca, u32 len) {
const u8 *pSrc = static_cast<const u8 *>(pSrca);
if (mHeaderLen != 0) {
s32 read_len = readHeader(&mHeaderLen, &mUncompSize, (u8 *)pSrc, len, mMaxUncompSize);
pSrc = (u8 *)pSrc - read_len;
len = len - read_len;
s32 read_len = readHeader(&mHeaderLen, &mUncompSize, pSrc, len, mMaxUncompSize);
pSrc += read_len;
len -= read_len;

if (len == 0) {
if (mHeaderLen == 0) {
Expand All @@ -126,35 +126,68 @@ s32 UncompContextSZS::readUncomp(const void *pSrc, u32 len) {
}
}

do {
u32 uncompressed_left = mUncompSize;
if (uncompressed_left < 1) {
break;
}
if (mChunkType == 2) {
u8 byte = *(u8 *)pSrc;
pSrc = (u8 *)pSrc + 1;
while (mUncompSize > 0) {
if (mState == 2) {
u32 num_bytes = *pSrc++ + 0x12;
len--;

u16 chunkLen = byte + 0x12;
if (uncompressed_left < chunkLen) {
if (num_bytes > mUncompSize) {
if (mMaxUncompSize == 0) {
return CX_READ_ERR_4;
}
chunkLen = uncompressed_left;
num_bytes = (u16)mUncompSize;
}
mUncompSize -= chunkLen;
mUncompSize -= num_bytes;
do {
chunkLen--;
*mpDest = mpDest[-_x10];
*mpDest = *(mpDest - mCopySrc);
mpDest++;
} while (chunkLen != 0);
mChunkType = 0;
} else if (mChunkType == 1) {
} while (--num_bytes);
mState = 0;
} else if (mState == 1) {
len--;
u32 b1 = (mFirstByte << 8) | *pSrc++;
u32 num_bytes = b1 >> 12;
mCopySrc = (b1 & 0xFFF) + 1;

if (num_bytes == 0) {
mState = 2;
} else {
num_bytes += 2;
if (num_bytes > mUncompSize) {
if (mMaxUncompSize == 0) {
return CX_READ_ERR_4;
}
num_bytes = (u16)mUncompSize;
}
mUncompSize -= num_bytes;
do {
*mpDest = *(mpDest - mCopySrc);
mpDest++;
} while (--num_bytes);
mState = 0;
}
} else {
if (mGroupHead == 0) {
len--;
mSecondByte = *pSrc++;
mGroupHead = 0x80;
if (len == 0) {
break;
}
}
if (mSecondByte & mGroupHead) {
*mpDest++ = *pSrc++;
mUncompSize--;
} else {
mFirstByte = *pSrc++;
mState = 1;
}
len--;
mGroupHead >>= 1;
}

} while (len != 0);
if (len == 0) {
break;
}
}

if (mUncompSize == 0 && mMaxUncompSize == 0 && len > 0x20) {
return CX_READ_ERR_3;
Expand All @@ -170,7 +203,7 @@ bool StreamDecompSZS::init(void *pDest, u32 maxCompressedSize) {
}

bool StreamDecompSZS::decomp(const void *pSrc, u32 len) {
return mContext.readUncomp(pSrc, len) == CX_READ_OK;
return mContext.readUncomp((const u8 *)pSrc, len) == CX_READ_OK;
}

} // namespace EGG

0 comments on commit 7a51afc

Please sign in to comment.