diff --git a/!Compatibility/api/luaAPI.lua b/!Compatibility/api/luaAPI.lua index 3dfbde2..0d9e6d3 100644 --- a/!Compatibility/api/luaAPI.lua +++ b/!Compatibility/api/luaAPI.lua @@ -2,6 +2,7 @@ local error = error local geterrorhandler = geterrorhandler local loadstring = loadstring +local next = next local pairs = pairs local pcall = pcall local tonumber = tonumber @@ -10,21 +11,12 @@ local type = type local unpack = unpack local abs, ceil, exp, floor = math.abs, math.ceil, math.exp, math.floor local find, format, gfind, gsub, len, sub = string.find, string.format, string.gfind, string.gsub, string.len, string.sub -local concat, tinsert, getn, setn = table.concat, table.insert, table.getn, table.setn +local concat, getn, setn, tremove = table.concat, table.getn, table.setn, table.remove math.fmod = math.mod math.huge = 1/0 string.gmatch = string.gfind - -function difftime(time2, time1) - if type(time2) ~= "number" then - error(format("bad argument #1 to 'difftime' (number expected, got %s)", time2 and type(time2) or "no value"), 2) - elseif time1 and type(time1) ~= "number" then - error(format("bad argument #2 to 'difftime' (number expected, got %s)", time1 and type(time1) or "no value"), 2) - end - - return time1 and time2 - time1 or time2 -end +gmatch = string.gfind function select(n, ...) if not (type(n) == "number" or (type(n) == "string" and n == "#")) then @@ -231,6 +223,7 @@ function string.reverse(str) return str end +strrev = string.reverse function string.split(delimiter, str) if type(delimiter) ~= "string" and type(delimiter) ~= "number" then @@ -240,7 +233,7 @@ function string.split(delimiter, str) end local fields = {} - gsub(str, format("([^%s]+)", delimiter), function(c) tinsert(fields, c) end) + gsub(str, format("([^%s]+)", delimiter), function(c) fields[getn(fields) + 1] = c end) return unpack(fields) end @@ -303,10 +296,15 @@ function string.trim(str, chars) local patternStart = loadstring("return \"^["..pattern.."](.-)$\"")() local patternEnd = loadstring("return \"^(.-)["..pattern.."]$\"")() - local trimed, x, y = 1 + local trimed, x, y = 1, 1, 1 while trimed > 0 do - str, x = gsub(str, patternStart, "%1") - str, y = gsub(str, patternEnd, "%1") + if x > 0 then + str, x = gsub(str, patternStart, "%1") + end + if y > 0 then + str, y = gsub(str, patternEnd, "%1") + end + trimed = x + y end @@ -320,6 +318,40 @@ function string.trim(str, chars) end strtrim = string.trim +function strconcat(...) + if arg.n == 0 then + return "" + elseif arg.n == 1 then + return tostring(arg[1]) + else + for i = 1, arg.n do + if type(arg[i]) ~= "string" then + error(format("attempt to concatenate a %s value", type(arg[i])), 2) + end + end + end + + return concat(arg) +end + +function table.maxn(t) + if type(t) ~= "table" then + error(format("bad argument #1 to 'maxn' (table expected, got %s)", t and type(t) or "no value"), 2) + end + + local maxn = 0 + local i = next(t, nil) + + while i do + if type(i) == "number" and i > maxn then + maxn = i + end + i = next(t, i) + end + + return maxn +end + function table.wipe(t) if type(t) ~= "table" then error(format("bad argument #1 to 'wipe' (table expected, got %s)", t and type(t) or "no value"), 2) diff --git a/!Compatibility/api/wowAPI.lua b/!Compatibility/api/wowAPI.lua index eced802..874215a 100644 --- a/!Compatibility/api/wowAPI.lua +++ b/!Compatibility/api/wowAPI.lua @@ -7,9 +7,13 @@ local select = select local tonumber = tonumber local type = type local unpack = unpack -local find, format, gsub, lower, match, upper = string.find, string.format, string.gsub, string.lower, string.match, string.upper +local find, format, gmatch, gsub, lower, match, upper = string.find, string.format, string.gmatch, string.gsub, string.lower, string.match, string.upper local getn = table.getn --WoW API +local debugstack = debugstack +local GetContainerItemInfo = GetContainerItemInfo +local GetContainerItemLink = GetContainerItemLink +local GetContainerNumSlots = GetContainerNumSlots local GetInventoryItemTexture = GetInventoryItemTexture local GetItemInfo = GetItemInfo local GetQuestGreenRange = GetQuestGreenRange @@ -20,12 +24,14 @@ local IsInInstance = IsInInstance local UnitLevel = UnitLevel --WoW Variables local DUNGEON_DIFFICULTY1 = DUNGEON_DIFFICULTY1 +local DURABILITY_TEMPLATE = gsub(DURABILITY_TEMPLATE, "%%d / %%d", "(%%d+) / (%%d+)") +local NUM_BAG_FRAMES = NUM_BAG_FRAMES local TIMEMANAGER_AM = gsub(TIME_TWELVEHOURAM, "^.-(%w+)$", "%1") local TIMEMANAGER_PM = gsub(TIME_TWELVEHOURPM, "^.-(%w+)$", "%1") -local DURABILITY_TEMPLATE = gsub(DURABILITY_TEMPLATE, "%%d / %%d", "(%%d+) / (%%d+)") --Libs local LBC = LibStub("LibBabble-Class-3.0"):GetLookupTable() local LBZ = LibStub("LibBabble-Zone-3.0"):GetLookupTable() +local IFDB = LibStub("ItemFamilyDB") CLASS_SORT_ORDER = { "WARRIOR", @@ -114,6 +120,31 @@ function hooksecurefunc(a1, a2, a3) end end +local secureFuncs = { + CameraOrSelectOrMoveStop = true, + MoveBackwardStop = true, + MoveForwardStop = true, + PitchDownStop = true, + PitchUpStop = true, + StrafeLeftStart = true, + StrafeRightStart = true, + ToggleMouseMove = true, + TurnLeftStart = true, + TurnOrActionStop = true, + TurnRightStart = true, + CameraOrSelectOrMoveStart = true, + Jump = true, + MoveBackwardStart = true, + MoveForwardStart = true, + PitchDownStart = true, + PitchUpStart = true, + StrafeLeftStop = true, + StrafeRightStop = true, + ToggleRun = true, + TurnLeftStop = true, + TurnOrActionStart = true, + TurnRightStop = true +} --[[ issecurevariable([table], variable) Returns 1, nil for undefined variables. This is because an undefined variable is secure since you have not tainted it. Returns 1, nil for all untainted variables (i.e. Blizzard variables). @@ -125,7 +156,18 @@ function issecurevariable(t, var) -- if type(var) ~= "table" or type(var) ~= "string" then -- error("Usage: issecurevariable([table,] \"variable\")", 2) -- end - return + + local isSecure = secureFuncs[t] and 1 or nil + if not isSecure then + return + end + + local taint + for x in gmatch(debugstack(), "\\AddOns\\(.-)\\") do + taint = x + end + + return isSecure, taint end function tContains(table, item) @@ -155,6 +197,16 @@ function UnitAura(unit, i, filter) end end +function difftime(time2, time1) + if type(time2) ~= "number" then + error(format("bad argument #1 to 'difftime' (number expected, got %s)", time2 and type(time2) or "no value"), 2) + elseif time1 and type(time1) ~= "number" then + error(format("bad argument #2 to 'difftime' (number expected, got %s)", time1 and type(time1) or "no value"), 2) + end + + return time1 and time2 - time1 or time2 +end + function BetterDate(formatString, timeVal) local dateTable = date("*t", timeVal) local amString = (dateTable.hour >= 12) and "PM" or "AM" @@ -265,29 +317,6 @@ function GetMapNameByID(id) return mapByID[tonumber(id)] end -local LBIBF = LibStub("LibBabble-ItemBagFamily-3.0") -function GetItemFamily(id) - if not id then return end - if type(id) == "table" or type(id) == "function" then return end - - if type(id) == "string" then - id = tonumber(match(id, "item:(%d+)")) - end - - return LBIBF.ItemFamily[id] or 0 -end - -function GetBagFamily(id) - if not id then return end - if type(id) == "table" or type(id) == "function" then return end - - if type(id) == "string" then - id = tonumber(match(id, "item:(%d+)")) - end - - return LBIBF.ItemBagFamily[id] or 0 -end - local arrow function GetPlayerFacing() if not arrow then @@ -417,6 +446,7 @@ function GetItemInfoByName(itemName) end if find(itemName, " of ") then + -- random enchantments itemName = gsub(itemName, " of Spirit", "") itemName = gsub(itemName, " of Intellect", "") itemName = gsub(itemName, " of Strength", "") @@ -461,7 +491,7 @@ function GetItemInfoByName(itemName) for itemID = 1, LAST_ITEM_ID do name = GetItemInfo(itemID) - if name ~= "" and name ~= nil then + if name ~= nil and name ~= "" then itemInfoDB[name] = itemID if name == itemName then @@ -476,19 +506,36 @@ function GetItemInfoByName(itemName) return GetItemInfo(itemInfoDB[itemName]) end +function GetItemFamily(item, isBag) + if not item or type(item) ~= "number" or type(item) ~= "string" then return end + + if type(item) == "string" then + local _, _, itemID = find(itemLink, "(%d+):") + if not itemID then return end + item = tonumber(itemID) + end + + if item > LAST_ITEM_ID then return end + + return (isBag and IFDB.ItemBagFamily[item] or IFDB.ItemFamily[item]) or 0 +end + function GetItemCount(itemName) + if type(itemName) ~= "string" then return 0 end + local count = 0 + for bag = NUM_BAG_FRAMES, 0, -1 do for slot = 1, GetContainerNumSlots(bag) do local _, itemCount = GetContainerItemInfo(bag, slot) + if itemCount then local itemLink = GetContainerItemLink(bag, slot) - local _, _, itemParse = find(itemLink, "(%d+):") - local queryName, _, _, _, _, _ = GetItemInfo(itemParse) - if queryName and queryName ~= "" then - if queryName == itemName then - count = count + itemCount - end + local _, _, itemID = find(itemLink, "(%d+):") + local queryName = GetItemInfo(itemID) + + if queryName and queryName == itemName then + count = count + itemCount end end end @@ -497,22 +544,22 @@ function GetItemCount(itemName) return count end -local scan +local scanTooltip function GetInventoryItemDurability(slot) - if not GetInventoryItemTexture("player", slot) then return nil, nil end + if not GetInventoryItemTexture("player", slot) then return end - if not scan then - scan = CreateFrame("GameTooltip", "DurabilityScan", nil, "ShoppingTooltipTemplate") - scan:SetOwner(UIParent, "ANCHOR_NONE") + if not scanTooltip then + scanTooltip = CreateFrame("GameTooltip", "Compatibility_ScanTooltip", nil, "ShoppingTooltipTemplate") + scanTooltip:SetOwner(UIParent, "ANCHOR_NONE") end - scan:ClearLines() - scan:SetInventoryItem("player", slot) + scanTooltip:ClearLines() + scanTooltip:SetInventoryItem("player", slot) - for i = 4, scan:NumLines() do - local text = _G[scan:GetName().."TextLeft"..i]:GetText() - for durability, max in string.gfind(text, DURABILITY_TEMPLATE) do - return tonumber(durability), tonumber(max) + for i = 4, scanTooltip:NumLines() do + local text = _G["Compatibility_ScanTooltipTextLeft"..i]:GetText() + for current, maximum in gmatch(text, DURABILITY_TEMPLATE) do + return tonumber(current), tonumber(maximum) end end -end \ No newline at end of file +end diff --git a/!Compatibility/libs/LibBabble-ItemBagFamily-3.0.lua b/!Compatibility/libs/ItemFamilyDB.lua similarity index 93% rename from !Compatibility/libs/LibBabble-ItemBagFamily-3.0.lua rename to !Compatibility/libs/ItemFamilyDB.lua index 0c1810d..1965d20 100644 --- a/!Compatibility/libs/LibBabble-ItemBagFamily-3.0.lua +++ b/!Compatibility/libs/ItemFamilyDB.lua @@ -1,30 +1,29 @@ -local MAJOR_VERSION = "LibBabble-ItemBagFamily-3.0" -local MINOR_VERSION = 90000 + tonumber(string.match("$Revision: 50 $", "%d+")) +local MAJOR_VERSION = "ItemFamilyDB" +local MINOR_VERSION = 90000 + tonumber(string.match("$Revision: 1 $", "%d+")) -if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end -local lib = LibStub("LibBabble-3.0"):New(MAJOR_VERSION, MINOR_VERSION) +local lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION) if not lib then return end -lib.ItemBagFamily = { - [8217] = 1, - [7371] = 1, - [7278] = 1, - [5439] = 1, - [3605] = 1, - [3573] = 1, - [2662] = 1, +lib.BagFamily = { [2101] = 1, - [19319] = 1, - [18714] = 1, + [2662] = 1, + [3573] = 1, + [3605] = 1, + [5439] = 1, + [7278] = 1, + [7371] = 1, + [8217] = 1, [11362] = 1, - [8218] = 2, - [7372] = 2, - [7279] = 2, - [5441] = 2, - [3604] = 2, - [3574] = 2, - [2663] = 2, + [18714] = 1, + [19319] = 1, [2102] = 2, + [2663] = 2, + [3574] = 2, + [3604] = 2, + [5441] = 2, + [7279] = 2, + [7372] = 2, + [8218] = 2, [19320] = 2, [21340] = 4, [21341] = 4, diff --git a/!Compatibility/libs/LibBabble-Zone-3.0.lua b/!Compatibility/libs/LibBabble-Zone-3.0.lua index f2657b3..dca540f 100644 --- a/!Compatibility/libs/LibBabble-Zone-3.0.lua +++ b/!Compatibility/libs/LibBabble-Zone-3.0.lua @@ -7,10 +7,8 @@ Dependencies: None License: MIT ]] -local match = string.match - local MAJOR_VERSION = "LibBabble-Zone-3.0" -local MINOR_VERSION = 90000 + tonumber(match("$Revision: 107 $", "%d+")) +local MINOR_VERSION = 90000 + tonumber(string.match("$Revision: 107 $", "%d+")) if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end local lib = LibStub("LibBabble-3.0"):New(MAJOR_VERSION, MINOR_VERSION) diff --git a/!Compatibility/libs/libs.xml b/!Compatibility/libs/libs.xml index c30f819..4f566ec 100644 --- a/!Compatibility/libs/libs.xml +++ b/!Compatibility/libs/libs.xml @@ -3,5 +3,5 @@