This commit is contained in:
dece 2020-04-14 18:39:42 +02:00
parent 019818f5f0
commit ce85e8e898
2 changed files with 43 additions and 25 deletions

View file

@ -36,7 +36,6 @@ pub fn load_name_map(path: &str) -> Result<HashMap<String, String>, Error> {
names.insert(hash.to_string(), name[2..].to_string());
}
}
println!("{:?}", names);
Ok(names)
}

View file

@ -1,12 +1,13 @@
use std::collections::HashMap;
use std::fs::File;
use std::fs;
use std::io;
extern crate nom;
use nom::{IResult};
use nom::combinator::verify;
use nom::multi::count;
use nom::number::complete::*;
use nom::sequence::tuple;
use nom::IResult;
#[derive(Debug)]
pub struct BhdHeader {
@ -24,8 +25,7 @@ pub struct BhdHeader {
const MAGIC: u32 = 0x35444842;
fn parse_header(i: &[u8]) -> IResult<&[u8], BhdHeader> {
let (i, (magic, flags, unk08, file_len, num_buckets, ofs_buckets)) =
tuple((
let (i, (magic, flags, unk08, file_len, num_buckets, ofs_buckets)) = tuple((
verify(le_u32, |m| *m == MAGIC),
count(le_i8, 4),
le_u32,
@ -33,14 +33,20 @@ fn parse_header(i: &[u8]) -> IResult<&[u8], BhdHeader> {
le_u32,
le_u32,
))(i)?;
Ok((i, BhdHeader {
Ok((
i,
BhdHeader {
magic,
unk04: flags[0], unk05: flags[1], unk06: flags[2], unk07: flags[3],
unk04: flags[0],
unk05: flags[1],
unk06: flags[2],
unk07: flags[3],
unk08,
file_len,
num_buckets,
ofs_buckets,
}))
},
))
}
#[derive(Debug)]
@ -79,7 +85,7 @@ pub fn parse(i: &[u8]) -> IResult<&[u8], Bhd> {
let (i, header) = parse_header(i)?;
let (i, bucket_infos) = count(parse_bucket_info, header.num_buckets as usize)(i)?;
let mut buckets: Vec<Vec<BhdFile>> = vec!();
let mut buckets: Vec<Vec<BhdFile>> = vec![];
for b in 0..header.num_buckets {
let bucket_info = &bucket_infos[b as usize];
let bucket_data = &full_file[bucket_info.offset as usize..];
@ -87,10 +93,23 @@ pub fn parse(i: &[u8]) -> IResult<&[u8], Bhd> {
buckets.push(bucket);
}
Ok((i, Bhd { header, bucket_infos, buckets }))
Ok((
i,
Bhd {
header,
bucket_infos,
buckets,
},
))
}
/// Extract files from a BHD/BDT pair.
pub fn extract(bhd: &Bhd, bdt_file: &File, names: &HashMap<String, String>, outputpath: &str) {
// TODO
pub fn extract(
bhd: &Bhd,
bdt_file: &fs::File,
names: &HashMap<String, String>,
outputpath: &str,
) -> Result<(), io::Error> {
fs::create_dir(outputpath)?;
Ok(())
}