Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! python3
- from PIL import Image
- import os, sys, time, random, pytesseract, pyautogui
- print('At any time, press Ctrl-C to quit the bot.\n')
- clientDetected = False
- clientPlaying = False
- pid = None
- window = None
- actualDesktop = None
- windowDesktop = None
- displaySize = None
- windowSize = None
- windowOffset = None
- def getDirectionAxis(fromX, fromY, toX, toY):
- if (toX == fromX):
- if (toY < fromY):
- return 0
- else:
- return 4
- else:
- if (toY == fromY):
- if (toX < fromX):
- return 6
- else:
- return 2
- else:
- if (toX < fromX):
- if (toY < fromY):
- return 7
- else:
- return 5
- else:
- if (toY < fromY):
- return 1
- else:
- return 3
- def getDirName(directionAxis):
- return {
- 0: 'N',
- 1: 'NE',
- 2: 'E',
- 3: 'SE',
- 4: 'S',
- 5: 'SW',
- 6: 'W',
- 7: 'NW',
- }[directionAxis]
- def getPid(program):
- os.system('(pidof ' + program + ') > .tmp')
- pid = open('.tmp', 'r').read()
- return pid.strip()
- def getWindow(pid):
- os.system('(xdotool search --pid ' + pid + ') > .tmp')
- window = open('.tmp', 'r').read()
- return window.strip()
- def getActualDesktop():
- os.system('(xdotool get_desktop) > .tmp')
- desktop = open('.tmp', 'r').read()
- return desktop.strip()
- def goToDesktop(desktop):
- os.system('(xdotool set_desktop ' + desktop + ') > .tmp')
- return True
- def getWindowDesktop(window):
- os.system('(xdotool get_desktop_for_window ' + window + ') > .tmp')
- windowDesktop = open('.tmp', 'r').read()
- return windowDesktop.strip()
- def setFocus(window):
- os.system('(xdotool windowfocus ' + window + ') > .tmp')
- os.system('(xdotool windowactivate ' + window + ') > .tmp')
- return True
- def maximizeWindow(window):
- os.system('(xdotool windowmove ' + window + ' 0 0) > .tmp')
- os.system('(xdotool windowsize ' + window + ' $(xdotool getdisplaygeometry)) > .tmp')
- os.system('(xdotool windowactivate ' + window + ') > .tmp')
- return True
- def minimizeWindow(window):
- os.system('(xdotool windowminimize ' + window + ') > .tmp')
- return True
- def setWindowPos(window, x, y):
- os.system('(xdotool windowmove ' + window + ' ' + str(x) + ' ' + str(y) +') > .tmp')
- return True
- return True
- def resizeWindow(window, x, y):
- os.system('(xdotool windowsize ' + window + ' ' + str(x) + ' ' + str(y) + ') > .tmp')
- return True
- def getWindowTitle(window):
- os.system('(xdotool getwindowname ' + window + ') > .tmp')
- windowTitle = open('.tmp', 'r').read()
- return windowTitle.strip()
- def getWindowsOffset(window):
- os.system('(xdotool getwindowgeometry --shell ' + window + ' | grep X=) > .tmp')
- windowX = open('.tmp', 'r').read().replace('X=', '')
- os.system('(xdotool getwindowgeometry --shell ' + window + ' | grep Y=) > .tmp')
- windowY = open('.tmp', 'r').read().replace('Y=', '')
- return [int(windowX), int(windowY)]
- def getWindowsSize(window):
- os.system('(xdotool getwindowgeometry --shell ' + window + ' | grep WIDTH=) > .tmp')
- windowWIDTH = open('.tmp', 'r').read().replace('WIDTH=', '')
- os.system('(xdotool getwindowgeometry --shell ' + window + ' | grep HEIGHT=) > .tmp')
- windowHEIGHT = open('.tmp', 'r').read().replace('HEIGHT=', '')
- return [int(windowWIDTH), int(windowHEIGHT)]
- def getDisplaySize():
- os.system('(xdotool getdisplaygeometry --shell | grep WIDTH=) > .tmp')
- windowWIDTH = open('.tmp', 'r').read().replace('WIDTH=', '')
- os.system('(xdotool getdisplaygeometry --shell | grep HEIGHT=) > .tmp')
- windowHEIGHT = open('.tmp', 'r').read().replace('HEIGHT=', '')
- return [int(windowWIDTH), int(windowHEIGHT)]
- def clearImage(image):
- pixels = image.load()
- for i in range(image.size[0]):
- for j in range(image.size[1]):
- x,y,z = pixels[i,j][0],pixels[i,j][1],pixels[i,j][2]
- x,y,z = abs(x-255), abs(y-255), abs(z-255)
- # Black Range
- if (x >= 100 and x <= 254):
- if (y >= 100 and y <= 254):
- if (y >= 100 and y <= 254):
- x,y,z=255,255,255
- pixels[i,j] = (x,y,z)
- width, height = image.size
- image = image.resize(((width * 2), (height * 2)), Image.NEAREST)
- return image
- def detectGameOpen():
- global clientDetected, clientPlaying
- clientDetected = False
- clientPlaying = False
- pid = getPid('Tibia/client')
- if (pid != False and pid != ""):
- window = getWindow(pid)
- if (window != False and window != ""):
- clientDetected = True
- title = getWindowTitle(window).split(" - ")
- if (len(title) == 2):
- clientPlaying = True
- def manageWindows():
- global pid, window, actualDesktop, windowDesktop, displaySize, windowSize, windowOffset
- pid = getPid('Tibia/client')
- window = getWindow(pid)
- actualDesktop = getActualDesktop()
- windowDesktop = getWindowDesktop(window)
- if (actualDesktop != windowDesktop):
- goToDesktop(windowDesktop)
- time.sleep(1)
- displaySize = getDisplaySize()
- windowSize = getWindowsSize(window)
- # setWindowPos(window, random.randint(0,100), random.randint(0,100))
- # time.sleep(1)
- # if (windowSize[0] != 1024 and windowSize[1] != 768):
- # resizeWindow(window, 1024, 768)
- # time.sleep(1)
- windowOffset = getWindowsOffset(window)
- setFocus(window)
- time.sleep(2)
- def start():
- while True:
- print("clientDetected: ", clientDetected)
- print("clientPlaying: ", clientPlaying)
- if (clientDetected == False):
- print('Detecting Tibia Client')
- detectGameOpen()
- if (clientDetected == False and clientPlaying == False):
- print('Could not find the Tibia Client');
- time.sleep(15)
- if (clientDetected == True and clientPlaying == False):
- print('Account not logged')
- time.sleep(15)
- if (clientDetected == True and clientPlaying == True):
- return False
- # main start
- try:
- start()
- manageWindows()
- dialog = pyautogui.locateOnScreen('./images/store_button.png');
- if (dialog != None):
- dialogX = dialog[0]
- dialogY = dialog[1]
- while True:
- # pega poção
- pyautogui.moveTo(202, 93, 1, pyautogui.easeInBounce)
- pyautogui.click(button='left', clicks=1, interval=0.0)
- pyautogui.dragTo(1827, 603, 1, button='left')
- time.sleep(0.25)
- # Consome as 100 poções usando magia
- for x in range(0,100):
- pyautogui.press('f9')
- time.sleep(2.1)
- pyautogui.press('f9')
- time.sleep(2.1)
- pyautogui.press('f2')
- time.sleep(0.25)
- # pass
- # Guarda os frascos vazios
- pyautogui.moveTo(1770, 541, 1, pyautogui.easeInBounce)
- pyautogui.click(button='left', clicks=1, interval=0.0)
- pyautogui.dragTo(255, 534, 1, button='left')
- time.sleep(0.25)
- else:
- print("Client not detected")
- except KeyboardInterrupt:
- print('\n\nBot stoped...\n\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement