From c346681e49a58ed4942c86b5f7621180cf410ddb Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 11 Nov 2016 17:30:49 +0400 Subject: [PATCH] implemented YaneSDK archives. --- ArcFormats/ArcFormats.csproj | 1 + ArcFormats/YaneSDK/ArcDAT.cs | 92 ++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 ArcFormats/YaneSDK/ArcDAT.cs diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 9a5e8763..f08d931c 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -457,6 +457,7 @@ + diff --git a/ArcFormats/YaneSDK/ArcDAT.cs b/ArcFormats/YaneSDK/ArcDAT.cs new file mode 100644 index 00000000..4140dabe --- /dev/null +++ b/ArcFormats/YaneSDK/ArcDAT.cs @@ -0,0 +1,92 @@ +//! \file ArcDAT.cs +//! \date Thu Nov 10 14:53:03 2016 +//! \brief YaneSDK 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.Utility; + +namespace GameRes.Formats.YaneSDK +{ + internal class YaneEntry : Entry + { + public uint EncryptedSize; + } + + [Export(typeof(ArchiveFormat))] + public class PakOpener : ArchiveFormat + { + public override string Tag { get { return "DAT/YaneSDK"; } } + public override string Description { get { return "YaneSDK engine resource archive"; } } + public override uint Signature { get { return 0; } } + public override bool IsHierarchic { get { return false; } } + public override bool CanWrite { get { return false; } } + + public override ArcFile TryOpen (ArcView file) + { + int count = (short)(file.View.ReadUInt16 (0) ^ 0x8080); + if (!IsSaneCount (count)) + return null; + + using (var input = file.CreateStream()) + using (var dec = new XoredStream (input, 0x80)) + using (var index = new BinaryReader (dec)) + { + index.BaseStream.Position = 2; + var name_buf = new byte[0x22]; + var dir = new List (count); + for (int i = 0; i < count; ++i) + { + if (0x22 != index.Read (name_buf, 0, 0x22)) + return null; + var name = Binary.GetCString (name_buf, 0); + var entry = FormatCatalog.Instance.Create (name); + entry.EncryptedSize = index.ReadUInt16(); + entry.Size = index.ReadUInt32(); + entry.Offset = 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) + { + var yent = entry as YaneEntry; + if (null == yent || 0 == yent.EncryptedSize) + return base.OpenEntry (arc, entry); + var header = arc.File.View.ReadBytes (yent.Offset, yent.EncryptedSize); + for (int i = 0; i < header.Length; ++i) + header[i] ^= 0x80; + if (yent.EncryptedSize >= yent.Size) + return new BinMemoryStream (header); + var rest = arc.File.CreateStream (yent.Offset + yent.EncryptedSize, yent.Size - yent.EncryptedSize); + return new PrefixStream (header, rest); + } + } +}