Thread Tools Display Modes
10-17-10, 03:37 AM   #1
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Not sure how to hooksecurefunc....

So I'm attempting to "rewrite" a global function for Grid, since I generally rewrite it for my own usage:

Original Function:
Code:
function GridFrame.prototype:SetBarColor(r, g, b, a)
    if GridFrame.db.profile.invertBarColor then
        self.Bar:SetStatusBarColor(r, g, b, a)
        self.BarBG:SetVertexColor(r * 0.2, g * 0.2, b * 0.2, 1)
    else
        self.Bar:SetStatusBarColor(0, 0, 0, 0.8)
        self.BarBG:SetVertexColor(r, g, b, a)
    end

    self:UpdateHealingBarColor()
end
I've looked over the API page regarding hooksecurefunc on wowwiki but I'm not sure exactly how to go about this particular function.

Could anyone show me how I can "rewrite" this function to my liking with a hooksecure?

What I've come up with:
Code:
local function GridFix(r, g, b, a)
	--do stuff
	print("Stuff Done!")
end

local f = CreateFrame"Frame"
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(self,event,...)
	local arg1 = ...
	if arg1 == "Grid" then
		hooksecurefunc(GridFrame.prototype:SetBarColor(r, g, b, a), GridFix(r,g,b,a))
	end
end)
  Reply With Quote
10-17-10, 04:10 AM   #2
d87
A Chromatic Dragonspawn
 
d87's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 163
you can't rewrite function with hooksecurefunc. you can only posthook it.

but the good news is that grid isn't secure and you can rewrite all you want simply doing
GridFrame.prototype.SetBarColor = GridFix
  Reply With Quote
10-17-10, 04:28 AM   #3
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by d87 View Post
you can't rewrite function with hooksecurefunc. you can only posthook it.

but the good news is that grid isn't secure and you can rewrite all you want simply doing
GridFrame.prototype.SetBarColor = GridFix
Mmm, I thought about that but all the internal referencing is gone.

I'm really unsure if this is even possible to simply change the function through another addon. Also note its not "prototype.SetBarColor" it's ":" which is using a frame reference.
  Reply With Quote
10-17-10, 04:36 AM   #4
d87
A Chromatic Dragonspawn
 
d87's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 163
A:B(c) <=> A.B(A,c)
  Reply With Quote
10-17-10, 04:51 AM   #5
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
Code:
local function GridFix(self, r, g, b, a)
    if GridFrame.db.profile.invertBarColor then
        self.Bar:SetStatusBarColor(r, g, b, a)
        self.BarBG:SetVertexColor(r * 0.1, g * 0.1, b * 0.1, 1)
    else
        self.Bar:SetStatusBarColor(0, 0, 0, 0.8)
        self.BarBG:SetVertexColor(r, g, b, a)
    end

    self:UpdateHealingBarColor()
end

f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self, event, ...)
    if GridFrame then
        GridFrame.prototype.SetBarColor = GridFix
    end    
    f:SetScript("OnEvent", nil)
    f:UnregisterEvent("PLAYER_ENTERING_WORLD")
end)
This seems to work. Had to use P_E_W since GridFrame didn't exist at ADDON_LOADED.
__________________
Oh, the simulated horror!
  Reply With Quote
10-17-10, 05:05 AM   #6
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Ailae View Post
Code:
local function GridFix(self, r, g, b, a)
    if GridFrame.db.profile.invertBarColor then
        self.Bar:SetStatusBarColor(r, g, b, a)
        self.BarBG:SetVertexColor(r * 0.1, g * 0.1, b * 0.1, 1)
    else
        self.Bar:SetStatusBarColor(0, 0, 0, 0.8)
        self.BarBG:SetVertexColor(r, g, b, a)
    end

    self:UpdateHealingBarColor()
end

f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self, event, ...)
    if GridFrame then
        GridFrame.prototype.SetBarColor = GridFix
    end    
    f:SetScript("OnEvent", nil)
    f:UnregisterEvent("PLAYER_ENTERING_WORLD")
end)
This seems to work. Had to use P_E_W since GridFrame didn't exist at ADDON_LOADED.
Yea I tried that too but GridFrame doesn't seem to exist at any point. I'm really a little stumped here.

