Add LZ models

This commit is contained in:
Matt Nadareski
2022-12-28 10:46:33 -08:00
parent 2b66efd11b
commit 94dfba4b4f
4 changed files with 125 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -0,0 +1,15 @@
namespace BurnOutSharp.Models.Compression.LZ
{
/// <see href="https://github.com/wine-mirror/wine/blob/master/include/lzexpand.h"/>
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,
}
}

View File

@@ -0,0 +1,17 @@
namespace BurnOutSharp.Models.Compression.LZ
{
/// <summary>
/// Format of first 14 byte of LZ compressed file
/// </summary>
/// <see href="https://github.com/wine-mirror/wine/blob/master/dlls/kernel32/lzexpand.c"/>
public sealed class FileHeaader
{
public byte[] Magic;
public byte CompressionType;
public char LastChar;
public uint RealLength;
}
}

View File

@@ -0,0 +1,72 @@
using System.IO;
namespace BurnOutSharp.Models.Compression.LZ
{
public sealed class State
{
/// <summary>
/// The real filedescriptor
/// </summary>
public Stream RealFD { get; set; }
/// <summary>
/// The last char of the filename
/// </summary>
public char LastChar { get; set; }
/// <summary>
/// The decompressed length of the file
/// </summary>
public uint RealLength { get; set; }
/// <summary>
/// The position the decompressor currently is
/// </summary>
public uint RealCurrent { get; set; }
/// <summary>
/// The position the user wants to read from
/// </summary>
public uint RealWanted { get; set; }
/// <summary>
/// The rotating LZ table
/// </summary>
public byte[] Table { get; set; }
/// <summary>
/// CURrent TABle ENTry
/// </summary>
public uint CurTabEnt { get; set; }
/// <summary>
/// Length and position of current string
/// </summary>
public byte StringLen { get; set; }
/// <summary>
/// From stringtable
/// </summary>
public uint StringPos { get; set; }
/// <summary>
/// Bitmask within blocks
/// </summary>
public ushort ByteType { get; set; }
/// <summary>
/// GETLEN bytes
/// </summary>
public byte[] Get { get; set; }
/// <summary>
/// Current read
/// </summary>
public uint GetCur { get; set; }
/// <summary>
/// Length last got
/// </summary>
public uint GetLen { get; set; }
}
}