View Single Post
10-03-15, 06:00 PM   #1
Nikita S. Doroshenko
A Cyclonian
 
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 45
How can i hook complex Blizz functions, like: Module:FuncName(arguments)?

I would like to SetJustifyH "CENTER" all ObjectiveTrackerBlocks and remove all "Dashes" as well. I'm talking about Blocks that contains information about Quests you currently track:
(Sorry for different language on screenshot)


Files that respond to this frames locates in Interface\AddOns\Blizzard_ObjectiveTracker\ folder.
There are lots of files in this folder, but I think most relevant is this: Blizzard_ObjectiveTracker.lua (link to wowprogramming.com)

There are lot's of complex functions that I had never worked before. For example:

Lua Code:
  1. function DEFAULT_OBJECTIVE_TRACKER_MODULE:SetHeader(block, text, animateReason)
  2.     block.module = self;
  3.     block.isHeader = true;
  4.     block.Text:SetText(text);
  5.     block.animateReason = animateReason or 0;
  6.     self.Header = block;
  7. end

I tried to investigate more information about this functions and how they works, and for me (person who never programmed before, it's pretty hard to instantly understand them, but i would like).
On Hooking Functions Guide I read that it's possible to hook this strange functions. This Guide gives this example:
Lua Code:
  1. --[[Functions called using the object calling syntax, object:method(...), can also be hooked; one simply has to remember that the construct is merely syntactic sugar for objec*****thod(object, ...);. To hook a function that was originally declared as:]]
  2. function AnAddon.Module:FuncName(arg1)
  3.   -- Things happen here...
  4. end
  5. --[[We store the original function and replace it with a hook:]]
  6. local original_AnAddon_Module_FuncName = AnAddon.Module.FuncName;
  7. function AnAddon.Module:FuncName(...)
  8.   local arg1 = ...; -- Use the vararg expression in case the function signature changes
  9.   if type(arg1) == "number" and arg1 > 0 then
  10.     -- Call the original function; because of object calling syntax,
  11.     --   pass self as the first argument.
  12.     return original_AnAddon_Module_FuncName(self, ...);
  13.   end
  14. end
  15. --[[The example hook above will only allow the original function to be called if the first argument is a strictly positive number.]]
According to this example, i tryed to hook Blizzards function "DEFAULT_OBJECTIVE_TRACKER_MODULE:SetHeader" with this code:

Lua Code:
  1. local DEFAULT_OBJECTIVE_TRACKER_MODULE_SET_HEADER = DEFAULT_OBJECTIVE_TRACKER_MODULE.SetHeader
  2. function DEFAULT_OBJECTIVE_TRACKER_MODULE:SetHeader(...)
  3.     print("TEST")
  4.     return DEFAULT_OBJECTIVE_TRACKER_MODULE_SET_HEADER(self, ...);
  5. end

But it looks like that i'm doing something wrong. I don't get any lua errors, but no print("TEST") as well, so it's not hooked.
I will very appreciate if you could help me with example of how can i hook this complex functions or with advice or ideas how can i SetJustifyH("CENTER") and remove Dash without hooking this crazy functions (Names of ObjectiveTrackerBlocks are dynamic: example on screenshot)
  Reply With Quote