Thread: Patch 6.0
View Single Post
04-01-14, 11:35 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,335
I guess you can try intercepting UI functions that set the text of various UI elements by hooking into the UI object metatables. For example, if you want to intercept and modify the text of every FontString object as they are being set, this example code would be a place to start.

Lua Code:
  1. --  First, we dynamicly create a FontString object in order to grab the shared FontString metatable
  2. local meta=getmetatable(UIParent:CreateFontString("BACKGROUND")).__index;
  3. local SetText=meta.SetText;--   Link to our original function
  4.  
  5. --  We need to secure hook the function in case this would be called by secure code
  6. hooksecurefunc(meta,"SetText",function(self,text)
  7. --  Even though the original function has already set the text as supplied, we'll replace it with our own
  8.  
  9. --  We don't want to throw a UI error if text isn't a string
  10.     if type(text)~="string" then return; end
  11.  
  12. --  We use string.gsub() to modify the text using the old function
  13.     SetText(self,text:gsub("SearchWord","ReplacementWord");
  14. end);

Note the secure hook method may not work for functions like GameTooltip:AddLine(), in which each call adds a new line.
__________________
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