-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqqRedCap.lua
347 lines (301 loc) · 9.92 KB
/
qqRedCap.lua
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
--[[
Description:
_hr_x 红包收到的 x 坐标
_hr_y 红包收到的 y 坐标
_hr_c 红包收到的 rgb 颜色
_cs 颜色相似度
--]]
local g_version = 'v1.0.03'
local g_degree = 99;
local g_screenWidth, g_screenHeight;
local g_rectLeft, g_rectRight, g_rectTop, g_rectBottom;
local g_rectWidth, g_rectHeight;
local g_clWordInputX, g_clWordInputY, g_clWordInputColor;
local g_clRedCloseX, g_clRedCloseY;
local g_clTabelRedCloseValid;
local g_clickDelay;
local TIMEOUT_CLOSE, TIMEOUT_OPEN = 5, 20; -- 1s, 4s
local g_timeout, g_closeTimeout = 0, 0;
function appInit()
local sz = require("sz");
local json = sz.json;
local jsonStr;
local ret1, ret2, ret3;
g_screenWidth, g_screenHeight = getScreenSize()
if (g_screenWidth + g_screenHeight) == (640 + 1136) then
-- iphone 5s
g_rectLeft, g_rectRight, g_rectTop, g_rectBottom = 123, 398, 535, 864;
g_rectWidth = g_rectRight - g_rectLeft;
g_rectHeight = g_rectBottom - g_rectTop;
g_clWordInputX, g_clWordInputY, g_clWordInputColor = 70, 420, 0xffedbf;
--_ho_x, _ho_y, _ho_c = 320, 715, 0xddbc84;
g_clRedCloseX, g_clRedCloseY = 554, 171;
g_clTabelRedCloseValid = {
{554, 195, 0x972438}, -- x
{424, 949, 0xdf8274} -- >
};
g_degree = 99;
--[[
elseif (g_screenWidth + g_screenHeight) == (1242 + 2208) then
-- iphone 6 plus
_ho_x, _ho_y, _ho_c = 620, 1330, 0xddbc84;
g_clRedCloseX, g_clRedCloseY = 90, 130;
g_clTableRedRcvValid = {
{293, 535, 0xcf3a50},
{293, 864, 0xc3304a},
}
g_clTabelRedCloseValid = {
{620, 260, 0xd84e43},
{620, 480, 0xfffaf5},
};
g_degree = 99;
--]]
else
error("您的设备分辨率不被支持");
end
local uiTable = {
["style"] = "default",
["width"] = g_screenWidth,
["height"] = g_screenHeight,
["config"] = "dlq_data2.dat",
["timer"] = 360,
views = {
{
["type"] = "Label",
["text"] = "qq抢红包"..g_version,
["size"] = 18,
["align"] = "center",
["color"] = "0,0,255",
},
{
["type"] = "RadioGroup",
["list"] = "延时,秒抢",
["select"] = "1",
},
--[[
{
["type"] = "Label",
["text"] = "操作方法: 运行选择躲避地雷-开启, 提示成功避雷针开启成功后, 打开多开小号再打开大号提示获取小号成功即可正常抢包!",
["size"] = 22,
["align"] = "left",
["color"] = "255,0,0",
},
--]]
}
}
jsonStr = json.encode(uiTable);
ret1, g_clickDelay, ret2, ret3 = showUI(jsonStr);
end
function _xprintf(s, ...)
return toast(s:format(...));
-- return wLog(LOG_FILE_NAME, s:format(...));
end
function xClick(...)
touchDown(...)
touchUp(...)
end
function isColor(x,y,c,s)
local fl,abs = math.floor,math.abs
s = fl(0xff*(100-s)*0.01)
local r,g,b = fl(c/0x10000),fl(c%0x10000/0x100),fl(c%0x100)
local rr,gg,bb = getColorRGB(x,y)
if abs(r-rr)<s and abs(g-gg)<s and abs(b-bb)<s then
return true
end
end
function multiColor(arr,s)
local fl,abs = math.floor,math.abs
s = fl(0xff*(100-s)*0.01)
keepScreen(true)
for var = 1, #arr do
local lr,lg,lb = getColorRGB(arr[var][1],arr[var][2])
local r = fl(arr[var][3]/0x10000)
local g = fl(arr[var][3]%0x10000/0x100)
local b = fl(arr[var][3]%0x100)
if abs(lr-r) > s or abs(lg-g) > s or abs(lb-b) > s then
keepScreen(false)
return false
end
end
keepScreen(false)
return true
end
-- the reference rect is 123,535 ~ 398,864
function handleRedReceived()
local x, y;
local rectBCX; -- bottom center x
local rectBCY; -- bottom center y
keepScreen(true);
-- first check with passwd red, we pick the color at 260,590
x, y = findMultiColorInRegionFuzzy(0xdf8173,
"0|-55|0xcf3a50,0|274|0xc3304a,-137|0|0xc3304a,138|0|0xc3304a",
95, 0, 0, g_screenWidth, g_screenHeight);
--wLog("test", "pwd found red: x = "..x..", y = "..y);
if x ~= -1 and y ~= -1 then
rectBCX = x;
rectBCY = y + (864 - 590);
-- find white color in region, if found, the red has not opened
x, y = findColorInRegionFuzzy(0xd87786, 100,
rectBCX-(g_rectWidth/2), rectBCY-50, rectBCX+(g_rectWidth/2), rectBCY);
if x ~= -1 and y ~= -1 then
xClick(rectBCX, rectBCY-100);
keepScreen(false);
return true;
end
x, y = findColorInRegionFuzzy(0xe7acb7, 100,
rectBCX-(g_rectWidth/2), rectBCY-50, rectBCX+(g_rectWidth/2), rectBCY);
if x ~= -1 and y ~= -1 then
xClick(rectBCX, rectBCY-100);
keepScreen(false);
return true;
end
end
-- first check with normal red, we pick the color at 260,588
x, y = findMultiColorInRegionFuzzy(0xd8746b,
"0|-53|0xcf3a50,0|276|0xc3304a,-137|0|0xc3304a,138|0|0xc3304a",
99, 0, 0, g_screenWidth, g_screenHeight);
--wLog("test", "nrl found red: x = "..x..", y = "..y);
if x ~= -1 and y ~= -1 then
rectBCX = x;
rectBCY = y + (864 - 588);
-- find white color in region, if found, the red has not opened
x, y = findColorInRegionFuzzy(0xd87786, 99,
rectBCX-(g_rectWidth/2), rectBCY-50, rectBCX+(g_rectWidth/2), rectBCY);
if x ~= -1 and y ~= -1 then
xClick(rectBCX, rectBCY-100);
keepScreen(false);
return true;
end
x, y = findColorInRegionFuzzy(0xe7acb7, 99,
rectBCX-(g_rectWidth/2), rectBCY-50, rectBCX+(g_rectWidth/2), rectBCY);
if x ~= -1 and y ~= -1 then
xClick(rectBCX, rectBCY-100);
keepScreen(false);
return true;
end
end
keepScreen(false);
return false;
end
function handleRedReceived_750_407()
local x, y;
local rectBCX; -- bottom center x
local rectBCY; -- bottom center y
keepScreen(true);
-- no password, check yellow cycle, we pick the color at 283,xxx
x, y = findMultiColorInRegionFuzzy(0xfed58b,
"0|-1|0xfed48b,0|1|0xe72655,-6|0|0xfed58b,5|0|0xfed58b",
95, 0, 0, g_screenWidth, g_screenHeight);
--_xprintf("pwd found red: x = "..x..", y = "..y);
if x ~= -1 and y ~= -1 then
xClick(x, y);
keepScreen(false);
return true;
end
-- with password, check yellow cycle, we pick the color at 283,xxx
x, y = findMultiColorInRegionFuzzy(0xfed58b,
"-1|0|0xfed58b,-2|0|0xfece89,-39|18|0xf58f76,38|18|0xf58f76",
95, 0, 0, g_screenWidth, g_screenHeight);
--_xprintf("pwd found red: x = "..x..", y = "..y);
if x ~= -1 and y ~= -1 then
xClick(x, y);
keepScreen(false);
return true;
end
keepScreen(false);
return false;
end
function handleRedOpen()
if isColor(g_clWordInputX, g_clWordInputY, g_clWordInputColor, g_degree) then
if (g_clickDelay == "0") then
toast("程序延时中,请勿手点红包", 1);
mSleep(math.random(1500,3000));
end
xClick(g_clWordInputX, g_clWordInputY); -- click on word
xClick(555, 1095); -- click on return button
return true;
end
return false;
end
function handleRedClose()
if multiColor(g_clTabelRedCloseValid, g_degree) then
--wLog("test", "close the window");
xClick(g_clRedCloseX, g_clRedCloseY);
--mSleep(1000); -- wait close finish
return true;
end
--wLog("test", "not found the color");
return false;
end
function handleRedClose_750_407()
if isColor(554, 195, 0x972438, 99) then
--wLog("test", "close the window");
xClick(g_clRedCloseX, g_clRedCloseY);
--mSleep(1000); -- wait close finish
return true;
end
--wLog("test", "not found the color");
return false;
end
local SWITCH_METATABLE = {
__index = function(t, k)
return rawget(t, "__default")
end,
}
function switchGenerator(tbl)
tbl = tbl or {}
setmetatable(tbl, SWITCH_METATABLE)
return function(case)
return tbl[case]()
end, tbl
end
local STATE_IDLE, STATE_RCVED = 0, 1;
local g_state = STATE_IDLE;
function handleDefault()
wLog("test", "call handleDefault");
end
function handleStateIdle()
if (handleRedReceived_750_407() == true) then
g_state = STATE_RCVED;
g_timeout = 0;
g_closeTimeout = TIMEOUT_CLOSE;
wLog("test", "handleStateIdle: state switch to "..g_state);
end
end
function handleStateReceived()
if isColor(g_clWordInputX, g_clWordInputY, g_clWordInputColor, g_degree) then
g_closeTimeout = g_closeTimeout + TIMEOUT_OPEN;
wLog("test", "handleStateReceived: timeout change to "..g_closeTimeout);
if (g_clickDelay == "0") then
toast("程序延时中,请勿手点红包", 1);
mSleep(math.random(1500,3000));
end
xClick(g_clWordInputX, g_clWordInputY); -- click on word
xClick(555, 1095); -- click on return button
end
if (handleRedClose_750_407() == true) then
g_state = STATE_IDLE;
wLog("test", "handleStateReceived: state switch to "..g_state);
end
end
local switchStateFunc, tblStateMachine = switchGenerator({
[STATE_IDLE] = handleStateIdle,
[STATE_RCVED] = handleStateReceived,
__default = handleDefault,
});
init(0);
mSleep(1000);
appInit();
initLog("test", 0);
while true do
-- prevent from no chance to click on the close window
if (g_state == STATE_RCVED) and (g_timeout > g_closeTimeout) then
g_timeout = 0;
g_state = STATE_IDLE;
wLog("test", "Timeout : state switch to "..g_state);
else
g_timeout = g_timeout + 1;
end
switchStateFunc(g_state);
mSleep(200);
end