From 4ee3511075e5c2e6b1e9ef159ad992cb81451bd0 Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 20 Feb 2016 18:23:02 +0400 Subject: [PATCH] implemented ADVEngine 'arc' archives and GPS images. --- ArcFormats/Abel/ArcARC.cs | 116 +++++++++++++++++++++++++++++ ArcFormats/Abel/ImageGPS.cs | 137 +++++++++++++++++++++++++++++++++++ ArcFormats/ArcFormats.csproj | 4 + supported.html | 17 ++++- 4 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 ArcFormats/Abel/ArcARC.cs create mode 100644 ArcFormats/Abel/ImageGPS.cs diff --git a/ArcFormats/Abel/ArcARC.cs b/ArcFormats/Abel/ArcARC.cs new file mode 100644 index 00000000..a5cf89bd --- /dev/null +++ b/ArcFormats/Abel/ArcARC.cs @@ -0,0 +1,116 @@ +//! \file ArcARC.cs +//! \date Sat Feb 20 13:02:18 2016 +//! \brief Archive format used by Abel subsidiaries. +// +// Copyright (C) 2016 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 GameRes.Compression; +using GameRes.Utility; + +namespace GameRes.Formats.Abel +{ + [Export(typeof(ArchiveFormat))] + public class ArcOpener : ArchiveFormat + { + public override string Tag { get { return "ARC/ADVENGINE"; } } + public override string Description { get { return "ADVEngine resource archive"; } } + public override uint Signature { get { return 0x00637261; } } // 'arc' + public override bool IsHierarchic { get { return false; } } + public override bool CanCreate { get { return false; } } + + public ArcOpener () + { + Extensions = new string[] { "" }; + } + + const int IndexEntrySize = 0x26; + + public override ArcFile TryOpen (ArcView file) + { + int count = file.View.ReadInt32 (8); + if (!IsSaneCount (count)) + return null; + uint base_offset = file.View.ReadUInt32 (0xC); + if (base_offset <= 0x18 || base_offset >= file.MaxOffset) + return null; + uint packed_size = file.View.ReadUInt32 (0x10); + int index_size = file.View.ReadInt32 (0x14); + if (packed_size > file.MaxOffset || index_size / IndexEntrySize != count) + return null; + var name_buffer = new byte[30]; + using (var packed = file.CreateStream (0x18, packed_size)) + using (var lzss = new LzssStream (packed)) + using (var index = new ArcView.Reader (lzss)) + { + var dir = new List (count); + for (int i = 0; i < count; ++i) + { + if (name_buffer.Length != index.Read (name_buffer, 0, name_buffer.Length)) + return null; + var name = Binary.GetCString (name_buffer, 0, name_buffer.Length); + var entry = FormatCatalog.Instance.Create (name); + if (name.EndsWith (".acd", StringComparison.InvariantCultureIgnoreCase)) + entry.Type = "script"; + entry.Offset = index.ReadUInt32() + base_offset; + entry.Size = index.ReadUInt32(); + 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.Size > 12 && entry.Name.EndsWith (".cmp", StringComparison.InvariantCultureIgnoreCase) + && arc.File.View.AsciiEqual (entry.Offset, "CMP\0")) + return OpenCmpEntry (arc, entry); + if (entry.Size > 8 && entry.Name.EndsWith (".acd", StringComparison.InvariantCultureIgnoreCase) + && arc.File.View.AsciiEqual (entry.Offset, "ACD\0")) + return OpenAcdEntry (arc, entry); + return base.OpenEntry (arc, entry); + } + + Stream OpenAcdEntry (ArcFile arc, Entry entry) + { + var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); + for (int i = 8; i < data.Length; ++i) + { + data[i] = (byte)(0xFF - data[i]); + } + return new MemoryStream (data); + } + + Stream OpenCmpEntry (ArcFile arc, Entry entry) + { + uint offset = arc.File.View.ReadUInt32 (entry.Offset+8); + if (offset >= entry.Size) + return base.OpenEntry (arc, entry); + return arc.File.CreateStream (entry.Offset+offset, entry.Size-offset); + } + } +} diff --git a/ArcFormats/Abel/ImageGPS.cs b/ArcFormats/Abel/ImageGPS.cs new file mode 100644 index 00000000..890a02e3 --- /dev/null +++ b/ArcFormats/Abel/ImageGPS.cs @@ -0,0 +1,137 @@ +//! \file ImageGPS.cs +//! \date Sat Feb 20 14:13:10 2016 +//! \brief ADVEngine compressed bitmap. +// +// Copyright (C) 2016 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 GameRes.Compression; +using GameRes.Utility; + +namespace GameRes.Formats.Abel +{ + internal class GpsMetaData : ImageMetaData + { + public byte Compression; + public int PackedSize; + public int UnpackedSize; + } + + [Export(typeof(ImageFormat))] + public class GpsFormat : BmpFormat + { + public override string Tag { get { return "GPS"; } } + public override string Description { get { return "ADVEngine compressed bitmap"; } } + public override uint Signature { get { return 0x535047; } } // 'GPS' + + public GpsFormat () + { + Extensions = new string[] { "gps", "cmp" }; + } + + public override ImageMetaData ReadMetaData (Stream stream) + { + var header = new byte[0x29]; + if (header.Length != stream.Read (header, 0, header.Length)) + return null; + var gps = new GpsMetaData + { + Width = LittleEndian.ToUInt32 (header, 0x19), + Height = LittleEndian.ToUInt32 (header, 0x1D), + Compression = header[0x10], + UnpackedSize = LittleEndian.ToInt32 (header, 0x11), + PackedSize = LittleEndian.ToInt32 (header, 0x15), + }; + // read BMP header + using (var input = OpenGpsStream (stream, gps.Compression, 0x54)) + { + var bmp_info = base.ReadMetaData (input); + if (null == bmp_info) + return null; + gps.BPP = bmp_info.BPP; + return gps; + } + } + + public override ImageData Read (Stream stream, ImageMetaData info) + { + var gps = (GpsMetaData)info; + stream.Position = 0x29; + using (var input = OpenGpsStream (stream, gps.Compression, gps.UnpackedSize)) + return base.Read (input, info); + } + + public override void Write (Stream file, ImageData image) + { + throw new System.NotImplementedException ("GpsFormat.Write not implemented"); + } + + Stream OpenGpsStream (Stream input, byte compression, int unpacked_size) + { + if (0 == compression) + return new StreamRegion (input, 0x29, true); + else if (1 == compression) + return OpenRLEStream (input, unpacked_size); + else if (2 == compression) + return new LzssStream (input, LzssMode.Decompress, true); + else if (3 == compression) + { + using (var lzss = new LzssStream (input, LzssMode.Decompress, true)) + return OpenRLEStream (lzss, unpacked_size); + } + else + throw new InvalidFormatException(); + } + + Stream OpenRLEStream (Stream input, int output_size) + { + var output = new byte[output_size]; + UnpackRLE (input, output); + return new MemoryStream (output); + } + + void UnpackRLE (Stream input, byte[] output) + { + int dst = 0; + while (dst < output.Length) + { + int count = Math.Min (3, output.Length-dst); + count = input.Read (output, dst, count); + if (count < 3) + break; + count = input.ReadByte(); + if (-1 == count) + break; + dst += 3; + if (count > 1) + { + count = Math.Min ((count-1) * 3, output.Length-dst); + Binary.CopyOverlapped (output, dst-3, dst, count); + dst += count; + } + } + } + } +} diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 5b6c2b8a..85016654 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -62,8 +62,11 @@ + + + @@ -251,6 +254,7 @@ + diff --git a/supported.html b/supported.html index fd00b271..bf328867 100644 --- a/supported.html +++ b/supported.html @@ -81,6 +81,7 @@ Okaa-san ga Ippai!
*.pakHyPackYesKogadoSymphonic Rain *+*.lst-NoNexton LikeC +Injoku Shinryuu Club
Moon.
Ryoujoku Famiresu Choukyou Menu
Ryoujoku Idol Mesu Dorei
@@ -148,9 +149,13 @@ Kyrie ~Blood Royal 3~
Shiosai no Himei
*.gcpCMP1No -*.pdPackOnly
PackPlus
FlyingShinePDFileYesFlying ShineCross†Channel +*.pdPackOnly
PackPlus
FlyingShinePDFileYesFlying Shine +Akarui Mirai ~Wet And Messy 2nd time~
+Cross†Channel
+Crime Rhyme
+ *.rpaRPA-3.0YesRen'PyKatawa Shoujo -*.arc-YesWill +*.arc-YesWill Cynthia ~Sincerely to You~
Folklore Jam
I/O
@@ -163,6 +168,7 @@ Tsuma Youji 2
Yume Miru Kusuri
*.wip
*.msk
*.mosWIPFNo +*.pnaPNAPNo *.xflLBYesLiar-soft Angel Bullet
Fairytale Requiem
@@ -176,6 +182,7 @@ Altered Pink ~Tokumu Sentai Duel Ranger~
Aozora Gakko no Sensei-kun
Cafe Sourire
Coμ
+Crime Rhyme series
Damegane
Distance
Fate/stay night
@@ -186,6 +193,7 @@ Hanafubuki ~Sennen no Koi o Shimashita~
Haruiro ☆ Communication ♪
Hime to Majin to Koi Suru Tamashii
Imouto Style
+Inaho no Mirai
Mayoeru Futari to Sekai no Subete
Natsupochi
Nidaime wa ☆ Mahou Shoujo
@@ -337,6 +345,7 @@ Trouble @ Spiral!
*.epaEPNo *.arcMAINoMatsuri Kikaku Chikan Sharyou Nigousha
+Hime Musha
Warusa
*.ami
*.cmp
AM
CMNo @@ -684,6 +693,10 @@ Unity Marriage ~Futari no Hanayome~
*.npkNPK2NoNitro+ Tokyo Necro
+*arcNoADVEngine +Thanatos no Koi ~In Ane Otouto Soukan~
+ +*.gpsGPSNo

1 Non-encrypted only