Thread Tools Display Modes
09-21-14, 07:54 AM   #1
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
How to hook this?

Im trying to hook this function:

Code:
function DEFAULT_OBJECTIVE_TRACKER_MODULE:SetStringText(fontString, text, useFullHeight, colorStyle, useHighlight)
	fontString:SetHeight(0);
	fontString:SetText(text);
	local stringHeight = fontString:GetHeight();
	if ( stringHeight > OBJECTIVE_TRACKER_DOUBLE_LINE_HEIGHT and not useFullHeight ) then
		fontString:SetHeight(OBJECTIVE_TRACKER_DOUBLE_LINE_HEIGHT);
		stringHeight = OBJECTIVE_TRACKER_DOUBLE_LINE_HEIGHT;
	end
	colorStyle = colorStyle or OBJECTIVE_TRACKER_COLOR["Normal"];
	if ( useHighlight and colorStyle.reverse ) then
		colorStyle = colorStyle.reverse;
	end
	if ( fontString.colorStyle ~= colorStyle ) then
		fontString:SetTextColor(colorStyle.r, colorStyle.g, colorStyle.b);
		fontString.colorStyle = colorStyle;
	end
	return stringHeight;
end
I tried using

Code:
hooksecurefunc(DEFAULT_OBJECTIVE_TRACKER_MODULE,"SetStringText",function(fontString, text, useFullHeight, colorStyle, useHighlight)
	fontString:SetHeight(0);
	fontString:SetText(text);
	local stringHeight = fontString:GetHeight();
	if ( stringHeight > OBJECTIVE_TRACKER_DOUBLE_LINE_HEIGHT and not useFullHeight ) then
		fontString:SetHeight(OBJECTIVE_TRACKER_DOUBLE_LINE_HEIGHT);
		stringHeight = OBJECTIVE_TRACKER_DOUBLE_LINE_HEIGHT;
	end
	colorStyle = colorStyle or OBJECTIVE_TRACKER_COLOR["Normal"];
	if ( useHighlight and colorStyle.reverse ) then
		colorStyle = colorStyle.reverse;
	end
	if ( fontString.colorStyle ~= colorStyle ) then
		fontString:SetTextColor(colorStyle.r, colorStyle.g, colorStyle.b);
		fontString.colorStyle = colorStyle;
	end
	return stringHeight;
end)
I want to alter the fontstrings, but it kept trowing errors at me. What am i doing wrong?
__________________
◘◘ Author of MiirGui Texture Pack - [Core] [Blue] [Grey] ◘◘
  Reply With Quote
09-21-14, 08:22 AM   #2
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
What error are you getting?
  Reply With Quote
09-21-14, 08:51 AM   #3
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
I am probably doing something very simple wrong.

This is the error message when trying to jsut hook the original function (without altering any code)

