(AosOpener): recognize compressed ABM images.

This commit is contained in:
morkt 2015-11-07 03:05:35 +04:00
parent 247f067737
commit 2d2da5e3e5

View File

@ -32,6 +32,11 @@ using GameRes.Utility;
namespace GameRes.Formats.Lilim namespace GameRes.Formats.Lilim
{ {
internal class AosEntry : Entry
{
public bool IsCompressed;
}
[Export(typeof(ArchiveFormat))] [Export(typeof(ArchiveFormat))]
public class AosOpener : ArchiveFormat public class AosOpener : ArchiveFormat
{ {
@ -76,13 +81,15 @@ namespace GameRes.Formats.Lilim
if (-1 == name_length) if (-1 == name_length)
name_length = name_buf.Length; name_length = name_buf.Length;
var name = Encodings.cp932.GetString (name_buf, 0, name_length); var name = Encodings.cp932.GetString (name_buf, 0, name_length);
var entry = FormatCatalog.Instance.Create<Entry> (name); var entry = FormatCatalog.Instance.Create<AosEntry> (name);
entry.Offset = file.View.ReadUInt32 (current_offset+0x10); entry.Offset = file.View.ReadUInt32 (current_offset+0x10);
entry.Size = file.View.ReadUInt32 (current_offset+0x14); entry.Size = file.View.ReadUInt32 (current_offset+0x14);
current_offset += 0x20; current_offset += 0x20;
entry.Offset += current_offset; entry.Offset += current_offset;
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase))
entry.IsCompressed = true;
dir.Add (entry); dir.Add (entry);
} }
} }
@ -91,8 +98,9 @@ namespace GameRes.Formats.Lilim
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (!entry.Name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) var aent = entry as AosEntry;
return arc.File.CreateStream (entry.Offset, entry.Size); if (null == aent || !aent.IsCompressed)
return base.OpenEntry (arc, entry);
uint unpacked_size = arc.File.View.ReadUInt32 (entry.Offset); uint unpacked_size = arc.File.View.ReadUInt32 (entry.Offset);
var packed = new byte[entry.Size-4]; var packed = new byte[entry.Size-4];
@ -140,11 +148,19 @@ namespace GameRes.Formats.Lilim
var name = file.View.ReadString (index_offset, 0x20); var name = file.View.ReadString (index_offset, 0x20);
if (0 == name.Length) if (0 == name.Length)
return null; return null;
var entry = FormatCatalog.Instance.Create<Entry> (name); var entry = FormatCatalog.Instance.Create<AosEntry> (name);
entry.Offset = base_offset + file.View.ReadUInt32 (index_offset+0x20); entry.Offset = base_offset + file.View.ReadUInt32 (index_offset+0x20);
entry.Size = file.View.ReadUInt32 (index_offset+0x24); entry.Size = file.View.ReadUInt32 (index_offset+0x24);
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase))
entry.IsCompressed = true;
else if (name.EndsWith (".cmp", StringComparison.InvariantCultureIgnoreCase))
{
entry.IsCompressed = true;
entry.Name = Path.ChangeExtension (entry.Name, ".abm");
entry.Type = "image";
}
dir.Add (entry); dir.Add (entry);
index_offset += 0x28; index_offset += 0x28;
} }