-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutoFish.py
154 lines (130 loc) · 5.43 KB
/
AutoFish.py
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
import time
import pyautogui
from PIL import ImageGrab,Image, ImageTk
import webbrowser
import keyboard
import tkinter as tk
import queue
import threading
def get_pixel_color(x, y):
screenshot = ImageGrab.grab(bbox=(x, y, x+1, y+1))
return screenshot.getpixel((0, 0))
def calculate_coordinates(screen_width, screen_height):
x_ratio = 1284 / 2560
y_ratio = 688 / 1440
x = int(screen_width * x_ratio)
y = int(screen_height * y_ratio)
return x, y
class AutoFishingGUI:
def __init__(self, root, gui_queue):
self.root = root
self.running = False
self.current_hotkey = 's'
self.gui_queue = gui_queue
self.last_detection_time = 0
self.max_inactive_time = 6
self.is_closed = False
self.setup_gui()
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
def setup_gui(self):
self.root.title("Automated Fishing")
self.root.geometry("300x200")
self.root.attributes("-topmost", True)
self.status_label = tk.Label(self.root, text="Disabled", fg="red").pack()
self.set_hotkey_button = tk.Button(self.root, text="Set New Hotkey", command=self.set_new_hotkey).pack()
self.current_hotkey_label = tk.Label(self.root, text=f"Current Hotkey: {self.current_hotkey}").pack()
footer_frame = tk.Frame(self.root)
footer_frame.pack(side=tk.BOTTOM, fill=tk.X)
tk.Label(footer_frame, text="Made by: xFlippy").pack(side=tk.LEFT)
self.setup_social_buttons(footer_frame)
keyboard.add_hotkey(self.current_hotkey, lambda: self.gui_queue.put(self.toggle_running))
def setup_social_buttons(self, footer_frame):
for social, url in [("youtube", "https://www.youtube.com/channel/UCHIk4-IrVb6351-NjHbrRow"),
("twitter", "https://twitter.com/gewoon_aardbei"),
("github", "https://github.com/xflipperkast")]:
img = ImageTk.PhotoImage(Image.open(f"imgs/{social}.png").resize((20, 20)))
button = tk.Button(footer_frame, image=img, command=lambda u=url: webbrowser.open(u))
button.image = img
button.pack(side=tk.LEFT)
def toggle_running(self):
self.running = not self.running
status_text = "Running" if self.running else "Paused"
status_color = "green" if self.running else "red"
self.status_label.config(text=status_text, fg=status_color)
self.last_detection_time = time.time()
if self.running:
self.check_fishing()
def set_new_hotkey(self):
self.set_hotkey_button.config(text="Press a Key...")
self.current_hotkey_label.config(text="Press a Key...")
def listen_for_hotkey():
new_hotkey = keyboard.read_hotkey(suppress=False)
self.gui_queue.put(lambda: self.update_hotkey(new_hotkey))
threading.Thread(target=listen_for_hotkey, daemon=True).start()
def update_hotkey(self, new_hotkey):
if new_hotkey:
keyboard.remove_hotkey(self.current_hotkey)
self.current_hotkey = new_hotkey
keyboard.add_hotkey(self.current_hotkey, lambda: self.gui_queue.put(self.toggle_running))
self.current_hotkey_label.config(text=f"Current Hotkey: {self.current_hotkey}")
self.set_hotkey_button.config(text="Set New Hotkey")
def on_closing(self):
self.running = False
self.is_closed = True
self.root.destroy()
keyboard.unhook_all_hotkeys()
def check_fishing(self):
if not self.running:
self.root.after(1000, self.check_fishing)
return
x, y = calculate_coordinates(pyautogui.size().width, pyautogui.size().height)
current_color = get_pixel_color(x, y)
target_color = (112, 237, 252)
if current_color == target_color:
pyautogui.click()
self.root.after(100, lambda: self.perform_click_sequence(x, y, target_color))
elif time.time() - self.last_detection_time > self.max_inactive_time:
pyautogui.click()
self.last_detection_time = time.time()
self.root.after(1000, self.check_fishing)
else:
self.root.after(100, self.check_fishing)
def perform_click_sequence(self, x, y, target_color):
if not self.running or get_pixel_color(x, y) != target_color:
self.root.after(500, lambda: self.finish_click_sequence(x, y))
return
pyautogui.click()
self.root.after(100, lambda: self.perform_click_sequence(x, y, target_color))
def finish_click_sequence(self, x, y):
if not self.running:
self.check_fishing()
return
pyautogui.click()
self.root.after(4500, lambda: self.second_click_in_sequence(x, y))
def second_click_in_sequence(self, x, y):
if self.running:
pyautogui.click()
self.last_detection_time = time.time()
self.check_fishing()
def main():
root = tk.Tk()
gui_queue = queue.Queue()
gui = AutoFishingGUI(root, gui_queue)
while True:
if gui.is_closed:
break
try:
func = gui_queue.get_nowait()
func()
except queue.Empty:
pass
except Exception as e:
print(f"An error occurred: {e}")
break
try:
root.update()
root.update_idletasks()
except tk.TclError:
break
if __name__ == "__main__":
main()