forked from HugoNeves/PCM-2013-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCM 2013 Bot v2.ahk
397 lines (340 loc) · 11.8 KB
/
PCM 2013 Bot v2.ahk
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
389
390
391
392
393
394
395
396
397
;;;;;;;;;;;;;;;; VARIABLES ;;;;;;;;;;;;;;;;
;; BUTTONS, COLORS AND POSITIONS
; MULTIPLAYER BUTTON
colorBtnMultiplayer := 0x40CDF6
posBtnMultiplayerX := 815
posBtnMultiplayerY := 122
; CONNECTION WITH THE SERVER HAS FAILED
colorBtnConnectionHasFailed := 0x22E6FE
posBtnConnectionHasFailedX := 1014
posBtnConnectionHasFailedY := 582
; YOU WERE DISCONNECTED / PROFILE ALREADY CONNECTED
colorBtnYouWereDisconnected := 0x22E6FE
posBtnYouWereDisconnectedX := 1008
posBtnYouWereDisconnectedY := 567
; GAME PORTS/YOU LEFT EARLY BUTTON
colorBtnGamePorts := 0x22E6FE
posBtnGamePortsX := 930
posBtnGamePortsY := 686
; STAGE BUTTON
colorBtnStage := 0x3CB9DD
posBtnStageX := 531
posBtnStageY := 127
; PLAY BUTTON
colorBtnPlay := 0x22E6FE
posBtnPlayX := 318
posBtnPlayY := 83
; LOOK FOR A GAME BUTTON
colorBtnLookGame := 0x22E6FE
posBtnLookGameX := 814
posBtnLookGameY := 185
; LOOKING FOR A GAME IN PROGRESS
colorLookInProgress := 0x3D3D3D
posLookInProgressX := 948
posLookInProgressY := 46
; MAIN MENU BUTTON
colorBtnMainMenu := 0x10CDFC
posBtnMainMenuX := 1765
posBtnMainMenuY := 43
; QUIT GAME BUTTON
colorBtnQuitGame := 0x5DDFFE
posBtnQuitGameX := 1891
posBtnQuitGameY := 43
; CONFIRM QUIT GAME BUTTON
colorBtnConfirmQuitGame := 0x22E6FE
posBtnConfirmQuitGameX := 893
posBtnConfirmQuitGameY := 569
; CHECK IF INGAME
colorChkInGame := 0x22E6FE
posChkInGame1X := 165
posChkInGame1Y := 82
posChkInGame2X := 586
posChkInGame2Y := 82
posChkInGame3X := 586
posChkInGame3Y := 1046
; PREVIOUS POINTS IN GAME
posPreviousPoint1X := 475
posPreviousPoint1Y := 240
posPreviousPoint2X := 1014
posPreviousPoint2Y := 213
posPreviousPoint3X := 1690
posPreviousPoint3Y := 153
posPreviousPoint4X := 984
posPreviousPoint4Y := 1006
; QUIT REPLAY BUTTON (AT REPLAY)
colorBtnQuitReplay := 0x22E6FE
posBtnQuitReplayX := 786
posBtnQuitReplayY := 605
; NEXT BUTTON
colorBtnNext := 0x07D4FA
posBtnNextX := 1746
posBtnNextY := 1048
; QUIT BUTTON
colorBtnQuit := 0x01CCFA
posBtnQuitX := 1757
posBtnQuitY := 1052
; OK BUTTON (AFTER FINISHING)
colorBtnOkAfterFinishing := 0x22E6FE
posBtnOkAfterFinishingX := 848
posBtnOkAfterFinishingY := 688
; GAME ERRORS
; TODO
;; GAME STATE VARIABLES
run := "true"
state := "stopped"
stageFound := "false"
previousTime := A_Now
currentTime :=
previousPointColor1 :=
previousPointColor2 :=
previousPointColor3 :=
previousPointColor4 :=
;;;;;;;;;;;;;;;; END OF VARIABLES ;;;;;;;;;;;;;;;;
;; AUXILIARY FUNCTIONS
MoveAndGetColorAt(posX, posY)
{
MouseMove, posX, posY
Sleep, 1000
PixelGetColor, colorAtPos, posX, posY
return %colorAtPos%
}
ClickAndSleep(posX, posY, sleepTime, msg, doLog)
{
Click, posX,posY
LogMessage(msg, doLog)
Sleep, sleepTime
}
LogMessage(msg, doLog)
{
if (doLog = "true")
{
FormatTime, Time,, dd/MM/yyyy HH:mm:ss
FileAppend, %Time% - %msg%`n, PCM 2013 BotLog.txt
}
}
;; END OF AUXILIARY FUNCTIONS
;;;;;;;;;;;;;;;; RUNNING BOT CODE ;;;;;;;;;;;;;;;;
#z::
MsgBox, Bot started!
LogMessage("Bot started", "true")
Loop
{
if (run = "false")
break
Process, Exist, PCM.exe
{
If ! ErrorLevel ; Game is off
{
LogMessage("Game is off, turning game on", "true")
Run, "F:\Jogos\Steam\SteamApps\common\Pro Cycling Manager 2013\Pro Cycling Manager 2013"
state := "stopped"
LogMessage("State -> stopped", "true")
Sleep, 90000
}
else ; Game is on
{
WinActivate, Pro Cycling Manager 2013
;; MULTIPLE DETECTIONS
; Game errors
; TODO
;;;;;;;;;;;;;;;; STATE STOPPED ;;;;;;;;;;;;;;;;
if (state = "stopped")
{
stageFound := "false"
; Message you were disconnected OR profile already connected, clicking ok
colorAtBtnYouWereDisconnected := MoveAndGetColorAt(posBtnYouWereDisconnectedX, posBtnYouWereDisconnectedY)
if (colorAtBtnYouWereDisconnected = colorBtnYouWereDisconnected)
{
ClickAndSleep(posBtnYouWereDisconnectedX, posBtnYouWereDisconnectedY, 5000, "Clicking ok at being disconnected OR at profile being already connected", "false")
Continue
}
; Main menu, clicking multiplayer
colorAtPosBtnMultiplayer := MoveAndGetColorAt(posBtnMultiplayerX, posBtnMultiplayerY)
if (colorAtPosBtnMultiplayer = colorBtnMultiplayer)
{
ClickAndSleep(posBtnMultiplayerX, posBtnMultiplayerY, 15000, "Clicking 'Multiplayer'", "false")
Continue
}
; Main menu, message connection with server has failed, clicking ok
colorAtPosBtnConnectionHasFailed := MoveAndGetColorAt(posBtnConnectionHasFailedX, posBtnConnectionHasFailedY)
if (colorAtPosBtnConnectionHasFailed = colorBtnConnectionHasFailed)
{
ClickAndSleep(posBtnConnectionHasFailedX, posBtnConnectionHasFailedY, 5000, "Clicking 'Ok' at connection failed", "false")
Continue
}
; Message test of game ports open, or message you left early, clicking ok
colorAtPosBtnGamePorts := MoveAndGetColorAt(posBtnGamePortsX, posBtnGamePortsY)
if (colorAtPosBtnGamePorts = colorBtnGamePorts)
{
ClickAndSleep(posBtnGamePortsX, posBtnGamePortsY, 5000, "Clicking 'Ok' at game ports or at you left early message", "false")
Continue
}
; Multiplayer menu, clicking stage
colorAtPosBtnStage := MoveAndGetColorAt(posBtnStageX, posBtnStageY)
if (colorAtPosBtnStage = colorBtnStage)
{
ClickAndSleep(posBtnStageX, posBtnStageY, 30000, "Clicking 'Stage'", "false")
Continue
}
; Play tab, clicking look for a game
colorAtLookInProgress := MoveAndGetColorAt(posLookInProgressX, posLookInProgressY)
colorAtBtnLookGame := MoveAndGetColorAt(posBtnLookGameX, posBtnLookGameY)
if ((colorAtBtnLookGame = colorBtnLookGame) and (colorAtLookInProgress = colorLookInProgress))
{
previousTime := A_Now
state := "searching"
LogMessage("State -> searching", "true")
ClickAndSleep(posBtnLookGameX, posBtnLookGameY, 300000, "Clicking 'Look for a game'", "true")
Continue
}
; Safe check to verify if user started bot already searching for a game, but a stage was not found/loaded yet
if ((colorAtBtnLookGame = colorBtnLookGame) and (colorAtLookInProgress != colorLookInProgress))
{
previousTime := A_Now
state := "searching"
LogMessage("State -> searching", "true")
Continue
}
; Stages menu (outside or inside of play tab), clicking play
colorAtPosBtnPlay := MoveAndGetColorAt(posBtnPlayX, posBtnPlayY)
if (colorAtPosBtnPlay = colorBtnPlay)
{
ClickAndSleep(posBtnPlayX, posBtnPlayY, 5000, "Clicking 'Play'", "false")
Continue
}
; If everything above fails, will assume bot was started already in state searching or ingame. By defining state as searching, bot will automatically change to state ingame afterwards, if needed
state := "searching"
LogMessage("State -> searching", "true")
}
;;;;;;;;;;;;;;;; END OF STATE STOPPED ;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; STATE SEARCHING ;;;;;;;;;;;;;;;;
if (state = "searching")
{
; Check if found stage
colorAtLookInProgress := MoveAndGetColorAt(posLookInProgressX, posLookInProgressY)
colorAtChkInGame1 := MoveAndGetColorAt(posChkInGame1X, posChkInGame1Y)
colorAtBtnLookGame := MoveAndGetColorAt(posBtnLookGameX, posBtnLookGameY)
if ((colorAtLookInProgress != colorLookInProgress) and (colorAtChkInGame1 = colorChkInGame) and (colorAtBtnLookGame != colorBtnLookGame) and (stageFound = "false"))
{
previousTime := A_Now
stageFound := "true"
Continue
}
; Check if not in menu looking for a game
colorAtChkInGame1 := MoveAndGetColorAt(posChkInGame1X, posChkInGame1Y)
colorAtChkInGame2 := MoveAndGetColorAt(posChkInGame2X, posChkInGame2Y)
colorAtChkInGame3 := MoveAndGetColorAt(posChkInGame3X, posChkInGame3Y)
if ((colorAtChkInGame1 != colorChkInGame) or (colorAtChkInGame2 != colorChkInGame) or (colorAtChkInGame3 != colorChkInGame))
{
previousTime := A_Now
state := "ingame"
LogMessage("State -> ingame", "true")
Continue
}
currentTime := A_Now
EnvSub, currentTime, %previousTime%, minutes
if (currentTime > 5) ; Too much time searching
{
; Clicking cancel
colorAtBtnLookGame := MoveAndGetColorAt(posBtnLookGameX, posBtnLookGameY)
if (colorAtBtnLookGame = colorBtnLookGame)
{
ClickAndSleep(posBtnLookGameX, posBtnLookGameY, 5000, "Clicking 'Cancel'", "false")
}
else ; This is just fucked up, closing game
{
LogMessage("Closing game", "true")
WinClose, Pro Cycling Manager 2013
}
state := "stopped"
LogMessage("State -> stopped", "true")
}
}
;;;;;;;;;;;;;;;; END OF STATE SEARCHING ;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; STATE INGAME ;;;;;;;;;;;;;;;;
if (state = "ingame")
{
; Replay menu, clicking race results
colorAtBtnQuitReplay := MoveAndGetColorAt(posBtnQuitReplayX, posBtnQuitReplayY)
if (colorAtBtnQuitReplay = colorBtnQuitReplay)
{
ClickAndSleep(posBtnQuitReplayX, posBtnQuitReplayY, 5000, "Clicking 'Race results'", "false")
Continue
}
; Journal news, clicking next
colorAtBtnNext := MoveAndGetColorAt(posBtnNextX, posBtnNextY)
if (colorAtBtnNext = colorBtnNext)
{
ClickAndSleep(posBtnNextX, posBtnNextY, 5000, "Clicking 'Next'", "false")
Continue
}
; Race results, clicking quit
colorAtBtnQuit := MoveAndGetColorAt(posBtnQuitX, posBtnQuitY)
if (colorAtBtnQuit = colorBtnQuit)
{
ClickAndSleep(posBtnQuitX, posBtnQuitY, 30000, "Clicking 'Quit'", "false")
Continue
}
; Coins results, clicking ok
colorAtBtnOkAfterFinishing := MoveAndGetColorAt(posBtnOkAfterFinishingX, posBtnOkAfterFinishingY)
if (colorAtBtnOkAfterFinishing = colorBtnOkAfterFinishing)
{
state := "stopped"
LogMessage("State -> stopped", "true")
ClickAndSleep(posBtnOkAfterFinishingX, posBtnOkAfterFinishingY, 5000, "Clicking 'Ok' at coins results", "false")
Continue
}
; Safe check to verify if user clicked 'ok' in coins message
colorAtChkInGame1 := MoveAndGetColorAt(posChkInGame1X, posChkInGame1Y)
colorAtChkInGame2 := MoveAndGetColorAt(posChkInGame2X, posChkInGame2Y)
colorAtChkInGame3 := MoveAndGetColorAt(posChkInGame3X, posChkInGame3Y)
if ((colorAtChkInGame1 = colorChkInGame) and (colorAtChkInGame2 = colorChkInGame) and (colorAtChkInGame3 = colorChkInGame))
{
state := "stopped"
LogMessage("State -> stopped", "true")
Continue
}
; Check if it's time to check for changes
currentTime := A_Now
EnvSub, currentTime, %previousTime%, minutes
if (currentTime > 10) ; Time to check if points changed
{
previousTime := A_Now
Send {Left 160}
colorAtPosPreviousPoint1 := MoveAndGetColorAt(posPreviousPoint1X, posPreviousPoint1Y)
colorAtPosPreviousPoint2 := MoveAndGetColorAt(posPreviousPoint2X, posPreviousPoint2Y)
colorAtPosPreviousPoint3 := MoveAndGetColorAt(posPreviousPoint3X, posPreviousPoint3Y)
colorAtPosPreviousPoint4 := MoveAndGetColorAt(posPreviousPoint4X, posPreviousPoint4Y)
if ((colorAtPosPreviousPoint1 = previousPointColor1) and (colorAtPosPreviousPoint2 = previousPointColor2) and (colorAtPosPreviousPoint3 = previousPointColor3) and (colorAtPosPreviousPoint4 = previousPointColor4))
{
; This is just fucked up, closing game
LogMessage("Closing game", "true")
WinClose, Pro Cycling Manager 2013
state := "stopped"
LogMessage("State -> stopped", "true")
Continue
}
else
{
previousPointColor1 := colorAtPosPreviousPoint1
previousPointColor2 := colorAtPosPreviousPoint2
previousPointColor3 := colorAtPosPreviousPoint3
previousPointColor4 := colorAtPosPreviousPoint4
}
}
Sleep, 60000
}
;;;;;;;;;;;;;;;; END OF STATE INGAME ;;;;;;;;;;;;;;;;
}
}
Sleep, 5000
}
return
;;;;;;;;;;;;;;;; RUNNING BOT CODE ;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; STOPPING BOT CODE ;;;;;;;;;;;;;;;;
#x::
MsgBox, Bot stopped!
LogMessage("Bot stopped", "true")
run := "false"
return
;;;;;;;;;;;;;;;; STOPPING BOT CODE ;;;;;;;;;;;;;;;;