-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.lua
More file actions
7447 lines (6509 loc) · 317 KB
/
Copy pathcore.lua
File metadata and controls
7447 lines (6509 loc) · 317 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
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
---@class core
_G.core = {}
---@alias game_objects_table game_object[]
---@alias item_slot_info_table item_slot_info[]
---@alias spell_costs_table spell_costs[]
---@alias buff_table buff[]
---@alias vec3_table vec3[]
---@alias vec2_table vec2[]
---@alias hit_data_table hit_data[]
---@alias consumable_data_table consumable_data[]
--- Log a message to the console.
---@param message string The message to log.
function core.log(message) end
--- Log a warning message to the console.
---@param message string The warning message to log.
function core.log_warning(message) end
--- Log an error message to the console.
---@param message string The error message to log.
function core.log_error(message) end
--- Register a function to be called before each tick.
---@param callback function The function to register as a pre-tick callback.
function core.register_on_pre_tick_callback(callback) end
--- Register a function to be called before each tick.
---@param callback function The function to register as a pre-tick callback.
function core.register_on_render_window_callback(callback) end
--- Register a function to be called during the update phase.
---@param callback function The function to register as an update callback.
function core.register_on_update_callback(callback) end
--- Register a function to be called during the rendering phase.
---@param callback function The function to register as a render callback.
function core.register_on_render_callback(callback) end
--- Register a function to be called during the rendering of menus.
---@param callback function The function to register as a render menu callback.
function core.register_on_render_menu_callback(callback) end
--- Register a function to be called to send control_panel data to core
---@param callback function The function to register as a control_panel callback
function core.register_on_render_control_panel_callback(callback) end
--- Register a function that triggers every time game registers a legit cast attempt
---@param callback function The function to register as a legit cast callback
function core.register_on_legit_spell_cast_callback(callback) end
---@class OnProcessSpellCastData
--- Defines the structure of the data table passed to the on_process_spell callback.
---@field spell_id number -- Unique identifier for the spell.
---@field caster game_object|nil -- The game object that cast the spell (or nil).
---@field target game_object|nil -- The game object targeted by the spell (or nil).
---@field spell_cast_time number -- The time when the spell was cast.
--- Registers a callback to be triggered when a spell is cast.
--- The callback function receives a OnProcessSpellCastData table as a parameter.
---@param callback fun(data: OnProcessSpellCastData): nil
function core.register_on_spell_cast_callback(callback) end
--- Registers a callback fired once per buffered WoW game event (drained each tick).
--- The callback receives the event name and a positional array of that event's arguments,
--- with original types preserved (string, number, boolean, or nil holes). Complex values
--- (table/function/userdata) arrive as their tostring() representation.
---
--- A nil argument leaves a HOLE in args rather than an entry, so the length operator is not a
--- reliable count for any payload with optional fields. Index positionally, never with ipairs.
---
--- The registration list is build_events_literal() in wow_core/src/core/game/event_pump.cpp
--- and that function is its only source of truth. As of 2026-09-19 (core 2.060) it is:
--- combat log COMBAT_LOG_EVENT_UNFILTERED
--- countdown START_PLAYER_COUNTDOWN, CANCEL_PLAYER_COUNTDOWN
--- spells SPELLS_CHANGED
--- spellcast UNIT_SPELLCAST_SENT, UNIT_SPELLCAST_START, UNIT_SPELLCAST_STOP,
--- UNIT_SPELLCAST_SUCCEEDED, UNIT_SPELLCAST_DELAYED, UNIT_SPELLCAST_FAILED,
--- UNIT_SPELLCAST_FAILED_QUIET, UNIT_SPELLCAST_INTERRUPTED,
--- UNIT_SPELLCAST_INTERRUPTIBLE, UNIT_SPELLCAST_NOT_INTERRUPTIBLE,
--- UNIT_SPELLCAST_CHANNEL_START, UNIT_SPELLCAST_CHANNEL_STOP,
--- UNIT_SPELLCAST_CHANNEL_UPDATE, UNIT_SPELLCAST_EMPOWER_START,
--- UNIT_SPELLCAST_EMPOWER_STOP, UNIT_SPELLCAST_EMPOWER_UPDATE,
--- UNIT_SPELLCAST_RETICLE_TARGET, UNIT_SPELLCAST_RETICLE_CLEAR,
--- UNIT_SPELLMISS, UNIT_SPELL_DIMINISH_CATEGORY_STATE_UPDATED
--- player PLAYER_EQUIPMENT_CHANGED, PLAYER_REGEN_ENABLED, PLAYER_REGEN_DISABLED,
--- PLAYER_STARTED_MOVING, PLAYER_STOPPED_MOVING, PLAYER_FLAGS_CHANGED,
--- PLAYER_LOGOUT
--- auras UNIT_AURA
--- confirms AUTOEQUIP_BIND_CONFIRM, EQUIP_BIND_CONFIRM, CONFIRM_BINDER, LOOT_BIND_CONFIRM
--- group GROUP_ROSTER_UPDATE, GROUP_JOINED, GROUP_LEFT
--- encounters ENCOUNTER_START, ENCOUNTER_END
--- challenge CHALLENGE_MODE_COMPLETED (retail only, no args: read the result with
--- core.world.get_challenge_completion_info)
--- talents CHARACTER_POINTS_CHANGED, CONFIRM_TALENT_WIPE, PLAYER_TALENT_UPDATE
--- (1.14+), TRAIT_CONFIG_UPDATED and TRAIT_NODE_CHANGED (retail 10.0+).
--- CONFIRM_TALENT_WIPE carries no args and is not a notification: the
--- trainer withholds the respec until core.game_ui.confirm_talent_wipe
--- answers it.
--- gossip GOSSIP_SHOW, GOSSIP_CLOSED
--- quests QUEST_GREETING, QUEST_DETAIL, QUEST_PROGRESS, QUEST_COMPLETE,
--- QUEST_FINISHED, QUEST_ACCEPTED, QUEST_TURNED_IN, QUEST_LOG_UPDATE,
--- QUEST_ITEM_UPDATE
--- chat CHAT_MSG_ADDON, CHAT_MSG_PARTY, CHAT_MSG_PARTY_LEADER
--- ui UI_ERROR_MESSAGE
--- auction AUCTION_HOUSE_SHOW, AUCTION_HOUSE_CLOSED, AUCTION_HOUSE_DISABLED,
--- AUCTION_HOUSE_NEW_RESULTS_RECEIVED, AUCTION_HOUSE_BROWSE_RESULTS_UPDATED,
--- AUCTION_HOUSE_BROWSE_RESULTS_ADDED, AUCTION_HOUSE_BROWSE_FAILURE,
--- AUCTION_HOUSE_FAVORITES_UPDATED, AUCTION_HOUSE_AUCTIONS_EXPIRED,
--- AUCTION_HOUSE_AUCTION_CREATED, AUCTION_HOUSE_THROTTLED_SYSTEM_READY,
--- AUCTION_CANCELED, OWNED_AUCTIONS_UPDATED, BIDS_UPDATED,
--- COMMODITY_SEARCH_RESULTS_UPDATED, COMMODITY_SEARCH_RESULTS_RECEIVED,
--- COMMODITY_PRICE_UPDATED, COMMODITY_PRICE_UNAVAILABLE,
--- COMMODITY_PURCHASE_SUCCEEDED, COMMODITY_PURCHASE_FAILED, COMMODITY_PURCHASED,
--- ITEM_SEARCH_RESULTS_UPDATED, ITEM_SEARCH_RESULTS_ADDED,
--- REPLICATE_ITEM_LIST_UPDATE, AUCTION_MULTISELL_START,
--- AUCTION_MULTISELL_UPDATE, AUCTION_MULTISELL_FAILURE
--- A name that does not exist on the current client is harmless, registration is pcall'd per
--- event, which is why the one list serves every game version.
---
--- Two events do not carry the WoW event's own arguments, because their real payload is either
--- unserializable or unreachable from a plugin:
---
--- COMBAT_LOG_EVENT_UNFILTERED: args are the flattened CombatLogGetCurrentEventInfo() payload
--- (timestamp, sub_event, hide_caster, source_guid, ...), not the raw event varargs.
---
--- UNIT_AURA: retail 9.0+ fires (unit, update_info) where update_info is a table, and aura data
--- is readable only inside WoW's secure environment. The core unpacks it there and emits ONE
--- RECORD PER AURA, so this callback runs many times per game event, tagged in args[1]:
--- "full" { "full", unit }
--- The unit's entire aura set was resent. Drop what you hold for that unit; a
--- burst of "added" records for it follows immediately in the same drain.
--- "added" { "added", unit, instance_id, spell_id, name, stacks, duration,
--- expiration_time, source_unit, is_helpful, is_harmful, dispel_name }
--- "updated" the same 12 fields, already re-queried by aura instance id
--- "removed" { "removed", unit, instance_id }
--- instance_id is the client's stable aura handle: it survives while the aura lives and is the
--- only thing "updated" and "removed" name, unlike the per-unit slot index which is reused as
--- soon as an aura fades. unit and source_unit are WoW unit TOKENS, not GUIDs; resolve them
--- with core.object_manager.get_object_from_guid, which accepts a token. source_unit is nil
--- when the client does not know the caster. duration and expiration_time are seconds on WoW's
--- GetTime() clock, NOT the core.game_time() milliseconds that game_object:get_buffs() uses.
--- Pre-9.0 clients have no update_info table, so args is just { unit }: no sub-type, no aura
--- fields, no instance id anywhere. playground_events/main.lua is a worked example of all of it.
---
--- The UNIT_SPELLCAST_* family, added 2026-09-01, is twenty events with one shape and several
--- traps. args[1] is always the CASTER'S unit token, despite Blizzard naming that parameter
--- unitTarget, and the common payload after it is { cast_guid, spell_id }:
--- { unit, cast_guid, spell_id } START, STOP, SUCCEEDED, DELAYED, FAILED,
--- FAILED_QUIET, INTERRUPTED, CHANNEL_START,
--- CHANNEL_STOP, CHANNEL_UPDATE, EMPOWER_START,
--- EMPOWER_UPDATE
--- { unit, cast_guid, spell_id, complete } EMPOWER_STOP
--- { unit } INTERRUPTIBLE, NOT_INTERRUPTIBLE
--- { unit, target_name, cast_guid, spell_id } SENT
--- SENT is the odd one twice over. Its second arg is the target's NAME, a plain string and not
--- a token, which pushes cast_guid and spell_id to 3 and 4; and it only ever fires for units
--- you control (player, pet, vehicle), because it reports the request your own client sent
--- rather than something it observed. Every other name in the family fires for any unit.
---
--- What will cost you an hour:
--- - unit is a TOKEN ("target", "arena2", "nameplate7"), never a GUID, and tokens are
--- recycled. Resolve with core.object_manager.get_object_from_guid, which accepts a token,
--- and store the GUID. Same rule and same reason as UNIT_AURA above.
--- - cast_guid is nil on the three CHANNEL_ events, so args[2] is a HOLE there and spell_id
--- is still at args[3]. #args lies. Key channels by unit plus spell_id.
--- - STOP does not mean the cast worked. It fires on completion, on self-cancel and on a
--- kick alike. SUCCEEDED is the completion signal. INTERRUPTED is caster-side and covers
--- moving and cancelling as well as being kicked, so for kick ATTRIBUTION use the combat
--- log SPELL_INTERRUPT sub-event, which names both sides.
--- - INTERRUPTIBLE and NOT_INTERRUPTIBLE carry only the unit. They say the flag on that
--- unit's current cast changed; they do not say which cast, so they are useless unless
--- you are already holding it.
--- - A channel reports SUCCEEDED BEFORE CHANNEL_START. The usual orders are
--- hard cast SENT -> START -> (DELAYED) -> SUCCEEDED -> STOP
--- channel SENT -> SUCCEEDED -> CHANNEL_START -> CHANNEL_UPDATE* -> CHANNEL_STOP
--- and an instant is SENT -> SUCCEEDED with no START at all. Records go into one buffer
--- and drain front to back, so the order you receive is the order they fired.
--- - Volume. These register with RegisterEvent, not RegisterUnitEvent, so every unit the
--- client has a frame for reports: target, focus, party, raid, arena, boss and every
--- nameplate. SUCCEEDED and START are the busy ones in a raid. Filter on the first line
--- of the handler, not after the work.
---
--- The EMPOWER_ and RETICLE_ names are retail only and UNIT_SPELL_DIMINISH_CATEGORY_STATE_UPDATED
--- is newer than both, so on the classic branches they simply never bind and never fire.
--- UNVERIFIED on this core, past args[1]: both RETICLE_ events, UNIT_SPELLMISS (believed
--- { unit, cast_guid, spell_id, miss_type }) and the DIMINISH event. The spellcast probe in
--- playground_events/main.lua dumps raw args for the whole family; run it and read the log
--- before trusting those positions.
---
--- You often do not need these events at all. game_object polls the same state:
--- is_casting_spell, get_active_spell_id, get_active_spell_target,
--- get_active_spell_cast_start_time/end_time, is_active_spell_interruptable,
--- is_channelling_spell, get_active_channel_spell_id and the empower stage accessors. Those
--- answer "what is this unit casting right now" on the core.game_time() millisecond clock and
--- are what a rotation should use. The events are for what polling cannot give you: the exact
--- frame of an edge, cast_guid identity tying START to SUCCEEDED or INTERRUPTED, and units you
--- are not already iterating.
---
--- The four confirms are a different kind of event and worth reading as a group. They are not
--- notifications of something that happened, they report an action the engine has WITHHELD and is
--- holding open until it is answered. Each has exactly one call that releases it, and until that
--- call arrives the client sits there:
--- AUTOEQUIP_BIND_CONFIRM { inventory_slot } -> core.input.equip_pending_item(inventory_slot)
--- EQUIP_BIND_CONFIRM { inventory_slot } -> core.input.equip_pending_item(inventory_slot)
--- CONFIRM_BINDER { binder_name } -> core.input.confirm_binder()
--- LOOT_BIND_CONFIRM { loot_slot } -> core.input.confirm_loot_slot(loot_slot - 1)
--- Blizzard's default UI answers all four from popup accept buttons, which is why they look like
--- UI concerns. LOOT_BIND_CONFIRM reports WoW's 1 based loot slot while confirm_loot_slot takes
--- the 0 based one the rest of the loot API uses, hence the subtraction. The two equip confirms
--- are also latched by the core, so core.game_ui.get_pending_equip_slot answers the same slot
--- outside the callback. playground_items/main.lua is the worked example.
---
--- The gossip and quest names were added 2026-08-30. A plugin cannot ask for an event the pump
--- does not register: this callback delivers the list above and nothing else, and there is no
--- Lua-side subscribe to fail loudly, so before that commit the whole pick-up/turn-in sequence
--- had to be polled. GOSSIP_SHOW and GOSSIP_CLOSED bracket the frame
--- the gossip readers see; QUEST_DETAIL, QUEST_PROGRESS and QUEST_COMPLETE are the three panel
--- states; QUEST_GREETING is the classic multi-quest picker with no retail equivalent. Read
--- the GOSSIP ACROSS GAME VERSIONS block further down this file before using any of it, and
--- prefer common/izi_sdk/izi_gossip.lua, which normalizes the retail and private-server
--- shapes.
---@param callback fun(event_name: string, args: (string|number|boolean|nil)[]): nil
function core.register_on_game_event_callback(callback) end
--- Get the current ping.
---@return number The current ping.
function core.get_ping()
return 0
end
--- Get the current time in seconds since the injection time.
---@return number The current time in seconds.
function core.time()
return 0
end
--- Useful for profiling
---@return number
function core.cpu_ticks()
return 0
end
--- Useful for profiling
---@return number
function core.cpu_ticks_per_second()
return 0
end
--- Returns a high-resolution CPU timestamp in nanoseconds. Useful for profiling.
---@return number nanoseconds The CPU time in nanoseconds.
function core.cpu_time()
return 0
end
--- Get the current game time in milliseconds since the start of the game.
---@return number The current game time in milliseconds.
function core.game_time()
return 0
end
--- Get the time in seconds since the last frame.
---@return number The time in seconds since the last frame.
function core.delta_time()
return 0
end
--- Get the screen position of cursor.
---@return vec2 The screen position of cursor.
function core.get_cursor_position()
return {}
end
--- Get the id of the current localplayer map.
---@return number The id of the current localplayer map.
function core.get_map_id()
return 0
end
---@return number
function core.get_instance_id()
return 0
end
---@return number
function core.get_difficulty_id()
return 0
end
--- Returns the level of the keystone the player is CARRYING. 0 when they hold none, and 0
--- on every non-retail client.
---@return number
function core.get_keystone_level()
return 0
end
--- Returns the challenge map id of the keystone the player is CARRYING. 0 when they hold
--- none, and 0 on every non-retail client. Pair it with core.get_keystone_level: the two
--- together are what identify a key.
---
--- This is not core.world.get_active_challenge_map_id, which answers the dungeon of the run
--- you are standing in. This one answers the key in your bag, which is usually a different
--- dungeon and exists while you are in no run at all.
---
--- It is also how you fill in your own row after core.game_ui.request_party_keystones: you
--- never receive your own addon message, so the party broadcast returns everybody's key
--- except yours.
---@return number
function core.get_keystone_map_id()
return 0
end
---@return string
function core.get_instance_name()
return ""
end
---@return string
function core.get_difficulty_name()
return ""
end
---@return string
function core.get_instance_type()
return ""
end
--- Get the name of the current localplayer map.
---@return string The name of the current localplayer map.
function core.get_map_name()
return ""
end
---@return number
---@param pos vec3
function core.get_height_for_position(pos)
return 0
end
--- True while the menu is actually on screen: shown and not minimized. Same
--- answer as core.graphics.is_menu_open() - core_lua repoints both at the Lua
--- menu's `menu:is_surface_open()` at boot, and the same caching caveat applies.
--- Note the name: this one is `is_main_menu_open` on the core table, NOT
--- `is_menu_open`; `core.is_menu_open` does not exist.
---@return boolean
function core.is_main_menu_open()
return false
end
---@return string
---Returns "Midnight", "Tbc", "Vanilla", "Mop", "Titan"
function core.get_game_version()
return ""
end
--- Returns the exact game version string (e.g. "wow_tbc_cn", "wow_tbc_ps", "wow_tbc_us", "wow_titan_cn", "wow_midnight_us").
---@return string version The exact game version.
function core.get_exact_game_version()
return ""
end
---@return string
---Returns "West", "China"
function core.get_game_region()
return ""
end
---@return nil
--- Set Game Window Foremost
function core.set_window_foremost()
return nil
end
--------------------------------------------------------------------------------
-- Sandbox file I O
--
-- This scripting environment is sandboxed on purpose to prevent malicious code.
-- You can only interact with files in two allowed locations:
--
-- 1) Game files, inside the World of Warcraft installation folder
-- Used by: core.read_file, core.read_file_partial, core.get_file_size
--
-- 2) Loader data files, inside the loader's scripts_data folder
-- Used by: core.create_data_file, core.create_data_folder, core.write_data_file
-- core.read_data_file, core.read_data_file_partial, core.get_data_file_size
--
-- Any attempt to access files outside these locations will fail.
--------------------------------------------------------------------------------
--- Reads the entire contents of a sandboxed game file.
---
--- Sandbox scope:
--- - Only files inside the World of Warcraft installation folder are accessible.
--- - Any path outside the WoW folder is blocked.
---
--- Path rules:
--- - `filename` is treated as a path inside the WoW folder.
--- - Use relative-style paths such as `Data/...` or `_retail_/...` depending on your client layout.
---
--- Returns:
--- - On success: the full file contents as a Lua string.
--- - On failure: typically an empty string or nil depending on native implementation.
---
--- Example:
--- ```lua
--- local text = core.read_file("_retail_/WTF/Config.wtf")
--- print("Config length:", #text)
--- ```
---
---@param filename string Path inside the World of Warcraft folder (UTF-8).
---@return string data The file contents as a Lua string.
function core.read_file(filename)
return ""
end
--- Reads a core-packaged asset using a safe path relative to the asset root.
--- Development builds read the plain asset directory; production builds read
--- the encrypted asset store. Absolute paths and traversal are rejected.
---@param relative_path string
---@return string|nil data
function core.read_asset_file(relative_path)
return nil
end
--- Reads a portion of a sandboxed game file, starting at a byte offset.
---
--- Sandbox scope:
--- - Only files inside the World of Warcraft installation folder are accessible.
--- - Any path outside the WoW folder is blocked.
--- - Returns nil if the file cannot be read (missing, outside scope, access denied, etc).
---
--- Path rules:
--- - `filename` is treated as a path inside the WoW folder.
--- - Use relative-style paths such as `Data/...` or `_retail_/...` depending on your client layout.
---
--- Notes:
--- - `offset` and `size_to_read` are in bytes.
--- - The returned string can contain binary data and may include zero bytes.
---
--- Example:
--- ```lua
--- local p = "_retail_/WTF/Config.wtf"
--- local chunk = core.read_file_partial(p, 0, 64)
--- if chunk then
--- print("First 64 bytes:", chunk)
--- else
--- print("Read failed (outside sandbox, missing, or access denied).")
--- end
--- ```
---
---@param filename string Path inside the World of Warcraft folder (UTF-8).
---@param offset integer Byte offset to start reading from.
---@param size_to_read integer Number of bytes to read.
---@return string|nil data The read bytes as a Lua string, or nil on failure.
function core.read_file_partial(filename, offset, size_to_read)
return ""
end
--- Gets the size of a sandboxed game file in bytes.
---
--- Sandbox scope:
--- - Only files inside the World of Warcraft installation folder are accessible.
--- - Any path outside the WoW folder is blocked.
---
--- Notes:
--- - If the file does not exist or is not accessible, the native side may return 0.
--- - If you need to distinguish "missing" vs "empty file", attempt a small read as well.
---
--- Example:
--- ```lua
--- local p = "_retail_/WTF/Config.wtf"
--- local size = core.get_file_size(p)
--- if size > 0 then
--- print("Config size:", size)
--- else
--- print("Missing, blocked, or empty file.")
--- end
--- ```
---
---@param filename string Path inside the World of Warcraft folder (UTF-8).
---@return integer size The file size in bytes.
function core.get_file_size(filename)
return 0
end
--- Creates a new data file inside the loader's `scripts_data/` directory.
---
--- Sandbox scope:
--- - Data files are stored under: `<loader_path>/scripts_data/`
--- - Only this directory is writable by scripts (by design).
---
--- Path rules:
--- - `filename` is relative to `scripts_data/`.
--- - Do not prefix with `scripts_data/` yourself.
---
--- Notes:
--- - Parent folders should exist. Use core.create_data_folder for subfolders if needed.
---
--- Example:
--- ```lua
--- core.create_data_file("settings.json")
--- core.write_data_file("settings.json", "{}")
--- ```
---
---@param filename string Path inside `scripts_data/` (UTF-8), relative to the loader data directory.
---@return nil
function core.create_data_file(filename)
return nil
end
--- Creates a folder inside the loader's `scripts_data/` directory.
---
--- Sandbox scope:
--- - Folders are created under: `<loader_path>/scripts_data/`
--- - Only this directory is writable by scripts (by design).
---
--- Path rules:
--- - `folder` is relative to `scripts_data/`.
--- - Do not prefix with `scripts_data/` yourself.
---
--- Example:
--- ```lua
--- core.create_data_folder("profiles")
--- core.create_data_file("profiles/user1.json")
--- ```
---
---@param folder string Folder path inside `scripts_data/` (UTF-8), relative to the loader data directory.
---@return nil
function core.create_data_folder(folder)
return nil
end
--- Writes data to a loader data file inside `scripts_data/`.
---
--- Sandbox scope:
--- - Files are written under: `<loader_path>/scripts_data/`
--- - Only this directory is writable by scripts (by design).
---
--- Path rules:
--- - `filename` is relative to `scripts_data/`.
--- - Do not prefix with `scripts_data/` yourself.
---
--- Notes:
--- - The write behavior (overwrite vs append) depends on native implementation.
--- In most systems this overwrites the file.
---
--- Example:
--- ```lua
--- core.write_data_file("cache/state.txt", "last_login=123")
--- ```
---
---@param filename string Path inside `scripts_data/` (UTF-8), relative to the loader data directory.
---@param data string The data to write into the file.
---@return nil
function core.write_data_file(filename, data)
return nil
end
--- Reads the entire contents of a loader data file from `scripts_data/`.
---
--- Sandbox scope:
--- - Files are read from: `<loader_path>/scripts_data/`
--- - You cannot access arbitrary PC files via this API.
---
--- Path rules:
--- - `filename` is relative to `scripts_data/`.
--- - Do not prefix with `scripts_data/` yourself.
---
--- Notes:
--- - Returned string can contain binary data.
--- - If the file cannot be read, the native side may return an empty string or nil depending on implementation.
---
--- Example:
--- ```lua
--- local json = core.read_data_file("settings.json")
--- if json and #json > 0 then
--- print("settings.json:", json)
--- end
--- ```
---
---@param filename string Path inside `scripts_data/` (UTF-8), relative to the loader data directory.
---@return string data The file contents as a Lua string.
function core.read_data_file(filename)
return ""
end
--- Creates a new log file.
---
--- Purpose:
--- - Log files are intended for diagnostics and debugging output.
--- - The exact storage location is implementation-defined by the loader.
---
--- Notes:
--- - If the log file already exists, the native side may truncate it or keep it, depending on implementation.
---
--- Example:
--- ```lua
--- core.create_log_file("combat.log")
--- core.write_log_file("combat.log", "addon started")
--- ```
---
---@param filename string The name of the log file to create.
---@return nil
function core.create_log_file(filename)
return nil
end
--- Creates a folder inside the loader's `scripts_log/` directory.
---
--- Sandbox scope:
--- - Folders are created under: `<loader_path>/scripts_log/`
--- - Only this directory is writable by scripts for logging (by design).
---
--- Path rules:
--- - `folder` is relative to `scripts_log/`.
--- - Do not prefix with `scripts_log/` yourself.
---
--- Notes:
--- - Intermediate segments are created automatically (path is walked segment by segment).
---
--- Example:
--- ```lua
--- core.create_log_folder("my_addon")
--- core.create_log_file("my_addon/combat.log")
--- ```
---
---@param folder string Folder path inside `scripts_log/` (UTF-8), relative to the loader log directory.
---@return boolean success `true` if the folder (and any missing parents) was created or already exists.
function core.create_log_folder(folder)
return true
end
--- Writes a message to a log file.
---
--- Purpose:
--- - Use this for debug output that should persist outside the in-game console.
---
--- Notes:
--- - Whether a newline is automatically appended depends on native implementation.
--- If you want one, include "\n" yourself.
---
--- Example:
--- ```lua
--- core.write_log_file("combat.log", "Target acquired: " .. tostring(unit_name) .. "\n")
--- ```
---
---@param filename string The name of the log file to write to.
---@param message string The message to write into the log file.
---@return nil
function core.write_log_file(filename, message)
return nil
end
--- Lists entry names (files and folders) inside a `scripts_log/` subdirectory.
---
--- Sandbox scope:
--- - Only reads from: `<loader_path>/scripts_log/<dir_name>/`
--- - Returns nil on failure (missing directory, path escape, etc).
---
---@param dir_name string Subdirectory name inside `scripts_log/` (UTF-8).
---@return string[]|nil entries Array of entry names, or nil on failure.
function core.read_log_dir(dir_name)
return nil
end
--- Recursively deletes a folder and all its contents under `scripts_log/`.
---
--- Sandbox scope:
--- - Only deletes inside: `<loader_path>/scripts_log/`
--- - Path traversal attempts are rejected (returns false).
---
---@param folder_path string Folder path inside `scripts_log/` (UTF-8).
---@return boolean success `true` if the folder was deleted successfully.
function core.delete_log_folder(folder_path)
return true
end
--- Returns the local system date and time as a table.
---
--- Useful in sandboxed Lua where `os.date()` / `os.time()` are unavailable.
---
---@return { year: integer, month: integer, day: integer, hour: integer, minute: integer, second: integer }
function core.get_local_time()
return { year = 2025, month = 1, day = 1, hour = 0, minute = 0, second = 0 }
end
--- Reads a portion of a loader data file from `scripts_data/`, starting at a byte offset.
---
--- Sandbox scope:
--- - Files are read from: `<loader_path>/scripts_data/`
--- - You cannot access arbitrary PC files via this API.
--- - Returns nil if the data file cannot be read (missing, not permitted, etc).
---
--- Path rules:
--- - `filename` is resolved relative to `scripts_data/`.
--- - Do not prefix with `scripts_data/` yourself.
---
--- Notes:
--- - `offset` and `size_to_read` are in bytes.
--- - The returned string can contain binary data and may include zero bytes.
---
--- Example:
--- ```lua
--- local name = "settings.json" -- resolved as: <loader_path>/scripts_data/settings.json
--- local chunk = core.read_data_file_partial(name, 0, 256)
--- if chunk then
--- print("JSON header:", chunk)
--- else
--- print("Read failed (missing or blocked).")
--- end
--- ```
---
---@param filename string Path inside `scripts_data/` (UTF-8), relative to the loader data directory.
---@param offset integer Byte offset to start reading from.
---@param size_to_read integer Number of bytes to read.
---@return string|nil data The read bytes as a Lua string, or nil on failure.
function core.read_data_file_partial(filename, offset, size_to_read)
return ""
end
--- Gets the size of a loader data file in bytes, from `scripts_data/`.
---
--- Sandbox scope:
--- - Only files inside the loader's `scripts_data/` directory are accessible.
---
--- Notes:
--- - If the file does not exist or is not accessible, the native side may return 0.
--- - If you need to distinguish "missing" vs "empty file", attempt a small partial read as well.
---
--- Example:
--- ```lua
--- local name = "settings.json"
--- local size = core.get_data_file_size(name)
--- if size > 0 then
--- print("settings.json size:", size)
--- else
--- print("Missing, blocked, or empty file.")
--- end
--- ```
---
---@param filename string Path inside `scripts_data/` (UTF-8), relative to the loader data directory.
---@return integer size The file size in bytes.
function core.get_data_file_size(filename)
return 0
end
--- Lists all files and folders in a directory inside `scripts_data/`.
---
--- Sandbox scope:
--- - Only directories inside the loader's `scripts_data/` directory are accessible.
--- - Any path outside `scripts_data/` will return nil.
---
--- Path rules:
--- - `directory` is relative to `scripts_data/`.
--- - Do not prefix with `scripts_data/` yourself.
--- - Use forward slashes or backslashes as path separators.
---
--- Returns:
--- - On success: a table (array) of file names in the directory.
--- - On failure: nil (path outside sandbox, doesn't exist, or not a directory).
---
--- Notes:
--- - Only returns file/folder names, not full paths.
--- - Includes both files and subdirectories.
--- - Does not include "." or ".." entries.
---
--- Example:
--- ```lua
--- local files = core.read_dir("profiles")
--- if files then
--- for i, name in ipairs(files) do
--- print("Found: " .. name)
--- end
--- else
--- print("Directory not found or outside sandbox")
--- end
--- ```
---
---@param directory string Directory path inside `scripts_data/` (UTF-8), relative to the loader data directory.
---@return string[]|nil files Array of file/folder names, or nil on failure.
function core.read_dir(directory)
return nil
end
--- Deletes a file inside the World of Warcraft installation folder.
---@param filename string Path inside the WoW folder (UTF-8).
---@return boolean success True if the file was deleted successfully.
function core.delete_file(filename)
return false
end
--- Deletes a log file from the `scripts_log/` directory.
---@param filename string The log file name to delete.
---@return boolean success True if the file was deleted successfully.
function core.delete_log_file(filename)
return false
end
--- Deletes a data file from the `scripts_data/` directory.
---@param filename string The data file name to delete.
---@return boolean success True if the file was deleted successfully.
function core.delete_data_file(filename)
return false
end
--- Returns the name of the plugin that owns the calling code, resolved from the
--- Lua stack. This is the plugin's DISPLAY name (the `name` its `header.lua`
--- returns), which is the same identity the native menu salts persistence with.
--- Falls back to the plugin's root folder name when the display name is empty.
---
--- Resolution walks the stack, so a cross-required shared module reports the
--- plugin that called into it, not the module's own package.
---
---@return string|nil plugin_name Owning plugin name, or nil when no plugin owns the frame.
function core.get_owning_plugin_name()
return nil
end
--- Wipes the entire persisted menu settings database (`settings.dat`).
---
--- Scope:
--- - Clears every stored widget value of every plugin, loaded or not.
--- - Backs the menu "factory reset all settings" action.
---
---@return boolean success True if the settings database was cleared.
function core.reset_menu_settings()
return false
end
--- Plays a sound by sound kit ID.
---@param id integer The sound kit ID to play.
---@return boolean will_play Whether the sound will play.
---@return number handle The sound handle that can be passed to core.stop_sound_by_handle.
function core.play_sound_by_id(id)
return false, 0
end
--- Stops a sound instance by handle.
---@param handle integer The handle returned by core.play_sound_by_id.
---@param fadeout_ms? integer Optional fadeout time in milliseconds.
---@return nil
function core.stop_sound_by_handle(handle, fadeout_ms)
return nil
end
--- Return if the player is typing something in any textbox like chat, aka is_chat_open, but scalable to other stuff of the game interface and including all addons hopefully
---@return boolean
function core.is_textbox_focused()
return false
end
---@class inventory
core.inventory = {}
--- Enumerate the items in one container.
---
--- BAG 0 DOES NOT MEAN "THE BACKPACK". It returns the player's ENTIRE item array: everything
--- worn, then the four bag slots, then the backpack. This surprises everyone who reads the
--- old one-line "0 = backpack" doc, it has now cost two separate investigations, and it is
--- NOT a private-server quirk, so the whole chain is written out here once.
---
--- WHAT THE CORE ACTUALLY DOES, read 2026-08-31 in wow_core:
---
--- lua_bindings_inventory.cpp lua_inventory_get_items passes bag_id through unchanged,
--- then publishes slot_id = native_index + 1 (`slot = slot + 1`).
--- game_inventory.cpp enumerate_inventory_bag -> get_bag_item_info, whose FIRST
--- statement is `bag_id = bag_id - 1`.
--- decremented id < 0 returns *local_player->get_inventory_instance(), the whole
--- player container. Every non-positive bag_id lands here.
--- decremented id >= 0 resolves that equipped bag's object by guid and walks the
--- bag's own item array, which is the container you expected.
--- decremented id >= 17 returns nothing, so bag_id 18 and up answer {}.
---
--- So bag_id 0 (backpack), -1 (bank), -2 (keyring) and -4 (tokens) ALL return the identical
--- whole-player-container list. The keyring and bank ids in the wowwiki table below are not
--- implemented, they just fall down the same branch. Bank bags 5 to 11 do reach the guid
--- lookup, but nobody has confirmed they resolve on any build here, so treat them as unproven.
---
--- THE PLAYER CONTAINER LAYOUT. Native indices, so published slot_id is one higher:
---
--- index 0 to 18 equipped gear, head through tabard, in INVSLOT_* order
--- index 19 to 22 the four equipped bag slots, the bag OBJECTS themselves
--- index 23 and up the backpack proper, then bank storage on some clients
---
--- The index the backpack starts at is a client-layout constant and it is the ONLY part of
--- this that differs per build. Measured values live in common/utility/inventory_helper.lua
--- as BAG_1_REAL_START, in published slot_id terms: 24 on wow_vanilla_ps and wow_tbc_ps,
--- 35 on the retail family.
---
--- Verified on wow_tbc_ps 2026-08-31 against the server's character_inventory table, level 70
--- rogue, same character and same minute. get_items_in_bag(0) answered 49@4 48@7 47@8 2092@16
--- 28979@18 4540@24 6948@25 for DB rows 3, 6, 7, 15, 17, 23, 24: five worn pieces, then bread
--- and a hearthstone. Five rows of equipment nobody asked for, and the two backpack rows.
---
--- THIS IS NOT A PRIVATE-SERVER DIVERGENCE AND AN #ifdef CANNOT FIX IT. The bag 0 branch has
--- no build guard at all. The one `#ifdef CLASSIC_PRIV` inside get_bag_item_info only picks
--- the f_get_bag_guid calling convention, and that line is reached only for bag_id >= 1.
--- wow_tbc_us runs the identical code and answers identically, so a private-server branch here
--- would make the PS builds DIFFER from the other TBC target rather than match it. See the
--- "Bag 0 is the whole player container" section of claude_md/GLOBAL/CORE_WOW.md before
--- reopening this.
---
--- Core reads this same buffer for game_object:for_each_equipped_item(), so as the code stands
--- today "bag 0" and "the equipped items" are literally one read.
---
--- DO NOT PASS A RAW slot_id TO core.input.use_container_item AND FRIENDS. Their (bag, slot)
--- pair is a slot WITHIN the named bag, and for bag 0 that means 1 to 16, not 24 to 39. A raw
--- 24 reaches C_Container.UseContainerItem(0, 24), which is out of range for a 16 slot
--- backpack. common/utility/inventory_helper.lua owns that conversion and is the supported way
--- to get a usable pair. The convention itself is written out in the core at
--- lua_bindings_input.cpp, "THE BAG SLOT CONVENTION, once, for every container binding".
---
--- DO NOT "FIX" THIS BINDING WITHOUT CHANGING inventory_helper.lua IN THE SAME COMMIT. Making
--- bag 0 mean the backpack would renumber its slot_ids to 1 to 16, every one of them below
--- BAG_1_REAL_START, so the helper's filter would discard the entire backpack and every
--- consumer would see empty bags. Core, the helper and this stub move together or not at all.
---@param bag_id integer BagId https://wowwiki-archive.fandom.com/wiki/BagId
---@return item_slot_info_table items One entry per OCCUPIED slot. Empty slots are skipped
--- entirely, so #items is an item count and never a slot count, and the list is not indexable
--- by slot. Each entry is { object = game_object, slot_id = native_index + 1 }, and carries no
--- item_id field: read the id off the object with item:get_item_id().
function core.inventory.get_items_in_bag(bag_id)
return {}
end
--- Returns the total number of slots a bag has.
---
--- IT DOES NOT TAKE THE SAME bag_id AS get_items_in_bag. This one is shifted by one, so the
--- pairing you want is get_num_bag_slots(N) alongside get_items_in_bag(N - 1). Passing the
--- same number to both asks about two different bags and the mistake is silent.
---
--- WHY, read 2026-08-31 in wow_core. The id is decremented TWICE on the way down, at two
--- sites that each look like the only one:
---
--- lua_bindings_inventory.cpp lua_inventory_get_bag_slots does `bag_id--` before the call.
--- game_inventory.cpp get_container_num_slots opens with `container_id--` again.
---
--- get_items_in_bag is decremented only once, in get_bag_item_info. That single missing
--- decrement is the whole difference between the two bindings, and it is worth stating as a
--- table because reading either file alone gives the wrong answer:
---
--- backpack get_items_in_bag(0) get_num_bag_slots(1)
--- first worn bag get_items_in_bag(1) get_num_bag_slots(2)
--- fourth worn bag get_items_in_bag(4) get_num_bag_slots(5)
---
--- get_num_bag_slots(0) therefore reaches container_id -2, fails the `container_id < -1`
--- guard, and returns 0 on EVERY build, always. A zero from bag 0 is not "no bag equipped"
--- and not a private-server defect, it is the answer to a question that cannot be asked this
--- way. common/utility/inventory_helper.lua currently calls it that way on the private-server
--- branch and falls back to a hardcoded 16, which is why the mistake has stayed invisible.
---
--- A zero from bags 1 to 4 does mean no bag is equipped in that slot.
---
--- One further caveat on the backpack count. get_container_num_slots reads it straight off the
--- player object at a hardcoded offset, 0x75D0 under IS_RETAIL and 0x1405A otherwise, rather
--- than from the per-build table in core_literal_imports.hpp that every other offset comes
--- from. The private-server clients have their own layout, o_player_inventory is 0x28FF8 there
--- against 0x165A8 on wow_tbc_us, so that literal has never been shown to be right on them.
--- Do not trust a backpack count from these builds without measuring it first.
--- @param bag_id integer Bag id, shifted one HIGHER than the get_items_in_bag id: 1 = backpack,
--- 2 to 5 = the four equipped bags.
--- @return integer num_slots Number of slots in the bag. 0 for bags 1 to 4 means no bag is
--- equipped there; 0 for bag_id 0 means the argument was out of range, see above.
function core.inventory.get_num_bag_slots(bag_id)
return 0
end
--- Returns the total cost in copper to repair all equipped items.
--- @return integer cost Repair cost in copper (0 if nothing to repair)
function core.inventory.get_total_repair_cost()
return 0
end
--- Returns whether the merchant currently open offers a repair service.
--- Only meaningful while a merchant window is open, between MERCHANT_SHOW and MERCHANT_CLOSED.
--- It answers false when no merchant is open, so it is not a substitute for a vendor-open check.
--- Read it before trusting a zero from get_total_repair_cost: that function wraps GetRepairAllCost,
--- which also needs a repair-capable merchant, so a zero cost means either "nothing is damaged" or
--- "this vendor cannot repair" and only can_merchant_repair separates the two.
--- The core normalizes the result to a boolean on every client, including the classic builds
--- where the game answers 1 or nil.
---@return boolean can_repair True when the open merchant can repair.
function core.inventory.can_merchant_repair()
return false
end
---@class inventory_item_durability
---@field current integer Current durability points. Zero with a positive max means the item is broken.
---@field max integer Maximum durability points. Zero means the slot is empty or the item has no durability.
--- Returns the durability of the item in one equipment slot.
--- The slot is an INVSLOT_* equipment slot id in the 1 to 19 range, not a bag slot.
--- Both fields are 0 when the slot is empty or the item does not track durability, so test
--- max > 0 before dividing, otherwise a tabard or a shirt divides by zero.
---@param slot integer Equipment slot id (INVSLOT_*, 1 to 19).
---@return inventory_item_durability durability Current and maximum durability points.
function core.inventory.get_item_durability(slot)
return {}