Skip to content

Commit 17b89fc

Browse files
committed
(Legacy): implemented 'Brownie' resources.
1 parent 6182cad commit 17b89fc

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

Legacy/Brownie/ArcNAF.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
}

Legacy/Brownie/AudioWAV.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//! \file AudioWAV.cs
2+
//! \date 2018 Apr 02
3+
//! \brief Brownie obfuscated WAV file.
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.ComponentModel.Composition;
27+
using System.IO;
28+
29+
namespace GameRes.Formats.Brownie
30+
{
31+
[Export(typeof(AudioFormat))]
32+
public class WavAudio : AudioFormat
33+
{
34+
public override string Tag { get { return "WAV/BROWNIE"; } }
35+
public override string Description { get { return "Brownie obfuscated WAV file"; } }
36+
public override uint Signature { get { return 0x58742367; } } // 'g#tX'
37+
public override bool CanWrite { get { return false; } }
38+
39+
public override SoundInput TryOpen (IBinaryStream file)
40+
{
41+
var header = file.ReadHeader (0x10).ToArray();
42+
header[0] = (byte)'R';
43+
header[1] = (byte)'I';
44+
header[2] = (byte)'F';
45+
header[3] = (byte)'F';
46+
for (int i = 4; i < 0x10; ++i)
47+
header[i] ^= 0x5C;
48+
if (!header.AsciiEqual (8, "WAVE"))
49+
return null;
50+
Stream input = new StreamRegion (file.AsStream, 0x10);
51+
input = new PrefixStream (header, input);
52+
return new WaveInput (input);
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)