diff --git a/src-tauri/src/injector.rs b/src-tauri/src/injector.rs index 49ccbd4e..0ba13eaf 100644 --- a/src-tauri/src/injector.rs +++ b/src-tauri/src/injector.rs @@ -86,8 +86,8 @@ pub async fn run_samp( match process { Ok(p) => { // let target_process = .unwrap(); - match inject_dll(p.id(), dll_path, 0) { - Ok(_) => inject_dll(p.id(), omp_file, 0), + match inject_dll(p.id(), dll_path, 0, false) { + Ok(_) => inject_dll(p.id(), omp_file, 0, false), Err(e) => { return Err(e); } @@ -114,7 +114,12 @@ pub async fn run_samp( } #[cfg(target_os = "windows")] -pub fn inject_dll(child: u32, dll_path: &str, times: u32) -> Result<(), String> { +pub fn inject_dll( + child: u32, + dll_path: &str, + times: u32, + waiting_for_vorbis: bool, +) -> Result<(), String> { use winapi::{ shared::minwindef::{FALSE, HMODULE}, um::{ @@ -126,47 +131,49 @@ pub fn inject_dll(child: u32, dll_path: &str, times: u32) -> Result<(), String> match OwnedProcess::from_pid(child) { Ok(p) => { - unsafe { - let handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, child); - let mut module_handles: [HMODULE; 1024] = [0 as *mut _; 1024]; - let mut found = 0; - - EnumProcessModulesEx( - handle, - module_handles.as_mut_ptr(), - module_handles.len() as _, - &mut found, - 0x03, - ); - - let mut bytes = [0i8; 1024]; - - if found == 0 { - let ten_millis = std::time::Duration::from_millis(500); - std::thread::sleep(ten_millis); - return inject_dll(child, dll_path, times); - } + if waiting_for_vorbis { + unsafe { + let handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, child); + let mut module_handles: [HMODULE; 1024] = [0 as *mut _; 1024]; + let mut found = 0; - let mut found_vorbis = false; - for i in 0..(found / 4) { - if GetModuleFileNameExA( + EnumProcessModulesEx( handle, - module_handles[i as usize], - bytes.as_mut_ptr(), - 1024, - ) != 0 - { - let string = std::ffi::CStr::from_ptr(bytes.as_ptr()); - if string.to_string_lossy().to_string().contains("vorbis") { - found_vorbis = true; + module_handles.as_mut_ptr(), + module_handles.len() as _, + &mut found, + 0x03, + ); + + let mut bytes = [0i8; 1024]; + + if found == 0 { + let ten_millis = std::time::Duration::from_millis(500); + std::thread::sleep(ten_millis); + return inject_dll(child, dll_path, times, true); + } + + let mut found_vorbis = false; + for i in 0..(found / 4) { + if GetModuleFileNameExA( + handle, + module_handles[i as usize], + bytes.as_mut_ptr(), + 1024, + ) != 0 + { + let string = std::ffi::CStr::from_ptr(bytes.as_ptr()); + if string.to_string_lossy().to_string().contains("vorbis") { + found_vorbis = true; + } } } - } - if !found_vorbis { - let ten_millis = std::time::Duration::from_millis(500); - std::thread::sleep(ten_millis); - return inject_dll(child, dll_path, times); + if !found_vorbis { + let ten_millis = std::time::Duration::from_millis(500); + std::thread::sleep(ten_millis); + return inject_dll(child, dll_path, times, true); + } } } @@ -177,18 +184,26 @@ pub fn inject_dll(child: u32, dll_path: &str, times: u32) -> Result<(), String> match syringe.inject(dll_path) { Ok(_) => Ok(()), Err(e) => { - let ten_millis = std::time::Duration::from_millis(1000); + let ten_millis = std::time::Duration::from_millis(500); std::thread::sleep(ten_millis); - if times == 10 { + if times == 5 { info!( - "[injector.rs] Dll {} injection failed: {}", + "[injector.rs] Initial DLL {} injection failed: {}", dll_path, e.to_string() ); + + if !waiting_for_vorbis { + return inject_dll(child, dll_path, 0, true); + } Err(format!("Injecting dll failed: {}", e.to_string())) } else { - inject_dll(child, dll_path, times + 1) + if !waiting_for_vorbis { + inject_dll(child, dll_path, times + 1, false) + } else { + inject_dll(child, dll_path, times + 1, true) + } } } } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 966ae2a6..309416f4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -16,6 +16,7 @@ use std::sync::Mutex; use gumdrop::Options; use injector::run_samp; use log::{error, info, LevelFilter}; +// use std::io::Read; use tauri::Manager; use tauri::PhysicalSize; @@ -46,6 +47,12 @@ async fn get_uri_scheme_value() -> String { #[tokio::main] async fn main() { + // let mut f = std::fs::File::open("D:\\Projects\\open.mp\\Launcher-tauri\\omp-launcher\\omp-client.dll").unwrap(); + // let mut contents = Vec::::new(); + // f.read_to_end(&mut contents).unwrap(); + // let digest = md5::compute(contents.as_slice()); + // println!("{:x}", digest); + tauri_plugin_deep_link::prepare("com.open.mp"); simple_logging::log_to_file("omp-launcher.log", LevelFilter::Info).unwrap();