diff --git a/ArcFormats/ArcAil.cs b/ArcFormats/Ail/ArcAil.cs similarity index 92% rename from ArcFormats/ArcAil.cs rename to ArcFormats/Ail/ArcAil.cs index bfbe9fde..35eee078 100644 --- a/ArcFormats/ArcAil.cs +++ b/ArcFormats/Ail/ArcAil.cs @@ -49,16 +49,37 @@ namespace GameRes.Formats.Ail int count = file.View.ReadInt32 (0); if (!IsSaneCount (count)) return null; - long offset = 4+count*4; + var dir = ReadIndex (file, 4, count); + if (null == dir) + return null; + return new ArcFile (file, this, dir); + } + + public override Stream OpenEntry (ArcFile arc, Entry entry) + { + var input = arc.File.CreateStream (entry.Offset, entry.Size); + var pentry = entry as PackedEntry; + if (null == pentry || !pentry.IsPacked) + return input; + using (input) + { + byte[] data = new byte[pentry.UnpackedSize]; + LzssUnpack (input, data); + return new BinMemoryStream (data, entry.Name); + } + } + + internal List ReadIndex (ArcView file, uint index_offset, int count) + { + var base_name = Path.GetFileNameWithoutExtension (file.Name); + long offset = index_offset + count*4; if (offset >= file.MaxOffset) return null; - var base_name = Path.GetFileNameWithoutExtension (file.Name); - uint index_offset = 4; - var dir = new List(); + var dir = new List (count/2); for (int i = 0; i < count; ++i) { uint size = file.View.ReadUInt32 (index_offset); - if (0 != size) + if (size != 0 && size != uint.MaxValue) { var entry = new PackedEntry { @@ -74,8 +95,14 @@ namespace GameRes.Formats.Ail } index_offset += 4; } - if (offset != file.MaxOffset || 0 == dir.Count) + if (0 == dir.Count) return null; + DetectFileTypes (file, dir); + return dir; + } + + internal void DetectFileTypes (ArcView file, List dir) + { byte[] preview = new byte[16]; byte[] sign_buf = new byte[4]; foreach (PackedEntry entry in dir) @@ -111,21 +138,6 @@ namespace GameRes.Formats.Ail if (0 != signature) SetEntryType (entry, signature); } - return new ArcFile (file, this, dir); - } - - public override Stream OpenEntry (ArcFile arc, Entry entry) - { - var input = arc.File.CreateStream (entry.Offset, entry.Size); - var pentry = entry as PackedEntry; - if (null == pentry || !pentry.IsPacked) - return input; - using (input) - { - byte[] data = new byte[pentry.UnpackedSize]; - LzssUnpack (input, data); - return new BinMemoryStream (data, entry.Name); - } } static void SetEntryType (Entry entry, uint signature) diff --git a/ArcFormats/Ail/ArcLNK2.cs b/ArcFormats/Ail/ArcLNK2.cs new file mode 100644 index 00000000..c81cc04d --- /dev/null +++ b/ArcFormats/Ail/ArcLNK2.cs @@ -0,0 +1,58 @@ +//! \file ArcLNK2.cs +//! \date 2018 Jan 04 +//! \brief Ail resource archive. +// +// Copyright (C) 2018 by morkt +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +using System; +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.IO; + +namespace GameRes.Formats.Ail +{ + [Export(typeof(ArchiveFormat))] + public class Lnk2Opener : DatOpener + { + public override string Tag { get { return "DAT/LNK2"; } } + public override string Description { get { return "Ail resource archive"; } } + public override uint Signature { get { return 0x324B4E4C; } } // 'LNK2' + public override bool IsHierarchic { get { return false; } } + public override bool CanWrite { get { return false; } } + + public Lnk2Opener () + { + Extensions = new string[] { "dat" }; + } + + public override ArcFile TryOpen (ArcView file) + { + int count = file.View.ReadInt32 (4)*2; + if (!IsSaneCount (count)) + return null; + var dir = ReadIndex (file, 8, count); + if (null == dir) + return null; + return new ArcFile (file, this, dir); + } + } +} diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index fc2d457f..cf3e8ab6 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -81,6 +81,7 @@ + @@ -506,7 +507,7 @@ - + @@ -1003,7 +1004,9 @@ - + + + perl "$(SolutionDir)inc-revision.pl" "$(ProjectPath)" $(ConfigurationName)