This repository has been archived by the owner on Sep 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
play.py
341 lines (289 loc) · 13.6 KB
/
play.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
import time
from memorpy import MemWorker, Process
from offsets import *
from utils import dereference_offsets, entities_aob_scan, fetch_entity, ginput_aob_scan
import keyboard
def main():
mem = MemWorker(name=PROCESS_NAME)
g_input_ptr = dereference_offsets(mem, g_input_offsets)
g_input = mem.Address(g_input_ptr + g_input_base_offset)
local_ptr = dereference_offsets(mem, local_ptr_offsets)
print('g_input: %s' % hex(g_input))
print('local_ptr: %s' % hex(local_ptr))
entity_pointers = entities_aob_scan(mem)
print('Removing local entity from entity list')
entity_pointers.remove(local_ptr)
entity_pointers = [local_ptr]+entity_pointers
# g_input = mem.Address(ginput_aob_scan(mem))
def calculate_actual_input():
# based on my settings for brawlhalla
val = 0
val |= LEFT * keyboard.is_pressed('LEFT')
val |= RIGHT * keyboard.is_pressed('RIGHT')
val |= UP * keyboard.is_pressed('UP')
val |= DOWN * keyboard.is_pressed('DOWN')
val |= DODGE * keyboard.is_pressed('x')
val |= THROW * keyboard.is_pressed('e')
val |= QUICK_ATTACK * keyboard.is_pressed('q')
val |= HEAVY_ATTACK * keyboard.is_pressed('w')
return val
def reset_input(address, hard=False, u=0):
if hard:
address.write(0)
time.sleep(0.03)
time.sleep(0.03)
address.write(calculate_actual_input() | u)
def fetch_entity_from_index(i):
return fetch_entity(mem, entity_pointers[i])
def down_quick(local, target, u=0):
target_direction = LEFT if local.x-target.x > 0 else RIGHT
g_input.write(target_direction | DOWN | QUICK_ATTACK | u)
def neutral_heavy(local, target):
target_direction = LEFT if local.x-target.x > 0 else RIGHT
if target_direction != local.direction:
g_input.write(target_direction)
reset_input(g_input)
g_input.write(HEAVY_ATTACK)
def side_heavy(local, target):
target_direction = LEFT if local.x-target.x > 0 else RIGHT
g_input.write(HEAVY_ATTACK | target_direction)
def down_heavy(local, target):
target_direction = LEFT if local.x-target.x > 0 else RIGHT
g_input.write(HEAVY_ATTACK | DOWN | target_direction)
def neutral_quick(local, target):
target_direction = LEFT if local.x-target.x > 0 else RIGHT
if target_direction != local.direction:
g_input.write(target_direction)
reset_input(g_input)
g_input.write(QUICK_ATTACK)
def side_air_quick(local, target, u=UP):
target_direction = LEFT if local.x-target.x > 0 else RIGHT
g_input.write(target_direction | u | QUICK_ATTACK)
def side_quick(local, target, u=UP):
target_direction = LEFT if local.x-target.x > 0 else RIGHT
g_input.write(target_direction | QUICK_ATTACK)
def air_quick(local, target, u=UP):
target_direction = LEFT if local.x-target.x > 0 else RIGHT
if target_direction != local.direction:
g_input.write(target_direction)
reset_input(g_input)
g_input.write(QUICK_ATTACK)
def gravity_cancel():
print('gravity cancel')
g_input.write(DODGE)
reset_input(g_input)
print('Entering script mode')
while True:
targets = [fetch_entity_from_index(i) for i in range(len(entity_pointers))]
# assuming first entity found is local player which might not be true?
local = targets.pop(0)
if local.in_animation or local.in_stun:
continue
current_input = g_input.read()
for target in targets:
dx = target.x-local.x
dy = target.y-local.y
if target.in_attack and abs(dx+target.x_vel-local.x_vel) < 300 and abs(dy+target.y_vel-local.y_vel) < 300 and local.can_dodge:
print('phase dodge')
if local.not_grounded:
g_input.write(DODGE | current_input)
else:
g_input.write(DODGE)
time.sleep(0.05)
reset_input(g_input)
break
if local.weapon == MELEE:
# jump if above near
if (150 < dy < 200) and (0 < abs(dx) < 250) and local.jump_count == 0 and target.in_stun:
print('jump if above near')
target_direction = LEFT if local.x-target.x > 0 else RIGHT
g_input.write(UP | target_direction)
reset_input(g_input)
break
# neutral quick
if (abs(dy) < 150) and (0 < abs(dx) < 150) and not local.not_grounded:
print('neutral quick')
neutral_quick(local, target)
reset_input(g_input)
break
# side quick
if (abs(dy) < 150) and (50 < abs(dx) < 350) and not local.not_grounded and target.in_stun:
print('side quick')
side_quick(local, target)
reset_input(g_input)
break
# down quick
if (abs(dy) < 150) and (100 < abs(dx) < 350) and not local.not_grounded:
print('down quick')
down_quick(local, target)
reset_input(g_input)
break
# quick
if (abs(dy) < 50) and (10 < abs(dx) < 250) and local.not_grounded:
print('air quick')
air_quick(local, target)
reset_input(g_input)
if -400 < dy < -100 and (abs(dy+abs(dx)) < 100) and local.not_grounded and local.jump_count == 0:
print('air down quick')
down_quick(local, target)
reset_input(g_input)
break
if local.weapon == SPEAR:
if 50 < dy < 350 and 400 > abs(dx) > 100:
if not local.not_grounded:
print('down quick')
down_quick(local, target)
reset_input(g_input)
break
if 100 < dy < 450 and 400 > abs(dx) > 50:
if not local.not_grounded:# and target.damage_taken > 180:
print('finish')
neutral_heavy(local, target)
reset_input(g_input)
break
elif local.not_grounded and local.can_dodge and target.in_stun:
print('finish')
gravity_cancel()
neutral_heavy(local, target)
reset_input(g_input)
break
if -150 < dy < 0 and 200 < abs(dx) and abs(dx) < 550:
if not local.not_grounded:
down_heavy(local, target)
reset_input(g_input)
break
if local.not_grounded and local.can_dodge and local.jump_count == 0:
gravity_cancel()
down_heavy(local, target)
reset_input(g_input)
break
# spear air side quick
if 200 < dy < 400 and 400 > abs(dx) > 100 and local.not_grounded and local.jump_count == 0:
print('air side quick')
# can be better with jump count (can jump)
side_air_quick(local, target)
reset_input(g_input)
break
# spear air quick
if abs(dy) < 300 and 300 > abs(dx) and local.not_grounded:
print('air quick')
# can be better with jump count (can jump)
air_quick(local, target)
reset_input(g_input)
break
# # quick
# if (abs(dy) < 150) and (100 < abs(dx) < 600) and not local.not_grounded:
# print('side quick')
# side_quick(local, target)
# reset_input(g_input)
# break
if local.weapon == KATAR:
# if 50 < dy < 350 and 300 > abs(dx) > 100:
if 400 > dy > 50 and (50 < abs(dx) < 400) and target.in_stun:
if not local.not_grounded:
print('down quick')
down_quick(local, target)
reset_input(g_input)
break
if -400 < dy < -100 and (abs(dy+abs(dx)) < 100) and local.not_grounded and local.jump_count == 0:
print('air down quick')
down_quick(local, target)
reset_input(g_input)
break
if 100 < dy < 600 and (abs(abs(dx)-dy) < 100) and local.not_grounded and local.jump_count == 0:
print('air side heavy')
side_heavy(local, target)
reset_input(g_input)
break
if (abs(dy) < 50) and (abs(dx) < 300 and target.in_stun) or (abs(dx) < 100) and not local.not_grounded:
print('nquick')
neutral_quick(local, target)
reset_input(g_input)
break
if (abs(dy) < 100) and (70 < abs(dx) < 400) and not local.not_grounded:
print('side quick')
side_quick(local, target)
reset_input(g_input)
break
if abs(dy) < 300 and 300 > abs(dx) and local.not_grounded:
print('air quick')
air_quick(local, target)
reset_input(g_input)
break
if 200 < dy < 400 and 300 > abs(dx) > 100 and local.not_grounded and local.jump_count == 0:
print('air side quick')
# can be better with jump count (can jump)
side_air_quick(local, target)
reset_input(g_input)
break
if local.weapon == SWORD:
if 300 < (dy+target.y_vel-local.y_vel) < 450 and 350 > abs(dx+target.x_vel-local.x_vel) > 200 and target.damage_taken > 180:
print('sword finish')
if local.not_grounded and local.can_dodge:
gravity_cancel()
neutral_heavy(local, target)
break
elif not local.not_grounded:
neutral_heavy(local, target)
break
if 100 < dy < 350 and 350 > abs(dx) > 100 and target.in_stun and target.damage_taken > 180:
print('sword stun finish')
if local.not_grounded and local.can_dodge:
gravity_cancel()
neutral_heavy(local, target)
reset_input(g_input)
break
elif not local.not_grounded:
neutral_heavy(local, target)
reset_input(g_input)
break
# jump if above near
if (100 < dy < 200) and (0 < abs(dx) < 200) and local.jump_count == 0 and target.in_stun:
print('jump if above near')
target_direction = LEFT if local.x-target.x > 0 else RIGHT
g_input.write(UP | target_direction)
reset_input(g_input)
break
# air down quick
if (-250 < dy < -50) and (0 < abs(dx) < 150) and local.not_grounded and local.jump_count == 0:
print('air down quick')
target_direction = LEFT if local.x-target.x > 0 else RIGHT
down_quick(local, target)
reset_input(g_input)
break
# air quick
if (100 < dy < 350) and (0 < abs(dx) < 200) and local.not_grounded:
print('air quick')
air_quick(local, target)
reset_input(g_input)
break
# air side quick
if (abs(dy) < 100) and (70 < abs(dx) < 350) and local.not_grounded and local.jump_count == 0:
print('air side quick')
target_direction = LEFT if local.x-target.x > 0 else RIGHT
side_air_quick(local, target, u=0)
reset_input(g_input)
break
# down quick
if (abs(dy) < 150) and (100 < abs(dx) < 350) and not local.not_grounded:
print('down quick')
down_quick(local, target)
reset_input(g_input)
break
if (target.in_animation and not target.in_stun) and abs(dx+target.x_vel-local.x_vel) < 400 and abs(dy+target.y_vel-local.y_vel) < 400 and not local.not_grounded:
print('jump dodge')
if current_input & UP:
reset_input(g_input, u=UP)
else:
g_input.write(UP)
reset_input(g_input)
break
# if dy > 100 and not local.not_grounded and abs(dx) < 250:
# print('jump up dude')
# if current_input & UP:
# reset_input(g_input, u=UP)
# else:
# g_input.write(UP)
# reset_input(g_input)
# break
main()