From 23e5856825da59a803196b84fcf799184a836ec7 Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 13 Feb 2016 17:37:32 +0400 Subject: [PATCH] implemented variations of PAC archives and PGD images. --- ArcFormats/ArcFormats.csproj | 3 + ArcFormats/Softpal/ArcPAC.cs | 138 +++++++++++++++++++++++++++++++++ ArcFormats/Softpal/AudioBGM.cs | 57 ++++++++++++++ ArcFormats/Softpal/ImagePGD.cs | 124 +++++++++++++++++++++++++++++ supported.html | 8 +- 5 files changed, 328 insertions(+), 2 deletions(-) create mode 100644 ArcFormats/Softpal/ArcPAC.cs create mode 100644 ArcFormats/Softpal/AudioBGM.cs create mode 100644 ArcFormats/Softpal/ImagePGD.cs diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 6559c859..78fdde98 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -63,6 +63,9 @@ + + + diff --git a/ArcFormats/Softpal/ArcPAC.cs b/ArcFormats/Softpal/ArcPAC.cs new file mode 100644 index 00000000..1a575bb9 --- /dev/null +++ b/ArcFormats/Softpal/ArcPAC.cs @@ -0,0 +1,138 @@ +//! \file ArcPAC.cs +//! \date Sat Feb 13 12:42:15 2016 +//! \brief Archive format used by subsidiaries of Amuse Craft (former Softpal). +// +// 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.Utility; + +namespace GameRes.Formats.Softpal +{ + [Export(typeof(ArchiveFormat))] + public class PacOpener : ArchiveFormat + { + public override string Tag { get { return "PAC/SOFTPAL"; } } + public override string Description { get { return "Archive format used by Softpal subsidiaries"; } } + public override uint Signature { get { return 0; } } + public override bool IsHierarchic { get { return false; } } + public override bool CanCreate { get { return false; } } + + public PacOpener () + { + Extensions = new string[] { "pac" }; + } + + public override ArcFile TryOpen (ArcView file) + { + int count = file.View.ReadInt32 (0); + if (!IsSaneCount (count)) + return null; + + uint index_offset = 0x3FE; + uint name_length = 0x20; + uint first_offset = file.View.ReadUInt32 (index_offset+name_length+4); + if (first_offset != index_offset + (uint)count*(name_length+8)) + { + name_length = 0x10; + first_offset = file.View.ReadUInt32 (index_offset+name_length+4); + if (first_offset != index_offset + (uint)count*(name_length+8)) + return null; + } + if (first_offset >= file.MaxOffset) + return null; + return ReadIndex (file, count, index_offset, name_length); + } + + protected ArcFile ReadIndex (ArcView file, int count, uint index_offset, uint name_length) + { + var dir = new List (count); + for (int i = 0; i < count; ++i) + { + var name = file.View.ReadString (index_offset, name_length); + index_offset += name_length; + var entry = FormatCatalog.Instance.Create (name); + entry.Size = file.View.ReadUInt32 (index_offset); + entry.Offset = file.View.ReadUInt32 (index_offset+4); + if (!entry.CheckPlacement (file.MaxOffset)) + return null; + dir.Add (entry); + index_offset += 8; + } + return new ArcFile (file, this, dir); + } + + public override Stream OpenEntry (ArcFile arc, Entry entry) + { + if ("image" == entry.Type || "audio" == entry.Type || entry.Size <= 16 + || '$' != arc.File.View.ReadByte (entry.Offset)) + return base.OpenEntry (arc, entry); + var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); + int count = (data.Length - 16) / 4; + if (count > 0) + { + unsafe + { + fixed (byte* data8 = &data[16]) + { + uint* data32 = (uint*)data8; + int shift = 4; + for (uint* data_end = data32 + count; data32 != data_end; ++data32) + { + byte* byte_ptr = (byte*)data32; + *byte_ptr = Binary.RotByteL (*byte_ptr, shift++); + *data32 ^= 0x084DF873u ^ 0xFF987DEEu; + } + } + } + } + return new MemoryStream (data); + } + } + + [Export(typeof(ArchiveFormat))] + public class Pac2Opener : PacOpener + { + public override string Tag { get { return "PAC/AMUSE"; } } + public override string Description { get { return "Archive format used by Amuse Craft subsidiaries"; } } + public override uint Signature { get { return 0x20434150; } } // 'PAC ' + 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 (8); + if (!IsSaneCount (count)) + return null; + + uint index_offset = 0x804; + uint name_length = 0x20; + uint first_offset = file.View.ReadUInt32 (index_offset+name_length+4); + if (first_offset != index_offset + (uint)count*(name_length+8)) + return null; + + return ReadIndex (file, count, index_offset, name_length); + } + } +} diff --git a/ArcFormats/Softpal/AudioBGM.cs b/ArcFormats/Softpal/AudioBGM.cs new file mode 100644 index 00000000..0b73772e --- /dev/null +++ b/ArcFormats/Softpal/AudioBGM.cs @@ -0,0 +1,57 @@ +//! \file AudioBGM.cs +//! \date Sat Feb 13 12:57:50 2016 +//! \brief Audio container used in Softpal PAC 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.Utility; + +namespace GameRes.Formats.Softpal +{ + [Export(typeof(AudioFormat))] + public class BgmAudio : OggAudio + { + public override string Tag { get { return "BGM/SOFTPAL"; } } + public override string Description { get { return "Softpal BGM format (Ogg/Vorbis)"; } } + public override uint Signature { get { return 0x204D4742; } } // 'BGM ' + + public BgmAudio () + { + Extensions = new string[] { "ogg" }; + } + + public override SoundInput TryOpen (Stream file) + { + var header = new byte[0x10]; // header contains music loop timing + if (0x10 != file.Read (header, 0, 0x10)) + return null; + if (!Binary.AsciiEqual (header, 0xC, "OggS")) + return null; + var input = new StreamRegion (file, 12); + return new OggInput (input); + // input is [intentionally] left undisposed in case of exception. + } + } +} diff --git a/ArcFormats/Softpal/ImagePGD.cs b/ArcFormats/Softpal/ImagePGD.cs new file mode 100644 index 00000000..412761b9 --- /dev/null +++ b/ArcFormats/Softpal/ImagePGD.cs @@ -0,0 +1,124 @@ +//! \file ImagePGD.cs +//! \date Sat Feb 13 13:56:06 2016 +//! \brief Image format used by subsidiaries of Amuse Craft (former Softpal). +// +// 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.ComponentModel.Composition; +using System.IO; +using System.Windows.Media; +using GameRes.Utility; + +namespace GameRes.Formats.Softpal +{ + [Export(typeof(ImageFormat))] + public class Pgd11Format : ImageFormat + { + public override string Tag { get { return "PGD/11_C"; } } + public override string Description { get { return "Image format used by Softpal subsidiaries"; } } + public override uint Signature { get { return 0x1C4547; } } // 'GE\x1C' + + public Pgd11Format () + { + Extensions = new string[] { "pgd" }; + } + + public override ImageMetaData ReadMetaData (Stream stream) + { + var header = new byte[0x20]; + if (header.Length != stream.Read (header, 0, header.Length)) + return null; + if (!Binary.AsciiEqual (header, 0x1C, "11_C")) + return null; + return new ImageMetaData + { + Width = LittleEndian.ToUInt32 (header, 0x0C), + Height = LittleEndian.ToUInt32 (header, 0x10), + OffsetX = LittleEndian.ToInt32 (header, 4), + OffsetY = LittleEndian.ToInt32 (header, 8), + BPP = 32, + }; + } + + public override ImageData Read (Stream stream, ImageMetaData info) + { + stream.Position = 0x20; + using (var reader = new ArcView.Reader (stream)) + { + int unpacked_size = reader.ReadInt32(); + reader.ReadInt32(); // packed_size + var planes = Unpack (reader, unpacked_size); + var pixels = new byte[planes.Length]; + int plane_size = (int)info.Width*(int)info.Height; + int b_src = 0; + int g_src = b_src+plane_size; + int r_src = g_src+plane_size; + int alpha_src = r_src+plane_size; + int dst = 0; + while (dst < pixels.Length) + { + pixels[dst++] = planes[b_src++]; + pixels[dst++] = planes[g_src++]; + pixels[dst++] = planes[r_src++]; + pixels[dst++] = planes[alpha_src++]; + } + return ImageData.Create (info, PixelFormats.Bgra32, null, pixels); + } + } + + byte[] Unpack (BinaryReader input, int unpacked_size) + { + var output = new byte[unpacked_size]; + int dst = 0; + int ctl = 2; + while (dst < output.Length) + { + ctl >>= 1; + if (1 == ctl) + { + ctl = input.ReadByte() | 0x100; + } + int count; + if (0 != (ctl & 1)) + { + int src = input.ReadUInt16(); + count = input.ReadByte(); + if (dst >= 0xFFC) + src += dst - 0xFFC; + Binary.CopyOverlapped (output, src, dst, count); + } + else + { + count = input.ReadByte(); + input.Read (output, dst, count); + } + dst += count; + } + return output; + } + + public override void Write (Stream file, ImageData image) + { + throw new System.NotImplementedException ("Pgd11Format.Write not implemented"); + } + } +} diff --git a/supported.html b/supported.html index a956fd01..9c98cac4 100644 --- a/supported.html +++ b/supported.html @@ -490,14 +490,14 @@ Answer Dead
Kango Sentai Nurse Ranger
*.abmBMNo -*.arc
*.xarc
*.bin
*.004MIKO
KOTORI
XARCNoXuse
ETERNAL +*.arc
*.xarc
*.binMIKO
KOTORI
XARCNoXuse
ETERNAL Barbaroi
Kikouyoku Senki Gin no Toki no Corona
Kikouyoku Senki Tenkuu no Yumina
Nega0
Seinarukana -The Spirit of Eternity Sword 2-
-*.wag
*.4agWAG@
GAF4No +*.wag
*.4ag
*.004WAG@
GAF4No *.ykcYKC001YesYuka Aozora no Mieru Oka
PriministAr
@@ -673,6 +673,10 @@ Komokyun!! ~Heart ni Yureru Tamashi no Fandisc~
*NNNNNoMoko Pro Houmon Hanbai ~Otona no Omocha Irimasen ka?~
+*.pac-
PACNoUnison Shift +Unity Marriage ~Futari no Hanayome~
+ +*.pgdGENo

1 Non-encrypted only