1
0
mirror of synced 2024-11-14 19:17:39 +01:00

Kirby and the Forgotten Land ZSTD support (#463)

This commit is contained in:
firubii 2022-03-08 18:24:34 -06:00 committed by GitHub
parent 6ce7e5c8ba
commit 488b689c27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 1 deletions

View File

@ -27,6 +27,7 @@ namespace Toolbox.Library.IO
items.Add(CreateMenu("lZ4")); items.Add(CreateMenu("lZ4"));
items.Add(CreateMenu("lZ4F")); items.Add(CreateMenu("lZ4F"));
items.Add(CreateMenu("ZSTD")); items.Add(CreateMenu("ZSTD"));
items.Add(CreateMenu("ZSTD (Kirby)"));
items.Add(CreateMenu("ZLIB")); items.Add(CreateMenu("ZLIB"));
items.Add(CreateMenu("ZLIB_GZ (Hyrule Warriors)")); items.Add(CreateMenu("ZLIB_GZ (Hyrule Warriors)"));
return items; return items;
@ -82,6 +83,8 @@ namespace Toolbox.Library.IO
OpenFileForCompression(new LZ4F(), Compress); OpenFileForCompression(new LZ4F(), Compress);
else if (Name == "ZSTD") else if (Name == "ZSTD")
OpenFileForCompression(new Zstb(), Compress); OpenFileForCompression(new Zstb(), Compress);
else if (Name == "ZSTD (Kirby)")
OpenFileForCompression(new Zstb_Kirby(), Compress);
else if (Name == "ZLIB") else if (Name == "ZLIB")
OpenFileForCompression(new Zlib(), Compress); OpenFileForCompression(new Zlib(), Compress);
else if (Name.Contains("ZLIB_GZ")) else if (Name.Contains("ZLIB_GZ"))

View File

@ -12,7 +12,7 @@ namespace Toolbox.Library
public class LZ4F : ICompressionFormat public class LZ4F : ICompressionFormat
{ {
public string[] Description { get; set; } = new string[] { "LZ4F Compression" }; public string[] Description { get; set; } = new string[] { "LZ4F Compression" };
public string[] Extension { get; set; } = new string[] { "*.cmp", "*.lz4f" }; public string[] Extension { get; set; } = new string[] { "*.cmp", "*.cmpbin", "*.lz4f" };
public override string ToString() { return "LZ4F"; } public override string ToString() { return "LZ4F"; }

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;
using Toolbox.Library.IO;
using K4os.Compression.LZ4.Streams;
namespace Toolbox.Library
{
public class Zstb_Kirby : ICompressionFormat
{
public string[] Description { get; set; } = new string[] { "ZSTD Compression (Kirby)" };
public string[] Extension { get; set; } = new string[] { "*.cmp" };
public override string ToString() { return "ZSTD (Kirby)"; }
public bool Identify(Stream stream, string fileName)
{
if (stream.Length < 12) return false;
using (var reader = new FileReader(stream, true))
{
uint DecompressedSize = reader.ReadUInt32();
uint magicCheck = reader.ReadUInt32();
bool ZSTDDefault = magicCheck == 0xFD2FB528;
return ZSTDDefault;
}
}
public bool CanCompress { get; } = true;
public Stream Decompress(Stream stream)
{
using (var reader = new FileReader(stream, true))
{
reader.Position = 0;
int OuSize = reader.ReadInt32();
int InSize = (int)stream.Length - 4;
var dec = Zstb.SDecompress(reader.getSection(4, InSize));
return new MemoryStream(dec);
}
}
public Stream Compress(Stream stream)
{
var mem = new MemoryStream();
using (var writer = new FileWriter(mem, true))
{
writer.Write((uint)stream.Length);
byte[] buffer = Zstb.SCompress(stream.ToArray());
writer.Write(buffer, 0, buffer.Length);
}
return mem;
}
}
}

View File

@ -32,6 +32,7 @@ namespace Toolbox.Library
Formats.Add(typeof(Zlib)); Formats.Add(typeof(Zlib));
Formats.Add(typeof(ZlibGZ)); Formats.Add(typeof(ZlibGZ));
Formats.Add(typeof(Zstb)); Formats.Add(typeof(Zstb));
Formats.Add(typeof(Zstb_Kirby));
Formats.Add(typeof(MtaCustomCmp)); Formats.Add(typeof(MtaCustomCmp));
Formats.Add(typeof(LZ77)); Formats.Add(typeof(LZ77));

View File

@ -238,6 +238,7 @@
<Compile Include="Compression\Formats\MtaCustomCmp.cs" /> <Compile Include="Compression\Formats\MtaCustomCmp.cs" />
<Compile Include="Compression\Formats\ZlibGZ.cs" /> <Compile Include="Compression\Formats\ZlibGZ.cs" />
<Compile Include="Compression\Formats\Zstb.cs" /> <Compile Include="Compression\Formats\Zstb.cs" />
<Compile Include="Compression\Formats\Zstb_Kirby.cs" />
<Compile Include="Compression\LZ77_WII.cs" /> <Compile Include="Compression\LZ77_WII.cs" />
<Compile Include="Compression\7ZIP\LZMA\LzmaBase.cs" /> <Compile Include="Compression\7ZIP\LZMA\LzmaBase.cs" />
<Compile Include="Compression\7ZIP\LZMA\LzmaDecoder.cs" /> <Compile Include="Compression\7ZIP\LZMA\LzmaDecoder.cs" />