implemented more of Leaf resources (LGF, TEX).

This commit is contained in:
morkt
2016-09-04 04:57:06 +04:00
parent bc62faa71a
commit 97e1c01be5
3 changed files with 241 additions and 1 deletions

View File

@@ -36,7 +36,7 @@ namespace GameRes.Formats.Leaf
public override string Tag { get { return "LAC"; } }
public override string Description { get { return "Leaf resource archive"; } }
public override uint Signature { get { return 0x43414C; } } // 'LAC'
public override bool IsHierarchic { get { return false; } }
public override bool IsHierarchic { get { return true; } }
public override bool CanCreate { get { return false; } }
public override ArcFile TryOpen (ArcView file)
@@ -78,4 +78,75 @@ namespace GameRes.Formats.Leaf
return lzs;
}
}
[Export(typeof(ArchiveFormat))]
public class PakOpener : ArchiveFormat
{
public override string Tag { get { return "PAK/LAC"; } }
public override string Description { get { return "Leaf resource archive"; } }
public override uint Signature { get { return 0x43414C; } } // 'LAC'
public override bool IsHierarchic { get { return false; } }
public override bool CanCreate { get { return false; } }
public PakOpener ()
{
Extensions = new string[] { "pak" };
}
public override ArcFile TryOpen (ArcView file)
{
int count = file.View.ReadInt32 (4);
if (!IsSaneCount (count))
return null;
uint index_offset = 8;
var dir = new List<Entry> (count);
var name_buf = new byte[0x20];
for (int i = 0; i < count; ++i)
{
file.View.Read (index_offset, name_buf, 0, 0x20);
index_offset += 0x20;
int l;
for (l = 0; l < 0x1F && name_buf[l] != 0; ++l)
{
name_buf[l] ^= 0xFF;
}
if (0 == l)
return null;
var name = Encodings.cp932.GetString (name_buf, 0, l);
var entry = FormatCatalog.Instance.Create<PackedEntry> (name);
entry.IsPacked = 0 != name_buf[0x1F];
entry.Size = file.View.ReadUInt32 (index_offset);
entry.Offset = file.View.ReadUInt32 (index_offset+4);
index_offset += 8;
if (!entry.CheckPlacement (file.MaxOffset))
return null;
dir.Add (entry);
}
return new ArcFile (file, this, dir);
}
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
var pent = entry as PackedEntry;
if (null == pent || !pent.IsPacked || entry.Size <= 4)
return base.OpenEntry (arc, entry);
if (0 == pent.UnpackedSize)
{
uint size = arc.File.View.ReadUInt32 (entry.Offset);
if (size == pent.Size)
{
pent.Offset += 4;
pent.Size -= 4;
}
pent.UnpackedSize = arc.File.View.ReadUInt32 (entry.Offset);
pent.Offset += 4;
pent.Size -= 4;
if (0 == pent.UnpackedSize)
++pent.UnpackedSize;
}
Stream input = arc.File.CreateStream (entry.Offset, entry.Size);
return new LzssStream (input);
}
}
}