194 lines
12 KiB
Lua
194 lines
12 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Bounded, persistent local session evidence. Never sends gameplay/chat actions.
|
|
local O={maxRows=8192,maxBytes=8388608,hooks={},unsupportedEvents={}}
|
|
WoWHybridNativeSessionObserver=O
|
|
local capture
|
|
local function stopLogs()
|
|
if O.ownsChatLog and type(LoggingChat)=="function"then pcall(LoggingChat,false);O.ownsChatLog=false;if capture then capture.ownsChatLog=false end end
|
|
if O.ownsCombatLog and type(LoggingCombat)=="function"then pcall(LoggingCombat,false);O.ownsCombatLog=false;if capture then capture.ownsCombatLog=false end end
|
|
end
|
|
local function startLogs()
|
|
if type(LoggingChat)=="function"then
|
|
local ok,previous=pcall(LoggingChat);local enabled,value=pcall(LoggingChat,true)
|
|
O.ownsChatLog=capture.ownsChatLog==true or (ok and not previous and enabled);capture.ownsChatLog=O.ownsChatLog;capture.chatLogEnabled=enabled and not not value
|
|
end
|
|
if type(LoggingCombat)=="function"then
|
|
local ok,previous=pcall(LoggingCombat);local enabled,value=pcall(LoggingCombat,true)
|
|
O.ownsCombatLog=capture.ownsCombatLog==true or (ok and not previous and enabled);capture.ownsCombatLog=O.ownsCombatLog;capture.combatLogEnabled=enabled and not not value
|
|
end
|
|
end
|
|
local function scalar(value)
|
|
if issecretvalue and issecretvalue(value) then return "<secret>" end
|
|
local kind=type(value)
|
|
if kind=="string" then return string.sub(value,1,8192)
|
|
elseif kind=="number"or kind=="boolean" then return value end
|
|
return "<"..kind..">"
|
|
end
|
|
local function recordWith(direction,name,mapper,...)
|
|
if not capture or not capture.active then return end
|
|
if GetTime()-O.started>7200 then capture.active=false;stopLogs();return end
|
|
local args={};local bytes=#name
|
|
for index=1,math.min(select("#",...),9)do
|
|
local value=mapper(select(index,...));args[index]=value
|
|
if type(value)=="string"then bytes=bytes+#value end
|
|
end
|
|
if #capture.rows>=O.maxRows or capture.bytes+bytes>O.maxBytes then capture.dropped=capture.dropped+1;return end
|
|
local row={time=GetTime(),direction=direction,name=name,args=args}
|
|
capture.rows[#capture.rows+1]=row
|
|
capture.bytes=capture.bytes+bytes
|
|
return row
|
|
end
|
|
local function record(direction,name,...)return recordWith(direction,name,scalar,...)end
|
|
local function observedScalar(value,limit)
|
|
if type(issecretvalue)~="function"then return {status="secret-guard-unavailable"}end
|
|
local ok,secret=pcall(issecretvalue,value)
|
|
if not ok or type(secret)~="boolean"then return {status="secret-guard-failed"}end
|
|
if secret then return {status="secret"}end
|
|
local kind=type(value)
|
|
if kind=="nil"then return {status="ordinary",kind=kind}end
|
|
if kind=="string"then return {status="ordinary",kind=kind,value=string.sub(value,1,limit)}end
|
|
if kind=="number"or kind=="boolean"then return {status="ordinary",kind=kind,value=value}end
|
|
return {status="unsupported",kind=kind}
|
|
end
|
|
local function chatScalar(value)
|
|
local result=observedScalar(value,8192)
|
|
if result.status=="ordinary"then return result.kind=="nil"and"<nil>"or result.value end
|
|
return "<"..result.status..">"
|
|
end
|
|
function O:Mark(text)record("marker","local",text)end
|
|
function O:Status()return capture end
|
|
local function hook(owner,key,label,chatGroup)
|
|
if type(owner[key])~="function"then O.hooks[label]=false;return end
|
|
local ok=pcall(hooksecurefunc,owner,key,function(...)
|
|
if chatGroup then
|
|
local row=recordWith("api_callback",label,chatScalar,...)
|
|
if row then row.chat_callable_group=chatGroup;row.counts_user_attempts=false end
|
|
else record("api",label,...)end
|
|
end)
|
|
O.hooks[label]=ok
|
|
end
|
|
-- One retained, read-only title namespace observation on the next normal world entry.
|
|
-- The indices are diagnostic inputs, not an asserted row/Mask_ID/API mapping.
|
|
local function observeOriginalTitles()
|
|
if not capture or capture.originalTitleMetadata then return end
|
|
local observation={schema=1,trigger="PLAYER_ENTERING_WORLD",indices={0,1,18,111,112,144,1225},calls={}}
|
|
capture.originalTitleMetadata=observation
|
|
if not capture.active then observation.status="recorder-inactive";return end
|
|
if type(issecretvalue)~="function"then observation.status="secret-guard-unavailable";return end
|
|
local function ordinary(value)
|
|
local ok,secret=pcall(issecretvalue,value)
|
|
if not ok or type(secret)~="boolean"then return {status="secret-guard-failed"}end
|
|
if secret then return {status="secret"}end
|
|
local kind=type(value)
|
|
if kind=="nil"then return {status="ordinary",kind=kind}end
|
|
if kind=="string"then return {status="ordinary",kind=kind,value=string.sub(value,1,1024)}end
|
|
if kind=="number"or kind=="boolean"then return {status="ordinary",kind=kind,value=value}end
|
|
return {status="unsupported",kind=kind}
|
|
end
|
|
local function pack(...)return {n=select("#",...),...}end
|
|
local function read(name,index)
|
|
local row={method=name,index=index};observation.calls[#observation.calls+1]=row
|
|
local getter=_G[name]
|
|
if type(getter)~="function"then row.status="unavailable";return end
|
|
local result
|
|
if index==nil then result=pack(pcall(getter))else result=pack(pcall(getter,index))end
|
|
if not result[1]then row.status="error";return end
|
|
row.status="returned";row.returnCount=result.n-1;row.values={}
|
|
for i=2,math.min(result.n,4)do row.values[i-1]=ordinary(result[i])end
|
|
end
|
|
read("GetNumTitles")
|
|
read("GetCurrentTitle")
|
|
for _,index in ipairs(observation.indices)do read("GetTitleName",index)end
|
|
observation.status="complete"
|
|
end
|
|
-- Fixed local realm getters only: no lookup, network request, setter or UI write.
|
|
local function observeOriginalRealm()
|
|
if not capture then return end
|
|
local previous=capture.originalRealmMetadata
|
|
-- Upgrade a persisted five-getter record once; it cannot answer the
|
|
-- original /w caller's regional-name guard in this collector revision.
|
|
if type(previous)=="table" and previous.collector_revision==2 then return end
|
|
local observation={schema=1,collector_revision=2,trigger="PLAYER_ENTERING_WORLD",observer_login_clock=O.started,calls={}}
|
|
capture.originalRealmMetadata=observation
|
|
if not capture.active then observation.status="recorder-inactive";return end
|
|
local function pack(...)return {n=select("#",...),...}end
|
|
local function read(name,unit,maximumReturns)
|
|
local row={method=name,unit=unit};observation.calls[#observation.calls+1]=row
|
|
local getter=_G[name]
|
|
if type(getter)~="function"then row.status="unavailable";return end
|
|
if type(issecretvalue)~="function"then row.status="secret-guard-unavailable";return end
|
|
local result
|
|
if unit then result=pack(pcall(getter,unit))else result=pack(pcall(getter))end
|
|
if not result[1]then row.status="error";return end
|
|
row.status="returned";row.returnCount=result.n-1;row.values={}
|
|
for i=2,math.min(result.n,maximumReturns+1)do row.values[i-1]=observedScalar(result[i],1024)end
|
|
end
|
|
read("GetRealmName",nil,1)
|
|
read("GetNormalizedRealmName",nil,1)
|
|
read("GetRealmID",nil,1)
|
|
read("GetCurrentRegion",nil,1)
|
|
read("UnitFullName","player",2)
|
|
read("RegionalUniqueNamesEnabled",nil,1)
|
|
observation.status="complete"
|
|
end
|
|
local function initialize()
|
|
GatewayDiagnosticsSaved=GatewayDiagnosticsSaved or {}
|
|
local old=GatewayDiagnosticsSaved.sessionObservation
|
|
if type(old)~="table"or old.schema~=1 or type(old.rows)~="table"then
|
|
old={schema=1,active=true,rows={},bytes=0,dropped=0,session=date("%Y%m%d-%H%M%S")}
|
|
GatewayDiagnosticsSaved.sessionObservation=old
|
|
end
|
|
capture=old;O.started=GetTime()
|
|
-- Secure post-hooks preserve the original calls, arguments and results.
|
|
local chatOwner=type(C_ChatInfo)=="table"and C_ChatInfo or nil
|
|
local globalChat=_G.SendChatMessage
|
|
local modernChat=chatOwner and chatOwner.SendChatMessage
|
|
local shared=type(globalChat)=="function"and type(modernChat)=="function"and globalChat==modernChat
|
|
capture.chatSendHookContract={schema=1,kind="secure-posthook-callback-observations",shared_callable_before_hooks=shared,
|
|
counting_policy="Callbacks and alias groups are evidence, not a user-attempt counter; do not sum alias callback rows as attempts.",
|
|
aliases={SendChatMessage=shared and"chat-send-shared"or"chat-send-global",["C_ChatInfo.SendChatMessage"]=shared and"chat-send-shared"or"chat-send-namespaced"}}
|
|
hook(_G,"SendChatMessage","SendChatMessage",capture.chatSendHookContract.aliases.SendChatMessage)
|
|
if chatOwner then hook(chatOwner,"SendChatMessage","C_ChatInfo.SendChatMessage",capture.chatSendHookContract.aliases["C_ChatInfo.SendChatMessage"])
|
|
else O.hooks["C_ChatInfo.SendChatMessage"]=false end
|
|
for _,key in ipairs({"SendMail","TakeInboxItem","TakeInboxMoney","ReturnInboxItem","DeleteInboxItem","CastSpellByID","CastSpellByName","UseAction","UseInventoryItem","Dismount"})do hook(_G,key,key)end
|
|
local groups={C_Container={"SortBags","SortBank","UseContainerItem","PickupContainerItem","SplitContainerItem"},
|
|
C_MountJournal={"SummonByID"},C_TradeSkillUI={"CraftRecipe"},
|
|
C_FriendList={"AddFriend","RemoveFriend","SendWho","ShowFriends"},C_GuildInfo={"GuildRoster"},C_ChatInfo={"SendAddonMessage"}}
|
|
for name,keys in pairs(groups)do
|
|
local owner=_G[name]
|
|
for _,key in ipairs(keys)do if type(owner)=="table"then hook(owner,key,name.."."..key)else O.hooks[name.."."..key]=false end end
|
|
end
|
|
capture.hooks=O.hooks;capture.unsupportedEvents=O.unsupportedEvents
|
|
if capture.active then startLogs()end
|
|
record("marker","observer-ready",capture.session)
|
|
DEFAULT_CHAT_FRAME:AddMessage("WoW-Hybrid session recording "..(capture.active and"active"or"stopped")..": events/API attempts plus chat/combat logs. /whsession for status; /reload or logout saves.")
|
|
end
|
|
local frame=CreateFrame("Frame")
|
|
local events={"PLAYER_LOGIN","PLAYER_ENTERING_WORLD","BAG_UPDATE_DELAYED","PLAYER_EQUIPMENT_CHANGED",
|
|
"UNIT_SPELLCAST_SENT","UNIT_SPELLCAST_START","UNIT_SPELLCAST_SUCCEEDED","UNIT_SPELLCAST_FAILED","UNIT_SPELLCAST_INTERRUPTED","UNIT_SPELLCAST_STOP",
|
|
"UNIT_AURA","UNIT_FLAGS","CHAT_MSG_LOOT","LOOT_OPENED","LOOT_CLOSED","TRADE_SKILL_UPDATE","TRADE_SKILL_ITEM_CRAFTED_RESULT",
|
|
"MAIL_SHOW","MAIL_CLOSED","MAIL_INBOX_UPDATE","MAIL_SEND_SUCCESS","MAIL_FAILED","MAIL_SUCCESS","CHAT_MSG_MONEY",
|
|
"CHAT_MSG_WHISPER","CHAT_MSG_WHISPER_INFORM","CHAT_MSG_GUILD","CHAT_MSG_OFFICER","CHAT_MSG_SYSTEM","CHAT_MSG_ADDON",
|
|
"GUILD_ROSTER_UPDATE","FRIENDLIST_UPDATE","WHO_LIST_UPDATE","PLAYER_MOUNT_DISPLAY_CHANGED","PLAYER_CONTROL_LOST","PLAYER_CONTROL_GAINED",
|
|
"PLAYER_DEAD","PLAYER_ALIVE","PLAYER_UNGHOST","UI_ERROR_MESSAGE","PLAYER_LOGOUT"}
|
|
for _,event in ipairs(events)do if not pcall(frame.RegisterEvent,frame,event)then O.unsupportedEvents[#O.unsupportedEvents+1]=event end end
|
|
frame:SetScript("OnEvent",function(_,event,...)
|
|
if event=="PLAYER_LOGIN"then initialize()end
|
|
if event=="PLAYER_ENTERING_WORLD"then observeOriginalTitles();observeOriginalRealm()end
|
|
if string.sub(event,1,5)=="UNIT_"then
|
|
local unit=select(1,...)
|
|
if issecretvalue and issecretvalue(unit)then return end
|
|
if unit~="player"and unit~="target"then return end
|
|
end
|
|
record("event",event,...)
|
|
end)
|
|
SLASH_WOWHYBRIDSESSION1="/whsession"
|
|
SlashCmdList.WOWHYBRIDSESSION=function(command)
|
|
if not capture then return end
|
|
if command=="stop"then capture.active=false;stopLogs()
|
|
elseif command=="start"then capture.active=true;O.started=GetTime();startLogs();record("marker","user-start")
|
|
elseif command=="mark"then record("marker","user-marker")end
|
|
DEFAULT_CHAT_FRAME:AddMessage("Session recording "..(capture.active and"active"or"stopped")..": "..#capture.rows.." rows; "..capture.dropped.." dropped. /reload or logout saves.")
|
|
end
|