|
| 1 | +//! \file ArcDM.cs |
| 2 | +//! \date 2023 Oct 24 |
| 3 | +//! \brief D-Motion engine resource archive. |
| 4 | +// |
| 5 | +// Copyright (C) 2023 by morkt |
| 6 | +// |
| 7 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +// of this software and associated documentation files (the "Software"), to |
| 9 | +// deal in the Software without restriction, including without limitation the |
| 10 | +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 11 | +// sell copies of the Software, and to permit persons to whom the Software is |
| 12 | +// furnished to do so, subject to the following conditions: |
| 13 | +// |
| 14 | +// The above copyright notice and this permission notice shall be included in |
| 15 | +// all copies or substantial portions of the Software. |
| 16 | +// |
| 17 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 23 | +// IN THE SOFTWARE. |
| 24 | +// |
| 25 | + |
| 26 | +using System.Collections.Generic; |
| 27 | +using System.ComponentModel.Composition; |
| 28 | + |
| 29 | +namespace GameRes.Formats.DMotion |
| 30 | +{ |
| 31 | + internal class ExtEntry : Entry |
| 32 | + { |
| 33 | + public int Count; |
| 34 | + } |
| 35 | + |
| 36 | + [Export(typeof(ArchiveFormat))] |
| 37 | + public class PakOpener : ArchiveFormat |
| 38 | + { |
| 39 | + public override string Tag => "256/DMOTION"; |
| 40 | + public override string Description => "D-Motion engine resource archive"; |
| 41 | + public override uint Signature => 0x4B434150; // 'PACK' |
| 42 | + public override bool IsHierarchic => false; |
| 43 | + public override bool CanWrite => false; |
| 44 | + |
| 45 | + public override ArcFile TryOpen (ArcView file) |
| 46 | + { |
| 47 | + if (!file.View.AsciiEqual (4, "FILE100DATA")) |
| 48 | + return null; |
| 49 | + if (!file.View.AsciiEqual (0x10, @".\\\")) |
| 50 | + return null; |
| 51 | + int ext_count = file.View.ReadUInt16 (0x16); |
| 52 | + long index_pos = file.View.ReadUInt32 (0x18); |
| 53 | + int total_count = 0; |
| 54 | + var ext_dir = new List<ExtEntry> (ext_count); |
| 55 | + for (int i = 0; i < ext_count; ++i) |
| 56 | + { |
| 57 | + var ext = new ExtEntry { |
| 58 | + Name = file.View.ReadString (index_pos, 4), |
| 59 | + Count = file.View.ReadUInt16 (index_pos+6), |
| 60 | + Offset = file.View.ReadUInt32 (index_pos+8), |
| 61 | + Size = file.View.ReadUInt32 (index_pos+12), |
| 62 | + }; |
| 63 | + ext_dir.Add (ext); |
| 64 | + total_count += ext.Count; |
| 65 | + index_pos += 0x10; |
| 66 | + } |
| 67 | + if (!IsSaneCount (total_count)) |
| 68 | + return null; |
| 69 | + |
| 70 | + var dir = new List<Entry> (total_count); |
| 71 | + foreach (var ext in ext_dir) |
| 72 | + { |
| 73 | + index_pos = ext.Offset; |
| 74 | + for (int i = 0; i < ext.Count; ++i) |
| 75 | + { |
| 76 | + var name = file.View.ReadString (index_pos, 8).TrimEnd() + ext.Name; |
| 77 | + var entry = Create<Entry> (name); |
| 78 | + entry.Offset = file.View.ReadUInt32 (index_pos+8); |
| 79 | + entry.Size = file.View.ReadUInt32 (index_pos+12); |
| 80 | + if (!entry.CheckPlacement (file.MaxOffset)) |
| 81 | + return null; |
| 82 | + dir.Add (entry); |
| 83 | + index_pos += 0x10; |
| 84 | + } |
| 85 | + } |
| 86 | + return new ArcFile (file, this, dir); |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments