Quantcast
to hook or not to hook - WoWInterface
Thread Tools Display Modes
01-19-14, 10:02 AM   #1
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
to hook or not to hook

The PAPERDOLL_STATINFO table has a table with an updateFunc for each player stat key.

I wanted to replace the behavior for armor, so I just created another update function with the modifications I wanted and assigned it, overwriting the old value:
Code:
PAPERDOLL_STATINFO["ARMOR"].updateFunc = theNewFunc
PaperDollFrame_UpdateStats() -- I called this afterward to force an update.
This code has been running in my UI for weeks now. I was looking into pulling it out of _DevPad and putting it into a standalone addon; so, I was doing some research into how other addons modify the stat tooltips. I found one addon that includes, as a side feature, the changes I made to the armor tooltip. Our implementations were nearly identical, except they do this:
Code:
hooksecurefunc(
	PAPERDOLL_STATINFO["ARMOR"],
	"updateFunc",
	function (statFrame, unit)
		
		-- ...

		statFrame:HookScript("OnEnter", Armor_OnEnter)
	end
)
So, is it necessary to do a secure hook here?
  Reply With Quote
01-19-14, 03:10 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
I would wildly guess that a secure hook would not be necessary. Just go without if you don't/until you do notice any taint.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
01-19-14, 04:27 PM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,059
You cause taint by replacing any function that the interface calls with your own and it's always better to avoid it wherever possible.
  Reply With Quote
01-19-14, 08:03 PM   #4
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
So, in this case for the paper doll stats frame and its tooltip, is it worth doing the hook and having all the other code still run and basically just be ... overwritten?
  Reply With Quote
01-19-14, 08:52 PM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,059
You should hook it, but not like the code you quoted because every single time PAPERDOLL_STATINFO.ARMOR.updateFunc is called it's going to add another function to statFrame's OnEnter.

You need to make sure you only hook it once.

As ridiculous as it may seem, it's better to overwrite the content of the tooltip after it's been filled out than to pre-hook it and cause taint because taint spreading from seemingly benign hooks like this cause the glyph frame to stop working and random frame level issues.
  Reply With Quote
01-19-14, 11:24 PM   #6
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Originally Posted by semlar View Post
You need to make sure you only hook it once.
Right, I forgot about that. Well, I guess that's a problem in that addon I copied that from :\.

Well, actually... If there's code like this:
Code:
frame:SetScript("OnEnter", something)
frame:HookScript("OnEnter", somethingElse)
frame:SetScript("OnEnter", something)
frame:HookScript("OnEnter", somethingElse)
Do calls to SetScript clear all hooks when the script is set to something else, or would the hooks persist? The Blizzard code for the armor tooltip sets the script every time, IIRC.

Update: Tested. SetScript clears the hook, so in this case, because of what the Blizzard code does, it will need to be re-hooked each time.

Last edited by pelf : 01-20-14 at 10:07 AM. Reason: more information
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » to hook or not to hook

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