Thread Tools Display Modes
05/07/16, 03:22 AM   #1
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
PreHooking protected functions

Even if it's really simple, it's not in the esoui files, so ..

Lua Code:
  1. --[[
  2. ZO_PreHookProtected is a rewrite of ZO_PreHook. It accepts Protected functions.
  3. IsProtectedFunction(existingFunctionName) will still return true even if existingFunctionName is not called
  4. Calling existingFunctionName() will work, it will call your function and depending on your code will run the prehooked function
  5. Calling CallSecureProtected("existingFunctionName", arg1) will work, it will call the original function only. You won't be able to "fake" other addons if they're correctly written, but mainly ESOUI code.
  6. Don't hook a non-protected function with this PreHook or game won't load
  7. ]]--
  8. function ZO_PreHookProtected(objectTable, existingFunctionName, hookFunction)
  9.     if(type(objectTable) == "string") then
  10.         hookFunction = existingFunctionName
  11.         existingFunctionName = objectTable
  12.         objectTable = _G
  13.     end
  14.  
  15.     local newFn = function(...)
  16.         if(not hookFunction(...)) then
  17.        
  18.             if IsProtectedFunction(existingFunctionName) then
  19.                 return CallSecureProtected(existingFunctionName, ...)
  20.             end
  21.            
  22.         end
  23.     end
  24.  
  25.     objectTable[existingFunctionName] = newFn
  26.  
  27. end

Doing this will mainly prehook ESOUI code and your own addon, so consider that the esoui code may not run because of another addon doing something else instead.
  Reply With Quote
05/07/16, 08:04 PM   #2
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
Could you provide an example using this hook? Thanks!!
  Reply With Quote
05/08/16, 04:58 AM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
I think you can use it as ZO_PreHook variant but ONLY for functions like UseItem() now.

Don't hook a non-protected function with this PreHook or game won't load
If you return true inside your PreHook UseItem won't be executed if I understand it correctly?

Lua Code:
  1. ZO_PreHookProtected('UseItem', MyUseItemFunction)
  2.  
  3. local function MyUseItemFunction(..)
  4.    if doNotUseItem then
  5.       return true
  6.    end
  7. end

Last edited by Baertram : 05/08/16 at 05:17 AM.
  Reply With Quote
05/08/16, 05:06 AM   #4
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
That's it, just like PreHook.

Main goal is to add a backup of the prehooked func inside your hooking function to change its parameters. My first need was to redirect moves for crafting bag.
  Reply With Quote

ESOUI » Developer Discussions » Tutorials & Other Helpful Info » PreHooking protected functions

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