From 5d386938dc264244a5b5c387099238fef89088d0 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Tue, 7 Nov 2023 03:09:55 +0100 Subject: [PATCH] Added support for decoding Brotli compression used in new formats --- 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: