1
Fork 0

auto load struct

This commit is contained in:
Andy Killorin 2025-03-22 15:05:30 -04:00
parent 474841212d
commit 321ece84bc
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
2 changed files with 45 additions and 9 deletions

View file

@ -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 struct Auto {
pub trait Auto { library: Arc<Library>,
// 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<Self> {
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 /// entrypoint
async fn run(interface: &AutoInterface); async fn run(&self, interface: &AutoInterface) {
/// register }
fn default_configs() -> [Configurable];
fn name() -> &'static str; pub fn configs(&self) -> &'static [Configurable] {
self.configs
}
pub fn name(&self) -> &'static str {
self.name
}
} }

View file

@ -2,7 +2,7 @@ use std::{fmt::format, ops::ControlFlow, result, sync::{atomic::Ordering, Arc},
use anyhow::{Context, Ok, Result}; use anyhow::{Context, Ok, Result};
use atomic_float::AtomicF32; 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 common::{ControlPacket, TelemetryPacket};
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use egui_toast::{Toast, ToastKind}; use egui_toast::{Toast, ToastKind};
@ -13,8 +13,17 @@ use tokio::{io::{AsyncReadExt, AsyncWriteExt, BufWriter, WriteHalf}, net::{tcp::
fn main() -> Result<()> { fn main() -> Result<()> {
get_confs().unwrap(); let auto = Auto::new("../auto/target/release/libauto.so")?;
panic!("got too far");
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); let (logging_sender, combatlog) = mpsc::channel(64);