Code:
Message: Interface\AddOns\miirGui\core.lua:912: attempt to call method 'SetHeight' (a nil value)
Time: 09/21/14 16:51:51
Count: 8
Stack: Interface\AddOns\miirGui\core.lua:912: in function <Interface\AddOns\miirGui\core.lua:911>
[C]: in function `SetStringText'
edit: This is all on PTR.
__________________
◘◘ Author of MiirGui Texture Pack - [Core] [Blue] [Grey] ◘◘
  Reply With Quote
09-21-14, 08:57 AM   #4
Tageshi
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 7
You have to notice a colon between DEFAULT_OBJECTIVE_TRACKER_MODULE and SetStringText.

Lua Code:
  1. function DEFAULT_OBJECTIVE_TRACKER_MODULE:SetStringText(fontString, text, useFullHeight, colorStyle, useHighlight)
is same as;

Lua Code:
  1. function DEFAULT_OBJECTIVE_TRACKER_MODULE.SetStringText(self, fontString, text, useFullHeight, colorStyle, useHighlight)

thus, try this;
Lua Code:
  1. hooksecurefunc(DEFAULT_OBJECTIVE_TRACKER_MODULE,"SetStringText",function(self, fontString, text, useFullHeight, colorStyle, useHighlight)
  Reply With Quote
09-21-14, 08:58 AM   #5
sticklord
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 57
Instead of:
Lua Code:
  1. hooksecurefunc(DEFAULT_OBJECTIVE_TRACKER_MODULE,"SetStringText",function(fontString, text, useFullHeight, colorStyle, useHighlight)

Use:
Lua Code:
  1. hooksecurefunc(DEFAULT_OBJECTIVE_TRACKER_MODULE,"SetStringText",function(_, fontString, text, useFullHeight, colorStyle, useHighlight)

Because i believe the original function has a magical hidden self there.

edit // goodamnit
  Reply With Quote
09-21-14, 09:01 AM   #6
Tageshi
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 7
LOL. What a coincidence.
  Reply With Quote
09-21-14, 09:02 AM   #7
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
Originally Posted by sticklord View Post
Instead of:
Lua Code:
  1. hooksecurefunc(DEFAULT_OBJECTIVE_TRACKER_MODULE,"SetStringText",function(fontString, text, useFullHeight, colorStyle, useHighlight)

Use:
Lua Code:
  1. hooksecurefunc(DEFAULT_OBJECTIVE_TRACKER_MODULE,"SetStringText",function(_, fontString, text, useFullHeight, colorStyle, useHighlight)

Because i believe the original function has a magical hidden self there.

edit // goodamnit
Thank you so much this works out perfectly. Now how can one get knowledge about which function have such a hidden self?
__________________
◘◘ Author of MiirGui Texture Pack - [Core] [Blue] [Grey] ◘◘
  Reply With Quote
09-21-14, 09:04 AM   #8
sticklord
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 57
@ Tageshi: Yeah, beat me by a minute!

@ Miiru: Look at the post above mine.
  Reply With Quote
09-21-14, 10:21 AM   #9
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
The self is not magically hidden.

The following does the same:

Code:
function SOMETHING:AddOne(two)
    print(self, two)
end

function SOMETHING.AddOne(self, two)
    print(self, two)
end
  Reply With Quote
01-18-15, 07:56 AM   #10
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
So the right way to hook

function HeirloomsMixin:UpdateButton(button)

is

hooksecurefunc(HeirloomsMixin,"UpdateButton",function(self,button)

I am a bit confused because the HeirloomsMixin is not in caps, but i do not know if it is relevant.
__________________
◘◘ Author of MiirGui Texture Pack - [Core] [Blue] [Grey] ◘◘

Last edited by Miiru : 01-18-15 at 11:27 AM.
  Reply With Quote
01-18-15, 11:39 AM   #11
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
http://wow.gamepedia.com/API_hooksecurefunc
http://wow.gamepedia.com/API_Frame_HookScript

You use both of them where it's needed.
__________________
AddOns: Tim @ WoWInterface
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote
01-18-15, 11:46 AM   #12
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Frame:HookScript() only works on script handlers, not regular functions stored as table entries.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
01-18-15, 12:40 PM   #13
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
So from reading this, i gather that

Code:
hooksecurefunc(HeirloomsMixin,"UpdateButton",function()
Print("Test")
end)
should work. Weirdly it does nothing at all, it does not even throw an error message.

Blizzard_HeirloomCollection.lua from ptr.
__________________
◘◘ Author of MiirGui Texture Pack - [Core] [Blue] [Grey] ◘◘

Last edited by Miiru : 01-18-15 at 01:39 PM.
  Reply With Quote
01-18-15, 04:12 PM   #14
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
I think that you need to hook HeirloomsJournal instead of HeirloomsMixin, as the former is the table that's used to call the method. Even though they're the same function in both tables, it's the table that matters when you hook it. Hooking can be confusing that way.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
01-18-15, 06:03 PM   #15
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
Originally Posted by SDPhantom View Post
Frame:HookScript() only works on script handlers, not regular functions stored as table entries.
Hence why I said "where it's needed".
__________________
AddOns: Tim @ WoWInterface
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote
01-18-15, 07:06 PM   #16
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by Miiru View Post
Weirdly it does nothing at all, it does not even throw an error message.

Blizzard_HeirloomCollection.lua from ptr.
You probably hooked it before the file was loaded.
  Reply With Quote
01-19-15, 12:55 AM   #17
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
Originally Posted by Lombra View Post
I think that you need to hook HeirloomsJournal instead of HeirloomsMixin, as the former is the table that's used to call the method. Even though they're the same function in both tables, it's the table that matters when you hook it. Hooking can be confusing that way.
That indeed did the trick, thank you very much
__________________
◘◘ Author of MiirGui Texture Pack - [Core] [Blue] [Grey] ◘◘
  Reply With Quote
01-20-15, 01:53 PM   #18
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by p3lim View Post
You probably hooked it before the file was loaded.
hooksecurefunc() throws an error if used on a function that doesn't exist.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
04-17-15, 12:09 AM   #19
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
I am running into the same problems again now that they are recoding the whole garrison code (why didnt they code it with tables in the first place?)

So i try to hook this function:

function GarrisonFollowerList:UpdateData() with

hooksecurefunc(GarrisonFollowerList,"UpdateData",miirgui_UpdateData)

when miirgui_UpdateData simply prints test. It does absolutely nothing. It does also not print a test message. So i recon it is the same problem as i had with the heirloom stuff.

Yet i cant seem to identify which is the right table to hook from now :/
Blizzard_GarrisonSharedTemplates.lua
__________________
◘◘ Author of MiirGui Texture Pack - [Core] [Blue] [Grey] ◘◘

Last edited by Miiru : 04-18-15 at 05:08 AM.
  Reply With Quote
04-18-15, 05:12 AM   #20
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
Seems like a have to use hooksecurefunc(GarrisonMissionFrameFollowers,"UpdateData",miirgui_UpdateData). If anybody cares
__________________
◘◘ Author of MiirGui Texture Pack - [Core] [Blue] [Grey] ◘◘
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to hook this?

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