lycheedev 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/bin/lycheedev.js +21 -6
  2. package/package.json +1 -1
  3. package/vendor/addon/Core/Bootstrap.lua +131 -131
  4. package/vendor/addon/Core/Clients/Mainline.lua +9 -9
  5. package/vendor/addon/Core/Clients/Mists.lua +9 -9
  6. package/vendor/addon/Core/Clients/Titan.lua +9 -9
  7. package/vendor/addon/Core/Compatibility.lua +43 -43
  8. package/vendor/addon/Core/Database.lua +859 -859
  9. package/vendor/addon/Core/Inspector.lua +647 -647
  10. package/vendor/addon/Core/Locale.lua +307 -307
  11. package/vendor/addon/Core/Locale_enUS.lua +318 -318
  12. package/vendor/addon/Core/Safety.lua +42 -42
  13. package/vendor/addon/Core/Serializer.lua +324 -324
  14. package/vendor/addon/Libs/AutomationQR.lua +1176 -1176
  15. package/vendor/addon/Lychee Dev_Mainline.toc +43 -43
  16. package/vendor/addon/Lychee Dev_Mists.toc +43 -43
  17. package/vendor/addon/Lychee Dev_Wrath.toc +43 -43
  18. package/vendor/addon/Modules/Automation/Controller.lua +757 -757
  19. package/vendor/addon/Modules/Automation/Report.lua +409 -409
  20. package/vendor/addon/Modules/Automation/auto/auto.lua +12 -12
  21. package/vendor/addon/Modules/Diagnostics.lua +238 -238
  22. package/vendor/addon/Modules/Events/Catalog.lua +184 -184
  23. package/vendor/addon/Modules/Events/CatalogData_Mainline.lua +1788 -1788
  24. package/vendor/addon/Modules/Events/CatalogData_Mists.lua +1489 -1489
  25. package/vendor/addon/Modules/Events/CatalogData_Titan.lua +1492 -1492
  26. package/vendor/addon/Modules/Events/Monitor.lua +181 -181
  27. package/vendor/addon/Modules/FunctionTrace.lua +85 -85
  28. package/vendor/addon/Modules/ObjectInspector.lua +329 -329
  29. package/vendor/addon/UI/AutomationOverlay.lua +183 -183
  30. package/vendor/addon/UI/Export.lua +140 -140
  31. package/vendor/addon/UI/Features.lua +890 -890
  32. package/vendor/addon/UI/MainWindow.lua +1145 -1145
  33. package/vendor/addon/UI/Pages/About.lua +223 -223
  34. package/vendor/addon/UI/Pages/Automation.lua +417 -417
  35. package/vendor/addon/UI/Pages/Diagnostics.lua +289 -289
  36. package/vendor/addon/UI/Pages/ExportRecords.lua +387 -387
  37. package/vendor/addon/UI/Pages/Object.lua +573 -573
  38. package/vendor/addon/UI/Pages/Trace.lua +165 -165
  39. package/vendor/skill/SKILL.md +94 -94
  40. package/vendor/skill/agents/openai.yaml +4 -4
  41. package/vendor/skill/references/automation.md +327 -327
  42. package/vendor/skill/references/runtime-investigations.md +97 -97
  43. package/vendor/skill/scripts/automation/__init__.py +1 -1
  44. package/vendor/skill/scripts/automation/registry.py +516 -516
  45. package/vendor/skill/scripts/automation/saved_variables.py +438 -438
  46. package/vendor/skill/scripts/automation/session.py +207 -207
  47. package/vendor/skill/scripts/automation/windows.py +573 -573
  48. package/vendor/skill/scripts/automation.py +865 -865
  49. package/vendor/skill/scripts/requirements.txt +13 -13
  50. package/vendor/skill/scripts/selftest_offline.py +981 -981
