diff --git a/Cargo.lock b/Cargo.lock index 9813092..276a42a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,15 +59,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" version = "1.0.86" @@ -1135,7 +1126,6 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" name = "jerry" version = "1.0.0" dependencies = [ - "ansi_term", "cached", "cgisf_lib", "chrono", @@ -1155,7 +1145,7 @@ dependencies = [ "tracing", "tts", "windows 0.56.0", - "winres", + "winresource", ] [[package]] @@ -2288,11 +2278,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.11" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" dependencies = [ "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.19.15", ] [[package]] @@ -2304,7 +2297,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_edit 0.22.13", ] [[package]] @@ -2316,6 +2309,19 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow 0.5.40", +] + [[package]] name = "toml_edit" version = "0.22.13" @@ -2326,7 +2332,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.9", ] [[package]] @@ -2998,6 +3004,15 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + [[package]] name = "winnow" version = "0.6.9" @@ -3018,12 +3033,13 @@ dependencies = [ ] [[package]] -name = "winres" -version = "0.1.12" +name = "winresource" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c" +checksum = "77e2aaaf8cfa92078c0c0375423d631f82f2f57979c2884fdd5f604a11e45329" dependencies = [ - "toml 0.5.11", + "toml 0.7.8", + "version_check", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6e8c38e..0f69460 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,9 +11,9 @@ edition = "2021" keywords = ["robot", "automation", "malware", "jerry"] categories = ["robot", "automation", "malware"] -[package.metadata.winres] +[package.metadata.winresource] LegalCopyright = "Copyright © callmeclover 2024" -FileDescription = "stupid robot nuisance" +OriginalFilename = "stupid robot nuisance" [dependencies] enigo = "0.2.1" @@ -27,7 +27,6 @@ lazy_static = "1.4.0" dialoguer = "0.11.0" time = "0.3.31" chrono = "0.4.31" -ansi_term = "0.12.1" regex = "1.10.3" reqwest = { version = "0.12.3", features = ["blocking"] } cgisf_lib = "0.2.1" @@ -48,7 +47,7 @@ version = "0.5.0" optional = true [build-dependencies] -winres = "0.1" +winresource = "0.1" [features] invisibility = ["dep:daemonize"] diff --git a/build.rs b/build.rs index a58036a..4147797 100644 --- a/build.rs +++ b/build.rs @@ -1,19 +1,15 @@ -extern crate winres; +extern crate winresource; fn main() { - if std::env::var("CARGO_CFG_TARGET_OS").unwrap() != "windows" { - return; - } - - if std::env::var("PROFILE").unwrap() == "release" { - let mut res = winres::WindowsResource::new(); + if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" { + let mut res = winresource::WindowsResource::new(); - res.set_icon("icon.ico").set_language(0x0409); + res.set_icon("resources/icon.ico").set_language(0x0409); if cfg!(feature = "advanced") { - res.set_manifest_file("manifest_adv.xml"); + res.set_manifest_file("resources/manifest_adv.xml"); } else { - res.set_manifest_file("manifest.xml"); + res.set_manifest_file("resources/manifest.xml"); } if let Err(e) = res.compile() { diff --git a/resources/icon.icns b/resources/icon.icns new file mode 100644 index 0000000..2f8cf5f Binary files /dev/null and b/resources/icon.icns differ diff --git a/icon.ico b/resources/icon.ico similarity index 100% rename from icon.ico rename to resources/icon.ico diff --git a/resources/icon.png b/resources/icon.png new file mode 100644 index 0000000..9067182 Binary files /dev/null and b/resources/icon.png differ diff --git a/manifest.xml b/resources/manifest.xml similarity index 100% rename from manifest.xml rename to resources/manifest.xml diff --git a/manifest_adv.xml b/resources/manifest_adv.xml similarity index 100% rename from manifest_adv.xml rename to resources/manifest_adv.xml diff --git a/src/func.rs b/src/func.rs index eadee74..f12fc6e 100644 --- a/src/func.rs +++ b/src/func.rs @@ -1,5 +1,8 @@ #[allow(clippy::wildcard_imports)] -use crate::{get_config, lists::*, Speed, SPEED_WEIGHTED_LISTS_SLOW, SPEED_WEIGHTED_LISTS_FAST, SPEED_WEIGHTED_LISTS_NORMAL}; +use crate::{ + get_config, lists::*, Speed, SPEED_WEIGHTED_LISTS_FAST, SPEED_WEIGHTED_LISTS_NORMAL, + SPEED_WEIGHTED_LISTS_SLOW, +}; #[cfg(all(feature = "advanced", target_os = "windows"))] use crate::{GamepadInjector, PenInjector}; use cgisf_lib::{gen_sentence, SentenceConfigBuilder}; @@ -62,7 +65,8 @@ pub fn drag_mouse_abs(enigo: &mut Enigo, pos: (i32, i32), speed: Speed) { for _ in 0..distance as usize { new_x += step_x; new_y += step_y; - enigo.move_mouse(new_x as i32, new_y as i32, Coordinate::Abs) + enigo + .move_mouse(new_x as i32, new_y as i32, Coordinate::Abs) .unwrap_or_else(|_| panic!("Unable to move mouse position to ({}, {}).", pos.0, pos.1)); thread::sleep(sleep_duration); } @@ -82,7 +86,8 @@ pub fn drag_mouse_rel(enigo: &mut Enigo, pos: (i32, i32), speed: Speed) { for _ in 0..distance as usize { new_x += step_x; new_y += step_y; - enigo.move_mouse(new_x as i32, new_y as i32, Coordinate::Abs) + enigo + .move_mouse(new_x as i32, new_y as i32, Coordinate::Abs) .unwrap_or_else(|_| panic!("Unable to move mouse position to ({}, {}).", pos.0, pos.1)); thread::sleep(sleep_duration); } @@ -147,68 +152,138 @@ fn mouse(enigo: &mut Enigo, rng: &mut rand::rngs::ThreadRng) { if Regex::new(r"mouse_down_.+").unwrap().is_match(click) { let typeclick: Button = convert_mouse_action(click.split('_').collect::>()[2]) .expect("cant convert mouse action"); - if get_config().extra.do_debugging { tracing::info!("mouse: holding button {:?}", typeclick) } + if get_config().extra.do_debugging { + tracing::info!("mouse: holding button {:?}", typeclick) + } let _ = enigo.button(typeclick, Direction::Press); thread::sleep(Duration::from_millis(rng.gen_range(0..=5000))); let _ = enigo.button(typeclick, Direction::Release); } else if Regex::new(r"mouse_click_.+").unwrap().is_match(click) { let typeclick: Button = convert_mouse_action(click.split('_').collect::>()[2]) .expect("cant convert mouse action"); - if get_config().extra.do_debugging { tracing::info!("mouse: clicking button {:?}", typeclick) } + if get_config().extra.do_debugging { + tracing::info!("mouse: clicking button {:?}", typeclick) + } let _ = enigo.button(typeclick, Direction::Click); } else { match click { - "mouse_move_abs" => enigo.move_mouse( - rng.gen_range(0..=enigo.main_display().unwrap().0), - rng.gen_range(0..=enigo.main_display().unwrap().1), - Coordinate::Abs - ).unwrap(), - "mouse_move_rel" => enigo.move_mouse( - rng.gen_range(0..=enigo.main_display().unwrap().0), - rng.gen_range(0..=enigo.main_display().unwrap().1), - Coordinate::Rel - ).unwrap(), + "mouse_move_abs" => enigo + .move_mouse( + rng.gen_range(0..=enigo.main_display().unwrap().0), + rng.gen_range(0..=enigo.main_display().unwrap().1), + Coordinate::Abs, + ) + .unwrap(), + "mouse_move_rel" => enigo + .move_mouse( + rng.gen_range(0..=enigo.main_display().unwrap().0), + rng.gen_range(0..=enigo.main_display().unwrap().1), + Coordinate::Rel, + ) + .unwrap(), "mouse_drag_abs_std" => drag_mouse_abs( enigo, - (rng.gen_range(0..=enigo.main_display().unwrap().0), - rng.gen_range(0..=enigo.main_display().unwrap().1)), - SPEED_WEIGHTED_LISTS_NORMAL[WeightedIndex::new(SPEED_WEIGHTED_LISTS_NORMAL.iter().map(|item: &(Speed, usize)| item.1)).unwrap().sample(rng)].0 + ( + rng.gen_range(0..=enigo.main_display().unwrap().0), + rng.gen_range(0..=enigo.main_display().unwrap().1), + ), + SPEED_WEIGHTED_LISTS_NORMAL[WeightedIndex::new( + SPEED_WEIGHTED_LISTS_NORMAL + .iter() + .map(|item: &(Speed, usize)| item.1), + ) + .unwrap() + .sample(rng)] + .0, ), "mouse_drag_rel_std" => drag_mouse_rel( enigo, - (rng.gen_range(0..=enigo.main_display().unwrap().0), - rng.gen_range(0..=enigo.main_display().unwrap().1)), - SPEED_WEIGHTED_LISTS_NORMAL[WeightedIndex::new(SPEED_WEIGHTED_LISTS_NORMAL.iter().map(|item: &(Speed, usize)| item.1)).unwrap().sample(rng)].0 + ( + rng.gen_range(0..=enigo.main_display().unwrap().0), + rng.gen_range(0..=enigo.main_display().unwrap().1), + ), + SPEED_WEIGHTED_LISTS_NORMAL[WeightedIndex::new( + SPEED_WEIGHTED_LISTS_NORMAL + .iter() + .map(|item: &(Speed, usize)| item.1), + ) + .unwrap() + .sample(rng)] + .0, ), "mouse_drag_abs_fst" => drag_mouse_abs( enigo, - (rng.gen_range(0..=enigo.main_display().unwrap().0), - rng.gen_range(0..=enigo.main_display().unwrap().1)), - SPEED_WEIGHTED_LISTS_FAST[WeightedIndex::new(SPEED_WEIGHTED_LISTS_FAST.iter().map(|item: &(Speed, usize)| item.1)).unwrap().sample(rng)].0, + ( + rng.gen_range(0..=enigo.main_display().unwrap().0), + rng.gen_range(0..=enigo.main_display().unwrap().1), + ), + SPEED_WEIGHTED_LISTS_FAST[WeightedIndex::new( + SPEED_WEIGHTED_LISTS_FAST + .iter() + .map(|item: &(Speed, usize)| item.1), + ) + .unwrap() + .sample(rng)] + .0, ), "mouse_drag_rel_fst" => drag_mouse_rel( enigo, - (rng.gen_range(0..=enigo.main_display().unwrap().0), - rng.gen_range(0..=enigo.main_display().unwrap().1)), - SPEED_WEIGHTED_LISTS_FAST[WeightedIndex::new(SPEED_WEIGHTED_LISTS_FAST.iter().map(|item: &(Speed, usize)| item.1)).unwrap().sample(rng)].0, + ( + rng.gen_range(0..=enigo.main_display().unwrap().0), + rng.gen_range(0..=enigo.main_display().unwrap().1), + ), + SPEED_WEIGHTED_LISTS_FAST[WeightedIndex::new( + SPEED_WEIGHTED_LISTS_FAST + .iter() + .map(|item: &(Speed, usize)| item.1), + ) + .unwrap() + .sample(rng)] + .0, ), "mouse_drag_abs_slw" => drag_mouse_abs( enigo, - (rng.gen_range(0..=enigo.main_display().unwrap().0), - rng.gen_range(0..=enigo.main_display().unwrap().1)), - SPEED_WEIGHTED_LISTS_SLOW[WeightedIndex::new(SPEED_WEIGHTED_LISTS_SLOW.iter().map(|item: &(Speed, usize)| item.1)).unwrap().sample(rng)].0, + ( + rng.gen_range(0..=enigo.main_display().unwrap().0), + rng.gen_range(0..=enigo.main_display().unwrap().1), + ), + SPEED_WEIGHTED_LISTS_SLOW[WeightedIndex::new( + SPEED_WEIGHTED_LISTS_SLOW + .iter() + .map(|item: &(Speed, usize)| item.1), + ) + .unwrap() + .sample(rng)] + .0, ), "mouse_drag_rel_slw" => drag_mouse_rel( enigo, - (rng.gen_range(0..=enigo.main_display().unwrap().0), - rng.gen_range(0..=enigo.main_display().unwrap().1)), - SPEED_WEIGHTED_LISTS_SLOW[WeightedIndex::new(SPEED_WEIGHTED_LISTS_SLOW.iter().map(|item: &(Speed, usize)| item.1)).unwrap().sample(rng)].0, + ( + rng.gen_range(0..=enigo.main_display().unwrap().0), + rng.gen_range(0..=enigo.main_display().unwrap().1), + ), + SPEED_WEIGHTED_LISTS_SLOW[WeightedIndex::new( + SPEED_WEIGHTED_LISTS_SLOW + .iter() + .map(|item: &(Speed, usize)| item.1), + ) + .unwrap() + .sample(rng)] + .0, ), - "mouse_scroll_x" => enigo.scroll(rng.gen_range(1..=200), Axis::Horizontal).unwrap(), - "mouse_scroll_y" => enigo.scroll(rng.gen_range(1..=175), Axis::Vertical).unwrap(), + "mouse_scroll_x" => enigo + .scroll(rng.gen_range(1..=200), Axis::Horizontal) + .unwrap(), + "mouse_scroll_y" => enigo + .scroll(rng.gen_range(1..=175), Axis::Vertical) + .unwrap(), "mouse_scroll_xy" => { - enigo.scroll(rng.gen_range(0..=200), Axis::Horizontal).unwrap(); - enigo.scroll(rng.gen_range(0..=175), Axis::Vertical).unwrap(); + enigo + .scroll(rng.gen_range(0..=200), Axis::Horizontal) + .unwrap(); + enigo + .scroll(rng.gen_range(0..=175), Axis::Vertical) + .unwrap(); } _ => {} } @@ -222,7 +297,9 @@ fn quote(tts: &mut Tts, rng: &mut rand::rngs::ThreadRng) { (QUOTES_QUESTION.to_vec(), 1), (QUOTES_STATEMENT.to_vec(), 2), ]; - if get_config().extra.do_debugging { tracing::info!("quote: choosing random sentence") } + if get_config().extra.do_debugging { + tracing::info!("quote: choosing random sentence") + } let index: WeightedIndex = WeightedIndex::new(lists.iter().map(|item| item.1)).unwrap(); let list: &Vec<(&str, usize)> = &lists[index.sample(rng)].0; let index2: WeightedIndex = WeightedIndex::new(list.iter().map(|item| item.1)).unwrap(); @@ -232,7 +309,9 @@ fn quote(tts: &mut Tts, rng: &mut rand::rngs::ThreadRng) { } fn quote_gen(tts: &mut Tts) { - if get_config().extra.do_debugging { tracing::info!("quote_gen: generating sentence") } + if get_config().extra.do_debugging { + tracing::info!("quote_gen: generating sentence") + } let quote: &str = &gen_sentence(SentenceConfigBuilder::random().build()); println!("{quote}"); let _ = tts.speak(quote, true); @@ -249,7 +328,9 @@ async fn quote_gen_ext(tts: &mut Tts) { ) .is_ok() { - if get_config().extra.do_debugging { tracing::info!("quote_gen_ext: internet check passed, sending request to sentence api") } + if get_config().extra.do_debugging { + tracing::info!("quote_gen_ext: internet check passed, sending request to sentence api") + } let quote: &str = &reqwest::get("http://metaphorpsum.com/sentences/1/") .await .expect("could not get external sentence api") @@ -416,21 +497,27 @@ fn pen(pen: &mut PenInjector, rng: &mut rand::rngs::ThreadRng) { rng.gen_range(0..=display.height).try_into().unwrap(), ); - if get_config().extra.do_debugging { tracing::info!("pen: updating x and y position to {:?}", placement) } + if get_config().extra.do_debugging { + tracing::info!("pen: updating x and y position to {:?}", placement) + } pen.update_position(placement); } "X_Move" => { let display = Screen::from_point(0, 0).unwrap().display_info; let placement = rng.gen_range(0..=display.width).try_into().unwrap(); - if get_config().extra.do_debugging { tracing::info!("pen: updating x position to {}", placement) } + if get_config().extra.do_debugging { + tracing::info!("pen: updating x position to {}", placement) + } pen.update_position((placement, -1)); } "Y_Move" => { let display = Screen::from_point(0, 0).unwrap().display_info; let placement = rng.gen_range(0..=display.height).try_into().unwrap(); - if get_config().extra.do_debugging { tracing::info!("pen: updating y position to {}", placement) } + if get_config().extra.do_debugging { + tracing::info!("pen: updating y position to {}", placement) + } pen.update_position((-1, placement)); } _ => { diff --git a/src/lists.rs b/src/lists.rs index 9d09a05..c2b6e2b 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -262,7 +262,8 @@ pub static GAMEPAD_BUTTONS: &[(&str, usize)] = &[ ]; #[allow(dead_code)] -pub static GAMEPAD_MOVE: &[(&str, usize)] = &[("LeftThumbstickMove", 3), ("RightThumbstickMove", 1)]; +pub static GAMEPAD_MOVE: &[(&str, usize)] = + &[("LeftThumbstickMove", 3), ("RightThumbstickMove", 1)]; #[allow(dead_code)] pub static GAMEPAD_SPECIAL: &[(&str, usize)] = &[ diff --git a/src/main.rs b/src/main.rs index ead6443..916cca3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,8 @@ -#![cfg_attr(all(feature = "invisibility", target_os = "windows"), windows_subsystem = "windows")] - +#![cfg_attr( + all(feature = "invisibility", target_os = "windows"), + windows_subsystem = "windows" +)] // Begin allow clippy warnings - #![allow(clippy::cast_possible_truncation)] #![allow(clippy::cast_precision_loss)] #![allow(clippy::cast_sign_loss)] @@ -12,7 +13,7 @@ mod config; mod func; mod lists; mod model; -use config::{Config, get_config, get_options}; +use config::{get_config, get_options, Config}; use enigo::{Enigo, Settings}; #[allow(clippy::wildcard_imports)] use func::*; diff --git a/src/model.rs b/src/model.rs index ebee441..3a3f8f6 100644 --- a/src/model.rs +++ b/src/model.rs @@ -232,6 +232,8 @@ pub enum Speed { Slowest = 3000, } -pub static SPEED_WEIGHTED_LISTS_SLOW: &[(Speed, usize)] = &[(Speed::Slow, 6), (Speed::Slower, 3), (Speed::Slowest, 1)]; -pub static SPEED_WEIGHTED_LISTS_FAST: &[(Speed, usize)] = &[(Speed::Fast, 6), (Speed::Faster, 3), (Speed::Fastest, 1)]; +pub static SPEED_WEIGHTED_LISTS_SLOW: &[(Speed, usize)] = + &[(Speed::Slow, 6), (Speed::Slower, 3), (Speed::Slowest, 1)]; +pub static SPEED_WEIGHTED_LISTS_FAST: &[(Speed, usize)] = + &[(Speed::Fast, 6), (Speed::Faster, 3), (Speed::Fastest, 1)]; pub static SPEED_WEIGHTED_LISTS_NORMAL: &[(Speed, usize)] = &[(Speed::Normal, 1)];