View Single Post
12-11-12, 02:18 PM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
I was bored, here's some code.

Lua Code:
  1. local CachedText={};
  2. local function OnShow(self) CachedText[self]=self:GetText(); end
  3. local function OnTextChanged(self) local txt=self:GetText(); if txt~="" then CachedText[self]=txt; end end
  4.  
  5. local Hooked={};
  6. hooksecurefunc("ChatEdit_ActivateChat",function(editbox)
  7.     if not Hooked[editbox] then
  8.         editbox:HookScript("OnShow",OnShow);
  9.         editbox:HookScript("OnTextChanged",OnTextChanged);
  10.         OnShow(editbox);--  Aready shown by the time this runs
  11.  
  12.         Hooked[editbox]=true;
  13.     end
  14. end);
  15.  
  16. local Count,Start=0,GetTime();
  17. hooksecurefunc("ChatEdit_SendText",function(editbox)
  18.     local cmd,now=((CachedText[editbox] or ""):match("^/%S+") or ""):upper(),GetTime();
  19.     if IsSecureCmd(cmd) or hash_SlashCmdList[cmd] or hash_EmoteTokenList[cmd] then
  20. --      Our reset command will run this too
  21.         if Count<0 then Count=0; return; end
  22.         if Count<1 then Start=now; end
  23.  
  24.         Count=Count+1;
  25.         local runtime=now-Start;
  26.         print(("%d commands run in %0.2f seconds. (%0.2f commands per second)"):format(Count,runtime,Count/runtime));
  27.     end
  28. end);
  29.  
  30. function SlashCmdList.SLASHCOUNT_RESET()
  31. --  Our hook will finish the reset
  32.     Count=-1;
  33. end
  34. SLASH_SLASHCOUNT_RESET1="/slashcountreset";
  35. SLASH_SLASHCOUNT_RESET2="/screset";
__________________
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 : 12-17-12 at 04:04 AM.
  Reply With Quote