add osu memory reader
This commit is contained in:
@@ -1,8 +1,23 @@
|
||||
mod reading_loop;
|
||||
mod structs;
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
use crate::reading_loop::process_reading_loop;
|
||||
use crate::structs::{State, StaticAddresses};
|
||||
use eyre::Report;
|
||||
use rosu_mem::{
|
||||
error::ProcessError,
|
||||
process::{Process, ProcessTraits},
|
||||
};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::{thread, time::Duration};
|
||||
use structs::{InnerValues, OutputValues};
|
||||
use tauri::Manager;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
println!("starting ezpplauncher!");
|
||||
osu_memory_reading();
|
||||
let mut builder = tauri::Builder::default().plugin(tauri_plugin_fs::init());
|
||||
#[cfg(desktop)]
|
||||
{
|
||||
@@ -21,3 +36,78 @@ pub fn run() {
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
fn osu_memory_reading() {
|
||||
thread::spawn(|| {
|
||||
let output_values = Arc::new(Mutex::new(OutputValues::default()));
|
||||
let inner_values = InnerValues::default();
|
||||
|
||||
let mut state = State {
|
||||
addresses: StaticAddresses::default(),
|
||||
ivalues: inner_values,
|
||||
values: output_values,
|
||||
};
|
||||
|
||||
'init_loop: loop {
|
||||
println!("Searching for osu! process");
|
||||
let p = match Process::initialize("osu!.exe") {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
println!("{:?}", Report::new(e));
|
||||
thread::sleep(Duration::from_millis(5000));
|
||||
continue 'init_loop;
|
||||
}
|
||||
};
|
||||
|
||||
println!("Reading static signatures...");
|
||||
match StaticAddresses::new(&p) {
|
||||
Ok(v) => state.addresses = v,
|
||||
Err(e) => {
|
||||
match e.downcast_ref::<ProcessError>() {
|
||||
Some(&ProcessError::ProcessNotFound) => {
|
||||
thread::sleep(Duration::from_millis(2000));
|
||||
continue 'init_loop
|
||||
},
|
||||
#[cfg(target_os = "windows")]
|
||||
Some(&ProcessError::OsError{ .. }) => {
|
||||
println!("{:?}", e);
|
||||
thread::sleep(Duration::from_millis(2000));
|
||||
continue 'init_loop
|
||||
},
|
||||
Some(_) | None => {
|
||||
println!("{:?}", e);
|
||||
thread::sleep(Duration::from_millis(2000));
|
||||
continue 'init_loop
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
println!("osu! process found, Starting reading loop");
|
||||
|
||||
'main_loop: loop {
|
||||
if let Err(e) = process_reading_loop(&p, &mut state) {
|
||||
match e.downcast_ref::<ProcessError>() {
|
||||
Some(&ProcessError::ProcessNotFound) => {
|
||||
thread::sleep(Duration::from_millis(5000));
|
||||
continue 'init_loop;
|
||||
},
|
||||
#[cfg(target_os = "windows")]
|
||||
Some(&ProcessError::OsError{ .. }) => {
|
||||
println!("{:?}", e);
|
||||
thread::sleep(Duration::from_millis(5000));
|
||||
continue 'init_loop
|
||||
},
|
||||
Some(_) | None => {
|
||||
println!("{:?}", e);
|
||||
thread::sleep(Duration::from_millis(5000));
|
||||
continue 'main_loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("{:?}", state.values.clone());
|
||||
thread::sleep(Duration::from_millis(2000));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user