local a=LibStub:NewLibrary("LibInternalCooldowns",1)if not a then return end;local b=LibStub:GetLibrary("CallbackHandler-1.0")local c=_G.GetInventoryItemLink;local d=_G.GetInventoryItemTexture;local e=_G.GetMacroInfo;local f=_G.GetActionInfo;local g=_G.string.sub;local h=_G.wipe;local i=UnitGUID("player")local j=_G.GetTime;a.spellToItem=a.spellToItem or{}a.cooldownStartTimes=a.cooldownStartTimes or{}a.cooldownDurations=a.cooldownDurations or{}a.callbacks=a.callbacks or b:New(a)a.cooldowns=a.cooldowns or nil;a.hooks=a.hooks or{}local k={}if not a.eventFrame then a.eventFrame=CreateFrame("Frame")a.eventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")a.eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")a.eventFrame:SetScript("OnEvent",function(l,m,...)l.lib[m](l.lib,m,...)end)end;a.eventFrame.lib=a;local n={SPELL_DISPEL=true,SPELL_DISPEL_FAILED=true,SPELL_STOLEN=true,SPELL_AURA_REMOVED=true,SPELL_AURA_REMOVED_DOSE=true,SPELL_AURA_BROKEN=true,SPELL_AURA_BROKEN_SPELL=true,SPELL_CAST_FAILED=true}local o={AMMOSLOT=0,INVTYPE_HEAD=1,INVTYPE_NECK=2,INVTYPE_SHOULDER=3,INVTYPE_BODY=4,INVTYPE_CHEST=5,INVTYPE_WAIST=6,INVTYPE_LEGS=7,INVTYPE_FEET=8,INVTYPE_WRIST=9,INVTYPE_HAND=10,INVTYPE_FINGER={11,12},INVTYPE_TRINKET={13,14},INVTYPE_CLOAK=15,INVTYPE_WEAPONMAINHAND=16,INVTYPE_2HWEAPON=16,INVTYPE_WEAPON={16,17},INVTYPE_HOLDABLE=17,INVTYPE_SHIELD=17,INVTYPE_WEAPONOFFHAND=17,INVTYPE_RANGED=18}function a:PLAYER_ENTERING_WORLD()i=UnitGUID("player")self:Hook("GetInventoryItemCooldown")self:Hook("GetActionCooldown")self:Hook("GetItemCooldown")end;function a:Hook(p)if a.hooks[p]then _G[p]=a.hooks[p]end;a.hooks[p]=_G[p]_G[p]=function(...)return self[p](self,...)end end;local function q(r,s)local t=c("player",r)if not t then return false end;local u,v=t:match("item:(%d+):(%d+)")if tonumber(v or-1)==s then return true,tonumber(u)else return false end end;local function w(u)local x,x,x,x,x,x,x,x,y=GetItemInfo(u)local r=o[y]if type(r)=="table"then for x,z in ipairs(r)do local t=c("player",z)if t and t:match(("item:%s"):format(u))then return true end end else local t=c("player",r)if t and t:match(("item:%s"):format(u))then return true end end;return false end;function a:COMBAT_LOG_EVENT_UNFILTERED(l,A,m,B,C,D,E,F,G,H,I)i=i or UnitGUID("player")if(E==i and(B==nil or B==E)or B==i)and not n[m]and g(m,0,6)=="SPELL_"then local u=a.spellToItem[H]if u then if type(u)=="table"then for J,z in ipairs(u)do if w(z)then self:SetCooldownFor(z,H,"ITEM")end end;return else if w(u)then self:SetCooldownFor(u,H,"ITEM")end;return end end;local s=a.enchants[H]if s then local s,K,L=unpack(s)local M,u,N,O;M,u=q(K,s)if M then N=u;if(k[K]or 0)<j()-(a.cooldowns[H]or 45)then k[K]=j()self:SetCooldownFor(u,H,"ENCHANT")return end end;M,u=q(L,s)if M then O=u;if(k[L]or 0)<j()-(a.cooldowns[H]or 45)then k[L]=j()self:SetCooldownFor(u,H,"ENCHANT")return end end;if N and O then if k[K]<k[L]then self:SetCooldownFor(N,H,"ENCHANT")else self:SetCooldownFor(O,H,"ENCHANT")end end end;local P=a.metas[H]if P then local t=c("player",1)if t then local Q=tonumber(t:match("item:(%d+)")or 0)if Q and Q~=0 then self:SetCooldownFor(Q,H,"META")end end;return end;local R=a.talents[H]if R then self:SetCooldownFor(("%s: %s"):format(UnitClass("player"),R),H,"TALENT")return end end end;function a:SetCooldownFor(u,H,S)local T=a.cooldowns[H]or 45;a.cooldownStartTimes[u]=j()a.cooldownDurations[u]=T;if S=="TALENT"then a.callbacks:Fire("InternalCooldowns_TalentProc",H,j(),T,S)else a.callbacks:Fire("InternalCooldowns_Proc",u,H,j(),T,S)end end;local function U(Q)if not Q then return end;local V=Q and a.cooldownStartTimes[Q]and a.cooldownDurations[Q]if V then if a.cooldownStartTimes[Q]+a.cooldownDurations[Q]>j()then return a.cooldownStartTimes[Q],a.cooldownDurations[Q],1 else return 0,0,0 end else return nil end end;function a:IsInternalItemCooldown(u)return U(u)~=nil end;function a:GetInventoryItemCooldown(W,r)local X,T,Y=self.hooks.GetInventoryItemCooldown(W,r)if not Y or Y==0 then local t=c("player",r)if t then local u=t:match("item:(%d+)")u=tonumber(u or 0)local X,T,Z=U(u)if X then return X,T,Z end end end;return X,T,Y end;function a:GetActionCooldown(_)local a0,Q,a1,a2=f(_)if a0=="item"then local X,T,Z=U(Q)if X then return X,T,Z end elseif a0=="macro"then local x,a3=e(Q)if a3==d("player",13)then Q=tonumber(c("player",13):match("item:(%d+)"))local X,T,Z=U(Q)if X then return X,T,Z end elseif a3==d("player",14)then Q=tonumber(c("player",14):match("item:(%d+)"))local X,T,Z=U(Q)if X then return X,T,Z end end end;return self.hooks.GetActionCooldown(_)end;function a:GetItemCooldown(a4)local Q;local a5=tonumber(a4)if a5 and a5>0 then Q=a4 elseif type(a4)=="string"then local p,t=GetItemInfo(a4)if t then Q=t:match("item:(%d+)")end end;if Q then Q=tonumber(Q)local X,T,Z=U(Q)if X then return X,T,Z end end;return self.hooks.GetItemCooldown(a4)end;local a6={[64411]=46017,[60065]={44914,40684,49074},[60488]=40373,[64713]=45518,[60064]={44912,40682,49706},[67703]={47303,47115},[67708]={47303,47115},[67772]={47464,47131},[67773]={47464,47131},[72416]={50398,50397},[72412]={50402,50401},[72418]={50399,50400},[72414]={50404,50403},[71485]=50362,[71492]=50362,[71486]=50362,[71484]=50362,[71491]=50362,[71487]=50362,[71556]=50363,[71560]=50363,[71558]=50363,[71561]=50363,[71559]=50363,[71557]=50363,[71401]=50342,[71541]=50343,[71610]=50359,[71641]=50366,[71633]=50352,[71639]=50349,[71601]=50353,[71644]=50348,[71605]=50360,[71636]=50365,[71584]=50358,[75466]=54572,[75473]=54588,[75458]=54569,[75456]=54590,[67117]={48501,48502,48503,48504,48505,48472,48474,48476,48478,48480,48491,48492,48493,48494,48495,48496,48497,48498,48499,48500,48486,48487,48488,48489,48490,48481,48482,48483,48484,48485},[67671]=47214,[67669]=47213,[64772]=45609,[65024]=46038,[60443]=40371,[64790]=45522,[60203]=42990,[60494]=40255,[65004]=65005,[60492]=39229,[60530]=40258,[60437]=40256,[49623]=37835,[65019]=45931,[64741]=45490,[65014]=45286,[65003]=45929,[60538]=40382,[58904]=43573,[64765]=45507,[71403]=50198,[60062]={40685,49078},[51353]=38358,[60218]=37220,[60479]=37660,[51348]=38359,[63250]=45131,[63250]=45219,[60302]=37390,[54808]=40865,[60483]=37264,[52424]=38675,[55018]=40767,[52419]=38674,[60520]=37657,[60307]=37064,[60233]={44253,44254,44255,42987},[60235]={44253,44254,44255,42987},[60229]={44253,44254,44255,42987},[60234]={44253,44254,44255,42987},[23684]=19288}local a7={[55637]={3722,15},[55775]={3730,15},[55767]={3728,15},[59626]={3790,16},[59625]={3790,16}}local a8={[55382]=41401,[32848]=25901,[23454]=25899,[55341]=41385,[18803]=25893,[32845]=25898,[39959]=32410,[55379]=41400}local a9={[72416]=60,[72412]=60,[72418]=60,[72414]=60,[60488]=15,[51348]=10,[51353]=10,[54808]=60,[55018]=60,[52419]=30,[59620]=90,[55382]=15,[32848]=15,[55341]=90,[48517]=30,[48518]=30,[47755]=12,[71485]=105,[71492]=105,[71486]=105,[71484]=105,[71491]=105,[71487]=105,[71556]=105,[71560]=105,[71558]=105,[71561]=105,[71559]=105,[71557]=105,[71605]=90,[71636]=90,[59626]=35,[59625]=35}local aa={[48517]="Eclipse",[48518]="Eclipse",[56453]="Lock and Load",[52286]="Will of the Necropolis",[47755]="Rapture"}a.spellToItem=a.spellToItem or{}a.cooldowns=a.cooldowns or{}a.enchants=a.enchants or{}a.metas=a.metas or{}a.talents=a.talents or{}a.talentsRev=a.talentsRev or{}local ab,ac={},{}local function ad(ae,af)h(ac)for x,z in ipairs(ae)do ac[z]=true end;for x,z in ipairs(af)do if not ac[z]then tinsert(ae,z)end end end;for J,z in pairs(a6)do local ag=a.spellToItem[J]if ag and ag~=z then if type(ag)=="table"then if type(z)~="table"then h(ab)tinsert(ab,z)end;ad(ag,ab)else a.spellToItem[J]={ag,z}end else a.spellToItem[J]=z end end;for J,z in pairs(a9)do a.cooldowns[J]=z end;for J,z in pairs(a7)do a.enchants[J]=z end;for J,z in pairs(a8)do a.metas[J]=z end;for J,z in pairs(aa)do a.talents[J]=z;if z~="Eclipse"then a.talentsRev[z]=J end end