Initial addons

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-10 13:02:16 +00:00
commit de17b0006e
17 changed files with 3257 additions and 0 deletions

View file

@ -0,0 +1,232 @@
-- Merges QuestieDB's Forever quest data into plain rows, without running its
-- generator. Each downloaded file runs in an empty environment: no io, os,
-- require, dofile or loadstring.
-- usage: lua extract.lua <qdb dir> <questie dir> <output file>
local qdb, questie, outPath = arg[1], arg[2], arg[3]
local function proxy(name)
local mt = {}
mt.__index = function(t, k)
local child = proxy(name .. "." .. tostring(k))
rawset(t, k, child)
return child
end
mt.__call = function() return proxy(name .. "()") end
mt.__add = function(a) return a end
mt.__sub = mt.__add
mt.__mul = mt.__add
mt.__unm = mt.__add
return setmetatable({}, mt)
end
local function sandbox(extra)
local env = {
pairs = pairs, ipairs = ipairs, type = type, tostring = tostring, tonumber = tonumber,
select = select, unpack = unpack, next = next, assert = assert, error = error,
rawget = rawget, rawset = rawset, setmetatable = setmetatable, getmetatable = getmetatable,
math = math, string = { format = string.format, find = string.find, match = string.match,
gsub = string.gsub, sub = string.sub, lower = string.lower, upper = string.upper,
byte = string.byte, char = string.char, rep = string.rep, len = string.len, gmatch = string.gmatch },
table = table,
}
for k, v in pairs(extra or {}) do env[k] = v end
return env
end
local function read(path)
local f = assert(io.open(path, "rb"), path)
local s = f:read("*a")
f:close()
assert(s:sub(1, 1) ~= "\27", "bytecode refused: " .. path)
return s
end
local function run(path, env, ...)
local chunk = assert(loadstring(read(path), "@" .. path))
setfenv(chunk, env)
return chunk(...)
end
-- Enums, read from QuestieDB's own definition files.
local Lib = { Enum = {} }
local function enumFile(name) run(qdb .. "/src/corrections/enum/" .. name .. ".lua", sandbox(), "QuestieDB", Lib) end
for _, name in ipairs({ "constants", "quests", "zones", "professions", "factions", "expansions" }) do
local ok, err = pcall(enumFile, name)
if not ok then io.stderr:write("enum ", name, ": ", tostring(err), "\n") end
end
local forever = assert(Lib.Enum.byExpansion and Lib.Enum.byExpansion.Forever, "no Forever enum")
forever.classKeys = forever.classKeys or assert(Lib.Enum.byExpansion.Classic.classKeys)
-- Raw rows and field indexes.
local modules = {}
local function module(name)
if not modules[name] then
modules[name] = proxy(name)
end
return modules[name]
end
local loader = {
CreateModule = function(_, name) rawset(modules, name, {}) return modules[name] end,
ImportModule = function(_, name) return module(name) end,
}
local rawQuestDB = {}
modules.QuestieDB = rawQuestDB
run(qdb .. "/data/Forever/foreverQuestDB.lua", sandbox({ QuestieLoader = loader }))
local realKeys = assert(rawQuestDB.questKeys)
local dataText = assert(rawQuestDB.questData)
assert(dataText:sub(1, 6) == "return")
local dataChunk = assert(loadstring(dataText, "=questData"))
setfenv(dataChunk, {})
local quests = dataChunk()
local ADD, REMOVE = 1000, 2000
local keyProxy = setmetatable({}, { __index = function(_, k)
local base, op = k:match("^(.-)_(add)$")
if not base then base, op = k:match("^(.-)_(remove)$") end
if base then
return assert(realKeys[base], k) + (op == "add" and ADD or REMOVE)
end
return assert(realKeys[k], k)
end })
modules = {
QuestieDB = { questKeys = keyProxy, raceKeys = forever.raceKeys, classKeys = forever.classKeys,
sortKeys = Lib.Enum.sortKeys, specialFlags = Lib.Enum.specialFlags, factionIDs = Lib.Enum.factionIDs },
ZoneDB = { zoneIDs = Lib.Enum.zoneIDs },
QuestieProfessions = { professionKeys = Lib.Enum.professionKeys or proxy("prof"),
specializationKeys = Lib.Enum.specializationKeys or proxy("spec") },
}
for k, v in pairs(modules) do
setmetatable(v, { __index = function(t, key) local p = proxy(k .. "." .. key); rawset(t, key, p); return p end })
end
local WANT = { "name", "questLevel", "requiredRaces", "requiredClasses", "preQuestGroup", "preQuestSingle",
"zoneOrSort", "nextQuestInChain", "breadcrumbForQuestId", "breadcrumbs", "objectives", "specialFlags" }
local wanted = {}
for _, n in ipairs(WANT) do wanted[realKeys[n]] = true end
local function contains(list, v) for _, x in ipairs(list) do if x == v then return true end end return false end
local changed = {}
local function apply(id, fixes)
local row = quests[id]
if not row then row = {}; quests[id] = row end
local removes, sets, adds = {}, {}, {}
for k, v in pairs(fixes) do
if k > REMOVE then removes[k - REMOVE] = v
elseif k > ADD then adds[k - ADD] = v
else sets[k] = v end
end
for k, v in pairs(removes) do
if wanted[k] and type(row[k]) == "table" and type(v) == "table" then
local kept = {}
for _, x in ipairs(row[k]) do if not contains(v, x) then kept[#kept + 1] = x end end
row[k] = kept
end
end
for k, v in pairs(sets) do row[k] = v end
for k, v in pairs(adds) do
if wanted[k] and type(v) == "table" then
row[k] = type(row[k]) == "table" and row[k] or {}
for _, x in ipairs(v) do if not contains(row[k], x) then table.insert(row[k], x) end end
end
end
end
local LAYERS = {
{ "Forever/legacy/classicQuestFixes.lua", "QuestieQuestFixes" },
{ "Forever/generated/foreverBaseQuest.lua", "ForeverBaseQuest" },
{ "Forever/traces/foreverQuestTraces.lua", "ForeverQuestTraces" },
{ "Forever/foreverQuestFixes.lua", "ForeverQuestFixes" },
}
local layerLoader = {
CreateModule = function(_, name) local m = {}; rawset(modules, name, m); return m end,
ImportModule = function(_, name) return modules[name] or proxy(name) end,
}
local stubs = { QuestieLoader = layerLoader, UnitFactionGroup = function() return "Alliance" end,
Questie = proxy("Questie") }
for _, layer in ipairs(LAYERS) do
run(qdb .. "/src/corrections/" .. layer[1], sandbox(stubs))
local fixes = modules[layer[2]]:Load()
local n = 0
for id, row in pairs(fixes) do apply(id, row); n = n + 1 end
io.stderr:write(layer[2], ": ", n, " rows\n")
end
-- Quest tags. Questie treats Forever as Era content here.
local tags = {}
do
local private = {}
local Expansions = { Era = 1, Tbc = 2, Wotlk = 3, Cata = 4, MoP = 5, Current = 1 }
local tagLoader = { ImportModule = function(_, name)
if name == "QuestieDB" then return { private = private } end
if name == "Expansions" then return Expansions end
if name == "l10n" then return function(s) return s end end
return proxy(name)
end }
run(questie .. "/Database/Corrections/questTagInfoCorrections.lua", sandbox({ QuestieLoader = tagLoader, Questie = proxy("Questie") }))
private.InitializeQuestTagInfoCorrections()
for id, tag in pairs(private.questTagCorrections) do
if type(tag) == "table" and tag[1] == 81 then tags[id] = true end
end
end
-- Dungeon list is parsed as text, not run.
local zoneNames, allNames = {}, {}
for line in read(qdb .. "/support/Forever/Zones/dungeons.lua"):gmatch("[^\n]+") do
local id, name, rest = line:match('^%s*%[(%d+)%]%s*=%s*{"([^"]+)",(.*)')
if id then
allNames[#allNames + 1] = name
zoneNames[tonumber(id)] = name
local alts = rest:match("^{([%d,%s]+)}")
if alts then for a in alts:gmatch("%d+") do zoneNames[tonumber(a)] = name end end
end
end
table.sort(allNames)
local q = {}
for id, row in pairs(quests) do
local r = {}
for _, n in ipairs(WANT) do r[n] = row[realKeys[n]] end
q[id] = r
end
local function ser(v)
if type(v) == "table" then
local parts, n = {}, 0
for k in pairs(v) do if type(k) == "number" and k > n then n = k end end
for i = 1, n do parts[i] = ser(v[i]) end
return "{" .. table.concat(parts, ",") .. "}"
elseif type(v) == "string" then return string.format("%q", v)
elseif v == nil then return "nil"
else return tostring(v) end
end
local out = assert(io.open(outPath, "w"))
out:write("return {quests={\n")
local ids = {}
for id in pairs(q) do ids[#ids + 1] = id end
table.sort(ids)
for _, id in ipairs(ids) do
local r = q[id]
out:write("[", id, "]={")
for _, n in ipairs(WANT) do
if r[n] ~= nil and n ~= "objectives" then out:write(n, "=", ser(r[n]), ",") end
end
out:write("},\n")
end
out:write("},\ntags={")
for id in pairs(tags) do out:write("[", id, "]=true,") end
out:write("},\nzoneNames={")
for id, name in pairs(zoneNames) do out:write("[", id, "]=", string.format("%q", name), ",") end
out:write("},\nallDungeons=", ser(allNames), ",\n")
out:write("ALL_ALLIANCE=", string.format("%.0f", forever.raceKeys.ALL_ALLIANCE), ",ALL_HORDE=", string.format("%.0f", forever.raceKeys.ALL_HORDE), ",\n")
out:write("classKeys=", "{")
for k, v in pairs(forever.classKeys) do out:write(k, "=", string.format("%.0f", v), ",") end
out:write("}}\n")
out:close()
io.stderr:write("quests: ", #ids, ", dungeon tags: ")
local c = 0; for _ in pairs(tags) do c = c + 1 end
io.stderr:write(c, "\n")

View file

@ -0,0 +1,157 @@
-- Turns merged.lua into the addon's Data.lua.
-- usage: lua generate.lua merged.lua Data.lua
local data = dofile(arg[1])
local q = data.quests
local FIVE_MAN = {}
for _, n in ipairs({ "Ragefire Chasm", "The Deadmines", "Wailing Caverns", "Shadowfang Keep", "Blackfathom Deeps",
"The Stockade", "Gnomeregan", "Razorfen Kraul", "Scarlet Monastery", "Razorfen Downs", "Uldaman", "Zul'Farrak",
"Maraudon", "The Temple of Atal'Hakkar", "Blackrock Depths", "Blackrock Spire", "Dire Maul", "Scholomance",
"Stratholme" }) do FIVE_MAN[n] = true end
local UNNAMED = ""
local dungeon = {}
for id, r in pairs(q) do
local name = r.zoneOrSort and data.zoneNames[r.zoneOrSort]
if name and FIVE_MAN[name] then
dungeon[id] = name
elseif data.tags[id] and not name then
dungeon[id] = UNNAMED
end
end
local function intersects(a, b)
for i = 0, 52 do
local bit = 2 ^ i
if math.floor(a / bit) % 2 == 1 and math.floor(b / bit) % 2 == 1 then return true end
end
return false
end
local nexts = {}
local function edge(a, b)
if a and b and a ~= 0 and b ~= 0 and a ~= b and q[a] and q[b] then
nexts[a] = nexts[a] or {}
nexts[a][b] = true
end
end
for id, r in pairs(q) do
for _, a in ipairs(r.preQuestSingle or {}) do edge(a, id) end
for _, a in ipairs(r.preQuestGroup or {}) do edge(a, id) end
edge(id, r.nextQuestInChain)
edge(id, r.breadcrumbForQuestId)
for _, a in ipairs(r.breadcrumbs or {}) do edge(a, id) end
end
local FACTIONS = { { bit = 1, mask = data.ALL_ALLIANCE }, { bit = 2, mask = data.ALL_HORDE } }
local CLASSES = { "WARRIOR", "PALADIN", "HUNTER", "ROGUE", "PRIEST", "SHAMAN", "MAGE", "WARLOCK", "DRUID" }
local ALL_CLASSES = 0
for _, c in ipairs(CLASSES) do ALL_CLASSES = ALL_CLASSES + data.classKeys[c] end
local function available(r, factionMask, classBit)
local races, classes = r.requiredRaces or 0, r.requiredClasses or 0
if races ~= 0 and not intersects(races, factionMask) then return false end
if classes ~= 0 and not intersects(classes, classBit) then return false end
return true
end
-- result[quest][dungeon][factionBit] = class mask
local result = {}
for _, faction in ipairs(FACTIONS) do
for _, class in ipairs(CLASSES) do
local classBit = data.classKeys[class]
local function walk(id, seen, found)
for b in pairs(nexts[id] or {}) do
if not seen[b] and available(q[b], faction.mask, classBit) then
seen[b] = true
if dungeon[b] then found[dungeon[b]] = true end
walk(b, seen, found)
end
end
end
for id, r in pairs(q) do
if available(r, faction.mask, classBit) then
local found = {}
walk(id, { [id] = true }, found)
found[dungeon[id] or false] = nil
for name in pairs(found) do
result[id] = result[id] or {}
result[id][name] = result[id][name] or {}
result[id][name][faction.bit] = (result[id][name][faction.bit] or 0) + classBit
end
end
end
end
end
local names, nameIndex = {}, {}
for _, n in ipairs(data.allDungeons) do
if FIVE_MAN[n] and not nameIndex[n] then
names[#names + 1] = n
nameIndex[n] = #names
end
end
nameIndex[UNNAMED] = 0
local ids = {}
for id in pairs(result) do ids[#ids + 1] = id end
table.sort(ids)
local out = assert(io.open(arg[2], "w"))
out:write("-- Generated from QuestieDB's Forever quest data. Do not edit.\n")
out:write("-- quests[id] = { dungeon, faction, classes, ... }; faction 1 Alliance, 2 Horde, 3 both; classes 0 = all; dungeon 0 = unnamed.\n")
out:write("local _, ns = ...\n\nns.dungeons = {\n")
for _, n in ipairs(names) do out:write(string.format(" %q,\n", n)) end
out:write("}\n\nns.quests = {\n")
for _, id in ipairs(ids) do
local parts = {}
local dungeonsHere = {}
for name in pairs(result[id]) do dungeonsHere[#dungeonsHere + 1] = name end
table.sort(dungeonsHere)
for _, name in ipairs(dungeonsHere) do
local byFaction = result[id][name]
local a, h = byFaction[1], byFaction[2]
local function emit(faction, mask)
parts[#parts + 1] = nameIndex[name] .. "," .. faction .. "," .. (mask == ALL_CLASSES and 0 or mask)
end
if a and a == h then
emit(3, a)
else
if a then emit(1, a) end
if h then emit(2, h) end
end
end
out:write(" [", id, "]={", table.concat(parts, ","), "},\n")
end
out:write("}\n")
out:close()
local function summary(faction, classBit, label)
local n, named = 0, 0
for id, row in pairs(result) do
local any, anyNamed = false, false
for name, f in pairs(row) do
if f[faction] and intersects(f[faction], classBit) then
any = true
if name ~= UNNAMED then anyNamed = true end
end
end
if any then n = n + 1 end
if anyNamed then named = named + 1 end
end
print(label, "pre-quests", n, "with a named dungeon", named)
end
print("rows", #ids)
summary(1, data.classKeys.SHAMAN, "Alliance shaman")
summary(1, data.classKeys.WARRIOR, "Alliance warrior")
summary(2, data.classKeys.WARRIOR, "Horde warrior")
local function show(id)
local r = result[id]
local list = {}
for name, f in pairs(r or {}) do
list[#list + 1] = (name == UNNAMED and "(unnamed)" or name) .. " A:" .. tostring(f[1]) .. " H:" .. tostring(f[2])
end
print(id, q[id] and q[id].name, table.concat(list, " | "))
end
for _, id in ipairs({ 65, 155, 166, 8928, 8916, 94501 }) do show(id) end