-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Pawn.lua
6004 lines (5389 loc) · 258 KB
/
Pawn.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Pawn by Vger-Azjol-Nerub
-- www.vgermods.com
-- © 2006-2024 Travis Spomer. This mod is released under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 license.
-- See Readme.htm for more information.
--
-- Main non-UI code
------------------------------------------------------------
PawnVersion = 2.1008
-- Pawn requires this version of VgerCore:
local PawnVgerCoreVersionRequired = 1.18
-- Floating point math
local PawnEpsilon = 0.0000000001
local PawnInfinity = 1.79769313E308
-- Set to true once initialization completes
local PawnIsInitialized
-- Name of our private tooltip defined in PawnUI.xml
PawnPrivateTooltipName = "PawnPrivateTooltip1"
-- Caching
-- An item in the cache has the following properties: Name, NumLines, UnknownLines, Stats, SocketBonusStats, UnenchantedStats, UnenchantedSocketBonusStats, Values, Link, PrettyLink, Level, Rarity, ID, InvType, Texture, ShouldUseGems
-- (See PawnGetEmptyCachedItem.)
-- An entry in the Values table is an ordered array in the following format:
-- { ScaleName, Value, UnenchantedValue }
local PawnItemCache
local PawnItemCacheMaxSize = 200 -- thanks to bag arrows, this should be greater than the number of possible inventory slots
local PawnScaleTotals = { }
-- Best gem data
-- Best gem data is broken down first by scale name, then by socket, then by minimum item level. "Gem info" is yet another table.
-- PawnScaleBestGems["Scale name"] = {
-- ["PrismaticSocket"] = { [0] = { gem info }, },
-- ["PrismaticSocketValue"] = { [0] = 234.56, }
-- ...and also Red, Yellow, Blue in place of Prismatic
-- }
PawnScaleBestGems = { }
PawnPlayerFullName = nil
-- Formatting
local PawnEnchantedAnnotationFormat, PawnUnenchantedAnnotationFormat, PawnNoValueAnnotationFormat
-- Plugin scale providers
-- PawnScaleProviders["Wowhead"] = { ["Name"] = "Wowhead scales", ["Function"] = <function> }
PawnScaleProviders = { }
local PawnScaleProvidersInitialized
-- "Constants"
local PawnCurrentScaleVersion = 1
local PawnTooltipAnnotation = " " .. PawnDiamondTexture -- diamond texture defined in Core.lua
local PawnScaleColorDarkFactor = 0.75 -- the unenchanted color is 75% of the enchanted color
PawnButtonPositionHidden = 0
PawnButtonPositionLeft = 1
PawnButtonPositionRight = 2
PawnImportScaleResultSuccess = 1
PawnImportScaleResultAlreadyExists = 2
PawnImportScaleResultTagError = 3
PawnIgnoreStatValue = -1000000
PawnBigUpgradeThreshold = 100 -- = 10000% upgrade: don't display upgrade numbers that large
-- Data used by PawnGetSlotsForItemType.
local PawnItemEquipLocToSlot1 =
{
INVTYPE_HEAD = 1,
INVTYPE_NECK = 2,
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_FINGER = 11,
INVTYPE_TRINKET = 13,
INVTYPE_CLOAK = 15,
INVTYPE_WEAPON = 16,
INVTYPE_SHIELD = 17,
INVTYPE_2HWEAPON = 16,
INVTYPE_WEAPONMAINHAND = 16,
INVTYPE_RANGED = 16,
INVTYPE_RANGEDRIGHT = 16,
INVTYPE_WEAPONOFFHAND = 17,
INVTYPE_HOLDABLE = 17,
INVTYPE_TABARD = 19,
}
-- In Classic, ranged weapons get their own slot.
if VgerCore.RangedSlotExists then
PawnItemEquipLocToSlot1.INVTYPE_RANGED = 18
PawnItemEquipLocToSlot1.INVTYPE_RANGEDRIGHT = 18
PawnItemEquipLocToSlot1.INVTYPE_RELIC = 18
PawnItemEquipLocToSlot1.INVTYPE_THROWN = 18
end
local PawnItemEquipLocToSlot2 =
{
INVTYPE_FINGER = 12,
INVTYPE_TRINKET = 14,
INVTYPE_WEAPON = 17,
}
local PawnReforgeableStats = { "CritRating", "DodgeRating", "ExpertiseRating", "HasteRating", "HitRating", "MasteryRating", "ParryRating", "Spirit" }
local PawnStatFriendlyNames = -- Currently only contains stat names used for reforging.
{
["CritRating"] = ITEM_MOD_CRIT_RATING_SHORT,
["DodgeRating"] = ITEM_MOD_DODGE_RATING_SHORT,
["ExpertiseRating"] = ITEM_MOD_EXPERTISE_RATING_SHORT,
["HasteRating"] = ITEM_MOD_HASTE_RATING_SHORT,
["HitRating"] = ITEM_MOD_HIT_RATING_SHORT,
["MasteryRating"] = ITEM_MOD_MASTERY_RATING_SHORT,
["ParryRating"] = ITEM_MOD_PARRY_RATING_SHORT,
["Spirit"] = ITEM_MOD_SPIRIT_SHORT,
}
-- Don't taint the global variable "_".
local _
------------------------------------------------------------
-- Called when an event that Pawn cares about is fired.
function PawnOnEvent(Event, arg1, arg2, ...)
if Event == "UNIT_INVENTORY_CHANGED" and arg1 == "player" then
PawnOnInventoryChanged()
elseif Event == "ITEM_LOCKED" then
PawnOnItemLocked(arg1, arg2)
PawnOnInventoryChanged()
elseif Event == "MERCHANT_UPDATE" then
PawnOnItemLost(GetBuybackItemLink(GetNumBuybackItems()))
elseif Event == "ADDON_LOADED" then
PawnOnAddonLoaded(arg1)
elseif Event == "PLAYER_SPECIALIZATION_CHANGED" and arg1 == "player" then
PawnOnSpecChanged()
elseif Event == "ARTIFACT_UPDATE" then
PawnOnArtifactUpdated()
elseif Event == "GROUP_ROSTER_UPDATE" then
PawnShowPlayingWithVgerEasterEgg()
elseif Event == "PLAYER_LOGIN" then
PawnInitialize()
elseif Event == "PLAYER_LOGOUT" then
PawnOnLogout()
end
end
-- Initializes Pawn after all saved variables have been loaded.
function PawnInitialize()
-- This only needs to happen once. If it's ever triggered again for any reason, bail out now.
if PawnIsInitialized then return end
local _
-- Check the current version of VgerCore.
if (not VgerCore) or (not VgerCore.Version) or (VgerCore.Version < PawnVgerCoreVersionRequired) then
if DEFAULT_CHAT_FRAME then DEFAULT_CHAT_FRAME:AddMessage("|cfffe8460" .. PawnLocal.NeedNewerVgerCoreMessage) end
message(PawnLocal.NeedNewerVgerCoreMessage)
return
end
-- Check the user's current locale, and show a message if it isn't the right one for this version of Pawn.
local CurrentLocale = GetLocale()
local CurrentLocaleIsSupported
local LanguageList = PawnLocalizedLanguages
for _, SupportedLocale in pairs(LanguageList) do
if CurrentLocale == SupportedLocale then
CurrentLocaleIsSupported = true
break
end
end
if not CurrentLocaleIsSupported then
-- No need to translate this string...
local WrongLocaleMessage = "Sorry, this version of Pawn is for English, French, German, Italian, Korean, Portuguese, Russian, Spanish, Simplified Chinese, and Traditional Chinese only."
VgerCore.Message(VgerCore.Color.Salmon .. WrongLocaleMessage)
message(WrongLocaleMessage)
end
-- Set up slash commands
SLASH_PAWN1 = "/pawn"
SlashCmdList["PAWN"] = PawnCommand
-- Set any unset options to their default values. If the user is a new Pawn user, all options
-- will be set to default values. If upgrading, only missing options will be set to default values.
PawnInitializeOptions()
-- Check for and set default keybindings.
PawnSetDefaultKeybindings()
-- Adjust UI elements.
PawnUI_InventoryPawnButton_Move()
-- Hook into events.
-- UI functions
hooksecurefunc("DeleteCursorItem",
function()
PawnOnItemLost(PawnLastCursorItemLink)
end)
hooksecurefunc("PickupMerchantItem",
function(Index)
if Index == 0 then PawnOnItemLost(PawnLastCursorItemLink) end
end)
-- Main game tooltip
-- Note that in Dragonflight, most or all of this could be replaced by hooking GameTooltip.ProcessInfo, but that won't work in older versions.
if not VgerCore.IsMainline then
-- SetAuctionItem was removed in 8.3.0 but is still there on Classic. The (incorrect) way that BankItems hooks this function
-- causes the detection to fail, so just directly check the version.
hooksecurefunc(GameTooltip, "SetAuctionItem", function(_, ...) PawnUpdateTooltip("GameTooltip", "SetAuctionItem", ...) end)
hooksecurefunc(GameTooltip, "SetAuctionSellItem", function(_, ...) PawnUpdateTooltip("GameTooltip", "SetAuctionSellItem", ...) end)
end
if VgerCore.IsMainline then
hooksecurefunc(GameTooltip, "SetItemKey", function(_, ItemID, ItemLevel, Suffix, ...) PawnUpdateTooltip("GameTooltip", "SetItemKey", ItemID, ItemLevel, Suffix, ...) end)
end
hooksecurefunc(GameTooltip, "SetBagItem", function() PawnUpdateTooltip("GameTooltip", "SetBagItem") end)
hooksecurefunc(GameTooltip, "SetBuybackItem", function() PawnUpdateTooltip("GameTooltip", "SetBuybackItem") end)
if GameTooltip.SetExistingSocketGem then
-- Gems don't exist in WoW Classic.
hooksecurefunc(GameTooltip, "SetExistingSocketGem", function() PawnUpdateTooltip("GameTooltip", "SetExistingSocketGem") end)
end
if GameTooltip.SetGuildBankItem then
-- Guild banks don't exist in WoW Classic.
hooksecurefunc(GameTooltip, "SetGuildBankItem", function() PawnUpdateTooltip("GameTooltip", "SetGuildBankItem") end)
end
if GameTooltip.SetHeirloomByItemID then
-- ...and neither do heirlooms.
hooksecurefunc(GameTooltip, "SetHeirloomByItemID", function() PawnUpdateTooltip("GameTooltip", "SetHeirloomByItemID") end)
end
hooksecurefunc(GameTooltip, "SetHyperlink", function(_, ...) PawnUpdateTooltip("GameTooltip", "SetHyperlink", ...) end)
hooksecurefunc(GameTooltip, "SetInboxItem", function() PawnUpdateTooltip("GameTooltip", "SetInboxItem") end)
hooksecurefunc(GameTooltip, "SetInventoryItem", function() PawnUpdateTooltip("GameTooltip", "SetInventoryItem") end)
hooksecurefunc(GameTooltip, "SetItemByID", function() PawnUpdateTooltip("GameTooltip", "SetItemByID") end)
hooksecurefunc(GameTooltip, "SetLootItem", function() PawnUpdateTooltip("GameTooltip", "SetLootItem") end)
hooksecurefunc(GameTooltip, "SetLootRollItem", function() PawnUpdateTooltip("GameTooltip", "SetLootRollItem") end)
hooksecurefunc(GameTooltip, "SetMerchantItem", function() PawnUpdateTooltip("GameTooltip", "SetMerchantItem") end)
hooksecurefunc(GameTooltip, "SetQuestItem", function() PawnUpdateTooltip("GameTooltip", "SetQuestItem") end)
hooksecurefunc(GameTooltip, "SetQuestLogItem", function() PawnUpdateTooltip("GameTooltip", "SetQuestLogItem") end)
hooksecurefunc(GameTooltip, "SetSendMailItem", function() PawnUpdateTooltip("GameTooltip", "SetSendMailItem") end)
if GameTooltip.SetSocketGem then
-- Gems don't exist in Classic.
hooksecurefunc(GameTooltip, "SetSocketGem", function() PawnUpdateTooltip("GameTooltip", "SetSocketGem") end)
end
hooksecurefunc(GameTooltip, "SetTradePlayerItem", function() PawnUpdateTooltip("GameTooltip", "SetTradePlayerItem") end)
if GameTooltip.SetRecipeResultItem then
hooksecurefunc(GameTooltip, "SetRecipeResultItem",
function(_, RecipeId)
local ItemLink = C_TradeSkillUI.GetRecipeItemLink(RecipeId)
PawnUpdateTooltip("GameTooltip", "SetHyperlink", ItemLink)
end)
end
if GameTooltip.SetTradeSkillItem then
hooksecurefunc(GameTooltip, "SetTradeSkillItem", function() PawnUpdateTooltip("GameTooltip", "SetTradeSkillItem") end)
end
hooksecurefunc(GameTooltip, "SetTradeTargetItem", function() PawnUpdateTooltip("GameTooltip", "SetTradeTargetItem") end)
if GameTooltip.SetVoidItem then
hooksecurefunc(GameTooltip, "SetVoidItem", function() PawnUpdateTooltip("GameTooltip", "SetVoidItem") end)
hooksecurefunc(GameTooltip, "SetVoidDepositItem", function() PawnUpdateTooltip("GameTooltip", "SetVoidDepositItem") end)
hooksecurefunc(GameTooltip, "SetVoidWithdrawalItem", function() PawnUpdateTooltip("GameTooltip", "SetVoidWithdrawalItem") end)
end
hooksecurefunc(GameTooltip, "SetTrainerService",
function(_, Index)
local ItemLink = GetTrainerServiceItemLink(Index)
if ItemLink then PawnUpdateTooltip("GameTooltip", "SetHyperlink", ItemLink) end
end)
if GameTooltip.SetWeeklyReward then
hooksecurefunc(GameTooltip, "SetWeeklyReward", function() PawnUpdateTooltip("GameTooltip", "SetWeeklyReward") end)
end
if GameTooltip.SetItemInteractionItem then
hooksecurefunc(GameTooltip, "SetItemInteractionItem", function() PawnUpdateTooltip("GameTooltip", "SetItemInteractionItem") end)
end
hooksecurefunc(GameTooltip, "Hide",
function()
PawnLastHoveredItem = nil
-- Hacky fix to prevent the green tooltip border from "leaking" if the next thing that is hovered over is not an item.
-- (Without this, hovering over an upgrade item and then a spell button would still get you a green border.)
if PawnCommon.ColorTooltipBorder then PawnSetTooltipBorderColor(GameTooltip, 1, 1, 1) end
end)
-- World quest embedded tooltips
hooksecurefunc("EmbeddedItemTooltip_SetItemByQuestReward",
function(self, QuestLogIndex, QuestID, ...)
if PawnCommon.ShowQuestUpgradeAdvisor then
local ItemName, ItemTexture = GetQuestLogRewardInfo(QuestLogIndex, QuestID)
if ItemName and ItemTexture then
PawnUpdateTooltip(self.Tooltip:GetName(), "SetQuestLogItem", "reward", QuestLogIndex, QuestID, ...)
self.Tooltip:Show() -- resizes the tooltip's boundaries in case our annotation made it wider
end
end
end)
-- The item link tooltip (only hook it if it's an actual item)
hooksecurefunc(ItemRefTooltip, "SetHyperlink",
function(_, ItemLink, ...)
-- Attach an icon to the tooltip first so that an existing icon can be hidden if the new hyperlink doesn't have one.
PawnAttachIconToTooltip(ItemRefTooltip, false, ItemLink)
if PawnGetHyperlinkType(ItemLink) ~= "item" then return end
PawnUpdateTooltip("ItemRefTooltip", "SetHyperlink", ItemLink, ...)
end)
ItemRefTooltip:HookScript("OnEnter", function() local _; _, PawnLastHoveredItem = ItemRefTooltip:GetItem() end)
ItemRefTooltip:HookScript("OnLeave", function() PawnLastHoveredItem = nil end)
ItemRefTooltip:HookScript("OnMouseUp",
function(_, button)
if button == "RightButton" then
local _, ItemLink = ItemRefTooltip:GetItem()
if ItemLink then PawnUI_SetCompareItemAndShow(2, ItemLink) end
elseif button == "LeftButton" and IsAltKeyDown() then
local _, ItemLink = ItemRefTooltip:GetItem()
if ItemLink then PawnUIGetAllTextForItem(ItemLink) end
end
end)
-- The group loot roll window
local LootRollClickHandler =
function(object, button)
if button == "RightButton" then
local ItemLink = GetLootRollItemLink(object:GetParent().rollID)
PawnUI_SetCompareItemAndShow(2, ItemLink)
end
end
GroupLootFrame1.IconFrame:HookScript("OnMouseUp", LootRollClickHandler)
GroupLootFrame2.IconFrame:HookScript("OnMouseUp", LootRollClickHandler)
GroupLootFrame3.IconFrame:HookScript("OnMouseUp", LootRollClickHandler)
GroupLootFrame4.IconFrame:HookScript("OnMouseUp", LootRollClickHandler)
GroupLootFrame1:HookScript("OnShow", PawnUI_GroupLootFrame_OnShow)
GroupLootFrame2:HookScript("OnShow", PawnUI_GroupLootFrame_OnShow)
GroupLootFrame3:HookScript("OnShow", PawnUI_GroupLootFrame_OnShow)
GroupLootFrame4:HookScript("OnShow", PawnUI_GroupLootFrame_OnShow)
-- The loot history window
-- (This was reimplemented as GroupLootHistoryFrame + LootHistoryElementMixin in 10.1.0. It's more challenging to
-- override than it was before, and given that I haven't even used the loot history window in like a decade... probably nbd.)
if LootHistoryFrame then
hooksecurefunc("LootHistoryFrame_UpdateItemFrame", PawnUI_LootHistoryFrame_UpdateItemFrame)
end
-- The loot won window
hooksecurefunc("LootWonAlertFrame_SetUp", PawnUI_LootWonAlertFrame_SetUp)
-- The "currently equipped" tooltips (two, in case of rings, trinkets, and dual wielding)
if ShoppingTooltip1.SetCompareItem then
hooksecurefunc(ShoppingTooltip1, "SetCompareItem",
function()
local _, ItemLink1 = ShoppingTooltip1:GetItem()
PawnUpdateTooltip("ShoppingTooltip1", "SetCompareItem", ItemLink1)
PawnAttachIconToTooltip(ShoppingTooltip1, true)
local _, ItemLink2 = ShoppingTooltip2:GetItem()
if ItemLink2 and ShoppingTooltip2:IsShown() then
PawnUpdateTooltip("ShoppingTooltip2", "SetHyperlink", ItemLink2)
PawnAttachIconToTooltip(ShoppingTooltip2, true)
end
end)
hooksecurefunc(ItemRefShoppingTooltip1, "SetCompareItem",
function()
local _, ItemLink1 = ItemRefShoppingTooltip1:GetItem()
PawnUpdateTooltip("ItemRefShoppingTooltip1", "SetCompareItem", ItemLink1)
PawnAttachIconToTooltip(ItemRefShoppingTooltip1, true)
local _, ItemLink2 = ItemRefShoppingTooltip2:GetItem()
if ItemLink2 and ItemRefShoppingTooltip2:IsShown() then
PawnUpdateTooltip("ItemRefShoppingTooltip2", "SetHyperlink", ItemLink2)
PawnAttachIconToTooltip(ItemRefShoppingTooltip2, true)
end
end)
end
-- Dragonflight replaces SetCompareItem with ProcessInfo. (ProcessInfo is now used internally by lots of
-- methods, but only in Dragonflight.)
if ShoppingTooltip1.ProcessInfo then
hooksecurefunc(ShoppingTooltip1, "ProcessInfo", function()
local _, ItemLink = TooltipUtil.GetDisplayedItem(ShoppingTooltip1)
if ItemLink then PawnUpdateTooltip("ShoppingTooltip1", "SetHyperlink", ItemLink) end
end)
hooksecurefunc(ShoppingTooltip2, "ProcessInfo", function()
local _, ItemLink = TooltipUtil.GetDisplayedItem(ShoppingTooltip2)
if ItemLink then PawnUpdateTooltip("ShoppingTooltip2", "SetHyperlink", ItemLink) end
end)
end
-- MultiTips compatibility
if MultiTips then
VgerCore.HookInsecureFunction(ItemRefTooltip2, "SetHyperlink", function(_, ItemLink) PawnUpdateTooltip("ItemRefTooltip2", "SetHyperlink", ItemLink) PawnAttachIconToTooltip(ItemRefTooltip2, false, ItemLink) end)
VgerCore.HookInsecureFunction(ItemRefTooltip3, "SetHyperlink", function(_, ItemLink) PawnUpdateTooltip("ItemRefTooltip3", "SetHyperlink", ItemLink) PawnAttachIconToTooltip(ItemRefTooltip3, false, ItemLink) end)
VgerCore.HookInsecureFunction(ItemRefTooltip4, "SetHyperlink", function(_, ItemLink) PawnUpdateTooltip("ItemRefTooltip4", "SetHyperlink", ItemLink) PawnAttachIconToTooltip(ItemRefTooltip4, false, ItemLink) end)
VgerCore.HookInsecureFunction(ItemRefTooltip5, "SetHyperlink", function(_, ItemLink) PawnUpdateTooltip("ItemRefTooltip5", "SetHyperlink", ItemLink) PawnAttachIconToTooltip(ItemRefTooltip5, false, ItemLink) end)
end
-- EquipCompare compatibility
if ComparisonTooltip1 then
if ComparisonTooltip1.SetHyperlinkCompareItem then VgerCore.HookInsecureFunction(ComparisonTooltip1, "SetHyperlinkCompareItem", function(_, ItemLink) PawnUpdateTooltip("ComparisonTooltip1", "SetHyperlinkCompareItem", ItemLink) PawnAttachIconToTooltip(ComparisonTooltip1, true) end) end
if ComparisonTooltip1.SetInventoryItem then VgerCore.HookInsecureFunction(ComparisonTooltip1, "SetInventoryItem", function() PawnUpdateTooltip("ComparisonTooltip1", "SetInventoryItem") PawnAttachIconToTooltip(ComparisonTooltip1, true) end) end -- EquipCompare with CharactersViewer
if ComparisonTooltip1.SetHyperlink then VgerCore.HookInsecureFunction(ComparisonTooltip1, "SetHyperlink", function(_, ItemLink) PawnUpdateTooltip("ComparisonTooltip1", "SetHyperlink", ItemLink) PawnAttachIconToTooltip(ComparisonTooltip1, true) end) end -- EquipCompare with Armory
end
if ComparisonTooltip2 then
if ComparisonTooltip2.SetHyperlinkCompareItem then VgerCore.HookInsecureFunction(ComparisonTooltip2, "SetHyperlinkCompareItem", function(_, ItemLink) PawnUpdateTooltip("ComparisonTooltip2", "SetHyperlinkCompareItem", ItemLink) PawnAttachIconToTooltip(ComparisonTooltip2, true) end) end
if ComparisonTooltip2.SetInventoryItem then VgerCore.HookInsecureFunction(ComparisonTooltip2, "SetInventoryItem", function() PawnUpdateTooltip("ComparisonTooltip2", "SetInventoryItem") PawnAttachIconToTooltip(ComparisonTooltip2, true) end) end -- EquipCompare with CharactersViewer
if ComparisonTooltip2.SetHyperlink then VgerCore.HookInsecureFunction(ComparisonTooltip2, "SetHyperlink", function(_, ItemLink) PawnUpdateTooltip("ComparisonTooltip2", "SetHyperlink", ItemLink) PawnAttachIconToTooltip(ComparisonTooltip2, true) end) end -- EquipCompare with Armory
end
-- Outfitter compatibility
if Outfitter and Outfitter._ExtendedCompareTooltip then
VgerCore.HookInsecureFunction(Outfitter._ExtendedCompareTooltip, "AddShoppingLink", function(self, _, _, pLink, ...) PawnUpdateTooltip("OutfitterCompareTooltip" .. self.NumTooltipsShown, "SetHyperlink", pLink) end)
end
-- AtlasLoot Enhanced compatibility
if AtlasLootTooltip then
VgerCore.HookInsecureFunction(AtlasLootTooltip, "SetHyperlink", function(_, ...) PawnUpdateTooltip("AtlasLootTooltip", "SetHyperlink", ...) end)
VgerCore.HookInsecureFunction(AtlasLootTooltip, "SetItemByID", function() PawnUpdateTooltip("AtlasLootTooltip", "SetItemByID") end)
end
-- LinkWrangler compatibility -- hook the Link Wrangler item link tooltips.
if LinkWrangler then
LinkWrangler.RegisterCallback("Pawn", PawnLinkWranglerOnTooltip, "refresh")
LinkWrangler.RegisterCallback("Pawn", PawnLinkWranglerOnTooltip, "refreshcomp")
end
-- ArkInventory integration: register the pawnupgrade() and pawnnotupgrade() rules
if ArkInventoryRules then
local arkInventoryModule = ArkInventoryRules:NewModule("Pawn")
ArkInventoryRules.Register(arkInventoryModule, "PAWNUPGRADE", ArkInventoryRulePawnUpgrade)
ArkInventoryRules.Register(arkInventoryModule, "PAWNNOTUPGRADE", ArkInventoryRulePawnNotUpgrade)
end
-- AceConfigDialog compatibility
if AceConfigDialogTooltip then
VgerCore.HookInsecureFunction(AceConfigDialogTooltip, "SetHyperlink", function(_, ItemLink) PawnUpdateTooltip("AceConfigDialogTooltip", "SetHyperlink", ItemLink) end)
end
-- In-bag upgrade icons
if VgerCore.IsMainline then
PawnOriginalIsContainerItemAnUpgrade = IsContainerItemAnUpgrade
PawnIsContainerItemAnUpgrade = function(bagID, slot, ...)
if PawnCommon.ShowBagUpgradeAdvisor then
local ItemInfo = C_Container.GetContainerItemInfo(bagID, slot)
if not ItemInfo or not ItemInfo.stackCount then return false end -- If the stack count is 0, it's clearly not an upgrade
if not ItemInfo.hyperlink then return nil end -- If we didn't get an item link, but there's an item there, try again later
return PawnShouldItemLinkHaveUpgradeArrow(ItemInfo.hyperlink, true) -- true means to check player level
else
if PawnOriginalIsContainerItemAnUpgrade then
---@diagnostic disable-next-line: redundant-parameter
return PawnOriginalIsContainerItemAnUpgrade(bagID, slot, ...)
else
-- If Pawn's bag advisor is off, AND the game's IsContainerItemAnUpgrade is missing, nothing's an upgrade.
return false
end
end
end
PawnUpdateItemUpgradeIcon = function(self)
if self.isExtended then return end
local IsUpgrade = PawnIsContainerItemAnUpgrade(self.GetBagID and self:GetBagID() or self:GetParent():GetID(), self:GetID())
if IsUpgrade == nil then
self.UpgradeIcon:SetShown(false)
self:SetScript("OnUpdate", self.TryUpdateItemUpgradeIcon or ContainerFrameItemButton_TryUpdateItemUpgradeIcon)
else
self.UpgradeIcon:SetShown(IsUpgrade)
self:SetScript("OnUpdate", nil)
end
end
end
if ContainerFrameItemButtonMixin and ContainerFrameItemButtonMixin.UpdateItemUpgradeIcon then
-- 10.0.0 only - this code was removed from the game in 10.0.2
-- First, hook ContainerFrameItemButtonMixin to affect all future bag frames.
hooksecurefunc(ContainerFrameItemButtonMixin, "UpdateItemUpgradeIcon", PawnUpdateItemUpgradeIcon)
-- Unfortunately, the Mixin is not a prototype so changes are not retroactive to bags that have already been created,
-- so now we need to update all of those.
for i = 1, NUM_TOTAL_BAG_FRAMES do
local Bag = _G["ContainerFrame" .. i]
if Bag.Items then
for _, Button in Bag:EnumerateItems() do
hooksecurefunc(Button, "UpdateItemUpgradeIcon", PawnUpdateItemUpgradeIcon)
end
end
end
elseif ContainerFrame_UpdateItemUpgradeIcons then
-- Legion through Shadowlands
-- Changing IsContainerItemAnUpgrade now causes taint errors, and replacing this function with a copy of itself
-- works on its own, but breaks other addons that hook this function like CanIMogIt. So, our best option appears to
-- be to just let the default version run, and then change its results immediately after.
hooksecurefunc("ContainerFrameItemButton_UpdateItemUpgradeIcon", PawnUpdateItemUpgradeIcon)
end
-- Dragonflight professions UI
if C_TradeSkillUI and C_TradeSkillUI.SetTooltipRecipeResultItem then
hooksecurefunc(C_TradeSkillUI, "SetTooltipRecipeResultItem", function() PawnUpdateTooltip("GameTooltip", "C_TradeSkillUI.SetTooltipRecipeResultItem") end)
end
-- We're now effectively initialized. Just the last steps of scale initialization remain.
PawnIsInitialized = true
-- If any of our dependencies have already loaded, pretend that they just loaded now.
if C_AddOns.IsAddOnLoaded("Blizzard_ArtifactUI") then PawnOnAddonLoaded("Blizzard_ArtifactUI") end
if C_AddOns.IsAddOnLoaded("Blizzard_EncounterJournal") then PawnOnAddonLoaded("Blizzard_EncounterJournal") end
if C_AddOns.IsAddOnLoaded("Blizzard_InspectUI") then PawnOnAddonLoaded("Blizzard_InspectUI") end
if C_AddOns.IsAddOnLoaded("Blizzard_ItemSocketingUI") then PawnOnAddonLoaded("Blizzard_ItemSocketingUI") end
if C_AddOns.IsAddOnLoaded("Blizzard_ReforgingUI") then PawnOnAddonLoaded("Blizzard_ReforgingUI") end
-- Now, load any plugins that are ready to be loaded.
PawnInitializePlugins()
-- Go through the user's scales and check them for errors.
for ScaleName, _ in pairs(PawnCommon.Scales) do
PawnCorrectScaleErrors(ScaleName)
end
-- Warn them if Pawn might be broken due to changing the thousands or decimal separator.
if not (GetLocale() == "frFR" and not VgerCore.IsMainline) then
-- The separator strings are completely wrong on French WoW Classic. :(
if (LARGE_NUMBER_SEPERATOR and PawnLocal.ThousandsSeparator ~= LARGE_NUMBER_SEPERATOR) or
(DECIMAL_SEPERATOR and PawnLocal.DecimalSeparator ~= DECIMAL_SEPERATOR) then
VgerCore.Fail("Pawn may provide incorrect advice due to a potential addon conflict: Pawn is not compatible with Combat Numbers Separator, Titan Panel Artifact Power, or other addons that change the way that numbers appear. Or, if you're seeing this right after a patch, please let Vger know you're seeing it on WoW " .. GetLocale() .. " " .. GetBuildInfo() .. ".")
end
end
-- If auto-spec is on, check their spec now in case they switched on a different PC.
if GetSpecialization then
PawnOnSpecChanged()
end
-- Then, recalculate totals.
-- This must be done after checking for errors is completed on all scales because it can trigger other recalculations.
for ScaleName, _ in pairs(PawnCommon.Scales) do
PawnRecalculateScaleTotal(ScaleName)
end
end
function PawnOnLogout()
-- Uninitialize all scale provider plugins.
PawnUnitializePlugins()
-- Clear out cached best item lists for all disabled scales.
if (not PawnCommon.ShowUpgradesOnTooltips) and (not PawnCommon.ShowLootUpgradeAdvisor) and (not PawnCommon.ShowQuestUpgradeAdvisor) then
-- The user has disabled all upgrade options, so clear out all upgrade information.
PawnInvalidateBestItems()
else
for _, Scale in pairs(PawnCommon.Scales) do
local CharacterOptions = Scale.PerCharacterOptions[PawnPlayerFullName]
if CharacterOptions and not CharacterOptions.Visible then
-- If this scale is hidden for this character, we can remove the character options table entirely since
-- Visible and BestItems are currently the only two members and we want to clear out BestItems for
-- invisible scales. (If more members are added in the future, this will need to be fleshed out.)
Scale.PerCharacterOptions[PawnPlayerFullName] = nil
end
end
end
end
function PawnOnAddonLoaded(AddonName)
-- Is Pawn hasn't initialized yet, skip this. We'll rerun this from PawnInitialize later.
if not PawnIsInitialized then return end
if AddonName == "Blizzard_InspectUI" then
-- After the inspect UI is loaded, we want to hook it to add the Pawn button.
PawnUI_InspectPawnButton_Attach()
elseif AddonName == "Blizzard_ItemSocketingUI" then
-- After the socketing UI is loaded, it gets a Pawn button too.
PawnUI_SocketingPawnButton_Attach()
elseif AddonName == "Blizzard_ReforgingUI" then
-- After the reforging UI is loaded, it gets the Pawn Reforging Advisor.
PawnUI_ReforgingAdvisor_Initialize()
elseif AddonName == "Blizzard_ArtifactUI" then
-- After the artifact UI is loaded, watch the relic sockets.
PawnUI_HookArtifactUI()
elseif AddonName == "Blizzard_EncounterJournal" then
-- After the encounter journal is loaded, watch the loot buttons.
PawnUI_HookEncounterJournal()
end
end
-- Resets all Pawn options and scales. Used to set the saved variable to a default state.
function PawnResetOptions()
PawnCommon = nil
PawnOptions = nil
PawnInitializeOptions()
end
-- Sets values for any options that don't have a value set yet. Useful when upgrading. This method can also be
-- called by any code that might run before initialization finishes to ensure that PawnCommon exists and is set up.
function PawnInitializeOptions()
local _
-- If either of the options tables don't exist yet, create them now.
if not PawnCommon then PawnCommon = {} end
if not PawnOptions then PawnOptions = {} end
-- We need to know the player's full name for some server-specific settings.
PawnPlayerFullName = UnitName("player") .. "-" .. GetRealmName()
-- Save the last known player name to PawnOptions so that we can detect character renames and server
-- transfers in the future.
PawnOptions.LastPlayerFullName = PawnPlayerFullName
-- Now, migrate all settings over to PawnCommon, and upgrade to the current version from any previous version
-- of Pawn (or none at all). Settings are respected in this order of preference:
-- 1. Global settings in PawnCommon
-- 2. Per-character settings in PawnOptions (used prior to Pawn 1.3)
-- 3. The default values for the settings.
PawnMigrateSetting("Debug", false)
PawnMigrateSetting("Digits", 1)
PawnMigrateSetting("ShowItemID", false)
PawnMigrateSetting("AlignNumbersRight", false)
PawnMigrateSetting("ButtonPosition", PawnButtonPositionRight)
PawnMigrateSetting("ShowTooltipIcons", true)
-- Set default values for other new options.
if PawnCommon.ShowUpgradesOnTooltips == nil then PawnCommon.ShowUpgradesOnTooltips = true end
if PawnCommon.ShowValuesForUpgradesOnly == nil then PawnCommon.ShowValuesForUpgradesOnly = true end
if PawnCommon.ColorTooltipBorder == nil then PawnCommon.ColorTooltipBorder = true end
if PawnCommon.ShowUpgradeAdvisors ~= nil then
-- If the user's upgrading from Pawn 1.5.4 or earlier, migrate the single upgrade advisors setting into the two settings in 1.5.5.
if PawnCommon.ShowLootUpgradeAdvisor == nil then PawnCommon.ShowLootUpgradeAdvisor = PawnCommon.ShowUpgradeAdvisors end
if PawnCommon.ShowQuestUpgradeAdvisor == nil then PawnCommon.ShowQuestUpgradeAdvisor = PawnCommon.ShowUpgradeAdvisors end
PawnCommon.ShowUpgradeAdvisors = nil
else
-- Otherwise just default them to on.
if PawnCommon.ShowLootUpgradeAdvisor == nil then PawnCommon.ShowLootUpgradeAdvisor = true end
if PawnCommon.ShowQuestUpgradeAdvisor == nil then PawnCommon.ShowQuestUpgradeAdvisor = true end
end
if PawnCommon.ShowSocketingAdvisor == nil then PawnCommon.ShowSocketingAdvisor = true end
-- Now, migrate all scales from this character over to PawnCommon.
if not PawnCommon.Scales then PawnCommon.Scales = {} end
if PawnOptions.Scales then
-- Looks like there's one or more scales on this character that need to be migrated.
for ScaleName, Scale in pairs(PawnOptions.Scales) do
if PawnCommon.Scales[ScaleName] then
-- This scale name already exists, so we have to make it unique first.
-- First, try just appending the player name.
-- If that's not good enough, start trying sequential numbers. (Sigh; why do people need
-- to make things so complicated? Did you really need ten characters with the same name
-- and identically named scales on each one?)
ScaleName = ScaleName .. " (" .. UnitName("player") .. ")"
local ScaleNameBase = ScaleName .. " ("
local i = 0
while PawnCommon.Scales[ScaleName] do
i = i + 1
ScaleName = ScaleNameBase .. i .. ")"
end
end
-- We now have a unique name for this scale, so transfer it over to the master scale list.
PawnCommon.Scales[ScaleName] = Scale
Scale.PerCharacterOptions = { }
Scale.PerCharacterOptions[PawnPlayerFullName] = { }
if not Scale.Hidden then
Scale.PerCharacterOptions[PawnPlayerFullName].Visible = true
end
Scale.NormalizationFactor = PawnOptions.NormalizationFactor
Scale.Hidden = nil
end
end
-- Now that migration is complete, remove all migrated scales from the per-character options.
PawnOptions.Scales = nil
-- These options have been removed or otherwise are no longer useful.
PawnOptions.ShowItemLevel = nil
PawnOptions.ShownGettingStarted = nil
PawnOptions.NormalizationFactor = nil
PawnCommon.ShowUnenchanted = nil
PawnCommon.ShowAsterisks = nil
PawnCommon.ShowBoth1HAnd2HUpgrades = nil
PawnCommon.ShowSpace = nil
-- Remove any stale scales from previous versions that might have accumulated.
-- the user might have accumulated.
local ScalesToDelete = { }
for ScaleName, Scale in pairs(PawnCommon.Scales) do
if Scale.Provider == "PawnPlaceholder" or Scale.Provider == "Starter" or Scale.Provider == "Wowhead" then tinsert(ScalesToDelete, ScaleName) end
end
for _, ScaleName in pairs(ScalesToDelete) do
PawnCommon.Scales[ScaleName] = nil
PawnRecalculateScaleTotal(ScaleName) -- removes information from the cache
end
-- And some more in WoW 7.1.
PawnCommon.IgnoreItemUpgrades = nil
-- Any new stuff since the last version they used?
if not PawnCommon.LastVersion then PawnCommon.LastVersion = 0 end
if not PawnOptions.LastVersion then PawnOptions.LastVersion = 0 end
if PawnCommon.LastVersion < 1.9 then
-- When upgrading to 1.9, enable the "ignore sockets on low-level items" option.
PawnCommon.IgnoreGemsWhileLeveling = true
end
if PawnCommon.LastVersion < 2.0000 then
-- The new "show spec icons" option is enabled by default.
PawnCommon.ShowSpecIcons = true
end
if PawnOptions.LastVersion < 2.0000 then
-- When upgrading each character to 2.0, turn on the auto-scale option, but just once.
PawnOptions.AutoSelectScales = true
end
if PawnCommon.LastVersion < 2.0101 then
-- The new Bag Upgrade Advisor is on by default, but it's not supported in Classic.
if VgerCore.IsMainline then
PawnCommon.ShowBagUpgradeAdvisor = true
else
PawnCommon.ShowBagUpgradeAdvisor = false
end
end
if PawnOptions.LastVersion < 2.0219 then
-- The item squish happened in WoW 8.0, so artifact relic item levels changed.
PawnOptions.Artifacts = nil
end
if PawnOptions.LastVersion < 2.0227 then
-- The artifact relic advisor is off by default as of 2.2.27.
PawnCommon.ShowRelicUpgrades = false
end
if PawnCommon.LastVersion < 2.0232 then
-- When upgrading to 2.2.32, turn off this annoying debug option if they still had it on.
PawnCommon.DebugCache = nil
end
if PawnCommon.LastVersion < 2.0244 then
-- The "show item level upgrades" option is new for 2.2.44 and on by default, but NOT in Classic.
if VgerCore.IsMainline then
PawnCommon.ShowItemLevelUpgrades = true
else
PawnCommon.ShowItemLevelUpgrades = false
end
end
if PawnCommon.LastVersion < 2.0403 then
-- Pawn 2.4 came out with patch 9.0 and the level squish, so reset everything.
-- Pawn 2.4.3 improved this behavior, so do it one last time.
PawnInvalidateBestItems()
end
if PawnOptions.LastVersion < 2.0400 then
-- The best item level data is still per-character, so we have to wait until first logon for that character.
-- If we already did that back in 2.4.0 we don't need to do this part again.
PawnClearBestItemLevelData()
end
if PawnCommon.LastVersion < 2.0402 and VgerCore.DeathKnightsExist then
-- Frost death knights can fully use 2H weapons again, but the setting to hide 2H upgrades is persistent.
-- Clear it this one time; people can go back to hiding them if they want.
local FrostDK = PawnCommon.Scales["\"MrRobot\":DEATHKNIGHT2"]
if FrostDK then FrostDK.DoNotShow2HUpgrades = false end
end
if (VgerCore.ReforgingExists and PawnCommon.LastVersion < 2.0902) then
-- Enable the reforging advisor by default on Cataclysm Classic.
PawnCommon.ShowReforgingAdvisor = true
end
if ((VgerCore.IsMainline) and PawnCommon.LastVersion < PawnMrRobotLastUpdatedVersion) or
((VgerCore.IsClassic or VgerCore.IsBurningCrusade or VgerCore.IsWrath or VgerCore.IsCataclysm) and PawnCommon.LastVersion < PawnClassicLastUpdatedVersion) then
-- If the Ask Mr. Robot scales have been updated since the last time they used Pawn, re-scan gear.
PawnInvalidateBestItems()
end
PawnCommon.LastVersion = PawnVersion
PawnOptions.LastVersion = PawnVersion
-- Pawn on WoW Classic doesn't have Automatic mode.
if not VgerCore.SpecsExist then
PawnOptions.AutoSelectScales = false
end
-- Finally, this stuff needs to get done after options are changed.
PawnRecreateAnnotationFormats()
end
-- If the specified setting does not exist in the common settings list, this function first tries to migrate it from the
-- current character's settings (from Pawn 1.2 or earlier). If it's not there either, it's set to a default value.
function PawnMigrateSetting(SettingName, Default)
if PawnCommon[SettingName] ~= nil then
PawnOptions[SettingName] = nil
return
end
if PawnOptions[SettingName] ~= nil then
PawnCommon[SettingName] = PawnOptions[SettingName]
PawnOptions[SettingName] = nil
return
end
PawnCommon[SettingName] = Default
end
-- Once per new version of Pawn that adds keybindings, bind the new actions to default keys.
function PawnSetDefaultKeybindings()
-- SaveBindings doesn't work on WoW Classic.
if not VgerCore.IsMainline then return end
-- It's possible that this will happen before the main initialization code, so we need to ensure that the
-- default Pawn options have been set already. Doing this multiple times is harmless.
if not PawnCommon then VgerCore.Fail("Can't set keybindings until Pawn starts to initialize.") return end
if PawnOptions.LastKeybindingsSet == nil then PawnOptions.LastKeybindingsSet = 0 end
local BindingSet = false
-- Keybindings for opening the Pawn UI and setting comparison items.
if PawnOptions.LastKeybindingsSet < 1 then
BindingSet = PawnSetKeybindingIfAvailable(PAWN_TOGGLE_UI_DEFAULT_KEY, "PAWN_TOGGLE_UI") or BindingSet
BindingSet = PawnSetKeybindingIfAvailable(PAWN_COMPARE_LEFT_DEFAULT_KEY, "PAWN_COMPARE_LEFT") or BindingSet
BindingSet = PawnSetKeybindingIfAvailable(PAWN_COMPARE_RIGHT_DEFAULT_KEY, "PAWN_COMPARE_RIGHT") or BindingSet
end
-- If any keybindings were changed, save the user's bindings.
if BindingSet then
local CurrentBindingSet = GetCurrentBindingSet()
if CurrentBindingSet == 1 or CurrentBindingSet == 2 then
SaveBindings(CurrentBindingSet)
else
VgerCore.Fail("GetCurrentBindingSet() returned unexpected value: " .. tostring(CurrentBindingSet))
end
end
-- Record that we've set those keybindings, so we don't try to set them again in the future, even if
-- the user clears them.
PawnOptions.LastKeybindingsSet = 1
end
-- Sets a keybinding to its default value if it's not already assigned to something else. Returns true if anything was changed.
function PawnSetKeybindingIfAvailable(Key, Binding)
-- Is this key already bound?
local ExistingBinding = GetBindingAction(Key, true) -- true: check overrides as well (ElvUI compatibility)
if not ExistingBinding or ExistingBinding == "" then
-- Bind this key to its default Pawn action.
SetBinding(Key, Binding)
return true
else
-- This key is already bound, so do nothing.
return false
end
end
-- Returns an empty Pawn scale table.
function PawnGetEmptyScale()
return
{
["PerCharacterOptions"] = { },
["Values"] = { },
}
end
-- Returns the default Pawn scale table, either for the current player's spec, or for the supplied class and spec if non-nil.
function PawnGetDefaultScale(ClassID, SpecID, NoStats)
local _
if ClassID == nil then
_, _, ClassID = UnitClass("player")
end
if not VgerCore.SpecsExist then
SpecID = nil
elseif SpecID == nil then
SpecID = GetSpecialization()
end
local Template = PawnFindScaleTemplate(ClassID, SpecID)
local ScaleValues = PawnGetStatValuesForTemplate(Template, NoStats)
return
{
["ClassID"] = ClassID,
["SpecID"] = SpecID,
["PerCharacterOptions"] = { },
["Values"] = ScaleValues,
}
end
-- LinkWrangler compatibility
function PawnLinkWranglerOnTooltip(Tooltip, ItemLink)
if not PawnIsInitialized then return end
if not Tooltip then return end
PawnUpdateTooltip(Tooltip:GetName(), "SetHyperlink", ItemLink)
PawnAttachIconToTooltip(Tooltip, false, ItemLink)
end
-- ArkInventory rules
function GetPawnStatusForArkInventoryRule(...)
if not PawnIsInitialized then VgerCore.Fail("Can't check to see if items are upgrades until Pawn is initialized") return end
local Info = ArkInventoryRules.Object.info
if not Info or ArkInventoryRules.Object.class ~= "item" then return false end
-- Use the same logic for determining whether or not an arrow should be shown, for consistency
local ItemLink = Info.h
return PawnIsItemDefinitivelyAnUpgrade(ItemLink, true)
end
function ArkInventoryRulePawnUpgrade(...)
-- For pawnupgrade(), we only want to return true if Pawn is sure that it is an upgrade.
-- This means for nil or false, we return false.
return GetPawnStatusForArkInventoryRule(...) == true
end
function ArkInventoryRulePawnNotUpgrade(...)
-- For pawnnotupgrade(), we only want to return true if Pawn is sure that it is not an upgrade
-- This means for nil or true, we return false.
return GetPawnStatusForArkInventoryRule(...) == false
end
-- This is a variant of PawnShouldItemLinkHaveUpgradeArrow for the ArkInventory rules.
-- It decidedly does not offer an opinion on items that are not gear or do not have stats. This means a true is a definitive upgrade
-- and a false is definitively not an upgrade. Otherwise, this function returns nil.
-- Returns:
-- true: This item is indeed an upgrade for something.
-- false: This item is not an upgrade.
-- nil: We're not sure or don't care because it isn't gear.
function PawnIsItemDefinitivelyAnUpgrade(ItemLink, CheckLevel)
-- REVIEW: This was copied from PawnShouldItemLinkHaveUpgradeArrow. This stuff could use some refactoring.
if not PawnIsInitialized then VgerCore.Fail("Can't check to see if items are upgrades until Pawn is initialized") return nil end
local _, _, _, _, MinLevel = C_Item.GetItemInfo(ItemLink)
-- If it doesn't have a minlevel, we don't care because it isn't gear
if MinLevel == nil then return nil end
-- If the gear minlevel is higher than the player, we don't care to determine if it is an upgrade, since they can't use it yet
-- but may not want to mark it as not an upgrade
if CheckLevel and UnitLevel("player") < MinLevel then return nil end
if PawnCanItemHaveStats(ItemLink) then
local Item = PawnGetItemData(ItemLink)
-- If there are no stats, we don't know what's happening, so we won't make a judgment
if Item == nil or Item.Link == nil then return nil end
local UpgradeInfo, ItemLevelIncrease = PawnIsItemAnUpgrade(Item)
-- If upgrade info was returned, it's an upgrade OR if there is an item level increase, it's an upgrade
return UpgradeInfo ~= nil or (PawnCommon.ShowItemLevelUpgrades and ItemLevelIncrease ~= nil)
elseif PawnCommon.ShowRelicUpgrades and PawnCanItemBeArtifactUpgrade(ItemLink) then
-- If there is artifact relic upgrade information, it's an upgrade.
return PawnGetRelicUpgradeInfo(ItemLink) ~= nil
else
-- If the item can't have stats, it isn't gear (probably), so we don't care.
return nil
end
end
-- If debugging is enabled, show a message; otherwise, do nothing.
function PawnDebugMessage(Message)
if PawnCommon.Debug then
VgerCore.Message(Message)
end
end
-- Processes a Pawn slash command.
function PawnCommand(Command)
if Command == "" then
PawnUIShow()
elseif Command == "debug on" then
PawnCommon.Debug = true
PawnResetTooltips()
if PawnUIFrame_DebugCheck then PawnUIFrame_DebugCheck:SetChecked(PawnCommon.Debug) end
elseif Command == "debug off" then
PawnCommon.Debug = false
PawnResetTooltips()
if PawnUIFrame_DebugCheck then PawnUIFrame_DebugCheck:SetChecked(PawnCommon.Debug) end
elseif Command == "backup" then
PawnUIExportAllScales()
elseif strsub(Command, 1, 7) == "tooltip" then
local ItemLink = strsub(Command, 9)
local ItemID = tonumber(ItemLink)
ItemRefTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE")
if ItemID then
ItemRefTooltip:SetHyperlink("item:" .. ItemID)
else
if strsub(ItemLink, 1, 5) ~= "item:" then ItemLink = "item:" .. ItemLink end
ItemRefTooltip:SetHyperlink(ItemLink)
end
ItemRefTooltip:Show()
elseif strsub(Command, 1, 7) == "compare" then
local ItemLink1, ItemLink2
if strsub(Command, 9, 13) == "left " then
local SplitIndex = strfind(Command, " right ", 13, true)
if SplitIndex and SplitIndex + 7 < strlen(Command) then
-- Left Item1 Right Item2
ItemLink1 = strsub(Command, 14, SplitIndex - 1)
ItemLink2 = strsub(Command, SplitIndex + 7)
else
-- Left Item1
ItemLink1 = strsub(Command, 14)
end
elseif strsub(Command, 9, 14) == "right " then
-- Right Item2
ItemLink2 = strsub(Command, 15)
else
-- Item2
ItemLink2 = strsub(Command, 9)
end
if ItemLink1 and strlen(ItemLink1) == 0 then ItemLink1 = nil end
if ItemLink2 and strlen(ItemLink2) == 0 then ItemLink2 = nil end
if ItemLink1 or ItemLink2 then
if ItemLink2 then
local IsReady2 = (C_Item.GetItemInfo(ItemLink2) ~= nil)
if IsReady2 then
PawnUI_SetCompareItemAndShow(2, ItemLink2)
else
C_Timer.After(1, function() PawnUI_SetCompareItemAndShow(2, ItemLink2) end)
end
end
if ItemLink1 then
local IsReady1 = (C_Item.GetItemInfo(ItemLink1) ~= nil)
if IsReady1 then
PawnUI_SetCompareItemAndShow(1, ItemLink1)