/ crates / emtk / src / main.rs
main.rs
 1  mod injector;
 2  
 3  use std::path::PathBuf;
 4  
 5  fn main() -> Result<(), Box<dyn std::error::Error>> {
 6  	let exanima_exe = match std::env::var("EXANIMA_EXE") {
 7  		Ok(var) => PathBuf::from(var),
 8  		Err(_) => PathBuf::from("./Exanima.exe"),
 9  	};
10  	if !exanima_exe.exists() {
11  		panic!("Could not find Exanima.exe\nEither set EXANIMA_EXE to the full path to Exanima.exe or move EMTK into the game folder")
12  	}
13  
14  	let ld_library_path = std::env::var("LD_LIBRARY_PATH").unwrap_or_default();
15  
16  	#[cfg(debug_assertions)]
17  	let emf_dll = {
18  		let path = ld_library_path
19  			.split(':')
20  			.map(|dir| PathBuf::from(dir).join("emf.dll"))
21  			.find(|path| path.exists())
22  			.unwrap_or_else(|| {
23  				panic!("Could not find emf.dll in any of the directories in LD_LIBRARY_PATH")
24  			});
25  		let path = path.canonicalize().unwrap();
26  		let path = path.to_string_lossy();
27  		path.to_string()
28  	};
29  
30  	#[cfg(not(debug_assertions))]
31  	let emf_dll = "emf.dll".to_string();
32  
33  	unsafe {
34  		injector::inject(
35  			&emf_dll,
36  			exanima_exe
37  				.to_str()
38  				.expect("error while looking for Exanima.exe"),
39  		)
40  		.expect("error trying to inject into Exanima.exe");
41  	}
42  	Ok(())
43  }