View Single Post
11-06-05, 04:13 PM   #1
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
Hooking a hooked function (tooltips specifically)

I've seen a few posts on hooking and such and they have all worked just fine. Unfortunately, I haven't seen any covering or how to deal with functions that are already hooked by another mod. What I'm trying to do is hook the UnitFrame_OnEnter function, so that I can let my mod have some TipBuddy support. The mod I'm working on is a unit frame mod so I need to have a custom UnitFrame_OnEnter for each frame (such as target, party1, party2, etc) unless there is a simple way of sending the UnitFrame_OnEnter function a specific this.unit value, in which case, screw the hooking. My most recent attempt looks like this.

Code:
local Original_UnitFrame_OnEnter = nil;

function Perl_Target_Tooltip_Hook()
	Original_UnitFrame_OnEnter = UnitFrame_OnEnter;
	UnitFrame_OnEnter = Perl_Target_Replacement_UnitFrame_OnEnter;
end

function Perl_Target_Tooltip_Unhook()
	UnitFrame_OnEnter = Original_UnitFrame_OnEnter;
end

function Perl_Target_Replacement_UnitFrame_OnEnter()	-- Taken from 1.8 UnitFrame_OnEnter()
	this.unit = "target";  --this is the whole reason i'm doing the hook, this one variable
	if ( SpellIsTargeting() ) then
		if ( SpellCanTargetUnit(this.unit) ) then
			SetCursor("CAST_CURSOR");
		else
			SetCursor("CAST_ERROR_CURSOR");
		end
	end

	GameTooltip_SetDefaultAnchor(GameTooltip, this);
	-- If showing newbie tips then only show the explanation
	if ( SHOW_NEWBIE_TIPS == "1" and this:GetName() ~= "PartyMemberFrame1" and this:GetName() ~= "PartyMemberFrame2" and this:GetName() ~= "PartyMemberFrame3" and this:GetName() ~= "PartyMemberFrame4") then
		if ( this:GetName() == "PlayerFrame" ) then
			GameTooltip_AddNewbieTip(PARTY_OPTIONS_LABEL, 1.0, 1.0, 1.0, NEWBIE_TOOLTIP_PARTYOPTIONS);
			return;
		elseif ( UnitPlayerControlled("target") and not UnitIsUnit("target", "player") and not UnitIsUnit("target", "pet") ) then
			GameTooltip_AddNewbieTip(PLAYER_OPTIONS_LABEL, 1.0, 1.0, 1.0, NEWBIE_TOOLTIP_PLAYEROPTIONS);
			return;
		end
	end
	
	if ( GameTooltip:SetUnit(this.unit) ) then
		this.updateTooltip = TOOLTIP_UPDATE_TIME;
	else
		this.updateTooltip = nil;
	end

	this.r, this.g, this.b = GameTooltip_UnitColor(this.unit);
	--GameTooltip:SetBackdropColor(this.r, this.g, this.b);
	GameTooltipTextLeft1:SetTextColor(this.r, this.g, this.b);
end
Then I just call UnitFrame_OnEnter(); in the OnEnter section in the XML and the hook works fine, but when I do this I end up breaking TipBuddy's hook it appears. Any ideas on how to do this correctly would be greatly appreciated.
  Reply With Quote