use std::io::{Cursor, Seek, SeekFrom};
use crate::ByteSpan;
use binrw::binrw;
use binrw::BinRead;
#[binrw]
#[br(little)]
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct RacialScalingParameters {
pub male_min_size: f32,
pub male_max_size: f32,
pub male_min_tail: f32,
pub male_max_tail: f32,
pub female_min_size: f32,
pub female_max_size: f32,
pub female_min_tail: f32,
pub female_max_tail: f32,
pub bust_min_x: f32,
pub bust_min_y: f32,
pub bust_min_z: f32,
pub bust_max_x: f32,
pub bust_max_y: f32,
pub bust_max_z: f32,
}
#[derive(Debug)]
pub struct CMP {
pub parameters: Vec<RacialScalingParameters>,
}
impl CMP {
pub fn from_existing(buffer: ByteSpan) -> Option<CMP> {
let mut cursor = Cursor::new(buffer);
cursor.seek(SeekFrom::Start(0x2a800)).ok()?;
let rem = buffer.len() - cursor.position() as usize;
let entries = rem / std::mem::size_of::<RacialScalingParameters>();
let mut parameters = vec![];
for _ in 0..entries {
parameters.push(RacialScalingParameters::read(&mut cursor).ok()?);
}
Some(CMP { parameters })
}
}
#[cfg(test)]
mod tests {
use std::fs::read;
use std::path::PathBuf;
use super::*;
#[test]
fn test_invalid() {
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
d.push("resources/tests");
d.push("random");
CMP::from_existing(&read(d).unwrap());
}
}