From 28269c5d755836f87c0c1bec7cc4ed08aa10a42f Mon Sep 17 00:00:00 2001 From: akanyan Date: Fri, 11 Apr 2025 23:07:45 +0000 Subject: [PATCH] feat: hardware aime --- rust/Cargo.lock | 125 +++++++++++++++++++++++++------- rust/Cargo.toml | 4 +- rust/src/appdata.rs | 2 +- rust/src/cmd.rs | 17 ++++- rust/src/download_handler.rs | 4 +- rust/src/lib.rs | 62 +++++++++++++--- rust/src/model/misc.rs | 26 ++++++- rust/src/model/profile.rs | 2 + rust/src/modules/segatools.rs | 27 ++++++- rust/src/profiles/mod.rs | 9 ++- src/components/App.vue | 22 +++--- src/components/options/Aime.vue | 43 +++++++++-- src/types.ts | 1 + 13 files changed, 276 insertions(+), 68 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 27467dc..08115f5 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -803,7 +803,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] @@ -1454,6 +1454,16 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "fern" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4316185f709b23713e41e3195f90edef7fb00c3ed4adc79769cf09cc762a3b29" +dependencies = [ + "colored", + "log", +] + [[package]] name = "field-offset" version = "0.3.6" @@ -2143,6 +2153,12 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" +[[package]] +name = "humantime" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f" + [[package]] name = "hyper" version = "1.6.0" @@ -2442,6 +2458,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "io-kit-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "617ee6cf8e3f66f3b4ea67a4058564628cde41901316e19f559e14c7c72c5e7b" +dependencies = [ + "core-foundation-sys", + "mach2", +] + [[package]] name = "ipnet" version = "2.11.0" @@ -2696,6 +2722,26 @@ dependencies = [ "redox_syscall", ] +[[package]] +name = "libudev" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b324152da65df7bb95acfcaab55e3097ceaab02fb19b228a9eb74d55f135e0" +dependencies = [ + "libc", + "libudev-sys", +] + +[[package]] +name = "libudev-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324" +dependencies = [ + "libc", + "pkg-config", +] + [[package]] name = "linux-raw-sys" version = "0.4.15" @@ -2766,6 +2812,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + [[package]] name = "markup5ever" version = "0.11.0" @@ -2917,6 +2972,17 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "nix" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", +] + [[package]] name = "nix" version = "0.29.0" @@ -2972,15 +3038,6 @@ dependencies = [ "syn 2.0.100", ] -[[package]] -name = "num_threads" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" -dependencies = [ - "libc", -] - [[package]] name = "objc-sys" version = "0.3.5" @@ -4459,6 +4516,25 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "serialport" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2daa7abb9b965493e3c8f4184c6f46435484ff2538a332b886788cf6768b927b" +dependencies = [ + "bitflags 2.9.0", + "cfg-if", + "core-foundation 0.10.0", + "core-foundation-sys", + "io-kit-sys", + "libudev", + "mach2", + "nix 0.26.4", + "scopeguard", + "unescaper", + "winapi", +] + [[package]] name = "servo_arc" version = "0.1.1" @@ -4544,18 +4620,6 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" -[[package]] -name = "simple_logger" -version = "5.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c5dfa5e08767553704aa0ffd9d9794d527103c736aba9854773851fd7497eb" -dependencies = [ - "colored", - "log", - "time", - "windows-sys 0.48.0", -] - [[package]] name = "siphasher" version = "0.3.11" @@ -4660,8 +4724,10 @@ dependencies = [ "directories", "displayz", "enumflags2", + "fern", "flate2", "futures", + "humantime", "junction", "log", "regex", @@ -4671,8 +4737,8 @@ dependencies = [ "serde_derive", "serde_json", "serde_json5", + "serialport", "sha256", - "simple_logger", "tauri", "tauri-build", "tauri-plugin-cli", @@ -5406,9 +5472,7 @@ checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" dependencies = [ "deranged", "itoa 1.0.15", - "libc", "num-conv", - "num_threads", "powerfmt", "serde", "time-core", @@ -5727,6 +5791,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "unescaper" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c878a167baa8afd137494101a688ef8c67125089ff2249284bd2b5f9bfedb815" +dependencies = [ + "thiserror 1.0.69", +] + [[package]] name = "unic-char-property" version = "0.9.0" @@ -6845,7 +6918,7 @@ dependencies = [ "futures-core", "futures-lite", "hex", - "nix", + "nix 0.29.0", "ordered-stream", "serde", "serde_repr", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 425ac32..0f50f33 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -28,7 +28,6 @@ futures = "0.3.31" tauri-plugin-shell = "2" directories = "6.0.0" rust-ini = "0.21.1" -simple_logger = "5.0.0" log = "0.4.25" regex = "1.11.1" zip = "2.2.2" @@ -43,6 +42,9 @@ tauri-plugin-fs = "2" yaml-rust2 = "0.10.0" enumflags2 = { version = "0.7.11", features = ["serde"] } sha256 = "1.6.0" +serialport = "4.7.1" +fern = { version ="0.7.1", features = ["colored"] } +humantime = "2.2.0" [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] tauri-plugin-cli = "2" diff --git a/rust/src/appdata.rs b/rust/src/appdata.rs index a265db7..9bc0649 100644 --- a/rust/src/appdata.rs +++ b/rust/src/appdata.rs @@ -43,7 +43,7 @@ impl AppData { .map_err(|e| log::error!("unable to load patch set: {e}")) .unwrap_or_default(); - log::debug!("Recent profile: {:?}", profile); + log::info!("recent profile: {:?}", profile); AppData { profile: profile, diff --git a/rust/src/cmd.rs b/rust/src/cmd.rs index ca131ed..360f0f2 100644 --- a/rust/src/cmd.rs +++ b/rust/src/cmd.rs @@ -1,6 +1,6 @@ use ini::Ini; use log; -use std::collections::HashMap; +use std::collections::{BTreeMap, HashMap}; use std::path::PathBuf; use tokio::sync::Mutex; use tokio::fs; @@ -445,6 +445,21 @@ pub async fn file_exists(path: String) -> Result { Ok(std::fs::exists(path).unwrap_or(false)) } +#[tauri::command] +pub async fn list_com_ports() -> Result, String> { + let ports = serialport::available_ports().unwrap_or(Vec::new()); + let mut res = BTreeMap::new(); + for p in ports { + log::debug!("port {}", p.port_name); + if p.port_name.starts_with("COM") { + if let Ok(parsed) = (p.port_name[3..]).parse() { + res.insert(p.port_name, parsed); + } + } + } + Ok(res) +} + #[tauri::command] pub async fn list_patches(state: State<'_, Mutex>, target: String) -> Result, String> { log::debug!("invoke: list_patches({})", target); diff --git a/rust/src/download_handler.rs b/rust/src/download_handler.rs index 233424c..524fe7e 100644 --- a/rust/src/download_handler.rs +++ b/rust/src/download_handler.rs @@ -43,7 +43,7 @@ impl DownloadHandler { let mut cache_file_w = File::create(&zip_path_part).await?; let mut byte_stream = reqwest::get(&rmt.download_url).await?.bytes_stream(); - log::info!("Downloading: {}", rmt.download_url); + log::info!("downloading: {}", rmt.download_url); while let Some(item) = byte_stream.next().await { let i = item?; cache_file_w.write_all(&mut i.as_ref()).await?; @@ -51,7 +51,7 @@ impl DownloadHandler { cache_file_w.sync_all().await?; tokio::fs::rename(&zip_path_part, &zip_path).await?; - log::debug!("Downloaded to {:?}", zip_path); + log::debug!("downloaded to {:?}", zip_path); app.emit("download-end", pkg_key)?; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index d146335..e015168 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -9,10 +9,11 @@ mod modules; mod profiles; mod patcher; -use std::sync::OnceLock; +use std::{sync::OnceLock, time::SystemTime}; use anyhow::anyhow; use closure::closure; use appdata::{AppData, ToggleAction}; +use fern::colors::{Color, ColoredLevelConfig}; use model::misc::Game; use pkg::PkgKey; use pkg_store::Payload; @@ -26,16 +27,6 @@ static EXIT_REQUESTED: OnceLock<()> = OnceLock::new(); #[cfg_attr(mobile, tauri::mobile_entry_point)] pub async fn run(_args: Vec) { - simple_logger::init_with_env().expect("Unable to initialize the logger"); - - log::info!( - "Running from {}", - std::env::current_dir() - .unwrap_or_default() - .to_str() - .unwrap_or_default() - ); - let tauri = tauri::Builder::default() .plugin(tauri_plugin_updater::Builder::new().build()) .plugin(tauri_plugin_single_instance::init(|app, args, _cwd| { @@ -58,6 +49,51 @@ pub async fn run(_args: Vec) { util::init_dirs(&apph); + let mut fern_builder; + { + let colors = ColoredLevelConfig::new() + .debug(Color::Green) + .info(Color::Blue) + .warn(Color::Yellow) + .error(Color::Red); + + fern_builder = fern::Dispatch::new() + .format(move |out, message, record| { + out.finish(format_args!( + "[{} {} {}] {}", + humantime::format_rfc3339_seconds(SystemTime::now()), + colors.color(record.level()), + record.target(), + message + )) + }) + .chain(std::io::stdout()) + .chain(fern::log_file(util::data_dir().join("log.txt")).expect("unable to initialize the logger")); + } + + #[cfg(debug_assertions)] + { + fern_builder = fern_builder.level(log::LevelFilter::Debug); + } + #[cfg(not(debug_assertions))] + { + if std::env::var("DEBUG_LOG") { + fern_builder = fern_builder.level(log::LevelFilter::Debug); + } else { + fern_builder = fern_builder.level(log::LevelFilter::Info); + } + } + + fern_builder.apply()?; + + log::info!( + "running from {}", + std::env::current_dir() + .unwrap_or_default() + .to_str() + .unwrap_or_default() + ); + let mut app_data = AppData::new(app.handle().clone()); let start_immediately; @@ -210,6 +246,8 @@ pub async fn run(_args: Vec) { cmd::list_directories, cmd::file_exists, + cmd::list_com_ports, + cmd::list_patches ]) .build(tauri::generate_context!()) @@ -245,7 +283,7 @@ fn deep_link(app: AppHandle, args: Vec) { let url = &args[1]; let proto = "rainycolor://"; if &url[..proto.len()] == proto { - log::info!("Deep link: {}", url); + log::info!("deep link: {}", url); let regex = regex::Regex::new( r"rainycolor://v1/install/rainy\.patafour\.zip/([^/]+)/([^/]+)/[0-9]+\.[0-9]+\.[0-9]+/" diff --git a/rust/src/model/misc.rs b/rust/src/model/misc.rs index ebbedfa..ebb4832 100644 --- a/rust/src/model/misc.rs +++ b/rust/src/model/misc.rs @@ -59,7 +59,7 @@ impl Game { pub fn amd_args(&self) -> Vec<&'static str> { match self { Game::Ongeki => vec!["-f", "-c", "config_common.json", "config_server.json", "config_client.json"], - Game::Chunithm => vec!["-c", "config_common.json", "config_server.json", "config_client.json", "config_cvt.json", "config_sp.json", "config_hook.json"] + Game::Chunithm => vec!["-c", "config_common.json", "config_server.json", "config_client.json", "config_cvt.json", "config_sp.json"] } } @@ -86,4 +86,28 @@ pub enum StartCheckError { MissingLocalPackage(PkgKey), MissingDependency(PkgKey, PkgKey), MissingTool(PkgKey), +} + +#[derive(Default, Serialize, Deserialize, Clone)] +pub struct ConfigHook { + #[serde(skip_serializing_if = "Option::is_none")] + pub allnet_auth: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub aime: Option, +} + +#[derive(Default, Serialize, Deserialize, Clone)] +pub struct ConfigHookAuth { + pub r#type: String +} + +#[derive(Default, Serialize, Deserialize, Clone)] +pub struct ConfigHookAime { + pub unit: Vec +} + +#[derive(Default, Serialize, Deserialize, Clone)] +pub struct ConfigHookAimeUnit { + pub port: i32, + pub id: i32 } \ No newline at end of file diff --git a/rust/src/model/profile.rs b/rust/src/model/profile.rs index 0782152..edbe6ec 100644 --- a/rust/src/model/profile.rs +++ b/rust/src/model/profile.rs @@ -39,6 +39,7 @@ pub struct Segatools { pub intel: bool, #[serde(default)] pub amnet: AMNet, + pub aime_port: Option, } impl Segatools { @@ -56,6 +57,7 @@ impl Segatools { aime: Aime::default(), intel: false, amnet: AMNet::default(), + aime_port: None } } } diff --git a/rust/src/modules/segatools.rs b/rust/src/modules/segatools.rs index 2771d68..ecacd55 100644 --- a/rust/src/modules/segatools.rs +++ b/rust/src/modules/segatools.rs @@ -1,7 +1,7 @@ use std::path::{PathBuf, Path}; use anyhow::{anyhow, Result}; use ini::Ini; -use crate::{model::{misc::Game, profile::{Aime, Segatools}}, profiles::ProfilePaths, util::{self, PathStr}}; +use crate::{model::{misc::{ConfigHook, ConfigHookAime, ConfigHookAimeUnit, ConfigHookAuth, Game}, profile::{Aime, Segatools}}, profiles::ProfilePaths, util::{self, PathStr}}; use crate::pkg_store::PackageStore; impl Segatools { @@ -171,6 +171,31 @@ impl Segatools { )?; } + let mut cfg_hook = ConfigHook::default(); + + if game == Game::Chunithm { + cfg_hook.allnet_auth = Some({ + ConfigHookAuth { + r#type: "1.0".to_owned() + } + }) + } + if let Some(port) = self.aime_port { + if self.aime == Aime::Disabled { + cfg_hook.aime = Some({ + ConfigHookAime { + unit: vec![ + ConfigHookAimeUnit { + port, + id: 1 + } + ] + } + }) + } + } + std::fs::write(pfx_dir.join("config_hook.json"), serde_json::to_string(&cfg_hook)?)?; + log::debug!("end line-up: segatools"); Ok(ini_out) diff --git a/rust/src/profiles/mod.rs b/rust/src/profiles/mod.rs index 7cfcaf1..7245871 100644 --- a/rust/src/profiles/mod.rs +++ b/rust/src/profiles/mod.rs @@ -142,7 +142,7 @@ impl Profile { } std::fs::write(&path, s) .map_err(|e| anyhow!("error when writing to {:?}: {}", path, e))?; - log::info!("Written to {:?}", path); + log::info!("profile written to {:?}", path); Ok(()) } @@ -293,6 +293,9 @@ impl Profile { .arg(sgt_dir.join(self.meta.game.hook_amd())) .arg("amdaemon.exe") .args(self.meta.game.amd_args()); + + amd_builder.arg(self.data_dir().join("config_hook.json")); + game_builder .env( "SEGATOOLS_CONFIG_PATH", @@ -351,8 +354,8 @@ impl Profile { util::pkill("amdaemon.exe").await; - log::info!("Launching amdaemon: {:?}", amd_builder); - log::info!("Launching {}: {:?}", self.meta.game, game_builder); + log::info!("launching amdaemon: {:?}", amd_builder); + log::info!("launching {}: {:?}", self.meta.game, game_builder); let mut amd = amd_builder.spawn()?; let mut game = game_builder.spawn()?; diff --git a/src/components/App.vue b/src/components/App.vue index c54325c..85b491b 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -148,29 +148,21 @@ listen<{ message: string; header: string }>('invoke-error', (event) => { >
-
+
@@ -316,4 +308,8 @@ body { .p-tablist-active-bar { display: none !important; } + +.p-tooltip { + min-width: 300px; +} diff --git a/src/components/options/Aime.vue b/src/components/options/Aime.vue index 2be9f60..7742279 100644 --- a/src/components/options/Aime.vue +++ b/src/components/options/Aime.vue @@ -1,5 +1,5 @@