-
Notifications
You must be signed in to change notification settings - Fork 138
/
autofish.ahk
221 lines (177 loc) · 7.34 KB
/
autofish.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
; "The AFKatch" v0.69
; Copyright (C) 2021 3096
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU Affero General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU Affero General Public License for more details.
;
; You should have received a copy of the GNU Affero General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
; Usage: Install ahk and right click script to run as admin.
; For every catch, press Ctrl F after you cast your rod (make sure the left click icon has changed)
; You need the config for your specific resolution. Delete configs for other resolution under "resolution configs".
#NoEnv
#Warn
SendMode Input
CoordMode, Pixel, Client
#IfWinActive ahk_class UnityWndClass
global AUTO_FISH_KEY := "^f"
global AUTO_FISH_CAUGHT_TIMEOUT := 10
; coords and pix counts are hardcoded cuz meh
; AUTO_FISH_SEARCH - search the region for the caret X coord
; AUTO_FISH_REEL_EARLY - a white pixel on the pull rod icon (lower right, when no bite)
; AUTO_FISH_TARGET_GLOW - the target zone yellow glow
; AUTO_FISH_CARET_GLOW - the caret (the pointer that moves left and right) yellow glow
; AUTO_FISH_CARET_WIDTH - the width of caret (extended part at top and bottom)
; AUTO_FISH_BAR_TARGET_DROP - pixel distance from caret glow to target zone glow
global AUTO_FISH_SEARCH_CONFIRMATION_THRESHOLD := 5 ; how many times to "double check" searched bar position
global AUTO_FISH_TARGET_GLOW_COLOR := 0xC0FFFF
global AUTO_FISH_CARET_GLOW_COLOR := 0xBEFFFF
global AUTO_FISH_GLOW_COLOR_VARIANCE := 3 ; this value should ideally be 0, but just in case
global AUTO_FISH_REEL_EARLY_VARIANCE := 64 ; decrease if you're not reeling, increase if you're reeling too early
; resolution configs
; 3840x2160
global AUTO_FISH_RESOLUTION_W := 3840
global AUTO_FISH_RESOLUTION_H := 2160
global AUTO_FISH_SEARCH_LEFT_X := 1430
global AUTO_FISH_SEARCH_TOP_Y := 146
global AUTO_FISH_SEARCH_BOTTOM_Y := 350
global AUTO_FISH_REEL_EARLY_X := 3246
global AUTO_FISH_REAL_EARLY_Y := 2000
global AUTO_FISH_CARET_WIDTH := 22
global AUTO_FISH_BAR_TARGET_DROP := 8
; 3440x1440
global AUTO_FISH_RESOLUTION_W := 3440
global AUTO_FISH_RESOLUTION_H := 1440
global AUTO_FISH_SEARCH_LEFT_X := 1395
global AUTO_FISH_SEARCH_TOP_Y := 98
global AUTO_FISH_SEARCH_BOTTOM_Y := 234
global AUTO_FISH_REEL_EARLY_X := 2948
global AUTO_FISH_REAL_EARLY_Y := 1334
global AUTO_FISH_CARET_WIDTH := 14
global AUTO_FISH_BAR_TARGET_DROP := 6
; 1920x1080
global AUTO_FISH_RESOLUTION_W := 1920
global AUTO_FISH_RESOLUTION_H := 1080
global AUTO_FISH_SEARCH_LEFT_X := 715
global AUTO_FISH_SEARCH_TOP_Y := 73
global AUTO_FISH_SEARCH_BOTTOM_Y := 175
global AUTO_FISH_REEL_EARLY_X := 1623
global AUTO_FISH_REAL_EARLY_Y := 1000
global AUTO_FISH_CARET_WIDTH := 11
global AUTO_FISH_BAR_TARGET_DROP := 4
Hotkey, %AUTO_FISH_KEY%, AutoFish
Return
AutoFish() {
; get game resolution
hWnd := WinExist("A")
VarSetCapacity(rect, 16)
DllCall("GetClientRect", "ptr", hWnd, "ptr", &rect)
clientW := NumGet(rect, 8, "int")
clientH := NumGet(rect, 12, "int")
if (clientW != AUTO_FISH_RESOLUTION_W or clientH != AUTO_FISH_RESOLUTION_H) {
MsgBox, Current resolution is not configured.
Return
}
searchRightX := clientW - AUTO_FISH_SEARCH_LEFT_X
caretPad := AUTO_FISH_CARET_WIDTH / 2
caretUpperY := -1
caretLowerY := -1
barTargetUpperY := -1
barTargetLowerY := -1
; check for pull-rod icon to detect bite
PixelGetColor, reelEarlyColor, AUTO_FISH_REEL_EARLY_X, AUTO_FISH_REAL_EARLY_Y
StringRight, recastKey, AUTO_FISH_KEY, 1
Loop {
PixelSearch, Px, Py
, AUTO_FISH_REEL_EARLY_X, AUTO_FISH_REAL_EARLY_Y
, AUTO_FISH_REEL_EARLY_X, AUTO_FISH_REAL_EARLY_Y
, reelEarlyColor, AUTO_FISH_REEL_EARLY_VARIANCE, Fast
if(ErrorLevel == 1) {
Break
}
if (GetKeyState("Space", "P") or GetKeyState("LButton", "P")) {
Return
}
Sleep, 16
}
Click
; search for bar location (yes, this sometimes moves around for some reason)
; thanks, syn! <3
lastFoundY := -1
lastFoundSameCount := 0
Loop {
PixelSearch, Px, Py
, AUTO_FISH_SEARCH_LEFT_X, AUTO_FISH_SEARCH_TOP_Y
, searchRightX, AUTO_FISH_SEARCH_BOTTOM_Y
, AUTO_FISH_CARET_GLOW_COLOR, AUTO_FISH_GLOW_COLOR_VARIANCE, Fast
; make sure the same pos is found multiple times to avoid reading from the starting animation
if (!ErrorLevel) {
if (Py == lastFoundY) {
lastFoundSameCount := lastFoundSameCount + 1
} else {
lastFoundY := Py
lastFoundSameCount := 0
}
}
if (lastFoundSameCount > AUTO_FISH_SEARCH_CONFIRMATION_THRESHOLD) {
caretUpperY := Py - AUTO_FISH_BAR_TARGET_DROP
caretLowerY := Py + AUTO_FISH_BAR_TARGET_DROP / 4
barTargetUpperY := Py + AUTO_FISH_BAR_TARGET_DROP
barTargetLowerY := Py + AUTO_FISH_BAR_TARGET_DROP * 2
Break
}
lastFoundY := Py
if (GetKeyState("Space", "P")) {
Return
}
; if entered this loop by mistake and hangs, user might try to activate auto fish again
if (GetKeyState(recastKey, "P")) {
AutoFish()
Return
}
Sleep, 20
}
curTimeOutCycleCount := 0
Loop {
; check for exit
if (GetKeyState("Space", "P") or curTimeOutCycleCount > AUTO_FISH_CAUGHT_TIMEOUT) {
Send, {Click up}
Return
}
; search color for caret/target positions
failedToFind := false
PixelSearch, curCaretX, Py
, AUTO_FISH_SEARCH_LEFT_X, caretUpperY
, searchRightX, caretLowerY
, AUTO_FISH_CARET_GLOW_COLOR, AUTO_FISH_GLOW_COLOR_VARIANCE, Fast
failedToFind := ErrorLevel or failedToFind
PixelSearch, curBarTargetXLeft, Py
, AUTO_FISH_SEARCH_LEFT_X, barTargetUpperY
, searchRightX, barTargetLowerY
, AUTO_FISH_TARGET_GLOW_COLOR, AUTO_FISH_GLOW_COLOR_VARIANCE, Fast
failedToFind := ErrorLevel or failedToFind
PixelSearch, curBarTargetXRight, Py
, searchRightX, barTargetUpperY
, AUTO_FISH_SEARCH_LEFT_X, barTargetLowerY
, AUTO_FISH_TARGET_GLOW_COLOR, AUTO_FISH_GLOW_COLOR_VARIANCE, Fast
failedToFind := ErrorLevel or failedToFind
if (failedToFind) {
curTimeOutCycleCount := curTimeOutCycleCount + 1
Continue
}
curTimeOutCycleCount := 0
; hold or release based on searched coords
if ((curBarTargetXLeft + curBarTargetXRight) / 2 > curCaretX + AUTO_FISH_CARET_WIDTH) {
Send, {Click down}
} else {
Send, {Click up}
}
}
}