Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. from PIL import ImageGrab, ImageFilter
  2. import PIL.Image
  3. import win32gui
  4. import os
  5. import pytesseract
  6. import cv2
  7. import io
  8. import deathbycaptcha
  9. import json
  10. import numpy as np
  11. import re
  12. from tkinter import *
  13. import time
  14. import tkinter.messagebox
  15. from threading import Thread
  16.  
  17.  
  18. class Config:
  19. username = 'drewdapilot'
  20. dbc_user = 'DrewDaPilot'
  21. dbc_pass = 'MCdude101'
  22.  
  23.  
  24. class SeatTracker:
  25. apparent_seat = int
  26. actual_seat = int
  27. actual_seats = {}
  28. seat_results = []
  29.  
  30.  
  31. client = deathbycaptcha.SocketClient(Config.dbc_user, Config.dbc_pass)
  32.  
  33.  
  34.  
  35.  
  36. toplist, winlist = [], []
  37. def enum_cb(hwnd, results):
  38. winlist.append((hwnd, win32gui.GetWindowText(hwnd)))
  39. win32gui.EnumWindows(enum_cb, toplist)
  40.  
  41.  
  42. positions = {}
  43.  
  44. def has_white(PIL_Image, threshold=720, min_white=100):
  45. """
  46. min_white is the minimum number of pixels in the image that are whiter than the threshold
  47. threshold is the minimum sum(RGB) to be considered white
  48. """
  49. arry = np.array(PIL_Image)
  50. w,h = PIL_Image.size
  51. x,y = 0,0
  52. whites = 0
  53.  
  54. while (x<h) and (y<w):
  55. if sum(arry[x,y]) >= threshold:
  56. whites += 1
  57. x += 1
  58. if x == h:
  59. x = 0
  60. y += 1
  61.  
  62. if whites >= min_white:
  63. return True
  64. return False
  65.  
  66. def Run():
  67. try:
  68. pokerwindow = [(hwnd, title) for hwnd, title in winlist if 'money' in title.lower()]
  69. # just grab the hwnd for first window matching firefox
  70. pokerwindow = pokerwindow[0]
  71. hwnd = pokerwindow[0]
  72. win32gui.SetForegroundWindow(hwnd)
  73. bbox = win32gui.GetWindowRect(hwnd)
  74. img = ImageGrab.grab(bbox)
  75. img.save('main.png')
  76.  
  77. coordinates = [
  78. (342,77,467,103),
  79. (682,142,784,165),
  80. (688,310,784,334),
  81. (372,394,482,419),
  82. (24,311,109,332),
  83. (19,146,118,165)
  84. ]
  85.  
  86. for i in range(len(coordinates)):
  87. seat = img.crop(coordinates[i])
  88. seat.save('seat%s.png' % str( i+1))
  89.  
  90. def seat_decode_thread(dictionary, key, path, size):
  91. result = client.decode(path, size)
  92. dictionary[key] = result
  93.  
  94. results_dict = {}
  95. threads = []
  96. for i in range(len(coordinates)):
  97. t = Thread(target=seat_decode_thread, args=(results_dict, i, 'seat%s.png' % str(i+1), 30))
  98. threads.append(t)
  99. for t in threads:
  100. t.start()
  101. for t in threads:
  102. t.join()
  103.  
  104. seat_result_dicts = []
  105. for i in range(len(results_dict)):
  106. seat_result_dicts.append(results_dict[i])
  107.  
  108. seat_results = []
  109. for srd in seat_result_dicts:
  110. try:
  111. seat_results.append(srd['text'])
  112. except:
  113. seat_results.append('')
  114. SeatTracker.seat_results = seat_results
  115. except IndexError:
  116. tkinter.messagebox.showinfo("Error", "The game was not started, please try again!")
  117.  
  118. window = Tk()
  119.  
  120. def GenMap():
  121. map = TopLevel()
  122. map.title("Seat Map")
  123. seat1_label = Label(text=SeatTracker.seat_results[1], side=TOP)
  124. seat2_label = Label(text=SeatTracker.seat_results[2], side=RIGHT)
  125. seat3_label = Label(text=SeatTracker.seat_results[3], side=RIGHT)
  126. seat4_label = Label(text=SeatTracker.seat_results[4], side=BOTTOM)
  127. seat6_label = Label(text=SeatTracker.seat_results[6], side=LEFT)
  128. seat5_label = Label(text=SeatTracker.seat_results[5], side=LEFT)
  129. seat1_label.pack()
  130. seat2_label.pack()
  131. seat3_label.pack()
  132. seat4_label.pack()
  133. seat5_label.pack()
  134. seat6_label.pack()
  135.  
  136.  
  137.  
  138. def Fill():
  139. filename = 'log.txt'
  140. with open(filename, 'r+') as myfile:
  141. data = myfile.read()
  142. SeatTracker.apparent_seat = SeatTracker.seat_results.index(Config.username) + 1
  143. SeatTracker.actual_seat = int(data[data.find(Config.username)-3])
  144. for i in range(6):
  145. if SeatTracker.seat_results[i] not in ['', 'k']:
  146. seat = PIL.Image.open('seat%s.png' % str(i + 1))
  147. if has_white(seat):
  148. seat_difference = SeatTracker.actual_seat - SeatTracker.apparent_seat
  149. SeatTracker.actual_seats[((i+seat_difference)%6)+1] = SeatTracker.seat_results[i]
  150. seat_difference = SeatTracker.actual_seat - SeatTracker.apparent_seat
  151. for k,v in SeatTracker.actual_seats.items():
  152. data.replace('Player%s' % k, v)
  153. print(data)
  154. myfile.seek(0)
  155. myfile.write(data)
  156. myfile.truncate()
  157.  
  158. window.title('PokerOS v1.0.0')
  159. RunButton = Button(text="Take Screenshot", command=Run)
  160. RunButton.pack()
  161. FillButton = Button(text="Fill Log with data:", command=Fill)
  162. FillButton.pack()
  163. MapButton = Button(text='View current map', command=GenMap)
  164. MapButton.pack()
  165. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement