diff --git a/src/main.rs b/src/main.rs index de99cc3..76205f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ extern crate winreg; use std::error::Error; +use winreg::RegValue; use std::result::Result; mod fps_settings; mod game_selection; @@ -27,7 +28,18 @@ fn run_program() -> Result<(), Box> { let game = game_selection::get_game_selection()?; let (reg_key_path, value_name_contains) = registry_info::get_registry_info(&game)?; let raw_value = registry_info::get_raw_value(®_key_path, &value_name_contains)?; - let mut json_value = raw_value::parse_raw_value(&raw_value)?; + let mut json_value = match raw_value::parse_raw_value(&raw_value) { + Ok(value) => value, + Err(_) => { + println!("Failed to parse value, attempting to clean value..."); + match raw_value::parse_raw_value(&clean_raw_value(&raw_value)) { + Ok(value) => value, + Err(_) => { + return Err("Failed to parse raw value after cleaning".into()); + } + } + } + }; fps_settings::print_current_values(&game, &json_value); let new_json_value = fps_settings::get_new_fps_settings(&game, &mut json_value)?; let new_raw_value = winreg::RegValue { @@ -40,3 +52,18 @@ fn run_program() -> Result<(), Box> { Ok(()) } + +// remove null bytes from raw value +fn clean_raw_value(raw_value: &RegValue) -> RegValue { + let mut bytes = raw_value.bytes.clone(); + let mut new_bytes = Vec::new(); + for byte in bytes.iter_mut() { + if *byte != 00 { + new_bytes.push(*byte); + } + } + RegValue { + bytes: new_bytes, + vtype: raw_value.vtype.clone(), + } +} \ No newline at end of file diff --git a/src/registry_info.rs b/src/registry_info.rs index 68c857e..6fa8c40 100644 --- a/src/registry_info.rs +++ b/src/registry_info.rs @@ -23,19 +23,16 @@ pub fn get_raw_value( value_name_contains: &str, ) -> Result> { let hkcu = RegKey::predef(HKEY_CURRENT_USER); - // println!("Opening {:?} \n", reg_key_path); let reg_key = hkcu.open_subkey_with_flags(reg_key_path, KEY_ALL_ACCESS)?; - // println!("Opened {:?} \n", reg_key_path); let values = reg_key .enum_values() .map(|x| x.unwrap().0) .collect::>(); - // println!("Found values: {:?} \n", values); let value_name = values .iter() .find(|&x| x.contains(value_name_contains)) .ok_or_else(|| format!("Value {} not found", value_name_contains))?; - // println!("Found {} at {:?} \n", value_name_contains, value_name); + println!("Found {} at {:?} \n", value_name_contains, value_name); reg_key .get_raw_value(value_name) .map_err(|e| format!("Failed to get raw value: {}", e).into())