Skip to content

Commit

Permalink
For loop y first, then x. Add beep. Add manifest.
Browse files Browse the repository at this point in the history
  • Loading branch information
ganlvtech committed Oct 4, 2021
1 parent ceca7e8 commit 47047ca
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
24 changes: 24 additions & 0 deletions genshin-auto-fish.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator"
uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet"
version="1" ID="Custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</asmv1:assembly>
12 changes: 6 additions & 6 deletions src/genshin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 25 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -35,20 +46,31 @@ 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
}
};
if is_down != is_prev_down {
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));
}
Expand Down

0 comments on commit 47047ca

Please sign in to comment.