Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import ImageGrab, ImageFilter
- import PIL.Image
- import win32gui
- import os
- import pytesseract
- import cv2
- import io
- import deathbycaptcha
- import json
- import numpy as np
- import re
- from tkinter import *
- import time
- import tkinter.messagebox
- from threading import Thread
- class Config:
- username = 'drewdapilot'
- dbc_user = 'DrewDaPilot'
- dbc_pass = 'MCdude101'
- class SeatTracker:
- apparent_seat = int
- actual_seat = int
- actual_seats = {}
- seat_results = []
- client = deathbycaptcha.SocketClient(Config.dbc_user, Config.dbc_pass)
- toplist, winlist = [], []
- def enum_cb(hwnd, results):
- winlist.append((hwnd, win32gui.GetWindowText(hwnd)))
- win32gui.EnumWindows(enum_cb, toplist)
- positions = {}
- def has_white(PIL_Image, threshold=720, min_white=100):
- """
- min_white is the minimum number of pixels in the image that are whiter than the threshold
- threshold is the minimum sum(RGB) to be considered white
- """
- arry = np.array(PIL_Image)
- w,h = PIL_Image.size
- x,y = 0,0
- whites = 0
- while (x<h) and (y<w):
- if sum(arry[x,y]) >= threshold:
- whites += 1
- x += 1
- if x == h:
- x = 0
- y += 1
- if whites >= min_white:
- return True
- return False
- def Run():
- try:
- pokerwindow = [(hwnd, title) for hwnd, title in winlist if 'money' in title.lower()]
- # just grab the hwnd for first window matching firefox
- pokerwindow = pokerwindow[0]
- hwnd = pokerwindow[0]
- win32gui.SetForegroundWindow(hwnd)
- bbox = win32gui.GetWindowRect(hwnd)
- img = ImageGrab.grab(bbox)
- img.save('main.png')
- coordinates = [
- (342,77,467,103),
- (682,142,784,165),
- (688,310,784,334),
- (372,394,482,419),
- (24,311,109,332),
- (19,146,118,165)
- ]
- for i in range(len(coordinates)):
- seat = img.crop(coordinates[i])
- seat.save('seat%s.png' % str( i+1))
- def seat_decode_thread(dictionary, key, path, size):
- result = client.decode(path, size)
- dictionary[key] = result
- results_dict = {}
- threads = []
- for i in range(len(coordinates)):
- t = Thread(target=seat_decode_thread, args=(results_dict, i, 'seat%s.png' % str(i+1), 30))
- threads.append(t)
- for t in threads:
- t.start()
- for t in threads:
- t.join()
- seat_result_dicts = []
- for i in range(len(results_dict)):
- seat_result_dicts.append(results_dict[i])
- seat_results = []
- for srd in seat_result_dicts:
- try:
- seat_results.append(srd['text'])
- except:
- seat_results.append('')
- SeatTracker.seat_results = seat_results
- except IndexError:
- tkinter.messagebox.showinfo("Error", "The game was not started, please try again!")
- window = Tk()
- def GenMap():
- map = TopLevel()
- map.title("Seat Map")
- seat1_label = Label(text=SeatTracker.seat_results[1], side=TOP)
- seat2_label = Label(text=SeatTracker.seat_results[2], side=RIGHT)
- seat3_label = Label(text=SeatTracker.seat_results[3], side=RIGHT)
- seat4_label = Label(text=SeatTracker.seat_results[4], side=BOTTOM)
- seat6_label = Label(text=SeatTracker.seat_results[6], side=LEFT)
- seat5_label = Label(text=SeatTracker.seat_results[5], side=LEFT)
- seat1_label.pack()
- seat2_label.pack()
- seat3_label.pack()
- seat4_label.pack()
- seat5_label.pack()
- seat6_label.pack()
- def Fill():
- filename = 'log.txt'
- with open(filename, 'r+') as myfile:
- data = myfile.read()
- SeatTracker.apparent_seat = SeatTracker.seat_results.index(Config.username) + 1
- SeatTracker.actual_seat = int(data[data.find(Config.username)-3])
- for i in range(6):
- if SeatTracker.seat_results[i] not in ['', 'k']:
- seat = PIL.Image.open('seat%s.png' % str(i + 1))
- if has_white(seat):
- seat_difference = SeatTracker.actual_seat - SeatTracker.apparent_seat
- SeatTracker.actual_seats[((i+seat_difference)%6)+1] = SeatTracker.seat_results[i]
- seat_difference = SeatTracker.actual_seat - SeatTracker.apparent_seat
- for k,v in SeatTracker.actual_seats.items():
- data.replace('Player%s' % k, v)
- print(data)
- myfile.seek(0)
- myfile.write(data)
- myfile.truncate()
- window.title('PokerOS v1.0.0')
- RunButton = Button(text="Take Screenshot", command=Run)
- RunButton.pack()
- FillButton = Button(text="Fill Log with data:", command=Fill)
- FillButton.pack()
- MapButton = Button(text='View current map', command=GenMap)
- MapButton.pack()
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement