Skip to content

Instantly share code, notes, and snippets.

@Meorawr
Last active August 30, 2024 20:23
Show Gist options
  • Save Meorawr/a12caab75d49c8352dcfed78fe3bcd25 to your computer and use it in GitHub Desktop.
Save Meorawr/a12caab75d49c8352dcfed78fe3bcd25 to your computer and use it in GitHub Desktop.
Creature Spawn Inspector
--
-- Creature GUID Inspector
--
function GTT_CreatureInspect(self)
local _, unit = self:GetUnit();
local guid = UnitGUID(unit or "none");
local prefix = string.match(guid, "^([CVP][^l][^-]+)");
if not guid or not prefix then
return;
end
if string.find(prefix, "^[CV]") then
local guidSpawnOffset = bit.band(tonumber(string.sub(guid, -6), 16), 0x7fffff);
local guidSpawnIndex = bit.rshift(bit.band(tonumber(string.sub(guid, -10, -6), 16), 0xffff8), 3);
local serverSpawnEpoch = GetServerTime() - (GetServerTime() % 2^23);
local guidSpawnTime = serverSpawnEpoch + guidSpawnOffset;
if guidSpawnTime > GetServerTime() then
-- Correction for units that survived the last epoch.
guidSpawnTime = guidSpawnTime - ((2^23) - 1);
end
local guidSpawnDate = date("%Y-%m-%d %H:%M:%S", guidSpawnTime);
GameTooltip_AddBlankLineToTooltip(self);
GameTooltip_AddColoredDoubleLine(self, "GUID", guid, NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR);
GameTooltip_AddColoredDoubleLine(self, "Spawn Date/Time", guidSpawnDate, NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR);
GameTooltip_AddColoredDoubleLine(self, "Spawn Time Data", string.format("%.6X", guidSpawnTime), NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR);
GameTooltip_AddColoredDoubleLine(self, "Spawn Index Data", string.format("%.5X", guidSpawnIndex), NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR);
elseif prefix == "Pet" then
local guidPetUID = string.sub(guid, -8);
local guidSpawnIndex = tonumber(string.sub(guid, -10, -9), 16);
GameTooltip_AddBlankLineToTooltip(self);
GameTooltip_AddColoredDoubleLine(self, "GUID", guid, NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR);
GameTooltip_AddColoredDoubleLine(self, "Pet UID", guidPetUID, NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR);
GameTooltip_AddColoredDoubleLine(self, "Spawn Index", guidSpawnIndex, NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR);
end
end
if not GTT_CreatureInspectHooked then
GTT_CreatureInspectHooked = true;
GameTooltip:HookScript("OnTooltipSetUnit", function(...) return GTT_CreatureInspect(...); end);
end
Copy link

ghost commented May 12, 2021

I figured this out last year, cool to see others have too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment