The problem I am seeing is that sometimes it seems to come unhooked. Is it possible that some other addon is hooking the same thing and overwriting my hook? If so, is there a way to stop this?
I cannot really test if it is another addon because this is my guilds raid loot distribution addon and I need my other addons running to raid. Also it does not happen all the time. It is very sporadic and simply reloading the ui fixes the issue.
Any help and/or advice would be greatly appreciated!
Are you using :SecureHook() because the function you are hooking is secure? If it is then whatever addon is breaking your hook must also be breaking all usage of the function. If its not a secure function then you have no reason to be using :SecureHook(), but you'll still have the problem of another addon breaking the hook.
Are you using :SecureHook() because the function you are hooking is secure? If it is then whatever addon is breaking your hook must also be breaking all usage of the function. If its not a secure function then you have no reason to be using :SecureHook(), but you'll still have the problem of another addon breaking the hook.
That's a good point. Come to think of it, I don't think HandleModifiedItemClick is a secure function. All it does is preview a wearable item in your character model, or insert the item link into the chat prompt.
From FrameXML\ItemButtonTemplate.lua
function HandleModifiedItemClick(link)
if ( IsModifiedClick("CHATLINK") ) then
if ( ChatEdit_InsertLink(link) ) then
return true;
end
end
if ( IsModifiedClick("DRESSUP") ) then
DressUpItemLink(link);
return true;
end
return false;
end
Ok so I added all the addons I use that hook HandleModifiedItemClick to optional dependencies and my hook still seems to stop working.
As I said earlier I set the hook up on initialize. Is there any reason it could come unhooked after zoning into an instance? Because it only ever happens on the first loot after zoning into an instance.
Only possibility is someone is hooking the function you are hooking and you haven't found one of them yet.
Another one is that someone overwrote HandleModifiedItemClick directly without hooking, replaced it, and/or removed the script from the buttons you are hooking.
Yet another possibility is that some UI elements specified script="HandleModifiedItemClick" directly in the XML, and thus bypasses your hook completely, because the original function reference is assigned to the XML template/element, not your hooked function reference. In this case, you need manually hook each frame yourself.
What I do when I need to find where a string of text could be among many files is, use PSPad's "Search / Replace in files..." option to scour the entire AddOns (or FrameXML) directory. It spits out all the files containing said text including line numbers and links that open the file(s) and move the cursor to the appropriate line. This is superior to Windows' search in that it's a lot faster, more accurate, and you can watch the progress.
I'm sure other editors not named Wordpad or Notepad have a similar function.
You can also download a standalone utility like Windows Grep, to get "search-and-replace in files" that works in conjunction with whichever text editor you actually use.
I used window's find command to find them. It feels like a poor man's grep.
Would it be bad to simply rehook the function either on command or on an event? Seems like it would be an easy work around, but I do not know if there would be bad side effects.
Sides effects yes. And a lot of it. If you hooked a function already hooked by another addon, and that addon rehooks your hook, and you rehook his hook, you may end up calling your hooked function 100s of times when it gets called just once. And his too. Never do something like that.
It's _always_ better to find the root cause of unhooking and fix it.
OnInitialize() is called by AceAddon-3.0 when the ADDON_LOADED event occurs for your addon (arg1 = "your addon"). This occurs right after the savedvariables of your addon has completed loading.
OnEnable() is called by AceAddon-3.0 when PLAYER_LOGIN event occurs (or when ADDON_LOADED event occurs for Load-On-Demand addons). OnEnabled is also called when :Enable() is called on your addon, should your addon ever be disabled by calling Disable() (which has its corresponding OnDisable() callback).
Basically, the difference between the 2 is a matter of timing. You should use OnInitialize() for one-time stuff. And OnEnable() for stuff that can be enabled/disabled such as registration of events, activating OnUpdates, etc.
then its most likely not another addon. can we see the code for the whole DSK_HandleModifiedItemClick function?
Yes...
function DrunkardSK:DSK_HandleModifiedItemClick(item)
if (Master) then
if (BidNotOpen) then
if (IsAltKeyDown() and
not IsShiftKeyDown() and
not IsControlKeyDown()) then
ItemLink = item;
DrunkardSK:SendCommMessage("DSKOpenBid", ItemLink, "RAID");
BidNotOpen = false;
DSKListFrame.closeBid:Enable();
end
end
end
end
Master is set if you are masterlooter and BidNotOpen if there is not currently a bid open. I did have some debugging prints in this function at one point and I saw none of them when the hooking seemed to stop working.
The original function returns true if the click is modified by "DRESSUP" (control) or "CHATLINK" (shift) or false otherwise. Perhaps this is the problem? (Just speculation.)
Master and BidNotOpen are globals? any chance these are getting overwritten by another mod? or even blizzard?
you may want to put those debug print statements back in right at the top just to confirm if your hook is being called.
this is what i use for my dkp mod to handle alt clicking items and links.
function ArkDKP.LootHook( )
ArkDKP:SecureHook( "SetItemRef",
function( link, name, button )
if ArkDKP.IsMaster( ) then
if ( IsAltKeyDown( ) and ( button == "RightButton" ) ) then
local link = string.match( link, "(item:.+)" )
ArkDKP.LootHookProcess( link, "link" )
end
end
end
)
ArkDKP:SecureHook( "ContainerFrameItemButton_OnModifiedClick",
function( frame, button )
if ArkDKP.IsMaster( ) then
if IsAltKeyDown( ) and button == "RightButton" then
local link = string.match( GetContainerItemLink( this:GetParent( ):GetID( ), this:GetID( ) ), "|H(item:.-)|h" )
ArkDKP.LootHookProcess( link, "link" )
end
end
end
)
end
mine picks up all the lootable items when you loot and queues them up so ive no need to check for alt clicking on the loot slots themselves but if thats what youre doing it shouldnt be too hard to figure out what the frame is called and hook that as well (if the setitemref hook doesnt work for that)
edit: i really should reverse that logic check and change this to frame
inside my
The problem I am seeing is that sometimes it seems to come unhooked. Is it possible that some other addon is hooking the same thing and overwriting my hook? If so, is there a way to stop this?
I cannot really test if it is another addon because this is my guilds raid loot distribution addon and I need my other addons running to raid. Also it does not happen all the time. It is very sporadic and simply reloading the ui fixes the issue.
Any help and/or advice would be greatly appreciated!
Yes.
No, not without narrowing down which addon it is and making sure it loads first (OptionalDeps), fix it, and/or alert the author of the faulty code.
Fun fun! Thanks for the quick reply!
That's a good point. Come to think of it, I don't think HandleModifiedItemClick is a secure function. All it does is preview a wearable item in your character model, or insert the item link into the chat prompt.
From FrameXML\ItemButtonTemplate.lua
And for sake of clarity what is the difference between a secure hook and a regular hook? How do I know if what I am hooking is secure or not?
Normal hooks are just what you think of as a hook.
http://www.wowwiki.com/Secure_Execution_and_Tainting
As I said earlier I set the hook up on initialize. Is there any reason it could come unhooked after zoning into an instance? Because it only ever happens on the first loot after zoning into an instance.
Another one is that someone overwrote HandleModifiedItemClick directly without hooking, replaced it, and/or removed the script from the buttons you are hooking.
Yet another possibility is that some UI elements specified script="HandleModifiedItemClick" directly in the XML, and thus bypasses your hook completely, because the original function reference is assigned to the XML template/element, not your hooked function reference. In this case, you need manually hook each frame yourself.
I'm sure other editors not named Wordpad or Notepad have a similar function.
Would it be bad to simply rehook the function either on command or on an event? Seems like it would be an easy work around, but I do not know if there would be bad side effects.
It's _always_ better to find the root cause of unhooking and fix it.
I really doubt this has anything to do with my current issue but I am curious.
OnEnable() is called by AceAddon-3.0 when PLAYER_LOGIN event occurs (or when ADDON_LOADED event occurs for Load-On-Demand addons). OnEnabled is also called when :Enable() is called on your addon, should your addon ever be disabled by calling Disable() (which has its corresponding OnDisable() callback).
Basically, the difference between the 2 is a matter of timing. You should use OnInitialize() for one-time stuff. And OnEnable() for stuff that can be enabled/disabled such as registration of events, activating OnUpdates, etc.
then its most likely not another addon. can we see the code for the whole DSK_HandleModifiedItemClick function?
or if you think its too large, what are you trying to do after someone shift or control clicks on a button that youre showing an item in?
just that youre hooking something that is used in a lot of places, on all item buttons (ie bags, bank, vault), do you really need to do that?
btw, do you have buggrabber (or equivalent) installed? ie could there just be a lua error after the first loot that youre not seeing?
Yes...
Master is set if you are masterlooter and BidNotOpen if there is not currently a bid open. I did have some debugging prints in this function at one point and I saw none of them when the hooking seemed to stop working.
When someone alt clicks and item the addon opens up bidding on the item to the raid. So, nothing for shift or ctrl.
It seemed the best way to do what I wanted to do.
Yes I use that. It is not an error.
you may want to put those debug print statements back in right at the top just to confirm if your hook is being called.
this is what i use for my dkp mod to handle alt clicking items and links.
mine picks up all the lootable items when you loot and queues them up so ive no need to check for alt clicking on the loot slots themselves but if thats what youre doing it shouldnt be too hard to figure out what the frame is called and hook that as well (if the setitemref hook doesnt work for that)
edit: i really should reverse that logic check and change this to frame