This commit is contained in:
2024-04-21 16:02:50 +02:00
parent 2dea132d7f
commit 6fa0fbdb77
10 changed files with 601 additions and 10 deletions

316
Cargo.lock generated
View File

@@ -68,7 +68,7 @@ dependencies = [
"accesskit",
"accesskit_macos",
"accesskit_windows",
"raw-window-handle",
"raw-window-handle 0.6.0",
"winit",
]
@@ -226,6 +226,25 @@ dependencies = [
"num-traits",
]
[[package]]
name = "arboard"
version = "3.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2041f1943049c7978768d84e6d0fd95de98b76d6c4727b09e78ec253d29fa58"
dependencies = [
"clipboard-win",
"core-graphics",
"image",
"log",
"objc",
"objc-foundation",
"objc_id",
"parking_lot",
"thiserror",
"windows-sys 0.48.0",
"x11rb",
]
[[package]]
name = "array-init"
version = "2.1.0"
@@ -351,6 +370,46 @@ dependencies = [
"bevy_internal",
]
[[package]]
name = "bevy-inspector-egui"
version = "0.23.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb36c3adb02afa4496085250d437217b2a5280d8dd464937c6c5b21bc88830c0"
dependencies = [
"bevy-inspector-egui-derive",
"bevy_app",
"bevy_asset",
"bevy_core",
"bevy_core_pipeline",
"bevy_ecs",
"bevy_egui",
"bevy_hierarchy",
"bevy_log",
"bevy_math",
"bevy_pbr",
"bevy_reflect",
"bevy_render",
"bevy_time",
"bevy_utils",
"bevy_window",
"egui",
"image",
"once_cell",
"pretty-type-name",
"smallvec",
]
[[package]]
name = "bevy-inspector-egui-derive"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3c488161a04a123e10273e16d4533945943fcfcf345f066242790e8977aee2d"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.58",
]
[[package]]
name = "bevy_a11y"
version = "0.13.2"
@@ -556,6 +615,20 @@ dependencies = [
"syn 2.0.58",
]
[[package]]
name = "bevy_egui"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b84bfb8d4104a1467910cf2090bc6a6d394ebde39c0dbc02397b45aa9ef88e80"
dependencies = [
"arboard",
"bevy",
"egui",
"thread_local",
"web-sys",
"webbrowser",
]
[[package]]
name = "bevy_encase_derive"
version = "0.13.2"
@@ -566,6 +639,14 @@ dependencies = [
"encase_derive_impl",
]
[[package]]
name = "bevy_enmacompat"
version = "0.1.0"
dependencies = [
"bevy",
"enmacompat",
]
[[package]]
name = "bevy_gilrs"
version = "0.13.2"
@@ -1069,7 +1150,7 @@ dependencies = [
"bevy_math",
"bevy_reflect",
"bevy_utils",
"raw-window-handle",
"raw-window-handle 0.6.0",
"smol_str",
]
@@ -1092,7 +1173,7 @@ dependencies = [
"bevy_utils",
"bevy_window",
"crossbeam-channel",
"raw-window-handle",
"raw-window-handle 0.6.0",
"wasm-bindgen",
"web-sys",
"winit",
@@ -1397,6 +1478,15 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
[[package]]
name = "clipboard-win"
version = "5.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79f4473f5144e20d9aceaf2972478f06ddf687831eafeeb434fbaf0acc4144ad"
dependencies = [
"error-code",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
@@ -1680,12 +1770,41 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
[[package]]
name = "ecolor"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03cfe80b1890e1a8cdbffc6044d6872e814aaf6011835a2a5e2db0e5c5c4ef4e"
dependencies = [
"bytemuck",
]
[[package]]
name = "egui"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180f595432a5b615fc6b74afef3955249b86cfea72607b40740a4cd60d5297d0"
dependencies = [
"ahash",
"epaint",
"nohash-hasher",
]
[[package]]
name = "either"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2"
[[package]]
name = "emath"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6916301ecf80448f786cdf3eb51d9dbdd831538732229d49119e2d4312eaaf09"
dependencies = [
"bytemuck",
]
[[package]]
name = "encase"
version = "0.7.0"
@@ -1728,6 +1847,21 @@ dependencies = [
"serde_json",
]
[[package]]
name = "epaint"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77b9fdf617dd7f58b0c8e6e9e4a1281f730cde0831d40547da446b2bb76a47af"
dependencies = [
"ab_glyph",
"ahash",
"bytemuck",
"ecolor",
"emath",
"nohash-hasher",
"parking_lot",
]
[[package]]
name = "equivalent"
version = "1.0.1"
@@ -1753,6 +1887,12 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "error-code"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0474425d51df81997e2f90a21591180b38eccf27292d755f3e30750225c175b"
[[package]]
name = "euclid"
version = "0.22.9"
@@ -1874,6 +2014,15 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
[[package]]
name = "form_urlencoded"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
dependencies = [
"percent-encoding",
]
[[package]]
name = "futures-core"
version = "0.3.30"
@@ -2173,6 +2322,15 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]]
name = "home"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "icrate"
version = "0.0.4"
@@ -2184,6 +2342,16 @@ dependencies = [
"objc2 0.4.1",
]
[[package]]
name = "idna"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
dependencies = [
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "image"
version = "0.24.9"
@@ -2195,6 +2363,7 @@ dependencies = [
"color_quant",
"num-traits",
"png",
"tiff",
]
[[package]]
@@ -2289,6 +2458,12 @@ dependencies = [
"libc",
]
[[package]]
name = "jpeg-decoder"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0"
[[package]]
name = "js-sys"
version = "0.3.69"
@@ -2489,6 +2664,27 @@ dependencies = [
"simd-adler32",
]
[[package]]
name = "modular-bitfield"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a53d79ba8304ac1c4f9eb3b9d281f21f7be9d4626f72ce7df4ad8fbde4f38a74"
dependencies = [
"modular-bitfield-impl",
"static_assertions",
]
[[package]]
name = "modular-bitfield-impl"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a7d5f7076603ebc68de2dc6a650ec331a062a13abaa346975be747bbfa4b789"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "naga"
version = "0.19.2"
@@ -2541,7 +2737,7 @@ dependencies = [
"log",
"ndk-sys",
"num_enum",
"raw-window-handle",
"raw-window-handle 0.6.0",
"thiserror",
]
@@ -2572,6 +2768,12 @@ dependencies = [
"libc",
]
[[package]]
name = "nohash-hasher"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
[[package]]
name = "nom"
version = "7.1.3"
@@ -2612,6 +2814,9 @@ name = "nucompat"
version = "0.1.0"
dependencies = [
"binrw",
"clap",
"flate2",
"modular-bitfield",
]
[[package]]
@@ -2665,6 +2870,17 @@ dependencies = [
"objc_exception",
]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]]
name = "objc-sys"
version = "0.2.0-beta.2"
@@ -2722,6 +2938,15 @@ dependencies = [
"cc",
]
[[package]]
name = "objc_id"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
dependencies = [
"objc",
]
[[package]]
name = "oboe"
version = "0.6.1"
@@ -2907,6 +3132,12 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa"
[[package]]
name = "pretty-type-name"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0f73cdaf19b52e6143685c3606206e114a4dfa969d6b14ec3894c88eb38bd4b"
[[package]]
name = "proc-macro-crate"
version = "3.1.0"
@@ -2961,6 +3192,12 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab"
[[package]]
name = "raw-window-handle"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
[[package]]
name = "raw-window-handle"
version = "0.6.0"
@@ -3366,6 +3603,17 @@ dependencies = [
"once_cell",
]
[[package]]
name = "tiff"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e"
dependencies = [
"flate2",
"jpeg-decoder",
"weezl",
]
[[package]]
name = "tiny-skia"
version = "0.11.4"
@@ -3522,12 +3770,27 @@ dependencies = [
"static_assertions",
]
[[package]]
name = "unicode-bidi"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-normalization"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.11.0"
@@ -3546,6 +3809,17 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "url"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
]
[[package]]
name = "utf8parse"
version = "0.2.1"
@@ -3595,6 +3869,9 @@ name = "wangan_sunrise"
version = "0.1.0"
dependencies = [
"bevy",
"bevy-inspector-egui",
"bevy_enmacompat",
"enmacompat",
]
[[package]]
@@ -3797,6 +4074,29 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "webbrowser"
version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db67ae75a9405634f5882791678772c94ff5f16a66535aae186e26aa0841fc8b"
dependencies = [
"core-foundation",
"home",
"jni",
"log",
"ndk-context",
"objc",
"raw-window-handle 0.5.2",
"url",
"web-sys",
]
[[package]]
name = "weezl"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
[[package]]
name = "wgpu"
version = "0.19.3"
@@ -3811,7 +4111,7 @@ dependencies = [
"naga",
"parking_lot",
"profiling",
"raw-window-handle",
"raw-window-handle 0.6.0",
"smallvec",
"static_assertions",
"wasm-bindgen",
@@ -3839,7 +4139,7 @@ dependencies = [
"once_cell",
"parking_lot",
"profiling",
"raw-window-handle",
"raw-window-handle 0.6.0",
"rustc-hash",
"smallvec",
"thiserror",
@@ -3882,7 +4182,7 @@ dependencies = [
"parking_lot",
"profiling",
"range-alloc",
"raw-window-handle",
"raw-window-handle 0.6.0",
"renderdoc-sys",
"rustc-hash",
"smallvec",
@@ -4254,7 +4554,7 @@ dependencies = [
"once_cell",
"orbclient",
"percent-encoding",
"raw-window-handle",
"raw-window-handle 0.6.0",
"redox_syscall 0.3.5",
"rustix",
"sctk-adwaita",

View File

@@ -1,3 +1,9 @@
[workspace]
members = ["bevy_nucompat", "nucompat", "enmacompat", "wangan_sunrise"]
members = [
"bevy_nucompat",
"nucompat",
"enmacompat",
"wangan_sunrise",
"bevy_enmacompat",
]
resolver = "2"

View File

@@ -0,0 +1,8 @@
[package]
name = "bevy_enmacompat"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = { version = "0.13" }
enmacompat = { path = "../enmacompat" }

View File

View File

@@ -5,3 +5,6 @@ edition = "2021"
[dependencies]
binrw = "0.13"
modular-bitfield = "0.11.2"
clap = { version = "4.5.4", features = ["derive"] }
flate2 = "1.0.28"

View File

@@ -0,0 +1,2 @@
pub mod nut;
pub mod xmd;

172
nucompat/src/formats/nut.rs Normal file
View File

@@ -0,0 +1,172 @@
use binrw::{args, binrw, BinRead, BinResult};
use modular_bitfield::{bitfield, specifiers::B9};
#[binrw]
#[brw(little)]
#[derive(Debug)]
pub enum NuNut {
#[brw(magic = b"NTP3", big)]
NTP3(NuNutData),
#[brw(magic = b"NTWD", little)]
NTWD(NuNutData),
#[brw(magic = b"NTLX", little)]
NTLX(NuNutData),
}
#[binrw]
#[brw(repr = u32)]
#[derive(Debug)]
pub enum NuTextureType {
DDS = 0,
GXT = 1,
}
#[binrw]
#[brw(big, repr = u16)]
#[derive(Debug)]
pub enum NuPixelFormat {
DXT1 = 0x00,
DXT3 = 0x01,
DXT5 = 0x02,
RGB16 = 0x08,
RGBA16 = 0x0C,
RGBA = 0x0E,
ABGR = 0x0F,
RGBA2 = 0x10,
RGBA1 = 0x11,
RGBA0 = 0x15,
CompressedRgRGTC2 = 0x16,
}
#[binrw]
#[br(assert(version == 2, "Unsupported version {}", version))]
#[derive(Debug)]
pub struct NuNutData {
pub version: u16,
#[br(temp)]
#[bw(calc(textures.len() as u16))]
count: u16,
#[brw(align_before = 0x10)]
#[br(count = count)]
pub textures: Vec<NuNutTexture>,
#[brw(align_before = 0x10)]
#[br(parse_with = parse_surfaces, args(&textures))]
pub surfaces: Vec<Vec<u8>>,
}
#[binrw::parser(reader, endian)]
fn parse_surfaces(textures: &Vec<NuNutTexture>) -> BinResult<Vec<Vec<u8>>> {
let mut surfaces = Vec::with_capacity(textures.len());
for texture in textures {
surfaces.push(Vec::<u8>::read_options(
reader,
endian,
args! {count: texture.data_size as usize},
)?);
}
Ok(surfaces)
}
#[binrw]
#[br(assert(header_size == self.header_size()))]
#[br(assert(size == self.size()))]
#[derive(Debug)]
pub struct NuNutTexture {
#[br(temp)]
#[bw(calc(self.size()))]
pub size: u64,
pub data_size: u32, // TODO: dynamic writing
#[brw(align_after = 0x10)]
#[br(temp)]
#[bw(calc(self.header_size()))]
pub header_size: u16,
#[brw(big)]
#[br(temp, dbg)]
#[bw(calc(mipmap_sizes.len() as u16))]
pub mipmap_count: u16,
pub pixel_format: NuPixelFormat,
pub width: u16,
pub height: u16,
pub texture_type: NuTextureType,
pub cubemap: NuNutCubemap,
#[brw(align_before = 0x10)]
pub data_offset: u32, // TODO: dynamic writing
#[brw(if(cubemap.is_cubemap()), align_before = 0x10)]
pub cubemap_sizes: [u16; 4],
#[brw(align_before = 0x10)]
#[br(count = mipmap_count)]
pub mipmap_sizes: Vec<u32>, // TODO: dynamic writing
#[brw(align_before = 0x10)]
pub ext: NuNutExt,
#[brw(align_before = 0x10, align_after = 0x10)]
pub gidx: NuNutGidx,
}
impl NuNutTexture {
fn header_size(&self) -> u16 {
if self.cubemap.is_cubemap() {
0x70
} else {
0x60
}
}
fn size(&self) -> u64 {
self.data_size as u64 + self.header_size() as u64
}
}
#[binrw]
#[brw(magic = b"eXt\0")]
#[derive(Debug)]
pub struct NuNutExt {
pub version: u32,
pub version2: u32,
pub unknown: u32,
}
#[binrw]
#[brw(magic = b"GIDX")]
#[derive(Debug)]
pub struct NuNutGidx {
pub unknown2: u32,
pub hash_id: u32,
}
#[bitfield]
#[binrw]
#[br(map = Self::from_bytes)]
#[bw(map = |&x| Self::into_bytes(x))]
#[derive(Debug, Clone, Copy)]
pub struct NuNutCubemap {
#[skip]
__: B9,
pub x_plus: bool,
pub x_minus: bool,
pub y_plus: bool,
pub y_minus: bool,
pub z_plus: bool,
pub z_minus: bool,
pub is_cubemap: bool,
}
impl NuNutCubemap {
pub fn cubemap_count(&self) -> u8 {
self.x_plus() as u8
+ self.x_minus() as u8
+ self.y_plus() as u8
+ self.y_minus() as u8
+ self.z_plus() as u8
+ self.z_minus() as u8
}
pub fn surface_count(&self) -> u8 {
self.cubemap_count().min(1)
}
}
#[binrw]
#[derive(Debug)]
pub struct NuNutSurface {}

View File

@@ -0,0 +1,26 @@
use binrw::binrw;
#[binrw]
#[brw(repr = u32)]
#[derive(Debug)]
pub enum NuXmdListCounts {
LmbTexturesResources = 1,
PosLenId = 3,
}
#[binrw]
#[brw(little, magic = b"XMD\0001\0")]
#[derive(Debug)]
pub struct NuXmd {
pub layout: NuXmdListCounts,
pub count: u32,
#[br(count = count)]
#[brw(align_after = 0x10)]
pub positions: Vec<u32>,
#[br(count = count)]
#[brw(align_after = 0x10)]
pub lengths: Vec<u32>,
#[br(count = count)]
#[brw(align_after = 0x10)]
pub ids: Vec<u32>,
}

View File

@@ -0,0 +1,55 @@
use std::io::{BufReader, Cursor, Read, Seek};
use binrw::{
binrw,
meta::{EndianKind, ReadEndian},
BinRead, BinResult, Endian,
};
use flate2::bufread::GzDecoder;
use formats::{nut::NuNut, xmd::NuXmd};
pub mod formats;
#[derive(Debug)]
pub enum NuFile {
Plain(Nu),
Gz(Nu),
}
impl ReadEndian for NuFile {
const ENDIAN: EndianKind = EndianKind::Endian(Endian::Little);
}
impl BinRead for NuFile {
type Args<'a> = ();
fn read_options<R: Read + Seek>(
reader: &mut R,
endian: binrw::Endian,
args: Self::Args<'_>,
) -> BinResult<Self> {
let mut signature = [0u8; 2];
reader.read_exact(&mut signature)?;
reader.seek(std::io::SeekFrom::Start(0))?;
if signature == [0x1F, 0x8B] {
let mut reader = BufReader::new(reader);
let mut decoder = GzDecoder::new(&mut reader);
let mut buf = Vec::new();
decoder.read_to_end(&mut buf)?;
Ok(NuFile::Gz(Nu::read_options(
&mut Cursor::new(buf),
endian,
args,
)?))
} else {
Ok(NuFile::Plain(Nu::read_options(reader, endian, args)?))
}
}
}
#[binrw]
#[derive(Debug)]
pub enum Nu {
Nut(NuNut),
Xmd(NuXmd),
}

View File

@@ -1 +1,20 @@
fn main() {}
use binrw::BinRead;
use clap::{command, Parser};
use nucompat::NuFile;
use std::fs::File;
#[derive(Parser)]
#[command(version, about)]
struct Args {
#[clap(short, long)]
path: std::path::PathBuf,
}
fn main() {
let args = Args::parse();
let file = File::open(&args.path).expect("Failed to open file");
let mut reader = std::io::BufReader::new(file);
let file = NuFile::read(&mut reader).unwrap();
println!("{:#?}", file);
}