diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index eb2173d3..42d64a11 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -75,6 +75,7 @@ + diff --git a/ArcFormats/Escude/ArcBIN.cs b/ArcFormats/Escude/ArcBIN.cs new file mode 100644 index 00000000..b65da9f5 --- /dev/null +++ b/ArcFormats/Escude/ArcBIN.cs @@ -0,0 +1,145 @@ +//! \file ArcBIN.cs +//! \date Sat Dec 19 06:16:35 2015 +//! \brief Escu:de resource archives. +// +// 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.Collections.Generic; +using System.ComponentModel.Composition; +using GameRes.Utility; + +namespace GameRes.Formats.Escude +{ + [Export(typeof(ArchiveFormat))] + public class BinOpener : FVP.BinOpener + { + public override string Tag { get { return "BIN/ESC-ARC"; } } + public override string Description { get { return "Escu:de resource archive"; } } + public override uint Signature { get { return 0x2D435345; } } // 'ESC-' + public override bool IsHierarchic { get { return true; } } + public override bool CanCreate { get { return false; } } + + public override ArcFile TryOpen (ArcView file) + { + if (!file.View.AsciiEqual (4, "ARC")) + return null; + int version = file.View.ReadByte (7) - '0'; + var reader = new IndexReader (file); + List dir = null; + if (1 == version) + dir = reader.ReadIndexV1(); + else if (2 == version) + dir = reader.ReadIndexV2(); + if (null == dir) + return null; + return new ArcFile (file, this, dir); + } + } + + internal sealed class IndexReader + { + ArcView m_file; + uint m_seed; + uint m_count; + + public IndexReader (ArcView file) + { + m_file = file; + m_seed = m_file.View.ReadUInt32 (8); + m_count = file.View.ReadUInt32 (0xC) ^ NextKey(); + } + + public List ReadIndexV1 () + { + if (!ArchiveFormat.IsSaneCount ((int)m_count)) + return null; + uint index_size = m_count * 0x88; + var index = m_file.View.ReadBytes (0x10, index_size); + if (index.Length != index_size) + return null; + Decrypt (index); + int index_offset = 0; + var dir = new List ((int)m_count); + for (uint i = 0; i < m_count; ++i) + { + var name = Binary.GetCString (index, index_offset, 0x80); + var entry = FormatCatalog.Instance.Create (name); + entry.Offset = LittleEndian.ToUInt32 (index, index_offset+0x80); + entry.Size = LittleEndian.ToUInt32 (index, index_offset+0x84); + if (!entry.CheckPlacement (m_file.MaxOffset)) + return null; + index_offset += 0x88; + dir.Add (entry); + } + return dir; + } + + public List ReadIndexV2 () + { + if (!ArchiveFormat.IsSaneCount ((int)m_count)) + return null; + + uint names_size = m_file.View.ReadUInt32 (0x10) ^ NextKey(); + uint index_size = m_count * 12; + var index = m_file.View.ReadBytes (0x14, index_size); + if (index.Length != index_size) + return null; + Decrypt (index); + int index_offset = 0; + uint filenames_base = 0x14 + index_size; + var dir = new List ((int)m_count); + for (uint i = 0; i < m_count; ++i) + { + uint filename_offset = LittleEndian.ToUInt32 (index, index_offset); + var name = m_file.View.ReadString (filenames_base+filename_offset, names_size-filename_offset); + var entry = FormatCatalog.Instance.Create (name); + entry.Offset = LittleEndian.ToUInt32 (index, index_offset+4); + entry.Size = LittleEndian.ToUInt32 (index, index_offset+8); + if (!entry.CheckPlacement (m_file.MaxOffset)) + return null; + index_offset += 12; + dir.Add (entry); + } + return dir; + } + + unsafe void Decrypt (byte[] data) + { + fixed (byte* raw = data) + { + uint* data32 = (uint*)raw; + for (int i = data.Length/4; i > 0; --i) + { + *data32++ ^= NextKey(); + } + } + } + + uint NextKey () + { + m_seed ^= 0x65AC9365; + m_seed ^= (((m_seed >> 1) ^ m_seed) >> 3) + ^ (((m_seed << 1) ^ m_seed) << 3); + return m_seed; + } + } +} diff --git a/supported.html b/supported.html index 18b6a719..d8899fd9 100644 --- a/supported.html +++ b/supported.html @@ -36,6 +36,7 @@ Kana ~Imouto~
Kohitsuji-tachi no Rakuen
Make Love Junkies
Natsu no Hitoshizuku
+Onedari Milky Pai
Private Nurse
Sensei 2
Shoujo Settai
@@ -272,6 +273,8 @@ Zansho Omimai MoushiagemasuShiinaRio v2.41
*.padPADNo *ARC2
ARC1NoAST Jokyoushi wo Kurau
+Nachtmusik
+Nachtmusik Another
Time Trouble ~Marie ni Kubikkake~
*.dat-NoAil @@ -385,6 +388,7 @@ Kimi no Koe ga Kikoeru
Kimi no Omoi, Sono Negai
Samurai Jupiter
Sora no Iro, Mizu no Iro
+Thunder Claps!
*.iksNPSRNoX[iks]Shikkan ~Hazukashimerareta Karada, Oreta Kokoro~ *.wbpARCFORM3 WBUGNoWild Bug @@ -565,6 +569,10 @@ Hitozuma Net Auction
AstralAir no Shiroki Towa
*.hzchzc1No +*.binESC-ARC1
ESC-ARC2NoEscu:de +Otome Renshin Prister
+Wondering Repair!
+

1 Non-encrypted only