1
0
mirror of synced 2024-11-12 02:00:50 +01:00

Add support for .z zlibbed files

This commit is contained in:
KillzXGaming 2019-04-30 19:38:39 -04:00
parent 21255d7c31
commit 18d891e1a0
9 changed files with 18 additions and 11 deletions

Binary file not shown.

View File

@ -136,7 +136,7 @@ namespace FirstPlugin
reader.Close();
reader.Dispose();
data = STLibraryCompression.ZLIB.Decompress(filedata, decompSize);
data = STLibraryCompression.ZLIB.Decompress(filedata);
}
return data;
}

View File

@ -204,7 +204,7 @@ namespace FirstPlugin
else if (header.Version > 22)
decomp = STLibraryCompression.Type_LZ4.Decompress(CompressedBlock);
else
decomp = STLibraryCompression.ZLIB.Decompress(CompressedBlock, Header.DecompressedSize);
decomp = STLibraryCompression.ZLIB.Decompress(CompressedBlock);
//Now it's decompressed lets parse!
using (var reader = new FileReader(decomp))

View File

@ -163,11 +163,19 @@ namespace Switch_Toolbox.Library.IO
data = STLibraryCompression.ZSTD.Decompress(fileReader.getSection(0, data.Length));
return OpenFileFormat(FileName, data, LeaveStreamOpen, InArchive, archiveNode, true, CompressionType.Zstb);
}
if (Magic == "ZLIB" || Path.GetExtension(FileName) == ".z")
if (Path.GetExtension(FileName) == ".z" && CompType == CompressionType.None)
{
if (data == null)
data = File.ReadAllBytes(FileName);
data = STLibraryCompression.ZLIB.Decompress(fileReader.getSection(2, data.Length - 2));
return OpenFileFormat(FileName, data, LeaveStreamOpen, InArchive, archiveNode, true, CompressionType.Zlib);
}
if (Magic == "ZLIB")
{
if (data == null)
data = File.ReadAllBytes(FileName);
data = STLibraryCompression.GZIP.Decompress(fileReader.getSection(64, data.Length - 64));
return OpenFileFormat(FileName, data, LeaveStreamOpen, InArchive, archiveNode, true, CompressionType.Zlib);
}
@ -310,16 +318,15 @@ namespace Switch_Toolbox.Library.IO
public class ZLIB
{
public static byte[] Decompress(byte[] b, uint DecompSize)
public static byte[] Decompress(byte[] b)
{
var output = new MemoryStream();
using (var compressedStream = new MemoryStream(b))
using (var zipStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
{
zipStream.CopyTo(output);
zipStream.Close();
output.Position = 0;
return output.ToArray();
using (var compressedStream = new MemoryStream(b)) {
using (var zipStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
{
zipStream.CopyTo(output);
return output.ToArray();
}
}
}