-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpyrobot.py
145 lines (111 loc) · 4.18 KB
/
pyrobot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#-*- coding: utf-8 -*-
"""
Toutes les coordonnées sont basées sur un écran de résolution 1920x1080
x_pad = 0
y_pad = 0
game area = x_pad+1, y_pad+1, x_pad+screen_width, y_pad+screen_height
"""
import config
import os
import time
import mouse
import win32api, win32con #à virer car déjà appelé dans mouse.py
from PIL import ImageOps # plus besoin
from PIL import ImageChops
import cv2
#import player
import sniffer
import queue
from threading import Thread
import watcher
import pyautogui
# x_pad and y_pad are the position of the window on your screen (no problem if full screen)
x_pad = 0
y_pad = 0
screen_width = 670
screen_height = 550
debug = False
teleport_key = "F5"
# Dev under Python 2.7
#cap = cv2.VideoCapture(0)
# Requirement : GRF edition to show up the monsters we want to target into color specific squares
# Requirement 2 : Disable lightmaps ( Ragnarök settings )
# pip install pydivert (for packet sniffing)
# We'll loop screenshotting the client window
# On these screenshots, we'll find the color specific squares and locate them using the "CONTOURS" technology of OpenCV
# Need to plug a winpcap listener on the client in order to analyze the incoming trafic (the incoming only) : It will allow us to watch HP / SP,
# Issue 1 :
# The cursor go on a location next to the target, but not on it.
# You sould configure your Python.exe to accept high resolution DPI => Go to your Python FOlder => right click => compatibilities .. and you're done
def watchScreen(mainQueue):
watcher.watch(mainQueue)
def program():
global mainQueue
mainQueue = queue.Queue()
t1 = Thread(target = watchScreen,args=(mainQueue,)) # target is the above function
t1.start() # start the thread
while(1):
if mainQueue.qsize() > 0:
print("There are "+str(mainQueue.qsize())+" items in queue")
element = mainQueue.get()
if element["type"]=="monster":
print("monster found on "+str(element["coord"][0])+","+str(element["coord"][1]))
pyautogui.moveTo(element["coord"][0],element["coord"][1])
pyautogui.press('f3')
pyautogui.click()
else:
time.sleep(1)
if __name__ == '__main__':
program()
"""
mouse.mousePos(x_pad,y_pad,coord)
#time.sleep(.2)
mouse.leftClick()
#time.sleep(7)
"""
# Display Window ...
#cv2.imshow('frame',frame)
#k = cv2.waitKey(2) & 0xFF
#if k == 27:
# break
"""
cv2.imshow('mask',mask)
cv2.imshow('res',res)
"""
# wait
"""
while(True):
printscreen_pil = ImageGrab.grab()
printscreen_numpy = numpy.array(printscreen_pil.getdata(),dtype='uint8')\
.reshape((printscreen_pil.size[1],printscreen_pil.size[0],3))
printscreen = printscreen_numpy.astype(numpy.float32)
template = cv2.imread('template.bmp',cv2.IMREAD_COLOR) # chargement du template .jpg en image OpenCV
method = 'cv2.TM_CCOEFF'
w, h, z = template.shape[::-1]
meth = eval(method) #la méthode de recherche du template
res = cv2.matchTemplate(printscreen_numpy,template,meth) # la fonction de recherche
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
top_left = max_loc
bottom_right = (top_left[0] + w, top_left[1] + h)
cv2.rectangle(printscreen,top_left, bottom_right, 255, 2)
cv2.imshow('window',printscreen_numpy)
time.sleep(5)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
"""
"""
im1 = screenGrab(x_pad,y_pad,screen_width,screen_height) #prise du screenshot
screenshot = numpy.array(im1) #transformation en image OpenCV
im1.save(os.getcwd() + '\\full_snap__' + str(int(time.time())) +'.png', 'PNG')
screen = cv2.imread('full_snap__1490995023.png')
template = cv2.imread('mobs/template.jpg',0) # chargement du template .jpg en image OpenCV
w, h = template.shape[::-1]
method=0 #la méthode de recherche du template
res = cv2.matchTemplate(screen,template,method) # la fonction de recherche
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
cv2.rectangle(screen,top_left, bottom_right, 255, 2)
time.sleep(1)
im2 = screenGrab(x_pad,y_pad,screen_width,screen_height)
diff = PIL.ImageChops.difference(im1, im2)
mouse.get_cords(x_pad,y_pad)"""