-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.py
executable file
·189 lines (142 loc) · 5.01 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
"""
Autoclicker for Blum drop mini-game
"""
import sys
import time
import dxcam
import mouse
import random
import keyboard
import datetime
from prepare_app import prepare_app
from constants import (
CLICK_LIMIT,
HELP_STRING,
ELECTIONS_MODE,
HALLOWEEN_MODE,
DOGS_DROP_TOGGLE,
AVG_GAME_DURATION,
BOMB_COLOR_TRIGGER,
APPLICATION_TRIGGER,
NEW_GAME_TRIGGER_POS,
PIXELS_PER_ITERATION,
DEFAULT_COLOR_TRIGGER,
DOGS_WHITE_COLOR_RANGE,
HALLOWEEN_COLOR_TRIGGER,
ELECTIONS_COLOR_TRIGGERS,
)
__author__ = "Wokzy"
def check_running(frame, application_bbox) -> bool:
""" Check if game is running by scanning color on timer positions """
for x, y in APPLICATION_TRIGGER['positions']:
x *= application_bbox[2] - application_bbox[0]
y *= application_bbox[3] - application_bbox[1]
x = int(x)
y = int(y)
x += application_bbox[0]
y += application_bbox[1]
if frame[y][x][0] == APPLICATION_TRIGGER['color'][0]:
if frame[y][x][1] == APPLICATION_TRIGGER['color'][1]:
if frame[y][x][2] == APPLICATION_TRIGGER['color'][2]:
return True
return False
def check_object(frame, x:int, y:int) -> bool:
""" Finding dropping objects by color """
def _check_color_trigger(color_trigger, limit:bool=True):
if not limit and random.random() > CLICK_LIMIT:
return False
if color_trigger['red']['min'] <= frame[y][x][0] <= color_trigger['red']['max']:
if color_trigger['green']['min'] <= frame[y][x][1] <= color_trigger['green']['max']:
# print(frame[y][x])
if color_trigger['blue']['min'] <= frame[y][x][2] <= color_trigger['blue']['max']:
return True
return False
if HALLOWEEN_MODE:
if _check_color_trigger(HALLOWEEN_COLOR_TRIGGER) or _check_color_trigger(BOMB_COLOR_TRIGGER):
return True
else:
if _check_color_trigger(DEFAULT_COLOR_TRIGGER):
return True
if ELECTIONS_MODE:
for color_trigger in ELECTIONS_COLOR_TRIGGERS:
if _check_color_trigger(color_trigger, False):
return True
#DOGS DROP
if DOGS_DROP_TOGGLE:
if frame[y][x][0] == frame[y][x][1] == frame[y][x][2] and DOGS_WHITE_COLOR_RANGE[0] <= frame[y][x][0] <= DOGS_WHITE_COLOR_RANGE[1]:
counter = 0
for i in range(-1, 2):
for j in range(-4, 2):
counter += (frame[y + j][x + i][0] == frame[y + j][x + i][1] == frame[y + j][x + i][2] and DOGS_WHITE_COLOR_RANGE[0] <= frame[y + j][x + i][0] <= DOGS_WHITE_COLOR_RANGE[1])
if counter >= 10:
return True
return False
def wait_running_game(camera, timeout:float = .0) -> None:
application_bbox = prepare_app()
frame = camera.get_latest_frame()
timer = time.time()
while not check_running(frame, application_bbox):
application_bbox = prepare_app()
frame = camera.get_latest_frame()
if timeout > 0.0:
assert time.time() - timer < timeout, f"Game has not been started for {timeout} seconds, exiting"
def main():
""" Autoclicker impl """
amount_of_games = 1
if len(sys.argv) > 1:
for arg in sys.argv:
if arg.isnumeric():
amount_of_games = int(arg)
break
camera = dxcam.create()
camera.start(target_fps=60)
frame = camera.get_latest_frame() # frame is an array with shape (y, x, 3)
print(f'Limited clicks: {CLICK_LIMIT}')
print('Trying to detect running game, click play')
wait_running_game(camera)
# time.sleep(2)
x_shift = 20
y_shift_top = 150
y_shift_bot = 250
game_counter = 0
application_bbox = prepare_app()
x_range = range(application_bbox[0] + x_shift, application_bbox[2] - x_shift, PIXELS_PER_ITERATION)
y_range = range(application_bbox[1] + y_shift_top, application_bbox[3] - y_shift_bot, PIXELS_PER_ITERATION)
while game_counter < amount_of_games:
game_counter += 1
print(f'Game {game_counter} detected!')
frame = camera.get_latest_frame()
__timer = datetime.datetime.now()
while check_running(frame, application_bbox) or (datetime.datetime.now() - __timer).total_seconds() < AVG_GAME_DURATION:
for x in x_range:
for y in y_range:
if check_object(frame, x, y):
mouse.move(x, y, absolute=True)
mouse.click(button='left')
time.sleep(0.3)
frame = camera.get_latest_frame()
else:
print('Finished')
if game_counter < amount_of_games:
time.sleep(0.5)
x = application_bbox[0] + int(NEW_GAME_TRIGGER_POS[0] * (application_bbox[2] - application_bbox[0]))
y = application_bbox[1] + int(NEW_GAME_TRIGGER_POS[1] * (application_bbox[3] - application_bbox[1]))
mouse.move(x, y, absolute=True)
mouse.click(button='left')
wait_running_game(camera, timeout = 12.5)
camera.stop()
def increase_click_limit():
global CLICK_LIMIT
CLICK_LIMIT = min(1.0, CLICK_LIMIT + 0.01)
print(f'Limit: {CLICK_LIMIT:.4}')
def decrease_click_limit():
global CLICK_LIMIT
CLICK_LIMIT = max(0.0, CLICK_LIMIT - 0.01)
print(f'Limit: {CLICK_LIMIT:.4}')
if __name__ == "__main__":
keyboard.add_hotkey('1', decrease_click_limit)
keyboard.add_hotkey('2', increase_click_limit)
if '--help' in sys.argv:
print(HELP_STRING)
else:
main()