mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-14 11:18:47 -05:00
Add oodle compression support (unofficial)
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using BundleCompression.Lzma;
|
||||
using BundleCompression.Oodle;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using K4os.Compression.LZ4;
|
||||
using ZstdSharp;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class BundleDecompressionHelper
|
||||
{
|
||||
private static readonly Decompressor ZstdDecompressor = new Decompressor();
|
||||
private static readonly string MsgPattern = @"\. ";
|
||||
|
||||
public static MemoryStream DecompressLzmaStream(MemoryStream inStream)
|
||||
{
|
||||
return SevenZipLzma.DecompressStream(inStream);
|
||||
}
|
||||
|
||||
public static long DecompressLzmaStream(Stream compressedStream, Stream decompressedStream, long compressedSize, long decompressedSize, ref string errorMsg)
|
||||
{
|
||||
var numWrite = -1L;
|
||||
try
|
||||
{
|
||||
numWrite = SevenZipLzma.DecompressStream(compressedStream, decompressedStream, compressedSize, decompressedSize);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Debug(e.ToString());
|
||||
errorMsg = $"({Regex.Split(e.Message, MsgPattern, RegexOptions.CultureInvariant)[0]})";
|
||||
}
|
||||
return numWrite;
|
||||
}
|
||||
|
||||
public static int DecompressBlock(CompressionType type, ReadOnlySpan<byte> srcBuffer, Span<byte> dstBuffer, ref string errorMsg)
|
||||
{
|
||||
var numWrite = -1;
|
||||
try
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CompressionType.Lz4:
|
||||
case CompressionType.Lz4HC:
|
||||
numWrite = LZ4Codec.Decode(srcBuffer, dstBuffer);
|
||||
break;
|
||||
case CompressionType.Zstd:
|
||||
numWrite = ZstdDecompressor.Unwrap(srcBuffer, dstBuffer);
|
||||
break;
|
||||
case CompressionType.Oodle:
|
||||
numWrite = OodleLZ.Decompress(srcBuffer, dstBuffer);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Debug(e.ToString());
|
||||
errorMsg = $"({Regex.Split(e.Message, MsgPattern, RegexOptions.CultureInvariant)[0]})";
|
||||
}
|
||||
return numWrite;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user