Repository navigation
Expand file tree
/
Copy pathmain.lua
More file actions
249 lines (229 loc) · 9.86 KB
/
Copy pathmain.lua
File metadata and controls
249 lines (229 loc) · 9.86 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
-- World Explorer (API 6): tabbed browser for Wave 15 definition tables and Wave 16 live readers/hooks.
local TABLES = { 'Items', 'Characters', 'Skills', 'Buffs', 'Quests', 'Stores', 'Craft Tools' }
local MAX_ROWS = 50
local state = {
table_idx = 2,
query = '',
cursor = 0,
next_cursor = nil,
faction_a = 1,
faction_b = 2,
cool_hook_on = false,
cool_mult = 0.50,
loot_hook_on = false,
loot_mult = 2.00,
}
local cool_handle = nil
local loot_handle = nil
local function clamp_text(s, limit)
local txt = tostring(s or '')
if #txt <= limit then return txt end
return string.sub(txt, 1, limit - 3) .. '...'
end
local panel = bsx.ui.panel('World Explorer (API 6)')
local table_summary_lbl
local table_listbox_id
local table_rows_cache = {}
local buffs_lbl, quests_lbl, sublevels_lbl, dyes_lbl, visuals_lbl, agreement_lbl, hooks_lbl
local function run_table_search(next_page)
local kind = TABLES[state.table_idx] or 'Characters'
local cur = next_page and (state.next_cursor or 0) or 0
state.cursor = cur
local rows, next_or_err
if kind == 'Items' then
local ok, r, e = pcall(game.items.find, state.query, MAX_ROWS, cur)
rows = ok and r or nil
next_or_err = ok and e or r
elseif kind == 'Characters' then
local ok, r, e = pcall(game.characters.find, state.query, MAX_ROWS, cur)
rows, next_or_err = ok and r or nil, ok and e or r
elseif kind == 'Skills' then
local ok, r, e = pcall(game.skills.find, state.query, MAX_ROWS, cur)
rows, next_or_err = ok and r or nil, ok and e or r
elseif kind == 'Buffs' then
local ok, r, e = pcall(game.buffs.find, state.query, MAX_ROWS, cur)
rows, next_or_err = ok and r or nil, ok and e or r
elseif kind == 'Quests' then
local ok, r, e = pcall(game.quests.find, state.query, MAX_ROWS, cur)
rows, next_or_err = ok and r or nil, ok and e or r
elseif kind == 'Stores' then
local ok, r, e = pcall(game.stores.find, state.query, MAX_ROWS, cur)
rows, next_or_err = ok and r or nil, ok and e or r
else
local ok, r, e = pcall(game.craft_tools.find, state.query, MAX_ROWS, cur)
rows, next_or_err = ok and r or nil, ok and e or r
end
if type(next_or_err) == 'number' then
state.next_cursor = next_or_err
else
state.next_cursor = nil
end
if panel and table_summary_lbl then
if type(rows) == 'table' then
local nxt = state.next_cursor and ('next=' .. tostring(state.next_cursor)) or 'end'
panel:set_text(table_summary_lbl, clamp_text(string.format('%s: %d rows (%s)', kind, #rows, nxt), 118))
else
panel:set_text(table_summary_lbl, clamp_text(kind .. ': unavailable (' .. tostring(next_or_err) .. ')', 118))
end
end
table_rows_cache = type(rows) == 'table' and rows or {}
if panel and table_listbox_id then
local list_items = {}
if type(rows) == 'table' and #rows > 0 then
for i = 1, #rows do
local r = rows[i]
local disp = r.display_name
local internal = r.name or r.internal_name
local title = (disp and disp ~= '' and internal and disp ~= internal)
and (tostring(disp) .. ' (' .. tostring(internal) .. ')')
or tostring(disp or internal or '-')
local id_str = tostring(r.row or r.id or i)
local key_str = r.key and ('key=' .. tostring(r.key)) or kind
list_items[#list_items + 1] = {
label = clamp_text(string.format('#%s %s', id_str, title), 110),
category = clamp_text(key_str, 40),
}
end
else
list_items[1] = { label = '(no matching rows)', category = kind }
end
panel:set_items(table_listbox_id, list_items, 1)
end
end
local function refresh_world_state()
local ok_b, buffs, b_err = pcall(game.buffs.active)
local ok_q, quests, q_err = pcall(game.quests.active)
local ok_s, subs, s_err = pcall(game.skills.sublevels)
local ok_d, dyes, d_err = pcall(game.appearance.equipped_dyes)
local ok_v, visuals, v_err = pcall(game.appearance.visual_items)
local ok_f, ag, f_err = pcall(game.factions.agreement, math.floor(state.faction_a), math.floor(state.faction_b))
if panel and buffs_lbl then
local msg = (ok_b and type(buffs) == 'table') and ('Active Buffs: ' .. #buffs .. (buffs[1] and (' (' .. tostring(buffs[1].name or buffs[1].buff_row) .. ')') or '')) or ('Active Buffs: ' .. tostring(b_err))
panel:set_text(buffs_lbl, clamp_text(msg, 118))
end
if panel and quests_lbl then
local done = 0
if ok_q and type(quests) == 'table' then
for _, q in ipairs(quests) do if q.completed then done = done + 1 end end
panel:set_text(quests_lbl, clamp_text(string.format('Quests observed: %d (%d completed)', #quests, done), 118))
else
panel:set_text(quests_lbl, clamp_text('Quests observed: ' .. tostring(q_err), 118))
end
end
if panel and sublevels_lbl then
local msg = (ok_s and type(subs) == 'table') and ('Active Skill Sublevels: ' .. #subs .. (subs[1] and (' (key ' .. tostring(subs[1].key) .. ' lv ' .. tostring(subs[1].level) .. ')') or '')) or ('Skill Sublevels: ' .. tostring(s_err))
panel:set_text(sublevels_lbl, clamp_text(msg, 118))
end
if panel and dyes_lbl then
local msg = (ok_d and type(dyes) == 'table') and ('Equipped Dye Slots: ' .. #dyes) or ('Equipped Dyes: ' .. tostring(d_err))
panel:set_text(dyes_lbl, clamp_text(msg, 118))
end
if panel and visuals_lbl then
local msg = (ok_v and type(visuals) == 'table') and ('Visual Equip Slots: ' .. #visuals) or ('Visual Slots: ' .. tostring(v_err))
panel:set_text(visuals_lbl, clamp_text(msg, 118))
end
if panel and agreement_lbl then
local tag = ag == 3 and 'Allied' or (ag == 4 and 'Neutral' or (ag == 5 and 'Unknown' or tostring(ag)))
local msg = (ok_f and ag ~= nil) and string.format('Faction %d vs %d: %s (%d)', state.faction_a, state.faction_b, tag, ag) or ('Faction Agreement: ' .. tostring(f_err))
panel:set_text(agreement_lbl, clamp_text(msg, 118))
end
return {
buffs = (ok_b and type(buffs) == 'table') and #buffs or -1,
quests = (ok_q and type(quests) == 'table') and #quests or -1,
sublevels = (ok_s and type(subs) == 'table') and #subs or -1,
dyes = (ok_d and type(dyes) == 'table') and #dyes or -1,
visuals = (ok_v and type(visuals) == 'table') and #visuals or -1,
}
end
local function sync_hooks()
if cool_handle then
cool_handle:remove()
cool_handle = nil
end
if loot_handle then
loot_handle:remove()
loot_handle = nil
end
local status_parts = {}
if state.cool_hook_on then
local h, err = game.hooks.add('on_item_cooldown', { mult = state.cool_mult })
cool_handle = h
status_parts[#status_parts + 1] = h and string.format('cooldown=%.2fx', state.cool_mult) or ('cooldown err=' .. tostring(err))
end
if state.loot_hook_on then
local h, err = game.hooks.add('on_loot_drop', { mult = state.loot_mult })
loot_handle = h
status_parts[#status_parts + 1] = h and string.format('loot=%.2fx', state.loot_mult) or ('loot err=' .. tostring(err))
end
if panel and hooks_lbl then
local msg = #status_parts > 0 and table.concat(status_parts, ', ') or 'Hooks idle (enable toggles above)'
panel:set_text(hooks_lbl, clamp_text(msg, 118))
end
end
if panel then
panel:begin_tab_bar('wx_tabs')
panel:tab('Tables')
panel:combo('Table', TABLES, state.table_idx, function(idx)
state.table_idx = idx
run_table_search(false)
end)
panel:input_text('Query (name/row/key)', state.query, function(q)
state.query = q or ''
run_table_search(false)
end)
panel:button('Search', function() run_table_search(false) end)
panel:same_line()
panel:button('Next Page', function() run_table_search(true) end)
table_summary_lbl = panel:text('Select Search to query table rows')
table_listbox_id = panel:listbox('Table Rows', { { label = '(loading...)', category = 'Table' } }, { height = 220, searchable = true }, function(idx)
local r = table_rows_cache[idx]
if r and table_summary_lbl then
local title = r.display_name or r.name or r.internal_name or '-'
panel:set_text(table_summary_lbl, clamp_text(string.format('Selected #%s key=%s %s', tostring(r.row or r.id or idx), tostring(r.key or '-'), tostring(title)), 118))
end
end)
panel:end_tab()
panel:tab('Player & World')
panel:button('Refresh Snapshot Readers', function() refresh_world_state() end)
buffs_lbl = panel:text('Active Buffs: waiting for world_ready')
quests_lbl = panel:text('Quests observed: waiting for world_ready')
sublevels_lbl = panel:text('Skill Sublevels: waiting for world_ready')
dyes_lbl = panel:text('Equipped Dyes: waiting for world_ready')
visuals_lbl = panel:text('Visual Slots: waiting for world_ready')
panel:slider('Faction A', 0, 20, state.faction_a, function(v)
state.faction_a = math.floor(v + 0.5)
refresh_world_state()
end)
panel:slider('Faction B', 0, 20, state.faction_b, function(v)
state.faction_b = math.floor(v + 0.5)
refresh_world_state()
end)
agreement_lbl = panel:text('Faction Agreement: waiting')
panel:end_tab()
panel:tab('API 6 Hooks')
hooks_lbl = panel:text('Hooks idle (enable toggles above)')
panel:checkbox('Scale Item Cooldowns', state.cool_hook_on, function(v)
state.cool_hook_on = (v == true)
sync_hooks()
end)
panel:slider('Cooldown Multiplier', 0.1, 2.0, state.cool_mult, function(v)
state.cool_mult = v
if state.cool_hook_on then sync_hooks() end
end)
panel:checkbox('Scale Loot Drop Rate', state.loot_hook_on, function(v)
state.loot_hook_on = (v == true)
sync_hooks()
end)
panel:slider('Loot Drop Multiplier', 0.5, 5.0, state.loot_mult, function(v)
state.loot_mult = v
if state.loot_hook_on then sync_hooks() end
end)
panel:end_tab()
panel:end_tab_bar()
end
bsx.on('world_ready', function()
local summary = refresh_world_state()
run_table_search(false)
bsx.log(string.format('WORLD_EXPLORER_READY buffs=%d quests=%d sublevels=%d dyes=%d visuals=%d',
summary.buffs, summary.quests, summary.sublevels, summary.dyes, summary.visuals))
end)