2020-04-19 11:52:42 +00:00
|
|
|
import logging
|
|
|
|
import sys
|
2020-04-18 11:32:14 +00:00
|
|
|
import time
|
2020-04-19 11:52:42 +00:00
|
|
|
import win32con
|
|
|
|
import win32gui
|
2020-04-18 11:32:14 +00:00
|
|
|
from threading import Thread
|
|
|
|
|
2020-04-15 11:27:26 +00:00
|
|
|
import cv2
|
2020-04-18 11:32:14 +00:00
|
|
|
import pywintypes
|
2020-04-19 11:52:42 +00:00
|
|
|
import fishy
|
2020-04-16 23:14:33 +00:00
|
|
|
from fishy.systems import *
|
2020-04-19 11:52:42 +00:00
|
|
|
from fishy.systems import helper
|
2020-04-17 13:08:26 +00:00
|
|
|
from fishy.systems.config import Config
|
2020-04-18 11:32:14 +00:00
|
|
|
from fishy.systems.gui import GUI, GUIStreamHandler, GUIEvent, GUIFunction
|
|
|
|
|
|
|
|
|
|
|
|
class Fishy:
|
|
|
|
def __init__(self, gui_ref, gui_event_buffer):
|
|
|
|
self.gui_events = gui_event_buffer
|
|
|
|
self.start = False
|
|
|
|
self.fishPixWindow = None
|
|
|
|
self.fishy_thread = None
|
|
|
|
self.gui = gui_ref
|
|
|
|
|
|
|
|
def start_fishing(self, ip: str, action_key: str, borderless: bool, collect_r: bool):
|
|
|
|
"""
|
|
|
|
Starts the fishing
|
|
|
|
code explained in comments in detail
|
|
|
|
"""
|
|
|
|
|
|
|
|
if ip != "":
|
|
|
|
net.initialize(ip)
|
|
|
|
|
|
|
|
# initialize widow
|
|
|
|
try:
|
|
|
|
Window.Init(borderless)
|
|
|
|
except pywintypes.error:
|
|
|
|
logging.info("Game window not found")
|
|
|
|
self.start = False
|
2019-02-16 11:32:20 +00:00
|
|
|
return
|
|
|
|
|
2020-04-18 11:32:14 +00:00
|
|
|
# initializes fishing modes and their callbacks
|
2020-04-19 11:52:42 +00:00
|
|
|
FishingMode("hook", 0, HookEvent(action_key, collect_r))
|
2020-04-18 11:32:14 +00:00
|
|
|
FishingMode("stick", 1, StickEvent())
|
|
|
|
FishingMode("look", 2, LookEvent())
|
|
|
|
FishingMode("idle", 3, IdleEvent(ip != ""))
|
2019-02-05 15:18:20 +00:00
|
|
|
|
2020-04-18 11:32:14 +00:00
|
|
|
logging.info("Starting the bot engine, look at the fishing hole to start fishing")
|
2019-02-15 13:44:49 +00:00
|
|
|
|
2020-04-18 11:32:14 +00:00
|
|
|
self.fishPixWindow = Window(color=cv2.COLOR_RGB2HSV)
|
2019-02-15 13:44:49 +00:00
|
|
|
|
2020-04-18 11:32:14 +00:00
|
|
|
# check for game window and stuff
|
|
|
|
self.gui.call(GUIFunction.STARTED, (True,))
|
|
|
|
while self.start:
|
2019-06-29 20:35:53 +00:00
|
|
|
# Services to be ran in the start of the main loop
|
2019-02-07 22:03:28 +00:00
|
|
|
Window.Loop()
|
|
|
|
|
2019-06-29 20:35:53 +00:00
|
|
|
# get the PixelLoc and find the color values, to give it to `FishingMode.Loop`
|
2020-04-18 11:32:14 +00:00
|
|
|
self.fishPixWindow.crop = PixelLoc.val
|
|
|
|
hueValue = self.fishPixWindow.getCapture()[0][0][0]
|
|
|
|
FishingMode.Loop(hueValue)
|
2019-06-29 20:35:53 +00:00
|
|
|
# Services to be ran in the end of the main loop
|
2019-02-07 22:03:28 +00:00
|
|
|
Window.LoopEnd()
|
2020-04-18 11:32:14 +00:00
|
|
|
logging.info("Fishing engine stopped")
|
|
|
|
self.gui.call(GUIFunction.STARTED, (False,))
|
|
|
|
|
|
|
|
def start_event_handler(self):
|
|
|
|
while True:
|
|
|
|
while len(self.gui_events) > 0:
|
|
|
|
event = self.gui_events.pop(0)
|
|
|
|
|
|
|
|
if event[0] == GUIEvent.START_BUTTON:
|
|
|
|
self.start = not self.start
|
|
|
|
if self.start:
|
|
|
|
self.fishy_thread = Thread(target=self.start_fishing, args=(*event[1],))
|
|
|
|
self.fishy_thread.start()
|
|
|
|
elif event[0] == GUIEvent.CHECK_PIXELVAL:
|
|
|
|
if self.start:
|
|
|
|
self.show_pixel_vals()
|
|
|
|
else:
|
|
|
|
logging.debug("Start the engine first before running this command")
|
|
|
|
elif event[0] == GUIEvent.QUIT:
|
|
|
|
self.start = False
|
|
|
|
return
|
|
|
|
|
|
|
|
def show_pixel_vals(self):
|
|
|
|
def show():
|
|
|
|
freq = 0.5
|
|
|
|
t = 0
|
|
|
|
while t < 10.0:
|
|
|
|
t += freq
|
|
|
|
logging.debug(str(FishingMode.CurrentMode.label) + ":" + str(self.fishPixWindow.getCapture()[0][0]))
|
|
|
|
time.sleep(freq)
|
|
|
|
|
|
|
|
logging.debug("Will display pixel values for 10 seconds")
|
|
|
|
time.sleep(5)
|
|
|
|
Thread(target=show, args=()).start()
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
|
2020-04-19 11:52:42 +00:00
|
|
|
def initialize(c: Config, gui):
|
|
|
|
if c.get("first_launch", True, False):
|
|
|
|
helper.create_shortcut()
|
|
|
|
c.set("first_launch", False)
|
|
|
|
|
|
|
|
try:
|
|
|
|
auto_upgrade()
|
|
|
|
helper.ping(c, "started")
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if not c.get("debug", False):
|
|
|
|
The_program_to_hide = win32gui.GetForegroundWindow()
|
|
|
|
win32gui.ShowWindow(The_program_to_hide, win32con.SW_HIDE)
|
|
|
|
helper.install_thread_excepthook()
|
|
|
|
sys.excepthook = helper.unhandled_exception_logging
|
|
|
|
|
2020-04-17 13:08:26 +00:00
|
|
|
rootLogger = logging.getLogger('')
|
|
|
|
rootLogger.setLevel(logging.DEBUG)
|
2020-04-19 11:52:42 +00:00
|
|
|
new_console = GUIStreamHandler(gui)
|
|
|
|
rootLogger.addHandler(new_console)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
c = Config()
|
|
|
|
events_buffer = []
|
|
|
|
gui = GUI(c, lambda a, b=None: events_buffer.append((a, b)))
|
|
|
|
initialize(c, gui)
|
2020-04-17 13:08:26 +00:00
|
|
|
|
|
|
|
gui.start()
|
2020-04-19 11:52:42 +00:00
|
|
|
logging.info(f"Fishybot v{fishy.__version__}")
|
2020-04-18 04:21:18 +00:00
|
|
|
|
2020-04-19 11:52:42 +00:00
|
|
|
helper.check_addon()
|
2020-04-18 11:32:14 +00:00
|
|
|
|
2020-04-19 11:52:42 +00:00
|
|
|
bot = Fishy(gui, events_buffer)
|
|
|
|
bot.start_event_handler()
|
|
|
|
helper.ping(c, f"closed,fishes:{G.totalFishCaught}")
|
2020-04-15 11:27:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|