-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
130 lines (122 loc) · 5.66 KB
/
Copy pathProgram.cs
File metadata and controls
130 lines (122 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace BotW_bars_extractor
{
class Program
{
static BinaryReader bread;
static BinaryWriter bwrite;
struct endFiles
{
public string name;
public uint offset;
}
static void Main(string[] args)
{
string output_bars = "";
if (args.Length == 1)
output_bars = args[0];
else {
System.Console.WriteLine("Usage: bars_extract <output .bars file>");
return;
}
FileInfo fi = new FileInfo(output_bars);
string input_folder = fi.DirectoryName + "\\" + fi.Name + "_extracted\\";
uint full_size = (uint)fi.Length;
bread = new BinaryReader(File.Open(output_bars, FileMode.Open));
Directory.CreateDirectory(input_folder);
//first 4 bytes form the word BARS(42 41 52 53)
string bars = new string(bread.ReadChars(4));
if (bars != "BARS") {
System.Console.WriteLine("Not a valid .bars file");
return;
}
//starting byte 0x4 is the lenght of the file, 4 bytes long. maximum file size would be 16777215 bytes.
uint file_size = readInt32be(bread);
//next 4 bytes seem to be always the same(FE FF 01 01).
bread.ReadChars(4);
List<uint> entries = collect_entries();
//after that starts the data itself.
List<endFiles> filesToCreate = new List<endFiles>();
for (int i = 0; i < entries.Count; i++)
{
string file_name = "";
if (i < entries.Count/2) {
bread.BaseStream.Position = entries[i];
//AMTA
bread.ReadChars(4);
//24 unknown bytes
bread.ReadChars(24);
//DATA
string chunk_name = new string(bread.ReadChars(4));
uint chunk_size = readInt32be(bread);
bread.BaseStream.Position += chunk_size;
//MARK
chunk_name = new string(bread.ReadChars(4));
chunk_size = readInt32be(bread);
bread.BaseStream.Position += chunk_size;
//EXT_
chunk_name = new string(bread.ReadChars(4));
chunk_size = readInt32be(bread);
bread.BaseStream.Position += chunk_size;
//STRG
//byte 0xA7 of the header contains the lenght of the file name.
chunk_name = new string(bread.ReadChars(4));
chunk_size = readInt32be(bread);
byte[] bytes = new byte[chunk_size-1];
for (uint j = 0; j < chunk_size-1; j++)
bytes[j] = bread.ReadByte();
file_name = System.Text.Encoding.UTF8.GetString(bytes)+ ".bfwav";
endFiles f1 = new endFiles();
f1.name = file_name;
f1.offset = entries[i+ entries.Count / 2];
filesToCreate.Add(f1);
} else {
//if the.bars doesn't have bfwav's inside then that second value is null(FF FF FF FF).
if (entries[i] == 0xffffffff) continue;
bread.BaseStream.Position = entries[i];
bwrite = new BinaryWriter(File.Open(input_folder + filesToCreate[i- entries.Count / 2].name, FileMode.Create));
bread.ReadBytes(4);//FWAV
bread.ReadBytes(2);//Byte order (feff)
bread.ReadBytes(2);//Header size(0040)
bread.ReadBytes(4);//Unknown
uint fwav_size = readInt32be(bread);
bread.BaseStream.Position -= 16;
for (uint ik = 0; ik < fwav_size; ik++)
bwrite.Write(bread.ReadByte());
}
}
}
static uint readInt32be(BinaryReader bread)
{
byte[] a32 = new byte[4];
a32 = bread.ReadBytes(4);
Array.Reverse(a32);
return BitConverter.ToUInt32(a32, 0);
}
static List<uint> collect_entries()
{
List<uint> entries = new List<uint>();
List<uint> filess = new List<uint>();
//next 4 bytes is the total of files packed inside.
uint files = readInt32be(bread);
//next bytes really can't make heads or tails of what it is, but could be a 4 bytes identifier of the files packed inside.
//can't be a crc because comparing the japanese and usa NV_Custom_NoActor.bars shows that those values are identical.
bread.BaseStream.Position += files*4;
//next bytes are the content index, 2 values 4 bytes long each,
for (uint i = 0; i < files; i++)
{
//first value is the offset to (what seems to be) the header and name of the file.
uint header = readInt32be(bread);
entries.Add(header);
//the second value is the offset to the file itself.
uint offset = readInt32be(bread);
filess.Add(offset);
}
entries = entries.Concat(filess).ToList();
return entries;
}
}
}