-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
388 lines (347 loc) · 12.2 KB
/
main.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
from elevate import elevate
elevate()
import sys
import subprocess
import utils
import time
import os
import psutil
import keyboard
import pyautogui
import threading
import clipboard
from python_imagesearch.imagesearch import imagesearch_count
pyautogui.PAUSE = 0.3
"""
These are [x,y] coordinates based on a 640x480 csgo window fixed on x=0, y=0
To capture just use print(pyautogui.position()) on a While True
"""
c_open_sidebar = [308,56]
c_open_invite = [249,70]
c_input_field = [140,110]
c_copy_code_btn = [174,132]
c_open_invite_options = [174,109]
c_invite_click_area = [140,124]
c_invite_send = [251,113]
c_cancel = [198,141]
c_enter_party = [308, 62]
c_enter_party_wm = [262, 61]
c_open_search = [9,30]
c_select_mm = [35,41]
c_select_wm = [61,41]
c_start_search = [251,220]
c_accept_match = [159,131]
c_reconnect_btn = [254,12]
c_screen_center = [160, 115]
g_start_delay = 130
g_reconnect_delay = 13
g_disconnect_delay = 42
g_status = 'Doing nothing'
g_screenSize = pyautogui.size()
g_team1 = []
g_team2 = []
g_wm_team1 = []
g_wm_team2 = []
def closeAllAccounts():
#need to close csgo first so it doesn't crash
for proc in psutil.process_iter(['name']):
if proc.info["name"] == ("csgo.exe"):
proc.kill()
for proc in psutil.process_iter(['name']):
if proc.info["name"] == ("steam.exe"):
proc.kill()
return
def openAllAccounts(_type=''):
closeAllAccounts()
utils.logger('openAll')
team1 = g_team1
team2 = g_team2
if _type == 'wm':
team1 = g_wm_team1
team2 = g_wm_team2
accounts = team1 + team2
for i, account in enumerate(accounts):
x = utils.positions[i]["x"]
y = utils.positions[i]["y"]
steamdir = utils.parseSteamDir()
args = utils.parseSteamArgs(account["username"], account["password"], x, y)
subprocess.Popen(steamdir + args, close_fds=True)
return
def openInviteMenu(account):
utils.mouse(account, c_open_sidebar, 'move')
time.sleep(0.1)
utils.mouse(account, c_open_sidebar, 'click', 2)
time.sleep(0.2)
utils.mouse(account, c_open_invite, 'click', 2)
time.sleep(0.2)
return
def inviteWithCode(receiver, sender):
r_x1 = receiver["coords"]["x1"]
r_y1 = receiver["coords"]["y1"]
s_x1 = sender["coords"]["x1"]
s_y1 = sender["coords"]["y1"]
pyautogui.moveTo(r_x1 + c_open_sidebar[0], r_y1 + c_open_sidebar[1])
time.sleep(0.3)
pyautogui.click(r_x1 + c_open_sidebar[0], r_y1 + c_open_sidebar[1])
time.sleep(0.1)
pyautogui.click(r_x1 + c_open_sidebar[0], r_y1 + c_open_sidebar[1])
time.sleep(0.2)
pyautogui.click(r_x1 + c_open_invite[0], r_y1 + c_open_invite[1], 2, 0.05)
time.sleep(0.1)
pyautogui.click(r_x1 + c_copy_code_btn[0], r_y1 + c_copy_code_btn[1], 2, 0.05)
time.sleep(0.1)
keyboard.press_and_release('esc')
#goes back to the account that send the invites
pyautogui.click(s_x1 + c_input_field[0], s_y1 + c_input_field[1], 2, 0.05)
keyboard.write(clipboard.paste())
pyautogui.click(s_x1 + c_open_invite_options[0], s_y1 + c_open_invite_options[1], 2, 0.05)
time.sleep(0.2)
pyautogui.click(s_x1 + c_invite_click_area[0], s_y1 + c_invite_click_area[1], 2, 0.05)
time.sleep(0.3)
pyautogui.click(s_x1 + c_invite_send[0], s_y1 + c_invite_send[1], 2, 0.05)
time.sleep(0.2)
pyautogui.click(s_x1 + c_cancel[0], s_y1 + c_cancel[1], 2, 0.05)
time.sleep(0.3)
keyboard.press_and_release('esc')
return
def invite(receiver, sender):
#sender = guy who will invite the rest of the accounts
#receiver = account who will receive the invite
openInviteMenu(sender)
inviteWithCode(receiver, sender)
return
def inviteSingleTeam(team):
for i, account in enumerate(team):
if i != 0:
invite(account, team[0])
return
def inviteTeams(_type):
team1 = g_team1
team2 = g_team2
if _type == 'wm':
team1 = g_wm_team1
team2 = g_wm_team2
utils.logger('inviting', '1')
for i, account in enumerate(team1):
if i != 0:
invite(account, team1[0])
utils.logger('inviting', '2')
for i, account in enumerate(team2):
if i != 0:
invite(account, team2[0])
return
def acceptInvites(_type):
team1 = g_team1
team2 = g_team2
enter_coord = c_enter_party
if _type == 'wm':
team1 = g_wm_team1
team2 = g_wm_team2
enter_coord = c_enter_party_wm
utils.logger('acceptingInvites', '1')
for i, account in enumerate(team1):
if i > 0:
utils.mouse(account, c_enter_party, 'move')
time.sleep(0.3)
utils.mouse(account, enter_coord, 'click', 2)
utils.logger('acceptingInvites', '2')
for i, account in enumerate(team2):
if i > 0:
utils.mouse(account, c_enter_party, 'move')
time.sleep(0.3)
utils.mouse(account, enter_coord, 'click', 2)
return
def startInvites(_type):
inviteTeams(_type)
time.sleep(10)
acceptInvites(_type)
return
def startIngameBoost(_type):
global g_status
utils.logger('startingMatch')
utils.mouse(account = g_wm_team2[0], _type='outside')
time.sleep(g_start_delay)
utils.logger('playingMatch')
team1 = g_team1
team2 = g_team2
loseTeam = team1
###
### still need to add some checking stuff
### can optimize by removing half of the code, but not now
if _type == 'wm':
team1 = g_wm_team1
team2 = g_wm_team2
#just draw for now
loseTeam = team1
for i in range(10):
if i > 0:
time.sleep(g_disconnect_delay)
if i > 4:
loseTeam = team2
for account in loseTeam:
pyautogui.moveTo(account["coords"]["x1"] + c_screen_center[0], account["coords"]["y1"] + c_screen_center[1])
time.sleep(0.1)
pyautogui.click(account["coords"]["x1"] + c_screen_center[0], account["coords"]["y1"] + c_screen_center[1])
keyboard.press_and_release('k')
time.sleep(0.5)
if i != 4:
utils.logger('disconnectedAccounts', str(g_reconnect_delay))
time.sleep(g_reconnect_delay)
if i != 9:
for account in loseTeam:
pyautogui.moveTo(account["coords"]["x1"] + c_reconnect_btn[0], account["coords"]["y1"] + c_reconnect_btn[1])
pyautogui.click(account["coords"]["x1"] + c_reconnect_btn[0], account["coords"]["y1"] + c_reconnect_btn[1])
time.sleep(0.05)
utils.mouse(account = g_wm_team2[0], _type='outside')
else:
for i in range(16):
if i > 0:
time.sleep(g_disconnect_delay)
for account in g_team2:
pyautogui.moveTo(account["coords"]["x1"] + c_screen_center[0], account["coords"]["y1"] + c_screen_center[1])
time.sleep(0.1)
pyautogui.click(account["coords"]["x1"] + c_screen_center[0], account["coords"]["y1"] + c_screen_center[1])
keyboard.press_and_release('k')
time.sleep(0.5)
time.sleep(g_reconnect_delay)
for account in g_team2:
pyautogui.moveTo(account["coords"]["x1"] + c_reconnect_btn[0], account["coords"]["y1"] + c_reconnect_btn[1])
pyautogui.click(account["coords"]["x1"] + c_reconnect_btn[0], account["coords"]["y1"] + c_reconnect_btn[1])
utils.logger('finishedPlaying')
time.sleep(40)
return
def startSearch(_type):
utils.logger('searchingMatch', 'Competitive')
clickSearchBtn(_type)
team1 = g_team1
team2 = g_team2
halfFound = 5
allFound = 10
if _type == 'wm':
team1 = g_wm_team1
team2 = g_wm_team2
halfFound = 2
allFound = 4
utils.logger('searchingMatch', 'Wingman')
while True:
count = imagesearch_count('./pics/Accept.png')
count2 = imagesearch_count('./pics/Accept2.png')
if (count + count2) == halfFound or ((count + count2) > 1 and (count + count2) < allFound):
time.sleep(5)
if (count + count2) == allFound:
acceptMatchAllAccounts(team1, team2)
else:
utils.logger('foundHalf')
utils.mouse(team2[0], c_accept_match, 'move')
utils.mouse(team2[0], c_accept_match, 'click', 2)
utils.mouse(team1[0], c_accept_match, 'move')
utils.mouse(team1[0], c_accept_match, 'click', 2)
utils.mouse(team2[0], c_start_search, 'move')
utils.mouse(team2[0], c_start_search, 'click')
utils.mouse(team1[0], c_start_search, 'move')
utils.mouse(team1[0], c_start_search, 'click')
time.sleep(60)
clickSearchBtn(_type)
elif count == allFound or count2 == allFound or (count+count2) == allFound:
utils.logger('foundAll')
acceptMatchAllAccounts(team1, team2)
break
return
def acceptMatchAllAccounts(team1, team2):
for i, account in enumerate(team1):
utils.mouse(account, c_accept_match, 'move')
utils.mouse(account, c_accept_match, 'click', 2)
for i, account in enumerate(team2):
utils.mouse(account, c_accept_match, 'move')
utils.mouse(account, c_accept_match, 'click', 2)
return
def clickSearchBtn(_type=''):
team1 = g_team1
team2 = g_team2
queue_btn = c_select_mm
if _type == 'wm':
team1 = g_wm_team1
team2 = g_wm_team2
queue_btn = c_select_wm
utils.mouse(team1[0], c_open_search, 'click')
time.sleep(0.3)
utils.mouse(team1[0], queue_btn, 'click')
utils.mouse(team2[0], c_open_search, 'move')
time.sleep(0.2)
utils.mouse(team2[0], c_open_search, 'click')
time.sleep(0.2)
utils.mouse(team1[0], c_start_search, 'click')
time.sleep(0.3)
utils.mouse(team2[0], queue_btn, 'click')
utils.mouse(team2[0], c_start_search, 'move')
time.sleep(0.2)
utils.mouse(team2[0], c_start_search, 'click')
return
def startMM():
if len(g_team1 + g_team2) == 10:
startSearch('mm')
startIngameBoost('mm')
return
def startWM():
if len (g_wm_team1 + g_wm_team2) == 4:
startSearch('wm')
startIngameBoost('wm')
return
def loadAccounts():
utils.logger('loadingAccounts')
accounts = utils.parseAccounts()
wm_accounts = utils.parseWMAccounts()
global g_team1
global g_team2
global g_wm_team1
global g_wm_team2
if accounts or wm_accounts:
g_team1 = utils.calcAccountsCoords(accounts, 'mm')["team1"]
g_team2 = utils.calcAccountsCoords(accounts, 'mm')["team2"]
g_wm_team1 = utils.calcAccountsCoords(wm_accounts, 'wm')["team1"]
g_wm_team2 = utils.calcAccountsCoords(wm_accounts, 'wm')["team2"]
if len(g_team1) == 5 or len(g_team2) == 5:
utils.logger('loaded', 'Matchmaking')
else:
utils.logger('notLoaded', 'Matchmaking')
if len(g_wm_team1) == 2 or len(g_wm_team2) == 2:
utils.logger('loaded', 'Wingman')
else:
utils.logger('notLoaded', 'Wingman')
return
def runForever(_type):
matchCount = 0
while True:
startInvites(_type)
if _type == 'wm':
matchCount += 1
utils.logger('matchCount', matchCount)
startWM()
elif _type == 'mm':
startMM()
def main():
utils.table_keybinds()
utils.logger('botStart')
loadAccounts()
keyboard.add_hotkey('f3', openAllAccounts)
keyboard.add_hotkey('f4', openAllAccounts, args=['wm'])
keyboard.add_hotkey('f5', loadAccounts)
keyboard.add_hotkey('f6', startMM)
keyboard.add_hotkey('f7', startWM)
keyboard.add_hotkey('f8', startInvites, args=['mm'])
keyboard.add_hotkey('f9', startInvites, args=['wm'])
keyboard.add_hotkey('f10', runForever, args=["wm"])
keyboard.add_hotkey('f11', closeAllAccounts)
while True:
time.sleep(0.02)
if keyboard.is_pressed('f12'):
return
#utils.mouse(account = g_wm_team2[0], _type='outside')
#printStatus()
#print(pyautogui.position())
return
if __name__ == '__main__':
# x = threading.Thread(target=main)
# x.start()
# x.join()
main()