forked from CohortMinseok/Bumblebee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
1710 lines (1580 loc) · 75.8 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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# import socket
# import pyautogui
# import signal
import win32gui
# import win32api
# import win32con
from io import BytesIO
import requests
import json
# import os
import sys
# import uuid
import random
import cv2
import time
from math import log10, floor
from time import perf_counter
import numpy as np
import threading
from pynput import keyboard
from pynput.keyboard import Listener as KeyListener # type: ignore[import]
from pynput.mouse import Listener as MouseListener # type: ignore[import]
from PIL import ImageGrab
from datetime import datetime
from game import Game
import asyncio
import tkinter as tk
from tkinter import messagebox
from tkinter import ttk
from tkinter import *
import gdi_capture
from PIL import Image, ImageTk
from configparser import ConfigParser
from typing import Final
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
from attack import leftp, leftr, rightp, rightr, sleep, npcp, npcr, refreshkeybind, goleftattack, gorightattack, goleftattackk, gorightattackk, \
goupattack, upjumpattack, godownattack, rightjumpjumpattack, \
stormwingrotation, castlewallrotation, bountyhuntrotation, send2, send3, goupattackv3, goupattackv2
# from runesolver import runechecker, gotorune, enablerune, disablerune, gotopoloportal, set_hwnd
from runesolver import RuneSolver
from initinterception import interception, move_to, move_relative, left_click, mouse_position, mousedown, mouseup, hold_mouse, custommoveto, initiate_move, \
auto_capture_devices2
class TkinterBot:
def __init__(self):
self.config = ConfigParser()
self.config.read('settings.ini')
self.config2 = ConfigParser()
self.config2.read('secret.ini')
self.minimapX = int(self.config.get('main', 'minimapX'))
self.minimapY = int(self.config.get('main', 'minimapY'))
self.initial_line_position = float(self.config.get('main', 'initial_line_position'))
self.initial_line_position2 = float(self.config.get('main', 'initial_line_position2'))
self.initial_line_position3 = float(self.config.get('main', 'initial_line_position3'))
self.initial_line_position4 = float(self.config.get('main', 'initial_line_position4'))
self.ipaddress = self.config.get('main', 'ipaddress')
self.g = Game((8, 63, self.minimapX, self.minimapY))
self.TOKEN = self.config2.get('telegram', 'TOKEN')
self.chat_id = self.config2.get('telegram', 'chat_id')
self.att = self.config.get('keybind', 'attack')
self.jump = self.config.get('keybind', 'jump')
self.teleport = self.config.get('keybind', 'teleport')
self.ropeconnect = self.config.get('keybind', 'ropeconnect')
self.npc = self.config.get('keybind', 'npc')
self.runesolver = RuneSolver()
self.application = None
self.threads = []
self.stop_event = threading.Event()
self.pause = True
self.telegram_keep_alive = True
self.acc_not_bind = False
self.telegram_started = False
self.tkinter_started = False
self.position10 = (480, 370, 481, 371)
self.position9 = (445, 405, 446, 406)
self.position8 = (430, 375, 431, 376)
self.position7 = (25, 10, 26, 11) #
self.position6 = (390, 400, 441, 401) #broid
# self.position6 = (440, 400, 441, 401) #no-broid
self.position5 = (300, 360, 301, 361)
self.position4 = (11, 88, 200, 200)
self.position44 = (11, 88, 200, 200)
self.position33 = (315, 40, 316, 41) #
self.position3 = (405, 75, 406, 76) #
self.position2 = (701, 472, 702, 473) #
self.polochecker = False
self.portaldialogueX = 222
self.portaldialogueY = 410
self.wolfdialogueY = 435
self.chathwnd=None
self.maplehwnd=None
self.whitedotoccur=False
self.gotoportal=True
self.pausepolochecker=False
self.replaceropeconnect=False
self.triggermousetest=False
self.init_maple_windows()
self.loop1 = asyncio.new_event_loop()
self.loop2 = asyncio.new_event_loop()
self.loop3 = asyncio.new_event_loop()
self.loop4 = asyncio.new_event_loop()
self.loop5 = asyncio.new_event_loop()
self.loop6 = asyncio.new_event_loop()
self.thread1 = threading.Thread(target=self.run_thread1)
self.thread2 = threading.Thread(target=self.run_thread2)
self.thread3 = threading.Thread(target=self.run_thread3)
self.thread6 = threading.Thread(target=self.run_thread6)
def init_tkinter(self):
self.root = tk.Tk()
self.root.title("chrome")
photo=PhotoImage(file='icon.ico')
self.root.iconphoto(False,photo)
screen_width = self.root.winfo_screenwidth()
screen_height = self.root.winfo_screenheight()
window_width = 600
window_height = 800
window_x = screen_width - window_width
window_y = 0
self.root.geometry(f"{window_width}x{window_height}+{window_x}+{window_y}")
self.root.grid_rowconfigure(0, weight=1)
self.root.grid_columnconfigure(0, weight=1)
# self.root.resizable(False,False)
# # background_image = tk.PhotoImage(file="bumblebee.gif")
# background_image = Image.open("bumblebee.gif")
# background_image = background_image.resize((window_width, window_height), Image.Resampling.LANCZOS)
# background_photo = ImageTk.PhotoImage(background_image)
# background_label = tk.Label(root, image=background_photo)
# background_label.place(relwidth=1, relheight=1)
# background_label.image = background_photo
print(f'setup_tab')
self.setup_tab()
print(f'setup_tab1')
self.setup_tab1()
print(f'setup_tab4')
self.setup_tab4()
# print(f'setup_tab5')
# self.setup_tab5()
print(f'setup_tab6')
self.setup_tab6()
print(f'setup_tabs_done')
self.root.grid_rowconfigure(0, weight=1)
self.root.grid_columnconfigure(0, weight=1)
self.root.protocol("WM_DELETE_WINDOW", self.on_close)
# self.threads = []
# self.stop_event = threading.Event()
# self.thread = threading.Thread(target=self.start_the_main, args=(self.stop_event,))
# self.thread.start()
# self.threads.append((self.thread, self.stop_event))
# self.thread2 = threading.Thread(target=self.start_the_main2, args=(self.stop_event,))
# self.thread2.start()
# self.threads.append((self.thread, self.stop_event), (self.thread2, self.stop_event))
self.tkinter_started=True
self.root.mainloop()
async def async_function(self, thread_name, iterations):
try:
self.application = Application.builder().token(self.TOKEN).build()
# self.application.add_handler(CommandHandler('start', self.start_command))
self.application.add_handler(CommandHandler('status', self.status_command))
# app.add_handler(CommandHandler('help', help_command))
# app.add_handler(CommandHandler('custom', custom_command))
# app.add_handler(MessageHandler(filters.TEXT, handle_message))
self.application.add_error_handler(self.error)
# async with self.application:
await self.application.initialize()
await self.application.start()
await self.application.updater.start_polling()
# self.root.mainloop() # press close and this line over
# await asyncio.sleep(30)
self.telegram_started = True
while self.telegram_keep_alive:
# for i in range(iterations):
# print(f"{thread_name} - Iteration i")
await asyncio.sleep(1) # Simulating asynchronous work
print(f'finished telegram_run1')
await self.application.updater.stop()
await self.application.stop()
await self.application.shutdown()
print(f'finished telegram_run2')
except Exception as e:
print(f'{e=}')
self.acc_not_bind = True
self.telegram_started = True
finally:
print(f'exiting telegram thread ..')
async def async_function2(self, thread_name, iterations):
while not self.telegram_started:
time.sleep(1)
self.init_tkinter()
# for i in range(iterations):
# print(f"{thread_name} - Iteration {i}")
# await asyncio.sleep(1) # Simulating asynchronous work
def run_thread1(self):
asyncio.set_event_loop(self.loop1)
self.loop1.run_until_complete(self.async_function("Thread 1", 5)) # telegram thread
def run_thread2(self):
asyncio.set_event_loop(self.loop2)
self.loop2.run_until_complete(self.async_function2("Thread 2", 5)) # tkinter init thread
def run_thread3(self):
asyncio.set_event_loop(self.loop3)
self.loop3.run_until_complete(self.async_function3("Thread 3", 5)) # main thread
def run_thread4(self):
print(f'run_thread4 started')
asyncio.set_event_loop(self.loop4)
self.loop4.run_until_complete(self.async_function4()) # checker thread
print(f'run_thread4 endeded')
def run_thread5(self):
print(f'run_thread5 started')
asyncio.set_event_loop(self.loop5)
self.loop5.run_until_complete(self.async_function5()) # gma thread
print(f'run_thread5 endeded')
def run_thread6(self):
asyncio.set_event_loop(self.loop6)
self.loop6.run_until_complete(self.async_function6()) # just a button loop
def start_threads(self):
# Start both threads
self.thread1.start()
self.thread2.start()
self.thread3.start()
self.thread6.start()
def wait_for_threads(self):
# Wait for both threads to finish
self.thread1.join()
self.thread2.join()
self.thread3.join()
self.thread6.join()
async def async_function3(self, thread_name, iterations):
print(f'bot has started ..')
while not self.tkinter_started:
time.sleep(1.01)
# while True: # testing purpose
# if self.pause:
# print(f'script is paused .. click resume to resume. ')
# while self.pause:
# # do nothing
# time.sleep(1)
# if self.stop_event.is_set():
# # self.thread4.join()
# return
# print(f'script resumed ..')
# # # whitedot = self.g.white_dot_checker()
# hwnd = win32gui.FindWindow(None, "MapleStory")
# position = win32gui.GetWindowRect(hwnd)
# x, y, w, h = position
# # # print(f'{x=} {y=} {w=} {h=}') # 8 left right 5 up down 29 title bar | minus left 8 | minus top 34
# # # print(f'{x=} {y=} {w=} {h=}') # 8 left right 1 up 8 down 30 title bar | minus left 8 | minus top 31
# # # # x+222, y+410
# # # # move_to(x+self.position5[0],y+self.position5[1])
# # move_to(x+self.portaldialogueX,y+self.portaldialogueY)
# # move_relative(100)
# # time.sleep(.5)
# targetx=500
# targety=600
# # with hold_mouse('left'):
# # for i in range(10):
# # print(f'{i=}')
# # move_relative(20,0)
# # move_relative(0,20)
# # time.sleep(.5)
# await custommoveto(targetx,targety)
# left_click()
# time.sleep(2.411) # when testing ..
# #
# # await rightjumpjumpattack()
# # time.sleep(1.011) # when testing ..
# #
# # # huntingmapcheckerlocations = self.g.hunting_map_timer_checker() # check if is hidden street bounty hunt
# # huntingmapcheckerlocations = self.g.hunting_map2_checker()
# # # huntingmapcheckerlocations = self.g.gma_detector() #
# # # huntingmapcheckerlocations = self.seperate_gma_detector() #
# # if huntingmapcheckerlocations is not None:
# # print(f'{huntingmapcheckerlocations=}')
# #
# #
# time.sleep(1.011) # when testing ..
self.thread4 = threading.Thread(target=self.run_thread4)
self.thread4.start()
self.thread5 = threading.Thread(target=self.run_thread5)
self.thread5.start()
left1=self.line_position_slider.get()
right1=self.line_position_slider2.get()
top1=self.line_position_slider3.get()
btm1=self.line_position_slider4.get()
left=self.line_position_slider.get()/2+0
right=self.line_position_slider2.get()/2+0
top=self.line_position_slider3.get()/2-8
btm=self.line_position_slider4.get()/2-8
randomlist = ['z', 'x', 'c', 'space', '2', '3', '0', 'f9', 'w', 'e', 'r', 't', 's', 'd', 'f', 'v']
offsetx=10
offsety=10
randommtimer0=0
randommtimer=0
replaceropeconnecttimer0=0
replaceropeconnecttimer=0
runonce=True
self.polocheckertimer0=0
polocheckertimer=0
runetimer0=0
runetimer=0
checkrune=True
solverune=False
self.now=0
xynotfound=0
await initiate_move()
while True:
if self.pause:
print(f'script is paused .. click resume to resume. ')
while self.pause:
# do nothing
time.sleep(1)
if self.stop_event.is_set():
self.thread4.join()
self.thread5.join()
return
print(f'script resumed ..')
#
time.sleep(.411) # when testing ..
# time.sleep(.011) # when real botting ..
g_variable = self.g.get_player_location()
x, y = (None, None) if g_variable is None else g_variable
if x == None or y == None:
xynotfound+=1
if xynotfound > 50:
t = time.localtime()
currenttime = time.strftime("%H:%M:%S", t)
print(f'something is wrong .. character not found .. exiting .. {currenttime}')
# stop_flag = True
# randompicker_thread.join()
self.pause=True
# return
print(f'x==None, pass ..')
time.sleep(.1)
pass
else:
xynotfound=0
if y > top and (y > btm-offsety and y <= btm+offsety):
if x > left+offsetx:
await random.choice([goleftattack, goleftattackk])()
elif x < left-offsetx:
await random.choice([gorightattack, gorightattackk])()
elif x >= left-offsetx and x <= left+offsetx:
if self.replaceropeconnect:
await random.choice([goupattackv3])()
else:
await random.choice([goupattack])()
elif y <= top+offsety and y > top-offsety:
if x < right-offsetx:
await random.choice([gorightattack, gorightattackk])()
elif x > right+offsetx:
await random.choice([goleftattack, goleftattackk])()
elif x >= right-offsetx and x <= right+offsetx:
await random.choice([godownattack])()
elif y > top and not (y > btm-offsety and y <= btm+offsety):
if x >= left-offsetx and x <= left+offsetx:
if self.replaceropeconnect:
await random.choice([goupattackv3])()
else:
await random.choice([goupattack])()
elif x >= right-offsetx and x <= right+offsetx:
await random.choice([godownattack])()
else:
await random.choice([godownattack])()
self.now = perf_counter()
randommtimer = self.now - randommtimer0
if randommtimer > 15:
randommtimer0 = self.now
p = random.randint(0, len(randomlist)-1)
code = random.choice(randomlist)
if code is not None:
print(f'randomiser {code=}')
await send2(code)
await send3(code)
if self.replaceropeconnect==True:
if runonce:
replaceropeconnecttimer0=self.now
runonce=False
replaceropeconnecttimer = self.now - replaceropeconnecttimer0
if replaceropeconnecttimer > 90:
self.replaceropeconnect=False
runonce=True
polocheckertimer = self.now - self.polocheckertimer0
if polocheckertimer > 90:
self.pausepolochecker=False
runetimer = self.now - runetimer0
if runetimer > 600: # change to 600 when haste
# if runetimer > 900: # change to 600 when haste
# checkrune = True
checkrune = False
if checkrune:
solverune = self.runesolver.runechecker(self.g)
# print(f'{x=} {y=} {statuetimer=} {fountaintimer=}, {runetimer=}, {cctimer=}')
print(f'{x=} {y=} {runetimer=} {solverune=} | {left=}, {top=}, {right=}, {btm=} | {left1=}, {top1=}, {right1=}, {btm1=}')
# print(f'{x=}, {y=} | {left=}, {top=}, {right=}, {btm=} | {left1=}, {top1=}, {right1=}, {btm1=}')
if solverune:
await self.runesolver.gotorune(self.g)
elif self.polochecker:
if self.whitedotoccur:
if not await self.polocheckerfunc(self.gotoportal):
self.replaceropeconnect=True
self.whitedotoccur=False
else:
await self.polocheckerfunc(self.gotoportal)
else:
pass
# print(f'{x=}, {y=} | {left=}, {top=}, {right=}, {btm=} | {left1=}, {top1=}, {right1=}, {btm1=}')
async def async_function4(self):
whitedotcounter=0
while True:
while self.pause:
time.sleep(1)
if self.stop_event.is_set():
return
# print(f'new checking cycle ..')
diedcheckerlocations = self.g.died_checker()
if diedcheckerlocations is not None:
print(f'{diedcheckerlocations=}')
# hwnd = win32gui.FindWindow(None, "MapleStory")
position = win32gui.GetWindowRect(self.maplehwnd)
x, y, w, h = position
print(f'moving to x, y')
await custommoveto(x+self.position6[0],y+self.position6[1])
time.sleep(.1)
print(f'clicking x, y')
left_click()
print(f'done clicking')
move_relative(10,0)
time.sleep(.1)
if not self.pausepolochecker:
polocheckerlocations = self.g.polo_checker() # check for portal on minimap
if polocheckerlocations is not None:
print(f'{polocheckerlocations=}')
self.polochecker = True
self.gotoportal=True
whitedotlocations = self.g.white_dot_checker()
if whitedotlocations is not None:
whitedotcounter+=1
if whitedotcounter>1:
self.whitedotoccur=True
self.polochecker=True
self.gotoportal=False
# if not await self.polocheckerfunc(False):
# self.replaceropeconnect=True
# position = win32gui.GetWindowRect(self.maplehwnd)
# x, y, w, h = position
# print(f'moving to x, y')
# await custommoveto(x+self.portaldialogueX,y+self.wolfdialogueY)
# time.sleep(.1)
# print(f'clicking x, y')
# left_click()
# print(f'done clicking')
# move_relative(10,0)
# time.sleep(.1)
elif whitedotlocations is None:
whitedotcounter=0
time.sleep(2)
async def async_function5(self): # gma_checker
while True:
while self.pause:
time.sleep(1)
if self.stop_event.is_set():
return
if self.chathwnd:
gmacheckerlocations = self.seperate_gma_detector()
if gmacheckerlocations:
print(f'got GM')
else:
print(f'no GM')
else:
print(f'chat window not found. ')
time.sleep(5)
async def async_function6(self): # just a button loop
while True:
time.sleep(1)
if self.stop_event.is_set():
print(f'async_function6 return. ')
return
if self.triggermousetest:
await initiate_move()
self.triggermousetest=False
# def find_maplestory_windows(self, hwnd, lParam):
# title = win32gui.GetWindowText(hwnd)
# if 'MapleStory' in title:
# print(f"Window Title: {title}, Handle: {hwnd}")
def init_maple_windows(self):
# win32gui.EnumWindows(self.find_maplestory_windows, 0)
# hwnd = win32gui.FindWindow(None, "MapleStory")
hwnd = 0
windows=[]
while True:
print(f'{hwnd}')
hwnd = win32gui.FindWindowEx(0,hwnd,None, "MapleStory")
if hwnd == 0:
break
windows.append(hwnd)
for windowhwnd in windows:
position = win32gui.GetWindowRect(windowhwnd)
x, y, w, h = position
if w-x == 410:
self.chathwnd=windowhwnd
else:
self.maplehwnd=windowhwnd
self.runesolver.set_maplehwnd(self.maplehwnd)
print(f'{self.maplehwnd}')
print(f'{x} {y} {w} {h}')
# screenshot = ImageGrab.grab(position)
# screenshot = np.array(screenshot)
# img = cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR)
# cv2.imshow(f'{windowhwnd}', img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
def rebindchathwnd(self):
hwnd = 0
windows=[]
while True:
print(f'{hwnd}')
hwnd = win32gui.FindWindowEx(0,hwnd,None, "MapleStory")
if hwnd == 0:
break
windows.append(hwnd)
for windowhwnd in windows:
position = win32gui.GetWindowRect(windowhwnd)
x, y, w, h = position
if w-x == 410:
self.chathwnd=windowhwnd
return True
return False
def seperate_gma_detector(self):
if self.chathwnd == None:
print(f'chat window not found. ')
return
try:
position = win32gui.GetWindowRect(self.chathwnd)
x, y, w, h = position
print(f'{x} {y} {w} {h}')
chatposition = (x,y+385,w-15,h-25)
screenshot = ImageGrab.grab(chatposition)
screenshot = np.array(screenshot)
img = cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR)
# cv2.imshow('img', img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
height, width = img.shape[0], img.shape[1]
# print(f'{img=}')
# img_reshaped = np.reshape(img, ((width * height), 4), order="C")
img_reshaped = np.reshape(img, ((width * height), 3), order="C")
# print(f'{img_reshaped=}')
# print(f'{img_reshaped[:,0]=}')
locations = []
sum_x, sum_y, count = 0, 0, 0
matches = np.where(
(img_reshaped[:,0] >= 201) & (img_reshaped[:,0] <= 225) &
(img_reshaped[:,1] >= 201) & (img_reshaped[:,1] <= 225) &
(img_reshaped[:,2] >= 201) & (img_reshaped[:,2] <= 225)
)[0]
# print(f'{matches=}')
for idx in matches:
# Calculate the original (x, y) position of each matching index.
sum_x += idx % width
sum_y += idx // width
count += 1
# print(f'{idx % width=} {idx // width=} {width=} {img_reshaped[idx]} {count=}')
if count > 0:
x_pos = sum_x / count
y_pos = sum_y / count
locations.append((x_pos, y_pos))
return locations
except Exception as e:
print(f'{e=}')
async def polocheckerfunc(self, gotoportal):
truefalse=True
if gotoportal:
portaltype = await self.runesolver.gotopoloportal(self.g)
else:
portaltype = await self.runesolver.checkportaltype(self.g)
if portaltype == 'b':
print(f'dobountyhuntrotation')
# do bountyhunt rotation for maybe 30sec
for i in range(6):
await bountyhuntrotation()
while True:
huntingmaptimerchecker = self.g.hunting_map_timer_checker()
if huntingmaptimerchecker is not None:
# do bountyhunt rotation
print(f'stillinportal')
await bountyhuntrotation()
pass
else:
print(f'notinportal')
while self.g.dark_checker() is not None:
print(f'map transitioning ..')
time.sleep(1)
await rightp()
time.sleep(1.5)
await rightr()
break
# press npc button 5 times to exit
await leftp()
time.sleep(.8)
await leftr()
for i in range(6):
await npcp()
await npcr()
time.sleep(.1)
time.sleep(2.)
elif portaltype == 'g':
print(f'doguardingrotation')
# do guardingthecastlewall rotation
for i in range(10):
await castlewallrotation()
while True:
huntingmaptimerchecker = self.g.hunting_map_timer_checker()
if huntingmaptimerchecker is not None:
# do guardingthecastlewall rotation
print(f'stillinportal')
await castlewallrotation()
pass
else:
print(f'notinportal')
while self.g.dark_checker() is not None:
print(f'map transitioning ..')
time.sleep(1)
await rightp()
time.sleep(1.5)
await rightr()
break
# press npc button 5 times to exit
await leftp()
time.sleep(.8)
await leftr()
for i in range(8):
await npcp()
await npcr()
await sleep(.1)
elif portaltype == 'd':
print(f'dostormwingrotation')
# do stormwing rotation
# for i in range(7):
# await stormwingrotation()
await self.stormwing(100)
while True:
huntingmaptimerchecker = self.g.hunting_map_timer_checker()
if huntingmaptimerchecker is not None:
# do stormwing rotation
print(f'stillinportal')
# await stormwingrotation()
await self.stormwing(10)
pass
else:
print(f'notinportal')
while self.g.dark_checker() is not None:
print(f'map transitioning ..')
time.sleep(1)
await rightp()
time.sleep(1.5)
await rightr()
break
# press npc button 5 times to exit
await leftp()
time.sleep(.8)
await leftr()
for i in range(7):
await npcp()
await npcr()
time.sleep(.1)
elif portaltype == 'e':
print(f'doespeciaspam')
# do especia spam
for i in range(5):
# await npcp()
# await npcr()
# r = random.randint(500,1000)
# r /= 1000
# await sleep(r)
await self.especia()
# check if timer still there
# if timer no longer there, press npc x4 to get out.
for count in range(100): # for testing
# while True:
huntingmaptimerchecker = self.g.especia_dot_checker()
if huntingmaptimerchecker is not None:
# do especia spam
print(f'stillinportal, {count=}')
# await npcp()
# await npcr()
# r = random.randint(500,1000)
# r /= 1000
# await sleep(r)
await self.especia()
pass
else:
print(f'notinportal')
while self.g.dark_checker() is not None:
print(f'map transitioning ..')
time.sleep(1)
time.sleep(1.5)
break
# press npc button 5 times to exit
for i in range(7):
await npcp()
await npcr()
time.sleep(.1)
elif portaltype == 'r':
print(f'fritoportalendchat')
# hwnd = win32gui.FindWindow(None, "MapleStory")
position = win32gui.GetWindowRect(self.maplehwnd)
x, y, w, h = position
time.sleep(.1)
await custommoveto(x+self.portaldialogueX,y+self.portaldialogueY)
time.sleep(.1)
left_click()
self.pausepolochecker=True
self.polocheckertimer0 = self.now
truefalse=False
elif portaltype == 'f':
print(f'clickendchat')
# click end chat cause flamewolf
# hwnd = win32gui.FindWindow(None, "MapleStory")
position = win32gui.GetWindowRect(self.maplehwnd)
x, y, w, h = position
time.sleep(.1)
await custommoveto(x+self.portaldialogueX,y+self.wolfdialogueY)
time.sleep(.1)
left_click()
self.pausepolochecker=True
self.polocheckertimer0 = self.now
truefalse=False
else:
print(f'enterportalfailedorerror')
# means enter portal failed, or error, back to training.
self.polochecker=False
return truefalse
async def status_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
message_type: str = update.message.chat.type
text: str = update.message.text
print(f'{update.message=}')
print(f'{self.chat_id=}')
print(f'{type(self.chat_id)=}')
print(f'{type(update.message.chat.id)=}')
if str(update.message.chat.id) == self.chat_id:
print(f'Access User ({update.message.chat.id}) in {message_type}: "{text}"')
pass
else:
print(f'Denied User ({update.message.chat.id}) in {message_type}: "{text}"')
return
print(f'User ({update.message.chat.id}) in {message_type}: "{text}"')
print(f'telegramstatus')
now = perf_counter()
photo0 = self.g.get_screenshot()
success, photo0_encoded = cv2.imencode('.png', photo0)
photo0_bytes = photo0_encoded.tobytes()
files = {'photo': photo0_bytes}
payload = {
'chat_id': self.chat_id,
'caption': 'dummy photo'
}
# response = requests.post('https://api.telegram.org/bot'+self.TOKEN+'/sendPhoto', data=payload, files=files)
# if response.status_code == 200:
# print(f'{perf_counter()-now =}')
# print(f"success {response.json().get('description')}")
# print(f"success {response.json()}")
# else:
# print(f"Request failed with status code_: {response.status_code}")
# print(f"{response.json().get('description')}")
# await update.message.reply_text('Hello! Thanks for chatting with me! I am a banana!')
await update.message.reply_photo(photo0_bytes)
print(f'{perf_counter()-now =}')
async def especia(self):
for i in range(1):
await npcp()
await npcr()
r = random.randint(500,1000)
r /= 1000
await sleep(r)
if self.pause:
print(f'script is paused .. click resume to resume. ')
while self.pause:
# do nothing
time.sleep(1)
if self.stop_event.is_set():
# self.thread4.join()
return
print(f'script resumed ..')
async def stormwing(self, count):
goleft=False
goright=True
## 1.8 165.2 (top=24.5?) (btm=62.5) (right=138.5?)
top=29.0
left=35.0 # 18.0 # 27.0
right=130 # 125.0 # 135.0 140.0 132.5
btm=58.0 # 54.5
for i in range(count):
huntingmaptimerchecker = self.g.hunting_map_timer_checker()
if huntingmaptimerchecker is None:
return
# time.sleep(.4) # running test
time.sleep(.3) # running real
# time.sleep(.2) # running real
g_variable = self.g.get_player_location()
x, y = (None, None) if g_variable is None else g_variable
if x == None or y == None:
xynotfound+=1
if xynotfound > 50:
t = time.localtime()
currenttime = time.strftime("%H:%M:%S", t)
print(f'something is wrong .. character not found .. exiting .. {currenttime}')
# stop_flag = True
# randompicker_thread.join()
return
print(f'x==None, pass ..')
time.sleep(.1)
pass
else:
xynotfound=0
print(f'{x=} {y=} {goleft=} {goright=}')
# time.sleep(.1)
if goright:
if x > right:
if y < btm:
await godownattack()
time.sleep(.3)
await goleftattack()
time.sleep(.1)
elif y > top:
await upjumpattack()
time.sleep(.3)
goright=False
goleft=True
else:
await gorightattack()
time.sleep(.3)
if x < left: # only if x < left
if y < btm:
await godownattack()
time.sleep(.3)
elif goleft:
if x < left: # only if x < left
if y > top:
time.sleep(.1)
await upjumpattack()
time.sleep(.3)
elif y < top:
await godownattack()
time.sleep(.3)
await gorightattack()
time.sleep(.3)
goright=True
goleft=False
else:
await goleftattack()
time.sleep(.3)
if x > right: # only if x > right
if y < btm:
await godownattack()
time.sleep(.3)
async def start_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
message_type: str = update.message.chat.type
text: str = update.message.text
print(f'{update.message}')
# global chat_id
# print(f'{chat_id =}')
if update.message.chat.id == 5630992696:
print(f'Access User ({update.message.chat.id}) in {message_type}: "{text}"')
pass
elif update.message.chat.id == 1125332211:
print(f'Access User ({update.message.chat.id}) in {message_type}: "{text}"')
pass
else:
print(f'Denied User ({update.message.chat.id}) in {message_type}: "{text}"')
return
print(f'User ({update.message.chat.id}) in {message_type}: "{text}"')
# if message_type == 'group':
# if BOT_USERNAME in text:
# new_text: str = text.replace(BOT_USERNAME, '').strip()
# response: str = handle_response(new_text)
# else:
# return
# else:
# response: str = handle_response(text)
await update.message.reply_text('Hello! Thanks for chatting with me! I am a banana!')
async def error(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
print(f'Update {update} caused error {context.error}')
# # very cool title bar
# root.overrideredirect(True) # Remove the title bar
# # Create a frame for a custom title bar
# title_bar = tk.Frame(root, bg="blue", height=30, relief="raised", bd=0)
# title_bar.pack(fill="x")
# # Create a custom font for title text
# title_font = ("Helvetica", 14)
# # Set the width and height of the button
# button_width = 15
# button_height = 3
# # Choose a brighter green color
# button_color = "lime"
# # Create a button with the custom font, width, height, and color
# button = tk.Button(title_bar, text="Click me!", command=on_button_click, font=title_font, width=button_width, height=button_height, bg=button_color)
# button.pack(side="left", padx=10)
# # Close button
# close_button = tk.Button(title_bar, text="X", command=root.destroy, font=title_font, width=2, height=1, bg="red", relief="flat")
# close_button.pack(side="right", padx=10)
# # Make the window draggable
# def start_drag(event):
# root.x = event.x
# root.y = event.y
# def drag(event):
# deltax = event.x - root.x
# deltay = event.y - root.y
# x = root.winfo_x() + deltax
# y = root.winfo_y() + deltay
# root.geometry(f"+{x}+{y}")
# title_bar.bind("<ButtonPress-1>", start_drag)
# title_bar.bind("<B1-Motion>", drag)
def setup_tab(self):
self.notebook = ttk.Notebook(self.root)
# Create tabs (frames) to be added to the Notebook
self.tab1 = ttk.Frame(self.notebook)
self.tab2 = ttk.Frame(self.notebook)
self.tab3 = ttk.Frame(self.notebook)
self.tab4 = ttk.Frame(self.notebook)
self.tab5 = ttk.Frame(self.notebook)
self.tab6 = ttk.Frame(self.notebook)
# Add tabs to the Notebook
self.notebook.add(self.tab1, text="Rotation")
self.notebook.add(self.tab2, text="Tab 2")
self.notebook.add(self.tab3, text="Tab 3")
self.notebook.add(self.tab4, text="Telegram")
self.notebook.add(self.tab5, text="Tab 5")
self.notebook.add(self.tab6, text="Settings")
# Bind the tab change event
self.notebook.bind("<<NotebookTabChanged>>", self.on_tab_change)
# Pack the Notebook widget
self.notebook.pack(expand=1, fill="both")
# Add content to each tab
label1 = tk.Label(self.tab1, text="Rectangular Rotation Method")
label1.pack(padx=10, pady=10)
label2 = tk.Label(self.tab2, text="Script Recording Method (Coming Soon .. )")
label2.pack(padx=10, pady=10)
label3 = tk.Label(self.tab3, text="Custom Map Rotation Design Method (Coming Soon ..)")
label3.pack(padx=10, pady=10)
label4 = tk.Label(self.tab4, text="Telegram Setup")
label4.pack(padx=10, pady=10)
label5 = tk.Label(self.tab5, text="Autoclicker (Monster Life)")
label5.pack(padx=10, pady=10)
label6 = tk.Label(self.tab6, text="Settings")
label6.pack(padx=10, pady=10)
def setup_tab1(self):
self.button = tk.Button(self.tab1, text="Resume", command=self.resumebutton, width=20, height=5, bg='tomato', font=('Helvetica', 16))
self.button.pack(pady=(10,20))
frame = tk.Frame(self.tab1, bg='', bd=0)
# frame = tk.Frame(root, bg='#ffbb29')
frame.pack(padx=0, pady=0)
# # label1 = tk.Label(frame, text="x:", fg="black", bg='#ffbb29')
# # label1.grid(row=0, column=0, padx=(5,0), pady=0, sticky=tk.E)
# entry1 = tk.Entry(frame, width=10, fg='Gray')