Files

632 lines
32 KiB
Lua

-- pfQuest on the OctoWoW Forever (70334) client.
-- pfQuest and pfQuest-turtle are 1.12 add-ons. Every file of both runs inside pfQuestEnv (the port's build adds
-- `setfenv(1, pfQuestEnv)` to the first line of each file), where:
-- * global writes stay private (no Blizzard global is ever written -> no secret-value taint), except the add-ons'
-- own SavedVariables, SLASH_/BINDING_ names and their named frames;
-- * 1.12 names resolve to the 1.12 behaviour (`this`/`arg1` in script handlers, the 1.12 world-map API on top of
-- C_Map, 1.12 return shapes of quest/item/gossip functions);
-- * pfQuest's replacements of Blizzard functions (QuestLog_Update, SetItemRef, ...) become secure post-hooks.
-- GetBuildInfo reports 11200 here so pfQuest takes its vanilla code paths (the Turtle database is vanilla).
local G = _G
local C = {}
local SAVED = {
pfQuest_questcache = true, pfQuest_global = true, pfQuest_config = true, pfBrowser_fav = true, pfQuest_history = true,
pfQuest_colors = true, pfQuest_server = true, pfQuest_track = true, pfQuest_turtlecount = true,
}
local function errorh(e) G.geterrorhandler()(e) end
------------------------------------------------------------------------------------------------------------------
-- Environment
------------------------------------------------------------------------------------------------------------------
local HOOKS = { -- Blizzard functions pfQuest replaces: become hooksecurefunc post-hooks
QuestLog_Update = true, QuestLogTitleButton_OnClick = true, RemoveQuestWatch = true, AddQuestWatch = true,
SetItemRef = true, AbandonQuest = true,
}
local in_hook, stubs, hooked, impl = {}, {}, {}, {}
-- 70334 has some of them only as C_QuestLog functions taking a questID
local QL = G.C_QuestLog
local HOOK_AT = {AddQuestWatch = "AddQuestWatch", RemoveQuestWatch = "RemoveQuestWatch", AbandonQuest = "AbandonQuest"}
local function to_id(i) return QL and QL.GetQuestIDForLogIndex and i and QL.GetQuestIDForLogIndex(i) end
local function to_index(id) return QL and QL.GetLogIndexForQuestID and id and QL.GetLogIndexForQuestID(id) end
impl.AddQuestWatch = function(i) local id = to_id(i) if id then return QL.AddQuestWatch(id) end end
impl.RemoveQuestWatch = function(i) local id = to_id(i) if id then return QL.RemoveQuestWatch(id) end end
impl.AbandonQuest = function() return QL.AbandonQuest() end
local function stub(name)
if not stubs[name] then
stubs[name] = function(...)
if in_hook[name] then return end
local f = G[name] or impl[name]
if f then return f(...) end
end
end
return stubs[name]
end
for name in pairs(HOOKS) do C[name] = stub(name) end
local function install_hook(k, v)
local function after(...)
in_hook[k] = true
C.__run(v, (...), C.event, select(2, ...))
in_hook[k] = nil
end
if G[k] then return pcall(G.hooksecurefunc, k, after) end
if QL and HOOK_AT[k] and QL[HOOK_AT[k]] then
return pcall(G.hooksecurefunc, QL, HOOK_AT[k], function(id, ...)
if k == "AbandonQuest" then return after() end
return after(to_index(id), ...)
end)
end
end
local env
env = setmetatable({}, {
__index = function(_, k) local v = C[k] if v == nil then v = G[k] end return v end,
__newindex = function(t, k, v)
if SAVED[k] or (type(k) == "string" and (k:find("^SLASH_") or k:find("^BINDING_"))) then G[k] = v return end
if HOOKS[k] then
if type(v) == "function" and v ~= stubs[k] and not hooked[v] then hooked[v] = true install_hook(k, v) end
return
end
rawset(t, k, v)
end,
})
pfQuestEnv = env
-- _G / getfenv(0) / getglobal inside pfQuest: private names first, then the real globals; writes follow the env rules
C._G = setmetatable({}, {
__index = function(_, k) local v = rawget(env, k) if v == nil then v = env[k] end return v end,
__newindex = function(_, k, v) env[k] = v end,
})
function C.getfenv(n) if n == 0 or n == nil then return C._G end return G.getfenv(n) end
function C.getglobal(k) return C._G[k] end
function C.setglobal(k, v) C._G[k] = v end
------------------------------------------------------------------------------------------------------------------
-- Lua 5.0 library names
------------------------------------------------------------------------------------------------------------------
local sizes = setmetatable({}, {__mode = "k"})
local function getn(t) local s, n = sizes[t], #t if s and s > n then return s end return n end
local function setn(t, n) if n == 0 or n == #t then sizes[t] = nil else sizes[t] = n end end
C.table = setmetatable({getn = getn, setn = setn}, {__index = G.table})
C.string = setmetatable({gfind = G.string.gmatch}, {__index = G.string})
C.math = setmetatable({mod = G.math.fmod}, {__index = G.math})
C.mod = G.math.fmod
C.gfind = G.string.gmatch
------------------------------------------------------------------------------------------------------------------
-- Script handlers: 1.12 passes this / event / arg1..arg9 as globals
------------------------------------------------------------------------------------------------------------------
-- call f with `this`/`event`/arg1.. set; with_event passes (self, event, ...) like the 2.x/3.x handler signature
local function call(f, self, event, with_event, ...)
local ot, oe = C.this, C.event
local o1, o2, o3, o4, o5, o6, o7, o8, o9 = C.arg1, C.arg2, C.arg3, C.arg4, C.arg5, C.arg6, C.arg7, C.arg8, C.arg9
C.this, C.event = self, event
C.arg1, C.arg2, C.arg3, C.arg4, C.arg5, C.arg6, C.arg7, C.arg8, C.arg9 = ...
local ok, r
if with_event then ok, r = xpcall(f, errorh, self, event, ...) else ok, r = xpcall(f, errorh, self, ...) end
C.this, C.event = ot, oe
C.arg1, C.arg2, C.arg3, C.arg4, C.arg5, C.arg6, C.arg7, C.arg8, C.arg9 = o1, o2, o3, o4, o5, o6, o7, o8, o9
return r
end
local function run(f, self, event, ...) return call(f, self, event, false, ...) end
C.__run = run
-- Gitea #10: the repository zip unpacks as AddOns/pfquest (lower case) or <name>-master, so ADDON_LOADED reports that
-- folder name and pfQuest's `arg1 == "pfQuest"` init (SavedVariables, version) never runs. Report the canonical name.
local CANONICAL = {pfquest = "pfQuest", ["pfquest-turtle"] = "pfQuest-turtle"}
local function addon_name(name)
if type(name) ~= "string" then return name end
local key = string.lower(name):gsub("%-master$", ""):gsub("%-main$", "")
return CANONICAL[key] or name
end
local function wrap(name, f)
if name == "OnEvent" then return function(self, event, ...)
if event == "ADDON_LOADED" then return call(f, self, event, true, addon_name((...)), select(2, ...)) end
call(f, self, event, true, ...)
end end
return function(self, ...) return run(f, self, C.event, ...) end
end
-- Events 70334 does not have; pfQuest frames registering them are raised by the compat layer itself.
local synthetic = {WORLD_MAP_UPDATE = {}, QUEST_QUERY_COMPLETE = {}}
local function fire(event, ...)
for frame in pairs(synthetic[event] or {}) do
local h = frame.__pf_scripts and frame.__pf_scripts.OnEvent
if h then call(h, frame, event, true, ...) end
end
end
C.__fire = fire
local function adopt_texture(t)
if not t or t.__pf then return t end
t.__pf = true
local SetTexture, SetGradient = t.SetTexture, t.SetGradient
function t:SetTexture(a, b, c, d, ...)
if type(a) == "number" and b ~= nil then return self:SetColorTexture(a, tonumber(b) or a, tonumber(c) or a, tonumber(d) or 1) end
return SetTexture(self, a, b, c, d, ...)
end
function t:SetGradientAlpha(o, r1, g1, b1, a1, r2, g2, b2, a2)
return SetGradient(self, o, G.CreateColor(r1, g1, b1, a1), G.CreateColor(r2, g2, b2, a2))
end
function t:SetGradient(o, r1, g1, b1, r2, g2, b2)
if type(r1) == "table" then return SetGradient(self, o, r1, g1) end
return SetGradient(self, o, G.CreateColor(r1, g1, b1, 1), G.CreateColor(r2, g2, b2, 1))
end
return t
end
local function adopt_font(o)
if not o or o.__pf_font or not o.SetFont then return o end
o.__pf_font = true
local SetFont = o.SetFont
function o:SetFont(file, size, flags) return SetFont(self, file, size, flags or "") end
return o
end
-- 1.12 accepted frame-strata names as draw layers
-- (and "NORMAL"); 70334 only takes these five, anything else becomes ARTWORK
local VALID = {BACKGROUND = true, BORDER = true, ARTWORK = true, OVERLAY = true, HIGHLIGHT = true}
local LAYERS = setmetatable({HIGH = "OVERLAY", DIALOG = "OVERLAY", TOOLTIP = "OVERLAY", FULLSCREEN = "OVERLAY",
FULLSCREEN_DIALOG = "OVERLAY"}, {__index = function(_, k) if k ~= nil and not VALID[k] then return "ARTWORK" end end})
local adopt
adopt = function(f)
if type(f) ~= "table" or f.__pf then return f end
f.__pf = true
local kind = f.GetObjectType and f:GetObjectType()
local SetScript, GetScript, HookScript = f.SetScript, f.GetScript, f.HookScript
if SetScript then
function f:SetScript(name, h)
self.__pf_scripts = self.__pf_scripts or {}
self.__pf_scripts[name] = h
if h == nil then return SetScript(self, name, nil) end
if not self:HasScript(name) then return end
return SetScript(self, name, wrap(name, h))
end
function f:GetScript(name)
if self.__pf_scripts and self.__pf_scripts[name] ~= nil then return self.__pf_scripts[name] end
-- a template's (Blizzard) handler: 1.12 code chains it as previous() without self, so bind the frame
local h = GetScript(self, name)
if not h then return nil end
local frame = self
return function(first, ...)
if first == nil and select("#", ...) == 0 then return h(frame) end
return h(first, ...)
end
end
function f:HookScript(name, h)
if not self:HasScript(name) then return end
return HookScript(self, name, wrap(name, h))
end
end
if f.RegisterEvent then
local RegisterEvent, UnregisterEvent, UnregisterAllEvents = f.RegisterEvent, f.UnregisterEvent, f.UnregisterAllEvents
function f:RegisterEvent(e)
if synthetic[e] then synthetic[e][self] = true return end
pcall(RegisterEvent, self, e) -- 1.12-only events are ignored
end
function f:UnregisterEvent(e)
if synthetic[e] then synthetic[e][self] = nil return end
pcall(UnregisterEvent, self, e)
end
function f:UnregisterAllEvents()
for _, l in pairs(synthetic) do l[self] = nil end
return UnregisterAllEvents(self)
end
end
if f.CreateTexture then local CT = f.CreateTexture function f:CreateTexture(n, layer, ...) return adopt_texture(CT(self, n, LAYERS[layer] or layer, ...)) end end
if f.CreateFontString then
local CF = f.CreateFontString
function f:CreateFontString(n, layer, template, ...)
layer = LAYERS[layer] or layer
local ok, fs = pcall(CF, self, n, layer, template, ...)
if not ok then fs = CF(self, n, layer) if template and G[template] then fs:SetFontObject(G[template]) end end
return adopt_font(fs)
end
end
if f.GetFontString then local GF = f.GetFontString function f:GetFontString() return adopt_font(GF(self)) end end
if kind == "EditBox" then adopt_font(f) end
if f.SetMinResize == nil and f.SetResizeBounds then
function f:SetMinResize(w, h) self.__minw, self.__minh = w, h self:SetResizeBounds(w, h, self.__maxw, self.__maxh) end
function f:SetMaxResize(w, h) self.__maxw, self.__maxh = w, h self:SetResizeBounds(self.__minw or 0, self.__minh or 0, w, h) end
end
if f.SetMaxLetters then local SML = f.SetMaxLetters function f:SetMaxLetters(n) return SML(self, n or 0) end end
for _, part in ipairs({"Normal", "Pushed", "Highlight", "Disabled", "Checked", "DisabledChecked"}) do
local set, clear = f["Set" .. part .. "Texture"], f["Clear" .. part .. "Texture"]
if set and clear then
f["Set" .. part .. "Texture"] = function(self, t, ...) if t == nil then return clear(self) end return set(self, t, ...) end
end
end
if f.GetRegions then
for _, r in ipairs({f:GetRegions()}) do
local t = r.GetObjectType and r:GetObjectType()
if t == "Texture" then adopt_texture(r) elseif t == "FontString" then adopt_font(r) end
end
end
return f
end
C.__adopt = adopt
local TEMPLATES = {UIPanelButtonTemplate2 = "UIPanelButtonTemplate", OptionsCheckButtonTemplate = "UICheckButtonTemplate",
UIPanelButtonGrayTemplate = "UIPanelButtonTemplate", OptionsSliderTemplate = "UISliderTemplateWithLabels"}
local BACKDROP = {Frame = true, Button = true, EditBox = true, CheckButton = true, ScrollFrame = true, Slider = true, StatusBar = true}
function C.CreateFrame(kind, name, parent, template, id)
if template then template = TEMPLATES[template] or template end
if BACKDROP[kind] and G.BackdropTemplateMixin and not (template and template:find("BackdropTemplate")) then
template = template and (template .. ",BackdropTemplate") or "BackdropTemplate"
end
if type(parent) == "table" and parent.__pf_real then parent = parent.__pf_real end
-- 1.12 WorldMapButton never zoomed; here it is the zooming canvas. Map controls (dropdowns) created on it go on the
-- fixed map viewport instead, so they stay in the window's corner; pins stay on the canvas.
if parent ~= nil and parent == rawget(C, "__canvas") and template and template:find("DropDown") then
local w = G.WorldMapFrame
parent = w and w.ScrollContainer or parent
end
local f = adopt(G.CreateFrame(kind, name, parent, template, id))
-- a template's child widgets (dropdown .Button, scroll bars, ...) get the same 1.12 behaviour
if template then
local function children(o) for _, c in ipairs({o:GetChildren()}) do if not c.__pf then adopt(c) children(c) end end end
children(f)
end
return f
end
-- Blizzard frames pfQuest scripts (WorldMapFrame): a proxy with the same widget handle; SetScript becomes HookScript so
-- the Blizzard handler and its fields stay untouched.
local proxies = {}
local function proxy(f)
if not f then return nil end
if proxies[f] then return proxies[f] end
local p = setmetatable({[0] = f[0], __pf_real = f}, {__index = function(_, k)
local v = f[k]
if k == "SetScript" or k == "HookScript" then
return function(_, name, h) if h and f:HasScript(name) then f:HookScript(name, wrap(name, h)) end end
end
-- 1.12 code chains the "previous" handler by calling it without self; Blizzard's own handler already runs
-- (we only hook), so the chained call must do nothing
if k == "GetScript" then return function() return function() end end end
if type(v) == "function" then return function(self, ...) return v(self == proxies[f] and f or self, ...) end end
return v
end})
proxies[f] = p
return p
end
------------------------------------------------------------------------------------------------------------------
-- Client identity and small 1.12 API differences
------------------------------------------------------------------------------------------------------------------
function C.GetBuildInfo() local v, b, d = G.GetBuildInfo() return v, b, d, 11200 end
-- 1.12 objective formats (70334's are positional, "%2$d/%3$d %1$s slain"); GetQuestLogLeaderBoard below serves this form
C.QUEST_MONSTERS_KILLED = "%s slain: %d/%d"
C.QUEST_OBJECTS_FOUND = "%s: %d/%d"
function C.MouseIsOver(f) return f and f:IsVisible() and f:IsMouseOver() end
function C.GetNumPartyMembers() return G.GetNumSubgroupMembers and G.GetNumSubgroupMembers() or 0 end
function C.GetMouseFocus() local t = G.GetMouseFoci and G.GetMouseFoci() return t and t[1] end
function C.StaticPopup_EditBoxOnTextChanged() end
function C.WorldMapFrame_ClearQuestPOIs() end
C.ChatFrameEditBox = setmetatable({}, {__index = function(_, k)
local box = G.ChatEdit_ChooseBoxForSend and G.ChatEdit_ChooseBoxForSend() or G.ChatFrame1EditBox
local v = box and box[k]
if k == "Insert" then return function(_, text) G.ChatEdit_ActivateChat(box) box:Insert(text) end end
if k == "Show" then return function() G.ChatEdit_ActivateChat(box) end end
if type(v) == "function" then return function(_, ...) return v(box, ...) end end
return v
end})
local SOUNDS = {igMainMenuOptionCheckBoxOn = "IG_MAINMENU_OPTION_CHECKBOX_ON", igMainMenuOptionCheckBoxOff = "IG_MAINMENU_OPTION_CHECKBOX_OFF",
igMainMenuOption = "IG_MAINMENU_OPTION", igMainMenuClose = "IG_MAINMENU_CLOSE", igMainMenuOpen = "IG_MAINMENU_OPEN",
igQuestLogOpen = "IG_QUEST_LOG_OPEN", igQuestLogClose = "IG_QUEST_LOG_CLOSE", MapPing = "MAP_PING"}
function C.PlaySound(s)
if type(s) == "string" then s = SOUNDS[s] and G.SOUNDKIT and G.SOUNDKIT[SOUNDS[s]] end
if s then G.PlaySound(s) end
end
-- 1.12 GetItemInfo: name, link, quality, minLevel, type, subType, stackCount, equipLoc, texture (no item level)
local GII = (G.C_Item and G.C_Item.GetItemInfo) or G.GetItemInfo
function C.GetItemInfo(item)
if type(item) == "string" then item = tonumber(item:match("item:(%d+)")) or tonumber(item) or item end
if item == nil or item == 0 or item == "" then return nil end
local ok, name, link, quality, _, minLevel, itype, subType, stack, equipLoc, texture = pcall(GII, item)
if not ok then return nil end
return name, link, quality, minLevel, itype, subType, stack, equipLoc, texture
end
function C.GetItemIcon(id) return G.C_Item and G.C_Item.GetItemIconByID(id) end
if G.C_Container then
C.GetContainerItemLink = G.C_Container.GetContainerItemLink
C.GetContainerNumSlots = G.C_Container.GetContainerNumSlots
end
if G.C_AddOns then
C.GetNumAddOns = G.C_AddOns.GetNumAddOns
C.GetAddOnMetadata = G.C_AddOns.GetAddOnMetadata
function C.GetAddOnInfo(i)
local name, title, notes, loadable, reason, security = G.C_AddOns.GetAddOnInfo(i)
return name, title, notes, G.C_AddOns.GetAddOnEnableState and G.C_AddOns.GetAddOnEnableState(i, G.UnitName("player")) > 0, loadable, reason, security
end
end
if G.C_ChatInfo then C.SendAddonMessage = G.C_ChatInfo.SendAddonMessage end
-- quest log: 1.12 shape title, level, tag, isHeader, isCollapsed, isComplete
function C.GetQuestLogTitle(i)
local title, level, _, isHeader, isCollapsed, isComplete = G.GetQuestLogTitle(i)
return title, level, nil, isHeader, isCollapsed, isComplete
end
local abandon_name
local function abandon_title()
if G.GetAbandonQuestName then return G.GetAbandonQuestName() end
local id = QL and QL.GetAbandonQuest and QL.GetAbandonQuest()
return id and QL.GetTitleForQuestID and QL.GetTitleForQuestID(id)
end
if QL and QL.SetAbandonQuest then pcall(G.hooksecurefunc, QL, "SetAbandonQuest", function() abandon_name = abandon_title() end) end
if G.SetAbandonQuest then pcall(G.hooksecurefunc, "SetAbandonQuest", function() abandon_name = abandon_title() end) end
function C.GetAbandonQuestName() if in_hook.AbandonQuest then return abandon_name end return abandon_title() end
-- gossip quests: 1.12 flat lists (title, level, isLowLevel, ...); selection by list position
local GI = G.C_GossipInfo
if GI then
local function flat(list)
local out = {}
for _, q in ipairs(list or {}) do out[#out + 1] = q.title out[#out + 1] = q.questLevel out[#out + 1] = q.isTrivial and true or false end
return G.unpack(out)
end
function C.GetGossipAvailableQuests() return flat(GI.GetAvailableQuests()) end
function C.GetGossipActiveQuests() return flat(GI.GetActiveQuests()) end
function C.SelectGossipAvailableQuest(i) local q = (GI.GetAvailableQuests() or {})[i] if q then GI.SelectAvailableQuest(q.questID) end end
function C.SelectGossipActiveQuest(i) local q = (GI.GetActiveQuests() or {})[i] if q then GI.SelectActiveQuest(q.questID) end end
end
-- StaticPopupDialogs: pfQuest's dialog handlers read `this`
C.StaticPopupDialogs = setmetatable({}, {
__index = function(_, k) return G.StaticPopupDialogs[k] end,
__newindex = function(_, k, v)
if type(v) == "table" then
for fk, fv in pairs(v) do
if type(fv) == "function" then v[fk] = function(self, ...) return run(fv, self, C.event, ...) end end
end
end
G.StaticPopupDialogs[k] = v
end,
})
-- UIDropDownMenu: initialize functions read `this`/arg1
function C.UIDropDownMenu_Initialize(frame, init, ...)
if type(frame) == "table" and frame.__pf_real then frame = frame.__pf_real end
return G.UIDropDownMenu_Initialize(frame, function(self, level, menuList) run(init, self, C.event, level, menuList) end, ...)
end
function C.UIDropDownMenu_AddButton(info, level)
if info and type(info.func) == "function" and not info.__pf then
local f = info.func
info.__pf = true
info.func = function(button, a1, a2, checked) run(f, button, C.event, a1, a2, checked) end
end
return G.UIDropDownMenu_AddButton(info, level)
end
-- 1.12 argument order (width, frame) for the size helpers
function C.UIDropDownMenu_SetWidth(a, b, ...) if type(a) == "number" then return G.UIDropDownMenu_SetWidth(b, a, ...) end return G.UIDropDownMenu_SetWidth(a, b, ...) end
function C.UIDropDownMenu_SetButtonWidth(a, b) if type(a) == "number" then return G.UIDropDownMenu_SetButtonWidth(b, a) end return G.UIDropDownMenu_SetButtonWidth(a, b) end
function C.UIDropDownMenu_SetText(a, b) if type(a) == "string" then return G.UIDropDownMenu_SetText(b, a) end return G.UIDropDownMenu_SetText(a, b) end
function C.UIDropDownMenu_JustifyText(a, b) if type(a) == "string" then return G.UIDropDownMenu_JustifyText(b, a) end return G.UIDropDownMenu_JustifyText(a, b) end
------------------------------------------------------------------------------------------------------------------
-- Quest log, questgiver and skill APIs: 1.12 calls on C_QuestLog / C_SkillInfo where the client has no global
------------------------------------------------------------------------------------------------------------------
local function fill(name, f) if G[name] == nil and C[name] == nil then C[name] = f end end
local selected -- 1.12 quest log selection (log index)
if QL then
fill("GetNumQuestLogEntries", function() return QL.GetNumQuestLogEntries() end)
fill("GetQuestLogSelection", function()
local id = QL.GetSelectedQuest and QL.GetSelectedQuest()
return (id and id > 0 and to_index(id)) or selected or 0
end)
fill("SelectQuestLogEntry", function(i) selected = i local id = to_id(i) if id and QL.SetSelectedQuest then QL.SetSelectedQuest(id) end end)
local function objectives(i)
local id = to_id(i or C.GetQuestLogSelection())
return id and QL.GetQuestObjectives(id) or {}
end
fill("GetNumQuestLeaderBoards", function(i) return #objectives(i) end)
-- objective text in the 1.12 form pfQuest parses ("<name> slain: x/y", "<name>: x/y"), numbers from C_QuestLog
local function name_of(text)
text = text:gsub("%d+%s*/%s*%d+", ""):gsub("^[%s:]+", ""):gsub("[%s:]+$", ""):gsub("%s+slain$", "")
return text
end
function C.GetQuestLogLeaderBoard(j, i)
local o = objectives(i)[j]
local text, otype, done
if o then text, otype, done = o.text, o.type, o.finished
elseif G.GetQuestLogLeaderBoard then text, otype, done = G.GetQuestLogLeaderBoard(j, i) end
if not text then return nil end
local have, need = o and o.numFulfilled, o and o.numRequired
if not need then have, need = text:match("(%d+)%s*/%s*(%d+)") end
if need and tonumber(need) and (otype == "monster" or otype == "item" or otype == "object") then
local name = name_of(text)
if otype == "monster" then text = ("%s slain: %d/%d"):format(name, have, need)
else text = ("%s: %d/%d"):format(name, have, need) end
end
return text, otype, done
end
fill("IsQuestWatched", function(i) local id = to_id(i) return id and QL.GetQuestWatchType(id) ~= nil or nil end)
fill("GetNumQuestWatches", function() return QL.GetNumQuestWatches and QL.GetNumQuestWatches() or 0 end)
fill("GetQuestLogQuestText", function(i)
local id = to_id(i or C.GetQuestLogSelection())
if G.GetQuestLogQuestText and id then return G.GetQuestLogQuestText(to_index(id)) end
return "", ""
end)
-- Always the 1.12 log-index form inside pfQuestEnv: a native GetQuestLink takes a questID, so the log index would
-- name another quest, the ID/title check in GetQuestIDs fails and pfQuest falls back to its title search
-- (OCTO freeze 2026-11-27). Blizzard's own GetQuestLink is untouched (C is pfQuest's environment only).
C.GetQuestLink = function(i)
local info = QL.GetInfo(i)
if not info or info.isHeader or not info.questID then return end
return ("|cffffff00|Hquest:%d:%d|h[%s]|h|r"):format(info.questID, info.level or 0, info.title or "")
end
end
-- the 1.12 shape is always served (title, level, tag, isHeader, isCollapsed, isComplete)
function C.GetQuestLogTitle(i)
if QL and QL.GetInfo then
local info = QL.GetInfo(i)
if not info then return nil end
local complete
if not info.isHeader and info.questID then
if QL.IsFailed and QL.IsFailed(info.questID) then complete = -1 elseif QL.IsComplete(info.questID) then complete = 1 end
end
return info.title, info.level, nil, info.isHeader, info.isCollapsed, complete
end
local title, level, _, isHeader, isCollapsed, isComplete = G.GetQuestLogTitle(i)
return title, level, nil, isHeader, isCollapsed, isComplete
end
local SI = G.C_SkillInfo
if SI then
fill("GetNumSkillLines", function() return SI.GetNumSkillLines() end)
fill("GetSkillLineInfo", function(i)
local s = i and i > 0 and SI.GetSkillLineInfo(i)
if not s then return nil end
return s.name, s.isHeader, not s.isCollapsed, s.rank, s.tempPoints, s.modifier, s.maxRank
end)
end
fill("TEXT", function(s) return s end)
fill("GetInventoryItemLink", function(unit, slot) return G.GetInventoryItemLink and G.GetInventoryItemLink(unit, slot) end)
-- Turtle server replies pfQuest waits for (".queststatus" -> TWQUEST addon messages with the completed quest ids):
-- 70334 only delivers registered prefixes
if G.C_ChatInfo and G.C_ChatInfo.RegisterAddonMessagePrefix then G.C_ChatInfo.RegisterAddonMessagePrefix("TWQUEST") end
-- pfQuest sends server commands on GUILD chat; 70334 refuses guild chat outside a guild, the server reads commands on SAY
function C.SendChatMessage(msg, chatType, ...)
if type(msg) == "string" and msg:sub(1, 1) == "." and chatType == "GUILD" then chatType = "SAY" end
return G.SendChatMessage(msg, chatType, ...)
end
-- 1.12 UnitName returns only the name (pfQuest passes it straight into gsub)
function C.UnitName(u) return (G.UnitName(u)) end
-- the 1.12 quest log window does not exist here (quests are in the map's quest panel): pfQuest's quest-log
-- decorations (language/database buttons, levels in titles) get hidden stand-ins and stay off
local function standin(kind) local f = G.CreateFrame(kind) f:Hide() f.UpdateScrollChildRect = function() end return f end
for n, kind in pairs({QuestLogFrame = "Frame", QuestLogFrameCloseButton = "Button", QuestLogListScrollFrame = "ScrollFrame",
QuestLogDetailScrollFrame = "ScrollFrame"}) do
if G[n] == nil then C[n] = standin(kind) end
end
if G.QUESTS_DISPLAYED == nil then C.QUESTS_DISPLAYED = 0 end
-- pfQuest hides the old quest-watch frame to replace it; give it its own hidden frame so Blizzard's tracker stays untouched
C.QuestWatchFrame = G.CreateFrame("Frame") C.QuestWatchFrame:Hide()
C.WatchFrame = C.QuestWatchFrame
-- names pfQuest reads that this client does not have: reported once per session to the error log (diagnostics)
local CHECK = {"GetNumQuestLogEntries", "GetQuestLogTitle", "GetQuestLogSelection", "SelectQuestLogEntry", "GetNumQuestLeaderBoards",
"GetQuestLogLeaderBoard", "IsQuestWatched", "GetQuestLink", "GetQuestLogQuestText", "GetNumAvailableQuests", "GetAvailableTitle",
"GetAvailableQuestInfo", "SelectAvailableQuest", "GetNumActiveQuests", "GetActiveTitle", "SelectActiveQuest", "AcceptQuest",
"CompleteQuest", "GetQuestReward", "GetNumQuestChoices", "IsQuestCompletable", "GetTitleText", "CollapseQuestHeader",
"GetNumSkillLines", "GetSkillLineInfo", "GetInventoryItemLink", "QuestLog_Update", "QuestLogTitleButton_OnClick", "SetItemRef",
"AddQuestWatch", "RemoveQuestWatch", "AbandonQuest", "QuestLogFrame", "QuestLogListScrollFrame", "QuestLogDetailScrollFrame",
"QuestFrameRewardPanel", "QuestFrameCompleteButton", "ItemRefTooltip", "GetQuestDifficultyColor", "QUESTS_DISPLAYED"}
local probe = G.CreateFrame("Frame")
probe:RegisterEvent("PLAYER_ENTERING_WORLD")
probe:SetScript("OnEvent", function(self)
self:UnregisterAllEvents()
local miss = {}
for _, n in ipairs(CHECK) do if G[n] == nil and C[n] == nil then miss[#miss + 1] = n end end
if #miss > 0 then G.geterrorhandler()("pfQuest 70334 port: client lacks " .. table.concat(miss, " ")) end
end)
------------------------------------------------------------------------------------------------------------------
-- 1.12 world map API on C_Map
------------------------------------------------------------------------------------------------------------------
local M = G.C_Map
local CONTINENTS = {1414, 1415} -- Kalimdor, Eastern Kingdoms (1.12 order)
local zones = {} -- continent index -> sorted zone UiMapIDs
local vmap -- the map the 1.12 API currently "shows"
local function zone_list(c)
if zones[c] then return zones[c] end
local list = {}
for _, info in ipairs(M.GetMapChildrenInfo(CONTINENTS[c], G.Enum.UIMapType.Zone, false) or {}) do list[#list + 1] = info end
table.sort(list, function(a, b) return a.name < b.name end)
local ids = {}
for i, info in ipairs(list) do ids[i] = info.mapID end
zones[c] = ids
return ids
end
local function locate(mapID) -- continent index, zone index of a UiMap
local id = mapID
while id and id > 0 do
local info = M.GetMapInfo(id)
if not info then break end
for c, cid in ipairs(CONTINENTS) do
if id == cid then
if mapID == cid then return c, 0 end
for z, zid in ipairs(zone_list(c)) do if zid == mapID then return c, z end end
return c, 0
end
end
id = info.parentMapID
end
return 0, 0
end
local function current()
local w = G.WorldMapFrame
if w and w:IsShown() then vmap = w:GetMapID() or vmap end
return vmap or M.GetBestMapForUnit("player")
end
C.__current_map = current
function C.GetMapContinents()
local names = {}
for i, id in ipairs(CONTINENTS) do local info = M.GetMapInfo(id) names[i] = info and info.name or "" end
return G.unpack(names)
end
function C.GetMapZones(c)
local names = {}
for i, id in ipairs(zone_list(c) or {}) do local info = M.GetMapInfo(id) names[i] = info and info.name or "" end
return G.unpack(names)
end
function C.GetCurrentMapContinent() local c = locate(current()) return c end
function C.GetCurrentMapZone() local _, z = locate(current()) return z end
local function show(id)
vmap = id
if G.WorldMapFrame and G.WorldMapFrame:IsShown() and id and G.WorldMapFrame:GetMapID() ~= id then G.WorldMapFrame:SetMapID(id) end
fire("WORLD_MAP_UPDATE")
end
function C.SetMapZoom(c, z)
if not c or c <= 0 then return show(947) end
if not z or z == 0 then return show(CONTINENTS[c]) end
return show(zone_list(c)[z] or CONTINENTS[c])
end
function C.SetMapToCurrentZone() return show(M.GetBestMapForUnit("player")) end
function C.GetMapInfo()
local info = M.GetMapInfo(current() or 0)
return info and (info.name:gsub("[%s']", "")) or nil
end
function C.GetPlayerMapPosition(unit)
local id = current()
local pos = id and M.GetPlayerMapPosition(id, unit or "player")
if not pos then return 0, 0 end
return pos:GetXY()
end
function C.GetCorpseMapPosition()
local id = current()
local pos = id and G.C_DeathInfo and G.C_DeathInfo.GetCorpseMapPosition(id)
if not pos then return 0, 0 end
return pos:GetXY()
end
C.WorldMapTooltip = G.GameTooltip
-- WorldMapButton: a pin layer covering the map canvas (canvas coordinates are 0..1 of the shown zone, like 1.12)
local canvas, map_hooked
local function world_map()
if not G.WorldMapFrame and G.C_AddOns and G.C_AddOns.LoadAddOn then pcall(G.C_AddOns.LoadAddOn, "Blizzard_WorldMap") end
local w = G.WorldMapFrame
if w and not map_hooked then
map_hooked = true
-- the map follows the player's navigation: WORLD_MAP_UPDATE for pfQuest when the shown map changes
pcall(G.hooksecurefunc, w, "OnMapChanged", function() vmap = w:GetMapID() fire("WORLD_MAP_UPDATE") end)
w:HookScript("OnShow", function() vmap = w:GetMapID() fire("WORLD_MAP_UPDATE") end)
end
return w
end
local function map_canvas()
if canvas then return canvas end
local w = world_map()
local child = w and w.ScrollContainer and w.ScrollContainer.Child
if not child then return nil end
canvas = adopt(G.CreateFrame("Frame", "pfQuestWorldMapCanvas", child))
canvas:SetAllPoints(child)
canvas:SetFrameLevel(child:GetFrameLevel() + 2000)
rawset(C, "__canvas", canvas)
return canvas
end
-- WorldMapDetailFrame: the same pin layer (pfQuest-turtle rescales it; it is our own frame)
setmetatable(C, {__index = function(_, k)
if k == "WorldMapButton" or k == "WorldMapDetailFrame" then return map_canvas() end
if k == "WorldMapFrame" then local w = world_map() return w and proxy(w) end
end})