(BLD0): unpack entries in OpenEntry.

This commit is contained in:
morkt 2018-10-25 16:46:58 +04:00
parent c44d5e0c97
commit ad6bddcb48

View File

@ -25,12 +25,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.IO;
using GameRes.Compression; using GameRes.Compression;
namespace GameRes.Formats.BellDa namespace GameRes.Formats.BellDa
{ {
[Export(typeof(ArchiveFormat))] [Export(typeof(ArchiveFormat))]
public class BldOpener : ArchiveFormat public sealed class BldOpener : ArchiveFormat
{ {
public override string Tag { get { return "DAT/BLD"; } } public override string Tag { get { return "DAT/BLD"; } }
public override string Description { get { return "BELL-DA resource archive"; } } public override string Description { get { return "BELL-DA resource archive"; } }
@ -54,7 +55,7 @@ namespace GameRes.Formats.BellDa
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
var name = file.View.ReadString (index_offset, 0xC); var name = file.View.ReadString (index_offset, 0xC);
var entry = FormatCatalog.Instance.Create<Entry> (name); var entry = Create<PackedEntry> (name);
entry.Offset = data_offset; entry.Offset = data_offset;
entry.Size = file.View.ReadUInt32 (index_offset+0xC); entry.Size = file.View.ReadUInt32 (index_offset+0xC);
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
@ -66,23 +67,25 @@ namespace GameRes.Formats.BellDa
return new ArcFile (file, this, dir); return new ArcFile (file, this, dir);
} }
public override IImageDecoder OpenImage (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
// XXX compression method identical to Maika.Mk2Opener // XXX compression method identical to Maika.Mk2Opener
var pent = (PackedEntry)entry;
if (null == pent || !pent.IsPacked)
{
var id_str = arc.File.View.ReadString (entry.Offset, 2); var id_str = arc.File.View.ReadString (entry.Offset, 2);
if (id_str != "B1" && id_str != "D1" && id_str != "E1") if (id_str != "B1" && id_str != "C1" && id_str != "D1" && id_str != "E1")
return base.OpenImage (arc, entry); return base.OpenEntry (arc, entry);
uint packed_size = arc.File.View.ReadUInt32 (entry.Offset+2); uint packed_size = arc.File.View.ReadUInt32 (entry.Offset+2);
if (packed_size != entry.Size - 10) if (packed_size != entry.Size - 10)
return base.OpenImage (arc, entry); return base.OpenEntry (arc, entry);
uint unpacked_size = arc.File.View.ReadUInt32 (entry.Offset+6); pent.Size = packed_size;
using (var input = arc.File.CreateStream (entry.Offset+10, packed_size)) pent.UnpackedSize = arc.File.View.ReadUInt32 (entry.Offset+6);
using (var lzss = new LzssReader (input, (int)packed_size, (int)unpacked_size)) pent.Offset += 10;
{ pent.IsPacked = true;
lzss.Unpack(); }
var bmp = new BinMemoryStream (lzss.Data, entry.Name); var input = arc.File.CreateStream (entry.Offset, entry.Size);
return new ImageFormatDecoder (bmp); return new LzssStream (input);
}
} }
} }
} }