From 190adb1d52de1cb52e1e79ec48375a240dbf0bc0 Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Sun, 18 Jun 2023 16:10:22 -0600 Subject: [PATCH] Redirect more domains --- src-tauri/lang/en.json | 2 +- src-tauri/src/config.rs | 1 + src-tauri/src/main.rs | 5 +- src-tauri/src/proxy.rs | 97 ++++++++++++++++++++++++------ src/ui/components/menu/Options.tsx | 15 +++++ src/utils/configuration.ts | 2 + 6 files changed, 101 insertions(+), 21 deletions(-) diff --git a/src-tauri/lang/en.json b/src-tauri/lang/en.json index 10eef33..c10e504 100644 --- a/src-tauri/lang/en.json +++ b/src-tauri/lang/en.json @@ -9,7 +9,7 @@ "port_placeholder": "Port...", "files_downloading": "Files Downloading: ", "files_extracting": "Files Extracting: ", - "game_path_notify": "Game path not found, remember to set it in !" + "game_path_notify": "Game path not found, remember to set it in settings!" }, "options": { "enabled": "Enabled", diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index db8ef96..93c7214 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -26,6 +26,7 @@ pub struct Configuration { pub horny_mode: Option, pub auto_mongodb: Option, pub un_elevated: Option, + pub redirect_more: Option, } pub fn config_path() -> PathBuf { diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 945e2bc..a03706d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -230,12 +230,11 @@ fn main() -> Result<(), ArgsError> { gamebanana::list_submissions, gamebanana::list_mods ]) - .on_window_event(|event| match event.event() { - tauri::WindowEvent::CloseRequested { api, .. } => { + .on_window_event(|event| { + if let tauri::WindowEvent::CloseRequested { .. } = event.event() { // Ensure all proxy stuff is handled disconnect(); } - _ => {} }) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src-tauri/src/proxy.rs b/src-tauri/src/proxy.rs index 3aa6666..b0e394a 100644 --- a/src-tauri/src/proxy.rs +++ b/src-tauri/src/proxy.rs @@ -3,6 +3,7 @@ * https://github.com/omjadas/hudsucker/blob/main/examples/log.rs */ +use crate::config::get_config; #[cfg(target_os = "linux")] use crate::system_helpers::run_command; @@ -60,24 +61,86 @@ impl HttpHandler for ProxyHandler { ) -> RequestOrResponse { let uri = req.uri().to_string(); - if uri.contains("hoyoverse.com") || uri.contains("mihoyo.com") || uri.contains("yuanshen.com") { - // Handle CONNECTs - if req.method().as_str() == "CONNECT" { - let builder = Response::builder() - .header("DecryptEndpoint", "Created") - .status(StatusCode::OK); - let res = builder.body(()).unwrap(); + match get_config().redirect_more { + Some(true) => { + if uri.contains("hoyoverse.com") + || uri.contains("mihoyo.com") + || uri.contains("yuanshen.com") + || uri.contains("starrails.com") + || uri.contains("bhsr.com") + || uri.contains("bh3.com") + || uri.contains("honkaiimpact3.com") + { + // Handle CONNECTs + if req.method().as_str() == "CONNECT" { + let builder = Response::builder() + .header("DecryptEndpoint", "Created") + .status(StatusCode::OK); + let res = builder.body(()).unwrap(); - // Respond to CONNECT - *res.body() - } else { - let uri_path_and_query = req.uri().path_and_query().unwrap().as_str(); - // Create new URI. - let new_uri = - Uri::from_str(format!("{}{}", SERVER.lock().unwrap(), uri_path_and_query).as_str()) - .unwrap(); - // Set request URI to the new one. - *req.uri_mut() = new_uri; + // Respond to CONNECT + *res.body() + } else { + let uri_path_and_query = req.uri().path_and_query().unwrap().as_str(); + // Create new URI. + let new_uri = + Uri::from_str(format!("{}{}", SERVER.lock().unwrap(), uri_path_and_query).as_str()) + .unwrap(); + // Set request URI to the new one. + *req.uri_mut() = new_uri; + } + } + } + Some(false) => { + if uri.contains("hoyoverse.com") + || uri.contains("mihoyo.com") + || uri.contains("yuanshen.com") + { + // Handle CONNECTs + if req.method().as_str() == "CONNECT" { + let builder = Response::builder() + .header("DecryptEndpoint", "Created") + .status(StatusCode::OK); + let res = builder.body(()).unwrap(); + + // Respond to CONNECT + *res.body() + } else { + let uri_path_and_query = req.uri().path_and_query().unwrap().as_str(); + // Create new URI. + let new_uri = + Uri::from_str(format!("{}{}", SERVER.lock().unwrap(), uri_path_and_query).as_str()) + .unwrap(); + // Set request URI to the new one. + *req.uri_mut() = new_uri; + } + } + } + // Use default as fallback + None => { + if uri.contains("hoyoverse.com") + || uri.contains("mihoyo.com") + || uri.contains("yuanshen.com") + { + // Handle CONNECTs + if req.method().as_str() == "CONNECT" { + let builder = Response::builder() + .header("DecryptEndpoint", "Created") + .status(StatusCode::OK); + let res = builder.body(()).unwrap(); + + // Respond to CONNECT + *res.body() + } else { + let uri_path_and_query = req.uri().path_and_query().unwrap().as_str(); + // Create new URI. + let new_uri = + Uri::from_str(format!("{}{}", SERVER.lock().unwrap(), uri_path_and_query).as_str()) + .unwrap(); + // Set request URI to the new one. + *req.uri_mut() = new_uri; + } + } } } diff --git a/src/ui/components/menu/Options.tsx b/src/ui/components/menu/Options.tsx index b0660ed..5d9c59f 100644 --- a/src/ui/components/menu/Options.tsx +++ b/src/ui/components/menu/Options.tsx @@ -42,6 +42,7 @@ interface IState { swag: boolean platform: string un_elevated: boolean + redirect_more: boolean // Swag stuff akebi_path: string @@ -72,6 +73,7 @@ export default class Options extends React.Component { auto_mongodb: false, platform: '', un_elevated: false, + redirect_more: false, // Swag stuff akebi_path: '', @@ -123,6 +125,7 @@ export default class Options extends React.Component { auto_mongodb: config.auto_mongodb || false, platform, un_elevated: config.un_elevated || false, + redirect_more: config.redirect_more || false, // Swag stuff akebi_path: config.akebi_path || '', @@ -388,6 +391,18 @@ export default class Options extends React.Component { /> + diff --git a/src/utils/configuration.ts b/src/utils/configuration.ts index 662c1ac..ad7b997 100644 --- a/src/utils/configuration.ts +++ b/src/utils/configuration.ts @@ -26,6 +26,7 @@ let defaultConfig: Configuration horny_mode: false, auto_mongodb: false, un_elevated: false, + redirect_more: false, } })() @@ -55,6 +56,7 @@ export interface Configuration { swag_mode?: boolean auto_mongodb: boolean un_elevated: boolean + redirect_more: boolean // Swag stuff akebi_path?: string