Skip to content

Commit

Permalink
fix uld reader, disable lots on no feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevii77 committed Nov 11, 2024
1 parent 1443a48 commit a967108
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 29 deletions.
6 changes: 3 additions & 3 deletions aetherment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
Expand All @@ -27,5 +27,5 @@ base32 = "0.5.0"
base64 = "0.22.1"

[features]
client = ["renderer/egui"]
plugin = ["renderer/imgui"]
client = ["dep:renderer", "renderer/egui"]
plugin = ["dep:renderer", "renderer/imgui"]
18 changes: 10 additions & 8 deletions aetherment/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<config::ConfigManager> = None;
Expand All @@ -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<Box<dyn modman::backend::Backend>> = None;
#[cfg(any(feature = "plugin", feature = "client"))]
pub fn backend() -> &'static mut Box<dyn modman::backend::Backend> {
unsafe{BACKEND.as_mut().unwrap()}
}
Expand All @@ -53,6 +53,7 @@ pub fn json_pretty<T: serde::Serialize>(data: &T) -> Result<String, serde_json::
Ok(String::from_utf8(serializer.into_inner()).unwrap())
}

#[cfg(any(feature = "plugin", feature = "client"))]
pub struct Core {
mods_tab: view::mods::Mods,
browser_tab: view::browser::Browser,
Expand All @@ -67,6 +68,7 @@ pub struct Core {
apply_progress: crate::modman::backend::ApplyProgress,
}

#[cfg(any(feature = "plugin", feature = "client"))]
impl Core {
pub fn new(log: fn(log::LogType, String), backend_initializers: modman::backend::BackendInitializers, issue_initializers: modman::issue::IssueInitializers, optional_initializers: modman::meta::OptionalInitializers) -> Self {
unsafe {
Expand Down
5 changes: 3 additions & 2 deletions aetherment/src/modman/backend/penumbra_ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,16 @@ 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();
for id in mod_list().into_iter() {
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;
Expand Down
6 changes: 5 additions & 1 deletion aetherment/src/modman/issue.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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()};
Expand Down Expand Up @@ -63,13 +64,16 @@ impl Issue {

// ----------

#[cfg(any(feature = "plugin", feature = "client"))]
pub struct IssueInitializers {
pub ui_resolution: Box<dyn Fn() -> u8>,
pub ui_theme: Box<dyn Fn() -> u8>,
pub collection: Box<dyn Fn(super::backend::CollectionType) -> super::backend::Collection>,
}

#[cfg(any(feature = "plugin", feature = "client"))]
static mut FUNCS: Option<IssueInitializers> = None;
#[cfg(any(feature = "plugin", feature = "client"))]
pub(crate) fn initialize(funcs: IssueInitializers) {
unsafe{FUNCS = Some(funcs)}
}
2 changes: 1 addition & 1 deletion aetherment/src/modman/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion aetherment/src/render_helper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use renderer::*;
#[cfg(any(feature = "plugin", feature = "client"))] use renderer::*;

pub trait EnumTools {
type Iterator: core::iter::Iterator<Item = Self>;
Expand All @@ -12,6 +12,7 @@ pub trait UiExt {
fn combo_enum<S: AsRef<str>, 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<S: AsRef<str>, Enum: EnumTools + PartialEq>(&mut self, label: S, val: &mut Enum) -> bool {
let mut changed = false;
Expand Down
10 changes: 5 additions & 5 deletions noumenon/src/format/game/tex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl Tiff for Tex {
}

impl Tga for Tex {
fn read<T>(reader: &mut T) -> Result<Self, Error> where
fn read<T>(reader: &mut T) -> Result<Self, Error> where
T: Read + Seek {
let img = image::io::Reader::with_format(BufReader::new(reader), image::ImageFormat::Tga)
.decode()?;
Expand All @@ -400,9 +400,9 @@ impl Tga for Tex {
},
data: img.into_rgba8().into_vec(),
})
}

fn write<T>(&self, writer: &mut T) -> Result<(), Error> where
}
fn write<T>(&self, writer: &mut T) -> Result<(), Error> where
T: Write + Seek {
let img = TgaEncoder::new(writer);
img.write_image(
Expand All @@ -413,5 +413,5 @@ impl Tga for Tex {
)?;

Ok(())
}
}
}
26 changes: 21 additions & 5 deletions noumenon/src/format/game/uld.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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))?;
Expand All @@ -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 {
Expand Down Expand Up @@ -287,7 +302,7 @@ pub struct UldComponent {
}

impl BinRead for UldComponent {
type Args<'a> = &'a [UldComponent];
type Args<'a> = &'a std::collections::HashMap<u32, ComponentType>;

fn read_options<R: Read + Seek>(reader: &mut R, endian: binrw::Endian, components: Self::Args<'_>,) -> binrw::BinResult<Self> {
let pos = reader.stream_position()?;
Expand Down Expand Up @@ -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, ())?;
}

Expand Down Expand Up @@ -458,7 +474,7 @@ pub struct WidgetData {
}

impl BinRead for WidgetData {
type Args<'a> = &'a [UldComponent];
type Args<'a> = &'a std::collections::HashMap<u32, ComponentType>;

fn read_options<R: Read + Seek>(reader: &mut R, endian: binrw::Endian, components: Self::Args<'_>,) -> binrw::BinResult<Self> {
let pos = reader.stream_position()?;
Expand Down
7 changes: 4 additions & 3 deletions noumenon/src/format/game/uld/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct NodeData {
}

impl BinRead for NodeData {
type Args<'a> = &'a [super::UldComponent];
type Args<'a> = &'a std::collections::HashMap<u32, super::ComponentType>;

fn read_options<R: Read + Seek>(reader: &mut R, endian: binrw::Endian, components: Self::Args<'_>,) -> binrw::BinResult<Self> {
let pos = reader.stream_position()?;
Expand Down Expand Up @@ -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<u32, super::ComponentType>);

fn read_options<R: Read + Seek>(reader: &mut R, endian: binrw::Endian, (node_type, node_size, components): Self::Args<'_>,) -> binrw::BinResult<Self> {
Ok(match node_type {
Expand All @@ -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];
Expand Down

0 comments on commit a967108

Please sign in to comment.