use crate::wad::{Builder, Tag};
use crate::wad::ffi::{doom, halflife, quake};
use oct::IntoOcts;
impl Builder {
pub fn dump(&self, buf: &mut [u8]) {
let mut cursor = 0;
let mut write = |data: &[u8]| {
let slot_end = cursor + data.len();
let slot = &mut buf[cursor..slot_end];
slot.copy_from_slice(data);
cursor += data.len();
};
let identification = self.inner.magic();
let numlumps = self.inner.lump_count().try_into().unwrap();
#[expect(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_wrap)]
let infotableofs = (self.inner.tag().header_size() + self.data.len()) as i32;
match self.inner.tag() {
Tag::Wad => {
let header = doom::wadinfo_t {
identification,
numlumps,
infotableofs,
};
write(header.as_octs());
}
Tag::Wad2 => {
let header = quake::wadinfo_t {
identification,
numlumps,
infotableofs,
};
write(header.as_octs());
}
Tag::Wad3 => {
let header = halflife::wadinfo_t {
identification,
numlumps,
infotableofs,
};
write(header.as_octs());
}
};
write(&self.data);
write(self.inner.directory().inner_as_bytes());
}
}