From 5f1641243b5ffd003c43d00e66b4ef74d95cbe9f Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 21 May 2016 10:31:09 +0400 Subject: [PATCH] variation of Nitro+ PAK archives. --- ArcFormats/ArcFormats.csproj | 1 + ArcFormats/NitroPlus/ArcNitro.cs | 4 +- ArcFormats/NitroPlus/ArcPAK.cs | 112 +++++++++++++++++++++++++++++++ supported.html | 9 ++- 4 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 ArcFormats/NitroPlus/ArcPAK.cs diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index fc89c2a2..2d5c99e8 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -96,6 +96,7 @@ + diff --git a/ArcFormats/NitroPlus/ArcNitro.cs b/ArcFormats/NitroPlus/ArcNitro.cs index 8c0fadaa..2d28a072 100644 --- a/ArcFormats/NitroPlus/ArcNitro.cs +++ b/ArcFormats/NitroPlus/ArcNitro.cs @@ -84,7 +84,7 @@ namespace GameRes.Formats.NitroPlus return null; int unpacked_size = file.View.ReadInt32 (8); uint packed_size = file.View.ReadUInt32 (0xC); - var input = file.CreateStream (0x114, packed_size); + using (var input = file.CreateStream (0x114, packed_size)) using (var header_stream = new ZLibStream (input, CompressionMode.Decompress)) using (var header = new BinaryReader (header_stream, Encoding.ASCII, true)) { @@ -147,7 +147,7 @@ namespace GameRes.Formats.NitroPlus var dir = new List (count); uint header_size = file.View.ReadUInt32 (0x110) ^ size_xor; long base_offset = 0x114 + header_size; - var input = file.CreateStream (0x114, header_size); + using (var input = file.CreateStream (0x114, header_size)) using (var header_stream = new ZLibStream (input, CompressionMode.Decompress)) using (var header = new BinaryReader (header_stream, Encoding.ASCII, true)) { diff --git a/ArcFormats/NitroPlus/ArcPAK.cs b/ArcFormats/NitroPlus/ArcPAK.cs new file mode 100644 index 00000000..2a212512 --- /dev/null +++ b/ArcFormats/NitroPlus/ArcPAK.cs @@ -0,0 +1,112 @@ +//! \file ArcPAK.cs +//! \date Sat May 21 00:12:14 2016 +//! \brief MAGI resource archive. +// +// 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; + +namespace GameRes.Formats.Magi +{ + // this format is very similar to NitroPlus.PakOpener v3, but has no encryption. + // + [Export(typeof(ArchiveFormat))] + public class PakOpener : ArchiveFormat + { + public override string Tag { get { return "PAK/MAGI"; } } + public override string Description { get { return "MAGI resource archive"; } } + public override uint Signature { get { return 3; } } + public override bool IsHierarchic { get { return true; } } + public override bool CanCreate { get { return false; } } + + public override ArcFile TryOpen (ArcView file) + { + int count = file.View.ReadInt32 (4); + if (!IsSaneCount (count)) + return null; + uint index_size = file.View.ReadUInt32 (0xC); + if (index_size > file.MaxOffset) + return null; + + long base_offset = 0x118 + index_size; + + using (var mem = file.CreateStream (0x118, index_size)) + using (var z = new ZLibStream (mem, CompressionMode.Decompress)) + using (var index = new BinaryReader (z)) + { + var name_buffer = new byte[0x100]; + var dir = new List (count); + for (int i = 0; i < count; ++i) + { + int name_length = index.ReadInt32(); + if (name_length <= 0 || name_length > name_buffer.Length) + return null; + if (name_length != index.Read (name_buffer, 0, name_length)) + return null; + var name = Encodings.cp932.GetString (name_buffer, 0, name_length); + var entry = FormatCatalog.Instance.Create (name); + entry.Offset = index.ReadUInt32() + base_offset; + uint size = index.ReadUInt32(); + index.ReadUInt32(); + uint flags = index.ReadUInt32(); + uint packed_size = index.ReadUInt32(); + entry.IsPacked = flags != 0 && packed_size != 0; + if (entry.IsPacked) + { + entry.Size = packed_size; + entry.UnpackedSize = size; + } + else + { + entry.Size = size; + entry.UnpackedSize = size; + } + if (!entry.CheckPlacement (file.MaxOffset)) + return null; + dir.Add (entry); + } + 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; + try + { + return new ZLibStream (input, CompressionMode.Decompress); + } + catch + { + input.Dispose(); + throw; + } + } + } +} diff --git a/supported.html b/supported.html index 017bb0bf..0f9da2ce 100644 --- a/supported.html +++ b/supported.html @@ -144,10 +144,12 @@ Sweet Pool
Zoku Satsuriku no Django
*.npa-YesNitro+Steins;Gate -*.pak\002\000\000\000
\003\000\000\000NoNitro+
CoreMoreco +*.pak\002\000\000\000
\003\000\000\000NoNitro+
CoreMoreco
MAGI
Hanachirasu
Jingai Makyou
Chibi Mama
+Ore to Imouto no Kounai Play
+Ren'ai Jugyou ~Oshiego no Yuuwaku~
*.nsa
*.sar-Yes1NScripter Binary Pot
@@ -345,6 +347,7 @@ Zansho Omimai MoushiagemasuShiinaRio v2.41
*.ogvOGVNo *.padPADNo *ARC2
ARC1NoAST +Bokura wa Piacere
Jokyoushi wo Kurau
Lovers Collection
Nachtmusik
@@ -830,6 +833,10 @@ Nora to Oujo to Noraneko Heart
Tsujidou-san no Jun'ai Road
Tsujidou-san no Virgin Road
+*.pak-NoMAGI +Ore to Imouto no Kounai Play
+Ren'ai Jugyou ~Oshiego no Yuuwaku~
+

1 Non-encrypted only