A simpler way would be to wait until later in the loading process to hook the tooltip and create a prehook the old fashioned way.
Lua Code:
local loader=CreateFrame("Frame");
loader:RegisterForEvents("PLAYER_LOGIN");-- Register for an event that appears late in the loading process. This makes it more likely our hook is the last to be set up
loader:SetScript("OnEvent",function()
local oldscript=GameTooltip:GetScript("OnTooltipSetItem");-- Save any previously registered scripts
GameTooltip:SetScript("OnTooltipSetItem",function(self,...)-- Futureproofing, support extra args to pass to previous scripts
-- Add your text here
-- Run any other addons' functions
if oldscript then return oldscript(self,...); end
end);
end);
This is done because
GameTooltip:HookScript() sets up a posthook, meaning the function you give it runs after any script that's already there. A prehook in contrast runs before any existing function. No protected function should be run from tooltip code, so taint shouldn't be an issue here.
In any occasion, trying to place your addon's text in a certain spot in the tooltip opens up race conditions competing with any other addon that might have that same design choice. The best and most efficient option is to let it be and do nothing.