Skip to content

Commit

Permalink
comments, cleanup, rewrite readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dromzeh committed Sep 23, 2023
1 parent 7b13495 commit 28c34a3
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 50 deletions.
37 changes: 15 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 2 additions & 0 deletions src/fps_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
Expand All @@ -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<Value, Box<dyn Error>> {
let input: String = if game != "hsr" {
let fps_options = Text::new("What FPS to set?").prompt();
Expand Down
1 change: 1 addition & 0 deletions src/game_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Box<dyn Error>> {
let games: Vec<&str> = vec!["Honkai: Star Rail", "Honkai Impact 3rd"];
let game_selection: Result<&str, InquireError> =
Expand Down
29 changes: 1 addition & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,18 +27,7 @@ fn run_program() -> Result<(), Box<dyn Error>> {
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(&reg_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 {
Expand All @@ -52,18 +40,3 @@ fn run_program() -> Result<(), Box<dyn Error>> {

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(),
}
}
2 changes: 2 additions & 0 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
Expand All @@ -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");
Expand Down
33 changes: 33 additions & 0 deletions src/raw_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value, Box<dyn Error>> {
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,
Expand All @@ -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<Value, Box<dyn Error>> {
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(),
}
}
2 changes: 2 additions & 0 deletions src/registry_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Error>> {
match game {
"hi3" => Ok((
Expand All @@ -18,6 +19,7 @@ pub fn get_registry_info(game: &str) -> Result<(String, String), Box<dyn Error>>
}
}

/// 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,
Expand Down

0 comments on commit 28c34a3

Please sign in to comment.