Posted by lucene on Wed, 11 Jul 2012 12:36:02
Hey i hope someone can help me with the issue im having. Its basically i would like to change the way how the default raid frame sort works.
So i would like to change the behavior of the following function from the default raid frame Blizzard_CompactRaidFrameManager.lua
function CRFSort_Group(token1, token2) if ( GetNumRaidMembers() > 0 ) then local id1 = tonumber(string.sub(token1, 5)); local id2 = tonumber(string.sub(token2, 5)); if ( not id1 or not id2 ) then return id1; end local _, _, subgroup1 = GetRaidRosterInfo(id1); local _, _, subgroup2 = GetRaidRosterInfo(id2); if ( subgroup1 and subgroup2 and subgroup1 ~= subgroup2 ) then return subgroup1 < subgroup2; end --Fallthrough: Sort by order in Raid window. return id1 < id2; else if ( token1 == "player" ) then return true; elseif ( token2 == "player" ) then return false; else return token1 < token2; --String compare is OK since we don't go above 1 digit for party. end end end
Is it even possible to override a function or need i listen to a specific api event. Im a web developer and i have some general knowledge in programming but im a newbie in LUA.
Someone have an idea how i can solve this issue ? I appreciate your detailed help.
Posted by stolenlegacy on Wed, 11 Jul 2012 12:41:54
Looking at the code, simply redefining it, then calling
function CRFSort_Group(token1,token2) -- your code end CompactRaidFrameContainer_SetFlowSortFunction(CompactRaidFrameManager.container, CRFSort_Group);
PS: Indent a block of text to have it show as code.
Posted by lucene on Wed, 11 Jul 2012 13:03:12
Thank you stolenlegacy for your quick reply.
Sorry for this dumb questions. But if i create a new addon and redefining the function, how can i be sure that my addon gets executed after the blizzard one ?
And whats the difference between redefining the function or use the Hooking method ?
Thanks in advance
Posted by stolenlegacy on Thu, 12 Jul 2012 02:02:58
Redefining overrides the previous one, preventing its execution. (Actually, it only replaces the memory pointer in the global variable with one to the new functions, so any addons that took a local reference to the old function won't be affected. Blizzard almost never does that though.) Hooking would mean your function is called after the original one with the same arguments.
To make sure your addon is executed after the Blizzard one, simply using
LoadAddOn("Blizzard_CompactRaidFrames")should do the trick.
Posted by lucene on Thu, 12 Jul 2012 11:17:49
Thanks a lot for your detailed explanation.
I have now created a new addon with this functionality and it works exactly like i want it. (Tested in a two member raid in the city)
But if i play a battleground with my addon active it throws sometimes a LUA error located in the blizzard scripts. After I researched the internet i think its a problem with some "protected/private" blizzard functions.
For test purposes i have hooked my custom function with the hooksecurefunc("xx", yy); method and added some print() outputs to make sure all my custom code works well. The behavior now is like you said, the function gets executed but dont override the existing one. I tried this script in a battleground too and all debug outputs are ok and no LUA error anymore.
So im pretty sure it has somthing to do with the "protected/private" function scope.
My question is now: Is it even possible to override/redefining a function and maintain the protected/private scope ? Or are there any other solutions for this problem ?
Thanks in advance
Posted by stolenlegacy on Fri, 13 Jul 2012 10:36:19
Hm, I wasn't aware that they were using protected functions for raid frame sorting. In that case, as you noticed, overriding the function will taint the code that calls it.
All code coming from a non-Blizzard addon is tainted (insecure) by default. There's nothing you can do about that, and it's what hooksecurefunc was made for.
Posted by lucene on Fri, 13 Jul 2012 12:35:07
Thank you again stolenlegacy.
The problem was that the raid frame needs to update in combat (someone joins or leaves raid) often occured in battlegrounds.
The method issecurevariable("CompactRaidFrame1") showed me that my own addon is tainting the raid frames. Unfortunately my sort function depends on the possibility to return its values, and thats not the case with hooksecurefunc.
I think i found a workaround to replace the sort function without allowing WOW to track it as tainting (eventually a bug).
Posted by jnwhiteh on Fri, 13 Jul 2012 15:03:01
Um.. You cannot provide a new sort function to the default raid frames without tainting. It's positively impossible, so if you think you've done it, it means you just haven't broken it yet =)
This is an intentional limitation of the system and won't ever be implemented or relaxed.
Posted by stolenlegacy on Fri, 13 Jul 2012 21:49:56
I'm not sure I follow what you did, lucene. Are you saying you managed to somehow allow your own function to run securely? That effectively should not happen. Could you provide your code?
Posted by lucene on Sat, 14 Jul 2012 12:42:00
Thanks for your interest again.
I dont think its a good idea to post my code in a public place until i know for sure whats up with it.
I have taken some screenshots, so you can actually see what it does, and why i think it doesnt taint any blizzard code. All screens are taken from the latest MOP Beta 5.0.3
So basicaly what my addon does: It allows me to sort the first five raid members in my party order (like in a 5 man group). So i have a fixed order for the first five people in my raid and i can use binds like "tar player/party1/party2..." in a matching order. I need this mainly in arenas.
- Addon loaded / custom sort deactivated (Raid leader has position #1) / no tainting
- Addon loaded / custom sort activated (Player has position #1) / no tainting
- Like pic 1, with open raid frame setting
- Like pic 2, with open raid frame setting
So like you can see i havent changed my raid frame settings and my custom sort is active but the /run print(issecurevariable("CompactRaidFrame1")) macro tells that nothing is taintig the raid frames. I dont get the raid frame curruption bug too.
In my first tests with just redefining the function i got the raid frame corruption bug and the macro told me that my addon is tainting the frames.
Am i missing something ? Or are there other ways to find out if i broke something ?
Posted by jnwhiteh on Sat, 14 Jul 2012 13:39:30
Yeah this shouldn't be possible, so either its not working the think its working or you've found an exploit. I suggest you post some code so we can see what you're doing.