Files

205 lines
12 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Passive official 1.12 client travel observer. Lua 5.0 syntax; no gameplay hooks/sends.
-- Original UI API observations are not packets, server coordinates or spawn completeness.
local function initialize()
if WoWHybridTravelObserver then return end
local function public(v)
if type(issecretvalue)=="function" then
local ok,secret=pcall(issecretvalue,v)
if not ok or secret then return nil end
end
if type(v)=="string" then return string.sub(v,1,256) end
if type(v)=="number" and v==v and v<=1e308 and v>=-1e308 then return v end
if type(v)=="boolean" then return v end
return nil
end
local function call(name,a,b)
local fn=getglobal(name);if type(fn)~="function" then return nil end
local ok,x,y,z,w
if b~=nil then ok,x,y,z,w=pcall(fn,a,b)
elseif a~=nil then ok,x,y,z,w=pcall(fn,a)
else ok,x,y,z,w=pcall(fn) end
if not ok then return nil end
return public(x),public(y),public(z),public(w)
end
local old=WoWHybridTravelCapture
if type(old)~="table" and type(pfUI_cache)=="table" then old=pfUI_cache.WoWHybridTravelCapture end
if type(old)~="table" or old.schema~=1 or type(old.rows)~="table" or
type(old.bytes)~="number" or type(old.dropped)~="number" or type(old.loads)~="number" then
old={schema=1,rows={},bytes=0,dropped=0,loads=0,eventCounts={}}
end
local C=old;C.loads=C.loads+1;C.eventCounts=C.eventCounts or {};C.coalesced=C.coalesced or {travel=0,unit=0,eventRows=0}
C.capturePolicy="v3-prioritized-travel-bounded-latest"
WoWHybridTravelCapture=C
if type(pfUI_cache)=="table" then pfUI_cache.WoWHybridTravelCapture=C end
local now=call("GetTime") or 0;local wall=call("time") or 0
local nonce="octo-travel-v3:"..tostring(wall)..":"..tostring(now)..":"..tostring(C.loads)
local O={active=true,capture=C,nonce=nonce,maxRows=4096,maxBytes=2097152,reserveRows=512,reserveBytes=262144,elapsed=0}
WoWHybridTravelObserver=O
local function bindCache()
if type(pfUI_cache)=="table" then pfUI_cache.WoWHybridTravelCapture=C end
return type(pfUI_cache)=="table" and pfUI_cache.WoWHybridTravelCapture==C
end
local lastUnit={};local lastTravel
local function same(a,b,keys)
if not a then return false end
for _,key in ipairs(keys)do if a[key]~=b[key] then return false end end
return true
end
local unitKeys={"unit","name","guid","level","creatureType","isPlayer","modelIDStatus"}
local travelKeys={"zone","subzone","realZone","mapContinent","mapZone","mapAreaID","mapX","mapY","onTaxi","mounted","speed","cacheBound"}
local function record(kind,data)
if not O.active then return end
-- Only locally created flat records with bounded scalar fields enter SavedVariables.
local row={kind=kind,nonce=nonce,time=call("GetTime") or 0};local bytes=string.len(kind)+string.len(nonce)+32
for k,v in pairs(data or {})do
local clean=public(v)
if clean~=nil then row[k]=clean;bytes=bytes+string.len(k)+string.len(tostring(clean))+8 end
end
-- These two fixed flat records retain current state even if historical rows fill.
if kind=="observer-ready" then C.latestReady=row end
if kind=="travel" then
C.latestTravel=row
if (row.reason=="periodic" or row.reason=="UNIT_FLAGS") and
same(lastTravel,row,travelKeys) and row.time-lastTravel.time<30 then
C.coalesced.travel=(C.coalesced.travel or 0)+1;return
end
elseif kind=="unit" then
local previous=lastUnit[row.unit]
if same(previous,row,unitKeys) and row.time-previous.time<30 then
C.coalesced.unit=(C.coalesced.unit or 0)+1;return
end
end
local important=kind=="travel" or kind=="observer-ready" or kind=="stopped"
local rowLimit=O.maxRows;local byteLimit=O.maxBytes
if not important then
rowLimit=rowLimit-math.min(O.reserveRows,math.floor(O.maxRows/4))
byteLimit=byteLimit-math.min(O.reserveBytes,math.floor(O.maxBytes/4))
end
if table.getn(C.rows)>=rowLimit or C.bytes+bytes>byteLimit then C.dropped=C.dropped+1;return end
table.insert(C.rows,row);C.bytes=C.bytes+bytes
if kind=="travel" then lastTravel=row elseif kind=="unit" then lastUnit[row.unit]=row end
end
local function unit(token)
if not call("UnitExists",token) then return end
record("unit",{unit=token,name=call("UnitName",token),guid=call("UnitGUID",token),
level=call("UnitLevel",token),creatureType=call("UnitCreatureType",token),
isPlayer=call("UnitIsPlayer",token),modelIDStatus="no-verified-vanilla-getter"})
end
local function auraIndex()
local start=public(PLAYER_BUFF_START_ID)
if start==-1 then return start,"global-vanilla-negative-one" end
if start==0 then return start,"global-tbc-zero" end
-- Exact inspected pfUI:GetEnvironment() binding; no search or guessed default.
if start==nil and pfUI and type(pfUI.env)=="table" then
start=public(pfUI.env.PLAYER_BUFF_START_ID)
if start==-1 and pfUI.expansion=="vanilla" then return start,"pfUI.env-vanilla-negative-one" end
if start==0 and pfUI.expansion=="tbc" then return start,"pfUI.env-tbc-zero" end
end
return nil,"unresolved-or-inconsistent-index-origin"
end
local auraSignatures={};local auraSerial=0
local function auras(reason)
-- Exact 1.12 index/filter API used by installed pfUI buff.lua and compat/vanilla.lua.
local start,origin=auraIndex();C.auraIndexOrigin=origin
if start==nil or
type(GetPlayerBuff)~="function" or type(GetPlayerBuffTexture)~="function" then return end
for _,filter in ipairs({"HELPFUL","HARMFUL"})do
local rows={};local signature=""
for slot=1,32 do
local bid,untilCancelled=call("GetPlayerBuff",start+slot,filter)
if type(bid)~="number" or bid<0 or bid>255 or bid~=math.floor(bid) then break end
local texture=call("GetPlayerBuffTexture",bid)
local stacks=call("GetPlayerBuffApplications",bid)
local left=call("GetPlayerBuffTimeLeft",bid)
table.insert(rows,{slot=slot,buffIndex=bid,texture=texture,stacks=stacks,
timeLeft=left,untilCancelled=untilCancelled,filter=filter})
signature=signature..tostring(slot)..":"..tostring(bid)..":"..tostring(texture)..":"..
tostring(stacks)..":"..tostring(untilCancelled)..";"
end
if auraSignatures[filter]~=signature or reason=="observer-ready" or reason=="PLAYER_LOGOUT" then
auraSignatures[filter]=signature;auraSerial=auraSerial+1
record("aura-snapshot",{reason=reason,filter=filter,snapshot=auraSerial,count=table.getn(rows)})
for _,row in ipairs(rows)do row.snapshot=auraSerial;record("aura",row)end
end
end
end
local function snapshot(reason)
local x,y=call("GetPlayerMapPosition","player")
record("travel",{reason=reason,cacheBound=bindCache(),zone=call("GetZoneText"),subzone=call("GetSubZoneText"),
realZone=call("GetRealZoneText"),mapContinent=call("GetCurrentMapContinent"),
mapZone=call("GetCurrentMapZone"),mapAreaID=call("GetCurrentMapAreaID"),mapX=x,mapY=y,
coordinateScope="current-map-context-not-forced-to-player-zone",
onTaxi=call("UnitOnTaxi","player"),mounted=call("IsMounted"),
speed=call("GetUnitSpeed","player")})
end
local function taxi()
unit("target");unit("npc")
local n=call("NumTaxiNodes")
if type(n)~="number" or n<0 or n>1024 or n~=math.floor(n) then return end
record("taxi-map",{nodeCount=n,limit=128})
for i=1,math.min(n,128)do
local x,y=call("TaxiNodePosition",i)
record("taxi-node",{index=i,name=call("TaxiNodeName",i),nodeType=call("TaxiNodeGetType",i),x=x,y=y})
end
end
local frame=CreateFrame("Frame");O.frame=frame
local names={"PLAYER_ENTERING_WORLD","ZONE_CHANGED_NEW_AREA","ZONE_CHANGED","ZONE_CHANGED_INDOORS",
"PLAYER_CONTROL_LOST","PLAYER_CONTROL_GAINED","PLAYER_TARGET_CHANGED","UPDATE_MOUSEOVER_UNIT",
"TAXIMAP_OPENED","TAXIMAP_CLOSED","PLAYER_AURAS_CHANGED","UNIT_FLAGS","PLAYER_LOGOUT",
"SPELLCAST_START","SPELLCAST_STOP","SPELLCAST_FAILED","SPELLCAST_INTERRUPTED","SPELLCAST_DELAYED",
"SPELLCAST_CHANNEL_START","SPELLCAST_CHANNEL_STOP","SPELLCAST_CHANNEL_UPDATE"}
C.unsupportedEvents={}
for _,name in ipairs(names)do
local ok=pcall(frame.RegisterEvent,frame,name)
if not ok then C.unsupportedEvents[name]=true end
end
local travelEvents={PLAYER_ENTERING_WORLD=true,ZONE_CHANGED_NEW_AREA=true,ZONE_CHANGED=true,
ZONE_CHANGED_INDOORS=true,PLAYER_CONTROL_LOST=true,PLAYER_CONTROL_GAINED=true,
TAXIMAP_OPENED=true,TAXIMAP_CLOSED=true,UNIT_FLAGS=true,PLAYER_LOGOUT=true}
frame:SetScript("OnEvent",function(self,modernEvent,modernUnit,modernArg2)
local name=public(modernEvent or event);local token=modernUnit or arg1;local second=modernArg2 or arg2
if type(name)~="string" or not O.active then return end
if name=="UNIT_FLAGS" and public(token)~="player" then return end
C.eventCounts[name]=(C.eventCounts[name] or 0)+1
bindCache()
local casting=string.sub(name,1,10)=="SPELLCAST_"
if not casting and travelEvents[name] and name~="UNIT_FLAGS" then record("event",{event=name})
else C.coalesced.eventRows=(C.coalesced.eventRows or 0)+1 end
if casting then
record("spellcast",{event=name,argument1=public(token),argument2=public(second)})
end
if name=="PLAYER_AURAS_CHANGED" or name=="PLAYER_ENTERING_WORLD" or name=="PLAYER_LOGOUT" then auras(name)end
if name=="PLAYER_TARGET_CHANGED" then unit("target")
elseif name=="UPDATE_MOUSEOVER_UNIT" then unit("mouseover")
elseif name=="TAXIMAP_OPENED" then taxi() end
if travelEvents[name] then snapshot(name)end
end)
frame:SetScript("OnUpdate",function(self,modernElapsed)
if not O.active then return end
local elapsed=public(modernElapsed or arg1)
if type(elapsed)~="number" or elapsed<0 then return end
O.elapsed=O.elapsed+elapsed
if O.elapsed>=5 then O.elapsed=0;snapshot("periodic");auras("periodic") end
end)
SlashCmdList=SlashCmdList or {};SLASH_WOWHYBRIDTRAVELCAPTURE1="/whtravel"
SlashCmdList.WOWHYBRIDTRAVELCAPTURE=function(message)
if message=="stop" then record("stopped",{});O.active=false;frame:UnregisterAllEvents() end
if DEFAULT_CHAT_FRAME then DEFAULT_CHAT_FRAME:AddMessage("Travel capture "..(O.active and "active" or "stopped")..
" nonce="..nonce.." cache="..tostring(bindCache()).." rows="..tostring(table.getn(C.rows)).." dropped="..tostring(C.dropped).."; reload/logout saves.") end
end
C.latestNonce=nonce
C.capabilities={}
for _,name in ipairs({"UnitGUID","IsMounted","UnitOnTaxi","GetPlayerMapPosition","GetCurrentMapAreaID","GetUnitSpeed","GetPlayerBuff","GetPlayerBuffTexture","GetPlayerBuffTimeLeft","GetPlayerBuffApplications"})do
C.capabilities[name]=type(getglobal(name))=="function"
end
record("observer-ready",{revision="octo-travel-v3",load=C.loads,cacheBound=bindCache()});snapshot("observer-ready");auras("observer-ready")
SlashCmdList.WOWHYBRIDTRAVELCAPTURE("")
end
-- Can load as a separate addon or an appended, journaled pfUI block.
local bootstrap=CreateFrame("Frame");bootstrap:RegisterEvent("PLAYER_LOGIN")
bootstrap:SetScript("OnEvent",function(self,name)
if (name or event)=="PLAYER_LOGIN" then bootstrap:UnregisterAllEvents();initialize() end
end)