-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBotFunctions.py
335 lines (281 loc) · 14.9 KB
/
BotFunctions.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#--------------------------------------
# system/native imports
#--------------------------------------
import time
#--------------------------------------
# public/3rd-party imports
#--------------------------------------
import numpy as np
import cv2 as cv
#--------------------------------------
# project specific imports
#--------------------------------------
from BotFunctionsTools import cBotFunctionsTools
from Constants import *
from autodb import clientDB
from ROICoords import cScanCoords as coords
#--------------------------------------
#class cBotFunctions(c cBotData):
class cBotFunctions(cBotFunctionsTools):
def __init__(self, pID, windowName, clientNum, deviceObj, adbSockInfo):
cBotFunctionsTools.__init__(self, pID, windowName, clientNum, deviceObj, adbSockInfo)
print("loading..")
self.dbConn = clientDB("autoTest.db", windowName, clientNum)
print("DB File created or already exists. loading..")
self.startPressed = False
self.updateRequired = False
self.gplayPressedPlayed = False
self.patchSuccess = False
self.inputAccData = False
self.reScanLobbyData = False # toggle
self.charsToFame = 0
self.totalChars = 0
self.dbDataCheck()
def dbDataCheck(self):
tblName = self.dbConn.CHAR_TBL_TITLE + str(self.cNum)
if self.dbConn.checkSetup() == 0: #need to register accData. 1st check if client table exists..
if not self.dbConn.doesTableExist(tblName):
self.dbConn.createClientAccDataTable(tblName)
self.inputAccData = True
elif self.dbConn.checkSetup() == -1: #row not registered so...
self.dbConn.registerClientInMain()
self.dbConn.createClientAccDataTable(tblName)
self.inputAccData = True
else: #good to go
if not self.dbConn.verifyValidTable(tblName):
print("OH NO SOMETHING BIG WRONG BIG BIG WRONG")
print("HELP!")
print("---------------------------------------")
self.inputAccData = False
def getCharLobbyData(self):
#make sure in char select lobby.. do on first run only?
currPage = -1
total = -1
first = False
while currPage != 1:
currPage = self.whichCharPage()
if currPage != 1:
if currPage <= 3:
self.movePage(0) #move left
else:
self.movePage(1)
else:
print("we are on page 1. continuing...")
first = True
while first == True or total == 7:
total = self.returnCharAmtOnPage()
if total == 7:
self.movePage(1)
first = False
currPage = self.whichCharPage()
if currPage != 1:
amt = total
total = (currPage - 1) * 7
total += amt
print("ok so total is: " + str(total))
return total
def getNamesFromFile(self, filename):
with open(filename, encoding= 'utf-8') as nameList:
tempList = nameList.readlines()
self.charsToFame = len(tempList)
data_tup = tuple(name.rstrip('\n') for name in tempList)
return data_tup
def listOfZeros(self, length):
return [0] * length
def listToTuple(self, length):
return tuple(self.listOfZeros(length))
def initFameDB(self):
tbl_name = "fameTable" + str(self.dbConn.noxNum)
if not self.dbConn.doesTableExist(tbl_name): #if tbl doesnt exist, lets set it up
names = self.getNamesFromFile('fameNames.txt')
input = ('charNum',) + names
self.dbConn.createTableIfDNE(tbl_name, 1, str(input))
data_tuple = self.listToTuple(self.charsToFame)
self.dbConn.registerFameAccData(names, data_tuple, self.totalChars)
# get char names from user input in pyqt (user enters 10 names, those are read in. store data after)
else:
pass
# tbl exists so go thru tbl and fame
def update():
pass
def startAQ(self):
pass
def doFame(self, charName, preSS, postSS):
jobDone = False
if self.scanThisROI(self.templateDict['searchplayersbtn'],480, 517, 135,238, 0.8, False) and not self.scanThisROI(self.templateDict['searchplayersbox'],110, 153, 390,570, 0.8, False):
self.sendTimedTap(146,226, 485, 510, keyConstants.SHORT_TAP_DURATION)
time.sleep(2)
if self.scanThisROI(self.templateDict['searchplayersbox'],110, 153, 390,570, 0.8, False):
if self.scanThisROI(self.templateDict['emptynamebox'],280, 310, 365,590, 0.8, False):
self.sendTimedTap(370,580, 290, 305, keyConstants.SHORT_TAP_DURATION)
time.sleep(1)
self.enterText(charName)
time.sleep(2.5)
print("y")
if not self.scanThisROI(self.templateDict['emptynamebox'],289, 305, 455,485, 0.8, False):
print("a")
while not self.scanThisROI(self.templateDict['emptynamebox'],289, 305, 455,485, 0.8, False) and self.scanThisROI(self.templateDict['confirmbtn'],380, 415, 530,655, 0.8, False):
print("s")
self.sendTimedTap(525,640, 383, 414, keyConstants.SHORT_TAP_DURATION)
time.sleep(2)
if self.scanThisROI(self.templateDict['searchresults'],115, 152, 431,600, 0.8, False):
self.sendTimedTap(280,400, 220, 315, keyConstants.SHORT_TAP_DURATION)
time.sleep(2)
if self.checkIfRightSubMenu('playerinfopage'):
time.sleep(2)
#self.saveImageAs(65,460,620,950, 1, preSS)
while not self.fameIsUsed():
self.sendTimedTap(645,660,85, 105, keyConstants.SHORT_TAP_DURATION)
time.sleep(2)
if self.fameIsUsed():
#self.saveImageAs(65,460,620,950, 1, postSS)
jobDone = True
print("done")
#self.returnToCharSelect()
def fameLoop(self, charName1, ss1, ss2):
done = False
self.openInGameMenu()
if self.checkIfInMenu():
self.enterSubMenu('communityicon')
time.sleep(2)
if self.checkIfRightSubMenu('communitypage'):
done = self.doFame(charName1, ss1, ss2)
if self.checkIfRightSubMenu('playerinfopage'):
time.sleep(2)
#self.saveImageAs(65,460,620,950, 1, ss1)
while not self.fameIsUsed():
self.sendTimedTap(645,660,85, 105, keyConstants.SHORT_TAP_DURATION)
time.sleep(2)
if self.fameIsUsed():
#self.saveImageAs(65,460,620,950, 1, ss2)
done = True
print("done")
#self.returnToCharSelect()
return done
#fameList consist of list of strings (names of chars)
def startFame(self, fameList):
#get name data from DB [separate table]
#each char should have own tbl keeping track of which chars successfully famed.
timestamp = time.strftime('_%H_%M_%S_')
ssName1 = "preFame" + timestamp
ssName2 = "postFame" + timestamp
if self.fameLoop("Meowkins", ssName1, ssName2):
famed = True
if famed:
print("famed, switching chars")
self.returnToCharSelect()
self.updateStageNum(stateConstants.L4_at_char_lobby)
atLevel = stateConstants.L4_at_char_lobby
self.gameState.updateStatus(stateConstants.L13_auto_quest, False)
self.gameState.goingBackToLobby = True
someVal += 1
famed = False
def botLoop(self, whichFeature, enabled):
firstrun = True
while enabled:
time.sleep(1)
#load data from db
level = self.gameState.returnStageNum()
self.gameState.printTest()
if level == stateConstants.L0_at_home_scr:
print("level 0")
if self.errorMsgFound:
print("Error lol")
#send touch.
if self.scanThisROI(self.templateDict['SCHK_0atHomeScreen'],0,457, 0, 865, 0.8, True):
print("MSM located! opening...")
self.sendTimedTap(self.matchCoords.xyLoc[0] + 5, self.matchCoords.xyLoc[0] + 20, self.matchCoords.xyLoc[1] - 45, self.matchCoords.xyLoc[1] - 30, 0.03)
if self.gameState.crashed:
self.gameState.resetOnCrash()
elif level == stateConstants.L1_at_start_ban:
print("level 1")
self.patchSuccess = True
if self.scanThisROI(self.templateDict['bannerexit2'],2,52,900,960,0.8,True):
self.sendTimedTap(919,949, 10, 41, keyConstants.SHORT_TAP_DURATION)
print("sent CMD, banner should be closing...")
elif level == stateConstants.L2_at_title_screen:
print("level 2")
#roiLoading = screen[self.adjustYoffset(48):self.adjustYoffset(98), 675:720]
if not self.scanThisROI(self.templateDict['SCHK_30loadingPage'], 48,98,685,735, 0.8, False):
self.sendTimedTap(183, 940, 28, 460, keyConstants.SHORT_TAP_DURATION)
time.sleep(3)
print("sent CMD, should pass title screen")
elif level == stateConstants.L3_load_entering_game:
print("level 3")
self.closeAnyLobbyPopup()
elif level == stateConstants.L4_at_char_lobby:
print("level 4")
if self.inputAccData:
done = False
while not done:
self.closeAnyLobbyPopup()
if self.gameState.returnStageNum() == stateConstants.L4_at_char_lobby:
self.totalChars = self.getCharLobbyData()
for x in range(0, self.totalChars):
self.dbConn.registerClientAccData(x)
self.initFameDB()
self.dbConn.updateSingleVar("MAIN_TBL_CLIENTS", "accDataRegistered", (1,) )
done = True
self.inputAccData = False
else:
self.findSelectedChar()
if firstrun and self.currChar != 0:
self.selectChar(0)
self.findSelectedChar()
if self.currChar == 0:
firstrun = False
elif firstrun and self.currChar == 0:
firstrun = False
if not firstrun:
if self.dbConn.getSingleValAccData("charDone", self.currChar):
self.selectChar(self.currChar + 1)
else:
if self.gameState.returnStageNum() == stateConstants.L4_at_char_lobby:
print("no popup detected! going in game")
self.sendTimedTap(707,899,445,479, keyConstants.SHORT_TAP_DURATION)
self.gameState.startPressed = True
time.sleep(2)
#check table exists.
self.closeAnyLobbyPopup()
print("at lvl 4 now baybee")
elif level == stateConstants.L16_loading_wait:
print("level 16")
if not self.updateRequired:
#if self.gplayPressedPlayed:
# if self.scanWindow2(self.templateDict['updateReqPopup4GooglePlayReady'], 0.8) or self.scanWindow2(self.templateDict['updateReqPopup4GooglePlayReady2'], 0.8):
# print("CRASHED BUT IT'S OK. RE-PRESSING PLAY.")
if self.scanThisROI(self.templateDict['SCHK_1exitbanner'],2,52,900,960,0.8,True):
self.sendTimedTap(919,949, 10, 41, keyConstants.SHORT_TAP_DURATION)
time.sleep(2)
elif self.scanThisROI(self.templateDict['downloadwarning'],coords.PATCH_DOWNLOAD[1][0], coords.PATCH_DOWNLOAD[1][1], coords.PATCH_DOWNLOAD[0][0], coords.PATCH_DOWNLOAD[0][1], 0.8, True):
self.sendTimedTap(coords.PATCH_CONFIRM[0][0], coords.PATCH_CONFIRM[0][1], coords.PATCH_CONFIRM[1][0], coords.PATCH_CONFIRM[1][1], keyConstants.SHORT_TAP_DURATION)
#
elif self.scanThisROI(self.templateDict['downloadwarning'],coords.PATCH_DOWNLOAD[1][0], coords.PATCH_DOWNLOAD[1][1], coords.PATCH_DOWNLOAD[0][0], coords.PATCH_DOWNLOAD[0][1], 0.8, True):
pass
elif self.scanThisROI(self.templateDict['updateReqPopup'],100,165,400,550,0.8,True):
self.updateRequired = True
self.sendTimedTap(400,555, 383, 414, keyConstants.SHORT_TAP_DURATION)
else:
if self.scanThisROI(self.templateDict['updateReqPopup2'], 110,200,195,600 ,0.8, True):
if self.scanThisROI(self.templateDict['updateReqPopup3'], 110,420,195,775 ,0.8, True):
self.sendTimedTap(self.matchCoords.xyLoc[0] + 195, self.matchCoords.xyLoc[0] + 500, self.matchCoords.xyLoc[1] + 110, self.matchCoords.xyLoc[1] + 200, 0.03)
time.sleep(1)
self.sendTimedTap(222, 450, 360, 410, 0.05)
else:
if self.scanWindow2(self.templateDict['updateReqPopup4GooglePlay'], 0.8):
self.sendTimedTap(self.matchCoords.xyLoc[0] - 100, self.matchCoords.xyLoc[0] + 100, self.matchCoords.xyLoc[1] - 50, self.matchCoords.xyLoc[1], 0.03)
elif self.scanWindow2(self.templateDict['updateReqPopup4GooglePlayReady'], 0.8) or self.scanWindow2(self.templateDict['updateReqPopup4GooglePlayReady2'], 0.8):
print("FOUND")
self.updateRequired = False
self.gplayPressedPlayed = True
self.sendTimedTap(self.matchCoords.xyLoc[0] - 100, self.matchCoords.xyLoc[0] + 100, self.matchCoords.xyLoc[1] - 50, self.matchCoords.xyLoc[1], 0.03)
#(332 - 50, 332, 656 - 100,656 + 100, True)
elif level == stateConstants.L5_ingame:
self.gameState.atLobby = False
if self.gameState.currState[stateConstants.L13_auto_quest]:
while self.gameState.currState[stateConstants.L13_auto_quest]:
pass
'''
check level
'''
pass