From 94dfba4b4f9b3edaa259a0518e7e1f9eb1bd465a Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 28 Dec 2022 10:46:33 -0800 Subject: [PATCH] Add LZ models --- .../Compression/LZ/Constants.cs | 21 ++++++ BurnOutSharp.Models/Compression/LZ/Enums.cs | 15 ++++ .../Compression/LZ/FileHeader.cs | 17 +++++ BurnOutSharp.Models/Compression/LZ/State.cs | 72 +++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 BurnOutSharp.Models/Compression/LZ/Constants.cs create mode 100644 BurnOutSharp.Models/Compression/LZ/Enums.cs create mode 100644 BurnOutSharp.Models/Compression/LZ/FileHeader.cs create mode 100644 BurnOutSharp.Models/Compression/LZ/State.cs diff --git a/BurnOutSharp.Models/Compression/LZ/Constants.cs b/BurnOutSharp.Models/Compression/LZ/Constants.cs new file mode 100644 index 00000000..b3322f9d --- /dev/null +++ b/BurnOutSharp.Models/Compression/LZ/Constants.cs @@ -0,0 +1,21 @@ +namespace BurnOutSharp.Models.Compression.LZ +{ + public static class Constants + { + public const int LZ_MAGIC_LEN = 8; + + public const int LZ_HEADER_LEN = 14; + + public static readonly byte[] MagicBytes = new byte[] { 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33 }; + + public const string MagicString = "SZDD\u0088\u00f0\u0027\u0033"; + + public const ulong MagicUInt64 = 0x3327f08844445a53; + + public const int LZ_TABLE_SIZE = 0x1000; + + public const int MAX_LZSTATES = 16; + + public const int LZ_MIN_HANDLE = 0x400; + } +} \ No newline at end of file diff --git a/BurnOutSharp.Models/Compression/LZ/Enums.cs b/BurnOutSharp.Models/Compression/LZ/Enums.cs new file mode 100644 index 00000000..43ac96af --- /dev/null +++ b/BurnOutSharp.Models/Compression/LZ/Enums.cs @@ -0,0 +1,15 @@ +namespace BurnOutSharp.Models.Compression.LZ +{ + /// + public enum LZERROR + { + LZERROR_BADINHANDLE = -1, + LZERROR_BADOUTHANDLE = -2, + LZERROR_READ = -3, + LZERROR_WRITE = -4, + LZERROR_GLOBALLOC = -5, + LZERROR_GLOBLOCK = -6, + LZERROR_BADVALUE = -7, + LZERROR_UNKNOWNALG = -8, + } +} \ No newline at end of file diff --git a/BurnOutSharp.Models/Compression/LZ/FileHeader.cs b/BurnOutSharp.Models/Compression/LZ/FileHeader.cs new file mode 100644 index 00000000..c6760343 --- /dev/null +++ b/BurnOutSharp.Models/Compression/LZ/FileHeader.cs @@ -0,0 +1,17 @@ +namespace BurnOutSharp.Models.Compression.LZ +{ + /// + /// Format of first 14 byte of LZ compressed file + /// + /// + public sealed class FileHeaader + { + public byte[] Magic; + + public byte CompressionType; + + public char LastChar; + + public uint RealLength; + } +} \ No newline at end of file diff --git a/BurnOutSharp.Models/Compression/LZ/State.cs b/BurnOutSharp.Models/Compression/LZ/State.cs new file mode 100644 index 00000000..03221a49 --- /dev/null +++ b/BurnOutSharp.Models/Compression/LZ/State.cs @@ -0,0 +1,72 @@ +using System.IO; + +namespace BurnOutSharp.Models.Compression.LZ +{ + public sealed class State + { + /// + /// The real filedescriptor + /// + public Stream RealFD { get; set; } + + /// + /// The last char of the filename + /// + public char LastChar { get; set; } + + /// + /// The decompressed length of the file + /// + public uint RealLength { get; set; } + + /// + /// The position the decompressor currently is + /// + public uint RealCurrent { get; set; } + + /// + /// The position the user wants to read from + /// + public uint RealWanted { get; set; } + + /// + /// The rotating LZ table + /// + public byte[] Table { get; set; } + + /// + /// CURrent TABle ENTry + /// + public uint CurTabEnt { get; set; } + + /// + /// Length and position of current string + /// + public byte StringLen { get; set; } + + /// + /// From stringtable + /// + public uint StringPos { get; set; } + + /// + /// Bitmask within blocks + /// + public ushort ByteType { get; set; } + + /// + /// GETLEN bytes + /// + public byte[] Get { get; set; } + + /// + /// Current read + /// + public uint GetCur { get; set; } + + /// + /// Length last got + /// + public uint GetLen { get; set; } + } +} \ No newline at end of file