Help with secure hooking

Hi all

I nam looking for a bit of guidance with hooking secure functions and/or triggering events for opening and closing the backpack.

I already have PLAYER_LOGIN, MERCHANT_SHOW and MERCHANT_CLOSED events working without issue.

On Townlong Yak I can find the BAG_OPEN and BAG_CLOSED events, as well as the ToggleBackpack, OpenBackpack and CloseBackpack functions yet I still have not been able to get any results when I run my code.

Here are my code chunks:

-- my hook functions
hooksecurefunc(
    "CloseBackpack",function()
        print("CloseBackpack hookedfunction fired")
    end
)
hooksecurefunc(
    "OpenBackpack",function()
        print("OpenBackpack hookedfunction fired")
    end
)
hooksecurefunc(
    "ToggleBackpack",function()
        print("ToggleBackpack hookedfunction fired")
    end
)
-- my event triggers
TestFrame:SetScript("OnEvent",function(self, event, ...)
    if event == "BAG_OPEN" then
        print("BAG_OPEN event triggered")
    elseif event == "BAG_CLOSED" then
        print("BAG_CLOSED event triggered")
    end
end
)
TestFrame:RegisterEvent("BAG_OPEN")
TestFrame:RegisterEvent("BAG_CLOSED")

Any sort of guidance and explanation of where I am going wrong would be great.

There surprisingly is no event for opening/closing inventory bags, you can verify this with /etrace

https://wow.gamepedia.com/BAG_OPEN

1 Like

OpenBag
ToggleBag

if youre only interested in the backpack then just check the first arg (will be the bag_id)

theres also these, which will open the backpack along with all the other bags

OpenAllBags
ToggleAllBags - may no longer exist

2 Likes

Hi Ketho and Arkayenro, thanks for the replies.

I still have not been able to crack this nut yet, so any further advice and/or suggestions would be a huge help.

if not even the hooksecurefuncs are working then are you sure you have the toc and everything else correct so it loads properly?

maybe throw a print statement outside the functions to prove the file is being loaded?

do you have something like the buggrabber and backsack addins for error checking?

Hi Ketho and Arkayenro

Sorry for the delayed reply, I am back on deck and ready to go.

You are both right the hook function is working perfectly, the issue was that I had not disabled the bag addon that I run, so a real boneheaded mistake.

My goal is to have a function run when the either the backpack, equipped bag, guild bank or the player bank open and close.

I want to hook that trigger but when I download and check other bag addons I have had very little success in understanding how and where they hook the function.

Is there a way to determine for each bag addon what or where the hooking function resides?

Just saw your WoWI thread.

https://www.wowinterface.com/forums/showthread.php?p=333847#post333847

the backpack and bags are already covered by those functions we’ve already mentioned

the others are typically done via listening for events as you always have visibility of those. ie you could hook the function that happens when the bank is opened but if someone (like me) takes control of it before you hook it, and moves it elsewhere, then while you can still hook it, it might not ever trigger (because i dont want it to as im overriding the bank) - its basically what you ran into with hooking the bag open function, the bag mod you had already overridden it.

this is one reason you cant have multiple bag mods, they cant play nicely because they all need to override that same function

for the bank and vault you need to listen for these game events;
BANKFRAME_OPENED
BANKFRAME_CLOSED
GUILDBANKFRAME_OPENED
GUILDBANKFRAME_CLOSED

note - they can trigger multiple times in a very short period so make sure you cater for that (the ace library has a bucket message type that i use for this purpose)

search for hooksecurefunc, and Events that are being listened for in their code. you can find all the wow events by googling wow api event

1 Like

Hi Ketho, Fizzlemizz and Arkayenro

Thank you all for your help and advice, I really appreciate these great communities and how helpful your responses are.

Once again thanks.