diff --git a/src/lib.rs b/src/lib.rs index 70b725b..c80b878 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,8 +13,7 @@ mod hooks; mod utils; mod watchdog; -use log::LevelFilter; -use log::{error, info, trace}; +use log::{debug, error, info}; use crate::config::CONFIG; use crate::dictionary::DICTIONARY; @@ -26,18 +25,15 @@ extern "C" fn attach() { // unsafe { // crash::install(); // } - if CONFIG.settings.watchdog { - watchdog::install(); - } - simple_logging::log_to_file(&CONFIG.settings.log_file, LevelFilter::Trace).unwrap(); + simple_logging::log_to_file(&CONFIG.settings.log_file, utils::log_level(CONFIG.settings.log_level)).unwrap(); if CONFIG.metadata.name != "dfint localization hook" { error!("unable to find config file"); utils::message_box( - "unable to find config file", + "Unable to find config file, translation unavaible", "dfint hook error", utils::MessageIconType::Error, ); - std::process::exit(2); + return; } info!("pe checksum: 0x{:x}", CONFIG.offset_metadata.checksum); info!("offsets version: {}", CONFIG.offset_metadata.version); @@ -47,10 +43,21 @@ extern "C" fn attach() { CONFIG.settings.dictionary, DICTIONARY.size() ); - unsafe { - hooks::attach_all().unwrap(); + match unsafe { hooks::attach_all() } { + Ok(_) => debug!("hooks attached"), + Err(err) => { + error!("unable to attach hooks, {:?}", err); + utils::message_box( + "Unable to attach hooks, translation unavaible", + "dfint hook error", + utils::MessageIconType::Error, + ); + return; + } + }; + if CONFIG.settings.watchdog { + watchdog::install(); } - trace!("hooks attached"); } #[static_init::destructor] @@ -58,8 +65,7 @@ extern "C" fn attach() { extern "C" fn detach() { unsafe { match hooks::disable_all() { - _ => (), + _ => debug!("hooks detached"), }; } - trace!("hooks detached"); } diff --git a/src/utils.rs b/src/utils.rs index c538b24..b535ed1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -147,3 +147,15 @@ pub static UTF_TO_CP1251: std::collections::HashMap = HashMap::from([ (36560, 161), (40657, 162), ]); + +pub fn log_level(level: usize) -> log::LevelFilter { + match level { + 0 => log::LevelFilter::Trace, + 1 => log::LevelFilter::Debug, + 2 => log::LevelFilter::Info, + 3 => log::LevelFilter::Warn, + 4 => log::LevelFilter::Error, + 5 => log::LevelFilter::Off, + _ => log::LevelFilter::Info, + } +}