From 43406ffd66f300c20224e0e8248398f13e1cdbc0 Mon Sep 17 00:00:00 2001 From: morkt Date: Tue, 4 Aug 2015 22:30:36 +0400 Subject: [PATCH] implemented AOS resource archives. --- ArcFormats/ArcAOS.cs | 109 +++++++++++++++++++++++++++++++++++ ArcFormats/ArcFormats.csproj | 3 + supported.html | 4 ++ 3 files changed, 116 insertions(+) create mode 100644 ArcFormats/ArcAOS.cs diff --git a/ArcFormats/ArcAOS.cs b/ArcFormats/ArcAOS.cs new file mode 100644 index 00000000..0877fe76 --- /dev/null +++ b/ArcFormats/ArcAOS.cs @@ -0,0 +1,109 @@ +//! \file ArcAOS.cs +//! \date Tue Aug 04 06:00:39 2015 +//! \brief LiLiM resource archive implementation. +// +// Copyright (C) 2015 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; +using System.Linq; +using GameRes.Utility; + +namespace GameRes.Formats.Lilim +{ + [Export(typeof(ArchiveFormat))] + public class AosOpener : ArchiveFormat + { + public override string Tag { get { return "AOS"; } } + public override string Description { get { return "LiLiM/Le.Chocolat engine resource archive"; } } + public override uint Signature { get { return 0; } } + public override bool IsHierarchic { get { return false; } } + public override bool CanCreate { get { return false; } } + + static readonly byte[] IndexLink = Enumerable.Repeat (0xff, 0x10).ToArray(); + static readonly byte[] IndexEnd = Enumerable.Repeat (0, 0x10).ToArray(); + + public override ArcFile TryOpen (ArcView file) + { + if (0 == file.View.ReadByte (0)) + return null; + uint first_offset = file.View.ReadUInt32 (0x10); + if (first_offset >= file.MaxOffset || 0 != (first_offset & 0x1F)) + return null; + var name_buf = new byte[0x10]; + if (0x10 != file.View.Read (first_offset, name_buf, 0, 0x10)) + return null; + if (!name_buf.SequenceEqual (IndexLink) && !name_buf.SequenceEqual (IndexEnd)) + return null; + + uint current_offset = 0; + var dir = new List (0x3E); + for (;;) + { + if (0x10 != file.View.Read (current_offset, name_buf, 0, 0x10)) + break; + if (name_buf.SequenceEqual (IndexLink)) + { + uint next_offset = file.View.ReadUInt32 (current_offset+0x10); + current_offset += 0x20 + next_offset; + if (current_offset >= file.MaxOffset) + break; + } + else + { + int name_length = Array.IndexOf (name_buf, 0); + if (0 == name_length) + break; + if (-1 == name_length) + name_length = name_buf.Length; + var name = Encodings.cp932.GetString (name_buf, 0, name_length); + var entry = FormatCatalog.Instance.CreateEntry (name); + entry.Offset = file.View.ReadUInt32 (current_offset+0x10); + entry.Size = file.View.ReadUInt32 (current_offset+0x14); + current_offset += 0x20; + entry.Offset += current_offset; + if (!entry.CheckPlacement (file.MaxOffset)) + return null; + dir.Add (entry); + } + } + return new ArcFile (file, this, dir); + } + + public override Stream OpenEntry (ArcFile arc, Entry entry) + { + if (!entry.Name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) + return arc.File.CreateStream (entry.Offset, entry.Size); + + uint unpacked_size = arc.File.View.ReadUInt32 (entry.Offset); + var packed = new byte[entry.Size-4]; + arc.File.View.Read (entry.Offset+4, packed, 0, (uint)packed.Length); + var unpacked = new byte[unpacked_size]; + + var decoder = new HuffmanDecoder (packed, unpacked); + decoder.Unpack(); + return new MemoryStream (unpacked); + } + } +} diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 6fe9a7a5..d9231069 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -69,6 +69,7 @@ + @@ -126,8 +127,10 @@ + + diff --git a/supported.html b/supported.html index ca0272f6..a98af289 100644 --- a/supported.html +++ b/supported.html @@ -204,6 +204,7 @@ Rikorisu ~Lycoris Radiata~
*.pmp
*.pmw-YesScenePlayerNyuujoku Hitozuma Jogakuen *.datGAMEDAT PACK
GAMEDAT PAC2No bootUP!
Pajamas Soft Aneimo 2 ~Second Stage~
+Momichupa Teacher!
Natsu no Owari no Nirvana
Prism Heart
@@ -297,6 +298,9 @@ Yami no Koe Zero
*.dwqBMP
JPEG
PNG
JPEG+MASK
PACKBMP+MASK
No *.vaw
*.wgqIF PACKTYPE==
OGGNo +*.aos-NoLiLiM +Answer Dead
+

1 Non-encrypted only