Thread Tools Display Modes
02-01-10, 02:22 AM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
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.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 02-01-10 at 02:26 AM.
  Reply With Quote
02-01-10, 03:11 AM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by zork View Post
That way you can rewrite anything Blizzard does again.
Not completely true - the original code still executes, directly before your code does.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
09-27-10, 02:45 PM   #3
Lane
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 36
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?
  Reply With Quote
10-01-10, 12:58 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
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.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote

WoWInterface » Developer Discussions » Tutorials & Other Helpful Info. » Hooking Blizzard Widgets/Functions

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off