parent
72cc3fecb6
commit
5fcd484f86
@ -0,0 +1,109 @@
|
||||
//typedef struct {
|
||||
// int unk00; Assert(unk00 == 0);
|
||||
// int dataOffset;
|
||||
// int dataLength;
|
||||
// int unk0C; Assert(unk0C == 1);
|
||||
//} Block <bgcolor=cLtGreen, optimize=false>;
|
||||
//
|
||||
//typedef struct {
|
||||
// char dcx[4]; Assert(dcx == "DCX\0");
|
||||
// int unk04; Assert(unk04 == 0x10000 || unk04 == 0x11000);
|
||||
// int unk08; Assert(unk08 == 0x18);
|
||||
// int unk0C; Assert(unk0C == 0x24);
|
||||
// int unk10; Assert(unk10 == 0x24 || unk10 == 0x44);
|
||||
// int unk14; // In EDGE, size from 0x20 to end of block headers
|
||||
// char dcs[4]; Assert(dcs == "DCS\0");
|
||||
// uint uncompressedSize <format=hex>;
|
||||
// uint compressedSize <format=hex>;
|
||||
// char dcp[4]; Assert(dcp == "DCP\0");
|
||||
// char format[4]; Assert(format == "DFLT" || format == "EDGE" || format == "KRAK");
|
||||
// int unk2C; Assert(unk2C == 0x20);
|
||||
// byte unk30; Assert(unk30 == 6|| unk30 == 8 || unk30 == 9);
|
||||
// byte unk31 <hidden=true>; Assert(unk31 == 0);
|
||||
// byte unk32 <hidden=true>; Assert(unk32 == 0);
|
||||
// byte unk33 <hidden=true>; Assert(unk33 == 0);
|
||||
// int unk34; Assert(unk34 == 0 || unk34 == 0x10000); // Block size for EDGE?
|
||||
// int unk38; Assert(unk38 == 0);
|
||||
// int unk3C; Assert(unk3C == 0);
|
||||
// int unk40;
|
||||
// char dca[4]; Assert(dca == "DCA\0");
|
||||
// int dcaSize; // From before "DCA" to dca end
|
||||
//
|
||||
// if (format == "EDGE") {
|
||||
// char egdt[4]; Assert(egdt == "EgdT");
|
||||
// int unk50; Assert(unk50 == 0x10100);
|
||||
// int unk54; Assert(unk54 == 0x24);
|
||||
// int unk58; Assert(unk58 == 0x10);
|
||||
// int unk5C; Assert(unk5C == 0x10000);
|
||||
// int lastBlockUncompressedSize;
|
||||
// int egdtSize; // From before "EgdT" to dca end
|
||||
// int blockCount;
|
||||
// int unk6C; Assert(unk6C == 0x100000);
|
||||
// Block blocks[blockCount];
|
||||
// }
|
||||
//} Header <bgcolor=cLtRed>;
|
||||
|
||||
use nom::IResult;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::multi::count;
|
||||
use nom::number::complete::*;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DcxHeader {
|
||||
pub magic: Vec<u8>,
|
||||
pub unk04: u32,
|
||||
pub ofs_dcs: u32,
|
||||
pub ofs_dcp: u32,
|
||||
pub unk10: u32,
|
||||
pub unk14: u32,
|
||||
}
|
||||
|
||||
const HEADER_MAGIC: u32 = 0x00504344;
|
||||
|
||||
fn parse_header(i: &[u8]) -> IResult<&[u8], DcxHeader> {
|
||||
let (i, (magic, unk04, ofs_dcs, ofs_dcp, unk10, unk14)) = tuple((
|
||||
tag(b"DCX\0"),
|
||||
be_u32,
|
||||
be_u32,
|
||||
be_u32,
|
||||
be_u32,
|
||||
be_u32,
|
||||
))(i)?;
|
||||
Ok((i, DcxHeader { magic: magic.to_vec(), unk04, ofs_dcs, ofs_dcp, unk10, unk14 }))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DcxSizes {
|
||||
pub magic: u32,
|
||||
pub uncompressed_size: u32,
|
||||
pub compressed_size: u32,
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Debug)]
|
||||
pub struct DcxParams {
|
||||
pub magic: u32,
|
||||
pub method: [u8; 4],
|
||||
pub ofs_dca: u32,
|
||||
pub unk0C: u32,
|
||||
pub unk10: u32,
|
||||
pub unk14: u32,
|
||||
pub unk18: u32,
|
||||
pub unk1C: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Dcx {
|
||||
pub header: DcxHeader,
|
||||
pub sizes: DcxSizes,
|
||||
pub params: DcxParams,
|
||||
}
|
||||
|
||||
pub fn parse(i: &[u8]) -> IResult<&[u8], u8> {
|
||||
let (i, header) = parse_header(i).unwrap();
|
||||
println!("{:?}", header);
|
||||
Ok((i, 0))
|
||||
|
||||
//Ok((i, Dcx { header: None, sizes: None, params: None }))
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
use std::fs;
|
||||
use std::io::{self, Read};
|
||||
|
||||
use crate::parsers::dcx;
|
||||
|
||||
pub fn extract_dcx(dcx_path: &str) -> Result<(), io::Error> {
|
||||
let mut dcx_file = fs::File::open(dcx_path)?;
|
||||
let file_len = dcx_file.metadata()?.len() as usize;
|
||||
let mut dcx_data = vec![0u8; file_len];
|
||||
dcx_file.read_exact(&mut dcx_data)?;
|
||||
dcx::parse(&dcx_data);
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in new issue