From 2ed0a0608e65218d101282f653f2cf847b213091 Mon Sep 17 00:00:00 2001
From: Razmoth <32140579+Razmoth@users.noreply.github.com>
Date: Fri, 23 Jun 2023 12:19:24 +0400
Subject: [PATCH] - Added Zstd support - Upgrade libraries.
---
AssetStudio/AssetStudio.csproj | 6 ++---
AssetStudio/BundleFile.cs | 34 ++++++++++++++++++++++++++--
AssetStudioCLI/AssetStudioCLI.csproj | 4 ++--
AssetStudioGUI/AssetStudioGUI.csproj | 2 +-
4 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/AssetStudio/AssetStudio.csproj b/AssetStudio/AssetStudio.csproj
index 898611e..c5c90bc 100644
--- a/AssetStudio/AssetStudio.csproj
+++ b/AssetStudio/AssetStudio.csproj
@@ -10,9 +10,9 @@
-
-
-
+
+
+
diff --git a/AssetStudio/BundleFile.cs b/AssetStudio/BundleFile.cs
index 9f48363..fbb1f62 100644
--- a/AssetStudio/BundleFile.cs
+++ b/AssetStudio/BundleFile.cs
@@ -1,4 +1,5 @@
using K4os.Compression.LZ4;
+using ZstdSharp;
using System;
using System.Data;
using System.IO;
@@ -31,7 +32,8 @@ namespace AssetStudio
Lz4,
Lz4HC,
Lzham,
- Lz4Mr0k
+ Lz4Mr0k,
+ Zstd = 5
}
public class BundleFile
@@ -423,7 +425,7 @@ namespace AssetStudio
}
case CompressionType.Lz4: //LZ4
case CompressionType.Lz4HC: //LZ4HC
- case CompressionType.Lz4Mr0k: //Lz4Mr0k
+ case CompressionType.Lz4Mr0k when Game.Type.IsMhyGroup(): //Lz4Mr0k
{
var compressedSize = (int)blockInfo.compressedSize;
var compressedBytes = BigArrayPool.Shared.Rent(compressedSize);
@@ -454,6 +456,34 @@ namespace AssetStudio
BigArrayPool.Shared.Return(uncompressedBytes);
break;
}
+ case CompressionType.Zstd when !Game.Type.IsMhyGroup(): //Zstd
+ {
+ var compressedSize = (int)blockInfo.compressedSize;
+ var compressedBytes = BigArrayPool.Shared.Rent(compressedSize);
+ reader.Read(compressedBytes, 0, compressedSize);
+
+ var uncompressedSize = (int)blockInfo.uncompressedSize;
+ var uncompressedBytes = BigArrayPool.Shared.Rent(uncompressedSize);
+
+ try
+ {
+ using var decompressor = new Decompressor();
+ var numWrite = decompressor.Unwrap(compressedBytes, 0, compressedSize, uncompressedBytes, 0, uncompressedSize);
+ if (numWrite != uncompressedSize)
+ {
+ throw new IOException($"Zstd decompression error, write {numWrite} bytes but expected {uncompressedSize} bytes");
+ }
+ }
+ catch(Exception ex)
+ {
+ Console.WriteLine($"Zstd decompression error:\n{ex}");
+ }
+
+ blocksStream.Write(uncompressedBytes.ToArray(), 0, uncompressedSize);
+ BigArrayPool.Shared.Return(compressedBytes);
+ BigArrayPool.Shared.Return(uncompressedBytes);
+ break;
+ }
default:
throw new IOException($"Unsupported compression type {compressionType}");
}
diff --git a/AssetStudioCLI/AssetStudioCLI.csproj b/AssetStudioCLI/AssetStudioCLI.csproj
index 5e0b00f..39ae6d9 100644
--- a/AssetStudioCLI/AssetStudioCLI.csproj
+++ b/AssetStudioCLI/AssetStudioCLI.csproj
@@ -11,9 +11,9 @@
-
+
-
+
diff --git a/AssetStudioGUI/AssetStudioGUI.csproj b/AssetStudioGUI/AssetStudioGUI.csproj
index dd8f311..78a6f8c 100644
--- a/AssetStudioGUI/AssetStudioGUI.csproj
+++ b/AssetStudioGUI/AssetStudioGUI.csproj
@@ -68,7 +68,7 @@
-
+
Libraries\OpenTK.WinForms.dll