-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStumbleBot.au3
388 lines (309 loc) · 7.68 KB
/
StumbleBot.au3
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
; Quit Bot with ESC key
HotKeySet("{ESC}", "_Terminate")
; Game Title
Global $title = "Stumble Guys"
_Main()
Func _Main()
; Change AutoIt defaults
Opt("MouseCoordMode", 0)
Opt("PixelCoordMode", 0)
Opt("SendKeyDownDelay", 25)
; Detect if game window is present and has focus
WinWaitActive($title)
; Get window handle
$hWnd = WinGetHandle($title)
$centerX = 1920/2;
$centerY = 1080/2;
; (main loop)
While 1
; Start new game
If DetectMainMenu($hWnd) = 1 Or DetectEventMenu($hWnd) = 1 Then
If DetectEventAvailable($hWnd) = 1 Then
ClickEventMenu()
Sleep(1000)
ContinueLoop
ElseIf DetectEventMenu($hWnd) = 1 Then
ClickPlayEvent()
Else
ClickPlayGame()
EndIf
Sleep(1000)
; not necessary but helps to determine current state
While DetectGameSearch($hWnd) = 1
; fake human behavior
If Random(0, 2) = 1 Then _MouseMoveRandom()
_Sleep(500, 1000)
WEnd
; screen transition
Sleep(500)
; not necessary but helps to determine current state
While DetectMapSelection($hWnd) = 1
; fake human behavior
If Random(0, 2) = 1 Then _Send("{SPACE}")
If Random(0, 2) = 1 Then _MouseMoveRandom()
_Sleep(500, 1000)
WEnd
; center mouse
_MouseMove(Random($centerX-5, $centerX+5), Random($centerY, $centerY+10));
; screen transition
Sleep(500)
; not necessary but helps to determine current state
While DetectGameStart($hWnd) = 1
Sleep(500)
WEnd
; There is a 3 second in game counter at the start of each round
Sleep(3000)
EndIf
; Fault tolerant approach
If DetectGameLost($hWnd) = 1 Then
; Leave game on loss
ClickLeaveGame()
Sleep(1000)
ElseIf DetectGetReward($hWnd) = 1 Then
; Claim participation reward
ClickGetReward()
Sleep(1000)
ElseIf DetectGameResults($hWnd) = 1 Then
; Round has finished, results are shown
; Must wait till screen goes away
Sleep(1000)
ElseIf DetectGameRunning($hWnd) = 1 Then
; Game is still on-going
; Warning: This condition will also be true for spectator mode on game loss (check loss first)
; AFK gameplay happens here
SimulateGamePlay($hWnd)
Else
Sleep(1000)
EndIf
; Game window must be active to continue
While WinActive($title) = 0
If WinExists($title) = 0 Then
_Terminate()
EndIf
Sleep(5000)
WEnd
WEnd
EndFunc
Func SimulateGamePlay(ByRef $hWnd)
Local $n = 4
Local $keys[$n] = ["Left", "Right", "Jump", "Run"]
For $counter = 1 to $n
If DetectGameRunning($hWnd) = 0 Or DetectGameLost($hWnd) = 1 Then
; Abort input on game loss to avoid waste of time
Return
EndIf
; Start running
_Send("{w down}")
_Sleep(500, 1500)
; Select random movement
$key = Random(0, $n-1)
Switch $keys[$key]
Case "Left"
$ms = Random(500, 1500)
Left($ms)
Case "Right"
$ms = Random(500, 1500)
Right($ms)
Case "Jump"
$ms = Random(100, 500)
Jump($ms)
_Sleep(500, 1000)
Case "Run"
_Sleep(500, 1500)
EndSwitch
; Stop running
_Sleep(0, 1000)
_Send("{w up}")
; Short pause
_Sleep(500, 1000)
Next
EndFunc
Func Left($ms = 500)
_Send("{a down}")
Sleep($ms)
_Send("{a up}")
EndFunc
Func Right($ms = 500)
_Send("{d down}")
Sleep($ms)
_Send("{d up}")
EndFunc
Func Jump($ms = 500)
_Send("{SPACE down}")
Sleep($ms)
_Send("{SPACE up}")
EndFunc
Func ClickPlayGame()
$x = Random(1538, 1873)
$y = Random(921, 1026)
_LeftClick($x, $y)
EndFunc
Func ClickEventMenu()
$x = Random(1053, 1465)
$y = Random(948, 1033)
_LeftClick($x, $y)
EndFunc
Func ClickPlayEvent()
$x = Random(200, 440)
$y = Random(915, 980)
_LeftClick($x, $y)
EndFunc
Func DetectMainMenu(ByRef $hWnd)
; (Yellow Play Button)
$c1 = PixelGetColor(1873, 921, $hWnd)
$hex = Hex($c1, 6)
If $hex = "FFC716" Then Return 1
; (Yellow Play Button) 2nd check
$c2 = PixelGetColor(1538, 1026, $hWnd)
$hex = Hex($c2, 6)
If $hex = "FFBA10" Then Return 1
Return 0
EndFunc
Func DetectEventAvailable(ByRef $hWnd)
; (Event Button)
$c1 = PixelGetColor(1050, 943, $hWnd)
$hex = Hex($c1, 6)
If $hex = "07406F" Then Return 1
; (Event Button) 2nd check
$c2 = PixelGetColor(1225, 949, $hWnd)
$hex = Hex($c2, 6)
If $hex = "07406F" Then Return 1
Return 0
EndFunc
Func DetectEventMenu(ByRef $hWnd)
; (Start Button)
$c1 = PixelGetColor(200, 915, $hWnd)
$hex = Hex($c1, 6)
If $hex = "0D89EC" Then Return 1
; (Start Button) 2nd check
$c2 = PixelGetColor(440, 980, $hWnd)
$hex = Hex($c2, 6)
If $hex = "0B6EE7" Then Return 1
Return 0
EndFunc
Func DetectGameSearch(ByRef $hWnd)
; (Gray Abort Button) 89A8B3
$c1 = PixelGetColor(333, 964, $hWnd)
$hex = Hex($c1, 6)
If $hex = "89A8B3" Then Return 1
; (Gray Abort Button) 7393A0
$c2 = PixelGetColor(65, 1022, $hWnd)
$hex = Hex($c2, 6)
If $hex = "7393A0" Then Return 1
Return 0
EndFunc
Func DetectMapSelection(ByRef $hWnd)
; (Purple Left Bottom) 9286FF
$c1 = PixelGetColor(99, 988, $hWnd)
$hex1 = Hex($c1, 6)
; (Purple Right Bottom) 6878FF
$c2 = PixelGetColor(1798, 991, $hWnd)
$hex2 = Hex($c2, 6)
; Both of them should match
If $hex1 = "9286FF" And $hex2 = "6878FF" Then Return 1
Return 0
EndFunc
Func DetectGameStart(ByRef $hWnd)
; (White Screen Banner) FFFFFF
$c1 = PixelGetColor(672, 72, $hWnd)
$hex1 = Hex($c1, 6)
; (White Screen Banner) FFFFFF
$c2 = PixelGetColor(1250, 52, $hWnd)
$hex2 = Hex($c2, 6)
; Both of them should match
If $hex1 = "FFFFFF" And $hex2 = "FFFFFF" Then Return 1
Return 0
EndFunc
Func DetectGameRunning(ByRef $hWnd)
; (White Player Arrow) FFFFFF
$c1 = PixelGetColor(959, 450, $hWnd)
$hex1 = Hex($c1, 6)
; (White Player Arrow) FFFFFF
$c2 = PixelGetColor(961, 448, $hWnd)
$hex2 = Hex($c2, 6)
; Both of them should match
If $hex1 = "FFFFFF" And $hex2 = "FFFFFF" Then Return 1
EndFunc
Func DetectGameResults(ByRef $hWnd)
; (Purple border of flying screen thing) 840BE9
$c1 = PixelGetColor(673, 133, $hWnd)
$hex = Hex($c1, 6)
If $hex = "840BE9" Then Return 1
; (Purple border of flying screen thing) EC43A7
$c2 = PixelGetColor(678, 167, $hWnd)
$hex = Hex($c2, 6)
If $hex = "EC43A7" Then Return 1
Return 0
EndFunc
Func DetectGameLost(ByRef $hWnd)
; (Red Leave Button) F7513F
$c1 = PixelGetColor(257, 973, $hWnd)
$hex = Hex($c1, 6)
If $hex = "F7513F" Then Return 1
; (Red Leave Button)F44131
$c2 = PixelGetColor(36, 1033, $hWnd)
$hex = Hex($c2, 6)
If $hex = "F44131" Then Return 1
Return 0
EndFunc
Func ClickLeaveGame()
$x = Random(36, 257)
$y = Random(973, 1033)
_LeftClick($x, $y)
EndFunc
Func DetectGetReward(ByRef $hWnd)
; (Green Get Button)
$c1 = PixelGetColor(1499, 915, $hWnd)
$hex = Hex($c1, 6)
If $hex = "55DB1E" Then Return 1
; (Green Get Button)
$c2 = PixelGetColor(1809, 1001, $hWnd)
$hex = Hex($c2, 6)
If $hex = "44D018" Then Return 1
Return 0
EndFunc
Func ClickGetReward()
$x = Random(1499, 1809)
$y = Random(915, 1001)
_LeftClick($x, $y)
EndFunc
Func _Sleep($min, $max)
Sleep(Random($min, $max))
EndFunc
Func _Send($keys, $flag = 0)
; Send key input to game only
If WinActive($title) = 0 Then Return
Send($keys, $flag)
EndFunc
Func _LeftClick($x, $y)
; Send clicks to game only
If WinActive($title) = 0 Then Return
MouseClick("left", $x, $y, 1, 10)
Sleep(100)
EndFunc
Func _MouseMove($x, $y, $speed = 20)
If WinActive($title) = 0 Then Return
MouseMove($x, $y, $speed)
Sleep(50)
EndFunc
Func _MouseMoveRandom($minSpeed = 20, $maxSpeed = 30)
If WinActive($title) = 0 Then Return
; Try to avoid outer borders
$x = Random(220, 1700)
$y = Random(180, 900)
$speed = Random($minSpeed, $maxSpeed)
MouseMove($x, $y, $speed)
Sleep(100)
EndFunc
Func _MouseMoveEvent($x = "", $y = "")
Local $MOUSEEVENTF_MOVE = 0x1
DllCall("user32.dll", "none", "mouse_event", _
"long", $MOUSEEVENTF_MOVE, _
"long", $x, _
"long", $y, _
"long", 0, _
"long", 0)
EndFunc
Func _Terminate()
Exit
EndFunc