From af09d30b3bf6507f5ae10c80e45f9b39f141f654 Mon Sep 17 00:00:00 2001 From: Denis <93516910+Bussun@users.noreply.github.com> Date: Fri, 28 Jan 2022 23:13:35 +0100 Subject: [PATCH] I'll work on Yaz0 more --- BMGEditor/FS/Yaz0Stream.cs | 67 ++------------------------------------ 1 file changed, 3 insertions(+), 64 deletions(-) diff --git a/BMGEditor/FS/Yaz0Stream.cs b/BMGEditor/FS/Yaz0Stream.cs index b7b8b17..b3d2872 100644 --- a/BMGEditor/FS/Yaz0Stream.cs +++ b/BMGEditor/FS/Yaz0Stream.cs @@ -25,76 +25,15 @@ namespace BMGEditor private Stream m_Backend; } - public static class Yaz0 // TODO: Finish rewriting this + public static class Yaz0 // TODO: Write it { - public static void Decompress(ref byte[] data) + unsafe public static void Decompress(ref byte[] data) { if (data[0] != 'Y' || data[1] != 'a' || data[2] != 'z' || data[3] != '0') return; Int32 decompSize = (data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]); - uint sourcePos = 16; //start at 0x10 - uint writePos = 0; //destination to write data to - byte[] decodedData = new byte[decompSize + 1]; - byte groupHead = 0; - byte lastGroupHead = 0; - uint validBitCount = 0; - - while (writePos < decompSize) - { - //System.Windows.Forms.MessageBox.Show(groupHead.ToString("X") + "|" + validBitCount); - if (validBitCount == 0) //new group header - { - groupHead = data[sourcePos]; - lastGroupHead = groupHead; - ++sourcePos; - validBitCount = 8; //reset count - } - if ((groupHead & 0x80) != 0) //straight copy as long as groupheader maintains left most bit as 1 (1000 0000) - { - decodedData[writePos] = data[sourcePos]; - writePos++; - sourcePos++; - } - else - { - byte b1 = data[sourcePos]; //byte 1 - byte b2 = data[sourcePos + 1]; //byte 2 - sourcePos += 2; //move past those two bytes - uint dist = (uint)((b1 & 0xF) << 8) | b2; //distance - if (Tests.isBE) - dist = (UInt32)((dist >> 24) | ((dist & 0xFF0000) >> 8) | ((dist & 0xFF00) << 8) | (dist << 24)); - - uint copySource = writePos - (dist + 1); //copy - uint numBytes = (uint)b1 >> 4; //how many bytes to copy - - //if (sourcePos-2 > 0x13C0) //debug decode - //System.Windows.Forms.MessageBox.Show("lastGroupHead: 0x" + lastGroupHead.ToString("X") + "\n" + "b1: 0x" + b1.ToString("X") + "\n" + "b2: 0x" + b2.ToString("X") + "\n" + "sourcePos: 0x" + sourcePos.ToString("X") + "\n" + "dist: " + dist + "\n" + "copySource: 0x" + copySource.ToString("X") + "\n" + "writePos: 0x" + writePos.ToString("X") + "\n" + "numBytes: " + numBytes); - - if (numBytes == 0) //If the first 4 bits of the first byte is 0... - { - numBytes = data[sourcePos] + (uint)0x12; - sourcePos++; - } - else - { - numBytes += 2; - } - for (int i = 0; i < numBytes; ++i) - { - decodedData[writePos] = decodedData[copySource]; - copySource++; - writePos++; - } - } - groupHead <<= 1; //left shift!!! - validBitCount -= 1; //group header validation count of the binary position - } - - Array.Resize(ref data, decompSize + 1); - decodedData.CopyTo(data, 0); - FileStream test = File.OpenWrite("./test.bin"); - test.Write(data); + return; } }