Skip to content

Commit d7fe186

Browse files
committed
Update packages
1 parent c3044bd commit d7fe186

File tree

4 files changed

+18
-344
lines changed

4 files changed

+18
-344
lines changed

SabreTools.Compression/Quantum/Decompressor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public byte[] Process()
148148
// Initialize the coding state
149149
CS_H = 0xffff;
150150
CS_L = 0x0000;
151-
CS_C = (ushort)(_bitStream.ReadBitsMSB(16) ?? 0);
151+
CS_C = (ushort)(_bitStream.ReadBitsBE(16) ?? 0);
152152

153153
// Loop until the end of the stream
154154
var bytes = new List<byte>();
@@ -187,25 +187,25 @@ public byte[] Process()
187187
{
188188
case 4:
189189
int model4sym = GetSymbol(_model4);
190-
int model4extra = (int)(_bitStream.ReadBitsMSB(PositionExtraBits[model4sym]) ?? 0);
190+
int model4extra = (int)(_bitStream.ReadBitsBE(PositionExtraBits[model4sym]) ?? 0);
191191
offset = PositionSlot[model4sym] + model4extra + 1;
192192
length = 3;
193193
break;
194194

195195
case 5:
196196
int model5sym = GetSymbol(_model5);
197-
int model5extra = (int)(_bitStream.ReadBitsMSB(PositionExtraBits[model5sym]) ?? 0);
197+
int model5extra = (int)(_bitStream.ReadBitsBE(PositionExtraBits[model5sym]) ?? 0);
198198
offset = PositionSlot[model5sym] + model5extra + 1;
199199
length = 4;
200200
break;
201201

202202
case 6:
203203
int lengthSym = GetSymbol(_model6len);
204-
int lengthExtra = (int)(_bitStream.ReadBitsMSB(LengthExtraBits[lengthSym]) ?? 0);
204+
int lengthExtra = (int)(_bitStream.ReadBitsBE(LengthExtraBits[lengthSym]) ?? 0);
205205
length = LengthSlot[lengthSym] + lengthExtra + 5;
206206

207207
int model6sym = GetSymbol(_model6);
208-
int model6extra = (int)(_bitStream.ReadBitsMSB(PositionExtraBits[model6sym]) ?? 0);
208+
int model6extra = (int)(_bitStream.ReadBitsBE(PositionExtraBits[model6sym]) ?? 0);
209209
offset = PositionSlot[model6sym] + model6extra + 1;
210210
break;
211211

SabreTools.Compression/SZDD/Decompressor.cs

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
3-
using System.Text;
4-
using SabreTools.IO.Extensions;
3+
using SabreTools.Models.LZ;
54

65
namespace SabreTools.Compression.SZDD
76
{
@@ -44,39 +43,27 @@ private Decompressor(Stream source)
4443
/// <summary>
4544
/// Create a KWAJ decompressor
4645
/// </summary>
47-
public static Decompressor CreateKWAJ(byte[] source)
48-
=> CreateKWAJ(new MemoryStream(source));
46+
public static Decompressor CreateKWAJ(byte[] source, KWAJCompressionType compressionType)
47+
=> CreateKWAJ(new MemoryStream(source), compressionType);
4948

5049
/// <summary>
5150
/// Create a KWAJ decompressor
5251
/// </summary>
53-
/// TODO: Replace validation when Models is updated
54-
public static Decompressor CreateKWAJ(Stream source)
52+
public static Decompressor CreateKWAJ(Stream source, KWAJCompressionType compressionType)
5553
{
5654
// Create the decompressor
5755
var decompressor = new Decompressor(source);
5856

59-
// Validate the header
60-
byte[] magic = source.ReadBytes(8);
61-
if (Encoding.ASCII.GetString(magic) != Encoding.ASCII.GetString([0x4B, 0x57, 0x41, 0x4A, 0x88, 0xF0, 0x27, 0xD1]))
62-
throw new InvalidDataException(nameof(source));
63-
ushort compressionType = source.ReadUInt16();
57+
// Set the format and return
6458
decompressor._format = compressionType switch
6559
{
66-
0 => Format.KWAJNoCompression,
67-
1 => Format.KWAJXor,
68-
2 => Format.KWAJQBasic,
69-
3 => Format.KWAJLZH,
70-
4 => Format.KWAJMSZIP,
60+
KWAJCompressionType.NoCompression => Format.KWAJNoCompression,
61+
KWAJCompressionType.NoCompressionXor => Format.KWAJXor,
62+
KWAJCompressionType.QBasic => Format.KWAJQBasic,
63+
KWAJCompressionType.LZH => Format.KWAJLZH,
64+
KWAJCompressionType.MSZIP => Format.KWAJMSZIP,
7165
_ => throw new IndexOutOfRangeException(nameof(source)),
7266
};
73-
74-
// Skip the rest of the header
75-
ushort dataOffset = source.ReadUInt16(); // DataOffset
76-
_ = source.ReadUInt16(); // HeaderFlags
77-
78-
// Seek and return
79-
source.Seek(dataOffset, SeekOrigin.Begin);
8067
return decompressor;
8168
}
8269

@@ -89,20 +76,11 @@ public static Decompressor CreateQBasic(byte[] source)
8976
/// <summary>
9077
/// Create a QBasic 4.5 installer SZDD decompressor
9178
/// </summary>
92-
/// TODO: Replace validation when Models is updated
9379
public static Decompressor CreateQBasic(Stream source)
9480
{
9581
// Create the decompressor
9682
var decompressor = new Decompressor(source);
9783

98-
// Validate the header
99-
byte[] magic = source.ReadBytes(8);
100-
if (Encoding.ASCII.GetString(magic) != Encoding.ASCII.GetString([0x53, 0x5A, 0x20, 0x88, 0xF0, 0x27, 0x33, 0xD1]))
101-
throw new InvalidDataException(nameof(source));
102-
103-
// Skip the rest of the header
104-
_ = source.ReadUInt32(); // RealLength
105-
10684
// Set the format and return
10785
decompressor._format = Format.QBasic;
10886
return decompressor;
@@ -117,24 +95,11 @@ public static Decompressor CreateSZDD(byte[] source)
11795
/// <summary>
11896
/// Create a standard SZDD decompressor
11997
/// </summary>
120-
/// TODO: Replace validation when Models is updated
12198
public static Decompressor CreateSZDD(Stream source)
12299
{
123100
// Create the decompressor
124101
var decompressor = new Decompressor(source);
125102

126-
// Validate the header
127-
byte[] magic = source.ReadBytes(8);
128-
if (Encoding.ASCII.GetString(magic) != Encoding.ASCII.GetString([0x53, 0x5A, 0x44, 0x44, 0x88, 0xF0, 0x27, 0x33]))
129-
throw new InvalidDataException(nameof(source));
130-
byte compressionType = source.ReadByteValue();
131-
if (compressionType != 0x41)
132-
throw new InvalidDataException(nameof(source));
133-
134-
// Skip the rest of the header
135-
_ = source.ReadByteValue(); // LastChar
136-
_ = source.ReadUInt32(); // RealLength
137-
138103
// Set the format and return
139104
decompressor._format = Format.SZDD;
140105
return decompressor;

SabreTools.Compression/SabreTools.Compression.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
</ItemGroup>
2727

2828
<ItemGroup>
29-
<PackageReference Include="SabreTools.IO" Version="1.5.1" />
30-
<PackageReference Include="SabreTools.Models" Version="1.5.1" />
29+
<PackageReference Include="SabreTools.IO" Version="1.6.1" />
30+
<PackageReference Include="SabreTools.Models" Version="1.5.7" />
3131
</ItemGroup>
3232

3333
</Project>

0 commit comments

Comments
 (0)