From d1d9699db3c5e2465ddb2344224adaf9a398bb14 Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 5 Aug 2016 19:35:04 +0400 Subject: [PATCH] implemented TTD archives. --- ArcFormats/ArcFormats.csproj | 1 + ArcFormats/Morning/ArcTTD.cs | 92 ++++++++++++++++++++++++++++++++++++ supported.html | 7 +++ 3 files changed, 100 insertions(+) create mode 100644 ArcFormats/Morning/ArcTTD.cs diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 3b6d1997..8952e92f 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -149,6 +149,7 @@ + diff --git a/ArcFormats/Morning/ArcTTD.cs b/ArcFormats/Morning/ArcTTD.cs new file mode 100644 index 00000000..01745b9c --- /dev/null +++ b/ArcFormats/Morning/ArcTTD.cs @@ -0,0 +1,92 @@ +//! \file ArcTTD.cs +//! \date Fri Aug 05 16:59:47 2016 +//! \brief Morning resource archives. +// +// 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.Collections.Generic; +using System.ComponentModel.Composition; +using System.IO; +using GameRes.Compression; +using GameRes.Utility; + +namespace GameRes.Formats.Morning +{ + [Export(typeof(ArchiveFormat))] + public class TtdOpener : ArchiveFormat + { + public override string Tag { get { return "TTD"; } } + public override string Description { get { return "Morning resource archive"; } } + public override uint Signature { get { return 0x4352462E; } } // '.FRC' + public override bool IsHierarchic { get { return false; } } + public override bool CanCreate { get { return false; } } + + public override ArcFile TryOpen (ArcView file) + { + int count = file.View.ReadInt32 (0xC); + if (!IsSaneCount (count)) + return null; + uint key = file.View.ReadUInt32 (4); + int index_size = count * 0x2C; + var index = file.View.ReadBytes (0x14, (uint)index_size); + if (index.Length != index_size) + return null; + Decrypt (index, key); + int index_offset = 0; + var dir = new List (count); + for (int i = 0; i < count; ++i) + { + var name = Binary.GetCString (index, index_offset+12, 0x20); + if (string.IsNullOrWhiteSpace (name)) + return null; + var entry = FormatCatalog.Instance.Create (name); + entry.Size = LittleEndian.ToUInt32 (index, index_offset); + entry.Offset = LittleEndian.ToUInt32 (index, index_offset+4); + if (!entry.CheckPlacement (file.MaxOffset)) + return null; + dir.Add (entry); + index_offset += 0x2C; + } + return new ArcFile (file, this, dir); + } + + public override Stream OpenEntry (ArcFile arc, Entry entry) + { + if (entry.Size <= 8 || !arc.File.View.AsciiEqual (entry.Offset, "DSFF")) + return base.OpenEntry (arc, entry); + var input = arc.File.CreateStream (entry.Offset+8, entry.Size-8); + var lzss = new LzssStream (input); + lzss.Config.FrameInitPos = 0xFF0; + return lzss; + } + + unsafe void Decrypt (byte[] data, uint key) + { + fixed (byte* data8 = data) + { + uint* data32 = (uint*)data8; + for (int length = data.Length / 4; length > 0; --length) + *data32++ ^= key; + } + } + } +} diff --git a/supported.html b/supported.html index d2a3b226..fd153205 100644 --- a/supported.html +++ b/supported.html @@ -254,6 +254,7 @@ Okiba ga Nai!
Oku-sama wa Moto Yariman
Omana 2: Omaenchi Moeteruzo
Ore no Saimin Fantasia
+Ouka Ryouran
RGH ~Koi to Hero to Gakuen to~
Riding Incubus
Seirei Tenshou
@@ -294,6 +295,7 @@ Assault Angel Canon
Chikatetsu Fuusa Jiken
Eien no Owari ni
Fuurinkanzan
+Gedou Yuusha
Himemiko
Ikusa Otome Valkyrie
Mahou Tenshi Misaki
@@ -613,6 +615,7 @@ Shinsetsu Ryouki no Ori
Gokudou no Hanayome
Inraku no Miko
Knight Carnival!
+Maou no Kuse ni Namaiki da! Torotoro Tropical!
Nise Kyoushi ~Seikatsu Shidou ADV~
Seal Princess
Zettai★Maou ~Boku no Mune-kyun Gakuen Saga~
@@ -726,6 +729,7 @@ Shukufuku no Kane no Oto wa, Sakurairo no Kaze to Tomo ni
*.bsaBSArcNoBishop Houkago ~Nureta Seifuku~
Kyouiku Shidou
+Sansha Mendan ~Rensa Suru Chijoku Choukyou no Gakuen~
Yakata ~Kannou Kitan~
*.bsgBSS-Graphics
BSS-CompositionNo @@ -1015,6 +1019,9 @@ Elevator Panic ~Misshitsu no Inkou~
*.datMK2.0NoMAIKA Uchuu Keiji Soldivan
+*.ttd.FRCNoMorning +Binkan Ecchi! ~Futari no Oyatsu wa Tokunou Milk~
+

1 Non-encrypted only