Thread Tools Display Modes
08-26-19, 07:27 PM   #1
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Need some help with secure hooking

Hi all

I am 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:

Lua Code:
  1. -- my hook functions
  2. hooksecurefunc(
  3.     "CloseBackpack",function()
  4.         print("CloseBackpack hookedfunction fired")
  5.     end
  6. )
  7. hooksecurefunc(
  8.     "OpenBackpack",function()
  9.         print("OpenBackpack hookedfunction fired")
  10.     end
  11. )
  12. hooksecurefunc(
  13.     "ToggleBackpack",function()
  14.         print("ToggleBackpack hookedfunction fired")
  15.     end
  16. )
Lua Code:
  1. -- my event triggers
  2. TestFrame:SetScript("OnEvent",function(self, event, ...)
  3.     if event == "BAG_OPEN" then
  4.         print("BAG_OPEN event triggered")
  5.     elseif event == "BAG_CLOSED" then
  6.         print("BAG_CLOSED event triggered")
  7.     end
  8. end
  9. )
  10. TestFrame:RegisterEvent("BAG_OPEN")
  11. TestFrame:RegisterEvent("BAG_CLOSED")
Any sort of guidance and explanation of where I am going wrong would be great.

Last edited by Walkerbo : 08-26-19 at 07:32 PM.
  Reply With Quote
08-27-19, 02:59 AM   #2
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
The hook secure part works fine, maybe you could post more code, so we can find the real problem.

I don't think use BAG_OPEN/BAG_CLOSED is a good choice since open/close bag is an ui action, it won't trigger the system event, you may try the BAG_UPDATE event for an example, so you can just move one item to another bag slot to trigger it.
  Reply With Quote
08-27-19, 07:51 AM   #3
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by Walkerbo View Post
yet I still have not been able to get any results when I run my code.
Originally Posted by kurapica.igas View Post
The hook secure part works fine, maybe you could post more code, so we can find the real problem.

I don't think use BAG_OPEN/BAG_CLOSED is a good choice since open/close bag is an ui action, it won't trigger the system event

This. Tell us more clearly what you're trying to do and post your full code
You just want to know when any of the bags gets opened rather than the backpack?

https://us.forums.blizzard.com/en/wo...hooking/265975
  Reply With Quote
09-17-19, 06:00 PM   #4
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Hi kurapica and Ketho

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?
  Reply With Quote
09-17-19, 06:12 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
At a guess, other addons are possibly hooking the Blizzard OpenBag(id, force), CloseBag(id) functions for bags.

GUILDBANKFRAME_OPENED/GUILDBANKFRAME_CLOSED
BANKFRAME_OPENED/BANKFRAME_CLOSED
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-17-19, 08:15 PM   #6
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Originally Posted by Walkerbo View Post
Hi kurapica and Ketho

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?
You can use /fstack to check the bag addon's frame name, and use frame:HookScript("OnShow", func) frame:HookScript("OnHide", func) to check them. It's more better than use secure hook.
  Reply With Quote
09-18-19, 05:03 PM   #7
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Hi Ketho, Fizzlemizz and kurapica

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

Once again thanks.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need some help with secure hooking

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