MyAddon = AceLibrary("AceAddon-2.0"):new("AceHook-2.0") -- hooking mixin
function MyAddon:OnInitialize()
self:Hook(DEFAULT_CHAT_FRAME, "AddMessage")
self:Hook(ChatFrame2, "AddMessage")
self:Hook(ChatFrame3, "AddMessage")
self:Hook(ChatFrame4, "AddMessage")
self:Hook(ChatFrame5, "AddMessage")
self:Hook(ChatFrame6, "AddMessage")
self:Hook(ChatFrame7, "AddMessage")
-- those all hook the AddMessage method of the chat frames.
-- They will be redirected to MyAddon:AddMessage(...)
end
function MyAddon:AddMessage(frame, text, r, g, b, id)
-- frame is the object that was hooked (one of the ChatFrames)
-- text, r, g, b, id are the other arguments provided to it.
local h,m = GetGameTime()
self.hooks[frame].AddMessage.orig(frame, string.format("[%02d:%02d] %s", h, m, text), r, g, b, id)
-- self.hooks[object][method].orig holds the original method. This should be called every time you deal with hooking.
-- be sure to provide all the arguments provided to you as well.
-- In this case, we pass back the method with modified arguments (adding a timestamp).
end