mirror of
https://github.com/Theaninova/WanganSunrise.git
synced 2025-12-11 02:56:17 +00:00
add zebra
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
use crate::{
|
||||
lane::{read_lane, EnmaLane},
|
||||
dist_cell::read_dist_cells,
|
||||
lane::EnmaLaneCell,
|
||||
section::{read_bank_cell, EnmaBankCell, EnmaSection},
|
||||
speed::{read_speed_cells, EnmaSpeedCell},
|
||||
speed::EnmaSpeedCell,
|
||||
windows_pe::WindowsPEFile,
|
||||
zebra::EnmaZebraCell,
|
||||
};
|
||||
use binrw::{BinRead, NullString};
|
||||
use serde::Serialize;
|
||||
@@ -62,8 +64,11 @@ pub fn read_area(file: &WindowsPEFile, address: u64) -> Result<EnmaArea, std::io
|
||||
.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)?,
|
||||
zebra_left: read_dist_cells(file, area.zebra_left_addr, area.max_dist, false)?,
|
||||
zebra_right: read_dist_cells(file, area.zebra_left_addr, area.max_dist, false)?,
|
||||
gaps: read_dist_cells(file, area.gaps_addr, area.max_dist, false)?,
|
||||
speed: read_dist_cells(file, area.speed_addr, area.max_dist, true)?,
|
||||
lane: read_dist_cells(file, area.lane_addr, area.max_dist, true)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -79,13 +84,13 @@ pub struct EnmaArea {
|
||||
pub sections: Vec<EnmaSection>,
|
||||
pub bank_left: Vec<EnmaBankCell>,
|
||||
pub bank_right: Vec<EnmaBankCell>,
|
||||
// TODO: Zebra Left
|
||||
// TODO: Zebra Right
|
||||
// TODO: Gaps
|
||||
pub zebra_left: Vec<EnmaZebraCell>,
|
||||
pub zebra_right: Vec<EnmaZebraCell>,
|
||||
pub gaps: Vec<f32>,
|
||||
// TODO: Non Guard Left
|
||||
// TODO: Non Guard Right
|
||||
pub speed: Vec<EnmaSpeedCell>,
|
||||
pub lane: Vec<EnmaLane>,
|
||||
pub lane: Vec<EnmaLaneCell>,
|
||||
}
|
||||
|
||||
#[derive(BinRead, Debug)]
|
||||
|
||||
44
enmacompat/src/dist_cell.rs
Normal file
44
enmacompat/src/dist_cell.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use binrw::BinRead;
|
||||
|
||||
use crate::windows_pe::WindowsPEFile;
|
||||
|
||||
pub trait EnmaDistCell {
|
||||
fn dist(&self) -> f32;
|
||||
fn size() -> u64;
|
||||
}
|
||||
|
||||
impl EnmaDistCell for f32 {
|
||||
fn dist(&self) -> f32 {
|
||||
*self
|
||||
}
|
||||
|
||||
fn size() -> u64 {
|
||||
4
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_dist_cells<'a, T>(
|
||||
file: &WindowsPEFile,
|
||||
mut address: u64,
|
||||
max_dist: f32,
|
||||
include_last: bool,
|
||||
) -> Result<Vec<T>, std::io::Error>
|
||||
where
|
||||
T: BinRead + EnmaDistCell,
|
||||
T::Args<'a>: Default,
|
||||
{
|
||||
let mut result = vec![];
|
||||
loop {
|
||||
let cell = file.read_addr::<T>(address)?;
|
||||
if cell.dist() >= max_dist {
|
||||
if include_last {
|
||||
result.push(cell);
|
||||
}
|
||||
break;
|
||||
}
|
||||
result.push(cell);
|
||||
address += T::size();
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::windows_pe::WindowsPEFile;
|
||||
use binrw::BinRead;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::dist_cell::EnmaDistCell;
|
||||
|
||||
#[derive(Debug, BinRead, Serialize)]
|
||||
pub struct EnmaLane {
|
||||
pub struct EnmaLaneCell {
|
||||
pub dist: f32,
|
||||
pub unk2: i32,
|
||||
pub unk3: i32,
|
||||
@@ -12,21 +13,12 @@ pub struct EnmaLane {
|
||||
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;
|
||||
impl EnmaDistCell for EnmaLaneCell {
|
||||
fn dist(&self) -> f32 {
|
||||
self.dist
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
fn size() -> u64 {
|
||||
0x20
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
pub mod area;
|
||||
pub mod dist_cell;
|
||||
pub mod lane;
|
||||
pub mod meta;
|
||||
pub mod section;
|
||||
pub mod speed;
|
||||
mod util;
|
||||
pub mod windows_pe;
|
||||
pub mod zebra;
|
||||
|
||||
@@ -35,8 +35,9 @@ impl EnmaMeta {
|
||||
}
|
||||
|
||||
println!(
|
||||
"\x1b[32m\x1b[1mArea Array\x1b[0m: \x1b[4m{:#x} ({} items)\x1b[0m",
|
||||
area_array_addr, area_array_count
|
||||
"\x1b[32m\x1b[1mArea Array\x1b[0m: \x1b[4m{:#x} ({} Areas)\x1b[0m",
|
||||
area_array_addr,
|
||||
area_array_count - 1
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::windows_pe::WindowsPEFile;
|
||||
use binrw::BinRead;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::dist_cell::EnmaDistCell;
|
||||
|
||||
#[derive(Debug, BinRead, Serialize)]
|
||||
pub struct EnmaSpeedCell {
|
||||
pub dist: f32,
|
||||
@@ -14,21 +15,12 @@ pub struct EnmaSpeedCell {
|
||||
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;
|
||||
impl EnmaDistCell for EnmaSpeedCell {
|
||||
fn dist(&self) -> f32 {
|
||||
self.dist
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
fn size() -> u64 {
|
||||
0x20
|
||||
}
|
||||
}
|
||||
|
||||
22
enmacompat/src/zebra.rs
Normal file
22
enmacompat/src/zebra.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use binrw::BinRead;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::dist_cell::EnmaDistCell;
|
||||
|
||||
#[derive(Debug, BinRead, Serialize)]
|
||||
pub struct EnmaZebraCell {
|
||||
pub dist: f32,
|
||||
pub unk1: f32,
|
||||
pub unk2: f32,
|
||||
pub unk3: i32,
|
||||
}
|
||||
|
||||
impl EnmaDistCell for EnmaZebraCell {
|
||||
fn dist(&self) -> f32 {
|
||||
self.dist
|
||||
}
|
||||
|
||||
fn size() -> u64 {
|
||||
0x10
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user