From 321ece84bc730ed434d35512c415cfc15ad6df97 Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Sat, 22 Mar 2025 15:05:30 -0400 Subject: [PATCH] auto load struct --- interface/src/auto.rs | 39 +++++++++++++++++++++++++++++++++------ interface/src/main.rs | 15 ++++++++++++--- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/interface/src/auto.rs b/interface/src/auto.rs index 283884b..2a954f3 100644 --- a/interface/src/auto.rs +++ b/interface/src/auto.rs @@ -93,13 +93,40 @@ impl Default for Configurable { } } -/// A fake trait in the sense that these methods are exposed as symbols, not trait methods -pub trait Auto { +pub struct Auto { + library: Arc, + // these aren't actually static, they have the same lifetime as the library xP + configs: &'static [Configurable], + name: &'static str, +} + +impl Auto { + pub fn new(path: &str) -> Result { + let lib = unsafe {Library::new(path)?}; + let lib = Arc::new(lib); + + let configurations: Symbol<&&[Configurable]> = unsafe {lib.get(b"CONFIGS").unwrap()}; + + let name: Symbol<&&'static str> = unsafe {lib.get(b"NAME").unwrap()}; + + + Ok(Self { + configs: *configurations, + name: *name, + library: lib, + }) + + } /// entrypoint - async fn run(interface: &AutoInterface); - /// register - fn default_configs() -> [Configurable]; - fn name() -> &'static str; + async fn run(&self, interface: &AutoInterface) { + } + + pub fn configs(&self) -> &'static [Configurable] { + self.configs + } + pub fn name(&self) -> &'static str { + self.name + } } diff --git a/interface/src/main.rs b/interface/src/main.rs index e99953f..4443fd1 100644 --- a/interface/src/main.rs +++ b/interface/src/main.rs @@ -2,7 +2,7 @@ use std::{fmt::format, ops::ControlFlow, result, sync::{atomic::Ordering, Arc}, use anyhow::{Context, Ok, Result}; use atomic_float::AtomicF32; -use interface::{auto::get_confs, combatlog::{combat_logger, CombatData}, POWER_THRESHOLD}; +use interface::{auto::{get_confs, Auto}, combatlog::{combat_logger, CombatData}, POWER_THRESHOLD}; use common::{ControlPacket, TelemetryPacket}; use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use egui_toast::{Toast, ToastKind}; @@ -13,8 +13,17 @@ use tokio::{io::{AsyncReadExt, AsyncWriteExt, BufWriter, WriteHalf}, net::{tcp:: fn main() -> Result<()> { - get_confs().unwrap(); - panic!("got too far"); + let auto = Auto::new("../auto/target/release/libauto.so")?; + + println!("name: {}", auto.name()); + + for config in auto.configs().iter() { + println!("co {}", config.name); + println!("co {:?}", config.description); + } + + + let (logging_sender, combatlog) = mpsc::channel(64);