From f3a7afab63190ae4caaf3c4f2b2306116c1fd32a Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 20 Apr 2018 21:16:19 +0400 Subject: [PATCH] (Malie.DatOpener): decompress zlib-compressed entries. --- ArcFormats/Malie/ArcLIB.cs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/ArcFormats/Malie/ArcLIB.cs b/ArcFormats/Malie/ArcLIB.cs index 0af6a89e..b33d6a6e 100644 --- a/ArcFormats/Malie/ArcLIB.cs +++ b/ArcFormats/Malie/ArcLIB.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.IO; +using GameRes.Compression; using GameRes.Utility; namespace GameRes.Formats.Malie @@ -167,8 +168,34 @@ namespace GameRes.Formats.Malie var march = arc as MalieArchive; if (null == march) return arc.File.CreateStream (entry.Offset, entry.Size); - var input = new EncryptedStream (march.File, march.Decryptor); - return new StreamRegion (input, entry.Offset, entry.Size); + Stream input = new EncryptedStream (march.File, march.Decryptor); + input = new StreamRegion (input, entry.Offset, entry.Size); + if (entry.Name.HasExtension (".txtz")) + { + input = new ZLibStream (input, CompressionMode.Decompress); + } + else if (entry.Name.HasExtension (".psbz")) + { + input = UnpackPsbz (input); + } + return input; + } + + Stream UnpackPsbz (Stream input) + { + var header = new byte[8]; + input.Read (header, 0, 8); + if (!header.AsciiEqual ("PSBZ")) + { + input.Position = 0; + return input; + } + int unpacked_size = header.ToInt32 (4); + var output = new MemoryStream (unpacked_size); + using (input = new ZLibStream (input, CompressionMode.Decompress)) + input.CopyTo (output); + output.Position = 0; + return output; } internal abstract class LibIndexReader : ILibIndexReader