Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 

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