Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy
- import pyautogui
- import cv2
- import time
- from time import gmtime, strftime
- import random
- import win32gui
- import win32api
- import win32con
- import keyboard
- import ctypes
- from ctypes import wintypes
- import pyKey
- from pyKey import pressKey, releaseKey, press, sendSequence, showKeys
- from datetime import datetime
- user32 = ctypes.WinDLL('user32', use_last_error=True)
- MAX_NB_RUNS = 500
- MAX_NB_BAIT = 0
- BAIT_DURATION_MIN = 50
- BAIT_DURATION_MAX = 55
- USE_TRAP = 0
- TRAP_DURATION_MIN = 300
- TRAP_DURATION_MAX = 305
- trap_status = "undeployed"
- last_trap_date = None
- trap_interval = None
- NB_RUNS = 0
- NB_BAITS_CONSUMED = 0
- INPUT_MOUSE = 0
- INPUT_KEYBOARD = 1
- INPUT_HARDWARE = 2
- KEYEVENTF_EXTENDEDKEY = 0x0001
- KEYEVENTF_KEYUP = 0x0002
- KEYEVENTF_UNICODE = 0x0004
- KEYEVENTF_SCANCODE = 0x0008
- MAPVK_VK_TO_VSC = 0
- # msdn.microsoft.com/en-us/library/dd375731
- VK_TAB = 0x09
- VK_MENU = 0x12
- VK_SPACE = 0x20
- # C struct definitions
- wintypes.ULONG_PTR = wintypes.WPARAM
- class MOUSEINPUT(ctypes.Structure):
- _fields_ = (("dx", wintypes.LONG),
- ("dy", wintypes.LONG),
- ("mouseData", wintypes.DWORD),
- ("dwFlags", wintypes.DWORD),
- ("time", wintypes.DWORD),
- ("dwExtraInfo", wintypes.ULONG_PTR))
- class KEYBDINPUT(ctypes.Structure):
- _fields_ = (("wVk", wintypes.WORD),
- ("wScan", wintypes.WORD),
- ("dwFlags", wintypes.DWORD),
- ("time", wintypes.DWORD),
- ("dwExtraInfo", wintypes.ULONG_PTR))
- def __init__(self, *args, **kwds):
- super(KEYBDINPUT, self).__init__(*args, **kwds)
- # some programs use the scan code even if KEYEVENTF_SCANCODE
- # isn't set in dwFflags, so attempt to map the correct code.
- if not self.dwFlags & KEYEVENTF_UNICODE:
- self.wScan = user32.MapVirtualKeyExW(self.wVk,
- MAPVK_VK_TO_VSC, 0)
- class HARDWAREINPUT(ctypes.Structure):
- _fields_ = (("uMsg", wintypes.DWORD),
- ("wParamL", wintypes.WORD),
- ("wParamH", wintypes.WORD))
- class INPUT(ctypes.Structure):
- class _INPUT(ctypes.Union):
- _fields_ = (("ki", KEYBDINPUT),
- ("mi", MOUSEINPUT),
- ("hi", HARDWAREINPUT))
- _anonymous_ = ("_input",)
- _fields_ = (("type", wintypes.DWORD),
- ("_input", _INPUT))
- LPINPUT = ctypes.POINTER(INPUT)
- def _check_count(result, func, args):
- if result == 0:
- raise ctypes.WinError(ctypes.get_last_error())
- return args
- # Functions
- def PressKey(hexKeyCode):
- x = INPUT(type=INPUT_KEYBOARD,
- ki=KEYBDINPUT(wVk=hexKeyCode))
- user32.SendInput(1, ctypes.byref(x), ctypes.sizeof(x))
- def ReleaseKey(hexKeyCode):
- x = INPUT(type=INPUT_KEYBOARD,
- ki=KEYBDINPUT(wVk=hexKeyCode,
- dwFlags=KEYEVENTF_KEYUP))
- user32.SendInput(1, ctypes.byref(x), ctypes.sizeof(x))
- def AltTab():
- """Press Alt+Tab and hold Alt key for 2 seconds
- in order to see the overlay.
- """
- PressKey(VK_MENU) # Alt
- PressKey(VK_TAB) # Tab
- ReleaseKey(VK_TAB) # Tab~
- time.sleep(2)
- ReleaseKey(VK_MENU) # Alt~
- def date_diff_in_Seconds(dt2, dt1):
- timedelta = dt2 - dt1
- return timedelta.days * 24 * 3600 + timedelta.seconds
- bait_interval = random.randint(BAIT_DURATION_MIN, BAIT_DURATION_MAX)
- last_bait_date = None
- def useBait():
- global last_bait_date
- global bait_interval
- global NB_BAITS_CONSUMED
- global MAX_NB_BAIT
- if NB_BAITS_CONSUMED < MAX_NB_BAIT:
- if last_bait_date is None:
- print(strftime("%H:%M:%S", gmtime()), "throwing bait")
- last_bait_date = datetime.now()
- bait_interval = random.randint(BAIT_DURATION_MIN, BAIT_DURATION_MAX)
- pressKey('s')
- time.sleep( random.uniform( 0.05, 0.1 ))
- releaseKey('s')
- time.sleep(5.5)
- NB_BAITS_CONSUMED += 1
- else:
- diff = date_diff_in_Seconds(datetime.now(), last_bait_date)
- if diff > bait_interval:
- last_bait_date = None
- fish3 = cv2.imread("fish3.png", 1)
- orange = cv2.imread("orange.png", 1)
- orange_height = orange.shape[0]
- orange_width = orange.shape[1]
- orange_x = None
- orange_y = None
- bouchon2 = cv2.imread("bouchon2.png", 0)
- bouchon2_height = bouchon2.shape[0]
- bouchon2_width = bouchon2.shape[1]
- bouchon2_x = None
- bouchon2_y = None
- def findOrangePosition(frame):
- lower_orange = numpy.array([15,100,100])
- upper_orange = numpy.array([19,255,255])
- result = None
- # Threshold the HSV image to get only blue colors
- mask = cv2.inRange(frame, lower_orange,upper_orange)
- orangecnts = cv2.findContours(mask.copy(),
- cv2.RETR_EXTERNAL,
- cv2.CHAIN_APPROX_SIMPLE)[-2]
- if len(orangecnts)>0:
- orange_area = max(orangecnts, key=cv2.contourArea)
- (xg,yg,wg,hg) = cv2.boundingRect(orange_area)
- result = yg+(hg*0.7)
- return result
- def rgbToHsv(red,green,blue):
- color = numpy.uint8([[[blue, green, red]]])
- hsv_color = cv2.cvtColor(color, cv2.COLOR_BGR2HSV)
- hue = hsv_color[0][0][0]
- print("Lower bound is :"),
- print("[" + str(hue-2) + ", 100, 100]\n")
- print("Upper bound is :"),
- print("[" + str(hue + 2) + ", 255, 255]")
- def useTrap():
- global last_trap_date
- global trap_interval
- global USE_TRAP
- global TRAP_DURATION_MIN
- global TRAP_DURATION_MAX
- global trap_status
- if USE_TRAP == 1:
- if last_trap_date is None:
- print(strftime("%H:%M:%S", gmtime()), "Using trap..")
- last_trap_date = datetime.now()
- trap_interval = random.randint(TRAP_DURATION_MIN, TRAP_DURATION_MAX)
- if trap_status == "deployed":
- pressKey('g')
- time.sleep( random.uniform( 0.05, 0.1 ))
- releaseKey('g')
- time.sleep(6)
- trap_status = "undeployed"
- pressKey('g')
- time.sleep( random.uniform( 0.05, 0.1 ))
- releaseKey('g')
- time.sleep(4)
- trap_status = "deployed"
- else:
- diff = date_diff_in_Seconds(datetime.now(), last_trap_date)
- if diff > trap_interval:
- last_trap_date = None
- def useNet():
- global bouchon2
- global bouchon2_height
- global bouchon2_width
- global orange
- global fish3
- global orange_height
- global orange_width
- global orange_x
- global orange_y
- global bouchon2_x
- global bouchon2_y
- image = pyautogui.screenshot(region=(0,0,int(screen.weight/2),screen.height))
- image = cv2.cvtColor(numpy.array(image), 0)
- image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
- fish3_coordinates = cv2.matchTemplate(image, fish3, cv2.TM_SQDIFF_NORMED)
- threshold = 0.009
- fish3_loc = numpy.where(fish3_coordinates <= threshold )
- print(strftime("%H:%M:%S", gmtime()),"CHECKING FISHING NET!")
- if len(fish3_loc[0]) > 0:
- pressKey('d')
- time.sleep(random.uniform( 0.05, 0.1 ))
- releaseKey('d')
- run = 1
- # image = pyautogui.screenshot(region=(300, 100, 400, 600))
- time.sleep(6.5)
- orangeNotFound = 1
- while(orangeNotFound):
- image = pyautogui.screenshot(region=(441,129,77,445))
- image = cv2.cvtColor(numpy.array(image), 0)
- image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
- orange_y = findOrangePosition(image)
- if orange_y is not None:
- print(strftime("%H:%M:%S", gmtime()),"START!")
- pyautogui.screenshot(region=(441,129,77,445)).save("detectedImagedddd.png")
- orangeNotFound = 0
- else:
- print(strftime("%H:%M:%S", gmtime()),"WAITING")
- while(run):
- image2 = pyautogui.screenshot(region=(441,129,77,445))
- image2 = cv2.cvtColor(numpy.array(image2), 0)
- image2 = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)
- bouchon2_coordinates = cv2.matchTemplate(image2, bouchon2, cv2.TM_CCOEFF_NORMED)
- bouchon2_loc = numpy.where( bouchon2_coordinates >= 0.7)
- if len(bouchon2_loc[0]) > 0:
- for pt in zip(*bouchon2_loc[::-1]):
- bouchon2_x = int(pt[0]+bouchon2_width/2)
- bouchon2_y = int(pt[1]+bouchon2_height/2)
- if bouchon2_y > orange_y:
- press('SPACEBAR')
- time.sleep(0.07)
- else:
- print(strftime("%H:%M:%S", gmtime()),"NOT FOUND BOUCHON")
- run=0
- time.sleep(random.uniform(4.5, 6.5))
- class screen:
- weight = 1920
- height = 1080
- flag = "pulled"
- # pyautogui.keyDown('z')
- template = cv2.imread("template.png", 0)
- bouchon = cv2.imread("bouchon.png", 0)
- print(strftime("%H:%M:%S", gmtime()), "starting a bot")
- time.sleep(5)
- last_throw_date = None
- while(NB_RUNS < MAX_NB_RUNS):
- if flag == "pulled":
- useTrap()
- useNet()
- useBait()
- print(strftime("%H:%M:%S", gmtime()), "throwing a fishing rod [1]","Runs == ",NB_RUNS)
- pressKey('w')
- time.sleep( random.uniform( 0.05, 0.1 ))
- releaseKey('w')
- flag = "thrown"
- last_throw_date = datetime.now()
- time.sleep( random.uniform(4.5, 6.5))
- image = pyautogui.screenshot(region=(screen.weight/2 - 100, screen.height/2 - 150, 200, 200))
- image = cv2.cvtColor(numpy.array(image), 0)
- image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- template_coordinates = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
- loc = numpy.where( template_coordinates >= 0.7)
- if len(loc[0]) > 0:
- if flag == "thrown":
- print(strftime("%H:%M:%S", gmtime()), "Time to fish! Runs == ",NB_RUNS)
- #r1 = random.randint(0, 20)
- #if r1 == 11:
- # time.sleep(random.uniform(1.5, 2))
- # NB_CONSECUTIVE_SUCCESS = 0
- #else:
- NB_RUNS+=1
- time.sleep(random.uniform(0.2, 1.0))
- last_throw_date = None
- pressKey('w')
- time.sleep( random.uniform( 0.05, 0.1 ))
- releaseKey('w')
- flag = "pulled"
- time.sleep(random.uniform(6.5, 7.2))
- bouchon_coordinates = cv2.matchTemplate(image, bouchon, cv2.TM_CCOEFF_NORMED)
- bouchon_loc = numpy.where( bouchon_coordinates >= 0.7)
- if len(bouchon_loc[0]) == 0 and flag == "pulled":
- useTrap()
- useNet()
- useBait()
- print(strftime("%H:%M:%S", gmtime()), "throwing a fishing rod [2]")
- pressKey('w')
- time.sleep(random.uniform( 0.05, 0.1 ))
- releaseKey('w')
- last_throw_date = datetime.now()
- flag = "thrown"
- time.sleep( random.uniform(4.5, 6.5))
- #print(strftime("%H:%M:%S", gmtime()), "Not time yet!")
- if last_throw_date is not None and date_diff_in_Seconds(datetime.now(), last_throw_date) > 50:
- print(strftime("%H:%M:%S", gmtime()), "Weird, nothing was found!")
- pressKey('w')
- time.sleep(random.uniform( 0.05, 0.1 ))
- releaseKey('w')
- last_throw_date = None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement