Skip to content

Commit 33b6b1a

Browse files
committed
chore: modernize entire repo
1 parent f70b2ca commit 33b6b1a

File tree

578 files changed

+37248
-38058
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

578 files changed

+37248
-38058
lines changed

PDTools.Compression/PDIZIP.cs

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,64 @@
88

99
using ICSharpCode.SharpZipLib.Zip.Compression;
1010

11-
namespace PDTools.Compression
12-
{
13-
public class PDIZIP
14-
{
15-
public const uint PDIZIP_MAGIC = 0xFF_F7_F3_2F;
11+
namespace PDTools.Compression;
1612

17-
public static bool Inflate(Stream input, Stream output, bool skipMagic = false)
18-
{
19-
if (!skipMagic && input.ReadUInt32() == PDIZIP_MAGIC)
20-
return false;
13+
public class PDIZIP
14+
{
15+
public const uint PDIZIP_MAGIC = 0xFF_F7_F3_2F;
2116

22-
// Read PDIZIP Header
23-
uint expand_size = input.ReadUInt32();
24-
uint compressed_size = input.ReadUInt32();
25-
uint fragment_size = input.ReadUInt32();
26-
int method = input.ReadInt32();
27-
input.ReadInt32s(3);
17+
public static bool Inflate(Stream input, Stream output, bool skipMagic = false)
18+
{
19+
if (!skipMagic && input.ReadUInt32() == PDIZIP_MAGIC)
20+
return false;
2821

29-
// Calculate the fragment (or chunk) count for the file
30-
uint fragmentCount = (compressed_size + fragment_size - 1) / fragment_size;
22+
// Read PDIZIP Header
23+
uint expand_size = input.ReadUInt32();
24+
uint compressed_size = input.ReadUInt32();
25+
uint fragment_size = input.ReadUInt32();
26+
int method = input.ReadInt32();
27+
input.ReadInt32s(3);
3128

32-
// Set up inflater and buffers
33-
Inflater inflater = new Inflater(true);
34-
byte[] fragment_buffer = ArrayPool<byte>.Shared.Rent((int)fragment_size);
35-
byte[] expand_buffer = ArrayPool<byte>.Shared.Rent(0x20000);
29+
// Calculate the fragment (or chunk) count for the file
30+
uint fragmentCount = (compressed_size + fragment_size - 1) / fragment_size;
3631

37-
for (uint i = 0; i < fragmentCount; i++)
38-
{
39-
if (input.ReadUInt32() != PDIZIP_MAGIC)
40-
throw new Exception("PDIZip Fragment magic did not match expected magic.");
32+
// Set up inflater and buffers
33+
Inflater inflater = new Inflater(true);
34+
byte[] fragment_buffer = ArrayPool<byte>.Shared.Rent((int)fragment_size);
35+
byte[] expand_buffer = ArrayPool<byte>.Shared.Rent(0x20000);
4136

42-
// Read Fragment header
43-
uint fragmentExpandSize = input.ReadUInt32();
44-
uint fragmentCompressedSize = input.ReadUInt32();
45-
uint Unk = input.ReadUInt32();
46-
47-
// Only way to do it properly apparently, inflate streams read too much data
48-
input.Read(fragment_buffer, 0, (int)fragmentCompressedSize);
49-
inflater.SetInput(fragment_buffer, 0, (int)fragmentCompressedSize);
37+
for (uint i = 0; i < fragmentCount; i++)
38+
{
39+
if (input.ReadUInt32() != PDIZIP_MAGIC)
40+
throw new Exception("PDIZip Fragment magic did not match expected magic.");
5041

51-
while (!inflater.IsFinished)
52-
{
53-
int inflated = inflater.Inflate(expand_buffer);
54-
output.Write(expand_buffer, 0, inflated);
55-
}
42+
// Read Fragment header
43+
uint fragmentExpandSize = input.ReadUInt32();
44+
uint fragmentCompressedSize = input.ReadUInt32();
45+
uint Unk = input.ReadUInt32();
5646

57-
// Crypto stream can't seek, so just manually move..
58-
int left = (int)(fragment_size - fragmentCompressedSize) - 0x10;
59-
if (i == 0)
60-
left -= 0x20;
61-
while (left-- > 0) input.ReadByte();
47+
// Only way to do it properly apparently, inflate streams read too much data
48+
input.ReadExactly(fragment_buffer, 0, (int)fragmentCompressedSize);
49+
inflater.SetInput(fragment_buffer, 0, (int)fragmentCompressedSize);
6250

63-
inflater.Reset(); // Prepare for next chunk
51+
while (!inflater.IsFinished)
52+
{
53+
int inflated = inflater.Inflate(expand_buffer);
54+
output.Write(expand_buffer, 0, inflated);
6455
}
6556

66-
ArrayPool<byte>.Shared.Return(fragment_buffer);
67-
ArrayPool<byte>.Shared.Return(expand_buffer);
57+
// Crypto stream can't seek, so just manually move..
58+
int left = (int)(fragment_size - fragmentCompressedSize) - 0x10;
59+
if (i == 0)
60+
left -= 0x20;
61+
while (left-- > 0) input.ReadByte();
6862

69-
return output.Length == expand_size;
63+
inflater.Reset(); // Prepare for next chunk
7064
}
65+
66+
ArrayPool<byte>.Shared.Return(fragment_buffer);
67+
ArrayPool<byte>.Shared.Return(expand_buffer);
68+
69+
return output.Length == expand_size;
7170
}
7271
}

PDTools.Compression/PDTools.Compression.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="ImpromptuNinjas.ZStd" Version="1.4.5.5" />
17-
<PackageReference Include="SharpZipLib" Version="1.3.2" />
17+
<PackageReference Include="SharpZipLib" Version="1.4.2" />
1818
<PackageReference Include="Syroot.BinaryData" Version="5.2.2" />
1919
<PackageReference Include="Syroot.BinaryData.Memory" Version="5.2.2" />
2020
</ItemGroup>

0 commit comments

Comments
 (0)