97 lines
2.4 KiB
Rust
97 lines
2.4 KiB
Rust
use maraiah::{durandal::{bin::*, chunk::*, err::*, image::*, text::*},
|
|
marathon::{machdr, map, pict, shp, term, wad}};
|
|
use std::{env, fs,
|
|
io::{self, Write}};
|
|
|
|
fn read_chunk(cid: &Ident, cnk: &[u8], eid: u16) -> ResultS<()>
|
|
{
|
|
match cid {
|
|
b"PICT" => {
|
|
let im = pict::load_pict(cnk)?;
|
|
println!("entry {} has PICT {}x{}", eid, im.w(), im.h());
|
|
let out = fs::File::create(&format!("out/{}.ppm", eid))?;
|
|
let mut out = io::BufWriter::new(out);
|
|
write_ppm(&mut out, &im)?;
|
|
}
|
|
b"Minf" => {
|
|
let minf = map::Minf::chunk(cnk)?;
|
|
println!("entry {} has {:#?}", eid, minf);
|
|
}
|
|
b"EPNT" => {
|
|
let epnt = map::Endpoint::chunk(cnk)?;
|
|
println!("entry {} has EPNT {:#?}", eid, epnt);
|
|
}
|
|
b"PNTS" => {
|
|
let epnt = map::Point::chunk(cnk)?;
|
|
println!("entry {} has PNTS {:#?}", eid, epnt);
|
|
}
|
|
b"LINS" => {
|
|
let line = map::Line::chunk(cnk)?;
|
|
println!("entry {} has LINS {:#?}", eid, line);
|
|
}
|
|
b"SIDS" => {
|
|
let line = map::Side::chunk(cnk)?;
|
|
println!("entry {} has SIDS {:#?}", eid, line);
|
|
}
|
|
b"term" => {
|
|
let term = term::Terminal::chunk(cnk)?;
|
|
println!("entry {} has term {:#?}", eid, term);
|
|
}
|
|
cid => {
|
|
let fname = format!("out/{:04}{}.bin", eid, mac_roman_conv(cid));
|
|
let out = fs::File::create(&fname)?;
|
|
let mut out = io::BufWriter::new(out);
|
|
out.write(cnk)?;
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn process_wad(b: &[u8]) -> ResultS<()>
|
|
{
|
|
let wad = wad::Wad::new(b)?;
|
|
|
|
println!("{:#?}", wad);
|
|
|
|
for (eid, ent) in wad.entries {
|
|
for (cid, cnk) in ent.chunks {
|
|
read_chunk(&cid, cnk, eid)?;
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn process_shp(b: &[u8]) -> ResultS<()>
|
|
{
|
|
shp::testfn_replaceme(b)
|
|
}
|
|
|
|
fn main() -> ResultS<()>
|
|
{
|
|
use memmap::Mmap;
|
|
|
|
for arg in env::args().skip(1) {
|
|
let (typ, fna) = if let Some(st) = arg.find(':') {
|
|
arg.split_at(st + 1)
|
|
} else {
|
|
("wad:", arg.as_str())
|
|
};
|
|
|
|
let fp = fs::File::open(fna)?;
|
|
let mm = unsafe {Mmap::map(&fp)?};
|
|
let b = &mm[machdr::try_mac_header(&mm)..];
|
|
|
|
match typ {
|
|
"wad:" => process_wad(b),
|
|
"shp:" => process_shp(b),
|
|
_ => Err(err_msg("invalid file type specified on commandline")),
|
|
}?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
// EOF
|