@@ -1,647 +1,647 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- local PAGE_SIZE = 200
4
- local MAX_SCANS_PER_PAGE = PAGE_SIZE * 4
5
- local STORED_MAX_DEPTH = 8
6
- local STORED_MAX_NODES = 4000
7
- local STORED_MAX_ENTRIES = 200
8
- local STORED_MAX_VALUE_BYTES = 512
9
-
10
- local function IsSecret(value)
11
- return issecretvalue and issecretvalue(value)
12
- end
13
-
14
- local function SafeToString(value)
15
- if IsSecret(value) then
16
- return ns.L.TREE_SECRET
17
- end
18
-
19
- local valueType = type(value)
20
- if valueType == "string" then
21
- return string.format("%q", value)
22
- elseif valueType == "number" or valueType == "boolean" or valueType == "nil" then
23
- return tostring(value)
24
- elseif valueType == "table" then
25
- return ns.L.TREE_TABLE
26
- end
27
-
28
- local succeeded, text = pcall(tostring, value)
29
- if succeeded then
30
- return "<" .. valueType .. ": " .. text .. ">"
31
- end
32
- return "<" .. valueType .. ">"
33
- end
34
-
35
- local function SortKey(value)
36
- if IsSecret(value) then
37
- return "0:<secret>"
38
- end
39
-
40
- local valueType = type(value)
41
- if valueType == "number" then
42
- return "1:" .. string.format("%020.6f", value)
43
- elseif valueType == "string" then
44
- return "2:" .. value
45
- elseif valueType == "boolean" then
46
- return value and "3:1" or "3:0"
47
- end
48
- return "4:" .. valueType .. ":" .. SafeToString(value)
49
- end
50
-
51
- local function FormatKey(key)
52
- if type(key) == "string" and key:match("^[%a_][%w_]*$") then
53
- return key
54
- end
55
- return "[" .. SafeToString(key) .. "]"
56
- end
57
-
58
- local function MarkerNode(label, text)
59
- return {
60
- label = label,
61
- kind = "marker",
62
- value = text,
63
- }
64
- end
65
-
66
- local function HasAncestorTable(parent, value)
67
- while parent do
68
- if parent.source == value then
69
- return true
70
- end
71
- parent = parent.parent
72
- end
73
- return false
74
- end
75
-
76
- local function GetMethod(value, methodName)
77
- if IsSecret(value) then
78
- return nil
79
- end
80
- local succeeded, method = pcall(function()
81
- return value[methodName]
82
- end)
83
- return succeeded and type(method) == "function" and method or nil
84
- end
85
-
86
- local function IsUIObject(value)
87
- return GetMethod(value, "GetObjectType") ~= nil
88
- end
89
-
90
- local function CallMethod(value, methodName)
91
- local method = GetMethod(value, methodName)
92
- if not method then
93
- return nil
94
- end
95
- local succeeded, result = pcall(method, value)
96
- if not succeeded or IsSecret(result) then
97
- return nil
98
- end
99
- return result
100
- end
101
-
102
- local function CollectMethodResults(value, methodName)
103
- local method = GetMethod(value, methodName)
104
- if not method then
105
- return nil
106
- end
107
- local packed = { pcall(method, value) }
108
- if not packed[1] then
109
- return nil
110
- end
111
- local results = {}
112
- for index = 2, #packed do
113
- if packed[index] ~= nil and not IsSecret(packed[index]) then
114
- results[#results + 1] = packed[index]
115
- end
116
- end
117
- return results
118
- end
119
-
120
- local function BuildUIObjectOverview(value)
121
- local overview = {
122
- [ns.L.FRAME_LUA_TYPE] = type(value),
123
- [ns.L.FRAME_OBJECT_TYPE] = CallMethod(value, "GetObjectType"),
124
- [ns.L.FRAME_NAME] = CallMethod(value, "GetName"),
125
- [ns.L.FRAME_SHOWN] = CallMethod(value, "IsShown"),
126
- [ns.L.FRAME_WIDTH] = CallMethod(value, "GetWidth"),
127
- [ns.L.FRAME_HEIGHT] = CallMethod(value, "GetHeight"),
128
- [ns.L.FRAME_SCALE] = CallMethod(value, "GetEffectiveScale"),
129
- [ns.L.FRAME_LEVEL] = CallMethod(value, "GetFrameLevel"),
130
- [ns.L.FRAME_STRATA] = CallMethod(value, "GetFrameStrata"),
131
- }
132
- local parent = CallMethod(value, "GetParent")
133
- if parent ~= nil then
134
- overview[ns.L.FRAME_PARENT] = CallMethod(parent, "GetName") or SafeToString(parent)
135
- end
136
- return overview
137
- end
138
-
139
- local function BuildNode(label, value, parent)
140
- if IsSecret(value) then
141
- return MarkerNode(label, ns.L.TREE_SECRET)
142
- end
143
-
144
- local isUIObject = IsUIObject(value)
145
- if type(value) ~= "table" and not isUIObject then
146
- return {
147
- label = label,
148
- kind = type(value),
149
- value = SafeToString(value),
150
- source = value,
151
- exportable = true,
152
- parent = parent,
153
- }
154
- elseif HasAncestorTable(parent, value) then
155
- return MarkerNode(label, ns.L.TREE_CYCLE)
156
- end
157
-
158
- return {
159
- label = label,
160
- kind = "table",
161
- value = ns.L.TREE_TABLE,
162
- children = {},
163
- expanded = parent == nil,
164
- source = value,
165
- exportable = true,
166
- isUIObject = isUIObject,
167
- parent = parent,
168
- cursor = nil,
169
- loadedCount = 0,
170
- secretKeyCount = 0,
171
- hasMore = true,
172
- loaded = false,
173
- }
174
- end
175
-
176
- local function AddUIObjectNodes(node)
177
- if not node.isUIObject then
178
- return
179
- end
180
-
181
- node.children[#node.children + 1] = BuildNode(ns.L.FRAME_OVERVIEW, BuildUIObjectOverview(node.source), node)
182
- node.loadedCount = node.loadedCount + 1
183
-
184
- local children = CollectMethodResults(node.source, "GetChildren")
185
- if children and #children > 0 then
186
- node.children[#node.children + 1] = BuildNode(ns.L.FRAME_CHILDREN, children, node)
187
- node.loadedCount = node.loadedCount + 1
188
- end
189
-
190
- local regions = CollectMethodResults(node.source, "GetRegions")
191
- if regions and #regions > 0 then
192
- node.children[#node.children + 1] = BuildNode(ns.L.FRAME_REGIONS, regions, node)
193
- node.loadedCount = node.loadedCount + 1
194
- end
195
- end
196
-
197
- local function RemoveLoadMoreNode(node)
198
- local last = node.children[#node.children]
199
- if last and last.kind == "load_more" then
200
- node.children[#node.children] = nil
201
- end
202
- end
203
-
204
- local function UpdateTableValue(node)
205
- if node.hasMore then
206
- node.value = string.format(ns.L.TREE_TABLE_MORE, node.loadedCount)
207
- else
208
- node.value = string.format(ns.L.TREE_TABLE_COUNT, node.loadedCount)
209
- end
210
- end
211
-
212
- function ns.LoadMoreValueTreeNode(node)
213
- if ns.IsCombatBlocked and ns.IsCombatBlocked() then
214
- return false, ns.L.COMBAT_BLOCKED
215
- elseif type(node) ~= "table" or node.kind ~= "table"
216
- or (type(node.source) ~= "table" and not node.isUIObject) then
217
- return false
218
- elseif not node.hasMore then
219
- return true
220
- end
221
-
222
- RemoveLoadMoreNode(node)
223
- if not node.loaded then
224
- AddUIObjectNodes(node)
225
- end
226
- local entries = {}
227
- local cursor = node.cursor
228
- local scanned = 0
229
-
230
- while type(node.source) == "table" and #entries < PAGE_SIZE and scanned < MAX_SCANS_PER_PAGE do
231
- local succeeded, key, value = pcall(next, node.source, cursor)
232
- if not succeeded then
233
- node.hasMore = false
234
- node.children[#node.children + 1] = MarkerNode("...", ns.L.TREE_TABLE_CHANGED)
235
- break
236
- elseif key == nil then
237
- node.hasMore = false
238
- break
239
- end
240
-
241
- cursor = key
242
- scanned = scanned + 1
243
- if IsSecret(key) then
244
- node.secretKeyCount = node.secretKeyCount + 1
245
- else
246
- entries[#entries + 1] = { key = key, value = value }
247
- end
248
- end
249
- if type(node.source) ~= "table" then
250
- node.hasMore = false
251
- end
252
-
253
- table.sort(entries, function(left, right)
254
- return SortKey(left.key) < SortKey(right.key)
255
- end)
256
- for index = 1, #entries do
257
- local entry = entries[index]
258
- node.children[#node.children + 1] = BuildNode(FormatKey(entry.key), entry.value, node)
259
- node.loadedCount = node.loadedCount + 1
260
- end
261
-
262
- node.cursor = cursor
263
- node.loaded = true
264
- if node.hasMore then
265
- node.children[#node.children + 1] = {
266
- label = ns.L.TREE_LOAD_MORE,
267
- kind = "load_more",
268
- value = ns.L.TREE_LOAD_NEXT,
269
- owner = node,
270
- }
271
- elseif node.secretKeyCount > 0 then
272
- node.children[#node.children + 1] = MarkerNode("...", string.format(ns.L.TREE_SECRET_KEYS, node.secretKeyCount))
273
- end
274
- UpdateTableValue(node)
275
- return true
276
- end
277
-
278
- function ns.CreateValueTree(values)
279
- if type(values) ~= "table" or type(values.n) ~= "number" or values.n <= 0 then
280
- return nil
281
- end
282
-
283
- local roots = {}
284
- for index = 1, values.n do
285
- local node = BuildNode("[" .. index .. "]", values[index], nil)
286
- roots[#roots + 1] = node
287
- if node.kind == "table" then
288
- ns.LoadMoreValueTreeNode(node)
289
- end
290
- end
291
-
292
- return {
293
- roots = roots,
294
- truncated = false,
295
- }
296
- end
297
-
298
- local function TrimStoredText(value)
299
- value = tostring(value or "")
300
- if #value <= STORED_MAX_VALUE_BYTES then
301
- return value
302
- end
303
- return value:sub(1, STORED_MAX_VALUE_BYTES) .. "..."
304
- end
305
-
306
- local function BuildStoredNode(label, value, context, depth)
307
- if context.count >= STORED_MAX_NODES then
308
- context.truncated = true
309
- return nil
310
- end
311
- context.count = context.count + 1
312
-
313
- if IsSecret(value) then
314
- return MarkerNode(label, ns.L.TREE_SECRET)
315
- end
316
-
317
- local isUIObject = IsUIObject(value)
318
- if type(value) ~= "table" and not isUIObject then
319
- return {
320
- label = label,
321
- kind = type(value),
322
- value = TrimStoredText(SafeToString(value)),
323
- }
324
- elseif context.ancestors[value] then
325
- return MarkerNode(label, ns.L.TREE_CYCLE)
326
- end
327
-
328
- local node = {
329
- label = label,
330
- kind = "table",
331
- value = ns.L.TREE_TABLE,
332
- children = {},
333
- expanded = depth == 0,
334
- loaded = true,
335
- hasMore = false,
336
- }
337
- if depth >= STORED_MAX_DEPTH then
338
- context.truncated = true
339
- node.children[1] = MarkerNode("...", ns.L.TREE_STORED_TRUNCATED)
340
- node.value = string.format(ns.L.TREE_TABLE_COUNT, 0)
341
- return node
342
- end
343
-
344
- context.ancestors[value] = true
345
- local entries = {}
346
- if isUIObject then
347
- entries[1] = { key = ns.L.FRAME_OVERVIEW, value = BuildUIObjectOverview(value) }
348
- end
349
- if type(value) == "table" then
350
- local cursor
351
- while #entries < STORED_MAX_ENTRIES and context.count + #entries < STORED_MAX_NODES do
352
- local succeeded, key, childValue = pcall(next, value, cursor)
353
- if not succeeded or key == nil then
354
- break
355
- end
356
- cursor = key
357
- if not IsSecret(key) then
358
- entries[#entries + 1] = { key = key, value = childValue }
359
- end
360
- end
361
- if cursor ~= nil then
362
- local succeeded, nextKey = pcall(next, value, cursor)
363
- if succeeded and nextKey ~= nil then
364
- context.truncated = true
365
- end
366
- end
367
- end
368
-
369
- table.sort(entries, function(left, right)
370
- return SortKey(left.key) < SortKey(right.key)
371
- end)
372
- for index = 1, #entries do
373
- local entry = entries[index]
374
- local child = BuildStoredNode(FormatKey(entry.key), entry.value, context, depth + 1)
375
- if not child then
376
- context.truncated = true
377
- break
378
- end
379
- node.children[#node.children + 1] = child
380
- end
381
- context.ancestors[value] = nil
382
-
383
- if context.truncated and #node.children < STORED_MAX_ENTRIES
384
- and context.count < STORED_MAX_NODES then
385
- node.children[#node.children + 1] = MarkerNode("...", ns.L.TREE_STORED_TRUNCATED)
386
- end
387
- node.value = string.format(ns.L.TREE_TABLE_COUNT, #node.children)
388
- return node
389
- end
390
-
391
- function ns.CreateStoredValueTree(values)
392
- if type(values) ~= "table" or type(values.n) ~= "number" or values.n <= 0 then
393
- return nil
394
- end
395
-
396
- local context = {
397
- count = 0,
398
- truncated = false,
399
- ancestors = {},
400
- }
401
- local roots = {}
402
- for index = 1, values.n do
403
- local node = BuildStoredNode("[" .. index .. "]", values[index], context, 0)
404
- if not node then
405
- break
406
- end
407
- roots[#roots + 1] = node
408
- end
409
- if context.truncated and #roots == 0 then
410
- roots[1] = MarkerNode("...", ns.L.TREE_STORED_TRUNCATED)
411
- end
412
- return {
413
- roots = roots,
414
- truncated = context.truncated,
415
- }
416
- end
417
-
418
- local function SkipSerializedWhitespace(text, position)
419
- while position <= #text do
420
- local character = text:sub(position, position)
421
- if character ~= " " and character ~= "\t" and character ~= "\r" and character ~= "\n" then
422
- break
423
- end
424
- position = position + 1
425
- end
426
- return position
427
- end
428
-
429
- local function TrimSerializedToken(text)
430
- return text:match("^%s*(.-)%s*$") or ""
431
- end
432
-
433
- local function ScanSerializedQuoted(text, position)
434
- local quote = text:sub(position, position)
435
- local cursor = position + 1
436
- while cursor <= #text do
437
- local character = text:sub(cursor, cursor)
438
- if character == "\\" then
439
- cursor = cursor + 2
440
- elseif character == quote then
441
- return text:sub(position, cursor), cursor + 1
442
- else
443
- cursor = cursor + 1
444
- end
445
- end
446
- return nil
447
- end
448
-
449
- local function ScanSerializedKey(text, position)
450
- local startPosition = position
451
- local braceDepth = 0
452
- local bracketDepth = 0
453
- while position <= #text do
454
- local character = text:sub(position, position)
455
- if character == "\"" or character == "'" then
456
- local _, nextPosition = ScanSerializedQuoted(text, position)
457
- if not nextPosition then
458
- return nil
459
- end
460
- position = nextPosition
461
- elseif character == "{" then
462
- braceDepth = braceDepth + 1
463
- position = position + 1
464
- elseif character == "}" then
465
- braceDepth = math.max(0, braceDepth - 1)
466
- position = position + 1
467
- elseif character == "[" then
468
- bracketDepth = bracketDepth + 1
469
- position = position + 1
470
- elseif character == "]" then
471
- if braceDepth == 0 and bracketDepth == 0 then
472
- return TrimSerializedToken(text:sub(startPosition, position - 1)), position + 1
473
- end
474
- bracketDepth = math.max(0, bracketDepth - 1)
475
- position = position + 1
476
- else
477
- position = position + 1
478
- end
479
- end
480
- return nil
481
- end
482
-
483
- local function FormatSerializedKey(token)
484
- local identifier = token:match('^"([_%a][_%w]*)"$') or token:match("^'([_%a][_%w]*)'$")
485
- if identifier then
486
- return identifier
487
- end
488
- return "[" .. token .. "]"
489
- end
490
-
491
- local function CreateSerializedScalarNode(label, token)
492
- local kind
493
- if token == "nil" then
494
- kind = "nil"
495
- elseif token == "true" or token == "false" then
496
- kind = "boolean"
497
- elseif tonumber(token) ~= nil then
498
- kind = "number"
499
- elseif token:sub(1, 1) == "<" then
500
- kind = "marker"
501
- else
502
- kind = "string"
503
- end
504
- return {
505
- label = label,
506
- kind = kind,
507
- value = TrimStoredText(token),
508
- }
509
- end
510
-
511
- local ParseSerializedNode
512
- ParseSerializedNode = function(text, position, label, context, depth)
513
- if context.count >= STORED_MAX_NODES then
514
- return nil
515
- end
516
- context.count = context.count + 1
517
- position = SkipSerializedWhitespace(text, position)
518
- local character = text:sub(position, position)
519
-
520
- if character == "\"" or character == "'" then
521
- local token, nextPosition = ScanSerializedQuoted(text, position)
522
- if not token then
523
- return nil
524
- end
525
- return CreateSerializedScalarNode(label, token), nextPosition
526
- elseif character ~= "{" then
527
- local startPosition = position
528
- while position <= #text do
529
- character = text:sub(position, position)
530
- if character == "," or character == "\r" or character == "\n" or character == "}" then
531
- break
532
- end
533
- position = position + 1
534
- end
535
- local token = TrimSerializedToken(text:sub(startPosition, position - 1))
536
- if token == "" then
537
- return nil
538
- end
539
- return CreateSerializedScalarNode(label, token), position
540
- end
541
-
542
- local node = {
543
- label = label,
544
- kind = "table",
545
- value = ns.L.TREE_TABLE,
546
- children = {},
547
- expanded = depth == 0,
548
- loaded = true,
549
- hasMore = false,
550
- }
551
- position = position + 1
552
- while position <= #text do
553
- position = SkipSerializedWhitespace(text, position)
554
- character = text:sub(position, position)
555
- if character == "}" then
556
- node.value = string.format(ns.L.TREE_TABLE_COUNT, #node.children)
557
- return node, position + 1
558
- elseif text:sub(position, position + 2) == "..." then
559
- local lineEnd = text:find("[\r\n]", position)
560
- local marker = TrimSerializedToken(text:sub(position, (lineEnd or (#text + 1)) - 1))
561
- node.children[#node.children + 1] = MarkerNode("...", marker)
562
- position = lineEnd or (#text + 1)
563
- elseif character ~= "[" then
564
- return nil
565
- else
566
- local keyToken, nextPosition = ScanSerializedKey(text, position + 1)
567
- if not keyToken then
568
- return nil
569
- end
570
- position = SkipSerializedWhitespace(text, nextPosition)
571
- if text:sub(position, position) ~= "=" then
572
- return nil
573
- end
574
- local child
575
- child, position = ParseSerializedNode(text, position + 1,
576
- FormatSerializedKey(keyToken), context, depth + 1)
577
- if not child then
578
- return nil
579
- end
580
- node.children[#node.children + 1] = child
581
- position = SkipSerializedWhitespace(text, position)
582
- if text:sub(position, position) == "," then
583
- position = position + 1
584
- end
585
- end
586
- end
587
- return nil
588
- end
589
-
590
- local function ParseSerializedRootHeader(text, position, expectedIndex)
591
- if text:sub(position, position) ~= "[" then
592
- return nil
593
- end
594
- local closing = text:find("]", position + 1, true)
595
- if not closing or tonumber(text:sub(position + 1, closing - 1)) ~= expectedIndex then
596
- return nil
597
- end
598
- position = SkipSerializedWhitespace(text, closing + 1)
599
- if text:sub(position, position) ~= "=" then
600
- return nil
601
- end
602
- return position + 1
603
- end
604
-
605
- function ns.CreateStoredTreeFromSerialized(text)
606
- if type(text) ~= "string" or text == "" then
607
- return nil
608
- end
609
-
610
- local position = text:find("^%[1%]%s*=")
611
- if not position then
612
- local lineStart = text:find("\n%[1%]%s*=")
613
- position = lineStart and lineStart + 1 or nil
614
- end
615
- if not position then
616
- return nil
617
- end
618
-
619
- local context = { count = 0 }
620
- local roots = {}
621
- local rootIndex = 1
622
- while position and position <= #text do
623
- position = ParseSerializedRootHeader(text, position, rootIndex)
624
- if not position then
625
- break
626
- end
627
- local node
628
- node, position = ParseSerializedNode(text, position, "[" .. rootIndex .. "]", context, 0)
629
- if not node then
630
- return nil
631
- end
632
- roots[#roots + 1] = node
633
- rootIndex = rootIndex + 1
634
- position = SkipSerializedWhitespace(text, position)
635
- if text:sub(position, position) ~= "[" then
636
- break
637
- end
638
- end
639
-
640
- if #roots == 0 then
641
- return nil
642
- end
643
- return {
644
- roots = roots,
645
- truncated = false,
646
- }
647
- end
1
+ local ADDON_NAME, ns = ...
2
+
3
+ local PAGE_SIZE = 200
4
+ local MAX_SCANS_PER_PAGE = PAGE_SIZE * 4
5
+ local STORED_MAX_DEPTH = 8
6
+ local STORED_MAX_NODES = 4000
7
+ local STORED_MAX_ENTRIES = 200
8
+ local STORED_MAX_VALUE_BYTES = 512
9
+
10
+ local function IsSecret(value)
11
+ return issecretvalue and issecretvalue(value)
12
+ end
13
+
14
+ local function SafeToString(value)
15
+ if IsSecret(value) then
16
+ return ns.L.TREE_SECRET
17
+ end
18
+
19
+ local valueType = type(value)
20
+ if valueType == "string" then
21
+ return string.format("%q", value)
22
+ elseif valueType == "number" or valueType == "boolean" or valueType == "nil" then
23
+ return tostring(value)
24
+ elseif valueType == "table" then
25
+ return ns.L.TREE_TABLE
26
+ end
27
+
28
+ local succeeded, text = pcall(tostring, value)
29
+ if succeeded then
30
+ return "<" .. valueType .. ": " .. text .. ">"
31
+ end
32
+ return "<" .. valueType .. ">"
33
+ end
34
+
35
+ local function SortKey(value)
36
+ if IsSecret(value) then
37
+ return "0:<secret>"
38
+ end
39
+
40
+ local valueType = type(value)
41
+ if valueType == "number" then
42
+ return "1:" .. string.format("%020.6f", value)
43
+ elseif valueType == "string" then
44
+ return "2:" .. value
45
+ elseif valueType == "boolean" then
46
+ return value and "3:1" or "3:0"
47
+ end
48
+ return "4:" .. valueType .. ":" .. SafeToString(value)
49
+ end
50
+
51
+ local function FormatKey(key)
52
+ if type(key) == "string" and key:match("^[%a_][%w_]*$") then
53
+ return key
54
+ end
55
+ return "[" .. SafeToString(key) .. "]"
56
+ end
57
+
58
+ local function MarkerNode(label, text)
59
+ return {
60
+ label = label,
61
+ kind = "marker",
62
+ value = text,
63
+ }
64
+ end
65
+
66
+ local function HasAncestorTable(parent, value)
67
+ while parent do
68
+ if parent.source == value then
69
+ return true
70
+ end
71
+ parent = parent.parent
72
+ end
73
+ return false
74
+ end
75
+
76
+ local function GetMethod(value, methodName)
77
+ if IsSecret(value) then
78
+ return nil
79
+ end
80
+ local succeeded, method = pcall(function()
81
+ return value[methodName]
82
+ end)
83
+ return succeeded and type(method) == "function" and method or nil
84
+ end
85
+
86
+ local function IsUIObject(value)
87
+ return GetMethod(value, "GetObjectType") ~= nil
88
+ end
89
+
90
+ local function CallMethod(value, methodName)
91
+ local method = GetMethod(value, methodName)
92
+ if not method then
93
+ return nil
94
+ end
95
+ local succeeded, result = pcall(method, value)
96
+ if not succeeded or IsSecret(result) then
97
+ return nil
98
+ end
99
+ return result
100
+ end
101
+
102
+ local function CollectMethodResults(value, methodName)
103
+ local method = GetMethod(value, methodName)
104
+ if not method then
105
+ return nil
106
+ end
107
+ local packed = { pcall(method, value) }
108
+ if not packed[1] then
109
+ return nil
110
+ end
111
+ local results = {}
112
+ for index = 2, #packed do
113
+ if packed[index] ~= nil and not IsSecret(packed[index]) then
114
+ results[#results + 1] = packed[index]
115
+ end
116
+ end
117
+ return results
118
+ end
119
+
120
+ local function BuildUIObjectOverview(value)
121
+ local overview = {
122
+ [ns.L.FRAME_LUA_TYPE] = type(value),
123
+ [ns.L.FRAME_OBJECT_TYPE] = CallMethod(value, "GetObjectType"),
124
+ [ns.L.FRAME_NAME] = CallMethod(value, "GetName"),
125
+ [ns.L.FRAME_SHOWN] = CallMethod(value, "IsShown"),
126
+ [ns.L.FRAME_WIDTH] = CallMethod(value, "GetWidth"),
127
+ [ns.L.FRAME_HEIGHT] = CallMethod(value, "GetHeight"),
128
+ [ns.L.FRAME_SCALE] = CallMethod(value, "GetEffectiveScale"),
129
+ [ns.L.FRAME_LEVEL] = CallMethod(value, "GetFrameLevel"),
130
+ [ns.L.FRAME_STRATA] = CallMethod(value, "GetFrameStrata"),
131
+ }
132
+ local parent = CallMethod(value, "GetParent")
133
+ if parent ~= nil then
134
+ overview[ns.L.FRAME_PARENT] = CallMethod(parent, "GetName") or SafeToString(parent)
135
+ end
136
+ return overview
137
+ end
138
+
139
+ local function BuildNode(label, value, parent)
140
+ if IsSecret(value) then
141
+ return MarkerNode(label, ns.L.TREE_SECRET)
142
+ end
143
+
144
+ local isUIObject = IsUIObject(value)
145
+ if type(value) ~= "table" and not isUIObject then
146
+ return {
147
+ label = label,
148
+ kind = type(value),
149
+ value = SafeToString(value),
150
+ source = value,
151
+ exportable = true,
152
+ parent = parent,
153
+ }
154
+ elseif HasAncestorTable(parent, value) then
155
+ return MarkerNode(label, ns.L.TREE_CYCLE)
156
+ end
157
+
158
+ return {
159
+ label = label,
160
+ kind = "table",
161
+ value = ns.L.TREE_TABLE,
162
+ children = {},
163
+ expanded = parent == nil,
164
+ source = value,
165
+ exportable = true,
166
+ isUIObject = isUIObject,
167
+ parent = parent,
168
+ cursor = nil,
169
+ loadedCount = 0,
170
+ secretKeyCount = 0,
171
+ hasMore = true,
172
+ loaded = false,
173
+ }
174
+ end
175
+
176
+ local function AddUIObjectNodes(node)
177
+ if not node.isUIObject then
178
+ return
179
+ end
180
+
181
+ node.children[#node.children + 1] = BuildNode(ns.L.FRAME_OVERVIEW, BuildUIObjectOverview(node.source), node)
182
+ node.loadedCount = node.loadedCount + 1
183
+
184
+ local children = CollectMethodResults(node.source, "GetChildren")
185
+ if children and #children > 0 then
186
+ node.children[#node.children + 1] = BuildNode(ns.L.FRAME_CHILDREN, children, node)
187
+ node.loadedCount = node.loadedCount + 1
188
+ end
189
+
190
+ local regions = CollectMethodResults(node.source, "GetRegions")
191
+ if regions and #regions > 0 then
192
+ node.children[#node.children + 1] = BuildNode(ns.L.FRAME_REGIONS, regions, node)
193
+ node.loadedCount = node.loadedCount + 1
194
+ end
195
+ end
196
+
197
+ local function RemoveLoadMoreNode(node)
198
+ local last = node.children[#node.children]
199
+ if last and last.kind == "load_more" then
200
+ node.children[#node.children] = nil
201
+ end
202
+ end
203
+
204
+ local function UpdateTableValue(node)
205
+ if node.hasMore then
206
+ node.value = string.format(ns.L.TREE_TABLE_MORE, node.loadedCount)
207
+ else
208
+ node.value = string.format(ns.L.TREE_TABLE_COUNT, node.loadedCount)
209
+ end
210
+ end
211
+
212
+ function ns.LoadMoreValueTreeNode(node)
213
+ if ns.IsCombatBlocked and ns.IsCombatBlocked() then
214
+ return false, ns.L.COMBAT_BLOCKED
215
+ elseif type(node) ~= "table" or node.kind ~= "table"
216
+ or (type(node.source) ~= "table" and not node.isUIObject) then
217
+ return false
218
+ elseif not node.hasMore then
219
+ return true
220
+ end
221
+
222
+ RemoveLoadMoreNode(node)
223
+ if not node.loaded then
224
+ AddUIObjectNodes(node)
225
+ end
226
+ local entries = {}
227
+ local cursor = node.cursor
228
+ local scanned = 0
229
+
230
+ while type(node.source) == "table" and #entries < PAGE_SIZE and scanned < MAX_SCANS_PER_PAGE do
231
+ local succeeded, key, value = pcall(next, node.source, cursor)
232
+ if not succeeded then
233
+ node.hasMore = false
234
+ node.children[#node.children + 1] = MarkerNode("...", ns.L.TREE_TABLE_CHANGED)
235
+ break
236
+ elseif key == nil then
237
+ node.hasMore = false
238
+ break
239
+ end
240
+
241
+ cursor = key
242
+ scanned = scanned + 1
243
+ if IsSecret(key) then
244
+ node.secretKeyCount = node.secretKeyCount + 1
245
+ else
246
+ entries[#entries + 1] = { key = key, value = value }
247
+ end
248
+ end
249
+ if type(node.source) ~= "table" then
250
+ node.hasMore = false
251
+ end
252
+
253
+ table.sort(entries, function(left, right)
254
+ return SortKey(left.key) < SortKey(right.key)
255
+ end)
256
+ for index = 1, #entries do
257
+ local entry = entries[index]
258
+ node.children[#node.children + 1] = BuildNode(FormatKey(entry.key), entry.value, node)
259
+ node.loadedCount = node.loadedCount + 1
260
+ end
261
+
262
+ node.cursor = cursor
263
+ node.loaded = true
264
+ if node.hasMore then
265
+ node.children[#node.children + 1] = {
266
+ label = ns.L.TREE_LOAD_MORE,
267
+ kind = "load_more",
268
+ value = ns.L.TREE_LOAD_NEXT,
269
+ owner = node,
270
+ }
271
+ elseif node.secretKeyCount > 0 then
272
+ node.children[#node.children + 1] = MarkerNode("...", string.format(ns.L.TREE_SECRET_KEYS, node.secretKeyCount))
273
+ end
274
+ UpdateTableValue(node)
275
+ return true
276
+ end
277
+
278
+ function ns.CreateValueTree(values)
279
+ if type(values) ~= "table" or type(values.n) ~= "number" or values.n <= 0 then
280
+ return nil
281
+ end
282
+
283
+ local roots = {}
284
+ for index = 1, values.n do
285
+ local node = BuildNode("[" .. index .. "]", values[index], nil)
286
+ roots[#roots + 1] = node
287
+ if node.kind == "table" then
288
+ ns.LoadMoreValueTreeNode(node)
289
+ end
290
+ end
291
+
292
+ return {
293
+ roots = roots,
294
+ truncated = false,
295
+ }
296
+ end
297
+
298
+ local function TrimStoredText(value)
299
+ value = tostring(value or "")
300
+ if #value <= STORED_MAX_VALUE_BYTES then
301
+ return value
302
+ end
303
+ return value:sub(1, STORED_MAX_VALUE_BYTES) .. "..."
304
+ end
305
+
306
+ local function BuildStoredNode(label, value, context, depth)
307
+ if context.count >= STORED_MAX_NODES then
308
+ context.truncated = true
309
+ return nil
310
+ end
311
+ context.count = context.count + 1
312
+
313
+ if IsSecret(value) then
314
+ return MarkerNode(label, ns.L.TREE_SECRET)
315
+ end
316
+
317
+ local isUIObject = IsUIObject(value)
318
+ if type(value) ~= "table" and not isUIObject then
319
+ return {
320
+ label = label,
321
+ kind = type(value),
322
+ value = TrimStoredText(SafeToString(value)),
323
+ }
324
+ elseif context.ancestors[value] then
325
+ return MarkerNode(label, ns.L.TREE_CYCLE)
326
+ end
327
+
328
+ local node = {
329
+ label = label,
330
+ kind = "table",
331
+ value = ns.L.TREE_TABLE,
332
+ children = {},
333
+ expanded = depth == 0,
334
+ loaded = true,
335
+ hasMore = false,
336
+ }
337
+ if depth >= STORED_MAX_DEPTH then
338
+ context.truncated = true
339
+ node.children[1] = MarkerNode("...", ns.L.TREE_STORED_TRUNCATED)
340
+ node.value = string.format(ns.L.TREE_TABLE_COUNT, 0)
341
+ return node
342
+ end
343
+
344
+ context.ancestors[value] = true
345
+ local entries = {}
346
+ if isUIObject then
347
+ entries[1] = { key = ns.L.FRAME_OVERVIEW, value = BuildUIObjectOverview(value) }
348
+ end
349
+ if type(value) == "table" then
350
+ local cursor
351
+ while #entries < STORED_MAX_ENTRIES and context.count + #entries < STORED_MAX_NODES do
352
+ local succeeded, key, childValue = pcall(next, value, cursor)
353
+ if not succeeded or key == nil then
354
+ break
355
+ end
356
+ cursor = key
357
+ if not IsSecret(key) then
358
+ entries[#entries + 1] = { key = key, value = childValue }
359
+ end
360
+ end
361
+ if cursor ~= nil then
362
+ local succeeded, nextKey = pcall(next, value, cursor)
363
+ if succeeded and nextKey ~= nil then
364
+ context.truncated = true
365
+ end
366
+ end
367
+ end
368
+
369
+ table.sort(entries, function(left, right)
370
+ return SortKey(left.key) < SortKey(right.key)
371
+ end)
372
+ for index = 1, #entries do
373
+ local entry = entries[index]
374
+ local child = BuildStoredNode(FormatKey(entry.key), entry.value, context, depth + 1)
375
+ if not child then
376
+ context.truncated = true
377
+ break
378
+ end
379
+ node.children[#node.children + 1] = child
380
+ end
381
+ context.ancestors[value] = nil
382
+
383
+ if context.truncated and #node.children < STORED_MAX_ENTRIES
384
+ and context.count < STORED_MAX_NODES then
385
+ node.children[#node.children + 1] = MarkerNode("...", ns.L.TREE_STORED_TRUNCATED)
386
+ end
387
+ node.value = string.format(ns.L.TREE_TABLE_COUNT, #node.children)
388
+ return node
389
+ end
390
+
391
+ function ns.CreateStoredValueTree(values)
392
+ if type(values) ~= "table" or type(values.n) ~= "number" or values.n <= 0 then
393
+ return nil
394
+ end
395
+
396
+ local context = {
397
+ count = 0,
398
+ truncated = false,
399
+ ancestors = {},
400
+ }
401
+ local roots = {}
402
+ for index = 1, values.n do
403
+ local node = BuildStoredNode("[" .. index .. "]", values[index], context, 0)
404
+ if not node then
405
+ break
406
+ end
407
+ roots[#roots + 1] = node
408
+ end
409
+ if context.truncated and #roots == 0 then
410
+ roots[1] = MarkerNode("...", ns.L.TREE_STORED_TRUNCATED)
411
+ end
412
+ return {
413
+ roots = roots,
414
+ truncated = context.truncated,
415
+ }
416
+ end
417
+
418
+ local function SkipSerializedWhitespace(text, position)
419
+ while position <= #text do
420
+ local character = text:sub(position, position)
421
+ if character ~= " " and character ~= "\t" and character ~= "\r" and character ~= "\n" then
422
+ break
423
+ end
424
+ position = position + 1
425
+ end
426
+ return position
427
+ end
428
+
429
+ local function TrimSerializedToken(text)
430
+ return text:match("^%s*(.-)%s*$") or ""
431
+ end
432
+
433
+ local function ScanSerializedQuoted(text, position)
434
+ local quote = text:sub(position, position)
435
+ local cursor = position + 1
436
+ while cursor <= #text do
437
+ local character = text:sub(cursor, cursor)
438
+ if character == "\\" then
439
+ cursor = cursor + 2
440
+ elseif character == quote then
441
+ return text:sub(position, cursor), cursor + 1
442
+ else
443
+ cursor = cursor + 1
444
+ end
445
+ end
446
+ return nil
447
+ end
448
+
449
+ local function ScanSerializedKey(text, position)
450
+ local startPosition = position
451
+ local braceDepth = 0
452
+ local bracketDepth = 0
453
+ while position <= #text do
454
+ local character = text:sub(position, position)
455
+ if character == "\"" or character == "'" then
456
+ local _, nextPosition = ScanSerializedQuoted(text, position)
457
+ if not nextPosition then
458
+ return nil
459
+ end
460
+ position = nextPosition
461
+ elseif character == "{" then
462
+ braceDepth = braceDepth + 1
463
+ position = position + 1
464
+ elseif character == "}" then
465
+ braceDepth = math.max(0, braceDepth - 1)
466
+ position = position + 1
467
+ elseif character == "[" then
468
+ bracketDepth = bracketDepth + 1
469
+ position = position + 1
470
+ elseif character == "]" then
471
+ if braceDepth == 0 and bracketDepth == 0 then
472
+ return TrimSerializedToken(text:sub(startPosition, position - 1)), position + 1
473
+ end
474
+ bracketDepth = math.max(0, bracketDepth - 1)
475
+ position = position + 1
476
+ else
477
+ position = position + 1
478
+ end
479
+ end
480
+ return nil
481
+ end
482
+
483
+ local function FormatSerializedKey(token)
484
+ local identifier = token:match('^"([_%a][_%w]*)"$') or token:match("^'([_%a][_%w]*)'$")
485
+ if identifier then
486
+ return identifier
487
+ end
488
+ return "[" .. token .. "]"
489
+ end
490
+
491
+ local function CreateSerializedScalarNode(label, token)
492
+ local kind
493
+ if token == "nil" then
494
+ kind = "nil"
495
+ elseif token == "true" or token == "false" then
496
+ kind = "boolean"
497
+ elseif tonumber(token) ~= nil then
498
+ kind = "number"
499
+ elseif token:sub(1, 1) == "<" then
500
+ kind = "marker"
501
+ else
502
+ kind = "string"
503
+ end
504
+ return {
505
+ label = label,
506
+ kind = kind,
507
+ value = TrimStoredText(token),
508
+ }
509
+ end
510
+
511
+ local ParseSerializedNode
512
+ ParseSerializedNode = function(text, position, label, context, depth)
513
+ if context.count >= STORED_MAX_NODES then
514
+ return nil
515
+ end
516
+ context.count = context.count + 1
517
+ position = SkipSerializedWhitespace(text, position)
518
+ local character = text:sub(position, position)
519
+
520
+ if character == "\"" or character == "'" then
521
+ local token, nextPosition = ScanSerializedQuoted(text, position)
522
+ if not token then
523
+ return nil
524
+ end
525
+ return CreateSerializedScalarNode(label, token), nextPosition
526
+ elseif character ~= "{" then
527
+ local startPosition = position
528
+ while position <= #text do
529
+ character = text:sub(position, position)
530
+ if character == "," or character == "\r" or character == "\n" or character == "}" then
531
+ break
532
+ end
533
+ position = position + 1
534
+ end
535
+ local token = TrimSerializedToken(text:sub(startPosition, position - 1))
536
+ if token == "" then
537
+ return nil
538
+ end
539
+ return CreateSerializedScalarNode(label, token), position
540
+ end
541
+
542
+ local node = {
543
+ label = label,
544
+ kind = "table",
545
+ value = ns.L.TREE_TABLE,
546
+ children = {},
547
+ expanded = depth == 0,
548
+ loaded = true,
549
+ hasMore = false,
550
+ }
551
+ position = position + 1
552
+ while position <= #text do
553
+ position = SkipSerializedWhitespace(text, position)
554
+ character = text:sub(position, position)
555
+ if character == "}" then
556
+ node.value = string.format(ns.L.TREE_TABLE_COUNT, #node.children)
557
+ return node, position + 1
558
+ elseif text:sub(position, position + 2) == "..." then
559
+ local lineEnd = text:find("[\r\n]", position)
560
+ local marker = TrimSerializedToken(text:sub(position, (lineEnd or (#text + 1)) - 1))
561
+ node.children[#node.children + 1] = MarkerNode("...", marker)
562
+ position = lineEnd or (#text + 1)
563
+ elseif character ~= "[" then
564
+ return nil
565
+ else
566
+ local keyToken, nextPosition = ScanSerializedKey(text, position + 1)
567
+ if not keyToken then
568
+ return nil
569
+ end
570
+ position = SkipSerializedWhitespace(text, nextPosition)
571
+ if text:sub(position, position) ~= "=" then
572
+ return nil
573
+ end
574
+ local child
575
+ child, position = ParseSerializedNode(text, position + 1,
576
+ FormatSerializedKey(keyToken), context, depth + 1)
577
+ if not child then
578
+ return nil
579
+ end
580
+ node.children[#node.children + 1] = child
581
+ position = SkipSerializedWhitespace(text, position)
582
+ if text:sub(position, position) == "," then
583
+ position = position + 1
584
+ end
585
+ end
586
+ end
587
+ return nil
588
+ end
589
+
590
+ local function ParseSerializedRootHeader(text, position, expectedIndex)
591
+ if text:sub(position, position) ~= "[" then
592
+ return nil
593
+ end
594
+ local closing = text:find("]", position + 1, true)
595
+ if not closing or tonumber(text:sub(position + 1, closing - 1)) ~= expectedIndex then
596
+ return nil
597
+ end
598
+ position = SkipSerializedWhitespace(text, closing + 1)
599
+ if text:sub(position, position) ~= "=" then
600
+ return nil
601
+ end
602
+ return position + 1
603
+ end
604
+
605
+ function ns.CreateStoredTreeFromSerialized(text)
606
+ if type(text) ~= "string" or text == "" then
607
+ return nil
608
+ end
609
+
610
+ local position = text:find("^%[1%]%s*=")
611
+ if not position then
612
+ local lineStart = text:find("\n%[1%]%s*=")
613
+ position = lineStart and lineStart + 1 or nil
614
+ end
615
+ if not position then
616
+ return nil
617
+ end
618
+
619
+ local context = { count = 0 }
620
+ local roots = {}
621
+ local rootIndex = 1
622
+ while position and position <= #text do
623
+ position = ParseSerializedRootHeader(text, position, rootIndex)
624
+ if not position then
625
+ break
626
+ end
627
+ local node
628
+ node, position = ParseSerializedNode(text, position, "[" .. rootIndex .. "]", context, 0)
629
+ if not node then
630
+ return nil
631
+ end
632
+ roots[#roots + 1] = node
633
+ rootIndex = rootIndex + 1
634
+ position = SkipSerializedWhitespace(text, position)
635
+ if text:sub(position, position) ~= "[" then
636
+ break
637
+ end
638
+ end
639
+
640
+ if #roots == 0 then
641
+ return nil
642
+ end
643
+ return {
644
+ roots = roots,
645
+ truncated = false,
646
+ }
647
+ end