mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-21 20:13:06 +00:00
Kirby and the Forgotten Land ZSTD support (#463)
This commit is contained in:
parent
6ce7e5c8ba
commit
488b689c27
5 changed files with 67 additions and 1 deletions
|
@ -27,6 +27,7 @@ namespace Toolbox.Library.IO
|
|||
items.Add(CreateMenu("lZ4"));
|
||||
items.Add(CreateMenu("lZ4F"));
|
||||
items.Add(CreateMenu("ZSTD"));
|
||||
items.Add(CreateMenu("ZSTD (Kirby)"));
|
||||
items.Add(CreateMenu("ZLIB"));
|
||||
items.Add(CreateMenu("ZLIB_GZ (Hyrule Warriors)"));
|
||||
return items;
|
||||
|
@ -82,6 +83,8 @@ namespace Toolbox.Library.IO
|
|||
OpenFileForCompression(new LZ4F(), Compress);
|
||||
else if (Name == "ZSTD")
|
||||
OpenFileForCompression(new Zstb(), Compress);
|
||||
else if (Name == "ZSTD (Kirby)")
|
||||
OpenFileForCompression(new Zstb_Kirby(), Compress);
|
||||
else if (Name == "ZLIB")
|
||||
OpenFileForCompression(new Zlib(), Compress);
|
||||
else if (Name.Contains("ZLIB_GZ"))
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Toolbox.Library
|
|||
public class LZ4F : ICompressionFormat
|
||||
{
|
||||
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"; }
|
||||
|
||||
|
|
61
Switch_Toolbox_Library/Compression/Formats/Zstb_Kirby.cs
Normal file
61
Switch_Toolbox_Library/Compression/Formats/Zstb_Kirby.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,6 +32,7 @@ namespace Toolbox.Library
|
|||
Formats.Add(typeof(Zlib));
|
||||
Formats.Add(typeof(ZlibGZ));
|
||||
Formats.Add(typeof(Zstb));
|
||||
Formats.Add(typeof(Zstb_Kirby));
|
||||
Formats.Add(typeof(MtaCustomCmp));
|
||||
Formats.Add(typeof(LZ77));
|
||||
|
||||
|
|
|
@ -238,6 +238,7 @@
|
|||
<Compile Include="Compression\Formats\MtaCustomCmp.cs" />
|
||||
<Compile Include="Compression\Formats\ZlibGZ.cs" />
|
||||
<Compile Include="Compression\Formats\Zstb.cs" />
|
||||
<Compile Include="Compression\Formats\Zstb_Kirby.cs" />
|
||||
<Compile Include="Compression\LZ77_WII.cs" />
|
||||
<Compile Include="Compression\7ZIP\LZMA\LzmaBase.cs" />
|
||||
<Compile Include="Compression\7ZIP\LZMA\LzmaDecoder.cs" />
|
||||
|
|
Loading…
Reference in a new issue