diff --git a/genshin-auto-fish.exe.manifest b/genshin-auto-fish.exe.manifest new file mode 100644 index 0000000..7ad40fe --- /dev/null +++ b/genshin-auto-fish.exe.manifest @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/genshin.rs b/src/genshin.rs index 9f6d0cc..26df43f 100644 --- a/src/genshin.rs +++ b/src/genshin.rs @@ -7,8 +7,8 @@ pub fn find_indicator(capture: &WindowCapture) -> Option<(usize, usize)> { let width = capture.get_width(); let height = capture.get_height(); let indicator_half_height = (0.01 * (height as f32)) as usize; - for x in ((0.35 * (width as f32)) as usize)..=((0.64 * (width as f32)) as usize) { - for y in indicator_half_height..=((0.33 * (height as f32)) as usize) { + for y in indicator_half_height..=((0.33 * (height as f32)) as usize) { + for x in ((0.35 * (width as f32)) as usize)..=((0.64 * (width as f32)) as usize) { let mut found = true; unsafe { if capture.get_color_unchecked(x as usize, y) != LIGHT_YELLOW { @@ -38,8 +38,8 @@ pub fn find_left_arrow(capture: &WindowCapture, indicator_y: usize) -> Option<(u let width = capture.get_width(); let height = capture.get_height(); let arrow_half_height = (0.007 * (height as f32)) as usize; - for x in ((0.35 * (width as f32)) as usize)..=((0.64 * (width as f32)) as usize) { - for y in (indicator_y - arrow_half_height)..=(indicator_y + arrow_half_height) { + for y in (indicator_y - arrow_half_height)..=(indicator_y + arrow_half_height) { + for x in ((0.35 * (width as f32)) as usize)..=((0.64 * (width as f32)) as usize) { let mut found = true; unsafe { if capture.get_color_unchecked(x as usize, y) != LIGHT_YELLOW { @@ -69,8 +69,8 @@ pub fn find_right_arrow(capture: &WindowCapture, indicator_y: usize) -> Option<( let width = capture.get_width(); let height = capture.get_height(); let arrow_half_height = (0.007 * (height as f32)) as usize; - for x in ((0.35 * (width as f32)) as usize)..=((0.64 * (width as f32)) as usize) { - for y in (indicator_y - arrow_half_height)..=(indicator_y + arrow_half_height) { + for y in (indicator_y - arrow_half_height)..=(indicator_y + arrow_half_height) { + for x in ((0.35 * (width as f32)) as usize)..=((0.64 * (width as f32)) as usize) { let mut found = true; unsafe { if capture.get_color_unchecked(x as usize, y) != LIGHT_YELLOW { diff --git a/src/main.rs b/src/main.rs index 02dd876..bd38fc0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,15 +2,26 @@ use std::thread::sleep; use std::time::Duration; use genshin_auto_fish::genshin::{find_fish_button, find_indicator, find_left_arrow, find_right_arrow}; -use genshin_auto_fish::windows::{set_dpi_aware, set_mouse_state, WindowCapture}; +use genshin_auto_fish::windows::{beep, set_dpi_aware, set_mouse_state, WindowCapture}; + +#[derive(Eq, PartialEq, Copy, Clone, Debug)] +enum FishingState { + Idle, + FoundButton, + FoundIndicator, +} fn main() { set_dpi_aware(); let mut capture = WindowCapture::new("UnityWndClass".to_string(), "原神".to_string()); let mut is_prev_down = false; + let mut prev_state = FishingState::Idle; + let mut state = FishingState::Idle; loop { if let Ok(()) = capture.capture() { let is_down = if let Some((indicator_x, indicator_y)) = find_indicator(&capture) { + state = FishingState::FoundIndicator; + let left_arrow_x = if let Some((left_arrow_x, _)) = find_left_arrow(&capture, indicator_y) { left_arrow_x } else { @@ -21,10 +32,10 @@ fn main() { } else { indicator_x }; + let width = capture.get_width(); let range_left_x = (0.35 * width as f32) as usize; let range_width = (0.29 * width as f32) as usize; - const N: usize = 40; let mut s = vec![b' '; N]; let indicator_i = (indicator_x - range_left_x) * N / range_width; @@ -35,13 +46,16 @@ fn main() { s[indicator_i] = b'|'; let s = String::from_utf8(s).unwrap(); let is_down = indicator_x < left_arrow_x + (right_arrow_x - left_arrow_x) / 3; - println!("[{}] {}", s, is_down); + println!("[{}] {} {}", s, is_down, indicator_y); + is_down } else { if let Some((x, y)) = find_fish_button(&capture) { + state = FishingState::FoundButton; println!("Found fish button: ({}, {})", x, y); true } else { + state = FishingState::Idle; false } }; @@ -49,6 +63,14 @@ fn main() { set_mouse_state(is_down); is_prev_down = is_down; } + if state != prev_state { + if state == FishingState::FoundButton && prev_state == FishingState::Idle { + beep(1046, 300); + } else if state == FishingState::Idle && prev_state == FishingState::FoundIndicator { + beep(523, 300); + } + prev_state = state; + } } sleep(Duration::from_millis(50)); }