|
| 1 | +//! \file ArcNAF.cs |
| 2 | +//! \date 2018 Apr 02 |
| 3 | +//! \brief Brownie resource archive. |
| 4 | +// |
| 5 | +// Copyright (C) 2018 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 | +using System.IO; |
| 29 | + |
| 30 | +namespace GameRes.Formats.Brownie |
| 31 | +{ |
| 32 | + [Export(typeof(ArchiveFormat))] |
| 33 | + public class NafOpener : ArchiveFormat |
| 34 | + { |
| 35 | + public override string Tag { get { return "NAF"; } } |
| 36 | + public override string Description { get { return "Brownie/NenGollo resource archive"; } } |
| 37 | + public override uint Signature { get { return 0x52422E31; } } // '1.BROWNIE/NenGollo' |
| 38 | + public override bool IsHierarchic { get { return false; } } |
| 39 | + public override bool CanWrite { get { return false; } } |
| 40 | + |
| 41 | + public override ArcFile TryOpen (ArcView file) |
| 42 | + { |
| 43 | + if (!file.View.AsciiEqual (0, "1.BROWNIE")) |
| 44 | + return null; |
| 45 | + int count = file.View.ReadInt32 (0x30); |
| 46 | + if (!IsSaneCount (count)) |
| 47 | + return null; |
| 48 | + |
| 49 | + uint index_offset = file.View.ReadUInt32 (0x34); |
| 50 | + var dir = new List<Entry> (count); |
| 51 | + for (int i = 0; i < count; ++i) |
| 52 | + { |
| 53 | + var name = file.View.ReadString (index_offset, 0x10); |
| 54 | + var ext = file.View.ReadString (index_offset+0x10, 4); |
| 55 | + name = Path.ChangeExtension (name, ext); |
| 56 | + var entry = FormatCatalog.Instance.Create<Entry> (name); |
| 57 | + entry.Offset = file.View.ReadUInt32 (index_offset+0x14); |
| 58 | + entry.Size = file.View.ReadUInt32 (index_offset+0x18); |
| 59 | + if (!entry.CheckPlacement (file.MaxOffset)) |
| 60 | + return null; |
| 61 | + dir.Add (entry); |
| 62 | + index_offset += 0x20; |
| 63 | + } |
| 64 | + return new ArcFile (file, this, dir); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments