rustfmt
This commit is contained in:
parent
019818f5f0
commit
ce85e8e898
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
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 {
|
||||
pub magic: u32,
|
||||
pub unk04: i8, // PC=0, PS3=-1
|
||||
pub unk04: i8, // PC=0, PS3=-1
|
||||
pub unk05: i8,
|
||||
pub unk06: i8,
|
||||
pub unk07: i8,
|
||||
|
@ -24,23 +25,28 @@ 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((
|
||||
verify(le_u32, |m| *m == MAGIC),
|
||||
count(le_i8, 4),
|
||||
le_u32,
|
||||
le_u32,
|
||||
le_u32,
|
||||
le_u32,
|
||||
))(i)?;
|
||||
Ok((i, BhdHeader {
|
||||
magic,
|
||||
unk04: flags[0], unk05: flags[1], unk06: flags[2], unk07: flags[3],
|
||||
unk08,
|
||||
file_len,
|
||||
num_buckets,
|
||||
ofs_buckets,
|
||||
}))
|
||||
let (i, (magic, flags, unk08, file_len, num_buckets, ofs_buckets)) = tuple((
|
||||
verify(le_u32, |m| *m == MAGIC),
|
||||
count(le_i8, 4),
|
||||
le_u32,
|
||||
le_u32,
|
||||
le_u32,
|
||||
le_u32,
|
||||
))(i)?;
|
||||
Ok((
|
||||
i,
|
||||
BhdHeader {
|
||||
magic,
|
||||
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(())
|
||||
}
|
||||
|
|
Reference in a new issue