use std::error::Error;
use std::fmt;
use std::mem;
use std::process::Command;
use std::thread::sleep;
use std::time::Duration;
pub fn inject_dll() -> Result<InjectorCode, Box<Error>> {
let code = Command::new("RLBot_Injector")
.arg("hidden")
.status()?
.code()
.unwrap();
let code: InjectorCode = unsafe { mem::transmute(code) };
match code {
InjectorCode::InjectionSuccessful => {
sleep(Duration::from_secs(20));
Ok(code)
}
InjectorCode::RLBotDLLAlreadyInjected => Ok(code),
_ => Err(From::from(code)),
}
}
#[allow(dead_code)]
#[derive(Debug, Eq, PartialEq)]
#[repr(i32)]
pub enum InjectorCode {
InjectionSuccessful = 0,
InjectionFailed = 1,
MultipleRocketLeagueProcessesFound = 2,
RLBotDLLAlreadyInjected = 3,
RLBotDLLNotFound = 4,
MultipleRLBotDLLFilesFound = 5,
}
impl Error for InjectorCode {}
impl fmt::Display for InjectorCode {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fmt::Debug::fmt(self, f)
}
}