-
Notifications
You must be signed in to change notification settings - Fork 63
/
util.lua
5256 lines (4663 loc) · 158 KB
/
util.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
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
-- print('util')
oppid = "com.hypergryph.arknights"
if use_zhuzhu_game then oppid = "com.hypergryph.arknightss" end
bppid = "com.hypergryph.arknights.bilibili"
-- apk502 = getApkVerInt() >= 502 or getApkVerInt() == 1
apk502 = getApkVerInt() >= 502
is_apk_old = function() return getApkVerInt() < 0 end
apk_old_warning = "怎么还有人用" .. getApkVerInt()
disable_game_up_check_wrapper = function(func)
return function(...)
local state = disable_game_up_check
disable_game_up_check = true
local ret = func(...)
disable_game_up_check = state
return ret
end
end
never_end_wrapper = function(func)
return function(...) while true do func(...) end end
end
still_wrapper = function(func)
return function(...)
-- nodeLib.keepNode()
keepCapture()
local ret = func(...)
releaseCapture()
-- nodeLib.releaseNode()
return ret
end
end
disable_log_wrapper = function(func, enable)
return function(...)
local state = disable_log
disable_log = not enable and true or false
local ret = func(...)
disable_log = state
return ret
end
end
enable_log_wrapper = function(func) return disable_log_wrapper(func, true) end
-- _restartScript = restartScript
-- 无障碍函数替换
if not openPermissionSetting then
openPermissionSetting =
function() stop("没root请换用无障碍版速通") end
isSnapshotServiceRun = function() return true end
isAccessibilityServiceRun = function() return true end
Path = {}
function Path:new(o)
o = o or {startTime = 0, durTime = 0, point = {}}
setmetatable(o, self)
self.__index = self
return o
end
function Path:setStartTime(t) self.startTime = t end
function Path:setDurTime(t) self.durTime = t end
function Path:addPoint(x, y)
table.insert(self.point, x)
table.insert(self.point, y)
end
Gesture = {}
function Gesture:new(o)
o = o or {path = {}}
setmetatable(o, self)
self.__index = self
return o
end
function Gesture:addPath(path) table.insert(self.path, path) end
gestureDispatchOnePath = function(path, id)
local point = path.point
if #point < 2 then return end
local start_time = time()
local timeline = {}
local length = 0
local x, y, px, py
px = point[1]
py = point[2]
sleep(path.startTime)
for i = 2, #point / 2 do
x = point[i * 2]
y = point[i * 2 + 1]
length = length + math.sqrt((x - px) ^ 2 + (y - py) ^ 2)
table.insert(timeline, length)
px, py = x, y
end
touchUp(id)
touchMove(id, point[1], point[2])
touchDown(id)
print(59, id, point)
for i = 2, #point / 2 do
x = point[i * 2]
y = point[i * 2 + 1]
timeline[i] = timeline[i] / length * path.durTime
touchMoveEx(id, x, y, timeline[i])
if time() - start_time > path.durTime then break end
end
sleep(max(0, time() - start_time - path.durTime))
print(60, id, point, start_time + path.durTime - time())
touchUp(id)
end
function Gesture:dispatch()
for id, path in pairs(self.path) do
log(71, id, path)
beginThread(gestureDispatchOnePath, path, id)
end
end
end
package = getPackageName()
-- transfer 节点精灵 to 懒人精灵
getColor = function(x, y)
local bgr = getPixelColor(x, y):upper()
return bgr:sub(7, 8) .. bgr:sub(5, 6) .. bgr:sub(3, 4)
end
time = systemTime
exit = exitScript
JsonDecode = jsonLib.decode
JsonEncode = jsonLib.encode
findNode = function(selector) return nodeLib.findOne(selector, true) end
findNodes = function(selector) return nodeLib.findAll(selector, true) end
clickNode = function(x) nodeLib.click(x, true) end
clickNodeFalse = function(x) nodeLib.click(x, false) end
clickPoint = function(x, y)
local gesture = Gesture:new()
local path = Path:new()
path:setStartTime(0)
path:setDurTime(1)
path:addPoint(x, y)
gesture:addPath(path)
gesture:dispatch()
end
_tap = tap
if not zero_wait_click then clickPoint = tap end
getDir = getWorkPath
base64 = getFileBase64
putClipboard = writePasteboard
getClipboard = readPasteboard
_toast = toast
toast = function(x)
_toast(x)
log(x)
end
deviceClickEventMaxX = nil
deviceClickEventMaxY = nil
catchClick = function()
if not root_mode then stop("未实现免root获取用户点击") end
local result = exec("su root sh -c 'getevent -l -c 4 -q'")
local x, y
x = result:match('POSITION_X%s+([^%s]+)')
y = result:match('POSITION_Y%s+([^%s]+)')
-- log(33, x, y)
if x and y then
if not deviceClickEventX then
local event = result:match('(/dev/[^:]+):.+POSITION_X')
result = exec("su root sh -c 'getevent -il " .. event .. "'")
deviceClickEventMaxX = result:match("POSITION_X[^\n]+max%s*(%d+)")
deviceClickEventMaxY = result:match("POSITION_Y[^\n]+max%s*(%d+)")
end
local screen = getScreen()
return {
x = math.round(tonumber(x, 16) * screen.width / deviceClickEventMaxX),
y = math.round(tonumber(y, 16) * screen.height / deviceClickEventMaxY),
}
end
end
home = function()
-- open(package)
keyPress(3)
end
back = function() keyPress(4) end
power = function() keyPress(26) end
_getDisplaySize = getDisplaySize
getDisplaySize = function()
-- override height and width
if type(force_height) == 'number' and type(force_width) == 'number' and
force_width > 0 and force_height > 0 then return force_width, force_height end
-- -- try to get from wm command, seems not work on real devices
-- local wmsize = exec("wm size")
-- local x, y = wmsize:match("(%d+)%s*x%s*(%d+)%s*$")
-- x = str2int(x, -1)
-- y = str2int(y, -1)
-- if x > 0 and y > 0 then return x, y end
-- use internal api
return _getDisplaySize()
end
getScreen = function()
local width, height = getDisplaySize()
if getDisplayRotate() % 2 == 1 then width, height = height, width end
return {width = width, height = height}
end
saveConfig = setStringConfig
loadConfig = function(k, v)
v = v or ''
local y = getStringConfig(k)
if not y or #y == 0 then y = v end
return y
end
peaceExit = function()
-- need_show_console = false
exit()
end
max = math.max
min = math.min
math.round = function(x) return math.floor(x + 0.5) end
round = math.round
clip = function(x, minimum, maximum) return min(max(x, minimum), maximum) end
-- https://stackoverflow.com/questions/9790688/escaping-strings-for-gsub
string.quote = function(str)
local quotepattern = '([' .. ("%^$().[]*+-?"):gsub("(.)", "%%%1") .. '])'
return str:gsub(quotepattern, "%%%1")
end
-- https://stackoverflow.com/questions/10460126/how-to-remove-spaces-from-a-string-in-lua
string.trim = function(s)
s = s or ''
return s:match '^()%s*$' and '' or s:match '^%s*(.*%S)'
end
string.count = function(str, pattern)
local ans = 0
for _ in str.gfind(pattern) do ans = ans + 1 end
return ans
end
string.map = function(str, map)
local ans = ''
for character in string.gmatch(str, "([%z\1-\127\194-\244][\128-\191]*)") do
-- print(217, character)
if map[character] == nil then
ans = ans .. character
else
ans = ans .. map[character]
end
end
return ans
end
string.split = function(str, sep)
if sep == nil then sep = "%s" end
local t = {}
for str in string.gmatch(str, "([^" .. sep .. "]+)") do table.insert(t, str) end
return t
end
-- 全角转半角
string.commonmap = function(str, extra_map)
return string.map(str, update({
[" "] = " ",
["1"] = "1",
["2"] = "2",
["3"] = "3",
["4"] = "4",
["5"] = "5",
["6"] = "6",
["7"] = '7',
["8"] = '8',
["9"] = '9',
["0"] = '0',
["A"] = 'a',
["B"] = 'b',
["C"] = 'c',
["D"] = 'd',
["E"] = 'e',
["F"] = 'f',
["G"] = 'g',
["H"] = 'h',
["I"] = 'i',
["J"] = 'j',
["K"] = 'k',
["L"] = 'l',
["M"] = 'm',
["N"] = 'n',
["O"] = 'o',
["P"] = 'p',
["Q"] = 'q',
["R"] = 'r',
["S"] = 's',
["T"] = 't',
["U"] = 'u',
["V"] = 'v',
["W"] = 'w',
["X"] = 'x',
["Y"] = 'y',
["Z"] = 'z',
["a"] = 'a',
["b"] = 'b',
["c"] = 'c',
["d"] = 'd',
["e"] = 'e',
["f"] = 'f',
["g"] = 'g',
["h"] = 'h',
["i"] = 'i',
["j"] = 'j',
["k"] = 'k',
["l"] = 'l',
["m"] = 'm',
["n"] = 'n',
["o"] = 'o',
["p"] = 'p',
["q"] = 'q',
["r"] = 'r',
["s"] = 's',
["t"] = 't',
["u"] = 'u',
["v"] = 'v',
["w"] = 'w',
["x"] = 'x',
["y"] = 'y',
["z"] = 'z',
[";"] = " ",
['"'] = " ",
["'"] = " ",
[";"] = " ",
[":"] = ":",
[":"] = ":",
[","] = " ",
["_"] = "-",
["-"] = "-",
["_"] = "-",
["、"] = " ",
[","] = " ",
["|"] = " ",
["@"] = "@",
["#"] = "#",
["\n"] = " ",
["\t"] = " ",
["!"] = "!",
["@"] = "@",
["#"] = "#",
["$"] = " ",
["%"] = " ",
["^"] = " ",
["&"] = " ",
["*"] = "*",
["("] = " ",
[")"] = " ",
["¥"] = " ",
["…"] = " ",
["×"] = "x",
["—"] = "-",
["+"] = "+",
}, extra_map or {}))
end
string.filterSplit = function(str, extra_map)
return string.split(string.commonmap(str, extra_map))
end
string.startsWith = function(str, prefix)
return string.sub(str, 1, string.len(prefix)) == prefix
end
string.endsWith = function(str, suffix)
return string.sub(str, #str - string.len(suffix) + 1) == suffix
end
startsWithX = function(x) return
function(prefix) return x:startsWith(prefix) end end
string.padStart = function(str, len, char)
if char == nil then char = " " end
return string.rep(char, len - #str) .. str
end
string.padEnd = function(str, len, char)
if char == nil then char = " " end
return str .. string.rep(char, len - #str)
end
table.diff = function(a, b)
local ans = {}
for k, v in pairs(a) do if v ~= b[k] then ans[k] = v end end
return ans
end
table.index = function(t, idx)
local ans = {}
for _, i in pairs(idx) do table.insert(ans, t[i]) end
return ans
end
table.reduce = function(t, f, a)
a = a or 0
for _, c in pairs(t) do a = f(a, c) end
return a
end
table.sum = function(t)
local a = 0
for _, c in pairs(t) do a = a + c end
return a
end
-- 从t中选出长度为n的所有组合,结果在ans,
table.combination = function(t, n)
local ans = {}
local cur = {}
local k = 1
combination(t, n, ans, cur, k)
return ans
end
combination = function(t, n, ans, cur, k)
-- cur = cur or {}
-- k = k or 1
if n == 0 then
table.insert(ans, shallowCopy(cur))
elseif k <= #t then
table.insert(cur, t[k])
combination(t, n - 1, ans, cur, k + 1)
cur[#cur] = nil
combination(t, n, ans, cur, k + 1)
end
end
table.flatten = function(t)
local ans = {}
for _, v in pairs(t) do
if type(v) == 'table' then
table.extend(ans, table.flatten(v))
else
table.insert(ans, v)
end
end
return ans
end
table.remove_duplicate = function(t)
local ans = {}
local visited = {}
for _, v in pairs(t) do
if not visited[v] then
table.insert(ans, v)
visited[v] = 1
end
end
return ans
end
-- 出现n次的元素
table.appear_times = function(t, times)
local ans = {}
local visited = {}
for _, v in pairs(t) do visited[v] = (visited[v] or 0) + 1 end
-- log(visited)
-- exit()
for k, _ in pairs(visited) do
if visited[k] == times then table.insert(ans, k) end
end
return ans
end
-- table.rotate = function(t, idx)
-- return table.extend(table.slice(t, idx), table.slice(t, 1, idx - 1))
-- end
-- 交
table.intersect = function(a, b)
local ans = {}
if #b < #a then a, b = b, a end
b = table.value2key(b)
a = table.value2key(a)
for k, _ in pairs(a) do if b[k] then table.insert(ans, k) end end
return ans
end
-- 差
table.subtract = function(a, b)
local ans = {}
b = table.value2key(b or {})
a = table.value2key(a or {})
for k, _ in pairs(a) do if not b[k] then table.insert(ans, k) end end
return ans
end
table.slice = function(tbl, first, last, step)
local sliced = {}
for i = first or 1, last or #tbl, step or 1 do sliced[#sliced + 1] = tbl[i] end
return sliced
end
-- shallow table
table.contains = function(a, b)
for k, v in pairs(b) do if a[k] ~= v then return false end end
return true
end
table.value2key = function(x)
local ans = {}
for k, v in pairs(x) do ans[v] = k end
return ans
end
table.select = function(mask, reference)
local ans = {}
for i = 1, #reference do if mask[i] then table.insert(ans, reference[i]) end end
return ans
end
-- return true if there is an x s.t. f(x) is true
table.any = function(t, f)
for k, v in pairs(t) do if f(v) then return true end end
end
-- return true if f(x) is all true
table.all = function(t, f)
for _, v in pairs(t) do if not f(v) then return false end end
return true
end
table.findv = function(t, f)
for k, v in pairs(t) do if f(v) then return v end end
end
table.filter = function(t, f)
local a = {}
for _, v in pairs(t) do if f(v) then table.insert(a, v) end end
return a
end
table.filterKV = function(t, f)
local a = {}
for k, v in pairs(t) do if f(k, v) then a[k] = v end end
return a
end
table.keys = function(t)
local a = {}
t = t or a
for k, _ in pairs(t) do table.insert(a, k) end
return a
end
table.values = function(t)
local a = {}
t = t or a
for _, v in pairs(t) do table.insert(a, v) end
return a
end
-- a,a+1,...b
range = function(a, b, s)
local t = {}
if not b and not s then a, b = 1, a end
s = s or 1
for i = a, b, s do table.insert(t, i) end
return t
end
table.includes = function(t, e)
return table.any(t, function(x) return x == e end)
end
string.includes = function(s, t)
for _, v in pairs(t) do if s:find(v) then return true end end
end
table.extend = function(t, e)
for k, v in pairs(e) do table.insert(t, v) end
return t
end
table.cat = function(t)
local ans = {}
for _, v in pairs(t) do for _, n in pairs(v) do table.insert(ans, n) end end
return ans
end
-- in = {
-- "A" = {1,4,5,7},
-- "B" = {1,2,5,6},
-- "C" = {3,4,6,7},
-- "D" = {2,3,6,7},
-- }
-- out = { {"A","B"},...}
-- n:key, m:value O(mmn)
table.reverseIndex = function(t)
local r = {}
local s = {}
for k, v in pairs(t) do for k2, v2 in pairs(v) do s[v2] = true end end
for k, v in pairs(s) do
r[k] = {}
for k2, v2 in pairs(t) do
if table.includes(v2, k) then table.insert(r[k], k2) end
end
end
for k, v in pairs(r) do table.sort(v) end
return r
end
table.find =
function(t, f) for k, v in pairs(t) do if f(v) then return k end end end
table.shuffle = function(tbl)
for i = #tbl, 2, -1 do
local j = math.random(i)
tbl[i], tbl[j] = tbl[j], tbl[i]
end
return tbl
end
-- one depth compare, and key-value pairs all same
table.equal = function(a, b)
if type(a) ~= 'table' or type(b) ~= 'table' then return end
if #a ~= #b then return end
if #a == 0 and #table.keys(a) ~= #table.keys(b) then return end
for k, v in pairs(a) do if v ~= b[k] then return end end
return true
end
-- one depth compare, and key all same
table.equalKey = function(a, b)
if type(a) ~= 'table' or type(b) ~= 'table' then return end
if #a ~= #b then return end
if #a == 0 and #table.keys(a) ~= #table.keys(b) then return end
for k, _ in pairs(a) do if b[k] == nil then return end end
return true
end
equalX = function(x) return function(y) return x == y end end
shallowCopy = function(x)
local y = {}
if x == nil then return y end
for k, v in pairs(x) do y[k] = v end
return y
end
update = function(b, x, inplace, false_as_nil)
local y = inplace and b or shallowCopy(b)
if x == nil then return y end
for k, v in pairs(x) do
if false_as_nil and v == false then v = nil end
y[k] = v
end
return y
end
-- n: num, a: alternative element
repeat_last = function(x, n, a)
if a == nil then a = x[#x] end
for i = 1, n do table.insert(x, a) end
return x
end
-- TODO: better algorithms
loop_times = function(x)
local times, f, n
local maxlen = 40 -- of one piece
local maxtimes = 1 -- of same pieces
if x == nil or #x == 0 then return 0 end
for i = 1, maxlen do
f = true
n = math.floor(#x / i)
if n <= maxtimes then break end
for j = 1, n - 1 do
for k = 1, i do
if x[#x - j * i - k + 1] ~= x[#x - k + 1] then
f = false
break
end
end
if not f then
maxtimes = math.max(maxtimes, j)
break
else
maxtimes = math.max(maxtimes, j + 1)
end
end
end
return maxtimes
end
map = function(...)
local a = {...}
local n = select("#", ...)
local r = {}
local f, x = a[1], a[2]
local p, ur
if n < 2 then return r end
if n == 2 then
n = #x
elseif n > 2 then
ur = true
x = {table.unpack(a, 2, n)}
n = n - 1
end
for i = 1, n do
p = x[i]
if type(f) == "function" then
p = f(p)
elseif type(f) == "table" then
p = f[p]
end
r[i] = p
end
if ur then return table.unpack(r, 1, n) end
return r
end
ssleep = function(x)
if x == nil then x = 1 end
sleep(x * 1000)
end
table.join = function(t, d)
t = t or {}
d = not d and ',' or d
local a = ''
for i = 1, #t do
a = a .. t[i]
if i ~= #t then a = a .. d end
end
return a
end
table.clear = function(x) for k, v in pairs(x) do x[k] = nil end end
removeFuncHash =
function(x) return x:startsWith('function') and 'function' or x end
table2string = function(t)
if type(t) == 'table' then
t = shallowCopy(t)
for k, v in pairs(t) do if type(v) == "function" then t[k] = 'func' end end
t = JsonEncode(t)
end
return t
end
-- log_history = {}
log = function(...)
if disable_log then return end
local arg = {...}
local l = table.join({
map(tostring, running, ' ', table.unpack(map(table2string, arg))),
}, ' ')
-- l = map(removeFuncHash, l)
-- l = map(table2string, l)
local a = os.date('%Y.%m.%d %H:%M:%S')
-- local a = time()
-- for _, v in pairs(l) do a = a .. ' ' .. v end
-- TODO: 有可能是日志太多导致速通停止运行
print(l)
console.println(1, a .. ' ' .. l)
-- writeLog(l)
end
open = function(id)
id = id or appid
runApp(id)
end
stop = function(msg, mode, nohome, complete)
msg = msg or ''
msg = "stop " .. msg
disable_log = false -- 强制开启日志
local info = table.join(qqmessage, ' ') .. ' ' .. msg
if complete then
captureqqimagedeliver("INFO", "任务结束", info, true)
cloud.completeTask(last_upload_img)
else
captureqqimagedeliver("WARN", "任务结束", info, true)
local type = ''
if msg:find("登录次数达到") then
type = cloud.FAILTASK_LINEBUSY
elseif msg:find("密码") then
type = cloud.FAILTASK_ACCOUNTERROR
end
cloud.failTask(last_upload_img, type)
end
toast(msg)
cloud.fetchSolveTask()
if not nohome then
closeapp(appid)
home()
end
ssleep(2)
if mode == 'next' then restart_account(true) end
if mode == 'cur' then restart_account(false) end
exit()
end
findColorAbsolute = function(color, confidence)
-- print(286, confidence)
confidence = confidence or 100
-- keepScreen(true)
for x, y, c in color:gmatch("(%d+),(%d+),(#[^|]+)") do
-- log(x, y, c)
if not compareColor(tonumber(x), tonumber(y), c, confidence) then
-- if getColor(tonumber(x), tonumber(y)).hex ~= c then
if verbose_fca then log(x, y, c) end
-- keepScreen(false)
return
end
end
local x, y = color:match("(%d+),(%d+)")
return {x = tonumber(x), y = tonumber(y)}
end
findOne_game_up_check_last_time = 0
findOne_keepalive_check_last_time = time()
findOne_last_time = time()
findOne_locked = false
findOne = function(x, confidence)
if type(x) == "function" then return x() end
-- 每5秒确认游戏在前台
if (time() - findOne_game_up_check_last_time > 5000) then
findOne_game_up_check_last_time = time()
wait_game_up()
end
local x0 = x
confidence = confidence or default_findcolor_confidence
if type(x) == 'string' and not x:find(coord_delimeter) then x = point[x] end
if type(x) == "function" then return x() end
if type(x) == "table" and #x == 0 then return findNode(x) end
if type(x) == "table" and #x > 0 then return x end
if type(x) == "string" then
-- 控制截图频率
local current = time()
if findOne_interval > 0 and current - findOne_last_time > findOne_interval then
findOne_last_time = time()
-- log(500)
-- releaseCapture()
keepCapture()
end
-- sleep(max(0, findOne_interval - (time() - findOne_last_time)))
-- findOne_last_time = time()
local pos
-- log(x0, rfl[x0], x, confidence)
if rfl[x0] then
if cmpColorEx(x, confidence) == 1 then pos = first_point[x0] end
else
local px, py
-- log(x0, rfg[x0], first_color[x0], x)
px, py = findMultiColor(rfg[x0][1], rfg[x0][2], rfg[x0][3], rfg[x0][4],
first_color[x0], x, 0, confidence)
if px ~= -1 then pos = {px, py} end
end
return pos
end
end
findAny = function(x) return appear(x, 0, 0) end
findOnes = function(x, confidence)
confidence = confidence or default_findcolor_confidence
log(rfg[x], first_color[x], point[x])
return findMultiColorAll(rfg[x][1], rfg[x][2], rfg[x][3], rfg[x][4],
first_color[x], point[x], 0, confidence) or {}
end
-- x={2,3} "信用" func nil
tap_last_time = time()
tap = function(x, noretry, allow_outside_game)
if not unsafe_tap and not allow_outside_game and not check_after_tap then
wait_game_up()
end
local x0 = x
if x == nil then return end
if x == true then return true end
if type(x) == "function" then return x() end
if type(x) == "string" and not x:find(coord_delimeter) then
x = point[x]
if type(x) == "string" then
local p = x:find(coord_delimeter)
local q = x:find(coord_delimeter, p + 1)
x = map(tonumber, {x:sub(1, p - 1), x:sub(p + 1, q - 1)})
end
end
log("tap", x0, x)
if type(x) ~= "table" then return end
-- log(843, tap_interval)
if tap_interval > 0 and tap_interval - (time() - tap_last_time) > 0 then
return
-- sleep(max(0, tap_interval - (time() - tap_last_time)))
end
tap_last_time = time()
-- log(838,x)
if #x > 0 then
clickPoint(x[1], x[2])
else
clickNode(x)
end
collectgarbage("collect")
-- collectgarbage('collect')
local start_time = time()
-- 后置检查
if not unsafe_tap and not allow_outside_game and check_after_tap then
wait_game_up()
end
-- 这个sleep的作用是两次gesture间隔太短被判定为长按/点击,游戏界面会无反应,
-- 所以click后需要等一会儿
-- 懒人无现象闪退,可能和点太快有关
sleep(max(milesecond_after_click + start_time - time(), 0))
-- 返回"面板"后易触发数据更新,导致操作失效
if noretry then return end
if type(x0) == 'string' and x0:startsWith('面板') then
wait(function()
if not findOne("面板") then return true end
if findOne("阿米娅") then
path.fallback.阿米娅()
return true
end
log("retap", x0)
tap(x0, true, allow_outside_game)
end, 10)
end
end
-- simple swip for 资源收集
swipq = function(direction)
local finger = {
point = {
{screen.width // 2, screen.height // 2},
{direction == 'right' and (screen.width - 1) or 0, screen.height // 2},
},
duration = 500,
}
gesture(finger)
sleep(finger.duration + 50)
end
-- quick swip for fight
swipu = function(dis)
log('swipu', dis)
-- preprocess distance
if type(dis) == "string" then dis = distance[dis] end
if type(dis) ~= "table" then dis = {dis} end
if not dis then return end
-- flatten to one depth
-- local max_once_dis = 1080
-- local freey = scale(150)
local freey = scale(150)
local freex = scale(360 / 720 * 1080) -- 第12章左上角
local max_once_dis = screen.width - scale(300) - freex
for _, d in pairs(dis) do
local sign = d > 0 and 1 or -1
if math.abs(d) == swip_right_max then
swipe(sign > 0 and "right" or "left")
else
-- 只实现了右移
if sign > 0 then stop("swipu左移未实现") end
local finger = {
{
point = {{freex, freey}, {freex, screen.height - 1}},
start = 0,
duration = 0,
},
}
local start = 0
local duration = 150
local interval = 50
local end_delay = 50
local flipy = swipu_flipy or 0
local flipx = swipu_flipx or 0
d = math.abs(d)
while d > 0 do
if d > max_once_dis then
table.insert(finger, {
point = {
{freex + max_once_dis, freey + flipx},
{freex + max_once_dis, freey + flipy},
},
start = start,
duration = duration,
})
else
table.insert(finger, {
point = {{freex + d, freey}, {freex + d + flipx, freey + flipy}},