-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.cpp
More file actions
226 lines (196 loc) · 6.55 KB
/
basic.cpp
File metadata and controls
226 lines (196 loc) · 6.55 KB
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
#include <basic.hpp>
namespace flag {
FLAG::FLAG(uint16 child, uint16 parent, string note) {
id = child | parent << 16;
text = std::move(note);
}
void Controller::pop() {
#if FLAG_UPDATE_LOG_FULL_SHOW
stringstream t;
layer.pop_back();
for (FLAG *s: layer) t << "/" << s->text;
Logger.trace(fformat("返回[{1}] ({0})",
t.str().replace(t.str().find('/'), 1, ""),
layer.back()->text));
#else
Logger.trace(fformat("POP ↓ {0}", layer.back().text));
layer.pop_back();
#endif
}
void Controller::push(FLAG *newflag) {
#if FLAG_UPDATE_LOG_FULL_SHOW
stringstream t;
layer.push_back(newflag);
for (FLAG *s: layer) t << "/" << s->text;
Logger.trace(fformat("进入[{1}] ({0})",
t.str().replace(t.str().find('/'), 1, ""),
layer.back()->text));
#else
Logger.trace(fformat("PUSH ↑ {0}", newflag.text));
layer.push_back(newflag);
#endif
}
void Controller::root(FLAG *newflag) {
#if FLAG_UPDATE_LOG_FULL_SHOW
stringstream t;
layer.clear();
layer.push_back(newflag);
for (FLAG *s: layer) t << "/" << s->text;
Logger.trace(fformat("设置根({0})", t.str().replace(t.str().find('/'), 1, "")));
#else
Logger.trace(fformat("ROOT ↓ {0}", newflag.text));
layer.clear();
layer.push_back(newflag);
#endif
}
void Controller::move(FLAG *newflag) {
#if FLAG_UPDATE_LOG_FULL_SHOW
stringstream t;
layer.pop_back();
layer.push_back(newflag);
for (FLAG *s: layer) t << "/" << s->text;
Logger.trace(fformat("移动到[{1}] ({0})",
t.str().replace(t.str().find('/'), 1, ""),
layer.back()->text));
#else
Logger.trace(fformat("MOVE → {0}", newflag.text));
layer.pop_back();
layer.push_back(newflag);
#endif
}
void Controller::show() {
stringstream t;
for (FLAG *s: layer) t << "/" << s->text;
Logger.info(fformat("当前位于 ({0})", t.str().replace(t.str().find('/'), 1, "")));
}
bool Controller::isBase(uint16 base) { return (layer.back()->id >> 16) == base; }
bool Controller::isFlag(FLAG *flag) { return flag->id == layer.back()->id; }
uint32 Controller::getFlag() { return layer.back()->id; }
string Controller::getNote() { return layer.back()->text; }
}
namespace basic {
bool visible(platform::TypeMEMU mu, const vector<templ::TL> &tllist, f32 thh, uint32 timeout, uint32 holdtime) {
if (timeout == 0xFFFFFFFF || tllist.empty()) return false;
if (tllist.empty()) {
Logger.error("disappear(): 空的模板对象列表");
return false;
}
clock_type start_time = clock_now;
clock_type break_time = clock_now + chrono::milliseconds(timeout);
Logger.info(fformat("等待出现[{0}] 超时{1}ms", tllist[0].text, timeout ? string(to_string(timeout)) : "∞"));
for (const templ::TL &tl: tllist) {
while (true) {
if (timeout != 0 && timeout_ms(break_time)) {
Logger.warn(fformat("出现超时[{0}]", tl.text));
return false;
}
mu.CaptureRender();
if (!match::matchtl(mu.screen, tl, thh, MT_DISABLE_LOG).empty()) {
if (holdtime) {
sleep_ms(holdtime);
mu.CaptureRender();
if (match::matchtl(mu.screen, tl, thh, MT_DISABLE_LOG).empty()) {
Logger.info(fformat("出现保持失败[{0}]", tl.text));
return false;
}
}
Logger.trace(fformat("出现完成[{0}] {1}ms", tl.text, difftime_ms(clock_now - start_time).count()));
return true;
}
}
}
return false;
}
bool disappear(platform::TypeMEMU mu, const vector<templ::TL> &tllist, f32 thh, uint32 timeout, uint32 holdtime) {
if (timeout == 0xFFFFFFFF) return false;
if (tllist.empty()) {
Logger.error("disappear(): 空的模板对象列表");
return false;
}
clock_type start_time = clock_now;
clock_type break_time = clock_now + chrono::milliseconds(timeout);
Logger.info(fformat("等待消失[{0}] 超时{1}ms", tllist[0].text, timeout ? string(to_string(timeout)) : "∞"));
for (const templ::TL &tl: tllist) {
while (true) {
if (timeout != 0 && timeout_ms(break_time)) {
Logger.warn(fformat("消失超时[{0}]", tl.text));
return false;
}
mu.CaptureRender();
if (match::matchtl(mu.screen, tl, thh, MT_DISABLE_LOG).empty()) {
if (holdtime) {
sleep_ms(holdtime);
mu.CaptureRender();
if (!match::matchtl(mu.screen, tl, thh, MT_DISABLE_LOG).empty()) {
Logger.info(fformat("消失保持失败[{0}]", tl.text));
return false;
}
}
Logger.trace(fformat("消失完成[{0}] {1}ms", tl.text, difftime_ms(clock_now - start_time).count()));
return true;
}
}
}
return false;
}
bool click(platform::TypeMEMU mu, const vector<templ::TL> &tllist, f32 thh,
click_param param, const click_extra &visi, const click_extra &disa) {
if (param.count < 1) return false;
for (const templ::TL &tl: tllist) {
if (tl.reg & FB_NONE_BIT) continue;
mu.CaptureRender();
vec_int32 XY = match::matchtl(mu.screen, tl, thh, 0);
if (XY.size() == 2) {
for (int i = 0; i < param.count; i++) {
pt2 TP(XY[0] + tl.halfW, XY[1] + tl.halfH);
if (param.random) TP = templ::GetFBrXY(XY, tl);
mu.InputClick(TP, param.press, utime::ms);
sleep_ms(param.sleep);
}
sleep_ms(param.retdelay);
} else continue;
bool ret = true;
if (visi.enable && visi.timeout != 0xFFFFFFFF) {
if (visi.tllist.empty())
ret = visible(mu, tllist, thh, visi.timeout, visi.holdtime);
else
ret = visible(mu, visi.tllist, thh, visi.timeout, visi.holdtime);
}
if (!ret) return false;
if (disa.enable && disa.timeout != 0xFFFFFFFF) {
if (disa.tllist.empty())
ret = disappear(mu, tllist, thh, disa.timeout, disa.holdtime);
else
ret = disappear(mu, disa.tllist, thh, disa.timeout, disa.holdtime);
}
if (!ret) return false;
return true;
}
return false;
}
int32 exist(platform::TypeMEMU mu, const vector<templ::TL> &tllist, f32 thh) {
cv::Mat screen;
for (const templ::TL &tl: tllist) {
mu.CaptureRender();
vec_int32 XY = match::matchtl(mu.screen, tl, thh, MT_RET_COUNT | MT_DISABLE_LOG);
if (!XY.empty() && XY[0] >= 1) {
//Logger.trace(fformat("存在[{0}] {1}个", tl.text,XY[0]));
return XY[0];
}
}
return 0;
}
int32 notexist(platform::TypeMEMU mu, const vector<templ::TL> &tllist, f32 thh) {
cv::Mat screen;
for (const templ::TL &tl: tllist) {
mu.CaptureRender();
vec_int32 XY = match::matchtl(mu.screen, tl, thh, MT_RET_COUNT | MT_DISABLE_LOG);
if (!XY.empty() && XY[0] == 0) {
//Logger.trace(fformat("存在[{0}] {1}个", tl.text,XY[0]));
return 1;
}
}
return 0;
}
click_param ClickParamDefault;
}