Repository navigation
Expand file tree
/
Copy pathDmorphOcto.lua
More file actions
4109 lines (3867 loc) · 132 KB
/
Copy pathDmorphOcto.lua
File metadata and controls
4109 lines (3867 loc) · 132 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
-- DMorph for OctoWoW: morph state, wardrobe, catalogue search and the chat
-- commands. The window lives in UI.lua and calls the same DmorphOcto.*
-- functions as the commands.
--
-- DMorph itself is a DLL built for WotLK 3.3.5a (build 12340) with that
-- client's addresses hardcoded, so it can't run on OctoWoW's 1.12.1 client.
-- This addon drives the morph API of VanillaHelpers.dll (v1.1.0+) instead:
-- OctoLauncher ships it as the "vanillaHelpers" mod and it is built for the
-- 1.12.1 client.
--
-- The client runs Lua 5.0: no #, no %, no string.match, no select(), and
-- table.getn() counts element by element, so long lists keep their own count.
local VERSION = "2.21.9"
local PREFIX = "|cff33ff99DMorph|r: "
-- VANILLAHELPERS_VERSION is major * 10000 + minor * 100 + patch; morphing
-- came in v1.1.0. Older versions load and set it, but can't morph.
local MORPH_VERSION = 10100
local function VersionText(v)
return format("%d.%d.%d", math.floor(v / 10000), math.floor(math.mod(v, 10000) / 100), math.mod(v, 100))
end
-- The other client mods that load the same way as VanillaHelpers. If none
-- of them runs either, the game wasn't started through OctoLauncher.
local function OtherClientMods()
local mods = {}
if SUPERWOW_VERSION then
table.insert(mods, "SuperWoW")
end
if type(C_Item) == "table" then
table.insert(mods, "ClassicAPI")
end
if type(GetNampowerVersion) == "function" then
table.insert(mods, "nampower")
end
if type(UnitXP) == "function" then
table.insert(mods, "UnitXP")
end
return mods
end
-- Why morphing doesn't work, and how to fix it (one chat-sized message).
local function MissingAPI()
if type(VANILLAHELPERS_VERSION) == "number" and VANILLAHELPERS_VERSION < MORPH_VERSION then
return "VanillaHelpers v" .. VersionText(VANILLAHELPERS_VERSION) .. " is running, but morphing needs v1.1.0 or newer. "
.. "Update the 'vanillaHelpers' mod in OctoLauncher, close the game and start it again."
elseif type(VANILLAHELPERS_VERSION) == "number" then
return "VanillaHelpers is running but its morph functions are missing: reinstall the 'vanillaHelpers' mod in OctoLauncher "
.. "and restart the game."
elseif table.getn(OtherClientMods()) > 0 then
return "VanillaHelpers isn't running, so morphing is unavailable (your other client mods are, so only it is missing). "
.. "Tick the 'vanillaHelpers' mod in OctoLauncher, close the game completely and press Play again."
end
return "VanillaHelpers isn't running, so morphing is unavailable. No client mods are running at all: start the game "
.. "from OctoLauncher (not WoW.exe), with the 'vanillaHelpers' mod ticked. Close the game completely first."
end
-- Player model display IDs, indexed by race ID. VanillaHelpers recognises
-- exactly these and rewrites race and gender as well, so your own skin, face
-- and hair carry over. Race 10 is the High Elf on Turtle-based clients.
local RACES = {
{ name = "Human", male = 49, female = 50, faction = "Alliance" },
{ name = "Orc", male = 51, female = 52, faction = "Horde" },
{ name = "Dwarf", male = 53, female = 54, faction = "Alliance" },
{ name = "Night Elf", male = 55, female = 56, faction = "Alliance" },
{ name = "Undead", male = 57, female = 58, faction = "Horde" },
{ name = "Tauren", male = 59, female = 60, faction = "Horde" },
{ name = "Gnome", male = 1563, female = 1564, faction = "Alliance" },
{ name = "Troll", male = 1478, female = 1479, faction = "Horde" },
{ name = "Goblin", male = 6894, female = 6895, faction = "Horde" },
{ name = "High Elf", male = 15476, female = 15475, faction = "Alliance" },
}
local RACE_ALIASES = {
human = 1, orc = 2, dwarf = 3, nightelf = 4, ne = 4, undead = 5, scourge = 5,
forsaken = 5, tauren = 6, gnome = 7, troll = 8, goblin = 9, highelf = 10,
bloodelf = 10,
}
-- UnitRace() file tokens, only used when the native model isn't in RACES.
local RACE_TOKENS = {
HUMAN = 1, ORC = 2, DWARF = 3, NIGHTELF = 4, SCOURGE = 5, TAUREN = 6,
GNOME = 7, TROLL = 8, GOBLIN = 9, HIGHELF = 10, BLOODELF = 10,
}
-- Inventory slots that show on the character model, numbered like DMorph
-- and GetInventorySlotInfo(). Neck, rings and trinkets have no model.
local SLOT_ORDER = { 1, 3, 4, 5, 6, 7, 8, 9, 10, 15, 16, 17, 18, 19 }
local SLOT_NAMES = {
[1] = "Head", [3] = "Shoulder", [4] = "Shirt", [5] = "Chest", [6] = "Waist",
[7] = "Legs", [8] = "Feet", [9] = "Wrist", [10] = "Hands", [15] = "Back",
[16] = "Main hand", [17] = "Off hand", [18] = "Ranged", [19] = "Tabard",
}
-- The slots whose enchant glow DmorphHelper can change.
local GLOW_SLOT = { [16] = true, [17] = true, [18] = true }
local SLOT_ALIASES = {
head = 1, shoulder = 3, shoulders = 3, shirt = 4, chest = 5, waist = 6,
belt = 6, legs = 7, feet = 8, boots = 8, wrist = 9, wrists = 9, hands = 10,
gloves = 10, back = 15, cloak = 15, mainhand = 16, offhand = 17,
ranged = 18, tabard = 19,
}
DmorphOcto = {
VERSION = VERSION,
MissingAPI = MissingAPI,
RACES = RACES,
SLOT_ORDER = SLOT_ORDER,
SLOT_NAMES = SLOT_NAMES,
GLOW_SLOTS = { 16, 17, 18 },
}
local M = DmorphOcto
-- An outfit is { display, race, gender (0 male, 1 female), items[slot] }.
local db -- DmorphOctoDB, per character: the outfit currently applied
local account -- DmorphOctoAccount, shared: saved outfits and the minimap button
local nativeRace, nativeGender
local sessionReady = false
local warnedMissingAPI = false
local pendingApply
local listeners = {}
local creatures
local items = {}
local sets
local looks = {}
local InitDB -- defined under State; the catalogue needs it first
local function Print(msg)
DEFAULT_CHAT_FRAME:AddMessage(PREFIX .. msg)
end
local function Report(ok, message)
Print(message)
end
local function HasMorphAPI()
return type(SetUnitDisplayID) == "function"
and type(SetUnitVisibleItemID) == "function"
and type(UnitDisplayInfo) == "function"
end
M.HasMorphAPI = HasMorphAPI
-- VanillaHelpers reports bad input with lua_error, so every call is guarded.
-- A nil value clears that override.
local function Morph(fn, a1, a2, a3)
return pcall(fn, a1, a2, a3)
end
local function ParseID(text)
local n = tonumber(text or "")
if n and n >= 0 and n <= 2147483647 and n == math.floor(n) then
return n
end
end
M.ParseID = ParseID
local function Trim(text)
local _, _, trimmed = strfind(text or "", "^%s*(.-)%s*$")
return trimmed
end
local function RaceModel(race, gender)
if gender == 1 then
return RACES[race].female
end
return RACES[race].male
end
function M.DescribeBody(race, gender)
if gender == 1 then
return RACES[race].name .. " female"
end
return RACES[race].name .. " male"
end
local function RaceList()
local list = ""
for race = 1, table.getn(RACES) do
list = list .. ", " .. race .. " " .. RACES[race].name
end
return strsub(list, 3)
end
local function SlotList()
local list = ""
for i = 1, table.getn(SLOT_ORDER) do
local slot = SLOT_ORDER[i]
list = list .. ", " .. slot .. " " .. strlower(SLOT_NAMES[slot])
end
return strsub(list, 3)
end
-- Catalogue -----------------------------------------------------------------
-- Data/*.lua hold the catalogue as text so the game loads it quickly; each
-- list is parsed the first time it's needed. An entry is
-- { id, name, lowercase name, quality, kind }.
local function NewCatalog()
return { ids = {}, names = {}, lower = {}, quality = {}, kind = {}, byID = {}, count = 0 }
end
local function AddEntry(catalog, id, name, quality, kind)
local n = catalog.count + 1
catalog.count = n
catalog.ids[n], catalog.names[n], catalog.lower[n] = id, name, strlower(name)
catalog.quality[n], catalog.kind[n] = quality, kind
if not catalog.byID[id] then
catalog.byID[id] = n
end
end
local function Before(a, b)
return a[3] < b[3] or (a[3] == b[3] and a[1] < b[1])
end
-- Merges two name-sorted lists. The data files are sorted the way Lua
-- compares strings, so this is one pass.
local function Merge(a, n, b, m)
local out, k, i, j = {}, 0, 1, 1
while i <= n or j <= m do
local x, y = a[i], b[j]
if not y or (x and not Before(y, x)) then
i = i + 1
else
x, j = y, j + 1
end
k = k + 1
out[k] = x
end
return out, k
end
local function Fill(catalog, list, count)
for i = 1, count do
local e = list[i]
AddEntry(catalog, e[1], e[2], e[4], e[5])
end
return catalog
end
-- Creature models by kind: a creature's name, or named after the model file;
-- 2 and 3 are the same for the models OctoWoW added to the stock 1.12.1 client.
M.KIND_CREATURE, M.KIND_MODEL, M.KIND_NEW, M.KIND_NEW_MODEL = 0, 1, 2, 3
-- Models brought over from later expansions by the porting tool, listed in
-- Data/Ported.lua (only on a PC that has the tool's patch-Z.mpq).
M.KIND_PORTED = 4
M.MODEL_FILTERS = {
{ text = "All models" },
{ text = "Creatures", kinds = { [0] = true, [2] = true } },
{ text = "Bosses", tag = "boss" },
{ text = "Rare creatures", tag = "rare" },
{ text = "Mounts", tag = "mount" },
{ text = "Other models", kinds = { [1] = true, [3] = true } },
{ text = "New in OctoWoW", kinds = { [2] = true, [3] = true } },
{ text = "Ported (later expansions)", kinds = { [4] = true } },
}
-- Items and sets are kind 0 (stock 1.12.1) or 2 (added by Turtle WoW / OctoWoW).
M.ITEM_FILTERS = {
{ text = "All items" },
{ text = "1.12 items", kinds = { [0] = true } },
{ text = "New in OctoWoW", kinds = { [2] = true } },
{ text = "Ported (later expansions)", kinds = { [4] = true } },
}
M.SET_FILTERS = {
{ text = "All sets" },
{ text = "1.12 sets", kinds = { [0] = true } },
{ text = "New in OctoWoW", kinds = { [2] = true } },
{ text = "Ported (later expansions)", kinds = { [4] = true } },
}
-- Item and set quality, as GetItemInfo() numbers it.
-- Item kinds (class * 100 + subclass, Data/ItemTypes.lua), in the order the
-- filter lists them: armour by material, then weapons.
M.ITEM_TYPES = {
{ 401, "Cloth" }, { 402, "Leather" }, { 403, "Mail" }, { 404, "Plate" }, { 406, "Shield" },
{ 400, "Miscellaneous" }, { 407, "Libram" }, { 408, "Idol" }, { 409, "Totem" },
{ 215, "Dagger" }, { 213, "Fist weapon" }, { 200, "One-handed axe" }, { 204, "One-handed mace" },
{ 207, "One-handed sword" }, { 201, "Two-handed axe" }, { 205, "Two-handed mace" },
{ 208, "Two-handed sword" }, { 206, "Polearm" }, { 210, "Staff" }, { 217, "Spear" }, { 202, "Bow" },
{ 218, "Crossbow" }, { 203, "Gun" }, { 216, "Thrown" }, { 219, "Wand" }, { 214, "Miscellaneous weapon" },
{ 220, "Fishing pole" },
}
M.ITEM_TYPE_NAMES = {}
for i = 1, table.getn(M.ITEM_TYPES) do
M.ITEM_TYPE_NAMES[M.ITEM_TYPES[i][1]] = M.ITEM_TYPES[i][2]
end
-- GetItemInfo's English sub-types, for items no data file knows.
local SUBTYPES = {
Armor = { Miscellaneous = 400, Cloth = 401, Leather = 402, Mail = 403, Plate = 404, Shields = 406,
Librams = 407, Idols = 408, Totems = 409 },
Weapon = { ["One-Handed Axes"] = 200, ["Two-Handed Axes"] = 201, Bows = 202, Guns = 203,
["One-Handed Maces"] = 204, ["Two-Handed Maces"] = 205, Polearms = 206, ["One-Handed Swords"] = 207,
["Two-Handed Swords"] = 208, Staves = 210, ["Fist Weapons"] = 213, Miscellaneous = 214, Daggers = 215,
Thrown = 216, Spears = 217, Crossbows = 218, Wands = 219, ["Fishing Pole"] = 220 },
}
M.QUALITY_FILTERS = {
{ text = "Any quality" },
{ text = "Poor", quality = 0 },
{ text = "Common", quality = 1 },
{ text = "Uncommon", quality = 2 },
{ text = "Rare", quality = 3 },
{ text = "Epic", quality = 4 },
{ text = "Legendary", quality = 5 },
}
-- Display and item IDs that can't show in this client: Data/HiddenModels.lua
-- and Data/HiddenItems.lua, written by tools/build_models.ps1 and
-- tools/build_items.ps1 from the game's own files.
local hiddenModels, hiddenItems
local function ReadIDs(text)
local set = {}
for id in string.gfind(text or "", "%d+") do
set[tonumber(id)] = true
end
return set
end
local function HiddenModels()
if not hiddenModels then
hiddenModels = ReadIDs(DmorphOcto_HiddenModels)
DmorphOcto_HiddenModels = nil
end
return hiddenModels
end
local function HiddenItems()
if not hiddenItems then
hiddenItems = ReadIDs(DmorphOcto_HiddenItems)
DmorphOcto_HiddenItems = nil
end
return hiddenItems
end
-- Display IDs from Data/Ported.lua: only PCs with the same ported pack have
-- their models. Others see your own model instead (Share.lua sends ported
-- looks apart, tagged with the pack, to DMorph users who have the same one).
local portedIDs = {}
-- Which ported pack this PC has: the porting tool's DmorphOcto_PortedPack if
-- it wrote one, else how many models, items and sets Ported.lua's three lists
-- have (read here, as Ported.lua loads before this file and the lists are
-- dropped once parsed). Two PCs with the same pack (Pack Ported.bat /
-- Install Ported.bat) match. Rows, not the lists' sizes (before 2.17.1): a
-- fix to the names or tags (mount names, rider poses) changed the size and
-- stopped two PCs with the same models seeing each other's ported looks.
local function Rows(text)
local _, n = string.gsub(text or "", "\n", "\n")
return n
end
local portedPack
if type(DmorphOcto_PortedPack) == "string" then
portedPack = DmorphOcto_PortedPack
elseif DmorphOcto_PortedData or DmorphOcto_PortedItems then
portedPack = "P" .. Rows(DmorphOcto_PortedData) .. "x" .. Rows(DmorphOcto_PortedItems)
.. "x" .. Rows(DmorphOcto_PortedSets)
end
if portedPack and not strfind(portedPack, "^%w+$") then
portedPack = nil
end
-- Rider poses: ported mounts whose riders Blizzard poses another way (Ported.lua's
-- tag "rider<animation>": 120 stands crouched on the mage discs, boards, kites
-- and carpets, 97 sits). DmorphHelper v14 (DmorphHelper_SetRiderPose) puts them
-- on whoever rides one. Read now, before the list is parsed and dropped.
local riderPoses = {}
for id, anim in string.gfind(DmorphOcto_PortedData or "", "(%d+)\t[^\t\r\n]*\t[^\t\r\n]*rider(%d+)") do
riderPoses[tonumber(id)] = tonumber(anim)
end
function M.GetRiderPose(displayID)
return riderPoses[tonumber(displayID or 0)]
end
local posesRegistered
local function RegisterRiderPoses()
if posesRegistered or type(DmorphHelper_SetRiderPose) ~= "function" or not next(riderPoses) then
return
end
posesRegistered = true
for id, anim in pairs(riderPoses) do
-- An error: the helper couldn't change the game's riding pose (/dmorph check says so).
if not pcall(DmorphHelper_SetRiderPose, id, anim) then
return
end
end
end
function M.GetPortedPack()
return portedPack
end
function M.IsPorted(displayID)
M.GetCreatureCatalog()
return portedIDs[tonumber(displayID or 0)] == true
end
-- Creatures.lua (named creatures) and Models.lua (every other display ID the
-- client has) together list every model, less the ones that can't show.
function M.GetCreatureCatalog()
if creatures then
return creatures
end
local hidden = HiddenModels()
local named, other, n, m = {}, {}, 0, 0
for id, name in string.gfind(DmorphOcto_CreatureData or "", "(%d+)\t([^\r\n]+)") do
id = tonumber(id)
if not hidden[id] then
n = n + 1
named[n] = { id, name, strlower(name), 0, M.KIND_CREATURE }
end
end
for id, kind, name in string.gfind(DmorphOcto_ModelData or "", "(%d+)\t(%d)\t([^\r\n]+)") do
id = tonumber(id)
if not hidden[id] then
m = m + 1
other[m] = { id, name, strlower(name), 0, tonumber(kind) }
end
end
DmorphOcto_CreatureData, DmorphOcto_ModelData = nil, nil -- the parsed tables replace the text
local all, count = Merge(named, n, other, m)
-- Data/Ported.lua: displayID<TAB>name<TAB>tags ("mount").
local ported, p, portedMounts = {}, 0, {}
for id, name, tags in string.gfind(DmorphOcto_PortedData or "", "(%d+)\t([^\t\r\n]+)\t?([^\r\n]*)") do
id = tonumber(id)
p = p + 1
ported[p] = { id, name, strlower(name), 0, M.KIND_PORTED }
portedIDs[id] = true
if strfind(tags, "mount") then
portedMounts[id] = true
end
end
DmorphOcto_PortedData = nil
table.sort(ported, Before)
creatures = Fill(NewCatalog(), Merge(all, count, ported, p))
-- Tags for the filters: bosses and rares by display and name, mounts by
-- display. Data/ModelTags.lua (OctoWoW's client and Turtle WoW's ranks) and
-- Data/ClassicTags.lua (the 1.12.1 database); a boss stays a boss. A mount
-- with its own name (Blizzard's) is listed under that name only, not under
-- every creature that shares the display.
local byName, mounts, mountTitles, titled = {}, {}, {}, {}
for _, text in ipairs({ DmorphOcto_TagData or "", DmorphOcto_ClassicTagData or "" }) do
for id, tag, name in string.gfind(text, "(%d+)\t(%a+)\t([^\r\n]*)") do
if tag == "mount" then
mounts[tonumber(id)] = true
if name ~= "" then
mountTitles[id .. "\t" .. strlower(name)] = true
end
else
local key = id .. "\t" .. strlower(name)
if byName[key] ~= "boss" then
byName[key] = tag
end
end
end
end
DmorphOcto_TagData, DmorphOcto_ClassicTagData = nil, nil
for id in pairs(portedMounts) do
mounts[id] = true
end
-- Displays with an entry under the mount's own name (else every entry counts).
for i = 1, creatures.count do
if mountTitles[creatures.ids[i] .. "\t" .. creatures.lower[i]] then
titled[creatures.ids[i]] = true
end
end
creatures.tags = {}
for i = 1, creatures.count do
local id = creatures.ids[i]
local key = id .. "\t" .. creatures.lower[i]
local tag = byName[key]
if mounts[id] and (not titled[id] or mountTitles[key]) then
tag = (tag and (tag .. " ") or "") .. "mount"
end
creatures.tags[i] = tag
end
return creatures
end
-- Inventory slots by the INVTYPE_ name GetItemInfo() returns.
local EQUIP_SLOTS = {
INVTYPE_HEAD = { 1 }, INVTYPE_SHOULDER = { 3 }, INVTYPE_BODY = { 4 }, INVTYPE_CHEST = { 5 },
INVTYPE_ROBE = { 5 }, INVTYPE_WAIST = { 6 }, INVTYPE_LEGS = { 7 }, INVTYPE_FEET = { 8 },
INVTYPE_WRIST = { 9 }, INVTYPE_HAND = { 10 }, INVTYPE_CLOAK = { 15 }, INVTYPE_TABARD = { 19 },
INVTYPE_WEAPON = { 16, 17 }, INVTYPE_2HWEAPON = { 16 }, INVTYPE_WEAPONMAINHAND = { 16 },
INVTYPE_SHIELD = { 17 }, INVTYPE_WEAPONOFFHAND = { 17 }, INVTYPE_HOLDABLE = { 17 },
INVTYPE_RANGED = { 18 }, INVTYPE_THROWN = { 18 }, INVTYPE_RANGEDRIGHT = { 18 },
}
-- Developers' test items ("Kazgrim Test Helm", "1000 Test dagger 60 blue"):
-- "test" as a word in the name.
local function IsTestItem(lower)
local at, stop = strfind(lower, "test", 1, true)
while at do
if not strfind(strsub(lower, at - 1, at - 1), "%a") and not strfind(strsub(lower, stop + 1, stop + 1), "%a") then
return true
end
at, stop = strfind(lower, "test", stop + 1, true)
end
return false
end
local function ParseItems(text, kind, list, n, skip)
local hidden = HiddenItems()
for id, quality, name in string.gfind(text or "", "(%d+)\t(%d)\t([^\r\n]+)") do
id = tonumber(id)
if not ((skip and skip[id]) or hidden[id] or IsTestItem(strlower(name))) then
n = n + 1
list[n] = { id, name, strlower(name), tonumber(quality), kind }
end
end
return list, n
end
-- Items the game told us about in this or an earlier session (see Item
-- lookup), saved as DmorphOctoAccount.itemInfo[id] = "slots<TAB>quality<TAB>name".
local function LearnedItems(slot, skip)
local list, n, hidden = {}, 0, HiddenItems()
for id, info in pairs(account.itemInfo) do
if info and not skip[id] and not hidden[id] then
local _, _, slots, quality, name = strfind(info, "^([%d,]+)\t(%-?%d+)\t(.+)$")
if slots and strfind("," .. slots .. ",", "," .. slot .. ",", 1, true) and not IsTestItem(strlower(name)) then
n = n + 1
list[n] = { id, name, strlower(name), tonumber(quality), M.KIND_NEW }
end
end
end
table.sort(list, Before)
return list, n
end
-- itemID -> kind, from Data/ItemTypes.lua and ItemsExtra.lua's item cache
-- kinds, read once.
local itemTypes
local function ReadItemTypes()
itemTypes = {}
for _, text in ipairs({ DmorphOcto_ItemTypeData or "", DmorphOcto_ItemTypeExtra or "" }) do
for kind, list in string.gfind(text, "(%d+)\t([%d,]+)") do
kind = tonumber(kind)
for id in string.gfind(list, "%d+") do
itemTypes[tonumber(id)] = kind
end
end
end
DmorphOcto_ItemTypeData, DmorphOcto_ItemTypeExtra = nil, nil
end
-- Ported weapons (Data/Ported.lua, DmorphOcto_PortedItems): item IDs only this
-- PC has. DmorphHelper v10+ answers the game's item cache for them with a real
-- item of the same kind (the template: held and sheathed the same) showing
-- the ported model. Kind -> the slots it fits (armour lines name their slot).
local PORTED_SLOTS = {
[200] = { 16, 17 }, [204] = { 16, 17 }, [207] = { 16, 17 }, [213] = { 16, 17 }, [215] = { 16, 17 },
[201] = { 16 }, [205] = { 16 }, [206] = { 16 }, [208] = { 16 }, [210] = { 16 },
[202] = { 18 }, [203] = { 18 }, [216] = { 18 }, [218] = { 18 }, [219] = { 18 },
[214] = { 17 }, [406] = { 17 },
}
local portedItems
local function PortedItems()
if not portedItems then
portedItems = {}
-- virtualID<TAB>display<TAB>kind<TAB>template<TAB>name[<TAB>slot[<TAB>quality]]
-- (slot 0 or none: the slots its kind fits; quality none: epic).
for id, display, kind, template, name, slot, quality in string.gfind(DmorphOcto_PortedItems or "",
"(%d+)\t(%d+)\t(%d+)\t(%d+)\t([^\t\r\n]+)\t?(%d*)\t?(%d*)") do
slot = tonumber(slot)
if slot == 0 then
slot = nil
end
portedItems[tonumber(id)] = { display = tonumber(display), kind = tonumber(kind), template = tonumber(template),
name = name, slot = slot, quality = tonumber(quality) or 4 }
end
DmorphOcto_PortedItems = nil
end
return portedItems
end
function M.IsPortedItem(itemID)
return PortedItems()[tonumber(itemID or 0)] ~= nil
end
local function HasVirtualItems()
return type(DmorphHelper_SetVirtualItem) == "function"
end
M.HasVirtualItems = HasVirtualItems
-- Tells DmorphHelper about every ported weapon, and asks the server for the
-- template items the game hasn't seen (their records are copied).
local portedRegistered
local function RegisterPortedItems()
if portedRegistered or not HasVirtualItems() or not next(PortedItems()) then
return
end
portedRegistered = true
local asked = {}
for id, p in pairs(PortedItems()) do
pcall(DmorphHelper_SetVirtualItem, id, p.template, p.display)
if not asked[p.template] then
asked[p.template] = true
local ok, name = pcall(GetItemInfo, p.template)
if not (ok and name) and type(C_Item) == "table" then
pcall(C_Item.RequestLoadItemDataByID, p.template)
end
end
end
end
M.RegisterPortedItems = RegisterPortedItems
-- An item's kind (401 cloth, 215 dagger, ...: M.ITEM_TYPES), or nil. Items no
-- data file knows are asked from the game, which knows the ones it has seen.
function M.GetItemType(itemID)
local ported = PortedItems()[itemID]
if ported then
return ported.kind
end
if not itemTypes then
ReadItemTypes()
end
local kind = itemTypes[itemID]
if not kind then
local ok, _, _, _, _, class, subclass = pcall(GetItemInfo, itemID)
kind = ok and SUBTYPES[class or ""] and SUBTYPES[class][subclass or ""]
if kind then
itemTypes[itemID] = kind
end
end
return kind
end
-- The kinds a catalogue's entries have, in M.ITEM_TYPES' order, each with how
-- many: { { kind, name, count }, ... }.
function M.GetCatalogTypes(catalog)
local counts = {}
for i = 1, catalog.count do
local kind = catalog.types and catalog.types[i]
if kind then
counts[kind] = (counts[kind] or 0) + 1
end
end
local list = {}
for i = 1, table.getn(M.ITEM_TYPES) do
local kind = M.ITEM_TYPES[i][1]
if counts[kind] then
table.insert(list, { kind, M.ITEM_TYPES[i][2], counts[kind] })
end
end
return list
end
-- Every item that fits the slot: Items.lua (the 1.12.1 database), then
-- ItemsExtra.lua (Turtle WoW and OctoWoW) and the items looked up in game.
function M.GetItemCatalog(slot)
if not items[slot] then
InitDB()
local base, n = ParseItems(DmorphOcto_ItemData and DmorphOcto_ItemData[slot], 0, {}, 0)
local seen = {}
for i = 1, n do
seen[base[i][1]] = true
end
local extra, m = ParseItems(DmorphOcto_ItemExtra and DmorphOcto_ItemExtra[slot], M.KIND_NEW, {}, 0, seen)
for i = 1, m do
seen[extra[i][1]] = true
end
local learned, k = LearnedItems(slot, seen)
local both, count = Merge(base, n, extra, m)
local all, total = Merge(both, count, learned, k)
-- Ported weapons and armour that fit the slot, with their Retail quality.
local ported, p = {}, 0
for id, item in pairs(PortedItems()) do
local slots = item.slot and { item.slot } or PORTED_SLOTS[item.kind] or {}
for i = 1, table.getn(slots) do
if slots[i] == slot then
p = p + 1
ported[p] = { id, item.name, strlower(item.name), item.quality, M.KIND_PORTED }
end
end
end
table.sort(ported, Before)
local catalog = Fill(NewCatalog(), Merge(all, total, ported, p))
catalog.types = {}
for i = 1, catalog.count do
catalog.types[i] = M.GetItemType(catalog.ids[i])
end
items[slot] = catalog
end
return items[slot]
end
-- The Slutmog tab's list (user, 18 Oct: "its own tab"): every revealing piece
-- (Data/Slutmog.lua) and OctoWoW's invisible Unseen Fashion items, from the
-- armour slots' item lists; catalog.slots[i] is the slot it's worn in.
-- Rebuilt when looked-up items join the lists.
local slutmogCatalog
M.SLUTMOG_SLOTS = { 1, 3, 4, 5, 6, 7, 8, 9, 10, 15, 19 }
function M.GetSlutmogCatalog()
local version = M.GetItemsVersion()
if not slutmogCatalog or slutmogCatalog.version ~= version then
local list, n, slotOf = {}, 0, {}
for s = 1, table.getn(M.SLUTMOG_SLOTS) do
local slot = M.SLUTMOG_SLOTS[s]
local c = M.GetItemCatalog(slot)
for i = 1, c.count do
local id = c.ids[i]
if not slotOf[id] and M.IsSlutmogItem(id, c.lower[i]) then
n = n + 1
list[n] = { id, c.names[i], c.lower[i], c.quality[i], c.kind[i] }
slotOf[id] = slot
end
end
end
table.sort(list, Before)
slutmogCatalog = Fill(NewCatalog(), list, n)
slutmogCatalog.slots = {}
for i = 1, slutmogCatalog.count do
slutmogCatalog.slots[i] = slotOf[slutmogCatalog.ids[i]]
end
slutmogCatalog.version = version
end
return slutmogCatalog
end
-- The slots an item can be morphed into, or nil if it isn't known.
local itemSlots
function M.GetItemSlots(itemID)
if not itemSlots then
itemSlots = {}
for i = 1, table.getn(SLOT_ORDER) do
local slot = SLOT_ORDER[i]
for id in pairs(M.GetItemCatalog(slot).byID) do
local list = itemSlots[id]
if not list then
list = {}
itemSlots[id] = list
end
table.insert(list, slot)
end
end
end
return itemSlots[itemID]
end
-- Item lists are rebuilt the next time they're needed (after a lookup).
local function ForgetItemLists()
items, itemSlots = {}, nil
if sets then
sets.qualityKnown = nil
end
end
-- An item's quality from the item lists, or nil.
local function ItemQuality(itemID)
local slots = M.GetItemSlots(itemID)
if slots then
local catalog = M.GetItemCatalog(slots[1])
return catalog.quality[catalog.byID[itemID]]
end
end
-- Every item set in the client, with the pieces that show on a character. A
-- set's quality is that of its best known piece.
function M.GetSetCatalog()
if not sets then
sets = NewCatalog()
sets.pieces = {}
local list, n = {}, 0
local function Pieces(text)
local pieces = {}
for piece in string.gfind(text, "%d+") do
table.insert(pieces, tonumber(piece))
end
return pieces
end
for id, kind, name, pieces in string.gfind(DmorphOcto_SetData or "", "(%d+)\t(%d)\t([^\t\r\n]+)\t([%d,]+)") do
n = n + 1
list[n] = { tonumber(id), name, strlower(name), tonumber(kind), Pieces(pieces) }
end
-- Data/Ported.lua's sets (DmorphOcto_PortedSets: name<TAB>virtual items),
-- only on the PC that has them; numbered after every real set.
local p = 0
for name, pieces in string.gfind(DmorphOcto_PortedSets or "", "([^\t\r\n]+)\t([%d,]+)") do
p = p + 1
n = n + 1
list[n] = { 900000 + p, name, strlower(name), M.KIND_PORTED, Pieces(pieces) }
end
DmorphOcto_SetData, DmorphOcto_PortedSets = nil, nil
if p > 0 then
table.sort(list, Before)
end
for i = 1, n do
AddEntry(sets, list[i][1], list[i][2], nil, list[i][4])
sets.pieces[sets.count] = list[i][5]
end
end
if not sets.qualityKnown then
sets.qualityKnown = true
sets.types = {}
for i = 1, sets.count do
-- Quality: the best piece's. Kind: the armour most pieces are made of.
local best, materials, kind = nil, {}, nil
for k = 1, table.getn(sets.pieces[i]) do
local quality = ItemQuality(sets.pieces[i][k])
if quality and (not best or quality > best) then
best = quality
end
local piece = M.GetItemType(sets.pieces[i][k])
if piece and piece >= 401 and piece <= 404 then
materials[piece] = (materials[piece] or 0) + 1
if not kind or materials[piece] > materials[kind] then
kind = piece
end
end
end
sets.quality[i], sets.types[i] = best, kind
end
end
return sets
end
-- The game's dressed NPCs of a race and gender (Data/Looks.lua), the fewest
-- clothes first. Each look is { displayID, skin, face, hair style, hair
-- colour, facial hair, pieces of clothing, outfit number }.
function M.GetLooks(race, gender)
local key = race .. ":" .. gender
if not looks[key] then
local list, n, hidden = {}, 0, HiddenModels()
local text = DmorphOcto_LookData and DmorphOcto_LookData[key] or ""
for a, b, c, d, e, f, g, h in string.gfind(text, "(%d+),(%d+),(%d+),(%d+),(%d+),(%d+),(%d+),(%d+)") do
if not hidden[tonumber(a)] then
n = n + 1
list[n] = { tonumber(a), tonumber(b), tonumber(c), tonumber(d), tonumber(e), tonumber(f), tonumber(g), tonumber(h) }
end
end
looks[key] = list
end
return looks[key]
end
-- The character creator's rows and the look field each one reads. NPC looks
-- are fixed combinations, so a row's < > goes to the next value some NPC of
-- that race has, in the look that keeps the most of the other rows.
M.LOOK_FEATURES = { "Skin colour", "Face", "Hair style", "Hair colour", "Facial hair", "Outfit" }
local LOOK_FIELDS = { 2, 3, 4, 5, 6, 8 }
-- What keeping each row is worth when another one changes. Each outweighs
-- all the ones below it: skin colour, hair style, hair colour, face, facial
-- hair, outfit.
local FEATURE_WEIGHTS = { 32, 4, 16, 8, 2, 1 }
-- The values row f (1-6) has among a race and gender's looks, sorted.
function M.GetLookValues(race, gender, f)
local list = M.GetLooks(race, gender)
local field = LOOK_FIELDS[f]
local seen, values = {}, {}
for k = 1, table.getn(list) do
local v = list[k][field]
if not seen[v] then
seen[v] = true
table.insert(values, v)
end
end
table.sort(values)
return values
end
-- Row f's value in a look.
function M.LookValue(look, f)
return look[LOOK_FIELDS[f]]
end
-- The position of the look that has `value` in row f and keeps the most of
-- look `from`'s other rows (then the most similar clothes), or nil.
function M.FindLook(race, gender, f, value, from)
local list = M.GetLooks(race, gender)
local field, want = LOOK_FIELDS[f], list[from]
local best, bestScore
for k = 1, table.getn(list) do
local look = list[k]
if look[field] == value then
local keep, pieces = 0, 0
if want then
for g = 1, 6 do
if g ~= f and look[LOOK_FIELDS[g]] == want[LOOK_FIELDS[g]] then
keep = keep + FEATURE_WEIGHTS[g]
end
end
pieces = math.abs(look[7] - want[7])
end
local score = keep * 1000 - pieces * 20 - look[7]
if not best or score > bestScore then
best, bestScore = k, score
end
end
end
return best
end
-- Every value of row f and, for each, the look FindLook picks from look `from`.
function M.GetLookChoices(race, gender, f, from)
local values, at = M.GetLookValues(race, gender, f), {}
for i = 1, table.getn(values) do
at[values[i]] = M.FindLook(race, gender, f, values[i], from)
end
return values, at
end
-- Row f of look `from` one value along (step 1 or -1, wrapping around). Returns
-- the new look's position, its place among the row's values, how many values
-- there are, and the other rows that had to change with it ({} if none); or
-- nil when every NPC of the race has the same value.
function M.StepLook(race, gender, f, from, step)
local list = M.GetLooks(race, gender)
local values = M.GetLookValues(race, gender, f)
local n, cur = table.getn(values), list[from]
if n < 2 or not cur then
return nil
end
local pos = 1
for i = 1, n do
if values[i] == cur[LOOK_FIELDS[f]] then
pos = i
end
end
pos = math.mod(pos - 1 + step + n, n) + 1
local k = M.FindLook(race, gender, f, values[pos], from)
local changed = {}
for g = 1, 6 do
if g ~= f and list[k][LOOK_FIELDS[g]] ~= cur[LOOK_FIELDS[g]] then
table.insert(changed, g)
end
end
return k, pos, n, changed
end
-- Item lookup -------------------------------------------------------------------
-- ItemsExtra.lua lists items whose slot isn't known offline: OctoWoW items
-- from Atlas-CFM's loot tables and the item sets. In the background, a few a
-- second, the addon reads them from the client's cache or (with ClassicAPI)
-- asks the server, and saves the answers account-wide. Found ones join the
-- item lists and the sets.
local LOOKUP_STEP, LOOKUP_TIMEOUT, LOOKUP_PARALLEL = 0.25, 20, 4
local lookup = { pos = 1, count = 0, ids = {}, waiting = {}, waitCount = 0, left = 0, version = 0 }
local function CanAskServer()
return type(C_Item) == "table" and type(C_Item.RequestLoadItemDataByID) == "function"
end
-- "slots<TAB>quality<TAB>name" for an item the client knows, false if it
-- doesn't show on a character, nil if the client doesn't know it yet.
local function ReadItemInfo(itemID)
local ok, name, _, quality, _, _, _, _, equipLoc = pcall(GetItemInfo, itemID)
if not (ok and name) then
return nil
end
local slots = EQUIP_SLOTS[equipLoc or ""]
if not slots then
return false
end
return table.concat(slots, ",") .. "\t" .. (quality or 1) .. "\t" .. string.gsub(name, "\t", " ")
end
local function Record(itemID, info)
if account.itemInfo[itemID] == nil and info ~= nil then
account.itemInfo[itemID] = info
lookup.left = lookup.left - 1
if info then
lookup.changed = true
end
end
end
-- How many items are still to be looked up, and how many there were.
function M.GetLookupStatus()
return lookup.left, lookup.count
end
-- Bumped whenever looked-up items join the lists, so the window can redraw.
function M.GetItemsVersion()
return lookup.version
end
local function StartLookup()
if lookup.started then
return
end
lookup.started = true
for id in string.gfind(DmorphOcto_ItemPending or "", "(%d+)\t") do
id = tonumber(id)
lookup.count = lookup.count + 1
lookup.ids[lookup.count] = id
if account.itemInfo[id] == nil then
lookup.left = lookup.left + 1
end
end
DmorphOcto_ItemPending = nil
-- OctoWoW's "Summer Collection of Unseen Fashion" (invisible pieces; the tabard
-- is 109): asked for once so they join the lists and the Slutmog filter.
for id = 100, 160 do
if account.itemInfo[id] == nil then
lookup.count = lookup.count + 1
lookup.ids[lookup.count] = id
lookup.left = lookup.left + 1
end
end
end