(Malie.DatOpener): decompress zlib-compressed entries.

This commit is contained in:
morkt 2018-04-20 21:16:19 +04:00
parent 99f5324a2c
commit f3a7afab63

View File

@ -27,6 +27,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.IO; using System.IO;
using GameRes.Compression;
using GameRes.Utility; using GameRes.Utility;
namespace GameRes.Formats.Malie namespace GameRes.Formats.Malie
@ -167,8 +168,34 @@ namespace GameRes.Formats.Malie
var march = arc as MalieArchive; var march = arc as MalieArchive;
if (null == march) if (null == march)
return arc.File.CreateStream (entry.Offset, entry.Size); return arc.File.CreateStream (entry.Offset, entry.Size);
var input = new EncryptedStream (march.File, march.Decryptor); Stream input = new EncryptedStream (march.File, march.Decryptor);
return new StreamRegion (input, entry.Offset, entry.Size); 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 internal abstract class LibIndexReader : ILibIndexReader