diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1784bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,221 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +################# +## JetBrains IDEA +################# + +.idea/ diff --git a/README.md b/README.md index 08705bb..88c1216 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,16 @@ Includes a database to initialize default prices from vanilla core. If your server has custom items or prices, those will be updated when you visit a vendor like the original plugin ![SellValue](https://user-images.githubusercontent.com/13628128/58877571-b9846e80-86d9-11e9-905d-5da424049b07.png) + +## Features + +Shows the value of items on the tooltip on + +- Items linked in chat +- Items in the loot window +- Items in the roll window +- Items in bags +- Items in bank +- Items in Quest reward +- Items in Quest log +- Items in Proficiency window diff --git a/SellValue.lua b/SellValue.lua index 22dabb9..5a45b55 100644 --- a/SellValue.lua +++ b/SellValue.lua @@ -5,15 +5,40 @@ local function hooksecurefunc(arg1, arg2, arg3) arg1, arg2, arg3 = _G, arg1, arg2 end local orig = arg1[arg2] - arg1[arg2] = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) - local x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20 = orig(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) - - arg3(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) - - return x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20 + arg1[arg2] = function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) + local x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20 = orig(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) + + arg3(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) + + return x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20 end end +function SellValue_SetTooltip(itemID, stackCount, tooltip) + if not tooltip then + tooltip = GameTooltip + end + + if not SellValues then + return + end + local price = SellValues[itemID]; + if price then + if price == 0 then + tooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 1.0); + else + SetTooltipMoney(tooltip, price * stackCount); + + end -- if price > 0 + + -- Adjust width and height to account for new lines + tooltip:SetHeight(tooltip:GetHeight() + 14); + if tooltip:GetWidth() < 120 then + tooltip:SetWidth(120); + end + end -- if price +end + function SellValue_OnLoad() -- Get initial prices from database @@ -22,216 +47,214 @@ function SellValue_OnLoad() this:RegisterEvent("MERCHANT_SHOW"); SellValue_Saved_OnTooltipAddMoney = SellValue_Tooltip:GetScript("OnTooltipAddMoney"); - + SellValue_Tooltip:SetScript("OnTooltipAddMoney", SellValue_OnTooltipAddMoney); + -- Hook item links tooltip + local org_OnHyperlinkShow = ChatFrame_OnHyperlinkShow + function ChatFrame_OnHyperlinkShow(link, text, button) + -- First, call the original function + org_OnHyperlinkShow(link, text, button); + + -- Now, call your custom function + local itemID = SellValue_IDFromLink(link); + SellValue_SetTooltip(itemID, 1, ItemRefTooltip); + end + + -- Hook loot tooltip + hooksecurefunc(GameTooltip, "SetLootItem", function(tip, lootIndex) + local _, _, stackCount = GetLootSlotInfo(lootIndex); + if stackCount > 0 then + local link = GetLootSlotLink(lootIndex); + local itemID = SellValue_IDFromLink(link) + + SellValue_SetTooltip(itemID, stackCount); + end + end + ); + + -- Hook group loot roll tooltip + hooksecurefunc(GameTooltip, "SetLootRollItem", function(tip, id) + local _, _, stackCount = GetLootRollItemInfo(id); + if stackCount > 0 then + local link = GetLootRollItemLink(id); + local itemID = SellValue_IDFromLink(link) + + SellValue_SetTooltip(itemID, stackCount); + end + end + ); + -- Hook bag tooltip - hooksecurefunc (GameTooltip, "SetBagItem", - function(tip, bag, slot) - if SellValues and not MerchantFrame:IsVisible() then - local _, stackCount = GetContainerItemInfo(bag, slot); - local itemID = SellValue_GetItemID(bag, slot); - - local price = SellValues[itemID]; - - if price then - if price == 0 then - GameTooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 1.0); - else - SetTooltipMoney(GameTooltip, price * stackCount); - - end -- if price > 0 - - -- Adjust width and height to account for new lines - GameTooltip:SetHeight(GameTooltip:GetHeight() + 14); - if GameTooltip:GetWidth() < 120 then - GameTooltip:SetWidth(120); - end - end -- if price - end - end + hooksecurefunc(GameTooltip, "SetBagItem", function(tip, bag, slot) + if not MerchantFrame:IsVisible() then + local _, stackCount = GetContainerItemInfo(bag, slot); + local itemID = SellValue_GetItemID(bag, slot); + + SellValue_SetTooltip(itemID, stackCount); + end + end ); - - + + -- Hook bank tooltip - hooksecurefunc (GameTooltip, "SetInventoryItem", - function(tip, unit, slot) - if SellValues and not MerchantFrame:IsVisible() and slot > 19 then - local stackCount = GetInventoryItemCount(unit, slot); - local itemID = SellValue_GetItemID(-1, slot); - - local price = SellValues[itemID]; - - if price then - if price == 0 then - GameTooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 1.0); - else - SetTooltipMoney(GameTooltip, price * stackCount); - - end -- if price > 0 - - -- Adjust width and height to account for new lines - GameTooltip:SetHeight(GameTooltip:GetHeight() + 14); - if GameTooltip:GetWidth() < 120 then - GameTooltip:SetWidth(120); - end - end -- if price - end - end + hooksecurefunc(GameTooltip, "SetInventoryItem", function(tip, unit, slot) + if not MerchantFrame:IsVisible() and slot > 19 then + local stackCount = GetInventoryItemCount(unit, slot); + local itemID = SellValue_GetItemID(-1, slot); + + SellValue_SetTooltip(itemID, stackCount); + end + end ); - + + -- Hook hyper links, used for BankItems addon + hooksecurefunc(GameTooltip, "SetHyperlink", function(tip, link) + local itemID = SellValue_IDFromLink(link); + SellValue_SetTooltip(itemID, 1); + end + ); + -- Hook quest reward tooltip - hooksecurefunc (GameTooltip, "SetQuestItem", - function(tip, qtype, slot) - if SellValues and (qtype == "reward" or qtype == "choice") then - local link = GetQuestItemLink(qtype, slot); - local _,_,stackCount = GetQuestItemInfo(qtype, slot); - local itemID = SellValue_IDFromLink(link); - - local price = SellValues[itemID]; - - if price then - if price == 0 then - GameTooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 1.0); - else - SetTooltipMoney(GameTooltip, price * stackCount); - - end -- if price > 0 - - -- Adjust width and height to account for new lines - GameTooltip:SetHeight(GameTooltip:GetHeight() + 14); - if GameTooltip:GetWidth() < 120 then - GameTooltip:SetWidth(120); - end - end -- if price - end - end + hooksecurefunc(GameTooltip, "SetQuestItem", function(tip, qtype, slot) + if qtype == "reward" or qtype == "choice" then + local link = GetQuestItemLink(qtype, slot); + local _, _, stackCount = GetQuestItemInfo(qtype, slot); + local itemID = SellValue_IDFromLink(link); + + SellValue_SetTooltip(itemID, stackCount) + end + end ); - + -- Hook questlog reward tooltip - hooksecurefunc (GameTooltip, "SetQuestLogItem", - function(tip, qtype, slot) - if SellValues then - - local stackCount = nil; - - if qtype == "reward" then - _,_,stackCount = GetQuestLogRewardInfo(slot); - elseif qtype == "choice" then - _,_,stackCount = GetQuestLogChoiceInfo(slot); - else - return - end - - local link = GetQuestLogItemLink(qtype, slot); - local itemID = SellValue_IDFromLink(link); - - local price = SellValues[itemID]; - - if price then - if price == 0 then - GameTooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 1.0); - else - SetTooltipMoney(GameTooltip, price * stackCount); - - end -- if price > 0 - - -- Adjust width and height to account for new lines - GameTooltip:SetHeight(GameTooltip:GetHeight() + 14); - if GameTooltip:GetWidth() < 120 then - GameTooltip:SetWidth(120); - end - end -- if price - end - end + hooksecurefunc(GameTooltip, "SetQuestLogItem", function(tip, qtype, slot) + local stackCount = nil; + + if qtype == "reward" then + _, _, stackCount = GetQuestLogRewardInfo(slot); + elseif qtype == "choice" then + _, _, stackCount = GetQuestLogChoiceInfo(slot); + else + return + end + + local link = GetQuestLogItemLink(qtype, slot); + local itemID = SellValue_IDFromLink(link); + + SellValue_SetTooltip(itemID, stackCount); + end ); -end + -- Hook trade skill tooltip + hooksecurefunc(GameTooltip, "SetTradeSkillItem", function(tip, tradeItemIndex, reagentIndex) + local stackCount = nil; + local link = nil; + + if reagentIndex then + _, _, stackCount = GetTradeSkillReagentInfo(tradeItemIndex, reagentIndex); + link = GetTradeSkillReagentItemLink(tradeItemIndex, reagentIndex); + else + stackCount = GetTradeSkillNumMade(tradeItemIndex); + link = GetTradeSkillItemLink(tradeItemIndex); + end + + local itemID = SellValue_IDFromLink(link); + SellValue_SetTooltip(itemID, stackCount); + end + ); +end function SellValue_OnEvent() - if event == "MERCHANT_SHOW" then - return SellValue_MerchantScan(this); - end + if event == "MERCHANT_SHOW" then + return SellValue_MerchantScan(this); + end end SellValue_Saved_GameTooltip_OnEvent = GameTooltip_OnEvent; -GameTooltip_OnEvent = function () - if event ~= "CLEAR_TOOLTIP" then - return SellValue_Saved_GameTooltip_OnEvent(); - end +GameTooltip_OnEvent = function() + if event ~= "CLEAR_TOOLTIP" then + return SellValue_Saved_GameTooltip_OnEvent(); + end end function SellValue_OnTooltipAddMoney () - -- call the original function first - SellValue_Saved_OnTooltipAddMoney(); + -- call the original function first + SellValue_Saved_OnTooltipAddMoney(); - -- The money in repair mode is the cost to repair, not sell - if InRepairMode() then return; end; + -- The money in repair mode is the cost to repair, not sell + if InRepairMode() then + return ; + end ; - SellValue_LastItemMoney = arg1; + SellValue_LastItemMoney = arg1; end function SellValue_SaveFor(bag, slot, name, money) - if not (bag and slot and name and money) then return; end; - - local _, stackCount = GetContainerItemInfo(bag, slot); - if stackCount and stackCount > 0 then - local costOfOne = money / stackCount; - - if not SellValues then SellValues = {}; end - - SellValues[name] = costOfOne; - end + if not (bag and slot and name and money) then + return ; + end ; + + local _, stackCount = GetContainerItemInfo(bag, slot); + if stackCount and stackCount > 0 then + local costOfOne = money / stackCount; + + if not SellValues then + SellValues = {}; + end + + SellValues[name] = costOfOne; + end end function SellValue_MerchantScan(frame) - for bag=0,NUM_BAG_FRAMES do - for slot=1,GetContainerNumSlots(bag) do - - local itemName = SellValue_GetItemID(bag, slot); - if itemName ~= "" then - SellValue_LastItemMoney = 0; - SellValue_Tooltip:SetBagItem(bag, slot); - SellValue_SaveFor(bag, slot, itemName, SellValue_LastItemMoney); - end -- if item name - end -- for slot - end -- for bag - + for bag = 0, NUM_BAG_FRAMES do + for slot = 1, GetContainerNumSlots(bag) do + + local itemName = SellValue_GetItemID(bag, slot); + if itemName ~= "" then + SellValue_LastItemMoney = 0; + SellValue_Tooltip:SetBagItem(bag, slot); + SellValue_SaveFor(bag, slot, itemName, SellValue_LastItemMoney); + end -- if item name + end -- for slot + end -- for bag + end function SellValue_OnHide() - -- ClearMoney() expects this to point to the tooltip itself, and this here - -- points to us, a child of the tip - this = this:GetParent(); - return GameTooltip_ClearMoney(); + -- ClearMoney() expects this to point to the tooltip itself, and this here + -- points to us, a child of the tip + this = this:GetParent(); + return GameTooltip_ClearMoney(); end function SellValue_GetItemID(bag, slot) - local linktext = nil; - - if (bag == -1) then - linktext = GetInventoryItemLink("player", slot); - else - linktext = GetContainerItemLink(bag, slot); - end - - if linktext then - return SellValue_IDFromLink(linktext); - else - return ""; - end + local linktext = nil; + + if (bag == -1) then + linktext = GetInventoryItemLink("player", slot); + else + linktext = GetContainerItemLink(bag, slot); + end + + if linktext then + return SellValue_IDFromLink(linktext); + else + return ""; + end end function SellValue_IDFromLink(itemlink) - if itemlink then - local foundlink,_,name = string.find(itemlink, "(item:%d+)"); - if foundlink then - return name; - else - return itemlink; - end - end - return; + if itemlink then + local foundlink, _, name = string.find(itemlink, "(item:%d+)"); + if foundlink then + return name; + else + return itemlink; + end + end + return ; end