Looking at the GridFrame.lua coding its being created as this:

Code:
local GridFrame = Grid:NewModule("GridFrame", "AceBucket-3.0", "AceTimer-3.0")
Which makes me think it's not able to be edited since its a one off created Global that's no longer referenced.
  Reply With Quote
10-17-10, 06:24 AM   #7
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
Sorry, I forgot I had manually edited the GridFrame.lua file so I thought everything was working okay. :P

Maybe something like this instead?

Code:
local GridPlaceHolder = nil
local function GridFix(self, r, g, b, a)
    if GridPlaceHolder.db.profile.invertBarColor then
        self.Bar:SetStatusBarColor(r, g, b, a)
        self.BarBG:SetVertexColor(r * 0.1, g * 0.1, b * 0.1, 1)
    else
        self.Bar:SetStatusBarColor(0, 0, 0, 0.8)
        self.BarBG:SetVertexColor(r, g, b, a)
    end

    self:UpdateHealingBarColor()
end

f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self, event, ...)
	GridPlaceHolder = Grid:GetModule("GridFrame")
	if GridPlaceHolder then
		GridPlaceHolder.prototype.SetBarColor = GridFix
	end	
	f:SetScript("OnEvent", nil)
end)
__________________
Oh, the simulated horror!
  Reply With Quote
10-17-10, 08:34 PM   #8
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Ailae View Post
Sorry, I forgot I had manually edited the GridFrame.lua file so I thought everything was working okay. :P

Maybe something like this instead?

Code:
local GridPlaceHolder = nil
local function GridFix(self, r, g, b, a)
    if GridPlaceHolder.db.profile.invertBarColor then
        self.Bar:SetStatusBarColor(r, g, b, a)
        self.BarBG:SetVertexColor(r * 0.1, g * 0.1, b * 0.1, 1)
    else
        self.Bar:SetStatusBarColor(0, 0, 0, 0.8)
        self.BarBG:SetVertexColor(r, g, b, a)
    end

    self:UpdateHealingBarColor()
end

f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self, event, ...)
	GridPlaceHolder = Grid:GetModule("GridFrame")
	if GridPlaceHolder then
		GridPlaceHolder.prototype.SetBarColor = GridFix
	end	
	f:SetScript("OnEvent", nil)
end)
Nope still giving nils for "self"
  Reply With Quote
10-18-10, 12:32 AM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
This is my theory of what's going on...

lua Code:
  1. a=function() end;
  2. b=a;
  3.  
  4. hooksecurefunc("a",function() end);

Say function "a" is the function prototype. If and when Grid copies this function to a created object, it stored the current pointer in "a". In this exercise, the pointer to function "a" is stored in variable "b". When you hook function "a" using hooksecurefunc(), the pointer in "a" is changed to the new function pointer. This doesn't change the pointer in variable "b", which still points to the old function instead of the hook.
__________________
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
10-18-10, 12:46 AM   #10
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by SDPhantom View Post
This is my theory of what's going on...

lua Code:
  1. a=function() end;
  2. b=a;
  3.  
  4. hooksecurefunc("a",function() end);

Say function "a" is the function prototype. If and when Grid copies this function to a created object, it stored the current pointer in "a". In this exercise, the pointer to function "a" is stored in variable "b". When you hook function "a" using hooksecurefunc(), the pointer in "a" is changed to the new function pointer. This doesn't change the pointer in variable "b", which still points to the old function instead of the hook.
I've left out the hooksecurefunc, and was attempting to rewrite the function globally when it was available.

There should be no hook in the above coding.
  Reply With Quote
10-20-10, 12:56 AM   #11
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by suicidalkatt View Post
I've left out the hooksecurefunc, and was attempting to rewrite the function globally when it was available.

There should be no hook in the above coding.
The same rule still applies whenever you try to change, remove, or replace the function in any way.
I don't know if this exact reason why is your code isn't running, but it's likely.
__________________
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)

Last edited by SDPhantom : 10-20-10 at 12:59 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Not sure how to hooksecurefunc....


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