implemented Ail 'LNK2' archives.

This commit is contained in:
morkt 2018-01-04 20:43:30 +04:00
parent babe2d93d7
commit d87ac53f9b
3 changed files with 96 additions and 23 deletions

View File

@ -49,16 +49,37 @@ namespace GameRes.Formats.Ail
int count = file.View.ReadInt32 (0); int count = file.View.ReadInt32 (0);
if (!IsSaneCount (count)) if (!IsSaneCount (count))
return null; 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<Entry> 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) if (offset >= file.MaxOffset)
return null; return null;
var base_name = Path.GetFileNameWithoutExtension (file.Name); var dir = new List<Entry> (count/2);
uint index_offset = 4;
var dir = new List<Entry>();
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
uint size = file.View.ReadUInt32 (index_offset); uint size = file.View.ReadUInt32 (index_offset);
if (0 != size) if (size != 0 && size != uint.MaxValue)
{ {
var entry = new PackedEntry var entry = new PackedEntry
{ {
@ -74,8 +95,14 @@ namespace GameRes.Formats.Ail
} }
index_offset += 4; index_offset += 4;
} }
if (offset != file.MaxOffset || 0 == dir.Count) if (0 == dir.Count)
return null; return null;
DetectFileTypes (file, dir);
return dir;
}
internal void DetectFileTypes (ArcView file, List<Entry> dir)
{
byte[] preview = new byte[16]; byte[] preview = new byte[16];
byte[] sign_buf = new byte[4]; byte[] sign_buf = new byte[4];
foreach (PackedEntry entry in dir) foreach (PackedEntry entry in dir)
@ -111,21 +138,6 @@ namespace GameRes.Formats.Ail
if (0 != signature) if (0 != signature)
SetEntryType (entry, 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) static void SetEntryType (Entry entry, uint signature)

58
ArcFormats/Ail/ArcLNK2.cs Normal file
View File

@ -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);
}
}
}

View File

@ -81,6 +81,7 @@
<Compile Include="Actgs\ArcDAT.cs" /> <Compile Include="Actgs\ArcDAT.cs" />
<Compile Include="AdvSys\ArcAdvSys3.cs" /> <Compile Include="AdvSys\ArcAdvSys3.cs" />
<Compile Include="AdvSys\ImageGWD.cs" /> <Compile Include="AdvSys\ImageGWD.cs" />
<Compile Include="Ail\ArcLNK2.cs" />
<Compile Include="AliceSoft\ArcAAR.cs" /> <Compile Include="AliceSoft\ArcAAR.cs" />
<Compile Include="AliceSoft\ArcAFA.cs" /> <Compile Include="AliceSoft\ArcAFA.cs" />
<Compile Include="AliceSoft\ArcALK.cs" /> <Compile Include="AliceSoft\ArcALK.cs" />
@ -506,7 +507,7 @@
<Compile Include="AdvSys\ArcAdvSysT.cs" /> <Compile Include="AdvSys\ArcAdvSysT.cs" />
<Compile Include="Cri\ArcAFS.cs" /> <Compile Include="Cri\ArcAFS.cs" />
<Compile Include="elf\ArcAi5Win.cs" /> <Compile Include="elf\ArcAi5Win.cs" />
<Compile Include="ArcAil.cs" /> <Compile Include="Ail\ArcAil.cs" />
<Compile Include="AliceSoft\ArcALD.cs" /> <Compile Include="AliceSoft\ArcALD.cs" />
<Compile Include="Amaterasu\ArcAMI.cs" /> <Compile Include="Amaterasu\ArcAMI.cs" />
<Compile Include="Lilim\ArcAOS.cs" /> <Compile Include="Lilim\ArcAOS.cs" />
@ -1003,7 +1004,9 @@
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Strings\arcStrings.ru-RU.resx" /> <EmbeddedResource Include="Strings\arcStrings.ru-RU.resx" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<Folder Include="Bonk\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PreBuildEvent>perl "$(SolutionDir)inc-revision.pl" "$(ProjectPath)" $(ConfigurationName) <PreBuildEvent>perl "$(SolutionDir)inc-revision.pl" "$(ProjectPath)" $(ConfigurationName)