Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.52 KB | None | 0 0
  1. import numpy
  2. import pyautogui
  3. import cv2
  4. import time
  5. from time import gmtime, strftime
  6. import random
  7. import win32gui
  8. import win32api
  9. import win32con
  10. import keyboard
  11.  
  12. import ctypes
  13. from ctypes import wintypes
  14.  
  15. import pyKey
  16. from pyKey import pressKey, releaseKey, press, sendSequence, showKeys
  17. from datetime import datetime
  18.  
  19. user32 = ctypes.WinDLL('user32', use_last_error=True)
  20. MAX_NB_RUNS = 500
  21. MAX_NB_BAIT = 0
  22. BAIT_DURATION_MIN = 50
  23. BAIT_DURATION_MAX = 55
  24.  
  25. USE_TRAP = 0
  26. TRAP_DURATION_MIN = 300
  27. TRAP_DURATION_MAX = 305
  28. trap_status = "undeployed"
  29. last_trap_date = None
  30. trap_interval = None
  31.  
  32.  
  33. NB_RUNS = 0
  34. NB_BAITS_CONSUMED = 0
  35. INPUT_MOUSE = 0
  36. INPUT_KEYBOARD = 1
  37. INPUT_HARDWARE = 2
  38.  
  39. KEYEVENTF_EXTENDEDKEY = 0x0001
  40. KEYEVENTF_KEYUP = 0x0002
  41. KEYEVENTF_UNICODE = 0x0004
  42. KEYEVENTF_SCANCODE = 0x0008
  43.  
  44. MAPVK_VK_TO_VSC = 0
  45.  
  46. # msdn.microsoft.com/en-us/library/dd375731
  47. VK_TAB = 0x09
  48. VK_MENU = 0x12
  49. VK_SPACE = 0x20
  50. # C struct definitions
  51.  
  52. wintypes.ULONG_PTR = wintypes.WPARAM
  53.  
  54.  
  55. class MOUSEINPUT(ctypes.Structure):
  56. _fields_ = (("dx", wintypes.LONG),
  57. ("dy", wintypes.LONG),
  58. ("mouseData", wintypes.DWORD),
  59. ("dwFlags", wintypes.DWORD),
  60. ("time", wintypes.DWORD),
  61. ("dwExtraInfo", wintypes.ULONG_PTR))
  62.  
  63. class KEYBDINPUT(ctypes.Structure):
  64. _fields_ = (("wVk", wintypes.WORD),
  65. ("wScan", wintypes.WORD),
  66. ("dwFlags", wintypes.DWORD),
  67. ("time", wintypes.DWORD),
  68. ("dwExtraInfo", wintypes.ULONG_PTR))
  69.  
  70. def __init__(self, *args, **kwds):
  71. super(KEYBDINPUT, self).__init__(*args, **kwds)
  72. # some programs use the scan code even if KEYEVENTF_SCANCODE
  73. # isn't set in dwFflags, so attempt to map the correct code.
  74. if not self.dwFlags & KEYEVENTF_UNICODE:
  75. self.wScan = user32.MapVirtualKeyExW(self.wVk,
  76. MAPVK_VK_TO_VSC, 0)
  77.  
  78. class HARDWAREINPUT(ctypes.Structure):
  79. _fields_ = (("uMsg", wintypes.DWORD),
  80. ("wParamL", wintypes.WORD),
  81. ("wParamH", wintypes.WORD))
  82.  
  83. class INPUT(ctypes.Structure):
  84. class _INPUT(ctypes.Union):
  85. _fields_ = (("ki", KEYBDINPUT),
  86. ("mi", MOUSEINPUT),
  87. ("hi", HARDWAREINPUT))
  88. _anonymous_ = ("_input",)
  89. _fields_ = (("type", wintypes.DWORD),
  90. ("_input", _INPUT))
  91.  
  92. LPINPUT = ctypes.POINTER(INPUT)
  93.  
  94. def _check_count(result, func, args):
  95. if result == 0:
  96. raise ctypes.WinError(ctypes.get_last_error())
  97. return args
  98.  
  99. # Functions
  100.  
  101. def PressKey(hexKeyCode):
  102. x = INPUT(type=INPUT_KEYBOARD,
  103. ki=KEYBDINPUT(wVk=hexKeyCode))
  104. user32.SendInput(1, ctypes.byref(x), ctypes.sizeof(x))
  105.  
  106. def ReleaseKey(hexKeyCode):
  107. x = INPUT(type=INPUT_KEYBOARD,
  108. ki=KEYBDINPUT(wVk=hexKeyCode,
  109. dwFlags=KEYEVENTF_KEYUP))
  110. user32.SendInput(1, ctypes.byref(x), ctypes.sizeof(x))
  111.  
  112. def AltTab():
  113. """Press Alt+Tab and hold Alt key for 2 seconds
  114. in order to see the overlay.
  115. """
  116. PressKey(VK_MENU) # Alt
  117. PressKey(VK_TAB) # Tab
  118. ReleaseKey(VK_TAB) # Tab~
  119. time.sleep(2)
  120. ReleaseKey(VK_MENU) # Alt~
  121.  
  122. def date_diff_in_Seconds(dt2, dt1):
  123. timedelta = dt2 - dt1
  124. return timedelta.days * 24 * 3600 + timedelta.seconds
  125.  
  126.  
  127.  
  128. bait_interval = random.randint(BAIT_DURATION_MIN, BAIT_DURATION_MAX)
  129. last_bait_date = None
  130. def useBait():
  131. global last_bait_date
  132. global bait_interval
  133. global NB_BAITS_CONSUMED
  134. global MAX_NB_BAIT
  135. if NB_BAITS_CONSUMED < MAX_NB_BAIT:
  136. if last_bait_date is None:
  137. print(strftime("%H:%M:%S", gmtime()), "throwing bait")
  138. last_bait_date = datetime.now()
  139. bait_interval = random.randint(BAIT_DURATION_MIN, BAIT_DURATION_MAX)
  140. pressKey('s')
  141. time.sleep( random.uniform( 0.05, 0.1 ))
  142. releaseKey('s')
  143. time.sleep(5.5)
  144. NB_BAITS_CONSUMED += 1
  145. else:
  146. diff = date_diff_in_Seconds(datetime.now(), last_bait_date)
  147. if diff > bait_interval:
  148. last_bait_date = None
  149.  
  150. fish3 = cv2.imread("fish3.png", 1)
  151. orange = cv2.imread("orange.png", 1)
  152. orange_height = orange.shape[0]
  153. orange_width = orange.shape[1]
  154. orange_x = None
  155. orange_y = None
  156.  
  157. bouchon2 = cv2.imread("bouchon2.png", 0)
  158. bouchon2_height = bouchon2.shape[0]
  159. bouchon2_width = bouchon2.shape[1]
  160. bouchon2_x = None
  161. bouchon2_y = None
  162.  
  163. def findOrangePosition(frame):
  164. lower_orange = numpy.array([15,100,100])
  165. upper_orange = numpy.array([19,255,255])
  166. result = None
  167. # Threshold the HSV image to get only blue colors
  168. mask = cv2.inRange(frame, lower_orange,upper_orange)
  169. orangecnts = cv2.findContours(mask.copy(),
  170. cv2.RETR_EXTERNAL,
  171. cv2.CHAIN_APPROX_SIMPLE)[-2]
  172. if len(orangecnts)>0:
  173. orange_area = max(orangecnts, key=cv2.contourArea)
  174. (xg,yg,wg,hg) = cv2.boundingRect(orange_area)
  175. result = yg+(hg*0.7)
  176. return result
  177.  
  178. def rgbToHsv(red,green,blue):
  179. color = numpy.uint8([[[blue, green, red]]])
  180. hsv_color = cv2.cvtColor(color, cv2.COLOR_BGR2HSV)
  181. hue = hsv_color[0][0][0]
  182.  
  183. print("Lower bound is :"),
  184. print("[" + str(hue-2) + ", 100, 100]\n")
  185.  
  186. print("Upper bound is :"),
  187. print("[" + str(hue + 2) + ", 255, 255]")
  188.  
  189. def useTrap():
  190. global last_trap_date
  191. global trap_interval
  192. global USE_TRAP
  193. global TRAP_DURATION_MIN
  194. global TRAP_DURATION_MAX
  195. global trap_status
  196.  
  197.  
  198. if USE_TRAP == 1:
  199. if last_trap_date is None:
  200. print(strftime("%H:%M:%S", gmtime()), "Using trap..")
  201. last_trap_date = datetime.now()
  202. trap_interval = random.randint(TRAP_DURATION_MIN, TRAP_DURATION_MAX)
  203.  
  204. if trap_status == "deployed":
  205. pressKey('g')
  206. time.sleep( random.uniform( 0.05, 0.1 ))
  207. releaseKey('g')
  208. time.sleep(6)
  209. trap_status = "undeployed"
  210.  
  211. pressKey('g')
  212. time.sleep( random.uniform( 0.05, 0.1 ))
  213. releaseKey('g')
  214. time.sleep(4)
  215. trap_status = "deployed"
  216.  
  217.  
  218. else:
  219. diff = date_diff_in_Seconds(datetime.now(), last_trap_date)
  220. if diff > trap_interval:
  221. last_trap_date = None
  222. def useNet():
  223. global bouchon2
  224. global bouchon2_height
  225. global bouchon2_width
  226. global orange
  227. global fish3
  228. global orange_height
  229. global orange_width
  230. global orange_x
  231. global orange_y
  232. global bouchon2_x
  233. global bouchon2_y
  234. image = pyautogui.screenshot(region=(0,0,int(screen.weight/2),screen.height))
  235. image = cv2.cvtColor(numpy.array(image), 0)
  236. image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
  237.  
  238. fish3_coordinates = cv2.matchTemplate(image, fish3, cv2.TM_SQDIFF_NORMED)
  239. threshold = 0.009
  240. fish3_loc = numpy.where(fish3_coordinates <= threshold )
  241. print(strftime("%H:%M:%S", gmtime()),"CHECKING FISHING NET!")
  242. if len(fish3_loc[0]) > 0:
  243. pressKey('d')
  244. time.sleep(random.uniform( 0.05, 0.1 ))
  245. releaseKey('d')
  246.  
  247. run = 1
  248. # image = pyautogui.screenshot(region=(300, 100, 400, 600))
  249. time.sleep(6.5)
  250. orangeNotFound = 1
  251. while(orangeNotFound):
  252. image = pyautogui.screenshot(region=(441,129,77,445))
  253. image = cv2.cvtColor(numpy.array(image), 0)
  254. image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
  255. orange_y = findOrangePosition(image)
  256. if orange_y is not None:
  257. print(strftime("%H:%M:%S", gmtime()),"START!")
  258. pyautogui.screenshot(region=(441,129,77,445)).save("detectedImagedddd.png")
  259. orangeNotFound = 0
  260. else:
  261. print(strftime("%H:%M:%S", gmtime()),"WAITING")
  262.  
  263. while(run):
  264. image2 = pyautogui.screenshot(region=(441,129,77,445))
  265. image2 = cv2.cvtColor(numpy.array(image2), 0)
  266. image2 = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)
  267.  
  268. bouchon2_coordinates = cv2.matchTemplate(image2, bouchon2, cv2.TM_CCOEFF_NORMED)
  269. bouchon2_loc = numpy.where( bouchon2_coordinates >= 0.7)
  270.  
  271. if len(bouchon2_loc[0]) > 0:
  272.  
  273. for pt in zip(*bouchon2_loc[::-1]):
  274. bouchon2_x = int(pt[0]+bouchon2_width/2)
  275. bouchon2_y = int(pt[1]+bouchon2_height/2)
  276. if bouchon2_y > orange_y:
  277. press('SPACEBAR')
  278. time.sleep(0.07)
  279. else:
  280. print(strftime("%H:%M:%S", gmtime()),"NOT FOUND BOUCHON")
  281. run=0
  282. time.sleep(random.uniform(4.5, 6.5))
  283.  
  284.  
  285. class screen:
  286. weight = 1920
  287. height = 1080
  288. flag = "pulled"
  289. # pyautogui.keyDown('z')
  290.  
  291. template = cv2.imread("template.png", 0)
  292. bouchon = cv2.imread("bouchon.png", 0)
  293.  
  294. print(strftime("%H:%M:%S", gmtime()), "starting a bot")
  295. time.sleep(5)
  296.  
  297. last_throw_date = None
  298.  
  299. while(NB_RUNS < MAX_NB_RUNS):
  300. if flag == "pulled":
  301. useTrap()
  302. useNet()
  303. useBait()
  304. print(strftime("%H:%M:%S", gmtime()), "throwing a fishing rod [1]","Runs == ",NB_RUNS)
  305. pressKey('w')
  306. time.sleep( random.uniform( 0.05, 0.1 ))
  307. releaseKey('w')
  308. flag = "thrown"
  309. last_throw_date = datetime.now()
  310. time.sleep( random.uniform(4.5, 6.5))
  311.  
  312.  
  313. image = pyautogui.screenshot(region=(screen.weight/2 - 100, screen.height/2 - 150, 200, 200))
  314. image = cv2.cvtColor(numpy.array(image), 0)
  315. image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  316.  
  317. template_coordinates = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
  318. loc = numpy.where( template_coordinates >= 0.7)
  319.  
  320.  
  321. if len(loc[0]) > 0:
  322. if flag == "thrown":
  323. print(strftime("%H:%M:%S", gmtime()), "Time to fish! Runs == ",NB_RUNS)
  324. #r1 = random.randint(0, 20)
  325. #if r1 == 11:
  326. # time.sleep(random.uniform(1.5, 2))
  327. # NB_CONSECUTIVE_SUCCESS = 0
  328. #else:
  329. NB_RUNS+=1
  330. time.sleep(random.uniform(0.2, 1.0))
  331. last_throw_date = None
  332.  
  333. pressKey('w')
  334. time.sleep( random.uniform( 0.05, 0.1 ))
  335. releaseKey('w')
  336. flag = "pulled"
  337. time.sleep(random.uniform(6.5, 7.2))
  338.  
  339. bouchon_coordinates = cv2.matchTemplate(image, bouchon, cv2.TM_CCOEFF_NORMED)
  340. bouchon_loc = numpy.where( bouchon_coordinates >= 0.7)
  341.  
  342. if len(bouchon_loc[0]) == 0 and flag == "pulled":
  343. useTrap()
  344. useNet()
  345. useBait()
  346.  
  347.  
  348. print(strftime("%H:%M:%S", gmtime()), "throwing a fishing rod [2]")
  349. pressKey('w')
  350. time.sleep(random.uniform( 0.05, 0.1 ))
  351. releaseKey('w')
  352. last_throw_date = datetime.now()
  353. flag = "thrown"
  354. time.sleep( random.uniform(4.5, 6.5))
  355.  
  356. #print(strftime("%H:%M:%S", gmtime()), "Not time yet!")
  357. if last_throw_date is not None and date_diff_in_Seconds(datetime.now(), last_throw_date) > 50:
  358. print(strftime("%H:%M:%S", gmtime()), "Weird, nothing was found!")
  359. pressKey('w')
  360. time.sleep(random.uniform( 0.05, 0.1 ))
  361. releaseKey('w')
  362. last_throw_date = None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement