diff --git a/README.md b/README.md index 64b2f7f..b139a6a 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,35 @@ # hyv-fps-unlocker -Lightweight program for Windows that allows you to modify the FPS of **Honkai Impact 3rd** and **Honkai: Star Rail** by changing registry values. - -Read the blog post about this project (For Hi3 unlocking) [here](https://dromzeh.dev/posts/hi3-fps-unlock/). - -> **Note**: -> Because you're modifying the registry, changing your options in-game **will overwrite the fps to the value you set in-game. To change the fps again, you will have to re-run the program.** +Manipulates registry entries for **Honkai Impact 3rd** and **Honkai: Star Rail**, unlocking the FPS cap. > **Warning**: -> **I am not responsible for any consequences that may occur from using this program.** Use at your own risk. +> I am not responsible for any damage caused to your system. Please use this program at your own risk. ## Download & Usage -## From the releases page - -- Download the latest release from [the releases page](https://github.com/dromzeh/hyv-fps-unlocker/releases) -- Run `hyv-fps-unlocker.exe` and follow the instructions. +### From the Releases Page -## Building +- Download the latest release from [the releases page](https://github.com/dromzeh/hyv-fps-unlocker/releases). +- Run `hyv-fps-unlocker.exe`. -- `git clone https://github.com/dromzeh/hyv-fps-unlocker` -- `cargo build --release` (Assuming you have [Rust](https://rustup.rs/) installed) -- Run the built executable in `./target/release/hyv-fps-unlocker.exe`. +## Building from Source -**You don't have to run the program as Administrator**, if you're having issues, you can try running it as Administrator. +- Clone the repository using `git clone https://github.com/dromzeh/hyv-fps-unlocker`. +- Build the project using `cargo build --release` (assuming you have [Rust](https://rustup.rs/) installed). +- Launch the compiled executable located in `./target/release/hyv-fps-unlocker.exe`. ## Known Issues -### Registry Issues [Can't be fixed] +### Registry Method Limitations -- Modifying the registry values **will NOT work if you have the game open.** -- The game **will overwrite the registry values if you change the FPS in-game.** -- **Options menus for games may not work as intended** after modifying the registry values. +- Altering registry values will be ineffective if the game is currently running. +- The game will overwrite the modified registry value(s) if you update settings in-game. +- Options menus in-game may not function as expected. ## Contributing -Pull requests are welcome. For major changes, please open an issue first. +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. ## License -hyv-fps-unlocker is licensed under [MIT](https://mit.dromzeh.dev/) - see [LICENSE](LICENSE) for more information. +**hyv-fps-unlocker** operates under the [MIT License](https://mit.dromzeh.dev/). Refer to [LICENSE](LICENSE). diff --git a/src/fps_settings.rs b/src/fps_settings.rs index f3e7262..4e33485 100644 --- a/src/fps_settings.rs +++ b/src/fps_settings.rs @@ -7,6 +7,7 @@ use std::error::Error; use std::result::Result; use std::string::String; +/// Prints the current FPS settings for a specified game. pub fn print_current_values(game: &str, json_value: &Value) { match game { "hsr" => println!("Current FPS Value: {}", json_value["FPS"]), @@ -15,6 +16,7 @@ pub fn print_current_values(game: &str, json_value: &Value) { } } +/// Prompts the user for a new FPS value and returns a new JSON value with the updated FPS value. pub fn get_new_fps_settings(game: &str, json_value: &mut Value) -> Result> { let input: String = if game != "hsr" { let fps_options = Text::new("What FPS to set?").prompt(); diff --git a/src/game_selection.rs b/src/game_selection.rs index 4b53c94..b175b17 100644 --- a/src/game_selection.rs +++ b/src/game_selection.rs @@ -4,6 +4,7 @@ use std::error::Error; use std::result::Result; use std::string::String; +/// Prompts the user for a game selection and returns the game abbreviation. pub fn get_game_selection() -> Result> { let games: Vec<&str> = vec!["Honkai: Star Rail", "Honkai Impact 3rd"]; let game_selection: Result<&str, InquireError> = diff --git a/src/main.rs b/src/main.rs index a3c50dc..8569c83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ extern crate winreg; use std::error::Error; use std::result::Result; -use winreg::RegValue; mod fps_settings; mod game_selection; mod message; @@ -28,18 +27,7 @@ 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 = match raw_value::parse_raw_value(&raw_value) { - Ok(value) => value, - Err(_) => { - println!("Failed to parse raw value, attempting to clean and parse again."); - match raw_value::parse_raw_value(&clean_raw_value(&raw_value)) { - Ok(value) => value, - Err(_) => { - return Err("Failed to parse raw value after attempting to clean. You might want to check the registry value manually. If you are sure the value is correct, please open a GitHub issue.".into()); - } - } - } - }; + let mut json_value = raw_value::parse_and_clean_raw_value(&raw_value)?; 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 { @@ -52,18 +40,3 @@ 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(), - } -} diff --git a/src/message.rs b/src/message.rs index fcb1996..92402c2 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2,6 +2,7 @@ use serde_json::Value; use std::io; use std::string::String; +/// Prints the current FPS settings for a specified game. pub fn print_success_message(game: &str, json_value: &Value) { match game { "hsr" => println!("FPS set to {}", json_value["FPS"]), @@ -10,6 +11,7 @@ pub fn print_success_message(game: &str, json_value: &Value) { } } +/// Waits for user input before exiting the program. pub fn wait_for_user_input() { let mut input = String::new(); println!("Press any key to exit"); diff --git a/src/raw_value.rs b/src/raw_value.rs index c62ef80..3fef163 100644 --- a/src/raw_value.rs +++ b/src/raw_value.rs @@ -4,11 +4,13 @@ use std::result::Result; use winreg::enums::*; use winreg::{RegKey, RegValue}; +/// Parses a raw value into a JSON value. pub fn parse_raw_value(raw_value: &RegValue) -> Result> { let json_value: Value = serde_json::from_slice(&raw_value.bytes)?; Ok(json_value) } +/// Writes a new raw value to the registry. pub fn write_new_raw_value( reg_key_path: &str, value_name_contains: &str, @@ -24,3 +26,34 @@ pub fn write_new_raw_value( reg_key.set_raw_value(value_name, new_raw_value)?; Ok(()) } + +/// Parses a raw value into a JSON value, and attempts to clean the raw value if parsing fails. +pub fn parse_and_clean_raw_value(raw_value: &RegValue) -> Result> { + match parse_raw_value(raw_value) { + Ok(value) => Ok(value), + Err(_) => { + println!("Failed to parse raw value, attempting to clean and parse again."); + match parse_raw_value(&clean_raw_value(raw_value)) { + Ok(value) => Ok(value), + Err(_) => { + Err("Failed to parse raw value after attempting to clean. You might want to check the registry value manually. If you are sure the value is correct, please open a GitHub issue.".into()) + } + } + } + } +} + +/// Removes all null bytes from a raw value to "clean" it if parsing fails. +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(), + } +} diff --git a/src/registry_info.rs b/src/registry_info.rs index 6fa8c40..448c7be 100644 --- a/src/registry_info.rs +++ b/src/registry_info.rs @@ -4,6 +4,7 @@ use std::string::String; use winreg::enums::*; use winreg::RegKey; +/// Retrieves the registry key path and value name for a specified game. pub fn get_registry_info(game: &str) -> Result<(String, String), Box> { match game { "hi3" => Ok(( @@ -18,6 +19,7 @@ pub fn get_registry_info(game: &str) -> Result<(String, String), Box> } } +/// Retrieves the raw value for a specified registry key path and value name. pub fn get_raw_value( reg_key_path: &str, value_name_contains: &str,