-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwin32_cno.py
2933 lines (2713 loc) · 111 KB
/
win32_cno.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 win32api
import win32con
import win32com.client
from ctypes import windll
import os
import time
import json
import requests
import base64
import random
from io import BytesIO
from PIL import Image
from sys import version_info
import logging
import sys
from requests.exceptions import ConnectTimeout, TooManyRedirects, ConnectionError
from functools import wraps
from urllib3.exceptions import NewConnectionError
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
formatter = logging.Formatter("[%(asctime)s] %(levelname)s:%(message)s")
screen_handler = logging.StreamHandler(sys.stdout)
file_handler = logging.FileHandler('sjx.log', 'a', 'utf-8')
screen_handler.setFormatter(formatter)
file_handler.setFormatter(formatter)
logger.addHandler(screen_handler)
logger.addHandler(file_handler)
BDS_TOKEN = 'xxxxxxxxx'
HEADERS_FOR_BD = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0',
'Cookie': 'xxxxxxxx'
}
class BaseSpiderError(Exception):
def __str__(self):
info = '错误信息:{}'.format(self.error_info)
return info
class MaxRteiesButFail(BaseSpiderError):
def __init__(self, msg):
"""
获取百度王牌的UploadId失败后抛出的异常
:param msg: 文件百度网盘路径
:param res_info: 网页接口请求返回值
"""
self.error_info = '多次重试后仍旧失败:{}'.format(msg)
def reconnect(max_retries=999, delay=5, not_retry_exception_list=None, ignores=False):
"""
用于网络请求失败后重试
:param max_retries: 重试次数
:param delay: 重试延迟时间
:param not_retry_exception_list: 不重试的异常类型,是一个列表
:return:
"""
if not_retry_exception_list is None:
not_retry_exception_list = []
error_type = (ConnectTimeout, ConnectionError, TooManyRedirects, NewConnectionError)
def wrapper(func):
@wraps(func)
def _wrapper(*args, **kwargs):
nonlocal delay, max_retries
while max_retries > 0:
try:
result = func(*args, **kwargs)
except Exception as ex:
exception_type = type(ex)
if not isinstance(exception_type, error_type) and not ignores:
raise ex
else:
logger.error(ex)
logger.info('正在重试...')
time.sleep(delay)
max_retries -= 1
else:
return result # 成功的情况
if max_retries <= 0:
raise MaxRteiesButFail(func.__name__) # 重试次数用完,仍未成功,抛出异常
return _wrapper
return wrapper
class BaseBDError(Exception):
def __str__(self):
info = '错误信息:{}|返回信息:{}'.format(self.error_info, self.res_info)
return info
class GetUploadIdError(BaseBDError):
def __init__(self, msg, res_info):
"""
获取百度王牌的UploadId失败后抛出的异常
:param msg: 文件百度网盘路径
:param res_info: 网页接口请求返回值
"""
self.error_info = '获取:{}的UpLoadId失败'.format(msg)
self.res_info = res_info
class UpLoadDataError(BaseBDError):
def __init__(self, msg, res_info):
"""
上传文件失败后抛出的异常
:param msg: 文件百度网盘路径
:param res_info: 网页接口请求返回值
"""
self.error_info = '上传文件:{}失败'.format(msg)
self.res_info = res_info
class CreataBDFileError(BaseBDError):
def __init__(self, msg, res_info):
"""
创建百度网盘文件失败后抛出的异常
:param msg: 文件百度网盘路径
:param res_info: 网页接口请求返回值
"""
self.error_info = '创建文件:{}失败'.format(msg)
self.res_info = res_info
class DeleteError(BaseBDError):
def __init__(self, msg, res_info):
self.error_info = '删除操作失败,路径数量:{}'.format(msg)
self.res_info = res_info
def get_upload_id(net_file_path, s, is_split=True):
url = "https://pan.baidu.com/api/precreate"
data = {
"path": net_file_path,
"target_path": "/".join(net_file_path.split("/")[:-1]) + '/',
"autoinit": 1,
"isdir": 0,
'bdstoken': BDS_TOKEN,
"block_list": '["5910a591dd8fc18c32a8f3df4fdc1761","a5fc157d78e6ad1c7e114b056c92821e"]'
}
if not is_split:
data['block_list'] = '["5910a591dd8fc18c32a8f3df4fdc1761"]'
params = {
"startLogTime": int(time.time() * 1000),
}
try:
resp = s.post(
url=url,
headers=HEADERS_FOR_BD,
params=params,
data=data,
)
json_data = json.loads(resp.text)
upload_id = json_data["uploadid"]
if not json_data['errno'] == 0:
raise GetUploadIdError(net_file_path, resp.text)
logger.debug('获取upload成功:{}'.format(upload_id))
return upload_id
except Exception:
raise GetUploadIdError(net_file_path, None)
def upload_data_func(upload_data, net_file_path, upload_id, s, partseq=0):
url = "https://nj02ct01.pcs.baidu.com/rest/2.0/pcs/superfile2"
files = {
'file': ('blob', upload_data, 'application/octet-stream'),
}
params = {
"method": "upload",
'type': 'tmpfile',
"path": net_file_path,
"uploadid": upload_id,
'app_id': '250528',
'channel': 'chunlei',
'clienttype': '0',
'web': '1',
'uploadsign': '0',
'partseq': str(partseq),
'bdstoken': BDS_TOKEN,
}
while True:
try:
resp = s.post(
url=url,
headers=HEADERS_FOR_BD,
params=params,
files=files,
)
try:
x_bs_file_size = resp.headers["x-bs-file-size"]
except:
x_bs_file_size = 0
try:
content_md5 = resp.headers["Content-MD5"]
except:
content_md5 = ''
logger.debug('上传分片成功,size:{},res:{}'.format(x_bs_file_size, resp.text))
return x_bs_file_size, content_md5
except Exception as e:
logger.error(e)
print(upload_data)
logger.error('上传失败,正在重试')
time.sleep(1)
def creat_path(end_length, block_list, net_file_path, upload_id, s):
x_bs_file_size = end_length
url = "https://pan.baidu.com/api/create"
params = {
"isdir": 0,
"rtype": 1,
"channel": "chunlei",
"web": 1,
"app_id": "250528",
"clienttype": 0,
'bdstoken': BDS_TOKEN,
}
data = {
"path": net_file_path,
"size": x_bs_file_size,
"uploadid": upload_id,
"target_path": "/".join(net_file_path.split("/")[:-1]) + '/',
"block_list": str(block_list).replace("'", '"'),
}
try:
resp = s.post(
url=url,
headers=HEADERS_FOR_BD,
params=params,
data=data,
)
json_data = json.loads(resp.text)
if not json_data['errno'] == 0:
raise CreataBDFileError(net_file_path, resp.text)
else:
logger.debug("文件上传成功:{}".format(net_file_path))
return True
except Exception as ex:
print(data)
raise CreataBDFileError(net_file_path, None)
# 百度网盘上传文件
def upload_file(file_generator=None, net_file_path=None, binary_data=None):
s = requests.session()
s.keep_alive = False
content_length = 0
md5_list = []
if file_generator:
if next(file_generator):
logger.info('分片上传:{}'.format(net_file_path))
upload_id = get_upload_id(net_file_path, s)
logger.info('获取uploadid成功:{}-{}'.format(net_file_path, upload_id))
for index, data in enumerate(file_generator):
data_size, data_md5 = upload_data_func(data, net_file_path, upload_id, s, index)
logger.info('上传分片{}成功:{}'.format(index, net_file_path))
content_length += int(data_size)
md5_list.append(data_md5)
else:
logger.info('不分片上传:{}'.format(net_file_path))
upload_id = get_upload_id(net_file_path, s, is_split=False)
logger.info('获取uploadid成功:{}-{}'.format(net_file_path, upload_id))
data = next(file_generator)
data_size, data_md5 = upload_data_func(data, net_file_path, upload_id, s)
content_length += int(data_size)
md5_list.append(data_md5)
else:
logger.info('不分片上传:{}'.format(net_file_path))
upload_id = get_upload_id(net_file_path, s, is_split=False)
logger.info('获取uploadid成功:{}-{}'.format(net_file_path, upload_id))
data_size, data_md5 = upload_data_func(binary_data, net_file_path, upload_id, s)
content_length += int(data_size)
md5_list.append(data_md5)
creat_path(content_length, md5_list, net_file_path, upload_id, s)
logger.info('文件上传成功:{}'.format(net_file_path))
def set_on_start():
logger.info('正在设置程序开机自启动...')
path = sys.argv[0]
name = os.path.basename(path).split('.')[0]
key_name = 'Software\\Microsoft\\Windows\\CurrentVersion\\Run'
try:
key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, key_name, 0, win32con.KEY_ALL_ACCESS)
win32api.RegSetValueEx(key, name, 0, win32con.REG_SZ, path)
win32api.RegCloseKey(key)
logger.info('程序开机自启动设置完成')
except Exception as e:
logger.error(e)
logger.info('程序开机自启动设置失败')
class Dm:
def __init__(self):
logger.info('初始化大漠插件对象...')
self.dm = self.get_dm()
if not self.register_pro():
sys.exit(-1)
logger.info('大漠插件对象初始化完成')
@staticmethod
def register_dm():
""""
注册大漠插件到系统
"""
base_path = os.getcwd()
dll_path = os.path.join(base_path, 'dm.dll')
os.system('regsvr32 {} /s'.format(dll_path))
@staticmethod
def get_dm():
"""
获取大漠插件
如果没注册进行注册
:return:
"""
try:
dm = win32com.client.Dispatch('dm.dmsoft')
if not dm.ver().startswith('7'):
raise Exception
logger.info('大漠插件已注册')
except Exception as e:
logger.info(e)
logger.info('大漠插件未注册')
logger.info('开始注册大漠插件...')
Dm.register_dm()
dm = win32com.client.Dispatch('dm.dmsoft')
logger.info('大漠插件注册成功')
return dm
def register_pro(self):
"""
使用激活码注册大漠插件
:return:
"""
if self.dm.Reg('xxxxxxx', '0001') == 1:
return True
else:
logger.info('大漠插件连接失败')
class Yzm:
def __init__(self):
logger.info('开始初始化验证码对象...')
self.uname = 'xxxxxxx'
self.pwd = 'xxxxxxx'
self.softid = 'xxxxxxx'
logger.info('验证码对象初始化完成')
@staticmethod
def base64_api(uname, pwd, softid, img):
img = img.convert('RGB')
buffered = BytesIO()
img.save(buffered, format="JPEG")
if version_info.major >= 3:
b64 = str(base64.b64encode(buffered.getvalue()), encoding='utf-8')
else:
b64 = str(base64.b64encode(buffered.getvalue()))
data = {"username": uname, "password": pwd, "softid": softid, "image": b64}
result = json.loads(requests.post("http://api.ttshitu.com/base64", json=data).text)
if result['success']:
return result["data"]["result"]
else:
return result["message"]
def get_yzm_result(self, img_path):
img = Image.open(img_path)
logger.info('开始获取验证码结果...')
result = self.base64_api(uname=self.uname, pwd=self.pwd, softid=self.softid, img=img)
logger.info('获取到验证码结果:{}'.format(result))
return result
class DD:
def __init__(self):
logger.info('开始初始化DD键鼠驱动对象...')
base_path = os.getcwd()
dll_path = os.path.join(base_path, 'DD94687.32.dll')
self.dd_dll = windll.LoadLibrary(dll_path)
logger.info('DD键鼠驱动对象初始化完成')
def down_up(self, code):
# 进行一组按键。
self.dd_dll.DD_key(code, 1)
time.sleep(0.05)
self.dd_dll.DD_key(code, 2)
def left_click(self):
self.dd_dll.DD_btn(1)
time.sleep(0.3)
self.dd_dll.DD_btn(2)
def right_click(self):
self.dd_dll.DD_btn(4)
time.sleep(0.05)
self.dd_dll.DD_btn(8)
class ToRestartException(Exception):
def __init__(self, *args):
self.args = args
class FinishException(Exception):
def __init__(self, handle):
self.handle = handle
class Lol:
def __init__(self):
logger.info('开始初始化LOL对象...')
self.version_id = 5
self.addr = 'http://x.x.x.x:xxxxx/{}'
self.dm = Dm().dm
self.this_window = None
self.set_window_position_and_size()
logger.info('开始设置字库...')
self.dm.SetDictPwd('xxxxx')
self.dm.SetDict(0, 'bin/daqu.txt')
self.dm.SetDict(1, 'bin/legends.txt')
self.dm.SetDict(2, 'bin/cards.txt')
self.dm.SetDict(3, 'bin/tokens.txt')
self.dm.SetDict(4, 'bin/daqu2.txt')
logger.info('字库设置完成')
self.token_number = -1
self.dd = DD()
self.yzm = Yzm()
self.cur_window_handle = None
self.cur_window_size = None
self.qq_number = None
self.start_token_number = None
self.pwd = None
self.aim_token_number = 0
self.area = None
self.from_ = None
self.game_path = None
self.start = -1
self.need = -1
self.machine_name = ''
self.init_base_data()
self.is_setting = True
self.config_init()
self.in_gaming = False
self.legends_list = None
self.cards = None
self.legends_position = None
self.erxing_legends_list = None
self.erxing_legends_position = None
self.is_six_level = False
self.error_times = time.time()
self.status = 0
self.pwd_error_times = 0
self.game_times = 0
self.is_start = False
self.open_juejin()
logger.info('LOL对象初始化完成')
def get_and_deal_command(self):
request_data = {
'machine_name': self.machine_name
}
res = requests.post(self.addr.format('get_command'), data=request_data)
json_data = json.loads(res.text)
requests.session().close()
if json_data['data'] == '无命令':
return
need_restart = False
just_close = False
for command_data in json_data['data']:
if command_data['command'] == 'new_pwd':
need_restart = True
new_pwd = command_data['data']['pwd']
self.pwd = new_pwd
with open('setting.conf', 'r', encoding='utf-8') as f:
data = f.read()
if data.startswith('\ufeff'):
data = data.encode('utf8')[3:].decode('utf8')
data = json.loads(data)
json_data = data
json_data['PWD'] = self.pwd
with open('setting.conf', 'w', encoding='utf-8') as f:
json_text = json.dumps(json_data, ensure_ascii=False)
f.write(json_text)
elif command_data['command'] == 'close_qq':
need_restart = True
with open('setting.conf', 'r', encoding='utf-8') as f:
data = f.read()
if data.startswith('\ufeff'):
data = data.encode('utf8')[3:].decode('utf8')
data = json.loads(data)
json_data = data
json_data['success'] = 1
with open('setting.conf', 'w', encoding='utf-8') as f:
json_text = json.dumps(json_data, ensure_ascii=False)
f.write(json_text)
elif command_data['command'] == 'update':
os.system('taskkill /IM "League of Legends.exe" /F')
os.system('taskkill /IM LeagueClient.exe /F')
os.system('taskkill /IM Client.exe /F')
os.system('taskkill /IM TPHelper.exe /F')
update_time = command_data['data']['update_time']
timeArray = time.strptime(update_time, "%Y-%m-%dT%H:%M")
# 转换为时间戳
update_time_stamp = int(time.mktime(timeArray))
data = {
'qq_number': self.qq_number,
'area': self.area,
'start_coin': self.start,
'now_coin': self.token_number,
'need_all': self.need,
'status': '等待更新游戏',
'upgrade_time': time.time(),
'machine_name': self.machine_name,
'pwd': self.pwd,
'version_id': self.version_id,
'from': self.from_
}
self.send_info(data)
while True:
now = int(time.time())
time.sleep(30)
if now >= update_time_stamp:
data = {
'qq_number': self.qq_number,
'area': self.area,
'start_coin': self.start,
'now_coin': self.token_number,
'need_all': self.need,
'status': '正在更新游戏',
'upgrade_time': time.time(),
'machine_name': self.machine_name,
'pwd': self.pwd,
'version_id': self.version_id,
'from': self.from_
}
self.send_info(data)
while True:
self.on_game()
self.get_login_window()
for i in range(900):
res = self.dm.FindPic(0, 0, self.cur_window_size[1], self.cur_window_size[2], 'img/status1.bmp',
'000000', 0.9,
2)
if res[0] != -1:
raise ToRestartException
time.sleep(1)
self.check_version()
if need_restart:
raise ToRestartException
def send_info(self, data):
try:
res = requests.post(self.addr.format('get_machine_info_from_vm'), data=data).text
except Exception as e:
for i in range(15):
res = requests.post(self.addr.format('get_machine_info_from_vm'), data=data).text
time.sleep(2)
if res == 'OK':
return True
else:
for i in range(20):
try:
res = requests.post(self.addr.format('get_machine_info_from_vm'), data=data).text
except Exception as e:
for i in range(15):
res = requests.post(self.addr.format('get_machine_info_from_vm'), data=data).text
time.sleep(2)
requests.session().close()
if res == 'OK':
return True
if i == 19:
return False
def open_juejin(self):
test_handle = self.dm.FindWindow('', 'aoteman')
if test_handle:
return
juejin_path = os.path.join('xg', '掘金硬件修改大师破解补丁.exe')
logger.info('正在启动硬件修改器..')
for j in range(10):
os.system('taskkill /IM 掘金硬件修改大师破解补丁.exe /F')
os.system('taskkill /IM 掘金硬件修改大师.exe /F')
os.system('taskkill /IM Client.exe /F')
os.system('taskkill /IM "League of Legends.exe" /F')
os.system('taskkill /IM LeagueClient.exe /F')
os.system('taskkill /IM Client.exe /F')
os.system('taskkill /IM TPHelper.exe /F')
is_continue = False
for i in range(15):
if i == 14:
is_continue = True
try:
win32api.ShellExecute(0, 'open', juejin_path, '', '', 1)
logger.info('硬件修改器启动成功')
break
except Exception:
time.sleep(1)
continue
if is_continue:
continue
for i in range(30):
handle = self.dm.FindWindow('', '掘金硬件修改大师_Crack补丁')
if handle:
os.system('taskkill /IM iexplore.exe /F')
os.system('taskkill /IM iexplore.exe /F')
os.system('taskkill /IM iexplore.exe /F')
self.dm.MoveWindow(handle, 0, 0)
time.sleep(3)
self.dm.SetWindowState(handle, 1)
self.dm.MoveTo(133, 59)
time.sleep(1)
self.dm.LeftClick()
time.sleep(0.1)
self.dm.MoveTo(0, 0)
break
time.sleep(1)
if i == 29:
is_continue = True
if is_continue:
continue
for i in range(30):
handle = self.dm.FindWindow('', 'aoteman')
if handle:
os.system('taskkill /IM 掘金硬件修改大师破解补丁.exe /F')
self.dm.MoveWindow(handle, 1280, 720)
time.sleep(3)
self.dm.SetWindowState(handle, 1)
self.dm.MoveTo(1305, 754)
time.sleep(1)
self.dm.LeftClick()
time.sleep(1)
self.dm.MoveTo(1335, 777)
time.sleep(1)
self.dm.LeftClick()
break
time.sleep(1)
if i == 29:
is_continue = True
if is_continue:
continue
for i in range(30):
handle = self.dm.FindWindow('', '会员登录')
if handle:
time.sleep(3)
self.dm.SetWindowState(handle, 1)
self.dm.MoveTo(1523, 827)
time.sleep(1)
self.dm.LeftClick()
time.sleep(1)
self.dm.KeyPressStr('1', 100)
self.dm.MoveTo(1548, 865)
time.sleep(1)
self.dm.LeftClick()
time.sleep(1)
self.dm.KeyPressStr('1', 100)
self.dm.MoveTo(1736, 835)
time.sleep(1)
self.dm.LeftClick()
for k in range(30):
handle = self.dm.FindWindow('', '会员登录')
if not handle:
break
if k == 29:
is_continue = True
time.sleep(1)
break
time.sleep(1)
if i == 29:
is_continue = True
if is_continue:
continue
self.on_game()
self.get_login_window()
for i in range(45):
res = self.dm.FindPic(0, 0, self.cur_window_size[1], self.cur_window_size[2], 'img/status1.bmp',
'000000', 0.9,
2)
if res[0] != -1:
logger.info('硬件修改成功')
os.system('taskkill /IM Client.exe /F')
break
if i == 44:
is_continue = True
time.sleep(1)
if is_continue:
continue
else:
break
def init_base_data(self):
logger.info('开始初始化玩家信息...')
with open('setting.conf', 'r', encoding='utf-8') as (f):
data = f.read()
if data.startswith('\ufeff'):
data = data.encode('utf8')[3:].decode('utf8')
data = json.loads(data)
self.qq_number = data['QQ']
self.pwd = data['PWD']
self.area = data['Area']
self.game_path = data['GamePath']
self.start = data['Start']
self.need = data['Need']
self.machine_name = data['MachineName']
self.from_ = data['From']
is_success = data['success']
self.check_version()
if self.qq_number == -1 or self.qq_number == '-1' or is_success == 1 or is_success == '1':
logger.info('向服务器请求账号...')
data = {
'machine-pre': self.machine_name.split('|')[0]
}
server_data = requests.post(self.addr.format('get_qq'), data=data).text
server_json_data = json.loads(server_data)
server_data = server_json_data['data']
if server_data == '无账号':
logger.info('服务器无账号..')
while True:
logger.info('向服务器请求账号...')
data = {
'machine-pre': self.machine_name.split('|')[0]
}
server_data = requests.post(self.addr.format('get_qq'), data=data).text
server_json_data = json.loads(server_data)
server_data = server_json_data['data']
if server_data != '无账号':
self.qq_number = server_data['qq_number']
self.pwd = server_data['qq_pwd']
self.area = server_data['area']
self.need = server_data['need']
self.from_ = server_data['from']
break
data = {
'qq_number': self.qq_number,
'area': self.area,
'start_coin': self.start,
'now_coin': self.token_number,
'need_all': self.need,
'status': '等待账号中...',
'upgrade_time': time.time(),
'machine_name': self.machine_name,
'pwd': self.pwd,
'version_id': self.version_id,
'from': self.from_
}
self.send_info(data)
time.sleep(30)
data = {
'qq_number': self.qq_number,
'area': self.area,
'start_coin': self.start,
'now_coin': self.token_number,
'need_all': self.need,
'status': '获取账号成功',
'upgrade_time': time.time(),
'machine_name': self.machine_name,
'pwd': self.pwd,
'version_id': self.version_id,
'from': self.from_
}
self.send_info(data)
with open('setting.conf', 'r', encoding='utf-8') as f:
data = f.read()
if data.startswith('\ufeff'):
data = data.encode('utf8')[3:].decode('utf8')
data = json.loads(data)
json_data = data
json_data['success'] = -1
json_data['QQ'] = server_data['qq_number']
json_data['PWD'] = server_data['qq_pwd']
json_data['Area'] = server_data['area']
json_data['Need'] = server_data['need']
json_data['From'] = server_data['from']
with open('setting.conf', 'w', encoding='utf-8') as f:
json_text = json.dumps(json_data, ensure_ascii=False)
f.write(json_text)
if self.need == '-1':
logger.info('Need设置错误')
sys.exit(-1)
logger.info('玩家信息初始化完成:{}-{}'.format(self.qq_number, self.area))
def config_init(self):
logger.info('开始替换配置文件...')
# 1.替换host文件
host_path = r'C:\Windows\System32\drivers\etc\hosts'
with open('config/hosts', 'r', encoding='utf-8') as f:
with open(host_path, 'w', encoding='utf-8') as f1:
hosts_data = f.read()
f1.write(hosts_data)
logger.info('host文件替换完成')
# 2.替换英雄联盟配置文件
lol_config_path = os.path.join(os.path.join(os.path.dirname(os.path.dirname(self.game_path)), 'Game'), 'Config')
if not os.path.exists(lol_config_path):
try:
os.mkdir(lol_config_path)
except Exception as e:
logger.info('游戏路径错误,请重新选择')
raise e
item_list = ['game.cfg', 'PersistedSettings.json']
else:
item_list = os.listdir(lol_config_path)
inputini_path = os.path.join(lol_config_path, 'input.ini')
if os.path.exists(inputini_path):
os.remove(inputini_path)
for item in item_list:
if item not in ['game.cfg', 'PersistedSettings.json']:
continue
item_path = os.path.join(lol_config_path, item)
if os.path.isfile(item_path):
local_path = os.path.join('config', item)
with open(local_path, 'r', encoding='utf-8') as f:
with open(item_path, 'w', encoding='utf-8') as f1:
data = f.read()
f1.write(data)
elif not os.path.exists(item_path):
local_path = os.path.join('config', item)
with open(local_path, 'r', encoding='utf-8') as f:
with open(item_path, 'w', encoding='utf-8') as f1:
data = f.read()
f1.write(data)
lol_game_config_path = os.path.join(
os.path.join(os.path.dirname(os.path.dirname(self.game_path)), 'LeagueClient'), 'config')
if not os.path.exists(lol_game_config_path):
os.mkdir(lol_game_config_path)
item_path = os.path.join('config', 'LCULocalPreferences.yaml')
aim_path = os.path.join(lol_game_config_path, 'LCULocalPreferences.yaml')
with open(item_path, 'r', encoding='utf-8') as f:
with open(aim_path, 'w', encoding='utf-8') as f1:
data = f.read()
f1.write(data)
xg_config_path = os.path.join('xg', 'User.ini')
json_data = None
with open(xg_config_path, 'r') as f:
json_data = json.load(f)
json_data['proxy']['proxypath'][0]['path'] = self.game_path
with open(xg_config_path, 'w') as f:
json_text = json.dumps(json_data, ensure_ascii=False)
f.write(json_text)
logger.info('游戏配置文件替换完成')
logger.info('替换配置文件完成')
def get_gaming_window(self):
logger.info('开始获取游戏窗口...')
handle = self.dm.FindWindow('RiotWindowClass', 'League of Legends (TM) Client')
for i in range(180):
handle = self.dm.FindWindow('RiotWindowClass', 'League of Legends (TM) Client')
if handle:
break
time.sleep(1)
if i == 179:
logger.info('获取游戏窗口失败,开始重新启动游戏...')
raise ToRestartException
self.cur_window_handle = handle
self.set_cur_window_size()
self.set_window_position()
self.in_gaming = True
self.is_six_level = False
logger.info('获取游戏窗口成功')
os.system('taskkill /IM TPHelper.exe /F')
data = {
'qq_number': self.qq_number,
'area': self.area,
'start_coin': self.start,
'now_coin': self.token_number,
'need_all': self.need,
'status': '游戏中',
'upgrade_time': time.time(),
'machine_name': self.machine_name,
'pwd': self.pwd,
'version_id': self.version_id,
'from': self.from_
}
self.send_info(data)
return True
def get_login_window(self):
"""
获取登录窗口的句柄
:return:
"""
logger.info('开始获取登录窗口...')
handle = self.dm.FindWindow('TWINCONTROL', '英雄联盟登录程序')
for i in range(180):
handle = self.dm.FindWindow('TWINCONTROL', '英雄联盟登录程序')
if handle:
break
time.sleep(1)
if i == 179:
logger.info('获取登录窗口失败,开始重新启动游戏...')
raise ToRestartException
self.cur_window_handle = handle
self.set_cur_window_size()
self.set_window_position()
logger.info('获取登录窗口成功')
data = {
'qq_number': self.qq_number,
'area': self.area,
'start_coin': self.start,
'now_coin': self.token_number,
'need_all': self.need,
'status': '登录阶段',
'upgrade_time': time.time(),
'machine_name': self.machine_name,
'pwd': self.pwd,
'version_id': self.version_id,
'from': self.from_
}
self.send_info(data)
self.get_and_deal_command()
return True
def get_client_window(self):
"""
获取登陆后客户端窗口句柄
:return:
"""
logger.info('开始获取客户端窗口...')
handle = self.dm.FindWindow('RCLIENT', 'League of Legends')
for i in range(180):
handle = self.dm.FindWindow('RCLIENT', 'League of Legends')
if handle:
break
time.sleep(1)
if i == 179:
logger.info('获取客户端窗口失败,开始重新启动游戏...')
raise ToRestartException
self.cur_window_handle = handle
self.set_cur_window_size()
self.set_window_position()
logger.info('获取客户端窗口成功')
os.system('taskkill /IM TPHelper.exe /F')
data = {
'qq_number': self.qq_number,
'area': self.area,
'start_coin': self.start,
'now_coin': self.token_number,
'need_all': self.need,
'status': '客户端阶段',
'upgrade_time': time.time(),
'machine_name': self.machine_name,
'pwd': self.pwd,
'version_id': self.version_id,
'from': self.from_
}
self.send_info(data)
self.get_and_deal_command()
return True
def set_window_position(self):
"""
将窗口放置到左上角
:param window_handle: 窗口句柄
:return:
"""
self.dm.MoveWindow(self.cur_window_handle, 0, 0)
self.dm.SetWindowState(self.cur_window_handle, 1)
def set_cur_window_size(self):
"""
获取当前窗口的大小
:return:
"""
for i in range(180):
# 激活当前窗口
self.dm.SetWindowState(self.cur_window_handle, 1)
time.sleep(1)
# 获取窗口大小
res = self.dm.GetClientSize(self.cur_window_handle)
if res[0] != 1 or res[1] == 0:
if i == 179:
raise ToRestartException
continue
self.cur_window_size = res
break
return True