WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Tutorials & Other Helpful Info. (https://www.wowinterface.com/forums/forumdisplay.php?f=12)
-   -   Hooking Blizzard Widgets/Functions (https://www.wowinterface.com/forums/showthread.php?t=30382)

zork 02-01-10 02:22 AM

Hooking Blizzard Widgets/Functions
 
For those of you who don't know this already.

It is possible to hook functions like "SetAlpha", "SetVertexColor" or "SetPoint" for a specific frame/button.

This comes in very handy if you rewrite Blizzard stuff and want to make sure it stays the way you want it.

Thanks to "hooksecurefunc" it won't cause tainting aswell.

Code:

  ----------------------
  --FUNCTIONS
  ----------------------
 
  local function am(text)
    DEFAULT_CHAT_FRAME:AddMessage(text)
  end

  local function mySetVertexColorFunc(self, r, g, b, a)
    --do stuff
    am("setvertexcol")
    if r then
      am(r)
    end
  end
 
  local function mySetStatusBarColorFunc(self, r, g, b, a)
    --do stuff
    am("setstatusbarcol")
    if r then
      am(r)
      if r > 0.3 then
        self:SetStatusBarColor(0.2,0.2,0.2,1)
      end
    end
  end 
 
  local function mySetAlphaFunc(self, a)
    --do stuff
    am("setalpha")
    if a then
      am(a)
    end
  end

 
  ----------------------
  --FRAMES
  ----------------------
 
  --set colors for any kind of frame/button
  frame1:SetVertexColor(1,0.2,0.2,1)
  frame2:SetStatusBarColor(0.2,0.2,1,1)


  ----------------------
  --HOOKS
  ----------------------

  --hook functions for that frame/button
  hooksecurefunc(frame1, "SetVertexColor", mySetVertexColorFunc)
  hooksecurefunc(frame1, "SetAlpha", mySetAlphaFunc)


  hooksecurefunc(frame2, "SetStatusBarColor", mySetStatusBarColorFunc)
  hooksecurefunc(frame2, "SetAlpha", mySetAlphaFunc)

That way you can rewrite anything Blizzard does again.

Think of a frame that you want to stay at Alpha(0.2) but Blizzard always sets it to Alpha(1), so just hook SetAlpha() and you can set it to "0.2" again.

Torhal 02-01-10 03:11 AM

Quote:

Originally Posted by zork (Post 176865)
That way you can rewrite anything Blizzard does again.

Not completely true - the original code still executes, directly before your code does.

Lane 09-27-10 02:45 PM

Can you use this to get the Duration of Debuffs on your target and put them somewhere else? Or should I just write it separately and not worry about hooking Blizzards code?

zork 10-01-10 12:58 AM

Debuffs are handled by the UnitAura event and your debuff could by any of target debuff buttons. You want http://www.wowinterface.com/download...-rFilter2.html or a mod alike.


All times are GMT -6. The time now is 04:57 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI