mirror of
https://github.com/Theaninova/WanganSunrise.git
synced 2025-12-10 10:36:14 +00:00
feat: bank stuff
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
/target
|
||||
/out
|
||||
/.direnv
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::{section::EnmaSection, windows_pe::WindowsPEFile};
|
||||
use crate::{
|
||||
section::{read_bank_cell, EnmaBankCell, EnmaSection},
|
||||
windows_pe::WindowsPEFile,
|
||||
};
|
||||
use binrw::{BinRead, NullString};
|
||||
use serde::Serialize;
|
||||
|
||||
@@ -53,19 +56,25 @@ pub fn read_area(file: &WindowsPEFile, address: u64) -> Result<EnmaArea, std::io
|
||||
related_area_addr: area.related_area_addr,
|
||||
unknown: area.unk2,
|
||||
sections: (0..area.section_count)
|
||||
.map(|i| file.read_addr::<EnmaSection>(area.sections_addr + i as u64 * 0x24))
|
||||
.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)?,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct EnmaArea {
|
||||
/// A unique identifier for the area
|
||||
pub id: u64,
|
||||
/// The name of the area
|
||||
pub name: String,
|
||||
pub stage_id: u64,
|
||||
pub related_area_addr: [u64; 4],
|
||||
pub unknown: [f32; 4],
|
||||
pub sections: Vec<EnmaSection>,
|
||||
pub bank_left: Vec<EnmaBankCell>,
|
||||
pub bank_right: Vec<EnmaBankCell>,
|
||||
}
|
||||
|
||||
#[derive(BinRead, Debug)]
|
||||
|
||||
@@ -26,13 +26,17 @@ fn main() {
|
||||
windows_pe_file.get_file_address(location).unwrap()
|
||||
);
|
||||
|
||||
for i in 1..2 {
|
||||
let mut i = 1;
|
||||
loop {
|
||||
let address = windows_pe_file.read_addr::<u64>(location + i * 8).unwrap();
|
||||
if address == 0 {
|
||||
break;
|
||||
}
|
||||
let area = read_area(&windows_pe_file, address).unwrap();
|
||||
|
||||
let file = File::create(format!("{}.json", area.name)).unwrap();
|
||||
let file = File::create(format!("out/{}.json", area.name)).unwrap();
|
||||
let mut writer = std::io::BufWriter::new(file);
|
||||
serde_json::to_writer_pretty(&mut writer, &area).unwrap();
|
||||
i += 1;
|
||||
}
|
||||
} else {
|
||||
println!("\x1b[31mArea array location could not found\x1b[0m");
|
||||
|
||||
@@ -1,16 +1,53 @@
|
||||
use binrw::BinRead;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::windows_pe::WindowsPEFile;
|
||||
|
||||
#[derive(Debug, BinRead, Serialize)]
|
||||
pub struct EnmaSection {
|
||||
/// The distance along the path
|
||||
pub distance: f32,
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub angle1: f32,
|
||||
pub angle2: f32,
|
||||
/// The position of the node in world space
|
||||
pub position: [f32; 2],
|
||||
/// The normal of the node
|
||||
pub normal: [f32; 2],
|
||||
/// The left wall, where the wall point is `position + normal * left`
|
||||
pub left: f32,
|
||||
/// The right wall, where the wall point is `position + normal * right`
|
||||
pub right: f32,
|
||||
/// The z component of the position
|
||||
pub height: f32,
|
||||
pub unk1: f32,
|
||||
pub unk2: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, BinRead, Serialize)]
|
||||
pub struct EnmaBankCell {
|
||||
/// The index of the section this bank belongs to
|
||||
pub section: i32,
|
||||
/// The width of the bank (it's unclear wether this is horizontal or diagonal)
|
||||
pub width: f32,
|
||||
/// The bank (it's unclear if this is a rotation in radians or a factor)
|
||||
pub bank: f32,
|
||||
/// If false then this bank cell is not connected to the previous one
|
||||
#[br(map = |x: u32| x == 1)]
|
||||
pub connect: bool,
|
||||
}
|
||||
|
||||
pub fn read_bank_cell(
|
||||
file: &WindowsPEFile,
|
||||
mut address: u64,
|
||||
section_count: i32,
|
||||
) -> Result<Vec<EnmaBankCell>, std::io::Error> {
|
||||
let mut result = vec![];
|
||||
loop {
|
||||
let bank = file.read_addr::<EnmaBankCell>(address)?;
|
||||
if bank.section >= section_count {
|
||||
break;
|
||||
}
|
||||
result.push(bank);
|
||||
address += 0x10;
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
@@ -140,6 +140,12 @@ impl WindowsPEFile {
|
||||
T: BinRead,
|
||||
T::Args<'a>: Default,
|
||||
{
|
||||
if address == 0 {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"Address null pointer dereference",
|
||||
));
|
||||
}
|
||||
let mut reader = BufReader::new(&self.file);
|
||||
if let Some(file_addr) = self.get_file_address(address) {
|
||||
reader.seek(std::io::SeekFrom::Start(file_addr as u64))?;
|
||||
|
||||
Reference in New Issue
Block a user