diff --git a/aetherment/Cargo.toml b/aetherment/Cargo.toml index b4e8fff..15e83f7 100644 --- a/aetherment/Cargo.toml +++ b/aetherment/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.6" edition = "2021" [dependencies] -renderer = {path = "../renderer"} +renderer = {path = "../renderer", optional = true} noumenon = {path = "../noumenon"} serde = {version = "1.0.171", features = ["derive"]} @@ -27,5 +27,5 @@ base32 = "0.5.0" base64 = "0.22.1" [features] -client = ["renderer/egui"] -plugin = ["renderer/imgui"] \ No newline at end of file +client = ["dep:renderer", "renderer/egui"] +plugin = ["dep:renderer", "renderer/imgui"] \ No newline at end of file diff --git a/aetherment/src/lib.rs b/aetherment/src/lib.rs index 8420658..b8c46f9 100644 --- a/aetherment/src/lib.rs +++ b/aetherment/src/lib.rs @@ -1,17 +1,15 @@ #[macro_use] mod log; +pub use log::LogType; + mod resource_loader; mod render_helper; mod config; pub mod modman; -mod view; -mod remote; -pub mod service; - -pub use log::LogType; -// pub use renderer; - -pub extern crate renderer; +#[cfg(any(feature = "plugin", feature = "client"))] mod view; +#[cfg(any(feature = "plugin", feature = "client"))] mod remote; +#[cfg(any(feature = "plugin", feature = "client"))] pub mod service; +#[cfg(any(feature = "plugin", feature = "client"))] pub extern crate renderer; pub use noumenon as noumenon_; // idk what to call it static mut CONFIG: Option = None; @@ -26,7 +24,9 @@ pub fn config() -> &'static mut config::ConfigManager { // not thread safe (probably), being used across threads, it will bite me in the ass // TODO: fix +#[cfg(any(feature = "plugin", feature = "client"))] static mut BACKEND: Option> = None; +#[cfg(any(feature = "plugin", feature = "client"))] pub fn backend() -> &'static mut Box { unsafe{BACKEND.as_mut().unwrap()} } @@ -53,6 +53,7 @@ pub fn json_pretty(data: &T) -> Result Self { unsafe { diff --git a/aetherment/src/modman/backend/penumbra_ipc.rs b/aetherment/src/modman/backend/penumbra_ipc.rs index 1666ba7..da109c3 100644 --- a/aetherment/src/modman/backend/penumbra_ipc.rs +++ b/aetherment/src/modman/backend/penumbra_ipc.rs @@ -335,6 +335,9 @@ impl super::Backend for Penumbra { } fn apply_ui_colors() { + let collection = get_collection(super::CollectionType::Interface); + if !collection.is_valid() {return} + let mut final_ui_colors = HashMap::<(bool, u32), (i32, [u8; 3])>::new(); let root = root_path(); @@ -342,8 +345,6 @@ fn apply_ui_colors() { let mod_dir = root.join(&id); let aeth_dir = mod_dir.join("aetherment"); if !aeth_dir.exists() {continue} - let collection = get_collection(super::CollectionType::Interface); - if !collection.is_valid() {continue} let settings = get_mod_settings(&collection.id, &id, true); if !settings.enabled {continue} let priority = settings.priority; diff --git a/aetherment/src/modman/issue.rs b/aetherment/src/modman/issue.rs index eb535d6..2ad81ee 100644 --- a/aetherment/src/modman/issue.rs +++ b/aetherment/src/modman/issue.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use crate::render_helper::EnumTools; +#[cfg(any(feature = "plugin", feature = "client"))] use crate::render_helper::EnumTools; #[derive(Debug, Clone, Deserialize, Serialize)] pub enum Issue { @@ -14,6 +14,7 @@ pub enum Status { Warning(String), } +#[cfg(any(feature = "plugin", feature = "client"))] impl Issue { pub fn get_status(&self) -> Status { let funcs = unsafe{FUNCS.as_ref().unwrap()}; @@ -63,13 +64,16 @@ impl Issue { // ---------- +#[cfg(any(feature = "plugin", feature = "client"))] pub struct IssueInitializers { pub ui_resolution: Box u8>, pub ui_theme: Box u8>, pub collection: Box super::backend::Collection>, } +#[cfg(any(feature = "plugin", feature = "client"))] static mut FUNCS: Option = None; +#[cfg(any(feature = "plugin", feature = "client"))] pub(crate) fn initialize(funcs: IssueInitializers) { unsafe{FUNCS = Some(funcs)} } \ No newline at end of file diff --git a/aetherment/src/modman/mod.rs b/aetherment/src/modman/mod.rs index f758208..e5bdfd2 100644 --- a/aetherment/src/modman/mod.rs +++ b/aetherment/src/modman/mod.rs @@ -2,7 +2,7 @@ use std::{collections::{HashSet, HashMap}, io::{Read, Write, Seek}}; use serde::{Deserialize, Serialize}; use crate::render_helper::EnumTools; -pub mod backend; +#[cfg(any(feature = "plugin", feature = "client"))] pub mod backend; pub mod meta; pub mod settings; // pub mod priority; diff --git a/aetherment/src/render_helper.rs b/aetherment/src/render_helper.rs index 9ea0e5d..7a6c1af 100644 --- a/aetherment/src/render_helper.rs +++ b/aetherment/src/render_helper.rs @@ -1,4 +1,4 @@ -use renderer::*; +#[cfg(any(feature = "plugin", feature = "client"))] use renderer::*; pub trait EnumTools { type Iterator: core::iter::Iterator; @@ -12,6 +12,7 @@ pub trait UiExt { fn combo_enum, Enum: EnumTools + PartialEq>(&mut self, label: S, val: &mut Enum) -> bool; } +#[cfg(any(feature = "plugin", feature = "client"))] impl<'a> UiExt for Ui<'a> { fn combo_enum, Enum: EnumTools + PartialEq>(&mut self, label: S, val: &mut Enum) -> bool { let mut changed = false; diff --git a/noumenon/src/format/game/tex.rs b/noumenon/src/format/game/tex.rs index 0d876df..166a44c 100755 --- a/noumenon/src/format/game/tex.rs +++ b/noumenon/src/format/game/tex.rs @@ -382,7 +382,7 @@ impl Tiff for Tex { } impl Tga for Tex { - fn read(reader: &mut T) -> Result where + fn read(reader: &mut T) -> Result where T: Read + Seek { let img = image::io::Reader::with_format(BufReader::new(reader), image::ImageFormat::Tga) .decode()?; @@ -400,9 +400,9 @@ impl Tga for Tex { }, data: img.into_rgba8().into_vec(), }) - } - - fn write(&self, writer: &mut T) -> Result<(), Error> where + } + + fn write(&self, writer: &mut T) -> Result<(), Error> where T: Write + Seek { let img = TgaEncoder::new(writer); img.write_image( @@ -413,5 +413,5 @@ impl Tga for Tex { )?; Ok(()) - } + } } \ No newline at end of file diff --git a/noumenon/src/format/game/uld.rs b/noumenon/src/format/game/uld.rs index f0b475c..9b3701c 100755 --- a/noumenon/src/format/game/uld.rs +++ b/noumenon/src/format/game/uld.rs @@ -1,4 +1,4 @@ -use std::{io::{Read, Seek, Write, SeekFrom}, fmt::Debug}; +use std::{fmt::Debug, io::{Read, Seek, SeekFrom, Write}}; use binrw::{binrw, BinRead, BinWrite}; use crate::{Error, NullReader, NullWriter}; @@ -80,9 +80,24 @@ impl BinRead for Uld { reader.seek(SeekFrom::Start(primary_pos + primary_header.component_offset as u64))?; let components_header = ListHeader::read_options(reader, endian, ())?; + let components_pos = reader.stream_position()?; + + // read in component types since earlier nodes can reference later components (i hate this) + let mut component_types = std::collections::HashMap::new(); + for _ in 0..components_header.element_count { + let id = u32::read_options(reader, endian, ())?; + reader.seek(SeekFrom::Current(3))?; + let component_type = ComponentType::read_options(reader, endian, ())?; + component_types.insert(id, component_type); + reader.seek(SeekFrom::Current(4))?; + let size = u16::read_options(reader, endian, ())?; + reader.seek(SeekFrom::Current(size as i64 - 14))?; + } + + reader.seek(SeekFrom::Start(components_pos))?; let mut components = Vec::with_capacity(components_header.element_count as usize); for _ in 0..components_header.element_count { - components.push(UldComponent::read_options(reader, endian, &components)?); + components.push(UldComponent::read_options(reader, endian, &component_types)?); } reader.seek(SeekFrom::Start(primary_pos + primary_header.timeline_offset as u64))?; @@ -100,7 +115,7 @@ impl BinRead for Uld { let widget_header = ListHeader::read_options(reader, endian, ())?; let mut widgets = Vec::with_capacity(widget_header.element_count as usize); for _ in 0..widget_header.element_count { - widgets.push(WidgetData::read_options(reader, endian, &components[..])?); + widgets.push(WidgetData::read_options(reader, endian, &component_types)?); } Ok(Self { @@ -287,7 +302,7 @@ pub struct UldComponent { } impl BinRead for UldComponent { - type Args<'a> = &'a [UldComponent]; + type Args<'a> = &'a std::collections::HashMap; fn read_options(reader: &mut R, endian: binrw::Endian, components: Self::Args<'_>,) -> binrw::BinResult { let pos = reader.stream_position()?; @@ -342,6 +357,7 @@ impl BinWrite for UldComponent { self.component.write_options(writer, endian, ())?; let node_pos = writer.stream_position()?; for node in &self.nodes { + // println!("node {i}; pos {}; {node:#?}\n", writer.stream_position()?); node.write_options(writer, endian, ())?; } @@ -458,7 +474,7 @@ pub struct WidgetData { } impl BinRead for WidgetData { - type Args<'a> = &'a [UldComponent]; + type Args<'a> = &'a std::collections::HashMap; fn read_options(reader: &mut R, endian: binrw::Endian, components: Self::Args<'_>,) -> binrw::BinResult { let pos = reader.stream_position()?; diff --git a/noumenon/src/format/game/uld/node.rs b/noumenon/src/format/game/uld/node.rs index aa5bf40..7bee874 100755 --- a/noumenon/src/format/game/uld/node.rs +++ b/noumenon/src/format/game/uld/node.rs @@ -94,7 +94,7 @@ pub struct NodeData { } impl BinRead for NodeData { - type Args<'a> = &'a [super::UldComponent]; + type Args<'a> = &'a std::collections::HashMap; fn read_options(reader: &mut R, endian: binrw::Endian, components: Self::Args<'_>,) -> binrw::BinResult { let pos = reader.stream_position()?; @@ -277,7 +277,7 @@ impl Default for Node { } impl BinRead for Node { - type Args<'a> = (u32, u16, &'a [super::UldComponent]); + type Args<'a> = (u32, u16, &'a std::collections::HashMap); fn read_options(reader: &mut R, endian: binrw::Endian, (node_type, node_size, components): Self::Args<'_>,) -> binrw::BinResult { Ok(match node_type { @@ -291,7 +291,8 @@ impl BinRead for Node { if node_size <= 88 { Node::Other(node_type) } else if node_type > 1000 { - let component_type = components.iter().find(|c| c.id == node_type).map_or(super::ComponentType::Custom, |v| v.component.get_type()); + // let component_type = components.iter().find(|c| c.id == node_type).map_or(super::ComponentType::Custom, |v| v.component.get_type()); + let component_type = components.get(&node_type).map_or(super::ComponentType::Custom, |v| *v); Node::Component(ComponentNode::read_options(reader, endian, (component_type, node_type))?) } else { let mut unknown_data = vec![0u8; node_size as usize - 88];