add lane data

This commit is contained in:
2024-04-17 23:23:07 +02:00
parent 819fafa92c
commit ce276e5ba0
4 changed files with 83 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
use crate::{
lane::{read_lane, EnmaLane},
section::{read_bank_cell, EnmaBankCell, EnmaSection},
speed::{read_speed_cells, EnmaSpeedCell},
windows_pe::WindowsPEFile,
};
use binrw::{BinRead, NullString};
@@ -54,12 +56,14 @@ pub fn read_area(file: &WindowsPEFile, address: u64) -> Result<EnmaArea, std::io
name: file.read_addr::<NullString>(area.name_addr)?.to_string(),
stage_id: area.stage_id,
related_area_addr: area.related_area_addr,
unknown: area.unk2,
max_dist: area.max_dist,
sections: (0..area.section_count)
.map(|i| file.read_addr::<EnmaSection>(area.sections_addr + i as u64 * 0x28))
.collect::<Result<_, _>>()?,
bank_left: read_bank_cell(file, area.bank_left_addr, area.section_count)?,
bank_right: read_bank_cell(file, area.bank_right_addr, area.section_count)?,
speed: read_speed_cells(file, area.speed_addr, area.max_dist)?,
lane: read_lane(file, area.lane_addr, area.max_dist)?,
})
}
@@ -71,10 +75,17 @@ pub struct EnmaArea {
pub name: String,
pub stage_id: u64,
pub related_area_addr: [u64; 4],
pub unknown: [f32; 4],
pub max_dist: f32,
pub sections: Vec<EnmaSection>,
pub bank_left: Vec<EnmaBankCell>,
pub bank_right: Vec<EnmaBankCell>,
// TODO: Zebra Left
// TODO: Zebra Right
// TODO: Gaps
// TODO: Non Guard Left
// TODO: Non Guard Right
pub speed: Vec<EnmaSpeedCell>,
pub lane: Vec<EnmaLane>,
}
#[derive(BinRead, Debug)]
@@ -86,8 +97,8 @@ pub struct EnmaAreaRaw {
pub related_area_addr: [u64; 4],
pub unk2: [f32; 4],
#[br(pad_before = 8, pad_after = 4)]
pub max_dist: f32,
pub sections_addr: u64,
pub section_count: i32,

32
enmacompat/src/lane.rs Normal file
View File

@@ -0,0 +1,32 @@
use crate::windows_pe::WindowsPEFile;
use binrw::BinRead;
use serde::Serialize;
#[derive(Debug, BinRead, Serialize)]
pub struct EnmaLane {
pub dist: f32,
pub unk2: i32,
pub unk3: i32,
pub unk4: f32,
pub left: [f32; 2],
pub right: [f32; 2],
}
pub fn read_lane(
file: &WindowsPEFile,
mut address: u64,
max_dist: f32,
) -> Result<Vec<EnmaLane>, std::io::Error> {
let mut result = vec![];
loop {
let lane = file.read_addr::<EnmaLane>(address)?;
let dist = lane.dist;
result.push(lane);
if dist >= max_dist {
break;
}
address += 0x20;
}
Ok(result)
}

View File

@@ -1,5 +1,7 @@
pub mod area;
pub mod lane;
pub mod meta;
pub mod section;
pub mod speed;
mod util;
pub mod windows_pe;

34
enmacompat/src/speed.rs Normal file
View File

@@ -0,0 +1,34 @@
use crate::windows_pe::WindowsPEFile;
use binrw::BinRead;
use serde::Serialize;
#[derive(Debug, BinRead, Serialize)]
pub struct EnmaSpeedCell {
pub dist: f32,
pub z: f32,
pub norm: f32,
pub handle_10: f32,
pub pow_10: f32,
pub ps_600: f32,
pub handle_22: f32,
pub pow_22: f32,
}
pub fn read_speed_cells(
file: &WindowsPEFile,
mut address: u64,
max_dist: f32,
) -> Result<Vec<EnmaSpeedCell>, std::io::Error> {
let mut result = vec![];
loop {
let speed = file.read_addr::<EnmaSpeedCell>(address)?;
let dist = speed.dist;
result.push(speed);
if dist >= max_dist {
break;
}
address += 0x20;
}
Ok(result)
}