forked from GrayTempest-400/warthunder-cv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
184 lines (157 loc) · 5.01 KB
/
utils.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
import ctypes
import os
import time
import pyautogui
import win32con
import win32gui
from loguru import logger
import dearpygui.dearpygui as dpg
from find import locate
logger.remove(handler_id=None)
logger.add("wtauto_{time:YYYY-MM-DD}.log", format='{time:YYYY-MM-DD HH:mm} {level} {message}', rotation='3 days',
encoding='UTF-8')
def active(): # 窗口置顶
global hwnd
hwnd = win32gui.FindWindow('DagorWClass', None)
win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
win32gui.SetWindowPos(hwnd, win32con.HWND_TOP, 0, 0, 0, 0, win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
win32gui.SetForegroundWindow(hwnd)
def click(p): # 第二种
hwnd = win32gui.FindWindow('DagorWClass', None)
win32gui.SetForegroundWindow(hwnd)
x = p[0]
y = p[1]
ctypes.windll.user32.SetCursorPos(x, y)
time.sleep(0.05)
ctypes.windll.user32.mouse_event(2, 0, 0, 0, 0)
time.sleep(0.01)
ctypes.windll.user32.mouse_event(4, 0, 0, 0, 0)
time.sleep(0.1)
pyautogui.moveTo(x=20, y=300)
def checklog(param):
out = param + '\n'
with open('pic/check/check.ini', 'r+') as check:
check.seek(0, 2)
check.write(out)
def logger_log(param):
try:
logger.info(param)
checklog(param)
print(param)
except:
logger.exception("日志异常")
def coun(name): # 读取本地有没有country文件,判断选择哪个国家
c = os.path.exists('pic/config/country.txt')
if c is True:
with open('pic/config/country.txt', 'w+') as country:
country.seek(0, 0)
co = country.readlines()
if co == name:
return co
else:
country.truncate(0)
country.write(name)
co = country.readlines()
return co
else:
with open('pic/config/country.txt', 'w+') as country:
country.seek(0, 0)
country.write(name)
co = country.readlines()
return co
def us():
coun('us')
dpg.delete_item(item='modal_id')
logger_log('选择美国')
def ger():
coun('ger')
dpg.delete_item(item='modal_id')
logger_log('选择德国')
def ussr():
coun('ussr')
dpg.delete_item(item='modal_id')
logger_log('选择苏联')
def uk():
coun('uk')
dpg.delete_item(item='modal_id')
logger_log('选择英国')
def jp():
coun('jp')
dpg.delete_item(item='modal_id')
logger_log('选择日本')
def it():
coun('it')
dpg.delete_item(item='modal_id')
logger_log('选择意呆')
def selectrun(): # 判断运行哪一个版本游戏
st = os.path.exists('pic/config/steam.d')
gj = os.path.exists('pic/config/gaijin.d')
if st is True:
logger_log('运行steam版')
return 1
elif gj is True:
logger_log('运行Gaijin版')
return 2
def selet_c(): # 选择国家
hwnd = win32gui.FindWindow('DagorWClass', None)
if not hwnd == 0:
se = os.path.exists('pic/config/country.txt')
print(se)
if se is True:
with open('pic/config/country.txt', 'r') as country:
co = country.readline()
print(co)
if co == 'us':
c = locate('pic/country/usa.png', 0.8)
time.sleep(0.5)
click(c)
time.sleep(1)
s = locate('pic/luncher/hang.png', 0.8)
click(s)
logger_log('选择完毕')
elif co == 'ger':
c = locate('pic/country/ger.png', 0.8)
time.sleep(0.5)
click(c)
time.sleep(1)
s = locate('pic/luncher/hang.png', 0.8)
click(s)
logger_log('选择完毕')
elif co == 'ussr':
c = locate('pic/country/ussr.png', 0.8)
time.sleep(0.5)
click(c)
time.sleep(1)
s = locate('pic/luncher/hang.png', 0.8)
click(s)
logger_log('选择完毕')
elif co == 'uk':
c = locate('pic/country/uk.png', 0.8)
time.sleep(0.5)
click(c)
time.sleep(1)
s = locate('pic/luncher/hang.png', 0.8)
click(s)
logger_log('选择完毕')
elif co == 'jp':
c = locate('pic/country/jp.png', 0.8)
time.sleep(0.5)
click(c)
time.sleep(1)
s = locate('pic/luncher/hang.png', 0.8)
click(s)
logger_log('选择完毕')
elif co == 'it':
c = locate('pic/country/it.png', 0.8)
time.sleep(0.5)
click(c)
time.sleep(1)
s = locate('pic/luncher/hang.png', 0.8)
click(s)
logger_log('选择完毕')
else:
a = False
return a
else:
a = False
return a