From 7b709d7702e0e79ef701f27f30e8c0ff03db09d2 Mon Sep 17 00:00:00 2001 From: Denis <93516910+Bussun@users.noreply.github.com> Date: Sun, 16 Jan 2022 16:15:34 +0100 Subject: [PATCH] Two files for this is too much --- BMGEditor/FS/Compression.cs | 45 ------------------------------------- BMGEditor/FS/Yaz0Stream.cs | 44 +++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 48 deletions(-) delete mode 100644 BMGEditor/FS/Compression.cs diff --git a/BMGEditor/FS/Compression.cs b/BMGEditor/FS/Compression.cs deleted file mode 100644 index 44b72a6..0000000 --- a/BMGEditor/FS/Compression.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; - -namespace BMGEditor -{ - public static class Yaz0 // TODO: Finish rewriting this - { - 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]); - byte[] output = new byte[decompSize]; - int Offs = 16; - int dstoffs = 0; - while (true) - { - byte header = data[Offs++]; - for (int i = 0; i < 8; i++) - { - if ((header & 0x80) != 0) output[dstoffs++] = data[Offs++]; - else - { - byte b = data[Offs++]; - int offs = ((b & 0xF) << 8 | data[Offs++]) + 1; - int length = (b >> 4) + 2; - if (length == 2) length = data[Offs++] + 0x12; - for (int j = 0; j < length; j++) - { - output[dstoffs] = output[dstoffs - offs]; - dstoffs++; - } - } - if (dstoffs >= decompSize) - { - Array.Resize(ref data, decompSize); - output.CopyTo(data, 0); - return; - } - header <<= 1; - } - } - } - } -} diff --git a/BMGEditor/FS/Yaz0Stream.cs b/BMGEditor/FS/Yaz0Stream.cs index d1da89a..a49b916 100644 --- a/BMGEditor/FS/Yaz0Stream.cs +++ b/BMGEditor/FS/Yaz0Stream.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.IO; namespace BMGEditor @@ -27,4 +24,45 @@ namespace BMGEditor private Stream m_Backend; } + + public static class Yaz0 // TODO: Finish rewriting this + { + 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]); + byte[] output = new byte[decompSize]; + int Offs = 16; + int dstoffs = 0; + while (true) + { + byte header = data[Offs++]; + for (int i = 0; i < 8; i++) + { + if ((header & 0x80) != 0) output[dstoffs++] = data[Offs++]; + else + { + byte b = data[Offs++]; + int offs = ((b & 0xF) << 8 | data[Offs++]) + 1; + int length = (b >> 4) + 2; + if (length == 2) length = data[Offs++] + 0x12; + for (int j = 0; j < length; j++) + { + output[dstoffs] = output[dstoffs - offs]; + dstoffs++; + } + } + if (dstoffs >= decompSize) + { + Array.Resize(ref data, decompSize); + output.CopyTo(data, 0); + return; + } + header <<= 1; + } + } + } + } }