WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Hooking a hooked function (tooltips specifically) (https://www.wowinterface.com/forums/showthread.php?t=2339)

Global 11-06-05 04:13 PM

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.

Kaelten 11-06-05 05:25 PM

You will have to call

Original_UnitFrame_OnEnter()

in your replacement to get it to work.

other options would be to chance tipbuddy's TOC file to make your's a dependency, which would be all in all a fairly bad idea if you plan to distrubite this.

Only thing else that comes to mind is to add support for TipBuddy, where if its present that you hook its funciton instead of the default one. IE's TipBuddy's Original UnitFrame OnEnter.

Global 11-06-05 05:46 PM

See, the thing is, I don't want to call the original ever because i need to set this:

this.unit = "target";

If i could somehow set this.unit in the unitframe_onenter i'd be gold. Without setting that value I just get the unit is not set error. I know it's possible since other unit frames like discord can do it, but it's hard to dig through all the more complicated code to find the few lines that do it.

Kaelten 11-06-05 05:49 PM

well you could actually hook the script using Set/GetScript()

problem is tha tunless you call the parent hook, you're going to have the incompatibiliity problem, or your going to have to have special code for eveything else.

Global 11-06-05 06:05 PM

I'm not familiar with Set/GetScript() so I'll have to take a look at it and get back to you. :)


All times are GMT -6. The time now is 05:55 AM.

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