From 2bb952f292ac9c2a1a1c84019d97b406018f7938 Mon Sep 17 00:00:00 2001 From: Taloth Date: Thu, 9 Nov 2023 23:45:30 +0100 Subject: [PATCH] Added support for decoding Brotli compression used in new formats (#7) --- AOEMods.Essence/SGA/Core/FileStorageType.cs | 12 +++++++++++- AOEMods.Essence/SGA/Graph/ArchiveFileNode.cs | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/AOEMods.Essence/SGA/Core/FileStorageType.cs b/AOEMods.Essence/SGA/Core/FileStorageType.cs index 3fa595d..d3bb64c 100644 --- a/AOEMods.Essence/SGA/Core/FileStorageType.cs +++ b/AOEMods.Essence/SGA/Core/FileStorageType.cs @@ -18,5 +18,15 @@ public enum FileStorageType : byte /// /// Stored compressed. /// - BufferCompress + BufferCompress, + + /// + /// Stored compressed. + /// + StreamCompressBrotli, + + /// + /// Stored compressed. + /// + BufferCompressBrotli } diff --git a/AOEMods.Essence/SGA/Graph/ArchiveFileNode.cs b/AOEMods.Essence/SGA/Graph/ArchiveFileNode.cs index f7030de..0a2f0ae 100644 --- a/AOEMods.Essence/SGA/Graph/ArchiveFileNode.cs +++ b/AOEMods.Essence/SGA/Graph/ArchiveFileNode.cs @@ -1,4 +1,5 @@ using AOEMods.Essence.SGA.Core; +using System.IO; using System.IO.Compression; using System.Text; @@ -67,6 +68,15 @@ public IEnumerable GetData() MemoryStream decoded = new((int)dataUncompressedLength); deflateStream.CopyTo(decoded); + return decoded.ToArray(); + } + case FileStorageType.StreamCompressBrotli: + case FileStorageType.BufferCompressBrotli: + { + using var brotliStream = new BrotliStream(dataStream, CompressionMode.Decompress, leaveOpen: true); + MemoryStream decoded = new((int)dataUncompressedLength); + brotliStream.CopyTo(decoded); + return decoded.ToArray(); } default: