2018-05-03 16:37:18 +00:00
|
|
|
"""Fishy
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
fishy.py -h | --help
|
|
|
|
fishy.py -v | --version
|
2019-02-05 16:44:48 +00:00
|
|
|
fishy.py [--ip=<ipv4>] [--hook-threshold=<int>] [--check-frequency=<hz>] [--no-resize]
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
Options:
|
2019-02-05 09:33:59 +00:00
|
|
|
-h, --help Show this screen.
|
|
|
|
-v, --version Show version.
|
2019-02-05 15:18:20 +00:00
|
|
|
--ip=<ipv4> Local Ip Address of the android phone.
|
|
|
|
--hook-threshold=<int> Threshold amount for classifier after which label changes [default: 3].
|
2019-02-05 09:33:59 +00:00
|
|
|
--check-frequency=<hz> Sleep after loop in s [default: 10].
|
2018-05-03 16:37:18 +00:00
|
|
|
"""
|
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
VERSION = "0.1.0"
|
|
|
|
print("Fishy " + VERSION + " for Elder Scrolls Online")
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
try:
|
|
|
|
from docopt import docopt
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
arguments = docopt(__doc__)
|
|
|
|
if arguments["--version"]:
|
|
|
|
quit()
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
print("Loading, Please Wait...")
|
|
|
|
import imutils as imutils
|
|
|
|
import numpy as np
|
|
|
|
from PIL import ImageGrab
|
|
|
|
import cv2
|
|
|
|
import pyautogui
|
|
|
|
import time
|
|
|
|
import fishy_network as net
|
|
|
|
from fishy_config import config_win
|
|
|
|
from pynput.keyboard import Key, Listener
|
|
|
|
from decimal import Decimal
|
2019-02-05 15:18:20 +00:00
|
|
|
from win32api import GetSystemMetrics
|
|
|
|
import pickle
|
2019-02-05 09:33:59 +00:00
|
|
|
except Exception:
|
|
|
|
raise
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 15:18:20 +00:00
|
|
|
controls = {"stop": [Key.f11, "f11"], "debug": [Key.f10, "f10"], "pause": [Key.f9, "f9"], "configPL": [Key.f8, "f8"]}
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
stop = False
|
|
|
|
pause = False
|
|
|
|
debug = False
|
2019-02-05 15:18:20 +00:00
|
|
|
configPL = False
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
IMG_SIZE = 100
|
|
|
|
LR = 1e-3
|
2019-02-05 09:33:59 +00:00
|
|
|
STICK_TIMEOUT = 30.0
|
|
|
|
NONE_TIMEOUT = 5.0
|
2018-05-03 16:37:18 +00:00
|
|
|
IP_ADDRESS = arguments["--ip"]
|
2019-02-05 15:18:20 +00:00
|
|
|
bbox = (0, 0, GetSystemMetrics(0), GetSystemMetrics(1))
|
|
|
|
|
|
|
|
try:
|
|
|
|
pixelLoc = pickle.load(open("pixelLoc.pickle", "rb"))
|
|
|
|
except (OSError, IOError) as e:
|
|
|
|
pixelLoc = [[240, 31], [241, 32]]
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
def process_img(original_img):
|
|
|
|
"""
|
|
|
|
Convert image into hsv and crop it to select the required pixel
|
|
|
|
:param original_img: image grabbed from screen
|
|
|
|
:return: processed image in hsv
|
|
|
|
"""
|
|
|
|
original_img = cv2.cvtColor(original_img, cv2.COLOR_BGR2HSV)
|
|
|
|
# y:y+h, x:x+w
|
|
|
|
croped_img = original_img[pixelLoc[0][1]:pixelLoc[1][1], pixelLoc[0][0]:pixelLoc[1][0]]
|
|
|
|
return croped_img
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
def process_show(original_img):
|
|
|
|
"""
|
|
|
|
Converts image into rgb and crop it to select the required pixel then scale it up for debuging
|
|
|
|
:param original_img: image grabbed from screen
|
|
|
|
:return: proessed image in rgb
|
|
|
|
"""
|
|
|
|
original_img = cv2.cvtColor(original_img, cv2.COLOR_BGR2RGB)
|
|
|
|
# y:y+h, x:x+w
|
|
|
|
croped_img = original_img[pixelLoc[0][1]:pixelLoc[1][1], pixelLoc[0][0]:pixelLoc[1][0]]
|
|
|
|
croped_img = imutils.resize(croped_img, width=200)
|
|
|
|
return croped_img
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
def round_float(v, ndigits=2, rt_str=False):
|
|
|
|
d = Decimal(v)
|
|
|
|
v_str = ("{0:.%sf}" % ndigits).format(round(d, ndigits))
|
|
|
|
if rt_str:
|
|
|
|
return v_str
|
|
|
|
return Decimal(v_str)
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def pullStick(fishCaught, timeToHook):
|
2019-02-05 09:33:59 +00:00
|
|
|
"""
|
|
|
|
Hooks the fish
|
|
|
|
:param fishCaught: fish cout to be displayed
|
|
|
|
:param timeToHook: time took to hook the fish
|
|
|
|
:return: void
|
|
|
|
"""
|
2019-02-05 15:18:20 +00:00
|
|
|
print("HOOOOOOOOOOOOOOOOOOOOOOOK....... " + str(fishCaught) + " caught " + " in " + str(
|
|
|
|
round_float(timeToHook)) + " secs")
|
2019-02-05 09:33:59 +00:00
|
|
|
pyautogui.press('e')
|
|
|
|
# Timer(0.5, pressE).start()
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def on_release(key):
|
2019-02-05 09:33:59 +00:00
|
|
|
"""
|
|
|
|
Read input
|
|
|
|
:param key: key released
|
|
|
|
:return: void
|
|
|
|
"""
|
2019-02-05 15:18:20 +00:00
|
|
|
global stop, pause, debug, configPL
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
if controls["pause"][0] == key:
|
|
|
|
pause = not pause
|
|
|
|
if pause:
|
|
|
|
print("PAUSED")
|
|
|
|
else:
|
|
|
|
print("STARTED")
|
|
|
|
|
|
|
|
elif controls["debug"][0] == key:
|
|
|
|
debug = not debug
|
|
|
|
|
|
|
|
elif controls["stop"][0] == key:
|
|
|
|
stop = True
|
|
|
|
|
2019-02-05 15:18:20 +00:00
|
|
|
elif controls["configPL"][0] == key:
|
|
|
|
configPL = not configPL
|
|
|
|
|
|
|
|
|
|
|
|
def updatePixelLoc():
|
|
|
|
global pixelLoc
|
|
|
|
x, y = pyautogui.position()
|
|
|
|
pixelLoc = [[x, y], [x + 1, y + 1]]
|
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
|
2018-05-03 16:37:18 +00:00
|
|
|
def startFishing():
|
2019-02-05 09:33:59 +00:00
|
|
|
"""
|
|
|
|
Starts the fishing codde
|
|
|
|
:return: void
|
|
|
|
"""
|
2018-05-03 16:37:18 +00:00
|
|
|
global stop, pause, debug
|
2019-02-05 09:33:59 +00:00
|
|
|
|
2018-05-03 16:37:18 +00:00
|
|
|
pause = True
|
|
|
|
showedControls = True
|
|
|
|
debug = False
|
|
|
|
stop = False
|
2019-02-05 09:33:59 +00:00
|
|
|
holeDepleteSent = True
|
|
|
|
timerStarted = False
|
|
|
|
use_net = False
|
|
|
|
hooked = False
|
2019-02-05 15:18:20 +00:00
|
|
|
configPixelSave = True
|
2019-02-05 16:44:48 +00:00
|
|
|
threwStick = False
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
fishCaught = 0
|
|
|
|
prevLabel = 0
|
|
|
|
labelNum = 3
|
|
|
|
hVals = [60, 18, 100]
|
|
|
|
current_thresh = 0
|
2018-05-03 16:37:18 +00:00
|
|
|
stickInitTime = time.time()
|
|
|
|
|
2019-02-05 16:44:48 +00:00
|
|
|
if not arguments["--no-resize"]:
|
|
|
|
config_win()
|
2019-02-05 15:18:20 +00:00
|
|
|
|
|
|
|
ctrl_help = controls["configPL"][1] + ": config pixel value\n" + controls["pause"][1] + ": start or pause\n" + \
|
|
|
|
controls["debug"][1] + ": start debug\n" + controls["stop"][1] + ": quit\n"
|
2019-02-05 09:33:59 +00:00
|
|
|
print(ctrl_help)
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
if IP_ADDRESS is not None:
|
|
|
|
use_net = True
|
|
|
|
net.initialize(IP_ADDRESS)
|
|
|
|
|
2019-02-05 15:18:20 +00:00
|
|
|
threshold = int(arguments["--hook-threshold"])
|
2019-02-05 09:33:59 +00:00
|
|
|
sleepFor = (1 / float(arguments["--check-frequency"]))
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
with Listener(on_release=on_release):
|
|
|
|
while not stop:
|
|
|
|
time.sleep(sleepFor)
|
|
|
|
# image grab
|
|
|
|
screen = np.array(ImageGrab.grab(bbox=bbox))
|
2018-05-03 16:37:18 +00:00
|
|
|
new_screen = process_img(screen)
|
2019-02-05 09:33:59 +00:00
|
|
|
hueValue = new_screen[0][0][0]
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
# find currentlable
|
|
|
|
currentLabel = 3
|
|
|
|
for i, val in enumerate(hVals):
|
|
|
|
if hueValue == val:
|
|
|
|
currentLabel = i
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
# check if it passes threshold, if so change labelNum
|
|
|
|
if prevLabel == currentLabel:
|
|
|
|
current_thresh += 1
|
|
|
|
else:
|
|
|
|
current_thresh = 0
|
|
|
|
prevLabel = currentLabel
|
|
|
|
if current_thresh >= threshold:
|
|
|
|
labelNum = currentLabel
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
# use label num
|
2018-05-03 16:37:18 +00:00
|
|
|
if not pause:
|
2019-02-05 09:33:59 +00:00
|
|
|
|
|
|
|
# fish caught
|
|
|
|
if labelNum == 0:
|
|
|
|
if not hooked:
|
|
|
|
fishCaught += 1
|
2018-05-03 16:37:18 +00:00
|
|
|
timeToHook = time.time() - stickInitTime
|
|
|
|
pullStick(fishCaught, timeToHook)
|
2019-02-05 09:33:59 +00:00
|
|
|
hooked = True
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
# fishing
|
2018-05-03 16:37:18 +00:00
|
|
|
if labelNum == 1:
|
2019-02-05 09:33:59 +00:00
|
|
|
hooked = False
|
|
|
|
if not timerStarted:
|
2018-05-03 16:37:18 +00:00
|
|
|
stickInitTime = time.time()
|
|
|
|
timerStarted = True
|
|
|
|
if (time.time() - stickInitTime) >= STICK_TIMEOUT:
|
|
|
|
print("STICK TIMED OUT, THROWING AGAIN")
|
2019-02-05 09:33:59 +00:00
|
|
|
pyautogui.press('e')
|
2018-05-03 16:37:18 +00:00
|
|
|
timerStarted = False
|
|
|
|
else:
|
|
|
|
timerStarted = False
|
|
|
|
|
2019-02-05 09:33:59 +00:00
|
|
|
# looking on hole
|
2018-05-03 16:37:18 +00:00
|
|
|
if labelNum == 2:
|
2019-02-05 16:44:48 +00:00
|
|
|
if not threwStick:
|
|
|
|
pyautogui.press('e')
|
|
|
|
threwStick = True
|
|
|
|
else:
|
|
|
|
threwStick = False
|
2019-02-05 09:33:59 +00:00
|
|
|
|
|
|
|
# not looking on hole
|
|
|
|
if labelNum == 3:
|
|
|
|
if not holeDepleteSent:
|
|
|
|
if fishCaught > 0:
|
2018-05-03 16:37:18 +00:00
|
|
|
print("HOLE DEPLETED")
|
|
|
|
if use_net:
|
|
|
|
net.sendHoleDeplete(fishCaught)
|
|
|
|
fishCaught = 0
|
|
|
|
holeDepleteSent = True
|
|
|
|
else:
|
2019-02-05 09:33:59 +00:00
|
|
|
holeDepleteSent = False
|
|
|
|
|
2019-02-05 15:18:20 +00:00
|
|
|
if debug or configPL:
|
2019-02-05 09:33:59 +00:00
|
|
|
print(str(labelNum) + ":" + str(hueValue))
|
|
|
|
cv2.imshow('image', process_show(screen))
|
2018-05-03 16:37:18 +00:00
|
|
|
showedControls = False
|
|
|
|
else:
|
|
|
|
if not showedControls:
|
|
|
|
showedControls = True
|
|
|
|
print(ctrl_help)
|
2019-02-05 09:33:59 +00:00
|
|
|
cv2.destroyAllWindows()
|
2018-05-03 16:37:18 +00:00
|
|
|
|
2019-02-05 15:18:20 +00:00
|
|
|
if configPL:
|
|
|
|
updatePixelLoc()
|
|
|
|
configPixelSave = False
|
|
|
|
elif not configPixelSave:
|
|
|
|
pickle.dump(pixelLoc, open("pixelLoc.pickle", "wb"))
|
|
|
|
cv2.waitKey(25)
|
2018-05-03 16:37:18 +00:00
|
|
|
|
|
|
|
|
2019-02-05 15:18:20 +00:00
|
|
|
if __name__ == "__main__":
|
2019-02-05 09:33:59 +00:00
|
|
|
startFishing()
|