mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-12 12:57:37 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb9579c398 | ||
|
|
5642644833 | ||
|
|
58e7e1a2c6 | ||
|
|
5339c97b1e | ||
|
|
7406ac5db1 | ||
|
|
1c263152e3 | ||
|
|
ab211962e5 | ||
|
|
33a23c563c | ||
|
|
17304929b5 | ||
|
|
d88f02fc90 | ||
|
|
1c79742cc3 | ||
|
|
d696a16ac4 | ||
|
|
2c1962b207 | ||
|
|
23cdbe196d | ||
|
|
8b6760cd77 | ||
|
|
7c2317aca1 | ||
|
|
b764b14df1 | ||
|
|
fc1bd30bef | ||
|
|
fe29ec050c | ||
|
|
7fafb89d1d | ||
|
|
bcefe3b87f | ||
|
|
9e03f69e9b | ||
|
|
694a7415ab | ||
|
|
23b102c60c | ||
|
|
e165aa6cd4 | ||
|
|
8ed32e6c8e | ||
|
|
26da489773 | ||
|
|
9c73430ddd | ||
|
|
e712af11a5 | ||
|
|
45291cb16b | ||
|
|
9bfbb2e6b0 | ||
|
|
d6bf05c12c | ||
|
|
07a4cbde43 | ||
|
|
017dc5b6f1 | ||
|
|
ddcb6ba9f0 | ||
|
|
17cf323a52 | ||
|
|
a0b7d03c28 | ||
|
|
15cae8a474 | ||
|
|
49865e9b9e | ||
|
|
98d4504b6f | ||
|
|
597530d558 | ||
|
|
2165a8e986 |
@@ -35,5 +35,6 @@ Util\EquipmentManager.lua
|
||||
Util\PlayerUtil.lua
|
||||
Util\SlashCommandsRegistry.lua
|
||||
Util\LinkUtil.lua
|
||||
Util\TradeSkillLink.lua
|
||||
Util\IconDataProvider.lua
|
||||
Util\GameTooltip.lua
|
||||
|
||||
@@ -123,14 +123,6 @@ PLAYER_FACTION_COLORS =
|
||||
[1] = PLAYER_FACTION_COLOR_ALLIANCE,
|
||||
};
|
||||
|
||||
WOW_PROJECT_MAINLINE = 1;
|
||||
WOW_PROJECT_CLASSIC = 2;
|
||||
WOW_PROJECT_BURNING_CRUSADE_CLASSIC = 5;
|
||||
WOW_PROJECT_WRATH_CLASSIC = 11;
|
||||
WOW_PROJECT_CATACLYSM_CLASSIC = 14;
|
||||
WOW_PROJECT_MISTS_CLASSIC = 19;
|
||||
WOW_PROJECT_ID = WOW_PROJECT_CLASSIC;
|
||||
|
||||
--
|
||||
-- Glyph
|
||||
--
|
||||
|
||||
@@ -0,0 +1,699 @@
|
||||
-- Trade-skill *list* links (`|Htrade:...|h`) — backport of the 2.x+ shareable
|
||||
-- profession link. The link is built entirely in the DLL
|
||||
-- (`GetTradeSkillListLink` / `GetCraftListLink`, see src/tradeskill/Link.cpp);
|
||||
-- this file only intercepts clicks on received links and renders the linker's
|
||||
-- recipe list in a scroll frame (the UI half).
|
||||
--
|
||||
-- link: |cffffd000|Htrade:<skillLineID>:<curRank>:<maxRank>:<linkerName>:<base64 bits>|h[Name]|h|r
|
||||
--
|
||||
-- "Which recipes are known" is a bitfield over the skill line's canonical
|
||||
-- recipe list (deterministic per DBC). The viewer lists the recipes the linker
|
||||
-- knows (with an "X of Y" summary of the whole skill line), regardless of what
|
||||
-- the reader can craft themselves.
|
||||
|
||||
-- Frame geometry mirrors the real TradeSkillFrame. Turtle ships an HD
|
||||
-- 768x512 two-column frame (TW-TradeSkill art); stock 1.12.1 only has the
|
||||
-- vanilla 384x512 single-column art, so on that client we fall back to the
|
||||
-- native Blizzard_TradeSkillUI geometry (list on top, detail below) rather
|
||||
-- than stretch the wide art. LO holds every layout value that differs.
|
||||
local TURTLE = (TURTLE_WOW_VERSION ~= nil);
|
||||
local FRAME_W = TURTLE and 768 or 384;
|
||||
local FRAME_H = 512;
|
||||
local NUM_ROWS = TURTLE and 19 or 8;
|
||||
local ROW_HEIGHT = 16;
|
||||
|
||||
local LO = TURTLE and {
|
||||
hit = { 2, 82, 2, 73 },
|
||||
quads = {
|
||||
{ "Interface\\TradeSkillFrame\\TW-TradeSkill-TopLeft", 512, 256, "TOPLEFT" },
|
||||
{ "Interface\\TradeSkillFrame\\TW-TradeSkill-TopRight", 256, 256, "TOPRIGHT" },
|
||||
{ "Interface\\TradeSkillFrame\\TW-TradeSkill-BotLeft2", 512, 256, "BOTTOMLEFT" },
|
||||
{ "Interface\\TradeSkillFrame\\TW-TradeSkill-BotRight2", 256, 256, "BOTTOMRIGHT" },
|
||||
},
|
||||
close = { -77, -8 },
|
||||
bar = { 596, 15, 76, -44 },
|
||||
barBdr = { 604, 22 },
|
||||
summary = { "TOPRIGHT", -110, -70 },
|
||||
drop = { 40, -60 },
|
||||
scroll = { 296, 330, 37, -98 },
|
||||
detail = { 379, -113 },
|
||||
exit = { "CENTER", "BOTTOMRIGHT", -128, 92 },
|
||||
} or {
|
||||
hit = { 0, 34, 0, 75 },
|
||||
quads = {
|
||||
{ "Interface\\ClassTrainerFrame\\UI-ClassTrainer-TopLeft", 256, 256, "TOPLEFT" },
|
||||
{ "Interface\\ClassTrainerFrame\\UI-ClassTrainer-TopRight", 128, 256, "TOPRIGHT" },
|
||||
{ "Interface\\TradeSkillFrame\\UI-TradeSkill-BotLeft", 256, 256, "BOTTOMLEFT" },
|
||||
{ "Interface\\ClassTrainerFrame\\UI-ClassTrainer-BotRight", 128, 256, "BOTTOMRIGHT" },
|
||||
},
|
||||
close = { -29, -8 },
|
||||
bar = { 268, 15, 73, -37 },
|
||||
barBdr = { 278, 22 },
|
||||
summary = { "TOPRIGHT", -40, -58 },
|
||||
drop = { 12, -62 },
|
||||
scroll = { 296, 130, 21, -96 },
|
||||
detail = { 28, -237 },
|
||||
exit = { "CENTER", "TOPLEFT", 305, -422 },
|
||||
};
|
||||
|
||||
local PROFESSION_ICONS = {
|
||||
[171] = "Trade_Alchemy",
|
||||
[164] = "Trade_BlackSmithing",
|
||||
[185] = "INV_Misc_Food_15", -- Cooking
|
||||
[333] = "Trade_Engraving", -- Enchanting
|
||||
[202] = "Trade_Engineering",
|
||||
[129] = "Spell_Holy_SealOfSacrifice", -- First Aid
|
||||
[165] = "INV_Misc_ArmorKit_17", -- Leatherworking
|
||||
[197] = "Trade_Tailoring",
|
||||
[186] = "Trade_Mining",
|
||||
[182] = "Trade_Herbalism",
|
||||
[393] = "INV_Misc_Pelt_Wolf_01", -- Skinning
|
||||
[356] = "Trade_Fishing",
|
||||
};
|
||||
|
||||
if TURTLE then
|
||||
PROFESSION_ICONS[142] = "Trade_Survival"
|
||||
PROFESSION_ICONS[755] = "INV_Misc_Gem_01" -- Jewelcrafting
|
||||
end
|
||||
|
||||
local function ProfessionIcon(skillLineID)
|
||||
local icon = PROFESSION_ICONS[skillLineID];
|
||||
return icon and ("Interface\\Icons\\" .. icon)
|
||||
or "Interface\\Icons\\INV_Misc_QuestionMark";
|
||||
end
|
||||
|
||||
local function DifficultyBand(skill, hi, lo)
|
||||
if not hi or hi <= 0 then
|
||||
return 3;
|
||||
end
|
||||
if not lo or lo == 0 then
|
||||
lo = (hi ~= 25) and (hi - 25) or 0;
|
||||
end
|
||||
local yellow = (hi + lo) / 2;
|
||||
if skill < lo then
|
||||
return 0; -- orange (optimal)
|
||||
elseif skill < yellow then
|
||||
return 1; -- yellow (medium)
|
||||
elseif skill < hi then
|
||||
return 2; -- green (easy)
|
||||
end
|
||||
return 3; -- grey (trivial)
|
||||
end
|
||||
|
||||
local BAND_COLOR = {
|
||||
[0] = DIFFICULT_DIFFICULTY_COLOR, -- orange
|
||||
[1] = FAIR_DIFFICULTY_COLOR, -- yellow
|
||||
[2] = EASY_DIFFICULTY_COLOR, -- green
|
||||
[3] = TRIVIAL_DIFFICULTY_COLOR, -- grey
|
||||
};
|
||||
|
||||
local function CraftableCount(entry)
|
||||
local reagents = entry.reagents;
|
||||
if not reagents or table.getn(reagents) == 0 then
|
||||
return nil;
|
||||
end
|
||||
local best;
|
||||
for i = 1, table.getn(reagents) do
|
||||
local r = reagents[i];
|
||||
local need = r.count or 1;
|
||||
local n = math.floor((C_Item.GetItemCount(r.itemID) or 0) / need);
|
||||
if not best or n < best then
|
||||
best = n;
|
||||
end
|
||||
end
|
||||
return best;
|
||||
end
|
||||
|
||||
local function ParseTradeLink(link)
|
||||
-- Current format, with the linker's name: trade:id:cur:max:Name:bits
|
||||
local _, _, id, cur, max, who, bits =
|
||||
string.find(link, "^trade:(%d+):(%d+):(%d+):([^:]+):([%w%+/]*)$");
|
||||
if not id then
|
||||
-- Legacy format (no name): trade:id:cur:max:bits
|
||||
who = nil;
|
||||
_, _, id, cur, max, bits =
|
||||
string.find(link, "^trade:(%d+):(%d+):(%d+):([%w%+/]*)$");
|
||||
end
|
||||
if not id then
|
||||
return nil;
|
||||
end
|
||||
return tonumber(id), tonumber(cur), tonumber(max), who, bits or "";
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Display frame (built lazily on first use)
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
local frame;
|
||||
local function ResolveSubclasses(list, onLoaded)
|
||||
local present, subs, anyItem = {}, {}, false;
|
||||
for i = 1, table.getn(list) do
|
||||
local r = list[i];
|
||||
if r.createdItem and r.createdItem > 0 then
|
||||
anyItem = true;
|
||||
if not r.subclass then
|
||||
-- GetItemInfoInstant's 3rd return is the localized subclass
|
||||
-- name (or nil when uncached).
|
||||
local _, _, subType = C_Item.GetItemInfoInstant(r.createdItem);
|
||||
if subType and subType ~= "" then
|
||||
r.subclass = subType;
|
||||
elseif onLoaded then
|
||||
-- Not cached — re-derive when the item loads.
|
||||
Item:CreateFromItemID(r.createdItem):ContinueOnItemLoad(onLoaded);
|
||||
end
|
||||
end
|
||||
if r.subclass and not present[r.subclass] then
|
||||
present[r.subclass] = true;
|
||||
table.insert(subs, r.subclass);
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(subs);
|
||||
return subs, anyItem;
|
||||
end
|
||||
|
||||
local SUBCLASS_ALL = {};
|
||||
|
||||
local function SubClassButton_OnClick()
|
||||
local v = this.value;
|
||||
if v == SUBCLASS_ALL then
|
||||
v = nil;
|
||||
end
|
||||
frame.subclassFilter = v;
|
||||
UIDropDownMenu_SetText(v or ALL_SUBCLASSES, frame.dropdown);
|
||||
frame:ApplyFilter();
|
||||
end
|
||||
|
||||
local function SubClassDropDown_Initialize()
|
||||
local info = {};
|
||||
info.text = ALL_SUBCLASSES;
|
||||
info.value = SUBCLASS_ALL;
|
||||
info.checked = (frame.subclassFilter == nil);
|
||||
info.func = SubClassButton_OnClick;
|
||||
UIDropDownMenu_AddButton(info);
|
||||
local subs = frame.subclasses or {};
|
||||
for i = 1, table.getn(subs) do
|
||||
local b = {};
|
||||
b.text = subs[i];
|
||||
b.value = subs[i];
|
||||
b.checked = (frame.subclassFilter == subs[i]);
|
||||
b.func = SubClassButton_OnClick;
|
||||
UIDropDownMenu_AddButton(b);
|
||||
end
|
||||
end
|
||||
|
||||
local function RefreshSubclasses()
|
||||
if not (frame and frame:IsShown() and frame.recipes) then
|
||||
return;
|
||||
end
|
||||
local subs, anyItem = ResolveSubclasses(frame.recipes, RefreshSubclasses);
|
||||
frame.subclasses = subs;
|
||||
if anyItem then
|
||||
UIDropDownMenu_Initialize(frame.dropdown, SubClassDropDown_Initialize);
|
||||
UIDropDownMenu_SetWidth(120, frame.dropdown);
|
||||
UIDropDownMenu_SetText(frame.subclassFilter or ALL_SUBCLASSES, frame.dropdown);
|
||||
frame.dropdown:Show();
|
||||
else
|
||||
frame.dropdown:Hide();
|
||||
end
|
||||
if frame.subclassFilter then
|
||||
frame:ApplyFilter();
|
||||
end
|
||||
end
|
||||
|
||||
local function CreateFrame_TradeSkillLink()
|
||||
local f = CreateFrame("Frame", "ClassicAPITradeSkillLinkFrame", UIParent);
|
||||
f:SetSize(FRAME_W, FRAME_H);
|
||||
f:SetPoint("CENTER", 0, 0);
|
||||
f:SetMovable(true);
|
||||
f:EnableMouse(true);
|
||||
f:SetHitRectInsets(LO.hit[1], LO.hit[2], LO.hit[3], LO.hit[4]);
|
||||
f:RegisterForDrag("LeftButton");
|
||||
f:SetScript("OnDragStart", function() this:StartMoving(); end);
|
||||
f:SetScript("OnDragStop", function() this:StopMovingOrSizing(); end);
|
||||
f:SetFrameStrata("DIALOG");
|
||||
f:Hide();
|
||||
tinsert(UISpecialFrames, f:GetName())
|
||||
|
||||
local portrait = f:CreateTexture(nil, "BACKGROUND");
|
||||
portrait:SetSize(60, 60);
|
||||
portrait:SetPoint("TOPLEFT", 7, -6);
|
||||
f.portrait = portrait;
|
||||
|
||||
for i = 1, table.getn(LO.quads) do
|
||||
local q = LO.quads[i];
|
||||
local tx = f:CreateTexture(nil, "BORDER");
|
||||
tx:SetTexture(q[1]);
|
||||
tx:SetSize(q[2], q[3]);
|
||||
tx:SetPoint(q[4]);
|
||||
end
|
||||
|
||||
local title = f:CreateFontString(nil, "OVERLAY", "GameFontNormal");
|
||||
title:SetPoint("TOP", 0, -18);
|
||||
f.title = title;
|
||||
|
||||
local close = CreateFrame("Button", nil, f, "UIPanelCloseButton");
|
||||
close:SetPoint("TOPRIGHT", LO.close[1], LO.close[2]);
|
||||
|
||||
local exit = CreateFrame("Button", nil, f, "UIPanelButtonTemplate");
|
||||
exit:SetSize(80, 22);
|
||||
exit:SetPoint(LO.exit[1], f, LO.exit[2], LO.exit[3], LO.exit[4]);
|
||||
exit:SetText(EXIT or "Exit");
|
||||
exit:SetScript("OnClick", function() f:Hide(); end);
|
||||
|
||||
local bar = CreateFrame("StatusBar", nil, f);
|
||||
bar:SetSize(LO.bar[1], LO.bar[2]);
|
||||
bar:SetPoint("TOPLEFT", LO.bar[3], LO.bar[4]);
|
||||
bar:SetStatusBarTexture("Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar");
|
||||
bar:SetStatusBarColor(0.0, 0.0, 1.0, 0.5);
|
||||
bar:SetMinMaxValues(0, 1);
|
||||
local barBg = bar:CreateTexture(nil, "BACKGROUND");
|
||||
barBg:SetAllPoints(bar);
|
||||
barBg:SetTexture(1, 1, 1, 0.2);
|
||||
barBg:SetVertexColor(0.0, 0.0, 0.75, 0.5);
|
||||
-- Border: tooltip edge around the bar (TradeSkillRankFrameBorder).
|
||||
local border = CreateFrame("Frame", nil, bar);
|
||||
border:SetSize(LO.barBdr[1], LO.barBdr[2]);
|
||||
border:SetPoint("LEFT", -5, 1);
|
||||
border:SetBackdrop({
|
||||
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16,
|
||||
});
|
||||
border:SetBackdropBorderColor(0.4, 0.4, 0.4);
|
||||
local barName = bar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall");
|
||||
barName:SetPoint("LEFT", 6, 1);
|
||||
local barRank = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
|
||||
barRank:SetJustifyH("LEFT");
|
||||
barRank:SetWidth(128);
|
||||
barRank:SetPoint("LEFT", barName, "RIGHT", 13, 0);
|
||||
f.bar = bar;
|
||||
f.barName = barName;
|
||||
f.barRank = barRank;
|
||||
|
||||
local summary = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
|
||||
summary:SetPoint(LO.summary[1], LO.summary[2], LO.summary[3]);
|
||||
f.summary = summary;
|
||||
|
||||
local dropdown = CreateFrame("Frame", "ClassicAPITradeSkillLinkSubClass", f,
|
||||
"UIDropDownMenuTemplate");
|
||||
dropdown:SetPoint("TOPLEFT", LO.drop[1], LO.drop[2]);
|
||||
f.dropdown = dropdown;
|
||||
f.subclassFilter = nil; -- nil = all subclasses
|
||||
|
||||
local scroll = CreateFrame("ScrollFrame", "ClassicAPITradeSkillLinkScroll",
|
||||
f, "FauxScrollFrameTemplate");
|
||||
scroll:SetSize(LO.scroll[1], LO.scroll[2]);
|
||||
scroll:SetPoint("TOPLEFT", LO.scroll[3], LO.scroll[4]);
|
||||
scroll:SetScript("OnVerticalScroll", function()
|
||||
FauxScrollFrame_OnVerticalScroll(ROW_HEIGHT, function() f:Refresh(); end)
|
||||
end)
|
||||
f.scroll = scroll;
|
||||
|
||||
f.rows = {};
|
||||
for i = 1, NUM_ROWS do
|
||||
local rowName = "ClassicAPITradeSkillLinkRow" .. i;
|
||||
local row = CreateFrame("Button", rowName, f,
|
||||
"ClassTrainerSkillButtonTemplate");
|
||||
row:SetWidth(290); -- height (16) comes from the template
|
||||
if i == 1 then
|
||||
row:SetPoint("TOPLEFT", scroll, "TOPLEFT", 0, 0);
|
||||
else
|
||||
row:SetPoint("TOPLEFT", f.rows[i - 1], "BOTTOMLEFT", 0, 0);
|
||||
end
|
||||
|
||||
row:SetNormalTexture("");
|
||||
row:SetDisabledTexture("");
|
||||
row:SetHighlightTexture("");
|
||||
|
||||
local txt = getglobal(rowName .. "Text");
|
||||
if txt then
|
||||
txt:ClearAllPoints();
|
||||
txt:SetPoint("LEFT", row, "LEFT", 4, 0);
|
||||
end
|
||||
|
||||
local sel = row:CreateTexture(nil, "BACKGROUND");
|
||||
sel:SetTexture("Interface\\Buttons\\UI-Listbox-Highlight2");
|
||||
sel:SetAllPoints(row);
|
||||
sel:Hide();
|
||||
row.select = sel;
|
||||
|
||||
-- Override the template's trainer scripts with ours.
|
||||
row:SetScript("OnClick", function()
|
||||
if this.entry then
|
||||
f:SelectRecipe(this.entry);
|
||||
end
|
||||
end);
|
||||
|
||||
f.rows[i] = row;
|
||||
end
|
||||
|
||||
local NUM_REAGENTS = 8;
|
||||
|
||||
local prodIcon = CreateFrame("Button", nil, f);
|
||||
prodIcon:SetSize(37, 37); -- TradeSkillSkillIcon is 37x37
|
||||
prodIcon:SetPoint("TOPLEFT", LO.detail[1], LO.detail[2]);
|
||||
prodIcon:SetNormalTexture("Interface\\Icons\\INV_Misc_QuestionMark");
|
||||
local hdrLeft = prodIcon:CreateTexture(nil, "BACKGROUND");
|
||||
hdrLeft:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-DetailHeaderLeft");
|
||||
hdrLeft:SetSize(256, 64); -- Blizzard's native fill width (+64 cap = 320 total)
|
||||
hdrLeft:SetPoint("TOPLEFT", prodIcon, "TOPLEFT", -8, 6);
|
||||
local hdrRight = prodIcon:CreateTexture(nil, "BACKGROUND");
|
||||
hdrRight:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-DetailHeaderRight");
|
||||
hdrRight:SetSize(64, 64);
|
||||
hdrRight:SetPoint("TOPLEFT", hdrLeft, "TOPRIGHT", 0, 0);
|
||||
local prodCount = prodIcon:CreateFontString(nil, "ARTWORK", "NumberFontNormal");
|
||||
prodCount:SetPoint("BOTTOMRIGHT", -5, 2);
|
||||
prodIcon.count = prodCount;
|
||||
f.prodIcon = prodIcon;
|
||||
|
||||
local prodName = prodIcon:CreateFontString(nil, "ARTWORK", "GameFontNormal");
|
||||
prodName:SetPoint("LEFT", prodIcon, "RIGHT", 5, 0);
|
||||
prodName:SetWidth(240);
|
||||
prodName:SetJustifyH("LEFT");
|
||||
prodName:SetJustifyV("MIDDLE");
|
||||
f.prodName = prodName;
|
||||
|
||||
local prodDesc = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
|
||||
prodDesc:SetPoint("TOPLEFT", prodIcon, "BOTTOMLEFT", 0, -6);
|
||||
prodDesc:SetWidth(280);
|
||||
prodDesc:SetJustifyH("LEFT");
|
||||
prodDesc:SetJustifyV("TOP");
|
||||
f.prodDesc = prodDesc;
|
||||
|
||||
local reagentLabel = f:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall");
|
||||
reagentLabel:SetPoint("TOPLEFT", prodDesc, "BOTTOMLEFT", 0, -8);
|
||||
reagentLabel:SetText(SPELL_REAGENTS or "Reagents:");
|
||||
f.reagentLabel = reagentLabel;
|
||||
|
||||
f.reagents = {};
|
||||
for i = 1, NUM_REAGENTS do
|
||||
local rowN = math.floor((i - 1) / 2);
|
||||
local col = (i - 1) - rowN * 2;
|
||||
local btn = CreateFrame("Button", nil, f);
|
||||
btn:SetSize(39, 39);
|
||||
btn:SetPoint("TOPLEFT", reagentLabel, "BOTTOMLEFT",
|
||||
col * 147 - 5, -3 - rowN * 43);
|
||||
btn:SetNormalTexture("Interface\\Icons\\INV_Misc_QuestionMark");
|
||||
local plate = btn:CreateTexture(nil, "BACKGROUND");
|
||||
plate:SetTexture("Interface\\QuestFrame\\UI-QuestItemNameFrame");
|
||||
plate:SetSize(128, 64);
|
||||
plate:SetPoint("LEFT", btn, "RIGHT", -10, 0);
|
||||
local cnt = btn:CreateFontString(nil, "ARTWORK", "NumberFontNormal");
|
||||
cnt:SetPoint("BOTTOMRIGHT", -4, 1);
|
||||
btn.count = cnt;
|
||||
local nm = btn:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
|
||||
nm:SetPoint("LEFT", plate, "LEFT", 15, 0);
|
||||
nm:SetSize(90, 36);
|
||||
nm:SetJustifyH("LEFT");
|
||||
nm:SetJustifyV("MIDDLE");
|
||||
btn.nameText = nm;
|
||||
btn:SetScript("OnEnter", function()
|
||||
if this.itemLink then
|
||||
GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
|
||||
GameTooltip:SetHyperlink(this.itemLink);
|
||||
GameTooltip:Show();
|
||||
end
|
||||
end);
|
||||
btn:SetScript("OnLeave", GameTooltip_Hide);
|
||||
btn:Hide();
|
||||
f.reagents[i] = btn;
|
||||
end
|
||||
|
||||
function f:RenderDetail(entry)
|
||||
local function itemInfo(id)
|
||||
local item = Item:CreateFromItemID(id);
|
||||
if not item:IsItemDataCached() then
|
||||
item:ContinueOnItemLoad(function()
|
||||
if self:IsShown() and self.selectedSpellID == entry.spellID then
|
||||
self:RenderDetail(entry);
|
||||
end
|
||||
end);
|
||||
end
|
||||
return item:GetItemName(), item:GetItemIcon(), item:GetItemLink();
|
||||
end
|
||||
|
||||
local prodTex, prodText, prodLink;
|
||||
local created = entry.createdItem or 0;
|
||||
if created > 0 then
|
||||
local name, tex, link = itemInfo(created);
|
||||
prodText = name or entry.name;
|
||||
prodTex = tex;
|
||||
prodLink = link;
|
||||
else
|
||||
prodText = entry.name;
|
||||
prodTex = C_Spell.GetSpellTexture(entry.spellID);
|
||||
end
|
||||
if created > 0 then
|
||||
self.prodDesc:SetText("");
|
||||
else
|
||||
self.prodDesc:SetText(C_Spell.GetSpellDescription(entry.spellID) or "");
|
||||
end
|
||||
self.prodIcon:SetNormalTexture(prodTex or
|
||||
"Interface\\Icons\\INV_Misc_QuestionMark");
|
||||
self.prodName:SetText(prodText or "");
|
||||
self.prodName:SetTextColor(NORMAL_FONT_COLOR:GetRGB());
|
||||
self.prodIcon.itemLink = prodLink; -- item tooltip when created > 0
|
||||
self.prodIcon.spellID = entry.spellID; -- else spell tooltip
|
||||
local made = entry.numMade or 0;
|
||||
self.prodIcon.count:SetText(made > 1 and tostring(made) or "");
|
||||
self.prodIcon:Show();
|
||||
|
||||
local reagents = entry.reagents or {};
|
||||
for i = 1, NUM_REAGENTS do
|
||||
local btn = self.reagents[i];
|
||||
local r = reagents[i];
|
||||
if r then
|
||||
local name, tex, link = itemInfo(r.itemID);
|
||||
btn:SetNormalTexture(tex or
|
||||
"Interface\\Icons\\INV_Misc_QuestionMark");
|
||||
btn.itemLink = link;
|
||||
btn.nameText:SetText(name or ("item:" .. r.itemID));
|
||||
local need = r.count or 1;
|
||||
local have = C_Item.GetItemCount(r.itemID) or 0;
|
||||
if have >= need then
|
||||
btn:GetNormalTexture():SetVertexColor(1, 1, 1);
|
||||
btn.nameText:SetTextColor(HIGHLIGHT_FONT_COLOR:GetRGB());
|
||||
else
|
||||
btn:GetNormalTexture():SetVertexColor(0.5, 0.5, 0.5);
|
||||
btn.nameText:SetTextColor(GRAY_FONT_COLOR:GetRGB());
|
||||
end
|
||||
local haveText = (have >= 100) and "*" or tostring(have);
|
||||
btn.count:SetText(haveText .. " /" .. need);
|
||||
btn:Show();
|
||||
else
|
||||
btn.itemLink = nil;
|
||||
btn:Hide();
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
prodIcon:SetScript("OnEnter", function()
|
||||
GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
|
||||
if this.itemLink then
|
||||
GameTooltip:SetHyperlink(this.itemLink);
|
||||
elseif this.spellID then
|
||||
GameTooltip:SetSpellByID(this.spellID);
|
||||
end
|
||||
GameTooltip:Show();
|
||||
end);
|
||||
prodIcon:SetScript("OnLeave", GameTooltip_Hide);
|
||||
|
||||
function f:SelectRecipe(entry)
|
||||
self.selectedSpellID = entry.spellID;
|
||||
self.selectedEntry = entry;
|
||||
self:RenderDetail(entry);
|
||||
self:Refresh();
|
||||
end
|
||||
|
||||
function f:ClearDetail()
|
||||
self.selectedSpellID = nil;
|
||||
self.selectedEntry = nil;
|
||||
self.prodIcon:Hide();
|
||||
self.prodName:SetText("");
|
||||
self.prodDesc:SetText("");
|
||||
for i = 1, NUM_REAGENTS do
|
||||
self.reagents[i]:Hide();
|
||||
end
|
||||
end
|
||||
|
||||
function f:Refresh()
|
||||
local recipes = self.displayed or {};
|
||||
local total = table.getn(recipes);
|
||||
FauxScrollFrame_Update(self.scroll, total, NUM_ROWS, ROW_HEIGHT);
|
||||
local offset = FauxScrollFrame_GetOffset(self.scroll);
|
||||
for i = 1, NUM_ROWS do
|
||||
local row = self.rows[i];
|
||||
local entry = recipes[offset + i];
|
||||
if entry then
|
||||
-- Append " [N]" when the reader can craft any (Blizzard's list).
|
||||
local craftable = CraftableCount(entry);
|
||||
local label = entry.name or "";
|
||||
if craftable and craftable > 0 then
|
||||
label = label .. " [" .. craftable .. "]";
|
||||
end
|
||||
row:SetText(label);
|
||||
local r, g, b = BAND_COLOR[entry.band or 3]:GetRGB();
|
||||
if self.selectedSpellID and entry.spellID == self.selectedSpellID then
|
||||
row.select:SetVertexColor(r, g, b);
|
||||
row.select:Show();
|
||||
row:SetTextColor(1, 1, 1);
|
||||
else
|
||||
row.select:Hide();
|
||||
row:SetTextColor(r, g, b);
|
||||
end
|
||||
row.spellID = entry.spellID;
|
||||
row.entry = entry;
|
||||
row:Show();
|
||||
else
|
||||
row.spellID = nil;
|
||||
row.entry = nil;
|
||||
row.select:Hide();
|
||||
row:Hide();
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function f:ApplyFilter()
|
||||
local src = self.recipes or {};
|
||||
if not self.subclassFilter then
|
||||
self.displayed = src;
|
||||
else
|
||||
local out = {};
|
||||
for i = 1, table.getn(src) do
|
||||
if src[i].subclass == self.subclassFilter then
|
||||
table.insert(out, src[i]);
|
||||
end
|
||||
end
|
||||
self.displayed = out;
|
||||
end
|
||||
local sb = getglobal("ClassicAPITradeSkillLinkScrollScrollBar");
|
||||
if sb then
|
||||
sb:SetValue(0);
|
||||
end
|
||||
self:Refresh();
|
||||
end
|
||||
|
||||
f:RegisterEvent("BAG_UPDATE_DELAYED");
|
||||
f:SetScript("OnEvent", function()
|
||||
if not f:IsShown() then
|
||||
return;
|
||||
end
|
||||
f:Refresh();
|
||||
if f.selectedEntry then
|
||||
f:RenderDetail(f.selectedEntry);
|
||||
end
|
||||
end);
|
||||
|
||||
return f;
|
||||
end
|
||||
|
||||
local function ShowTradeSkillLink(link, text)
|
||||
local id, cur, max, who, bits = ParseTradeLink(link);
|
||||
if not id then
|
||||
return false;
|
||||
end
|
||||
local recipes = C_TradeSkillUI.GetTradeSkillListRecipes(id, bits);
|
||||
if not recipes then
|
||||
return false;
|
||||
end
|
||||
|
||||
local prof = text and string.match(text, "|h%[(.+)%]|h") or "Trade Skills";
|
||||
local total = table.getn(recipes);
|
||||
local knownList = {};
|
||||
for i = 1, total do
|
||||
local r = recipes[i];
|
||||
if r.isKnown then
|
||||
r.band = DifficultyBand(cur or 0, r.trivialLevel, r.greenLevel);
|
||||
r.name = GetSpellInfo(r.spellID) or ("spell:" .. r.spellID);
|
||||
table.insert(knownList, r);
|
||||
end
|
||||
end
|
||||
table.sort(knownList, function(a, b)
|
||||
if a.band ~= b.band then
|
||||
return a.band < b.band;
|
||||
end
|
||||
return a.name < b.name;
|
||||
end);
|
||||
local known = table.getn(knownList);
|
||||
|
||||
if not frame then
|
||||
frame = CreateFrame_TradeSkillLink();
|
||||
end
|
||||
frame.title:SetText(who and who ~= "" and (who .. " - " .. prof) or prof);
|
||||
SetPortraitToTexture(frame.portrait, ProfessionIcon(id));
|
||||
frame.bar:SetMinMaxValues(0, (max and max > 0) and max or 1);
|
||||
frame.bar:SetValue(cur or 0);
|
||||
frame.barName:SetText(prof);
|
||||
frame.barRank:SetText(string.format("%d/%d", cur or 0, max or 0));
|
||||
frame.summary:SetText(string.format("%d of %d recipes known", known, total));
|
||||
frame.recipes = knownList;
|
||||
frame.subclassFilter = nil;
|
||||
|
||||
frame:ClearDetail();
|
||||
frame:Show();
|
||||
RefreshSubclasses();
|
||||
frame:ApplyFilter();
|
||||
local first = frame.displayed and frame.displayed[1];
|
||||
if first then
|
||||
frame:SelectRecipe(first);
|
||||
end
|
||||
return true;
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Click interception: handle `trade:` before the engine's SetHyperlink (which
|
||||
-- in 1.12 only knows item:/enchant: and would reject the link).
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
local originalSetItemRef = SetItemRef;
|
||||
function SetItemRef(link, text, button, chatFrame)
|
||||
if type(link) == "string" and string.sub(link, 1, 6) == "trade:" then
|
||||
if IsShiftKeyDown() and ChatFrameEditBox and ChatFrameEditBox:IsVisible() then
|
||||
ChatFrameEditBox:Insert(text);
|
||||
return;
|
||||
end
|
||||
if ShowTradeSkillLink(link, text) then
|
||||
return;
|
||||
end
|
||||
end
|
||||
return originalSetItemRef(link, text, button, chatFrame);
|
||||
end
|
||||
|
||||
local function CreateProfessionLinkButton(parentName, getLink)
|
||||
local parent = _G[parentName];
|
||||
local btnName = parentName .. "LinkButton";
|
||||
if _G[btnName] or not parent then
|
||||
return;
|
||||
end
|
||||
local btn = CreateFrame("Button", btnName, parent);
|
||||
btn:SetSize(16, 16);
|
||||
btn:SetPoint("LEFT", _G[parentName .. "TitleText"], "RIGHT", 4, 0);
|
||||
|
||||
local icon = "Interface\\GossipFrame\\PetitionGossipIcon";
|
||||
btn:SetNormalTexture(icon);
|
||||
btn:SetHighlightTexture(icon, "ADD");
|
||||
|
||||
btn:SetScript("OnClick", function()
|
||||
local link = getLink();
|
||||
if not link then
|
||||
return;
|
||||
end
|
||||
if not ChatFrameEditBox:IsVisible() then
|
||||
ChatFrameEditBox:Show();
|
||||
end
|
||||
ChatFrameEditBox:Insert(link);
|
||||
end);
|
||||
btn:SetScript("OnEnter", function()
|
||||
GameTooltip:SetOwner(this, "ANCHOR_TOPLEFT");
|
||||
GameTooltip:SetText(LINK_TRADESKILL_TOOLTIP, nil, nil, nil, nil, 1);
|
||||
GameTooltip:Show();
|
||||
end);
|
||||
btn:SetScript("OnLeave", GameTooltip_Hide);
|
||||
end
|
||||
|
||||
EventUtil.ContinueOnAddOnLoaded("Blizzard_TradeSkillUI", function()
|
||||
CreateProfessionLinkButton("TradeSkillFrame", C_TradeSkillUI.GetTradeSkillListLink);
|
||||
end);
|
||||
|
||||
EventUtil.ContinueOnAddOnLoaded("Blizzard_CraftUI", function()
|
||||
CreateProfessionLinkButton("CraftFrame", C_TradeSkillUI.GetCraftListLink);
|
||||
end);
|
||||
@@ -24,3 +24,4 @@ SLASH_EQUIP_SET2 = "/equipset";
|
||||
SLASH_FOCUS1 = "/focus";
|
||||
SLASH_FOCUS2 = "/focus";
|
||||
TARGETFOCUS = "Target Focus";
|
||||
LINK_TRADESKILL_TOOLTIP = "Click here to create a link to your profession.";
|
||||
+4
-1
@@ -99,7 +99,10 @@ target_compile_definitions(
|
||||
${PROJECT_NAME}
|
||||
PRIVATE CLASSICAPI_VERSION_VALUE=${CLASSICAPI_VERSION_VALUE})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE minhook advapi32)
|
||||
# ole32: COM (CoInitializeEx / CoCreateInstance / CoTaskMemFree) for the
|
||||
# SAPI text-to-speech backend in src/voicechat/Tts.cpp. The SAPI GUIDs are
|
||||
# instantiated in that TU via <initguid.h>, so no sapi.lib is needed.
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE minhook advapi32 ole32)
|
||||
|
||||
target_include_directories(
|
||||
${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
|
||||
@@ -33,6 +33,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
|
||||
| [Expansion](docs/API.md#expansion) | `ClassicExpansionAtLeast`, `ClassicExpansionAtMost`, `GetClassicExpansionLevel` |
|
||||
| [Faction](docs/API.md#faction) | `C_Reputation.GetFactionDataByIndex`, `C_Reputation.GetFactionStandings`, `C_Reputation.GetLastStandingChange`, `C_Reputation.GetWatchedFactionData`, `C_Reputation.SetWatchedFactionByID`, `GetFactionIDByIndex`, `GetFactionInfoByID`, `GetFactionParentID` |
|
||||
| [Focus](docs/API.md#focus) | `ClearFocus`, `FocusUnit` |
|
||||
| [Frame](docs/API.md#frame) | `region:SetPoint("point")` (one-arg form), `region:SetSize`, `region:GetSize`, `frame:SetShown`, `frame:SetResizeBounds`, `frame:HookScript`, `frame:IsEventRegistered` |
|
||||
| [FriendList](docs/API.md#friendlist) | `C_FriendList.IsWhoQueryPending`, `C_FriendList.SendWhoQueryByName` |
|
||||
| [GameObject](docs/API.md#gameobject) | `C_GameObjectInfo.GetGameObjectInfoByID`, `C_GameObjectInfo.RequestLoadGameObjectByID` |
|
||||
| [Gossip](docs/API.md#gossip) | `C_GossipInfo.CloseGossip`, `C_GossipInfo.GetActiveQuests`, `C_GossipInfo.GetAvailableQuests`, `C_GossipInfo.GetNumActiveQuests`, `C_GossipInfo.GetNumAvailableQuests`, `C_GossipInfo.GetNumOptions`, `C_GossipInfo.GetOptions`, `C_GossipInfo.GetText`, `C_GossipInfo.SelectActiveQuest`, `C_GossipInfo.SelectAvailableQuest`, `C_GossipInfo.SelectOption`, `C_GossipInfo.SelectOptionByIndex` |
|
||||
@@ -42,13 +43,14 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
|
||||
| [Instance](docs/API.md#instance) | `GetInstanceInfo` |
|
||||
| [Item](docs/API.md#item) | `C_Item.DoesItemExist`, `C_Item.DoesItemExistByID`, `C_Item.EquipItemByName`, `C_Item.GetCurrentItemLevel`, `C_Item.GetDetailedItemLevelInfo`, `C_Item.GetEnchantInfo`, `C_Item.GetItemCount`, `C_Item.GetItemFamily`, `C_Item.GetItemGUID`, `C_Item.GetItemIcon`, `C_Item.GetItemIconByID`, `C_Item.GetItemID`, `C_Item.GetItemInfoInstant`, `C_Item.GetItemInventorySlotInfo`, `C_Item.GetItemInventorySlotKey`, `C_Item.GetItemInventoryType`, `C_Item.GetItemInventoryTypeByID`, `C_Item.GetItemLink`, `C_Item.GetItemLocation`, `C_Item.GetItemMaxStackSize`, `C_Item.GetItemMaxStackSizeByID`, `C_Item.GetItemName`, `C_Item.GetItemNameByID`, `C_Item.GetItemQuality`, `C_Item.GetItemQualityByID`, `C_Item.GetItemSellPrice`, `C_Item.GetItemSellPriceByID`, `C_Item.GetItemSetID`, `C_Item.GetItemSetIDByID`, `C_Item.GetItemSetInfo`, `C_Item.GetItemSpell`, `C_Item.GetItemStatDelta`, `C_Item.GetItemStats`, `C_Item.GetItemSubClassInfo`, `C_Item.GetItemUniqueness`, `C_Item.GetItemUniquenessByID`, `C_Item.GetStackCount`, `C_Item.GetWeaponEnchantInfo`, `C_Item.IsBound`, `C_Item.IsEquippableItem`, `C_Item.IsEquippedItem`, `C_Item.IsItemDataCached`, `C_Item.IsItemDataCachedByID`, `C_Item.IsItemGUIDInInventory`, `C_Item.IsItemOpenable`, `C_Item.IsLocked`, `C_Item.LockItem`, `C_Item.LockItemByGUID`, `C_Item.UnlockAllItems`, `C_Item.UnlockItem`, `C_Item.RequestLoadItemData`, `C_Item.RequestLoadItemDataByID`, `C_Item.UseAtCursor`, `C_Item.UseAtUnit`, `C_Item.UseItemByName`, `GetAuctionItemID`, `GetAuctionSellItemID`, `GetAverageItemLevel`, `GetCraftReagentItemID`, `GetInboxItemID`, `GetInventoryItemDurability`, `GetInventoryItemID`, `GetInventoryItemsForSlot`, `GetInventoryItemRepairCost`, `GetItemIcon`, `GetLootRollItemID`, `GetLootSlotItemID`, `GetMerchantItemID`, `GetQuestItemID`, `GetQuestLogItemID`, `GetTradePlayerItemID`, `GetTradeSkillItemID`, `GetTradeSkillReagentItemID`, `GetTradeTargetItemID`, `OffhandHasWeapon` |
|
||||
| [Loot](docs/API.md#loot) | `C_Loot.GetNearbyLootableUnits`, `C_Loot.GetLastScanResults`, `C_Loot.IsScanInProgress`, `C_Loot.LootUnit`, `C_Loot.LootUnitItem`, `C_Loot.ScanNearbyLoot` |
|
||||
| [LossOfControl](docs/API.md#lossofcontrol) | `C_LossOfControl.GetActiveLossOfControlData`, `C_LossOfControl.GetActiveLossOfControlDataCount` |
|
||||
| [Macros](docs/API.md#macros) | `GetLooseMacroIcons`, `GetLooseMacroItemIcons`, `GetMacroIcons`, `GetMacroItemIcons`, `GetMacroSpell` |
|
||||
| [Mail](docs/API.md#mail) | `GetInboxItemLink`, `GetSendMailItemLink` |
|
||||
| [Map](docs/API.md#map) | `C_Map.GetBestMapForUnit` |
|
||||
| [Map](docs/API.md#map) | `C_Map.GetBestMapForUnit`, `C_Map.GetMapOverlays` |
|
||||
| [MerchantFrame](docs/API.md#merchantframe) | `C_MerchantFrame.GetBuybackItemID`, `C_MerchantFrame.GetItemInfo`, `C_MerchantFrame.GetNumJunkItems`, `C_MerchantFrame.IsMerchantItemRefundable`, `C_MerchantFrame.IsSellAllJunkEnabled`, `C_MerchantFrame.SellAllJunkItems` |
|
||||
| [NamePlate](docs/API.md#nameplate) | `C_NamePlate.GetNamePlateForGUID`, `C_NamePlate.GetNamePlateForUnit`, `C_NamePlate.GetNamePlateGUIDs`, `C_NamePlate.GetNamePlates` |
|
||||
| [NameCache](docs/API.md#namecache) | `C_PlayerCache.GetPlayerInfoByName`, `C_PlayerCache.IsEnabled`, `C_PlayerCache.IsScanEnabled`, `C_PlayerCache.RememberPlayer`, `C_PlayerCache.SetEnabled`, `C_PlayerCache.SetScanEnabled`, `C_PlayerInfo.GUIDIsCreature`, `C_PlayerInfo.GUIDIsGameObject`, `C_PlayerInfo.GUIDIsPet`, `C_PlayerInfo.GUIDIsPlayer`, `GetPlayerInfoByGUID`, `UnitNameFromGUID` |
|
||||
| [Quest](docs/API.md#quest) | `C_QuestLog.GetQuestDetails`, `C_QuestLog.GetQuestIDForLogIndex`, `C_QuestLog.GetTitleForQuestID`, `C_QuestLog.IsOnQuest`, `C_QuestLog.IsQuestDataCachedByID`, `C_QuestLog.IsUnitOnQuest`, `C_QuestLog.RequestLoadQuestByID`, `GetQuestLogLeaderBoardID` |
|
||||
| [Quest](docs/API.md#quest) | `C_QuestLog.GetNumQuestObjectives`, `C_QuestLog.GetQuestDetails`, `C_QuestLog.GetQuestIDForLogIndex`, `C_QuestLog.GetTitleForQuestID`, `C_QuestLog.IsOnQuest`, `C_QuestLog.IsQuestDataCachedByID`, `C_QuestLog.IsUnitOnQuest`, `C_QuestLog.RequestLoadQuestByID`, `GetQuestLogLeaderBoardID` |
|
||||
| [Screen](docs/API.md#screen) | `GetPhysicalScreenSize` |
|
||||
| [Spell](docs/API.md#spell) | `C_Spell.CancelSpellByID`, `C_Spell.CastAtCursor`, `C_Spell.CastAtUnit`, `C_Spell.CastingInfo`, `C_Spell.ChannelInfo`, `C_Spell.DoesSpellExist`, `C_Spell.GetSchoolString`, `C_Spell.GetSpellCooldown`, `C_Spell.GetSpellDescription`, `C_Spell.GetSpellInfo`, `C_Spell.GetSpellLink`, `C_Spell.GetSpellMechanicByID`, `C_Spell.GetSpellName`, `C_Spell.GetSpellPowerCost`, `C_Spell.GetSpellRadius`, `C_Spell.GetSpellReagents`, `C_Spell.GetSpellSubtext`, `C_Spell.GetSpellTexture`, `C_Spell.IsAutoAttackSpell`, `C_Spell.IsCurrentSpell`, `C_Spell.IsRangedAutoAttackSpell`, `C_Spell.IsSelfBuff`, `C_Spell.IsSpellHarmful`, `C_Spell.IsSpellHelpful`, `C_Spell.IsSpellPassive`, `C_Spell.IsSpellUsable`, `C_Spell.SpellHasRange`, `C_Spell.UnitCastingInfo`, `C_Spell.UnitChannelInfo`, `CancelSpellByName`, `CastSpellNoToggle`, `GetCraftSpellID`, `GetSpellInfo`, `GetSpellLink`, `GetSpellRadius`, `GetSpellSchool`, `IsHarmfulSpell`, `IsHelpfulSpell`, `IsPassiveSpell`, `IsPlayerSpell`, `IsSpellKnown`, `IsUsableSpell`, `SpellHasRange` |
|
||||
| [SpellBook](docs/API.md#spellbook) | `C_SpellBook.GetCurrentLevelSpells`, `C_SpellBook.GetSpellLevelLearned`, `C_SpellBook.GetSpellSkillLine`, `C_SpellBook.IsAutoAttackSpellBookItem`, `C_SpellBook.IsRangedAutoAttackSpellBookItem`, `FindSpellBookSlotByID` |
|
||||
@@ -56,9 +58,12 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
|
||||
| [Table](docs/API.md#table) | `table.wipe` |
|
||||
| [Talent](docs/API.md#talent) | `GetTalentIDByIndex`, `GetTalentSpellID` |
|
||||
| [Time](docs/API.md#time) | `C_DateAndTime.AdjustTimeByDays`, `C_DateAndTime.AdjustTimeByMinutes`, `C_DateAndTime.CompareCalendarTime`, `C_DateAndTime.GetCalendarTimeFromEpoch`, `C_DateAndTime.GetCurrentCalendarTime`, `C_DateAndTime.GetSecondsUntilDailyReset`, `C_DateAndTime.GetServerTimeLocal`, `C_Timer.After`, `C_Timer.NewTicker`, `C_Timer.NewTimer`, `GetServerTime` |
|
||||
| [TradeSkillUI](docs/API.md#tradeskillui) | `C_TradeSkillUI.GetTradeSkillListLink`, `C_TradeSkillUI.GetCraftListLink`, `C_TradeSkillUI.GetTradeSkillListRecipes` |
|
||||
| [UIColor](docs/API.md#uicolor) | `C_UIColor.GetColors` |
|
||||
| [Unit](docs/API.md#unit) | `GetUnitSpeed`, `UnitClassBase`, `UnitGUID`, `UnitInRange`, `UnitIsAFK`, `UnitIsDND`, `UnitIsFeignDeath`, `UnitIsInMyGuild`, `UnitIsPossessed`, `UnitPower`, `UnitPowerMax`, `UnitPowerType`, `UnitRaceBase`, `UnitStandState`, `UnitSubName`, `UnitTokenFromGUID` |
|
||||
| [UnitAuras](docs/API.md#unitauras) | `C_UnitAuras.GetAuraDataByIndex`, `C_UnitAuras.GetAuraDataBySpellName`, `C_UnitAuras.GetAuraDispelTypeColor`, `C_UnitAuras.GetBuffDataByIndex`, `C_UnitAuras.GetDebuffDataByIndex`, `C_UnitAuras.GetPlayerAuraBySpellID`, `C_UnitAuras.GetUnitAuraBySpellID`, `C_UnitAuras.GetUnitAuras` |
|
||||
| [UnitAuras](docs/API.md#unitauras) | `C_UnitAuras.GetAuraDataByIndex`, `C_UnitAuras.GetAuraDataBySpellName`, `C_UnitAuras.GetAuraDispelTypeColor`, `C_UnitAuras.GetBuffDataByIndex`, `C_UnitAuras.GetDebuffDataByIndex`, `C_UnitAuras.GetPlayerAuraBySpellID`, `C_UnitAuras.GetUnitAuraBySpellID`, `C_UnitAuras.GetUnitAuras`, `C_UnitAuras.RegisterComboDuration` |
|
||||
| [VoiceChat](docs/API.md#voicechat) | `C_VoiceChat.GetTtsVoices`, `C_VoiceChat.GetRemoteTtsVoices`, `C_VoiceChat.SpeakText`, `C_VoiceChat.StopSpeakingText`, `C_TTSSettings.GetSpeechRate`, `C_TTSSettings.GetSpeechVolume`, `C_TTSSettings.GetSpeechVoiceID`, `C_TTSSettings.GetVoiceOptionName`, `C_TTSSettings.SetSpeechRate`, `C_TTSSettings.SetSpeechVolume`, `C_TTSSettings.SetVoiceOption`, `C_TTSSettings.SetVoiceOptionByName`, `C_TTSSettings.SetDefaultSettings`, `C_TTSSettings.RefreshVoices` |
|
||||
| [XMLUtil](docs/API.md#xmlutil) | `C_XMLUtil.DoesTemplateExist`, `C_XMLUtil.GetTemplateInfo`, `C_XMLUtil.GetTemplates` |
|
||||
|
||||
### GlueXML calls
|
||||
|
||||
@@ -117,10 +122,13 @@ when launching with `-console`), not as Lua functions. See the
|
||||
| `HEARTHSTONE_BOUND` | *(none)* |
|
||||
| `ITEM_DATA_LOAD_RESULT` | `itemID, success` |
|
||||
| `LOOT_SCAN_COMPLETED` | *(none)* |
|
||||
| `LOSS_OF_CONTROL_ADDED` | `eventIndex` |
|
||||
| `LOSS_OF_CONTROL_UPDATE` | `unitToken` (always `"player"`) |
|
||||
| `MODIFIER_STATE_CHANGED` | `keyName, down` |
|
||||
| `NAME_PLATE_CREATED` | `nameplateFrame` |
|
||||
| `NAME_PLATE_UNIT_ADDED` | `unitToken` ("nameplateN") |
|
||||
| `NAME_PLATE_UNIT_REMOVED` | `unitToken` ("nameplateN") |
|
||||
| `PLAYER_EQUIPMENT_CHANGED` | `equipmentSlot, hasCurrent` |
|
||||
| `PLAYER_FOCUS_CHANGED` | *(none)* |
|
||||
| `PLAYER_STARTED_LOOKING` | *(none)* |
|
||||
| `PLAYER_STOPPED_LOOKING` | *(none)* |
|
||||
@@ -130,8 +138,14 @@ when launching with `-console`), not as Lua functions. See the
|
||||
| `PLAYER_STOPPED_TURNING` | *(none)* |
|
||||
| `QUEST_ACCEPTED` | `questLogIndex, questID` |
|
||||
| `QUEST_DATA_LOAD_RESULT` | `questID, success` |
|
||||
| `QUEST_REMOVED` | `questID` |
|
||||
| `QUEST_TURNED_IN` | `questID, xpReward, moneyReward` |
|
||||
| `UPDATE_INVENTORY_DURABILITY` | *(none)* |
|
||||
| `UPDATE_SHAPESHIFT_FORM` | *(none)* |
|
||||
| `VOICE_CHAT_TTS_PLAYBACK_STARTED` | `numConsumers, utteranceID, durationMS, destination` |
|
||||
| `VOICE_CHAT_TTS_PLAYBACK_FINISHED` | `numConsumers, utteranceID, destination` |
|
||||
| `VOICE_CHAT_TTS_PLAYBACK_FAILED` | `status, utteranceID, destination` |
|
||||
| `VOICE_CHAT_TTS_VOICES_UPDATE` | *(none)* |
|
||||
|
||||
### Globals
|
||||
|
||||
|
||||
@@ -2725,7 +2725,26 @@ matching modern's 3-tuple. `CastSpellNoToggle("<name>")` macros are
|
||||
also recognized because `Spell::CastNoToggle` already hooks the same
|
||||
parser to register that pattern.
|
||||
|
||||
## 88. `PLAYER_EQUIPMENT_CHANGED(equipmentSlot, hasCurrent)` event
|
||||
## ~~88. `PLAYER_EQUIPMENT_CHANGED(equipmentSlot, hasCurrent)` event~~ — DONE
|
||||
|
||||
**Resolution (2026-07-04, src/player/Equipment.cpp):** the 2026-05-22
|
||||
investigation kept trying to hook a FIRER of UNIT_INVENTORY_CHANGED.
|
||||
The winning move was the opposite: the engine has a generic
|
||||
descriptor-field observer system (the "__AUCMirrorHandler__" nodes —
|
||||
registrar `FUN_00467E70`, dispatcher `FUN_00465570` with per-node
|
||||
mirror + memcmp change detection). `FUN_004F8CC0` registers observers
|
||||
for the bag/backpack/bank/keyring GUID ranges but never for equipment
|
||||
`0x4A8..0x538` — so we co-hook it and REGISTER OUR OWN observer per
|
||||
equipment field, mirroring the engine's registration exactly (bank 4,
|
||||
size 8, player GUID). Callback ABI verified from the dispatcher call
|
||||
site at `0x004655DC` + `FUN_004F8DB0`'s `RET 0x10`:
|
||||
`__fastcall(fieldOffset /*ecx*/, size /*edx*/, guidLo, guidHi,
|
||||
oldValue*, userArg)`. hasCurrent read from the invMgr GUID array (the
|
||||
same "current truth" the engine's bag callback reads). No polling, no
|
||||
hot hook, engine-managed lifetime (setup re-runs each enter-world).
|
||||
Offsets documented at `FUN_DESC_OBSERVER_REGISTER` in Offsets.h.
|
||||
|
||||
Original notes below kept for the investigation trail.
|
||||
|
||||
WotLK-era event that fires every time a paperdoll slot changes
|
||||
(equip, unequip, swap). Heavily used by gear-tracking,
|
||||
@@ -2828,7 +2847,33 @@ Same diff feeds `EQUIPMENT_SETS_CHANGED` /
|
||||
module — currently those fire only on user-side mutations, not
|
||||
on inventory changes that affect a set's "equipped count".
|
||||
|
||||
## 89. `UPDATE_INVENTORY_DURABILITY` event
|
||||
## ~~89. `UPDATE_INVENTORY_DURABILITY` event~~ — DONE
|
||||
|
||||
**Resolution (2026-07-04, src/player/Equipment.cpp):** co-hook the
|
||||
engine's inventory-alerts recompute `FUN_004C7EE0` — the routine that
|
||||
walks equipment slots, reads each item's durability/broken state from
|
||||
the descriptor, and unconditionally fires vanilla's
|
||||
`UPDATE_INVENTORY_ALERTS` (event 501). The engine calls it whenever an
|
||||
owned item's fields change (the item post-update handler `FUN_005D9A90`
|
||||
routes every item values-update through it, alongside
|
||||
UNIT_INVENTORY_CHANGED and the bag-update chain) plus equip and
|
||||
enter-world paths — i.e., it IS the engine's own "durability may have
|
||||
changed" signal. Post-original we diff a per-slot {guid, durability}
|
||||
snapshot (seeded silently on the first recompute per enter-world) and
|
||||
fire once per recompute with a real change. No polling, no hot hook.
|
||||
|
||||
**Dead end tried first:** bank-1 (ITEM field) descriptor observers per
|
||||
equipped item, via the TODO #88 observer system. They register without
|
||||
error but are NEVER invoked — item values-updates demonstrably arrive
|
||||
(probed the values pre-pass `FUN_00465330`) and player-bank observers
|
||||
fire in the same session; registration arithmetic fully verified (bank
|
||||
base `FUN_00465690(1)=0x18`, bank walk item 0→1→2, anchors match
|
||||
dispatch). Prime suspect: the registrar's internal wrapper lookup
|
||||
(`FUN_00464890`, the observer registry — NOT the object manager)
|
||||
silently no-ops for item objects. See the DEAD END note at
|
||||
`OFF_DESC_ITEM_DURABILITY` in Offsets.h.
|
||||
|
||||
Original notes below kept for the investigation trail.
|
||||
|
||||
Fires when any equipped item's durability changes — picks up
|
||||
combat damage, repairs, item destruction. Used by Repair-O-Matic
|
||||
|
||||
+739
-32
@@ -90,6 +90,8 @@ build instructions.
|
||||
- [Events](#events)
|
||||
- [`C_EventUtils.IsEventValid(eventName)`](#c_eventutilsiseventvalideventname)
|
||||
- [`BAG_UPDATE_DELAYED` event](#bag_update_delayed-event)
|
||||
- [`PLAYER_EQUIPMENT_CHANGED` event](#player_equipment_changed-event)
|
||||
- [`UPDATE_INVENTORY_DURABILITY` event](#update_inventory_durability-event)
|
||||
- [`HEARTHSTONE_BOUND` event](#hearthstone_bound-event)
|
||||
- [Player input-state events (`PLAYER_STARTED_MOVING` / `LOOKING` / `TURNING` + `STOPPED_*`)](#player-input-state-events)
|
||||
- [`GLOBAL_MOUSE_DOWN` / `GLOBAL_MOUSE_UP` events](#global_mouse_down--global_mouse_up-events)
|
||||
@@ -98,10 +100,12 @@ build instructions.
|
||||
- [`EQUIPMENT_SWAP_FINISHED` event](#equipment_swap_finished-event)
|
||||
- [`FACTION_STANDING_CHANGED` event](#faction_standing_changed-event)
|
||||
- [`LOOT_SCAN_COMPLETED` event](#loot_scan_completed-event)
|
||||
- [`LOSS_OF_CONTROL_ADDED` / `LOSS_OF_CONTROL_UPDATE` events](#loss_of_control_added--loss_of_control_update-events)
|
||||
- [`MODIFIER_STATE_CHANGED` event](#modifier_state_changed-event)
|
||||
- [`NAME_PLATE_CREATED` / `NAME_PLATE_UNIT_ADDED` / `NAME_PLATE_UNIT_REMOVED` events](#name_plate_created--name_plate_unit_added--name_plate_unit_removed-events)
|
||||
- [`PLAYER_FOCUS_CHANGED` event](#player_focus_changed-event)
|
||||
- [`QUEST_ACCEPTED` event](#quest_accepted-event)
|
||||
- [`QUEST_REMOVED` event](#quest_removed-event)
|
||||
- [`QUEST_TURNED_IN` event](#quest_turned_in-event)
|
||||
- [`UNIT_FACTION` event (fire-coverage fix)](#unit_faction-event-fire-coverage-fix)
|
||||
- [`UPDATE_SHAPESHIFT_FORM` event](#update_shapeshift_form-event)
|
||||
@@ -127,6 +131,14 @@ build instructions.
|
||||
- [Unit token (`focus` / `focustarget`)](#unit-token-focus--focustarget)
|
||||
- [Bindings (`FOCUSTARGET` / `TARGETFOCUS`)](#bindings-focustarget--targetfocus)
|
||||
|
||||
- [Frame](#frame)
|
||||
- [`region:SetPoint("point")` (one-argument form)](#regionsetpointpoint-one-argument-form)
|
||||
- [`region:SetSize(width, height)` / `region:GetSize()`](#regionsetsizewidth-height--regiongetsize)
|
||||
- [`frame:SetShown(shown)`](#framesetshownshown)
|
||||
- [`frame:SetResizeBounds(minWidth, minHeight [, maxWidth, maxHeight])`](#framesetresizeboundsminwidth-minheight--maxwidth-maxheight)
|
||||
- [`frame:HookScript(scriptType, handler)`](#framehookscriptscripttype-handler)
|
||||
- [`frame:IsEventRegistered(event)`](#frameiseventregisteredevent)
|
||||
|
||||
- [FriendList](#friendlist)
|
||||
- [`C_FriendList.SendWhoQueryByName(name)`](#c_friendlistsendwhoquerybynamename)
|
||||
- [`C_FriendList.IsWhoQueryPending()`](#c_friendlistiswhoquerypending)
|
||||
@@ -243,6 +255,10 @@ build instructions.
|
||||
- [`C_Loot.IsScanInProgress()`](#c_lootisscaninprogress)
|
||||
- [`C_Loot.GetLastScanResults()`](#c_lootgetlastscanresults)
|
||||
|
||||
- [LossOfControl](#lossofcontrol)
|
||||
- [`C_LossOfControl.GetActiveLossOfControlDataCount()`](#c_lossofcontrolgetactivelossofcontroldatacount)
|
||||
- [`C_LossOfControl.GetActiveLossOfControlData(index)`](#c_lossofcontrolgetactivelossofcontroldataindex)
|
||||
|
||||
- [Macros](#macros)
|
||||
- [Numeric spellIDs in `/cast` and `CastSpellByName`](#numeric-spellids-in-cast-and-castspellbyname)
|
||||
- [`CastSpellNoToggle` as a macro cast line](#castspellnotoggle-as-a-macro-cast-line)
|
||||
@@ -255,6 +271,7 @@ build instructions.
|
||||
|
||||
- [Map](#map)
|
||||
- [`C_Map.GetBestMapForUnit(unitToken)`](#c_mapgetbestmapforunitunittoken)
|
||||
- [`C_Map.GetMapOverlays([areaID])`](#c_mapgetmapoverlaysareaid)
|
||||
|
||||
- [MerchantFrame](#merchantframe)
|
||||
- [`C_MerchantFrame.GetItemInfo(slot)`](#c_merchantframegetiteminfoslot)
|
||||
@@ -289,6 +306,7 @@ build instructions.
|
||||
- [`C_QuestLog.IsUnitOnQuest(unit, questID)`](#c_questlogisunitonquestunit-questid)
|
||||
- [`C_QuestLog.GetTitleForQuestID(questID)`](#c_questloggettitleforquestidquestid)
|
||||
- [`C_QuestLog.GetQuestDetails(questID)`](#c_questloggetquestdetailsquestid)
|
||||
- [`C_QuestLog.GetNumQuestObjectives(questID)`](#c_questloggetnumquestobjectivesquestid)
|
||||
- [`C_QuestLog.IsQuestDataCachedByID(questID)`](#c_questlogisquestdatacachedbyidquestid)
|
||||
- [`GetQuestLogLeaderBoardID(objectiveIndex [, questIndex])`](#getquestlogleaderboardidobjectiveindex--questindex)
|
||||
|
||||
@@ -326,8 +344,8 @@ build instructions.
|
||||
- [`C_Spell.IsSpellHarmful(spellID)` / `C_Spell.IsSpellHelpful(spellID)`](#c_spellisspellharmfulspellid--c_spellisspellhelpfulspellid)
|
||||
- [`GetSpellSchool(spellID)`](#getspellschoolspellid)
|
||||
- [`CastSpellNoToggle(name | spellID)`](#castspellnotogglename--spellid)
|
||||
- [`C_Spell.CastAtCursor(spellID)`](#c_spellcastatcursorspellid)
|
||||
- [`C_Spell.CastAtUnit(spellID, unit)`](#c_spellcastatunitspellid-unit)
|
||||
- [`C_Spell.CastAtCursor(spellIDOrName)`](#c_spellcastatcursorspellidorname)
|
||||
- [`C_Spell.CastAtUnit(spellIDOrName, unit)`](#c_spellcastatunitspellidorname-unit)
|
||||
- [`C_Spell.CancelSpellByID(spellID)` / `CancelSpellByName(name)`](#c_spellcancelspellbyidspellid--cancelspellbynamename)
|
||||
- [`C_Spell.UnitCastingInfo(unit)` / `C_Spell.CastingInfo()`](#c_spellunitcastinginfounit--c_spellcastinginfo)
|
||||
- [`C_Spell.UnitChannelInfo(unit)` / `C_Spell.ChannelInfo()`](#c_spellunitchannelinfounit--c_spellchannelinfo)
|
||||
@@ -373,6 +391,11 @@ build instructions.
|
||||
- [`C_DateAndTime.GetServerTimeLocal()`](#c_dateandtimegetservertimelocal)
|
||||
- [`C_DateAndTime.GetSecondsUntilDailyReset()`](#c_dateandtimegetsecondsuntildailyreset)
|
||||
|
||||
- [TradeSkillUI](#tradeskillui)
|
||||
- [`C_TradeSkillUI.GetTradeSkillListLink()`](#c_tradeskilluigettradeskilllistlink)
|
||||
- [`C_TradeSkillUI.GetCraftListLink()`](#c_tradeskilluigetcraftlistlink)
|
||||
- [`C_TradeSkillUI.GetTradeSkillListRecipes(skillLineID, bits)`](#c_tradeskilluigettradeskilllistrecipesskilllineid-bits)
|
||||
|
||||
- [UIColor](#uicolor)
|
||||
- [`C_UIColor.GetColors()`](#c_uicolorgetcolors)
|
||||
|
||||
@@ -399,9 +422,23 @@ build instructions.
|
||||
- [`C_UnitAuras.GetUnitAuraBySpellID(unit, spellID [, filter])`](#c_unitaurasgetunitaurabyspellidunit-spellid--filter)
|
||||
- [`C_UnitAuras.GetPlayerAuraBySpellID(spellID)`](#c_unitaurasgetplayeraurabyspellidspellid)
|
||||
- [`C_UnitAuras.GetAuraDataBySpellName(unit, spellName [, filter])`](#c_unitaurasgetauradatabyspellnameunit-spellname--filter)
|
||||
- [`C_UnitAuras.RegisterComboDuration(spellID, baseSeconds, maxSeconds)`](#c_unitaurasregistercombodurationspellid-baseseconds-maxseconds)
|
||||
- [`C_UnitAuras.GetUnitAuras(unit [, filter])`](#c_unitaurasgetunitaurasunit--filter)
|
||||
- [`C_UnitAuras.GetAuraDispelTypeColor(dispelName)`](#c_unitaurasgetauradispeltypecolordispelname)
|
||||
|
||||
- [VoiceChat](#voicechat)
|
||||
- [`C_VoiceChat.GetTtsVoices()` / `C_VoiceChat.GetRemoteTtsVoices()`](#c_voicechatgetttsvoices--c_voicechatgetremotettsvoices)
|
||||
- [`C_VoiceChat.SpeakText(voiceID, text [, destination, rate, volume])`](#c_voicechatspeaktextvoiceid-text--destination-rate-volume)
|
||||
- [`C_VoiceChat.StopSpeakingText()`](#c_voicechatstopspeakingtext)
|
||||
|
||||
- [XMLUtil](#xmlutil)
|
||||
- [`C_XMLUtil.GetTemplates()`](#c_xmlutilgettemplates)
|
||||
- [`C_XMLUtil.GetTemplateInfo(name)`](#c_xmlutilgettemplateinfoname)
|
||||
- [`C_XMLUtil.DoesTemplateExist(name)`](#c_xmlutildoestemplateexistname)
|
||||
- [`C_TTSSettings` — getters & setters](#c_ttssettings--getters--setters)
|
||||
- [TTS events](#tts-events)
|
||||
- [TTS CVars](#tts-cvars)
|
||||
|
||||
## Account
|
||||
|
||||
### `SaveAccount(name, password)` / `DeleteAccount(name)` / `GetSavedAccounts()` / `LoginWithSavedAccount(name)` — GlueXML only
|
||||
@@ -1994,6 +2031,68 @@ event handlers.
|
||||
> currently won't trigger `BAG_UPDATE_DELAYED`. Player bag (0..4)
|
||||
> and bank (5..10) updates work normally — the 95% case.
|
||||
|
||||
### `PLAYER_EQUIPMENT_CHANGED` event
|
||||
|
||||
Backport of the WotLK-era event that fires once per paperdoll slot
|
||||
change — equip, unequip, or swap:
|
||||
|
||||
```
|
||||
PLAYER_EQUIPMENT_CHANGED: equipmentSlot, hasCurrent
|
||||
```
|
||||
|
||||
- **`equipmentSlot`** (number) — the 1-based inventory slot that
|
||||
changed (`1` = head … `19` = tabard; same numbering as
|
||||
`GetInventoryItemLink("player", slot)`).
|
||||
- **`hasCurrent`** — `1` when the slot now holds an item, `nil` when
|
||||
it's now empty (write `if hasCurrent then` as in modern code —
|
||||
vanilla's event dispatcher can't push real booleans).
|
||||
|
||||
Vanilla only fires `UNIT_INVENTORY_CHANGED("player")`, which doesn't
|
||||
say *which* slot changed; this event lets gear trackers, stat sheets,
|
||||
and tooltip decorators refresh exactly one slot instead of rescanning
|
||||
all 19.
|
||||
|
||||
```lua
|
||||
local f = CreateFrame("Frame")
|
||||
f:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
|
||||
f:SetScript("OnEvent", function()
|
||||
print("slot", arg1, arg2 and "equipped" or "now empty")
|
||||
end)
|
||||
```
|
||||
|
||||
Fully event-driven — no polling. The DLL registers change observers
|
||||
for the 19 equipment GUID fields of the player descriptor through the
|
||||
engine's own field-observer system (the same mechanism the engine
|
||||
uses to watch bag slots), so the event fires exactly when the
|
||||
server's update packet writes a new item GUID into a slot, once per
|
||||
changed slot. Swapping two items (e.g. weapon ⇄ bag) fires once per
|
||||
affected equipment slot.
|
||||
|
||||
### `UPDATE_INVENTORY_DURABILITY` event
|
||||
|
||||
Backport of the modern event that fires — with no payload — when an
|
||||
equipped item's durability changes: combat damage, resurrection
|
||||
penalty, repairs. The standard consumer pattern works unchanged:
|
||||
rescan the 19 slots with `GetInventoryItemDurability` on each fire.
|
||||
|
||||
```lua
|
||||
local f = CreateFrame("Frame")
|
||||
f:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
|
||||
f:SetScript("OnEvent", RefreshMyDurabilityHUD)
|
||||
```
|
||||
|
||||
Event-driven, no polling: piggybacks on the engine's own
|
||||
inventory-alerts recompute — the routine behind vanilla's
|
||||
`UPDATE_INVENTORY_ALERTS` (the red/yellow "broken armor man"), which
|
||||
the engine runs whenever an owned item's fields change, on equip
|
||||
changes, and at enter-world. On each recompute the DLL diffs a
|
||||
per-slot `{item, durability}` snapshot and fires once when anything
|
||||
actually changed — a death dinging all your armor produces one event,
|
||||
not nineteen. Also fires when the *set* of equipped items changes
|
||||
(swapping to a differently-damaged item updates durability UI, so
|
||||
consumers want the refresh anyway). Bag-carried items don't trigger
|
||||
it: vanilla renders durability UI for equipped gear only.
|
||||
|
||||
### `HEARTHSTONE_BOUND` event
|
||||
|
||||
Fires (with no payload) every time the player binds their
|
||||
@@ -2219,6 +2318,24 @@ empty. Doesn't fire spuriously for scans triggered by other addons
|
||||
(only one scan runs at a time; concurrent attempts return `false`
|
||||
from `ScanNearbyLoot`). See the Loot section for the full scan flow.
|
||||
|
||||
### `LOSS_OF_CONTROL_ADDED` / `LOSS_OF_CONTROL_UPDATE` events
|
||||
|
||||
Fire as loss-of-control effects change, so a UI can react without polling.
|
||||
Register like any engine event
|
||||
(`frame:RegisterEvent("LOSS_OF_CONTROL_ADDED")`).
|
||||
|
||||
| Event | Args | When |
|
||||
|---|---|---|
|
||||
| `LOSS_OF_CONTROL_ADDED` | `eventIndex` (number) | A new effect was applied — `eventIndex` is its 1-based index for [`C_LossOfControl.GetActiveLossOfControlData`](#c_lossofcontrolgetactivelossofcontroldataindex). |
|
||||
| `LOSS_OF_CONTROL_UPDATE` | `unitToken` (string) | The active set changed — an effect was added, fell off, or expired. Re-scan with `GetActiveLossOfControlData`. Always `"player"` (vanilla only tracks the local player), but passed so the event shape matches modern WoW and leaves room for per-unit tracking. |
|
||||
|
||||
Detection is a per-frame diff of the active set (effect *expiry* has no engine
|
||||
packet to hook), so events land within a frame of the change and coalesce
|
||||
multiple simultaneous changes into a single `LOSS_OF_CONTROL_UPDATE`. A
|
||||
counterspelled cast, for instance, fires two `ADDED` (the school lockout and,
|
||||
with Improved Counterspell, the silence) then an `UPDATE` as each expires.
|
||||
See the [LossOfControl](#lossofcontrol) section for the effect data.
|
||||
|
||||
### `MODIFIER_STATE_CHANGED` event
|
||||
|
||||
Fires on every modifier-key press and release with `(key, down)`:
|
||||
@@ -2379,6 +2496,41 @@ quests within the same engine tick, so single-add is always a real
|
||||
user accept. A brand-new character's very first quest accept
|
||||
(`0 → 1` entries) fires correctly.
|
||||
|
||||
### `QUEST_REMOVED` event
|
||||
|
||||
Fires once per quest leaving the local quest log, with the questID as
|
||||
the single payload arg. Covers **both turn-ins and abandons** — the
|
||||
two are distinguishable by whether a `QUEST_TURNED_IN` accompanies
|
||||
the removal. Polyfills modern WoW's event of the same name (added in
|
||||
8.0.1; the Classic-era signature is the bare questID, which is what
|
||||
we match).
|
||||
|
||||
```lua
|
||||
local f = CreateFrame("Frame")
|
||||
f:RegisterEvent("QUEST_REMOVED")
|
||||
f:SetScript("OnEvent", function()
|
||||
if event == "QUEST_REMOVED" then
|
||||
local questID = arg1
|
||||
-- ...
|
||||
end
|
||||
end)
|
||||
```
|
||||
|
||||
Synthesized from the same `FUN_QUEST_LOG_REBUILD` pre-/post-snapshot
|
||||
diff as `QUEST_ACCEPTED` — the removal side of the delta. For
|
||||
turn-ins, `QUEST_REMOVED` fires **after** `QUEST_TURNED_IN`, matching
|
||||
retail ordering: the SMSG_QUESTGIVER_QUEST_COMPLETE packet doesn't
|
||||
touch the log itself; the removal arrives in the follow-up quest-log
|
||||
update packets, whose rebuild triggers the diff. The observed turn-in
|
||||
sequence is `QUEST_TURNED_IN` → `UNIT_QUEST_LOG_CHANGED` →
|
||||
`QUEST_LOG_UPDATE` (fired inside the rebuild) → `QUEST_REMOVED`.
|
||||
|
||||
**Does not fire on login / character-switch resyncs.** Same
|
||||
suppression rule as `QUEST_ACCEPTED` (a user action removes at most
|
||||
one quest per rebuild), plus one extra gate: a rebuild that removes
|
||||
one quest while adding several is a cross-character resync shape, not
|
||||
gameplay, and stays silent.
|
||||
|
||||
### `QUEST_TURNED_IN` event
|
||||
|
||||
Fires when the server confirms a quest turn-in
|
||||
@@ -2930,6 +3082,84 @@ TARGETING block, the DLL splices the two `<Binding>` entries into the
|
||||
engine's `Interface\FrameXML\Bindings.xml` at file-read time via a
|
||||
hook on `FUN_FILE_READ` — see [`src/bindings/Inject.cpp`](../src/bindings/Inject.cpp).
|
||||
|
||||
## Frame
|
||||
|
||||
Modern Region/Frame method backports. Modern addon ports routinely
|
||||
call these methods unconditionally — they're the C-level frame surface
|
||||
later clients take for granted. This section is that surface on 1.12.
|
||||
Methods are registered on the engine's own per-frame-type method
|
||||
registries
|
||||
(`SetSize`/`GetSize` on the Region base, so they resolve on frames,
|
||||
buttons, textures and fontstrings alike), and each delegates to the
|
||||
engine's own implementations — UI-scale conversion, object resolution
|
||||
and type checking are all the engine's code.
|
||||
|
||||
### `region:SetPoint("point")` (one-argument form)
|
||||
|
||||
Vanilla's `SetPoint` parser accepts every modern call shape —
|
||||
`(point, region)`, `(point, region, relativePoint [, x, y])`,
|
||||
`(point, x, y)`, even an explicit `nil` region — **except** the bare
|
||||
one-argument form, which raises the usage error (a fully-omitted third
|
||||
argument fails its type validation). A co-hook on the engine's
|
||||
`Script_SetPoint` normalizes `region:SetPoint("RIGHT")` to
|
||||
`(point, 0, 0)` — vanilla's parent-relative form, which is exactly the
|
||||
modern semantic (anchor to the parent's same point, zero offsets).
|
||||
|
||||
### `region:SetSize(width, height)` / `region:GetSize()`
|
||||
|
||||
The modern combined setter/getter for `SetWidth`+`SetHeight` /
|
||||
`GetWidth`+`GetHeight`. Works on any region type — frames, buttons,
|
||||
textures (including engine-created ones like
|
||||
`button:GetNormalTexture()`), fontstrings.
|
||||
|
||||
### `frame:SetShown(shown)`
|
||||
|
||||
`Show()` if `shown` is truthy, `Hide()` otherwise. Registered for
|
||||
frames, textures and fontstrings (each branch has its own engine
|
||||
Show/Hide implementation).
|
||||
|
||||
### `frame:SetResizeBounds(minWidth, minHeight [, maxWidth, maxHeight])`
|
||||
|
||||
The modern rename of vanilla's `SetMinResize` / `SetMaxResize` pair.
|
||||
The max pair is applied only when both values are given.
|
||||
|
||||
### `frame:HookScript(scriptType, handler)`
|
||||
|
||||
Vanilla has no `HookScript` at all. This backport chains: the
|
||||
previously-set handler runs first, vanilla-style (no arguments — it
|
||||
reads the `this`/`event`/`argN` globals like every 1.12 handler), then
|
||||
`handler` is invoked **modern-style** with positional arguments:
|
||||
`(frame, event, arg1..arg9)` for `OnEvent` scripts and
|
||||
`(frame, arg1..arg9)` for everything else. That matches the compat
|
||||
convention modern addon ports expect, so handlers written as
|
||||
`function(self, ...) ... end` work unmodified. Vanilla-style handlers
|
||||
passed to `HookScript` also keep working — the globals are set as
|
||||
usual and extra arguments are simply ignored.
|
||||
|
||||
```lua
|
||||
button:HookScript("OnEnter", function(self)
|
||||
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
||||
GameTooltip:SetText("hello")
|
||||
GameTooltip:Show()
|
||||
end)
|
||||
```
|
||||
|
||||
### `frame:IsEventRegistered(event)`
|
||||
|
||||
Vanilla ships `RegisterEvent` / `UnregisterEvent` but not the query.
|
||||
Returns `true` if the frame is currently registered for `event`,
|
||||
`false` otherwise (including for an unknown event name). Reuses the
|
||||
engine's own subscriber-chain membership check — the same walk
|
||||
`RegisterEvent` performs before appending — so the answer is exactly
|
||||
what the event dispatcher sees. Works on any frame.
|
||||
|
||||
```lua
|
||||
local f = CreateFrame("Frame")
|
||||
f:RegisterEvent("PLAYER_LOGIN")
|
||||
f:IsEventRegistered("PLAYER_LOGIN") -- true
|
||||
f:IsEventRegistered("PLAYER_LOGOUT") -- false
|
||||
```
|
||||
|
||||
## FriendList
|
||||
|
||||
### `C_FriendList.SendWhoQueryByName(name)`
|
||||
@@ -5294,7 +5524,7 @@ C_Item.UseAtCursor("Iron Grenade")
|
||||
|
||||
Implementation chains the existing item-use path
|
||||
(`Item::Location::FindByArgInBags` + `FUN_ITEM_USE`) with
|
||||
[`Spell::AtCursor::Resolve`](#c_spellcastatcursorspellid) — same
|
||||
[`Spell::AtCursor::Resolve`](#c_spellcastatcursorspellidorname) — same
|
||||
cursor-resolution helper `C_Spell.CastAtCursor` uses. When the item
|
||||
fires a non-ground-target spell, the cursor leg no-ops and returns
|
||||
`false`; the item still uses normally (any implicit target — current
|
||||
@@ -5322,7 +5552,7 @@ C_Item.UseAtUnit("Iron Grenade", "player")
|
||||
Same chain as `UseAtCursor` (`Item::Location::FindByArgInBags` +
|
||||
`FUN_ITEM_USE`) but committing the placement at the unit's world
|
||||
position via
|
||||
[`Spell::AtCursor::CommitAtCoords`](#c_spellcastatunitspellid-unit)
|
||||
[`Spell::AtCursor::CommitAtCoords`](#c_spellcastatunitspellidorname-unit)
|
||||
instead of the cursor raycast. Returns `true` when the placement
|
||||
landed at the unit; `false` for non-ground-target items (the item
|
||||
still fires with any implicit target), unparseable input,
|
||||
@@ -5895,6 +6125,61 @@ tooltip display, extract the payload form via
|
||||
requires the literal `"item:"` prefix and rejects full `|cff...|Hitem...|h`
|
||||
input.
|
||||
|
||||
## LossOfControl
|
||||
|
||||
Backports `C_LossOfControl` — the active crowd-control / interrupt effects on
|
||||
the **local player**. Vanilla has no such aggregation layer (it's a Mists-era
|
||||
addition), so it's synthesized: CC types from the player's debuffs, and the
|
||||
school-interrupt lockout from the `SMSG_SPELL_COOLDOWN` the server sends on a
|
||||
Counterspell / Kick.
|
||||
|
||||
### `C_LossOfControl.GetActiveLossOfControlDataCount()`
|
||||
|
||||
Returns the number of active loss-of-control effects on the player (`0` when
|
||||
none).
|
||||
|
||||
### `C_LossOfControl.GetActiveLossOfControlData(index)`
|
||||
|
||||
Returns a `LossOfControlData` table for the `index`-th active effect (1-based,
|
||||
up to the count above), or `nil` if the index is out of range.
|
||||
|
||||
```lua
|
||||
for i = 1, C_LossOfControl.GetActiveLossOfControlDataCount() do
|
||||
local d = C_LossOfControl.GetActiveLossOfControlData(i)
|
||||
print(d.locType, d.displayText, d.timeRemaining)
|
||||
end
|
||||
```
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `locType` | string | `"STUN"`, `"FEAR"`, `"ROOT"`, `"CONFUSE"`, `"CHARM"`, `"POSSESS"`, `"SILENCE"`, `"PACIFY"`, `"PACIFYSILENCE"`, `"DISARM"`, or `"SCHOOL_INTERRUPT"`. |
|
||||
| `spellID` | number | The spell causing the effect. `0` for `SCHOOL_INTERRUPT` (the interrupting spell isn't in the lockout packet). |
|
||||
| `displayText` | string | Effect name — the spell name for CC, `"Interrupted"` for `SCHOOL_INTERRUPT`. |
|
||||
| `iconTexture` | string | The spell's icon path (vanilla has no FileDataIDs; the path is the functional equivalent). `""` for `SCHOOL_INTERRUPT`. |
|
||||
| `startTime` | number? | `GetTime()`-epoch seconds. Present for `SCHOOL_INTERRUPT` and for CC whose applying cast ClassicAPI observed; `nil` otherwise. |
|
||||
| `timeRemaining` | number? | Seconds remaining. |
|
||||
| `duration` | number? | Effect duration, in seconds. |
|
||||
| `lockoutSchool` | number | The locked spell-school mask for `SCHOOL_INTERRUPT` (feed to `C_Spell.GetSchoolString` for the name); `0` for CC effects. |
|
||||
| `priority` | number | Always `0` — no vanilla equivalent. |
|
||||
| `displayType` | number | Always `2` (show for the effect's full duration). |
|
||||
|
||||
Fidelity vs. retail:
|
||||
|
||||
- **`SCHOOL_INTERRUPT`** is derived from the server's own lockout packet
|
||||
(`Player::ProhibitSpellSchool` sends a single `SMSG_SPELL_COOLDOWN` listing
|
||||
every spell of the interrupted school at one uniform duration), so the school
|
||||
and duration are authoritative. The interrupting spell itself isn't
|
||||
transmitted, hence `spellID = 0` and `displayText = "Interrupted"`.
|
||||
- **CC timing** is best-effort — `startTime` / `timeRemaining` / `duration` are
|
||||
filled when ClassicAPI observed the cast that applied the aura (the
|
||||
`Aura::Source` cache) and are `nil` otherwise. The fields are nullable in the
|
||||
modern contract.
|
||||
- **`auraInstanceID`** is omitted (`nil`) — a Dragonflight concept with no
|
||||
vanilla equivalent.
|
||||
|
||||
The `LOSS_OF_CONTROL_ADDED` / `LOSS_OF_CONTROL_UPDATE` events fire as these
|
||||
effects change — see [Events](#loss_of_control_added--loss_of_control_update-events).
|
||||
|
||||
## Macros
|
||||
|
||||
Engine-level extensions to how macros are parsed and dispatched. These
|
||||
@@ -6171,7 +6456,71 @@ UI map ID.** Stormwind City in this backport is `1519`, not retail's
|
||||
`84`. Addons that hardcode modern UI map IDs need a translation table
|
||||
(or, simpler: compare against IDs this same function produces).
|
||||
|
||||
## MerchantFrame
|
||||
### `C_Map.GetMapOverlays([areaID])`
|
||||
|
||||
ClassicAPI extension. Returns every `WorldMapOverlay.dbc` entry for a
|
||||
zone — **explored or not** — with the tile grid fully resolved. The
|
||||
engine's own `GetNumMapOverlays` / `GetMapOverlayInfo` only expose
|
||||
overlays the character has discovered (the exploration gate is a
|
||||
server-fed list), which is why map-reveal addons traditionally ship
|
||||
hand-measured overlay tables; this replaces those with a live DBC
|
||||
read that works for every zone on any client.
|
||||
|
||||
With no argument, returns the overlays of the world map's currently
|
||||
**viewed** zone (the same continent/zone selection `GetMapInfo`
|
||||
resolves — so it drops straight into a `WorldMapFrame_Update` hook).
|
||||
With a numeric `areaID` (`AreaTable.dbc` id, the same identity
|
||||
`C_Map.GetBestMapForUnit` returns), returns that zone's overlays from
|
||||
anywhere.
|
||||
|
||||
Each overlay table:
|
||||
|
||||
| field | meaning |
|
||||
|---|---|
|
||||
| `textureName` | bare DBC name (`"GOLDSHIRE"`) |
|
||||
| `texturePath` | `Interface\WorldMap\<dir>\GOLDSHIRE` (engine format) |
|
||||
| `textureWidth` / `textureHeight` | the DBC placement rect |
|
||||
| `offsetX` / `offsetY` | placement on the zone canvas |
|
||||
| `mapPointX` / `mapPointY` | DBC map-point fields |
|
||||
| `tileCols` / `tileRows` / `upscaled` | the **resolved** tile grid |
|
||||
| `tiles` | ready-to-draw tile array (below) |
|
||||
|
||||
Each `tiles` entry: `file` (texture path including the tile number,
|
||||
`SetTexture`-ready), `width` / `height` (draw size in map pixels),
|
||||
`texCoordX` / `texCoordY` (right/bottom texcoords), `offsetX` /
|
||||
`offsetY` (absolute canvas position). Drawing an overlay is a dumb
|
||||
loop:
|
||||
|
||||
```lua
|
||||
for _, ov in ipairs(C_Map.GetMapOverlays()) do
|
||||
for _, t in ipairs(ov.tiles) do
|
||||
local tex = pool:Acquire()
|
||||
tex:SetTexture(t.file)
|
||||
tex:SetWidth(t.width) tex:SetHeight(t.height)
|
||||
tex:SetTexCoord(0, t.texCoordX, 0, t.texCoordY)
|
||||
tex:SetPoint("TOPLEFT", WorldMapDetailFrame, "TOPLEFT", t.offsetX, -t.offsetY)
|
||||
tex:Show()
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
> **Why `tiles` exists (don't derive the grid yourself).** The
|
||||
> canonical layout is `ceil(w/256) × ceil(h/256)` tiles numbered
|
||||
> row-major, and on stock 1.12 data that's always right — but Octo's
|
||||
> shipped data breaks it in three distinct ways: DBC rects that round
|
||||
> away a narrow sliver column (Icepoint's Kaneq'nuun has a real 8px
|
||||
> third column; trusting `ceil` shears the whole overlay into
|
||||
> misplaced strips), unrelated foreign tiles appended to an overlay's
|
||||
> number sequence (drawing by file count scatters duplicate landmass),
|
||||
> and same-rect re-exports at higher resolution (Stonetalon's
|
||||
> Windshear Crag: 4 real tiles for a 1-tile rect, all of which must be
|
||||
> kept and scaled). ClassicAPI disambiguates per overlay from the
|
||||
> actual BLP header dimensions via the engine's own VFS (a sweep of
|
||||
> all 707 overlays found 108 with such art/DBC mismatches), caches the
|
||||
> result for the session, and hands back tiles that are simply
|
||||
> correct. `textureWidth`/`textureHeight` remain the raw DBC rect —
|
||||
> reliable for placement; it's only the tile count they imply that
|
||||
> lies.
|
||||
|
||||
Backports the six `C_MerchantFrame.*` calls retail addons use when
|
||||
interacting with a vendor. All entry points read the engine's
|
||||
@@ -7053,6 +7402,26 @@ Reagents for Reclaimers Inc. level 40 (no tag)
|
||||
with `d.choiceItems = {{id=6793, count=1}, {id=6794, count=1}}`,
|
||||
`d.rewardMoney = 3500`, `d.rewardMoneyAtMaxLevel = 1920`, etc.
|
||||
|
||||
### `C_QuestLog.GetNumQuestObjectives(questID)`
|
||||
|
||||
The quest's objective count — exactly the length
|
||||
`GetQuestDetails(questID).requirements` would have — read straight from
|
||||
the quest cache with **no Lua tables or strings materialized**. Returns
|
||||
`nil` when the quest isn't cached (same contract as `GetQuestDetails`).
|
||||
|
||||
```lua
|
||||
local n = C_QuestLog.GetNumQuestObjectives(1467) -- 1
|
||||
```
|
||||
|
||||
Use this instead of `GetQuestDetails` when only the count matters —
|
||||
e.g. bounds-checking authored objective indices across every step of a
|
||||
guide at load time. `GetQuestDetails` copies the quest's description /
|
||||
objectives / completion text into Lua strings and builds ~20 table
|
||||
fields per call; harmless one at a time, but a login-path loop over
|
||||
hundreds of cached quests can put real pressure on vanilla's
|
||||
fixed-size Lua memory pool. This accessor costs a few dozen byte reads
|
||||
regardless of cache temperature.
|
||||
|
||||
### `C_QuestLog.IsQuestDataCachedByID(questID)`
|
||||
|
||||
Returns `true` if the quest's static data is currently in the
|
||||
@@ -8122,28 +8491,37 @@ Using this from inside a macro action slot? See
|
||||
[`CastSpellNoToggle` as a macro cast line](#castspellnotoggle-as-a-macro-cast-line) below for the additional
|
||||
parser support that makes the slot tag correctly for action-bar UIs.
|
||||
|
||||
### `C_Spell.CastAtCursor(spellID)`
|
||||
### `C_Spell.CastAtCursor(spellIDOrName)`
|
||||
|
||||
Casts a ground-target spell at the player's current cursor world
|
||||
position, bypassing the manual click on the AoE reticle the engine
|
||||
would otherwise require. ClassicAPI's analog of modern's
|
||||
`/cast [@cursor] Blizzard`. Returns `true` when the cursor-placement
|
||||
leg landed; `false` for non-ground-target spells (cast still fires
|
||||
normally on the current target), unknown spellIDs, cursor over UI /
|
||||
normally on the current target), unknown spells, cursor over UI /
|
||||
off-screen, etc.
|
||||
|
||||
Accepts a **spellID** or a **spell name**:
|
||||
|
||||
```lua
|
||||
C_Spell.CastAtCursor(10) -- Blizzard rank 1 at cursor
|
||||
C_Spell.CastAtCursor(2120) -- Flamestrike rank 1 at cursor
|
||||
C_Spell.CastAtCursor(10) -- Blizzard Rank 1 (exact spellID)
|
||||
C_Spell.CastAtCursor(2120) -- Flamestrike Rank 1
|
||||
C_Spell.CastAtCursor("Blizzard") -- highest known rank
|
||||
C_Spell.CastAtCursor("Blizzard(Rank 6)") -- that specific rank
|
||||
```
|
||||
|
||||
A **numeric** spellID casts that *exact* spell — every rank is its own
|
||||
spellID, so `10` casts Blizzard Rank 1 (not the highest known rank). A
|
||||
**name** goes through the engine's own resolver, which parses a trailing
|
||||
`(Rank N)`; a bare name casts the highest rank you know.
|
||||
|
||||
Two-stage internally:
|
||||
|
||||
1. Initiates the cast through the same path
|
||||
[`CastSpellByName`](docs/API.md#numeric-spellids-in-cast-and-castspellbyname)
|
||||
uses (`FUN_RESOLVE_SPELL_NAME_TO_SLOT` + the engine's cast
|
||||
dispatcher). If the spell needs a ground target, the engine
|
||||
enters placement mode and arms the AoE reticle.
|
||||
1. Initiates the cast: a numeric spellID resolves to its exact spellbook
|
||||
slot (`Spell::Lookup::FindSpellbookSlot`, so the requested rank is the one
|
||||
that fires), a name goes through `FUN_RESOLVE_SPELL_NAME_TO_SLOT`; either
|
||||
way it dispatches through the engine's cast dispatcher. If the spell needs
|
||||
a ground target, the engine enters placement mode and arms the AoE reticle.
|
||||
|
||||
2. Refreshes the cursor's screen→world raycast via
|
||||
`FUN_REFRESH_CURSOR_RAYCAST` (the same internal the engine fires
|
||||
@@ -8162,24 +8540,28 @@ The companion item version is
|
||||
[`C_Item.UseAtCursor`](#c_itemuseatcursoriteminfo) — same chain via
|
||||
the item-use path for grenades / on-use ground-target items.
|
||||
|
||||
### `C_Spell.CastAtUnit(spellID, unit)`
|
||||
### `C_Spell.CastAtUnit(spellIDOrName, unit)`
|
||||
|
||||
Casts a ground-target spell at `unit`'s feet, bypassing the AoE
|
||||
reticle click. ClassicAPI's analog of modern's
|
||||
`/cast [@unit] Flamestrike` — `CastAtUnit(spellID, "player")` drops it
|
||||
`/cast [@unit] Flamestrike` — `CastAtUnit(spell, "player")` drops it
|
||||
at the player's position, `"target"` at the target's, and so on for
|
||||
any unit token (`"mouseover"`, `"party1"`, `"raid7"`, …). Returns
|
||||
`true` when the placement landed at the unit; `false` for
|
||||
non-ground-target spells (cast still fires normally), unknown
|
||||
spellIDs, or a unit with no resolvable position.
|
||||
spells, or a unit with no resolvable position.
|
||||
|
||||
The first argument takes a spellID or a spell name, with the same
|
||||
exact-rank / `(Rank N)` semantics as `CastAtCursor`.
|
||||
|
||||
```lua
|
||||
C_Spell.CastAtUnit(2120, "target") -- Flamestrike at the target's feet
|
||||
C_Spell.CastAtUnit(10, "player") -- Blizzard centered on yourself
|
||||
C_Spell.CastAtUnit(2120, "target") -- Flamestrike at the target's feet
|
||||
C_Spell.CastAtUnit(10, "player") -- Blizzard Rank 1 on yourself
|
||||
C_Spell.CastAtUnit("Blizzard(Rank 6)", "target")
|
||||
```
|
||||
|
||||
Same two-stage shape as
|
||||
[`C_Spell.CastAtCursor`](#c_spellcastatcursorspellid), but instead of
|
||||
[`C_Spell.CastAtCursor`](#c_spellcastatcursorspellidorname), but instead of
|
||||
the cursor raycast, step 2 reads the unit's world position from its
|
||||
`GetPosition` virtual (the same one `CheckInteractDistance` /
|
||||
`UnitInRange` use) and commits placement there via
|
||||
@@ -8268,18 +8650,28 @@ so progress is `(GetTime()*1000 - startTimeMs) / (endTimeMs - startTimeMs)`.
|
||||
> another unit's cast with a server-authoritative cast time, cached per
|
||||
> caster GUID. So `C_Spell.UnitCastingInfo("target")` now backs
|
||||
> enemy/target/focus/nameplate cast bars. Instant casts return `nil` (no
|
||||
> cast bar). Best-effort for remote units, in three ways: only casts that
|
||||
> began while the unit was in range are seen; since 1.12 has no per-unit
|
||||
> interrupt packet to hook, an *interrupted* remote cast lingers until its
|
||||
> computed `endTimeMs` rather than clearing instantly; and the remote
|
||||
> `startTimeMs`/`endTimeMs` are shifted later by roughly your latency.
|
||||
> (1.12's `SMSG_SPELL_START` carries only a single `castTime`, so we stamp
|
||||
> `start = now, end = now + castTime` on receipt. 3.3.5+ avoids the skew
|
||||
> because its packet carries *both* total and remaining cast time and
|
||||
> back-dates `start = now − elapsed`; the 1.12 packet has no field to
|
||||
> recover `elapsed` from.) The **local player is unaffected** by all of
|
||||
> this — its cast is detected client-side at the moment of cast, no packet
|
||||
> involved.
|
||||
> cast bar). Aborted remote casts (interrupt, death, movement, cancel)
|
||||
> clear the same tick — a co-hook on the engine's own
|
||||
> `CGUnit_C::ClearCastingSpell` (the choke point every "unit stopped
|
||||
> casting" path funnels through) evicts the cached cast the moment the
|
||||
> engine stops the unit's cast visual, backstopped by co-hooks on the
|
||||
> `SMSG_SPELL_FAILURE` / `SMSG_SPELL_FAILED_OTHER` packets for servers
|
||||
> that broadcast them (Turtle's core doesn't — its interrupt propagation
|
||||
> reaches observers through SuperWoW, which the choke-point hook catches
|
||||
> too). Verified: Kick / Earth Shock / Counterspell each clear the
|
||||
> victim's bar, while non-interrupting damage doesn't false-clear it.
|
||||
> Best-effort for remote units, in three ways: only casts that began while
|
||||
> the unit was in range are seen; the remote `startTimeMs`/`endTimeMs` are
|
||||
> shifted later by roughly your latency (1.12's `SMSG_SPELL_START` carries
|
||||
> only a single `castTime`, so we stamp `start = now, end = now + castTime`
|
||||
> on receipt — 3.3.5+ avoids the skew because its packet carries *both*
|
||||
> total and remaining cast time and back-dates `start = now − elapsed`;
|
||||
> the 1.12 packet has no field to recover `elapsed` from); and remote
|
||||
> **pushback is invisible** — the server sends `SMSG_SPELL_DELAYED` only
|
||||
> to the affected caster, so another unit's bar can't stretch when they
|
||||
> take damage. The **local player is unaffected** by all of this — its
|
||||
> cast is detected client-side at the moment of cast, no packet involved,
|
||||
> and its pushback is tracked.
|
||||
>
|
||||
> `isTradeskill` is real — the spell's `SPELL_ATTR_TRADESPELL` flag, so
|
||||
> profession recipe casts (smelting, cooking/enchanting recipes, …)
|
||||
@@ -9049,6 +9441,95 @@ wall-clock time). Returns 0 if called before login.
|
||||
> midnight, not UTC midnight (though they happen to coincide for
|
||||
> Turtle WoW since the server reports UTC-aligned components).
|
||||
|
||||
## TradeSkillUI
|
||||
|
||||
Backports the 2.x+ **trade-skill list link** — the shareable
|
||||
`|Htrade:...|h[Profession]|h` link that shows a player's profession and
|
||||
which recipes they know. Vanilla 1.12 has no such link type (the engine's
|
||||
hyperlink parser only knows `item:` and `enchant:`), so both the link and the
|
||||
click-to-view UI are synthesized. Clicking a received link opens a
|
||||
crafting-window-style frame (the real `TradeSkillFrame` parchment art) listing
|
||||
the recipes the linker knows — difficulty-coloured and sorted high-craft-first
|
||||
— with a skill-rank bar and an "X of Y recipes known" summary.
|
||||
|
||||
The "known recipes" data is a bitfield over the skill line's **canonical
|
||||
recipe list** — every `SkillLineAbility.dbc` row for the skill line that is a
|
||||
craftable recipe, in ascending record-ID order. That ordering is identical on
|
||||
every client with the same DBC, so the sender and reader agree on the
|
||||
bit-index space with no handshake. Whether the sender knows a given recipe
|
||||
comes from the same player-spell bitmap `IsPlayerSpell` reads (which covers
|
||||
profession recipes), so the link is self-contained — the reader needs neither
|
||||
the sender online nor the profession itself.
|
||||
|
||||
### `C_TradeSkillUI.GetTradeSkillListLink()`
|
||||
|
||||
Returns the `|Htrade:...|h` link for the **currently-open** trade skill
|
||||
window, or `nil` if no profession window is open.
|
||||
|
||||
```lua
|
||||
-- with a profession window open:
|
||||
local link = C_TradeSkillUI.GetTradeSkillListLink()
|
||||
-- "|cffffd000|Htrade:164:300:300:Bob:eE0C...|h[Blacksmithing]|h|r"
|
||||
ChatEdit_InsertLink(link) -- or SendChatMessage(link, "GUILD"), etc.
|
||||
```
|
||||
|
||||
Built entirely in the DLL — no addon wiring. The window only needs to be open
|
||||
long enough to identify the profession; the recipe data is read from the spell
|
||||
bitmap, not the window's server list. Wire format (a ClassicAPI-private shape
|
||||
modeled on the 2.x link, with the linker's name in the slot 2.x used for the
|
||||
GUID):
|
||||
|
||||
```
|
||||
|cffffd000|Htrade:<skillLineID>:<curRank>:<maxRank>:<linkerName>:<base64 bits>|h[Name]|h|r
|
||||
```
|
||||
|
||||
`skillLineID` is the `SkillLine.dbc` row (164 = Blacksmithing); `curRank` /
|
||||
`maxRank` are the linker's skill level (cosmetic); `linkerName` is the linking
|
||||
character's name (shown in the viewer title); the base64 tail packs 6 recipes
|
||||
per character, LSB-first. Links from before this field was added (no
|
||||
`linkerName`) still decode — the viewer just omits the name from its title.
|
||||
|
||||
Clicking a `trade:` link is handled automatically (an override of
|
||||
`SetItemRef`) — it opens the recipe viewer. No addon wiring needed.
|
||||
|
||||
### `C_TradeSkillUI.GetCraftListLink()`
|
||||
|
||||
Same as `GetTradeSkillListLink`, but for the **Craft window** — vanilla's
|
||||
separate profession frame used by Enchanting and pet training. Returns `nil`
|
||||
unless `CraftFrame` is shown. The two windows have separate storage and can be
|
||||
open simultaneously, so they get separate builders (matching WotLK); the
|
||||
resulting link is the same `|Htrade:...|h` format and opens the same viewer.
|
||||
|
||||
```lua
|
||||
local link = C_TradeSkillUI.GetCraftListLink() -- with the enchanting window open
|
||||
-- "|cffffd000|Htrade:333:300:300:Bob:...|h[Enchanting]|h|r"
|
||||
```
|
||||
|
||||
### `C_TradeSkillUI.GetTradeSkillListRecipes(skillLineID, bits)`
|
||||
|
||||
Decodes a link's bitfield against a skill line's canonical recipe list.
|
||||
Returns an array table:
|
||||
|
||||
```lua
|
||||
local recipes = C_TradeSkillUI.GetTradeSkillListRecipes(164, "eE0C...")
|
||||
-- recipes[i] = { spellID, isKnown, trivialLevel, greenLevel, createdItem }
|
||||
for i = 1, table.getn(recipes) do
|
||||
local name = GetSpellInfo(recipes[i].spellID)
|
||||
print(name, recipes[i].isKnown and "known" or "unknown")
|
||||
end
|
||||
```
|
||||
|
||||
`trivialLevel` / `greenLevel` are the skill levels the recipe turns grey /
|
||||
green at — the recipe's difficulty band, coloured against the linker's skill
|
||||
exactly as the default UI does (the required-skill field is uselessly `1` for
|
||||
nearly every trainer-taught recipe). `createdItem` is the crafted item's ID
|
||||
(`0` for enchants), which the viewer uses to build its subclass filter.
|
||||
|
||||
The array is in canonical recipe order (one entry per *possible* recipe in the
|
||||
skill line, not just the known ones). Turn a `spellID` into a name/icon with
|
||||
[`GetSpellInfo`](#getspellinfospellid). Recipes past the end of a short/garbled
|
||||
`bits` string decode as not-known rather than erroring.
|
||||
|
||||
## UIColor
|
||||
|
||||
### `C_UIColor.GetColors()`
|
||||
@@ -9728,6 +10209,38 @@ a non-English client, pass the localized name — addons that
|
||||
hard-code English names should use `GetUnitAuraBySpellID`
|
||||
instead for portability.
|
||||
|
||||
### `C_UnitAuras.RegisterComboDuration(spellID, baseSeconds, maxSeconds)`
|
||||
|
||||
ClassicAPI extension — **you normally never call this**. Overrides the
|
||||
combo-point duration data for one spellID, for servers whose values
|
||||
differ from (or are missing in) the client's `SpellDuration.dbc`.
|
||||
Returns `true` on success; re-registering a spellID replaces its entry.
|
||||
|
||||
Background: combo-point finishers (Rupture, Kidney Shot, Slice and
|
||||
Dice, …) get their real duration computed **server-side** at cast time
|
||||
as `base + (max − base) × comboPoints / 5`, and 1.12 never transmits
|
||||
the result for debuffs the player puts on other units (verified with a
|
||||
whole-protocol packet capture). ClassicAPI therefore mirrors the
|
||||
computation automatically: it snapshots your combo points the instant
|
||||
the cast request leaves the client and applies the same formula from
|
||||
the spell's own `SpellDuration.dbc` row, so `duration`/
|
||||
`expirationTime` in every `AuraData` are combo-accurate out of the box
|
||||
— Rupture at 4 CP reads 14s, not the 6s base. Your duration talents
|
||||
apply on top, in the server's order. No registration involved.
|
||||
|
||||
The override exists only for spells whose client DBC data is missing
|
||||
or wrong on a specific server. The known case — Turtle's reworked Rip
|
||||
(8s + 2s per combo point), whose SpellDuration row exists on the
|
||||
server only — is built into ClassicAPI and gated on the client-data
|
||||
bug itself: the fallback applies only while the spell's DurationIndex
|
||||
points at a SpellDuration row the client doesn't have (a condition
|
||||
unique to Rip on Turtle's client; on a stock client Rip's index
|
||||
resolves normally, and if Turtle ever ships the missing row, the DBC
|
||||
takes over automatically). No realm detection involved. This function
|
||||
is the escape hatch for *other* custom servers with the same class of
|
||||
gap — call it from your own config or addon; a registered override
|
||||
beats both the DBC and the built-in values.
|
||||
|
||||
### `C_UnitAuras.GetUnitAuras(unit [, filter])`
|
||||
|
||||
Returns a numerically-indexed array of `AuraData` tables for every
|
||||
@@ -9763,3 +10276,197 @@ builds. So the returned value carries the mixin methods
|
||||
`.r/.g/.b/.a` fields. Falls back to a plain `{r,g,b,a}` table if
|
||||
`CreateColor` isn't loaded yet (shouldn't happen — `!!!ClassicAPI`
|
||||
loads first thanks to the triple-`!` prefix).
|
||||
|
||||
## VoiceChat
|
||||
|
||||
Backport of modern WoW's text-to-speech surface — the `C_VoiceChat` and
|
||||
`C_TTSSettings` namespaces — backed by **Windows SAPI** (the OS speech
|
||||
engine). All playback is **local** (rendered on your own machine);
|
||||
vanilla 1.12 has no voice-chat transport, so there is nothing "remote" to
|
||||
transmit synthesized speech into.
|
||||
|
||||
> **Coexistence with VanillaTTS:** the same surface also ships as the
|
||||
> standalone [VanillaTTS](https://github.com/brues-code/VanillaTTS) DLL,
|
||||
> which adds a software-synth backend for Wine. If `VanillaTTS.dll` is
|
||||
> loaded in the same client, this built-in module stands down automatically
|
||||
> (registers none of the functions, events, or cvars below) and VanillaTTS
|
||||
> provides them instead — the Lua-visible API is identical either way, so
|
||||
> addons don't need to care which one is active.
|
||||
|
||||
SAPI is created lazily on first use. If SAPI is unavailable (e.g. running
|
||||
the client under Wine, or a stripped Windows), every call degrades
|
||||
gracefully: `GetTtsVoices` returns an empty table, `SpeakText` fires
|
||||
`VOICE_CHAT_TTS_PLAYBACK_FAILED` and does nothing, and the client stays
|
||||
stable — there is no crash. Install more voices under **Windows Settings →
|
||||
Time & Language → Speech**, then call `C_TTSSettings.RefreshVoices()`.
|
||||
|
||||
### `C_VoiceChat.GetTtsVoices()` / `C_VoiceChat.GetRemoteTtsVoices()`
|
||||
|
||||
Return a numerically-indexed array of voice tables — one per SAPI voice
|
||||
installed on the machine:
|
||||
|
||||
```lua
|
||||
for _, v in ipairs(C_VoiceChat.GetTtsVoices()) do
|
||||
print(v.voiceID, v.name) -- e.g. 0 "Microsoft David Desktop - English (United States)"
|
||||
end
|
||||
```
|
||||
|
||||
Each entry is `{ voiceID = <0-based index>, name = <display name> }`. The
|
||||
`voiceID` is the index you pass to `SpeakText` and store via
|
||||
`C_TTSSettings.SetVoiceOption`. `GetRemoteTtsVoices` is an alias returning
|
||||
the same local list (kept for API parity — vanilla has no voice chat).
|
||||
Calling either refreshes the cached voice list and fires
|
||||
`VOICE_CHAT_TTS_VOICES_UPDATE` if it changed.
|
||||
|
||||
### `C_VoiceChat.SpeakText(voiceID, text [, destination, rate, volume])`
|
||||
|
||||
Speaks `text` aloud using the SAPI voice at index `voiceID`.
|
||||
|
||||
```lua
|
||||
C_VoiceChat.SpeakText(
|
||||
C_TTSSettings.GetSpeechVoiceID(), -- use the configured voice
|
||||
UnitName("target") or "no target")
|
||||
```
|
||||
|
||||
- **`voiceID`** (number, required) — index into `GetTtsVoices()`. Note this
|
||||
is an **explicit argument** — `SpeakText` does *not* read the `ttsVoice`
|
||||
cvar itself, matching Blizzard's contract. Pass
|
||||
`C_TTSSettings.GetSpeechVoiceID()` to honor the configured default.
|
||||
- **`text`** (string, required) — UTF-8; spoken as-is.
|
||||
- **`destination`** (number, optional, default `1`) — `1` =
|
||||
`LOCAL_PLAYBACK`, `4` = `QUEUED_LOCAL_PLAYBACK`. Accepted for parity;
|
||||
both queue FIFO through SAPI (no app-side queue).
|
||||
- **`rate`** (number, optional, default `0`) — speech rate, clamped to
|
||||
`[-10, 10]`.
|
||||
- **`volume`** (number, optional, default `100`) — clamped to `[0, 100]`.
|
||||
|
||||
Speech is asynchronous. The call returns immediately and fires
|
||||
`VOICE_CHAT_TTS_PLAYBACK_STARTED` when SAPI begins the utterance and
|
||||
`VOICE_CHAT_TTS_PLAYBACK_FINISHED` when it completes (or
|
||||
`..._PLAYBACK_FAILED` if the voice/engine is unavailable). Raises a Lua
|
||||
error if `voiceID` isn't a number or `text` isn't a string.
|
||||
|
||||
### `C_VoiceChat.StopSpeakingText()`
|
||||
|
||||
Stops and purges everything currently playing or queued.
|
||||
|
||||
### `C_TTSSettings` — getters & setters
|
||||
|
||||
The settings store (separate from `SpeakText`, which takes its parameters
|
||||
explicitly). All three values are backed by CVars (see below), so they
|
||||
**persist across sessions** and are clamped to valid ranges on write.
|
||||
|
||||
| Function | Returns / effect |
|
||||
|---|---|
|
||||
| `C_TTSSettings.GetSpeechRate()` | configured rate, `[-10, 10]` (default `0`) |
|
||||
| `C_TTSSettings.GetSpeechVolume()` | configured volume, `[0, 100]` (default `100`) |
|
||||
| `C_TTSSettings.GetSpeechVoiceID()` | configured voice index (default `0`) |
|
||||
| `C_TTSSettings.GetVoiceOptionName()` | display name of the configured voice, or `""` |
|
||||
| `C_TTSSettings.SetSpeechRate(rate)` | set rate (clamped) |
|
||||
| `C_TTSSettings.SetSpeechVolume(volume)` | set volume (clamped) |
|
||||
| `C_TTSSettings.SetVoiceOption(voiceID)` | set the voice by index (clamped to installed count) |
|
||||
| `C_TTSSettings.SetVoiceOptionByName(name)` | set the voice by display name (case-insensitive exact match) |
|
||||
| `C_TTSSettings.SetDefaultSettings()` | reset to voice `1` (if present, else `0`), rate `0`, volume `100` |
|
||||
| `C_TTSSettings.RefreshVoices()` | re-enumerate SAPI voices; fires `VOICE_CHAT_TTS_VOICES_UPDATE` if the list changed |
|
||||
|
||||
```lua
|
||||
C_TTSSettings.SetVoiceOptionByName("Microsoft Zira Desktop - English (United States)")
|
||||
C_TTSSettings.SetSpeechVolume(150) -- clamps to 100
|
||||
print(C_TTSSettings.GetVoiceOptionName()) -- "Microsoft Zira Desktop - ..."
|
||||
```
|
||||
|
||||
### TTS events
|
||||
|
||||
Registered like any engine event (`frame:RegisterEvent("VOICE_CHAT_TTS_PLAYBACK_STARTED")`).
|
||||
|
||||
| Event | Args |
|
||||
|---|---|
|
||||
| `VOICE_CHAT_TTS_PLAYBACK_STARTED` | `numConsumers` (number), `utteranceID` (number), `durationMS` (number, always `0`), `destination` (number) |
|
||||
| `VOICE_CHAT_TTS_PLAYBACK_FINISHED` | `numConsumers` (number), `utteranceID` (number), `destination` (number) |
|
||||
| `VOICE_CHAT_TTS_PLAYBACK_FAILED` | `status` (string — e.g. `"EngineAllocationFailed"`, `"InternalError"`), `utteranceID` (number), `destination` (number) |
|
||||
| `VOICE_CHAT_TTS_VOICES_UPDATE` | *(none)* — the installed-voice list changed |
|
||||
| `VOICE_CHAT_TTS_SPEAK_TEXT_UPDATE` | reserved for parity; not currently fired |
|
||||
|
||||
`utteranceID` correlates the START/FINISHED/FAILED events for a given
|
||||
`SpeakText` call. `PLAYBACK_FINISHED` fires only when playback actually
|
||||
completes, so it's the signal to start the next utterance in a queue.
|
||||
|
||||
### TTS CVars
|
||||
|
||||
The `C_TTSSettings` values are stored as engine CVars, persisted to
|
||||
`WTF\Config.wtf`. You can also read/write them with the standard
|
||||
`GetCVar`/`SetCVar` (or `/console set`); writes are clamped by the same
|
||||
validation:
|
||||
|
||||
| CVar | Default | Range | Backing setting |
|
||||
|---|---|---|---|
|
||||
| `ttsVoice` | `0` | `[0, voiceCount-1]` | `GetSpeechVoiceID` / `SetVoiceOption` |
|
||||
| `ttsSpeed` | `0` | `[-10, 10]` | `GetSpeechRate` / `SetSpeechRate` |
|
||||
| `ttsVolume` | `100` | `[0, 100]` | `GetSpeechVolume` / `SetSpeechVolume` |
|
||||
|
||||
## XMLUtil
|
||||
|
||||
### `C_XMLUtil.GetTemplates()`
|
||||
|
||||
Returns an array of every registered **virtual XML template** — the
|
||||
`virtual="true"` frames that `inherits=` targets — one entry per template:
|
||||
|
||||
```lua
|
||||
for _, t in ipairs(C_XMLUtil.GetTemplates()) do
|
||||
print(t.name, t.type) -- e.g. "UIPanelButtonTemplate" "Button"
|
||||
end
|
||||
```
|
||||
|
||||
Each entry is `{ name = <string>, type = <frameType> }`, where `type` is the
|
||||
XML element tag the template was declared with (`"Frame"`, `"Button"`,
|
||||
`"CheckButton"`, `"StatusBar"`, …).
|
||||
|
||||
The list is read straight from the engine's virtual-template registry — the
|
||||
same store the XML loader fills for `inherits=` — so it covers every template
|
||||
currently loaded from **both** Blizzard FrameXML and addon `.xml` files, and is
|
||||
rebuilt on `/reload`. Font templates live in a separate registry and are not
|
||||
included (matching retail, where `GetTemplates` returns frame templates).
|
||||
Returns an empty table if no template has registered yet.
|
||||
|
||||
> **Note (vanilla vs. retail):** retail's `XMLTemplateListInfo` carries only
|
||||
> the `name` and `type` fields, both provided here. There's no filtering —
|
||||
> every virtual template is returned, in hash-table order (not load or
|
||||
> alphabetical order).
|
||||
|
||||
### `C_XMLUtil.GetTemplateInfo(name)`
|
||||
|
||||
Returns an `XMLTemplateInfo` table for the named template, or `nil` if no
|
||||
template of that name is registered:
|
||||
|
||||
```lua
|
||||
local info = C_XMLUtil.GetTemplateInfo("StatFrameTemplate")
|
||||
-- { type = "Frame", width = 104, height = 13, keyValues = {}, inherits = nil }
|
||||
```
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `type` | string | The template's frame type — its XML element tag (`"Frame"`, `"Button"`, …). |
|
||||
| `width` / `height` | number | The size **statically declared on the template itself** via a `<Size>` element, or `0` if it declares none (including when the size comes from an inherited template rather than a direct `<Size>`). |
|
||||
| `keyValues` | table | Always an **empty table** in 1.12 — the vanilla XML schema has no `<KeyValues>` element, so no template can carry key/value pairs. Present for API parity. |
|
||||
| `inherits` | string? | The template's `inherits=` attribute (a comma-delimited list), or `nil` if it inherits nothing. |
|
||||
|
||||
Lookup is by name through the engine's own template registry — the same
|
||||
resolution `inherits=` uses — so it's case-insensitive and covers both
|
||||
Blizzard FrameXML and addon templates.
|
||||
|
||||
> **Not provided:** retail's `sourceLocation` field (file:line where the
|
||||
> template was defined) is a 10.2.0 addition; vanilla records no source
|
||||
> location for XML nodes, so the field is omitted (reads as `nil`).
|
||||
|
||||
### `C_XMLUtil.DoesTemplateExist(name)`
|
||||
|
||||
Returns `true` if a virtual template of that name is registered, `false`
|
||||
otherwise:
|
||||
|
||||
```lua
|
||||
if C_XMLUtil.DoesTemplateExist("MyAddonRowTemplate") then
|
||||
button = CreateFrame("Button", nil, parent, "MyAddonRowTemplate")
|
||||
end
|
||||
```
|
||||
|
||||
Case-insensitive, resolved through the same registry as `inherits=`.
|
||||
|
||||
+537
-25
@@ -542,7 +542,99 @@ enum Offsets {
|
||||
// addon's CHAT_MSG_* OnEvent.
|
||||
FUN_CHAT_DISPATCH = 0x0049A870,
|
||||
// Per-player inventory manager lives at this offset on the player object.
|
||||
// +0x00 = u32 slot count (OFF_INVMGR_SLOT_COUNT), +0x04 = u64* GUID
|
||||
// array (see OFF_INVMGR_GUID_ARRAY below for the slot-range map).
|
||||
OFF_PLAYER_INVENTORY_MANAGER = 0x1D38,
|
||||
OFF_INVMGR_SLOT_COUNT = 0x00,
|
||||
|
||||
// --- Descriptor-field observer system --------------------------------
|
||||
// The engine's generic "watch a descriptor field range for changes"
|
||||
// mechanism (nodes tagged "__AUCMirrorHandler__", 0x30 bytes). The
|
||||
// registrar attaches a node to the object's per-field observer anchors;
|
||||
// each node keeps a private MIRROR of the watched bytes, seeded from
|
||||
// the live value at registration. During SMSG_UPDATE_OBJECT processing
|
||||
// the dispatcher FUN_00465570 memcmps live vs mirror and invokes the
|
||||
// callback only on a real change (the mirror is then re-synced by
|
||||
// FUN_004667A0). Firing engine events from the callback is sanctioned —
|
||||
// the engine's own bag observer does exactly that.
|
||||
//
|
||||
// Registrar — __fastcall(int bank /*ecx*/, uint32_t fieldOffset /*edx*/,
|
||||
// uint32_t guidLo, uint32_t guidHi, int size, const void *callback,
|
||||
// void *userArg1, void *userArg2). `guid` selects the watched OBJECT
|
||||
// (player, item, container, …); `bank` selects its field bank
|
||||
// (1 = ITEM, 2 = CONTAINER, 4 = PLAYER — the engine's per-bag
|
||||
// manager FUN_004F91A0 registers bank-2 observers on each equipped
|
||||
// bag's CGContainer); `fieldOffset` is BANK-relative (container
|
||||
// SLOT_1 = 8, not its descriptor-absolute 0x20). The engine's
|
||||
// inventory setup FUN_004F8CC0 registers the player's bag/backpack/
|
||||
// bank/keyring GUID ranges this way — but NOT equipment.
|
||||
FUN_DESC_OBSERVER_REGISTER = 0x00467E70,
|
||||
|
||||
// Unregister — __fastcall(int bank /*ecx*/, uint32_t fieldOffset
|
||||
// /*edx*/, uint32_t guidLo, uint32_t guidHi, const void *callback,
|
||||
// void *userArg1). Removes the node matching (callback, userArg1)
|
||||
// from that object+field's observer list; harmless no-op when
|
||||
// nothing matches. What FUN_004F91A0 calls for an unequipped bag.
|
||||
FUN_DESC_OBSERVER_UNREGISTER = 0x00467FB0,
|
||||
|
||||
// Observer callback ABI (verified from the dispatcher's call site at
|
||||
// 0x004655DC + the engine callback FUN_004F8DB0's RET 0x10):
|
||||
// int __fastcall cb(uint32_t fieldOffset /*ecx, as registered*/,
|
||||
// uint32_t size /*edx*/,
|
||||
// uint32_t guidLo, uint32_t guidHi,
|
||||
// const uint32_t *oldValue /*the node's mirror*/,
|
||||
// void *userArg1) → return 1, callee cleans 0x10.
|
||||
// The live (new) value is NOT passed — read it from the object (the
|
||||
// engine's bag callback reads the invMgr GUID array).
|
||||
|
||||
// The engine's inventory observer setup — registers the bag-slot
|
||||
// GUID-field observers above, once per enter-world (sole caller is the
|
||||
// enter-world initializer FUN_004908C0, latched by DAT_00B4B424).
|
||||
// Player::Equipment co-hooks it to register the equipment-slot
|
||||
// observers the engine never installs; the co-hook inherits the exact
|
||||
// engine timing + lifetime (nodes die with the player object).
|
||||
FUN_INV_OBSERVER_SETUP = 0x004F8CC0,
|
||||
|
||||
// PLAYER_FIELD_INV_SLOT_HEAD — first of the 19 equipment-slot u64 GUID
|
||||
// fields in the player descriptor (0x4A8..0x538, stride 8; 0x540 is
|
||||
// the first equipped-bag slot). 0-based slot = (offset - 0x4A8) >> 3;
|
||||
// Lua inventory slot (GetInventoryItemLink etc.) = that + 1.
|
||||
OFF_DESC_PLAYER_EQUIP_FIRST = 0x4A8,
|
||||
DESC_PLAYER_EQUIP_SLOTS = 19,
|
||||
DESC_OBSERVER_BANK_PLAYER = 4,
|
||||
|
||||
// ITEM_FIELD_DURABILITY, ITEM-bank-relative: descriptor-absolute
|
||||
// +0xA0 (field index 0x28, which counts the 6 OBJECT fields) minus
|
||||
// the 0x18-byte OBJECT prefix. u32.
|
||||
//
|
||||
// DEAD END — bank-1 (ITEM field) observers register without error but
|
||||
// are NEVER invoked: item values-updates demonstrably arrive
|
||||
// (verified by probing the values pre-pass FUN_00465330) and
|
||||
// player-bank observers fire in the same session, yet item-bank
|
||||
// callbacks stay silent. Registration arithmetic was fully verified
|
||||
// (bank base FUN_00465690(1)=0x18, next-bank walk FUN_004656E0
|
||||
// item: 0→1→2, anchors match dispatch), so the suspect is the
|
||||
// registrar's internal wrapper lookup (FUN_00464890 — the observer
|
||||
// registry, NOT the object manager) silently no-op'ing for item
|
||||
// objects. UPDATE_INVENTORY_DURABILITY is instead backed by
|
||||
// FUN_INVENTORY_ALERTS_RECOMPUTE below. Constants kept for the
|
||||
// investigation trail.
|
||||
DESC_OBSERVER_BANK_ITEM = 1,
|
||||
OFF_DESC_ITEM_DURABILITY = 0x88,
|
||||
|
||||
// The engine's inventory-alerts recompute — walks the equipment
|
||||
// slots, reads each item's ITEM_FIELD_DURABILITY / MAXDURABILITY /
|
||||
// broken flag from the descriptor, fills the per-slot alert table at
|
||||
// [DAT_00B71F60], and UNCONDITIONALLY fires UPDATE_INVENTORY_ALERTS
|
||||
// (event 501) at the end. The engine calls it whenever an owned
|
||||
// item's fields change (the item post-update handler FUN_005D9A90 —
|
||||
// which also fires UNIT_INVENTORY_CHANGED and the bag-update chain —
|
||||
// routes every item values-update through it) plus equip and
|
||||
// enter-world paths. That makes it the engine's own "durability may
|
||||
// have changed" signal: Player::Equipment co-hooks it and diffs a
|
||||
// {guid, durability} snapshot per slot to back
|
||||
// UPDATE_INVENTORY_DURABILITY. void __fastcall(), no args.
|
||||
FUN_INVENTORY_ALERTS_RECOMPUTE = 0x004C7EE0,
|
||||
// ItemMgr::GetItemBySlot — __thiscall(this, slot) → CGItem* (NULL if empty).
|
||||
// Slot is the engine's linearized slot index, not bagID/slot tuple.
|
||||
FUN_ITEMMGR_GET_ITEM_BY_SLOT = 0x006228A0,
|
||||
@@ -870,12 +962,231 @@ enum Offsets {
|
||||
|
||||
// `SMSG_SPELL_DELAYED` handler — `int __stdcall(uint32_t *opCode,
|
||||
// CDataStore *packet)`. Body: `guid(u64), delayMs(u32)`. The server
|
||||
// only sends this to the affected caster, so in practice it's always
|
||||
// the local player's cast pushback (taking damage mid-cast). `Spell::
|
||||
// Cast` co-hooks it to extend the tracked cast's end time so the bar
|
||||
// reflects pushback. Mirrored from nampower's SpellDelayedHook.
|
||||
// only sends this to the affected caster — empirically confirmed on
|
||||
// Turtle (melee-pushback test: only the victim's client received it) —
|
||||
// so remote units' pushback is NOT recoverable client-side; only the
|
||||
// local player's cast pushback is trackable. `Spell::Cast` co-hooks it
|
||||
// to extend the tracked cast's end time so the bar reflects pushback.
|
||||
// Mirrored from nampower's SpellDelayedHook.
|
||||
FUN_SPELL_DELAYED = 0x006E74F0,
|
||||
|
||||
// `MSG_CHANNEL_START` handler — `int __stdcall(uint32_t *opCode,
|
||||
// CDataStore *packet)`. Body: `spellId(u32), durationMs(u32)`. Sent
|
||||
// only to the caster when their channel begins, with the server-
|
||||
// authoritative duration. `Spell::Cast` co-hooks it to stamp the
|
||||
// player's channel — required for cast-then-channel spells (Mind
|
||||
// Control: 3 s cast then 60 s channel), whose SMSG_SPELL_START only
|
||||
// covers the cast phase. Address + layout mirrored from nampower's
|
||||
// SpellChannelStartHandlerHook (they hook it too — accepted co-hook
|
||||
// collision, per-channel-start frequency).
|
||||
FUN_SPELL_CHANNEL_START = 0x006E7550,
|
||||
|
||||
// `SMSG_SPELL_FAILED_OTHER` handler — `int __stdcall(uint32_t *opCode,
|
||||
// CDataStore *packet)`, same shape as FUN_SPELL_DELAYED. Body:
|
||||
// `casterGuid(u64, plain), spellId(u32)`. In (v)mangos cores this is
|
||||
// broadcast to observers when a started cast aborts (interrupt, death,
|
||||
// movement, fizzle) — but Turtle's core does NOT send it (verified
|
||||
// in-game: interrupts arrive with neither this nor SMSG_SPELL_FAILURE;
|
||||
// observers learn of the abort via SuperWoW instead — see
|
||||
// FUN_UNIT_CLEAR_CASTING_SPELL). `Spell::Cast` co-hooks it anyway as a
|
||||
// backstop for servers that do send it, invalidating the matching
|
||||
// remote-cast cache entry (and the player's own server-stamped chained
|
||||
// recast). Address + packet layout mirrored from nampower's
|
||||
// SpellFailedOtherHandlerHook.
|
||||
FUN_SPELL_FAILED_OTHER = 0x006E8E40,
|
||||
|
||||
// `SMSG_SPELL_FAILURE` handler — same `int __stdcall(uint32_t *opCode,
|
||||
// CDataStore *packet)` shape. Body: `casterGuid(u64, plain),
|
||||
// spellId(u32), result(u8)` — a superset of FAILED_OTHER's with a
|
||||
// trailing result byte. Decompiled at 0x006E8D80: resolves the caster
|
||||
// unit (FUN_00468460 typemask 8) and stops its cast visual via the SAME
|
||||
// unit methods FAILED_OTHER's handler calls (FUN_0060d040 +
|
||||
// FUN_00614150), plus extra channel/visual cleanup. Servers derived
|
||||
// from (v)mangos broadcast BOTH packets from Spell::SendInterrupted,
|
||||
// but which one a given core actually emits per abort path varies —
|
||||
// `Spell::Cast` co-hooks this one alongside FAILED_OTHER so a remote
|
||||
// interrupt evicts the cast cache regardless of which sibling arrives.
|
||||
// nampower calls this SpellFailedHandler (offsets.hpp) but doesn't
|
||||
// hook it.
|
||||
FUN_SPELL_FAILURE = 0x006E8D80,
|
||||
|
||||
// `CGUnit_C::ClearCastingSpell` — `__thiscall void(CGUnit *unit,
|
||||
// int spellID, char notify, char cleanup)` (nampower names the offset
|
||||
// but never hooks it). THE engine choke point for "this unit stopped
|
||||
// casting": gated on `spellID == [unit+0xC8C]` (the unit's live
|
||||
// current-cast spellID, set by SMSG_SPELL_START processing), it zeros
|
||||
// that field and clears the casting flag (bit 0x400 at [unit+0xD58]).
|
||||
// Ten callers converge here: both failure-packet handlers, the
|
||||
// SPELL_GO handler (natural completion), the movement handler
|
||||
// (0x006018f0 — moving units aren't casting), the health-diff handler
|
||||
// (0x006046f0, death), the unit animation-event dispatcher
|
||||
// (0x0060e0a0), the local cancel path (0x006e7040, sends
|
||||
// CMSG_CANCEL_CAST), and Spell_C_SpellFailed. Hooking THIS instead of
|
||||
// individual packets makes remote-cast eviction independent of which
|
||||
// packet the server actually sends — load-bearing on Turtle, whose
|
||||
// core does NOT broadcast SMSG_SPELL_FAILURE / SMSG_SPELL_FAILED_OTHER
|
||||
// on interrupt (verified: neither handler fires while the victim's
|
||||
// cast visual demonstrably stops).
|
||||
FUN_UNIT_CLEAR_CASTING_SPELL = 0x0060D040,
|
||||
|
||||
// CGUnit field: the unit's current-cast spellID (0 = not casting).
|
||||
// The regular-cast analog of OFF_UNIT_FIELD_CHANNEL_SPELL — but a
|
||||
// plain CGUnit member, NOT a descriptor UpdateField (client-derived
|
||||
// from SMSG_SPELL_START, not server-broadcast state).
|
||||
OFF_UNIT_CAST_SPELL = 0xC8C,
|
||||
|
||||
// NetClient message dispatch — `__thiscall void(void *conn, uint32_t
|
||||
// arg, CDataStore *packet)`. Reads the u16 opcode off the packet
|
||||
// cursor, then invokes `[conn + opcode*4 + 0x74]` (the handler table
|
||||
// FUN_005ab650 / FUN_00537a60 register into; per-handler userParam
|
||||
// parallel table at +0xD64). EVERY server message the client processes
|
||||
// funnels through here (the raw-ingress sibling at 0x00537B10 only
|
||||
// special-cases 0x1DD compressed-moves before queueing into this).
|
||||
// Useful as a temporary whole-protocol sniff point: co-hook, peek the
|
||||
// u16 at the cursor, restore, log.
|
||||
FUN_NET_MESSAGE_DISPATCH = 0x00537AA0,
|
||||
|
||||
// NetClient send — `__thiscall void(void *conn, CDataStore *packet)`.
|
||||
// The outgoing counterpart of FUN_NET_MESSAGE_DISPATCH: every CMSG the
|
||||
// client sends funnels through it (the argless wrapper `FUN_005AB630`,
|
||||
// nampower's ClientServices_Send, resolves the connection singleton
|
||||
// with the packet in ECX and calls this). The packet's leading u32 is
|
||||
// the opcode; `m_size - m_read` is what goes on the wire.
|
||||
// `Aura::ComboDuration` co-hooks it to snapshot combo points the
|
||||
// moment CMSG_CAST_SPELL leaves — before the server consumes them —
|
||||
// which also covers nampower-queued casts (they re-enter the engine's
|
||||
// cast path and send normally, unlike a Spell_C_CastSpell co-hook,
|
||||
// which nampower's trampoline re-entry would bypass).
|
||||
FUN_NET_SEND = 0x005379A0,
|
||||
|
||||
// Outgoing opcode: CMSG_CAST_SPELL. Body: `spellId(u32),
|
||||
// targetFlags(u16), <target per flags>`.
|
||||
OP_CMSG_CAST_SPELL = 0x12E,
|
||||
|
||||
// Spell.dbc DurationIndex (column 30) — row into SpellDuration.dbc.
|
||||
// Offset = 30*4, consistent with the verified neighbors
|
||||
// (CastingTimeIndex col 18 = +0x48, PowerType col 31 = +0x7C).
|
||||
OFF_SPELL_RECORD_DURATION_INDEX = 0x78,
|
||||
|
||||
// SpellDuration.dbc — records/count slots per docs/DBCs.md. Record:
|
||||
// `{id@+0, baseMs@+4 (i32), perLevelMs@+8 (i32), maxMs@+0xC (i32)}`.
|
||||
// Combo-point finishers are exactly the rows with base != max: the
|
||||
// server computes `base + (max - base) * comboPoints / 5`
|
||||
// ((v)mangos CalculateSpellDuration — verified against the DBC:
|
||||
// Rupture 6000/16000 = 6+2*CP, Kidney Shot 1000/6000 = 1+1*CP,
|
||||
// Slice and Dice 6000/21000 = 6+3*CP, Expose Armor 30000/30000 =
|
||||
// fixed). NOTE: rows can dangle — Turtle's client DBC has no record
|
||||
// for Rip's DurationIndex 87 (records[87] == NULL), which is why
|
||||
// Rip reads duration 0 client-side there.
|
||||
VAR_SPELL_DURATION_RECORDS = 0x00C0D828,
|
||||
VAR_SPELL_DURATION_COUNT = 0x00C0D82C,
|
||||
|
||||
// Combo points, within the CGPlayer `+0xE68` sub-struct (see
|
||||
// OFF_CGPLAYER_INFO). Verified from Script_GetComboPoints
|
||||
// (0x0051A190): CP count byte at `[player+0xE68]+0x1029`, the combo
|
||||
// TARGET's guid (u64) at `[player+0xE68]+0x838` (compared against
|
||||
// the current-target global 0x00B4E2D8 before the Lua function
|
||||
// reports a non-zero count).
|
||||
OFF_CGPLAYER_COMBO_POINTS = 0x1029,
|
||||
OFF_CGPLAYER_COMBO_TARGET = 0x838,
|
||||
|
||||
// ---- Frame-method registries beyond GameTooltip's ------------------
|
||||
// Same per-type registry mechanism as VAR_GAMETOOLTIP_METHOD_REGISTRY
|
||||
// (docs/BlizzardScriptAPI.md "Frame types & their methods" has the
|
||||
// full 23-table catalogue). The dispatcher resolves methods through
|
||||
// the type hierarchy, so a method added to the REGION base registry
|
||||
// (the 19-entry core-layout table: GetWidth/SetPoint/…) is callable
|
||||
// on every region type — frames, buttons, textures, fontstrings.
|
||||
// `Frame::Modern` uses these to backport modern API (SetSize,
|
||||
// SetShown, SetResizeBounds).
|
||||
VAR_REGION_METHOD_REGISTRY = 0x00CF54B4,
|
||||
VAR_FRAME_METHOD_REGISTRY = 0x00CF4D38,
|
||||
VAR_TEXTURE_METHOD_REGISTRY = 0x00CF5434,
|
||||
VAR_FONTSTRING_METHOD_REGISTRY = 0x00CF5400,
|
||||
|
||||
// Engine Script_* method implementations `Frame::Modern` delegates to
|
||||
// (each `int __fastcall(void *L)`, reading self at stack index 1).
|
||||
// Addresses from the docs/raw_methods.txt catalogue. Show/Hide are
|
||||
// PER-BRANCH (Frame vs Texture vs FontString each register their own
|
||||
// script function with its own object typecheck), so SetShown is
|
||||
// registered per branch with the matching delegates.
|
||||
FUN_SCRIPT_REGION_SETWIDTH = 0x007A1F20,
|
||||
FUN_SCRIPT_REGION_SETHEIGHT = 0x007A2150,
|
||||
FUN_SCRIPT_REGION_GETWIDTH = 0x007A1E00,
|
||||
FUN_SCRIPT_REGION_GETHEIGHT = 0x007A2030,
|
||||
FUN_SCRIPT_FRAME_SHOW = 0x00775750,
|
||||
FUN_SCRIPT_FRAME_HIDE = 0x00775810,
|
||||
FUN_SCRIPT_FRAME_SETMINRESIZE = 0x00776020,
|
||||
FUN_SCRIPT_FRAME_SETMAXRESIZE = 0x007762A0,
|
||||
FUN_SCRIPT_FRAME_GETSCRIPT = 0x00774780,
|
||||
FUN_SCRIPT_FRAME_SETSCRIPT = 0x007748D0,
|
||||
FUN_SCRIPT_TEXTURE_SHOW = 0x0079B770,
|
||||
FUN_SCRIPT_TEXTURE_HIDE = 0x0079B830,
|
||||
FUN_SCRIPT_FONTSTRING_SHOW = 0x0079CDB0,
|
||||
FUN_SCRIPT_FONTSTRING_HIDE = 0x0079CE70,
|
||||
|
||||
// ---- World map overlay data (WorldMapOverlay.dbc + WorldMapArea.dbc)
|
||||
// Backs `C_Map.GetMapOverlays`. Instance VAs per docs/DBCs.md;
|
||||
// schemas verified against the extracted DBCs AND the engine's own
|
||||
// reader `Script_GetMapOverlayInfo` (0x004A8A00), which reads the
|
||||
// same fields for its 7 returns.
|
||||
//
|
||||
// WorldMapArea.dbc record (8 fields, 0x20 bytes):
|
||||
// {ID@+0, mapID@+4, areaID@+8 (AreaTable, 0 for continent rows),
|
||||
// name@+0xC (char*, the map directory name GetMapInfo returns),
|
||||
// locLeft/locRight/locTop/locBottom floats}
|
||||
VAR_WORLDMAP_AREA_RECORDS = 0x00C0D5BC,
|
||||
VAR_WORLDMAP_AREA_COUNT = 0x00C0D5C0,
|
||||
OFF_WMA_AREA_ID = 0x08,
|
||||
OFF_WMA_NAME = 0x0C,
|
||||
|
||||
// WorldMapOverlay.dbc record (17 fields, 0x44 bytes):
|
||||
// {ID@+0, worldMapAreaID@+4 (-> WorldMapArea row),
|
||||
// areaID[4]@+8..+0x14 (AreaTable ids the overlay reveals),
|
||||
// mapPointX@+0x18, mapPointY@+0x1C, textureName@+0x20 (char*,
|
||||
// bare name), textureWidth@+0x24, textureHeight@+0x28,
|
||||
// offsetX@+0x2C, offsetY@+0x30, hitRect@+0x34..+0x40}
|
||||
// The engine's Lua surface only exposes EXPLORED overlays: the
|
||||
// discovered-overlay ID list at 0x00B6E630 (count 0x00B6E6B4) gates
|
||||
// Script_GetMapOverlayInfo. Reading the DBC directly bypasses the
|
||||
// exploration gate — every overlay of a zone, explored or not.
|
||||
VAR_WORLDMAP_OVERLAY_RECORDS = 0x00C0D594,
|
||||
VAR_WORLDMAP_OVERLAY_COUNT = 0x00C0D598,
|
||||
OFF_WMO_WORLDMAP_AREA = 0x04,
|
||||
OFF_WMO_MAP_POINT_X = 0x18,
|
||||
OFF_WMO_MAP_POINT_Y = 0x1C,
|
||||
OFF_WMO_TEXTURE_NAME = 0x20,
|
||||
OFF_WMO_TEXTURE_WIDTH = 0x24,
|
||||
OFF_WMO_TEXTURE_HEIGHT = 0x28,
|
||||
OFF_WMO_OFFSET_X = 0x2C,
|
||||
OFF_WMO_OFFSET_Y = 0x30,
|
||||
|
||||
// Current world-map view selection — the globals the engine's
|
||||
// current-map-name resolver (FUN_004a6cf0, behind GetMapInfo) reads:
|
||||
// continent index, zone index (-1 = whole continent), the default
|
||||
// WorldMapArea row used when no continent is selected, and the
|
||||
// per-continent data blob (base ptr; stride 0x10024 per continent,
|
||||
// continent's own WMA row at +0x04, per-zone WMA row array ptr at
|
||||
// +0x10).
|
||||
VAR_WORLDMAP_CONTINENT_INDEX = 0x0084506C,
|
||||
VAR_WORLDMAP_ZONE_INDEX = 0x00845070,
|
||||
VAR_WORLDMAP_DEFAULT_AREA_ROW = 0x00845074,
|
||||
VAR_WORLDMAP_CONTINENT_DATA = 0x00B6E668,
|
||||
WORLDMAP_CONTINENT_STRIDE = 0x10024,
|
||||
|
||||
// `Script_SetPoint` — the ONE SetPoint implementation, registered in
|
||||
// the Region base table and inherited by every region type. Vanilla's
|
||||
// parser accepts (point, region), (point, region, relPoint[, x, y]),
|
||||
// (point, x, y), and even an explicit nil region — but NOT the bare
|
||||
// one-arg form (`fs:SetPoint("RIGHT")`): a fully-omitted arg 3 is
|
||||
// LUA_TNONE, which fails the string/table/number/nil check and raises
|
||||
// the usage error. Modern clients accept it (anchor to parent at the
|
||||
// same point, zero offsets). `Frame::Modern` co-hooks this and
|
||||
// normalizes the one-arg call to (point, 0, 0) — the vanilla
|
||||
// (point, x, y) form, which is parent-relative and thus exactly the
|
||||
// modern semantic.
|
||||
FUN_SCRIPT_REGION_SETPOINT = 0x007A2540,
|
||||
|
||||
// `CGUnit_C::OnAuraAdded` — `__thiscall void(CGUnit *unit, uint32_t
|
||||
// slot, uint32_t spellId)` (i.e. `__fastcall(unit /*ecx*/, edx_unused,
|
||||
// slot, spellId)`). Fires for EVERY aura that lands on a tracked unit,
|
||||
@@ -1083,6 +1394,7 @@ enum Offsets {
|
||||
OBJ_TYPE_ITEM = 2,
|
||||
OBJ_TYPE_CONTAINER = 4,
|
||||
OBJ_TYPE_UNIT = 8,
|
||||
OBJ_TYPE_PLAYER = 0x10, // what the engine's bag observer FUN_004F8DB0 passes
|
||||
OBJ_TYPE_GAMEOBJECT = 0x20, // 1<<5; passed by FUN_0052AA20 (hover-tooltip populator).
|
||||
|
||||
// `CGObject::GetName` — returns the display-name `const char *` for
|
||||
@@ -1872,6 +2184,15 @@ enum Offsets {
|
||||
OFF_SLA_CLASS_MASK = 0x10,
|
||||
OFF_SLA_EXCLUDE_RACE = 0x14,
|
||||
OFF_SLA_EXCLUDE_CLASS = 0x18,
|
||||
// Skill-up threshold ranks (grey / green) at record fields 10/11.
|
||||
// A row with either nonzero is a craftable recipe; profession
|
||||
// rank-up / passive rows have both zero. Empirically: the
|
||||
// Blacksmithing skill line has 343 SLA rows, 334 with a nonzero
|
||||
// threshold — the 9 excluded are the Apprentice..Artisan rank
|
||||
// spells and skill grants. This is the discriminator
|
||||
// `TradeSkill::Link` uses to build the canonical recipe universe.
|
||||
OFF_SLA_TRIVIAL_SKILL_HIGH = 0x28,
|
||||
OFF_SLA_TRIVIAL_SKILL_LOW = 0x2C,
|
||||
|
||||
// SkillLine.dbc — the skill/category each SLA row points into via
|
||||
// its `skillId` field. Each record carries a 9-locale localized
|
||||
@@ -1904,6 +2225,24 @@ enum Offsets {
|
||||
OFF_PLAYER_SKILL_LINE_ID = 0x00,
|
||||
OFF_PLAYER_SKILL_RANK = 0x10,
|
||||
|
||||
// Live per-skill current/max rank. These are NOT in
|
||||
// `VAR_PLAYER_SKILL_LIST` (that entry's `+0x10` is numTempPoints) —
|
||||
// the real ranks live in the CGPlayer `+0xE68` sub-struct
|
||||
// (`OFF_CGPLAYER_INFO`). `FUN_SKILL_LINE_TO_SLOT`
|
||||
// (`__thiscall(player, skillLineID) -> slot`) maps a SkillLine.dbc
|
||||
// row to its slot; the slot indexes a `SKILL_INFO_STRIDE`-byte
|
||||
// record at `[player+0xE68] + OFF_SKILL_INFO_TABLE + slot*stride`:
|
||||
// current `+0x0`, max `+0x2`, rank bonus `+0x6` (all u16 — add the
|
||||
// bonus when the base value is nonzero). Source: `Script_GetTradeSkillLine`
|
||||
// (`0x004FDD40`) / `Script_GetSkillLineInfo` (`0x004D3610`). Verified
|
||||
// in-game vs. those functions (Tailoring 261/300, Enchanting 186/240).
|
||||
FUN_SKILL_LINE_TO_SLOT = 0x005EA3F0,
|
||||
OFF_SKILL_INFO_TABLE = 0x84C,
|
||||
SKILL_INFO_STRIDE = 0xC,
|
||||
OFF_SKILL_INFO_CUR = 0x0,
|
||||
OFF_SKILL_INFO_MAX = 0x2,
|
||||
OFF_SKILL_INFO_BONUS = 0x6,
|
||||
|
||||
// Per-itemClass proficiency bitmap maintained by the engine.
|
||||
// 17 u32 entries (indexed by Item.dbc `m_class`, 0..16). Each
|
||||
// entry is a bitmask where bit N is set if the player has
|
||||
@@ -1940,7 +2279,18 @@ enum Offsets {
|
||||
// Verified via the `IsAssistingRitual` development session by
|
||||
// observing `0xEE00 → 0xEE05` on `/sit` over a chair (the medium-
|
||||
// chair sit value 5).
|
||||
//
|
||||
// Byte 3 (the AnimTier / misc-flags byte, mask 0x02000000 on the
|
||||
// u32) is the **stealth / sneak flag**: set while the unit is in
|
||||
// the sneaking anim tier (Rogue Stealth, Druid Prowl, Shadowmeld),
|
||||
// which is what drives the client's semi-transparent render of a
|
||||
// stealthed unit. Verified via `_classicapi_DiffAll`: a Prowl
|
||||
// toggle from a Cat-Form baseline flips byte 3 `0x00 → 0x02` while
|
||||
// every other descriptor change is aura-array slot metadata — so
|
||||
// this is the only standalone broadcast bit that means "stealthed".
|
||||
// Read by `IsStealthed()`.
|
||||
OFF_UNIT_FIELD_BYTES_1 = 0x210,
|
||||
UNIT_BYTES_1_STEALTH_FLAG = 0x02000000,
|
||||
|
||||
// `__fastcall(void)` engine helper that refreshes the bonus
|
||||
// action bar from the local player's current shapeshift form
|
||||
@@ -2418,10 +2768,10 @@ enum Offsets {
|
||||
// walks the player's slot data, repopulates `VAR_QUEST_LOG_ENTRIES`
|
||||
// / `VAR_QUEST_LOG_ENTRY_COUNT`, then fires QUEST_LOG_UPDATE.
|
||||
//
|
||||
// Hooked by `Quest::Accepted` to snapshot the log pre-/post-rebuild
|
||||
// and fire `QUEST_ACCEPTED(logIndex, questID)` for the diff. Single
|
||||
// quiet target in the `0x004DExxx` quest region — no known DLL
|
||||
// collisions.
|
||||
// Hooked by `Quest::LogEvents` to snapshot the log pre-/post-rebuild
|
||||
// and fire `QUEST_ACCEPTED(logIndex, questID)` / `QUEST_REMOVED(questID)`
|
||||
// for the diff. Single quiet target in the `0x004DExxx` quest region —
|
||||
// no known DLL collisions.
|
||||
FUN_QUEST_LOG_REBUILD = 0x004DE510,
|
||||
|
||||
// Player and pet spellbooks — flat int32 arrays indexed by 0-based slot.
|
||||
@@ -2850,6 +3200,7 @@ enum Offsets {
|
||||
SPELLMOD_SLOT_STRIDE = 0x74, // bytes per familyFlagBit row
|
||||
SPELLMOD_SLOT_COUNT = 64, // SpellFamilyFlags is 64-bit
|
||||
SPELLMOD_OP_RADIUS = 6, // op index for spell radius
|
||||
SPELLMOD_OP_DURATION = 1, // op index for aura duration
|
||||
|
||||
// SpellDispelType.dbc — maps dispel-type IDs (1..N) to localized
|
||||
// names like "Magic", "Curse", "Disease", "Poison". Used by
|
||||
@@ -3112,6 +3463,15 @@ enum Offsets {
|
||||
OFF_EVENT_ENTRY_NAME = 0x00,
|
||||
OFF_EVENT_ENTRY_HEAD = 0x0C,
|
||||
|
||||
// Subscriber-chain node layout — the linked list hanging off each
|
||||
// entry's +0x0C head, derived from Frame::RegisterEvent
|
||||
// (FUN_00702140): each node is `{ ?, next@+0x04, frame@+0x08 }`, where
|
||||
// `frame` is the CFrameScriptObject* subscriber. A node value with its
|
||||
// low bit set (or null) is the end/empty sentinel. Walked by
|
||||
// Frame:IsEventRegistered to test membership.
|
||||
OFF_EVENT_NODE_NEXT = 0x04,
|
||||
OFF_EVENT_NODE_FRAME = 0x08,
|
||||
|
||||
// `Frame::RegisterEvent` — the C++ helper called by the Lua
|
||||
// `frame:RegisterEvent(eventName)` method (`Script_RegisterEvent` at
|
||||
// `0x00774A40`). `__thiscall` with `(this=frame, eventName)`. Walks
|
||||
@@ -3540,23 +3900,15 @@ enum Offsets {
|
||||
VAR_ADDON_ARRAY = 0x00BE1B94,
|
||||
VAR_ADDON_COUNT = 0x00BE1B90,
|
||||
|
||||
// Player visibility/state byte field, broadcast in UpdateFields.
|
||||
// Found empirically via _classicapi_DescDump (see src/debug/).
|
||||
// Treated as a u32 but the meaningful bits all live in byte 0:
|
||||
// 0x02 — set when the player has any visibility/form-modifying
|
||||
// state active (stealth, mount, possibly shapeshift —
|
||||
// set by stealth and mount in our test data).
|
||||
// 0x08, 0x10 — set together when mounted (alongside 0x02).
|
||||
//
|
||||
// Ambiguity: bit 0x02 alone doesn't distinguish stealth from
|
||||
// other visibility-modifying states. Stealth detection AND-gates
|
||||
// with `mountDisplayID == 0` to exclude mount; if shapeshift
|
||||
// also sets bit 0x02 we'd false-positive on druids in form
|
||||
// (untested). The robust path is to walk the player's aura
|
||||
// list looking for the actual stealth/prowl spell — left as
|
||||
// future work if false-positives turn up.
|
||||
OFF_PLAYER_FIELD_VIS_BYTES = 0x17C,
|
||||
PLAYER_VIS_BIT_STEALTH = 0x02,
|
||||
// NOTE: an earlier revision defined OFF_PLAYER_FIELD_VIS_BYTES /
|
||||
// PLAYER_VIS_BIT_STEALTH here at 0x17C, believing bit 0x02 was a
|
||||
// "stealth bit". That was wrong: 0x17C is UNIT_FIELD_AURALEVELS
|
||||
// (per-slot caster-level bytes; see OFF_UNIT_FIELD_AURALEVELS above),
|
||||
// and the old read only appeared to work by coincidence (a caster-
|
||||
// level byte that happened to have bit 0x02 set on the test char;
|
||||
// at level 60 = 0x3C it doesn't, so it read false). The real stealth
|
||||
// flag is UNIT_FIELD_BYTES_1 byte 3 (UNIT_BYTES_1_STEALTH_FLAG); see
|
||||
// that field above. IsStealthed reads it.
|
||||
|
||||
// Mount display ID — the creature display ID the engine renders
|
||||
// under the mounted player. Zero when not mounted, non-zero
|
||||
@@ -4221,6 +4573,19 @@ enum Offsets {
|
||||
// with craft).
|
||||
VAR_TRADESKILL_ENTRIES = 0x00BDDFC0,
|
||||
VAR_TRADESKILL_COUNT = 0x00BDE04C,
|
||||
// SkillLine.dbc row ID of the currently-open trade skill window
|
||||
// (the profession the player has open). Bounds-checked against
|
||||
// `VAR_SKILL_LINE_COUNT` and used as `records[id]` by
|
||||
// `Script_GetTradeSkillLine` (`0x004FDD40`). <= 0 / stale when no
|
||||
// window is open. `FUN_004FC870` zeroes it on close (and fires
|
||||
// event `0x13B`), so `> 0` reliably means "trade window open".
|
||||
VAR_CURRENT_TRADESKILL_LINE = 0x00BDE040,
|
||||
// Craft window (Enchanting, pet training) open-state flag — nonzero
|
||||
// (3 for the enchanting-style craft) while open; `FUN_004F5FE0`
|
||||
// zeroes it on close (fires event `0x169`). The Craft window has no
|
||||
// skill-line-ID global — `TradeSkill::Link` derives the skill line
|
||||
// from the first craft recipe — so this is the "craft open" gate.
|
||||
VAR_CRAFT_WINDOW_STATE = 0x00BDCFB8,
|
||||
// Spell.dbc "produced item" field for crafting recipes — the
|
||||
// itemID this spell creates when cast. Reagent itemIDs and
|
||||
// counts live at `OFF_SPELL_REAGENT_ID` / `OFF_SPELL_REAGENT_COUNT`
|
||||
@@ -4245,6 +4610,18 @@ enum Offsets {
|
||||
OFF_SPELL_RECORD_EFFECT_MISC_VALUE = 0x1A8, // int32[3]
|
||||
SPELL_RECORD_EFFECT_COUNT = 3,
|
||||
|
||||
// SPELL_EFFECT_* id array (`Effect[3]`) — five arrays before
|
||||
// EffectBasePoints (`+0x130`), so `0x130 - 5*0xC`. Used to tell craft
|
||||
// recipes from profession abilities (Disenchant etc.) that also carry
|
||||
// skill-up thresholds. Recipe-producing effects: CREATE_ITEM (items),
|
||||
// ENCHANT_ITEM / _TEMPORARY (enchants), and LEARN_SPELL (Turtle's custom
|
||||
// recipes, e.g. "Steel Plate Boots" = effect 36).
|
||||
OFF_SPELL_RECORD_EFFECT = 0xF4, // int32[3]
|
||||
SPELL_EFFECT_CREATE_ITEM = 24,
|
||||
SPELL_EFFECT_LEARN_SPELL = 36,
|
||||
SPELL_EFFECT_ENCHANT_ITEM = 53,
|
||||
SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY = 54,
|
||||
|
||||
// EffectBasePoints[3] — the base magnitude of each effect, stored as
|
||||
// (value - 1) for the fixed-die spells that back item stats (the
|
||||
// engine adds a 1..dieSides roll; dieSides == 1 makes it value = base
|
||||
@@ -4285,9 +4662,33 @@ enum Offsets {
|
||||
// reads `spellRec[+0x14]` as the spell's mechanic when the per-
|
||||
// effect EffectMiscValue is 0. Read by C_Spell.GetSpellMechanicByID.
|
||||
OFF_SPELL_RECORD_MECHANIC = 0x14,
|
||||
SPELL_AURA_MOD_STEALTH = 16,
|
||||
SPELL_AURA_MOD_SHAPESHIFT = 36,
|
||||
SPELL_AURA_MOUNTED = 78,
|
||||
|
||||
// Control-loss aura effect types (EffectApplyAuraName values), used by
|
||||
// C_LossOfControl to classify a debuff. Values are authoritative from the
|
||||
// Turtle server's indexed SPELL_AURA proc-handler table (SharedDefines).
|
||||
SPELL_AURA_MOD_POSSESS = 2,
|
||||
SPELL_AURA_MOD_CONFUSE = 5,
|
||||
SPELL_AURA_MOD_CHARM = 6,
|
||||
SPELL_AURA_MOD_FEAR = 7,
|
||||
SPELL_AURA_MOD_STUN = 12,
|
||||
SPELL_AURA_MOD_PACIFY = 25,
|
||||
SPELL_AURA_MOD_ROOT = 26,
|
||||
SPELL_AURA_MOD_SILENCE = 27,
|
||||
SPELL_AURA_MOD_PACIFY_SILENCE = 60,
|
||||
SPELL_AURA_MOD_DISARM = 67,
|
||||
|
||||
// SMSG_SPELL_COOLDOWN (0x134) handler, registered by the spell-opcode
|
||||
// boot registrar FUN_006e7150 exactly like the failure/channel handlers
|
||||
// Spell::Cast co-hooks — same `int __stdcall(uint32_t *opCode,
|
||||
// CDataStore *packet)` shape. Body: GUID(u64) then (spellID, durationMs)
|
||||
// u32 pairs. A player-GUID packet carrying >=2 spells that all share one
|
||||
// duration is a school-interrupt lockout (Player::ProhibitSpellSchool is
|
||||
// the only sender of that shape); see src/lossofcontrol/Info.cpp.
|
||||
FUN_SPELL_COOLDOWN_HANDLER = 0x006E9460,
|
||||
|
||||
// Gossip menu data. Populated by the SMSG_GOSSIP_MESSAGE packet
|
||||
// handler at 0x004E26E0 and reset by FUN_004E26A0 each time a new
|
||||
// gossip window opens. Two parallel storage arrays:
|
||||
@@ -4337,6 +4738,80 @@ enum Offsets {
|
||||
FUN_GOSSIP_SELECT_ACTIVE_QUEST = 0x004E2600,
|
||||
FUN_SCRIPT_CLOSE_GOSSIP = 0x004E2B20,
|
||||
|
||||
// Current gossip NPC GUID (u64). Set by the SMSG_GOSSIP_MESSAGE
|
||||
// handler, cleared by the gossip-close worker at 0x004E1FA0 (which
|
||||
// then fires GOSSIP_CLOSED, event 0x12B). Non-zero = a gossip
|
||||
// session is live — the gate that keeps `C_GossipInfo` from serving
|
||||
// the previous NPC's stale arrays/text after close.
|
||||
VAR_GOSSIP_NPC_GUID = 0x00BC3F58,
|
||||
|
||||
// --- Quest-greeting state (SMSG_QUESTGIVER_QUEST_LIST) -------------
|
||||
// Vanilla's SECOND questgiver path: NPCs without a gossip menu send
|
||||
// SMSG_QUESTGIVER_QUEST_LIST, whose handler (FUN_005dbb10) fills a
|
||||
// storage entirely separate from the gossip arrays and fires
|
||||
// QUEST_GREETING (event 300 = 0x12C) — the QuestFrameGreetingPanel
|
||||
// ("Current Quests" / "Available Quests"). Vanilla Lua reads it via
|
||||
// GetGreetingText / Get{Available,Active}Title / etc.; C_GossipInfo
|
||||
// merges it in so modern-addon ports work on greeting NPCs too.
|
||||
//
|
||||
// Shared quest-session state, written by the panel-begin helper
|
||||
// FUN_00500bd0(panelType, textID, guidLo, guidHi, ...):
|
||||
// VAR_QUESTGIVER_GUID — u64, the current questgiver. Cleared by
|
||||
// the session-close worker FUN_00501130 (fires QUEST_FINISHED,
|
||||
// event 0x130). Non-zero = quest session live.
|
||||
// VAR_QUEST_PANEL_TYPE — i32 panel: 0 greeting, 1 detail,
|
||||
// 2 progress, 3 reward. begin(0) also zeroes both greeting
|
||||
// arrays + counts + the text buffers.
|
||||
VAR_QUESTGIVER_GUID = 0x00BE0810,
|
||||
VAR_QUEST_PANEL_TYPE = 0x00BE0818,
|
||||
|
||||
// GUID the greeting arrays were filled for — written ONLY by the
|
||||
// SMSG_QUESTGIVER_QUEST_LIST handler. The greeting arrays are valid
|
||||
// iff this equals VAR_QUESTGIVER_GUID (and that is non-zero);
|
||||
// otherwise they're leftovers from an older NPC (e.g. the current
|
||||
// quest session came from a gossip-menu quest click, which begins
|
||||
// at panel 1 without ever clearing the greeting arrays).
|
||||
VAR_GREETING_NPC_GUID = 0x00C4D740,
|
||||
|
||||
// Greeting text (0x200 inline, $N/$C-expanded) — what vanilla's
|
||||
// Script_GetGreetingText pushes.
|
||||
VAR_QUEST_GREETING_TEXT = 0x00BDE068,
|
||||
|
||||
// The two greeting quest arrays: 32 entries, stride 0x4C =
|
||||
// { u32 questID @ +0, i32 level @ +4, char title[0x40] @ +8,
|
||||
// u32 extra @ +0x48 (available: status==0 flag; active: always
|
||||
// 0 — the appender FUN_00500e90 never stores the status, see
|
||||
// the scratch arrays below for isComplete) }.
|
||||
// Appenders: FUN_00500e40 (available), FUN_00500e90 (active).
|
||||
// Readers: Script_Get{Available,Active}{Title,Level} @ 0x00501AC0/
|
||||
// 0x00501B30/0x00501BA0/0x00501C20.
|
||||
VAR_GREETING_AVAILABLE_ENTRIES = 0x00BDFE60,
|
||||
VAR_GREETING_ACTIVE_ENTRIES = 0x00BDE690,
|
||||
GREETING_QUESTS_STRIDE = 0x4C,
|
||||
GREETING_QUESTS_MAX = 32,
|
||||
OFF_GREETING_QUEST_ID = 0x000,
|
||||
OFF_GREETING_QUEST_LEVEL = 0x004,
|
||||
OFF_GREETING_QUEST_TITLE = 0x008,
|
||||
VAR_GREETING_AVAILABLE_COUNT = 0x00BE0834,
|
||||
VAR_GREETING_ACTIVE_COUNT = 0x00BE0838,
|
||||
|
||||
// Scratch arrays the SMSG_QUESTGIVER_QUEST_LIST handler fills in
|
||||
// packet order (32 × u32 each, zeroed per packet): questIDs and the
|
||||
// per-quest dialog status. Status 3|4 = active (same sentinel as
|
||||
// the gossip quest rows), 4 = complete/turn-in-ready. The canonical
|
||||
// greeting arrays drop the status, so `isComplete` for an active
|
||||
// greeting quest is recovered by questID lookup here.
|
||||
VAR_GREETING_SCRATCH_IDS = 0x00C4D2B0,
|
||||
VAR_GREETING_SCRATCH_STATUS = 0x00C4D340,
|
||||
|
||||
// Engine greeting-quest selectors — the workers vanilla's
|
||||
// Script_Select{Available,Active}Quest call: `__fastcall(int
|
||||
// idx0Based)`, index straight into the corresponding greeting
|
||||
// array. They validate VAR_QUESTGIVER_GUID internally and send
|
||||
// CMSG_QUESTGIVER_{QUERY_QUEST,COMPLETE_QUEST}.
|
||||
FUN_GREETING_SELECT_AVAILABLE_QUEST = 0x005012A0,
|
||||
FUN_GREETING_SELECT_ACTIVE_QUEST = 0x00501320,
|
||||
|
||||
// CDataStore primitive readers — `__thiscall void(this, void *out)`.
|
||||
// Read at the current cursor (`+0x14`) and advance it by the value
|
||||
// size. We call these directly from `Unit::MirrorTimer` to peek
|
||||
@@ -4506,4 +4981,41 @@ enum Offsets {
|
||||
// matching what `FUN_00494B60` and the trade-attached paths pass
|
||||
// when re-resolving the cursor GUID to a `CGItem *`.
|
||||
FUN_OBJECT_FROM_GUID = 0x00468460,
|
||||
|
||||
// Virtual XML-template registry (a Storm hash table) — the store that
|
||||
// backs `inherits=` and `C_XMLUtil.GetTemplates`. The XML parser
|
||||
// (`FUN_006ede10`) registers every `virtual="true"` frame into it via
|
||||
// `FUN_006ee500`; the inherits resolver reads it via `FUN_006ee6f0`.
|
||||
// Both operate on these globals, so it's the authoritative template list.
|
||||
// See src/xml/Templates.cpp.
|
||||
//
|
||||
// VAR_XML_TEMPLATE_TABLE holds a POINTER to the bucket array (0 / the
|
||||
// array unallocated) and VAR_XML_TEMPLATE_MASK the bucket-count mask;
|
||||
// mask == 0xFFFFFFFF means no template has ever registered (walk = empty).
|
||||
VAR_XML_TEMPLATE_TABLE = 0x00CEEA1C,
|
||||
VAR_XML_TEMPLATE_MASK = 0x00CEEA24,
|
||||
// Bucket struct (0xC bytes): { linkOffset@+0x0, ?@+0x4, chainHead@+0x8 }.
|
||||
// A node's next pointer is at `*(node + linkOffset + 4)`; the tail
|
||||
// sentinel has its low bit set (chain ends on `(ptr & 1) != 0`).
|
||||
XML_TEMPLATE_BUCKET_STRIDE = 0xC,
|
||||
OFF_XML_TEMPLATE_BUCKET_LINKOFF = 0x0,
|
||||
OFF_XML_TEMPLATE_BUCKET_HEAD = 0x8,
|
||||
// Registry node payload: template name string @+0x14, parsed definition
|
||||
// XML node @+0x18 (hash @+0x0, virtual flag @+0x1C — unused here).
|
||||
OFF_XML_TEMPLATE_NODE_NAME = 0x14,
|
||||
OFF_XML_TEMPLATE_NODE_DEF = 0x18,
|
||||
// Parsed XML element node: its tag-name string ("Frame" / "Button" /
|
||||
// "CheckButton" / …) lives at +0x8 — this is the frame "type".
|
||||
OFF_XML_NODE_TAG = 0x8,
|
||||
// The definition node retains its full parsed DOM subtree — used by
|
||||
// GetTemplateInfo to read `<Size>` / `inherits=`. First child @+0x4, next
|
||||
// sibling @+0x1C. Attributes are read by name via the node method
|
||||
// FUN_006f2cf0 (`__thiscall(node, name) -> value string`, null if absent).
|
||||
OFF_XML_NODE_CHILD = 0x4,
|
||||
OFF_XML_NODE_SIBLING = 0x1C,
|
||||
FUN_XML_NODE_GET_ATTRIBUTE = 0x006F2CF0,
|
||||
// By-name template lookup — the same one `inherits=` resolves through.
|
||||
// `__fastcall(const char *name) -> definition node`, 0 if unregistered
|
||||
// (case-insensitive, hashed). See FUN_006ee6f0 in Templates.cpp notes.
|
||||
FUN_XML_TEMPLATE_LOOKUP = 0x006EE6F0,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// See ComboDuration.h for the contract and the protocol findings that
|
||||
// motivate the design (the server never transmits target-debuff
|
||||
// durations in 1.12).
|
||||
|
||||
#include "ComboDuration.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "net/PacketReader.h"
|
||||
#include "spell/Mod.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Aura::ComboDuration {
|
||||
|
||||
namespace {
|
||||
|
||||
using Net::CDataStore;
|
||||
|
||||
uint32_t NowMs() {
|
||||
using TickCount_t = uint32_t(__fastcall *)();
|
||||
return reinterpret_cast<TickCount_t>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_OS_TICKCOUNT_MS))();
|
||||
}
|
||||
|
||||
// ---- Combo-point snapshot (NetClient send co-hook) ------------------------
|
||||
|
||||
// The player's live combo points, read the same way Script_GetComboPoints
|
||||
// (0x0051A190) does: the CP byte on the CGPlayer +0xE68 sub-struct. The player
|
||||
// comes from the shared Unit::Identity::PlayerObject() (the object-manager GUID
|
||||
// resolve, our fastest player-object path — returns null pre-world rather than
|
||||
// throwing), so this stays safe from any context the send hook can fire in.
|
||||
uint8_t CurrentComboPoints() {
|
||||
const uint8_t *player = Unit::Identity::PlayerObject();
|
||||
if (player == nullptr)
|
||||
return 0;
|
||||
const uint8_t *info = *reinterpret_cast<const uint8_t *const *>(
|
||||
player + Offsets::OFF_CGPLAYER_INFO);
|
||||
if (info == nullptr)
|
||||
return 0;
|
||||
return *(info + Offsets::OFF_CGPLAYER_COMBO_POINTS);
|
||||
}
|
||||
|
||||
// One cast in flight at a time is the practical case (a second finisher
|
||||
// can't be cast until the server consumes the first one's combo points),
|
||||
// so a single slot with a spellID match and a short TTL suffices.
|
||||
struct Capture {
|
||||
uint32_t spellId;
|
||||
uint8_t comboPoints;
|
||||
uint32_t capturedMs;
|
||||
};
|
||||
Capture g_capture{0, 0, 0};
|
||||
|
||||
// Worst-case send -> SMSG_SPELL_GO roundtrip. Past this the snapshot is
|
||||
// stale (the cast failed / was rejected) and must not scale a later cast.
|
||||
constexpr uint32_t kCaptureTtlMs = 2000;
|
||||
|
||||
int ConsumeCapturedCP(uint32_t spellId) {
|
||||
const Capture c = g_capture;
|
||||
g_capture = {0, 0, 0};
|
||||
if (c.spellId != spellId || c.comboPoints == 0)
|
||||
return 0;
|
||||
if (NowMs() - c.capturedMs >= kCaptureTtlMs)
|
||||
return 0;
|
||||
return c.comboPoints;
|
||||
}
|
||||
|
||||
// Co-hook on the NetClient send — the one funnel every outgoing CMSG
|
||||
// passes through, including casts released from nampower's spell queue
|
||||
// (which bypass any co-hook on Spell_C_CastSpell itself via trampoline
|
||||
// re-entry, but still build and send CMSG_CAST_SPELL through the engine).
|
||||
// Snapshot the combo points at the moment the cast request leaves: the
|
||||
// server consumes them before SMSG_SPELL_GO arrives, so reading at
|
||||
// SpellGo time is too late.
|
||||
using NetSend_t = void(__fastcall *)(void *conn, void *edx,
|
||||
CDataStore *packet);
|
||||
NetSend_t g_origNetSend = nullptr;
|
||||
|
||||
void __fastcall NetSend_h(void *conn, void *edx, CDataStore *packet) {
|
||||
if (packet != nullptr) {
|
||||
const uint32_t saved = packet->m_read;
|
||||
const uint32_t opcode = Net::Read<uint32_t>(packet);
|
||||
if (opcode == Offsets::OP_CMSG_CAST_SPELL) {
|
||||
const uint32_t spellId = Net::Read<uint32_t>(packet);
|
||||
if (spellId != 0)
|
||||
g_capture = {spellId, CurrentComboPoints(), NowMs()};
|
||||
}
|
||||
packet->m_read = saved;
|
||||
}
|
||||
g_origNetSend(conn, edx, packet);
|
||||
}
|
||||
|
||||
const Game::HookAutoRegister _sendHook{
|
||||
Offsets::FUN_NET_SEND, reinterpret_cast<void *>(&NetSend_h),
|
||||
reinterpret_cast<void **>(&g_origNetSend)};
|
||||
|
||||
// ---- Duration data (SpellDuration.dbc + Lua overrides) --------------------
|
||||
|
||||
// Lua-registered overrides for spells whose client DBC row is missing or
|
||||
// wrong. Turtle's reworked Rip is the motivating case: its DurationIndex
|
||||
// dangles (records[87] == NULL in Turtle's SpellDuration.dbc) because the
|
||||
// rework lives entirely server-side, so the values must come from config.
|
||||
struct Override {
|
||||
uint32_t spellId;
|
||||
int32_t baseMs;
|
||||
int32_t maxMs;
|
||||
};
|
||||
constexpr int kMaxOverrides = 64;
|
||||
Override g_overrides[kMaxOverrides];
|
||||
int g_overrideCount = 0;
|
||||
|
||||
const Override *FindOverride(uint32_t spellId) {
|
||||
for (int i = 0; i < g_overrideCount; ++i) {
|
||||
if (g_overrides[i].spellId == spellId)
|
||||
return &g_overrides[i];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Known values for spells whose duration row DANGLES — a non-zero
|
||||
// DurationIndex pointing at a SpellDuration row the client doesn't have.
|
||||
// Consulted ONLY when that exact condition holds, so the gate is the bug
|
||||
// itself, not a server fingerprint: on a stock client every one of these
|
||||
// resolves to a valid row and this table is never reached, and if the
|
||||
// broken client data is ever fixed the DBC row takes over automatically.
|
||||
//
|
||||
// Turtle's reworked Rip is the known case: all six ranks point at
|
||||
// SpellDuration row 87, which Turtle added on the SERVER only
|
||||
// ({8000, 0, 18000} — live server data shows 10/12/14/16/18s at 1..5 CP,
|
||||
// i.e. 8s + 2s per combo point); their client patch never shipped the
|
||||
// row (the client table jumps 86 -> 105). Verified the only dangling
|
||||
// duration index in the entire client Spell.dbc.
|
||||
constexpr Override kDanglingRowKnown[] = {
|
||||
{1079, 8000, 18000}, {9492, 8000, 18000}, {9493, 8000, 18000},
|
||||
{9752, 8000, 18000}, {9894, 8000, 18000}, {9896, 8000, 18000},
|
||||
};
|
||||
|
||||
const Override *FindDanglingRowKnown(uint32_t spellId) {
|
||||
for (const auto &k : kDanglingRowKnown) {
|
||||
if (k.spellId == spellId)
|
||||
return &k;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// `C_UnitAuras.RegisterComboDuration(spellID, baseSeconds, maxSeconds)`
|
||||
// -> true on success. Re-registering a spellID replaces its entry.
|
||||
// Values are in seconds to match the C_UnitAuras duration convention;
|
||||
// the formula applied is the server's own:
|
||||
// `base + (max - base) * comboPoints / 5`.
|
||||
int __fastcall Script_RegisterComboDuration(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1) || !Game::Lua::IsNumber(L, 2) ||
|
||||
!Game::Lua::IsNumber(L, 3)) {
|
||||
Game::Lua::Error(
|
||||
L, "Usage: C_UnitAuras.RegisterComboDuration(spellID, "
|
||||
"baseSeconds, maxSeconds)");
|
||||
return 0;
|
||||
}
|
||||
const auto spellId = static_cast<uint32_t>(Game::Lua::ToNumber(L, 1));
|
||||
const auto baseMs = static_cast<int32_t>(Game::Lua::ToNumber(L, 2) * 1000.0);
|
||||
const auto maxMs = static_cast<int32_t>(Game::Lua::ToNumber(L, 3) * 1000.0);
|
||||
if (spellId == 0 || baseMs < 0 || maxMs <= 0) {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
}
|
||||
for (int i = 0; i < g_overrideCount; ++i) {
|
||||
if (g_overrides[i].spellId == spellId) {
|
||||
g_overrides[i] = {spellId, baseMs, maxMs};
|
||||
Game::Lua::PushBool(L, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (g_overrideCount >= kMaxOverrides) {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
}
|
||||
g_overrides[g_overrideCount++] = {spellId, baseMs, maxMs};
|
||||
Game::Lua::PushBool(L, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_UnitAuras", "RegisterComboDuration",
|
||||
&Script_RegisterComboDuration);
|
||||
}
|
||||
|
||||
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace
|
||||
|
||||
uint32_t TryComboScaledMs(const uint8_t *spellRecord, uint32_t spellId) {
|
||||
if (spellRecord == nullptr || spellId == 0)
|
||||
return 0;
|
||||
const int cp = ConsumeCapturedCP(spellId);
|
||||
if (cp <= 0 || cp > 5)
|
||||
return 0;
|
||||
|
||||
int32_t baseMs = 0;
|
||||
int32_t maxMs = 0;
|
||||
if (const Override *o = FindOverride(spellId)) {
|
||||
baseMs = o->baseMs;
|
||||
maxMs = o->maxMs;
|
||||
} else {
|
||||
const int idx = *reinterpret_cast<const int *>(
|
||||
spellRecord + Offsets::OFF_SPELL_RECORD_DURATION_INDEX);
|
||||
const uint8_t *row =
|
||||
DBC::Record(Offsets::VAR_SPELL_DURATION_RECORDS,
|
||||
Offsets::VAR_SPELL_DURATION_COUNT,
|
||||
static_cast<uint32_t>(idx));
|
||||
if (row != nullptr) {
|
||||
baseMs = *reinterpret_cast<const int32_t *>(row + 0x4);
|
||||
maxMs = *reinterpret_cast<const int32_t *>(row + 0xC);
|
||||
} else if (idx != 0) {
|
||||
// Dangling duration index — the client data is broken for this
|
||||
// spell. Fall back to the built-in known values (Turtle Rip).
|
||||
const Override *k = FindDanglingRowKnown(spellId);
|
||||
if (k == nullptr)
|
||||
return 0;
|
||||
baseMs = k->baseMs;
|
||||
maxMs = k->maxMs;
|
||||
} else {
|
||||
return 0; // no duration row at all
|
||||
}
|
||||
}
|
||||
|
||||
// The server scales only when the row has a combo range: base != max
|
||||
// ((v)mangos CalculateSpellDuration). base < 0 is the "infinite"
|
||||
// sentinel; fixed-duration rows (base == max) take the regular path.
|
||||
if (baseMs < 0 || maxMs <= 0 || baseMs == maxMs)
|
||||
return 0;
|
||||
|
||||
int32_t durationMs = baseMs + (maxMs - baseMs) * cp / 5;
|
||||
if (durationMs <= 0)
|
||||
return 0;
|
||||
|
||||
// Player duration SpellMods apply on top of the combo-scaled value,
|
||||
// matching the server's order (scale, then ApplySpellMod).
|
||||
durationMs = static_cast<int32_t>(Spell::Mod::Apply(
|
||||
spellRecord, Offsets::SPELLMOD_OP_DURATION,
|
||||
static_cast<float>(durationMs)));
|
||||
return durationMs > 0 ? static_cast<uint32_t>(durationMs) : 0;
|
||||
}
|
||||
|
||||
} // namespace Aura::ComboDuration
|
||||
@@ -0,0 +1,50 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// `Aura::ComboDuration` — combo-point-scaled durations for finisher
|
||||
// auras (Rupture, Kidney Shot, Slice and Dice, Rip, …).
|
||||
//
|
||||
// The 1.12 server computes a finisher's real duration at cast time as
|
||||
// `base + (max - base) * comboPoints / 5` from the spell's
|
||||
// SpellDuration.dbc row and never transmits the result for auras the
|
||||
// player puts on OTHER units (verified with a whole-protocol sniff:
|
||||
// SMSG_UPDATE_AURA_DURATION is self-scoped, and nothing else carries
|
||||
// it). So this module mirrors the computation client-side:
|
||||
//
|
||||
// - a co-hook on the NetClient send (`FUN_NET_SEND`) snapshots the
|
||||
// player's combo points the instant CMSG_CAST_SPELL leaves — the
|
||||
// one moment the count is still intact (the server clears it
|
||||
// before SMSG_SPELL_GO comes back);
|
||||
// - `TryComboScaledMs` consumes that snapshot when `Aura::Source`'s
|
||||
// SpellGo hook stores the aura, computing the scaled duration from
|
||||
// SpellDuration.dbc and applying the player's duration SpellMods on
|
||||
// top, matching the server's order of operations. Spells whose
|
||||
// duration index DANGLES (client data bug — Turtle's reworked Rip
|
||||
// is the known case) fall back to built-in values gated on that
|
||||
// exact condition; a Lua-registered override
|
||||
// (`C_UnitAuras.RegisterComboDuration`) beats both, as an escape
|
||||
// hatch for other servers whose values differ from the client DBC.
|
||||
namespace Aura::ComboDuration {
|
||||
|
||||
// Combo-scaled duration (ms) for a player-cast spell, or 0 when it
|
||||
// doesn't apply: no combo points captured for this cast, the spell's
|
||||
// duration row isn't combo-scaled (base == max) and has no override,
|
||||
// or the row is missing. A 0 return means "use the regular base
|
||||
// duration path".
|
||||
uint32_t TryComboScaledMs(const uint8_t *spellRecord, uint32_t spellId);
|
||||
|
||||
} // namespace Aura::ComboDuration
|
||||
+33
-4
@@ -492,6 +492,25 @@ void PushFromCache(void *L, const uint8_t *unit,
|
||||
c.casterGuid);
|
||||
}
|
||||
|
||||
// True if `unit`'s descriptor currently exposes any visible aura in either
|
||||
// range. The cache fallback is only trustworthy when the descriptor has been
|
||||
// wholesale-cleared: the two states it exists for — rogue stealth and party
|
||||
// range fluctuation — clear the *entire* aura array at once. If the unit shows
|
||||
// even one live aura, the descriptor is authoritative, so a cache entry the
|
||||
// descriptor lacks is a genuinely-gone aura we never saw removed (e.g. a
|
||||
// no-duration debuff — Ghost/Spirit — on a unit that died and resurrected out
|
||||
// of our visibility, so no OnAuraRemoved fired and its infinite entry never
|
||||
// expired). Surfacing it then produces a stuck phantom.
|
||||
bool DescriptorHasVisibleAura(const uint8_t *unit) {
|
||||
if (unit == nullptr)
|
||||
return false;
|
||||
for (int slot = 0; slot < Offsets::UNIT_AURA_TOTAL; ++slot) {
|
||||
if (IsSlotPopulated(unit, slot))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Counts populated descriptor slots matching `filter` (and `playerOnly`).
|
||||
int CountSlots(const uint8_t *unit, Filter filter, bool playerOnly) {
|
||||
if (unit == nullptr)
|
||||
@@ -515,12 +534,18 @@ int CountSlots(const uint8_t *unit, Filter filter, bool playerOnly) {
|
||||
constexpr int kFallbackMax = Offsets::UNIT_AURA_TOTAL;
|
||||
|
||||
// Whether cache entry `c` should be surfaced as a fallback for `unit` under
|
||||
// `filter`/`playerOnly`: it must not already be in a populated descriptor slot
|
||||
// (no double-listing the same live aura) and, when player-filtered, must have
|
||||
// been cast by us. Superseded / dispelled auras are kept out of the cache by
|
||||
// `Aura::Source`'s removal eviction, not filtered here.
|
||||
// `filter`/`playerOnly`: the spell must be a user-visible aura, it must not
|
||||
// already be in a populated descriptor slot (no double-listing the same live
|
||||
// aura) and, when player-filtered, must have been cast by us. Superseded /
|
||||
// dispelled auras are kept out of the cache by `Aura::Source`'s removal
|
||||
// eviction, not filtered here.
|
||||
bool FallbackEligible(const uint8_t *unit, const Aura::Source::CachedAura &c,
|
||||
Filter filter, bool playerOnly) {
|
||||
if (!IsVisible(SpellRecord(c.spellId)))
|
||||
return false; // hidden/internal aura (e.g. SPELL_ATTR_HIDDEN_CLIENTSIDE):
|
||||
// the descriptor path drops these via IsSlotPopulated, so
|
||||
// the cache path must apply the same engine predicate or
|
||||
// they leak through as tooltip-less phantom buffs.
|
||||
if (FindSlotBySpellID(unit, c.spellId, &filter, false) >= 0)
|
||||
return false; // still in the descriptor — returned via the slot path
|
||||
if (playerOnly && c.casterGuid != Unit::Identity::PlayerGuid())
|
||||
@@ -534,6 +559,8 @@ bool PushNthCacheFallback(void *L, const uint8_t *unit, int oneBasedIndex,
|
||||
Filter filter, bool playerOnly) {
|
||||
if (unit == nullptr)
|
||||
return false;
|
||||
if (DescriptorHasVisibleAura(unit))
|
||||
return false; // descriptor authoritative — see DescriptorHasVisibleAura
|
||||
// The descriptor held `descCount` matches; the caller already found fewer
|
||||
// than `oneBasedIndex` there, so the cache supplies index
|
||||
// `oneBasedIndex - descCount` (1-based) of the entries it didn't.
|
||||
@@ -562,6 +589,8 @@ void AppendCacheFallbacks(void *L, const uint8_t *unit, Filter filter,
|
||||
bool playerOnly, int outerIdx, int &nextKey) {
|
||||
if (unit == nullptr)
|
||||
return;
|
||||
if (DescriptorHasVisibleAura(unit))
|
||||
return; // descriptor authoritative — see DescriptorHasVisibleAura
|
||||
const uint64_t guid = UnitGuid(unit);
|
||||
if (guid == 0)
|
||||
return;
|
||||
|
||||
+40
-1
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "Source.h"
|
||||
|
||||
#include "ComboDuration.h"
|
||||
#include "Data.h"
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
@@ -149,10 +150,40 @@ void Evict(uint64_t targetGuid, uint32_t spellId) {
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe the whole cache. Used on a map transition (see OnWorldTick).
|
||||
void FlushAll() {
|
||||
for (auto &e : g_cache)
|
||||
e.used = false;
|
||||
}
|
||||
|
||||
// -1 = no map seen yet (never a valid Map.dbc id), so the first tick just
|
||||
// records the current map without flushing.
|
||||
int g_lastMapId = -1;
|
||||
|
||||
// Drop entries whose timed aura has elapsed so the table doesn't fill with
|
||||
// stale combat debuffs. Infinite-duration entries (expirationMs == 0) stay
|
||||
// until overwritten.
|
||||
//
|
||||
// Also flush the entire cache on a map-ID change. A battleground/instance/
|
||||
// continent transition (including the teleport out of a BG via /afk) bulk-
|
||||
// clears the player's aura descriptor WITHOUT firing per-aura OnAuraRemoved,
|
||||
// so entries for auras that are now gone would linger and the
|
||||
// GetAuraDataByIndex fallback would keep surfacing them — the "buffs/debuffs
|
||||
// stuck after leaving a battleground" report. Every other unit from the old
|
||||
// map has despawned too, and the local player's real auras re-sync into the
|
||||
// descriptor / PLAYER_BUFF tables on entering the new world, so a full flush
|
||||
// loses nothing legitimate. Crucially, the descriptor drops the fallback
|
||||
// must survive — rogue stealth and party-range fluctuation — do NOT change
|
||||
// the map ID, so they're unaffected.
|
||||
void OnWorldTick() {
|
||||
const int mapId = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CURRENT_MAP_ID));
|
||||
if (mapId != g_lastMapId) {
|
||||
if (g_lastMapId != -1)
|
||||
FlushAll();
|
||||
g_lastMapId = mapId;
|
||||
}
|
||||
|
||||
const uint32_t now = NowMs();
|
||||
for (auto &e : g_cache) {
|
||||
if (e.used && e.expirationMs != 0 && now >= e.expirationMs)
|
||||
@@ -203,7 +234,15 @@ void __fastcall SpellGo_h(uint64_t *itemGUID, uint64_t *casterGUID,
|
||||
return;
|
||||
|
||||
const bool casterIsPlayer = (caster == Unit::Identity::PlayerGuid());
|
||||
const uint32_t durationMs = SpellDurationMs(rec, casterIsPlayer);
|
||||
// Combo-point finishers (Rupture, Kidney Shot, …) have their real
|
||||
// duration computed at cast time from the combo points spent — the
|
||||
// base-duration helper can't know it. ComboDuration mirrors the
|
||||
// server's computation from the CP snapshot its send hook captured;
|
||||
// 0 means "not combo-scaled", fall through to the base path.
|
||||
uint32_t durationMs =
|
||||
casterIsPlayer ? ComboDuration::TryComboScaledMs(rec, spellId) : 0;
|
||||
if (durationMs == 0)
|
||||
durationMs = SpellDurationMs(rec, casterIsPlayer);
|
||||
const uint32_t expirationMs = durationMs > 0 ? NowMs() + durationMs : 0;
|
||||
|
||||
if (numTargets == 0) {
|
||||
|
||||
+29
-26
@@ -30,6 +30,16 @@ constexpr int kMaxDepth = 64;
|
||||
|
||||
// ---------------- encode ----------------
|
||||
|
||||
// tinycbor's grow-and-retry contract: on buffer overflow the encoder
|
||||
// switches to counting mode (end = NULL, accumulates bytes_needed) and
|
||||
// encoding must CONTINUE so the final tally is complete — a nested
|
||||
// container's tally only reaches the parent via close_container. So
|
||||
// CborErrorOutOfMemory is not a failure here; the caller reads
|
||||
// cbor_encoder_get_extra_bytes_needed() afterwards, resizes, retries.
|
||||
bool EncOk(CborError err) {
|
||||
return err == CborNoError || err == CborErrorOutOfMemory;
|
||||
}
|
||||
|
||||
bool EncodeValue(void *L, int idx, CborEncoder *enc, int depth);
|
||||
|
||||
bool IsLuaArray(void *L, int idx, int &outLen) {
|
||||
@@ -73,8 +83,8 @@ bool EncodeTable(void *L, int idx, CborEncoder *enc, int depth) {
|
||||
int arrayLen = 0;
|
||||
if (IsLuaArray(L, idx, arrayLen)) {
|
||||
CborEncoder arr;
|
||||
if (cbor_encoder_create_array(enc, &arr,
|
||||
static_cast<size_t>(arrayLen)) != CborNoError)
|
||||
if (!EncOk(cbor_encoder_create_array(enc, &arr,
|
||||
static_cast<size_t>(arrayLen))))
|
||||
return false;
|
||||
for (int i = 1; i <= arrayLen; ++i) {
|
||||
Game::Lua::PushNumber(L, static_cast<double>(i));
|
||||
@@ -85,12 +95,12 @@ bool EncodeTable(void *L, int idx, CborEncoder *enc, int depth) {
|
||||
}
|
||||
Game::Lua::SetTop(L, -2);
|
||||
}
|
||||
return cbor_encoder_close_container(enc, &arr) == CborNoError;
|
||||
return EncOk(cbor_encoder_close_container(enc, &arr));
|
||||
}
|
||||
|
||||
const int pairs = CountTablePairs(L, idx);
|
||||
CborEncoder map;
|
||||
if (cbor_encoder_create_map(enc, &map, static_cast<size_t>(pairs)) != CborNoError)
|
||||
if (!EncOk(cbor_encoder_create_map(enc, &map, static_cast<size_t>(pairs))))
|
||||
return false;
|
||||
Game::Lua::PushNil(L);
|
||||
while (Game::Lua::Next(L, idx) != 0) {
|
||||
@@ -101,16 +111,16 @@ bool EncodeTable(void *L, int idx, CborEncoder *enc, int depth) {
|
||||
}
|
||||
Game::Lua::SetTop(L, -2);
|
||||
}
|
||||
return cbor_encoder_close_container(enc, &map) == CborNoError;
|
||||
return EncOk(cbor_encoder_close_container(enc, &map));
|
||||
}
|
||||
|
||||
bool EncodeValue(void *L, int idx, CborEncoder *enc, int depth) {
|
||||
switch (Game::Lua::Type(L, idx)) {
|
||||
case Game::Lua::TYPE_NIL:
|
||||
return cbor_encode_null(enc) == CborNoError;
|
||||
return EncOk(cbor_encode_null(enc));
|
||||
case Game::Lua::TYPE_BOOLEAN:
|
||||
return cbor_encode_boolean(enc,
|
||||
Game::Lua::ToBoolean(L, idx) != 0) == CborNoError;
|
||||
return EncOk(cbor_encode_boolean(enc,
|
||||
Game::Lua::ToBoolean(L, idx) != 0));
|
||||
case Game::Lua::TYPE_NUMBER: {
|
||||
const double n = Game::Lua::ToNumber(L, idx);
|
||||
// Whole numbers in [-2^53, 2^53] go out as integers so
|
||||
@@ -118,17 +128,17 @@ bool EncodeValue(void *L, int idx, CborEncoder *enc, int depth) {
|
||||
if (std::isfinite(n) && n == std::floor(n) &&
|
||||
n >= -9007199254740992.0 && n <= 9007199254740992.0) {
|
||||
if (n >= 0.0)
|
||||
return cbor_encode_uint(enc,
|
||||
static_cast<uint64_t>(n)) == CborNoError;
|
||||
return cbor_encode_negative_int(enc,
|
||||
static_cast<uint64_t>(-n)) == CborNoError;
|
||||
return EncOk(cbor_encode_uint(enc,
|
||||
static_cast<uint64_t>(n)));
|
||||
return EncOk(cbor_encode_negative_int(enc,
|
||||
static_cast<uint64_t>(-n)));
|
||||
}
|
||||
return cbor_encode_double(enc, n) == CborNoError;
|
||||
return EncOk(cbor_encode_double(enc, n));
|
||||
}
|
||||
case Game::Lua::TYPE_STRING: {
|
||||
const char *s = Game::Lua::ToString(L, idx);
|
||||
const unsigned int n = Game::Lua::StrLen(L, idx);
|
||||
return cbor_encode_text_string(enc, s, n) == CborNoError;
|
||||
return EncOk(cbor_encode_text_string(enc, s, n));
|
||||
}
|
||||
case Game::Lua::TYPE_TABLE:
|
||||
return EncodeTable(L, idx, enc, depth);
|
||||
@@ -143,22 +153,15 @@ int __fastcall Script_SerializeCBOR(void *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// tinycbor encodes into a fixed-size buffer; if it overflows, it
|
||||
// tracks the extra bytes needed so we can resize and retry.
|
||||
// tinycbor encodes into a fixed-size buffer; on overflow it keeps
|
||||
// encoding in counting mode (EncOk treats OutOfMemory as success) so
|
||||
// the extra-bytes tally is complete, then we resize and retry once.
|
||||
std::vector<uint8_t> buf(256);
|
||||
for (;;) {
|
||||
CborEncoder enc;
|
||||
cbor_encoder_init(&enc, buf.data(), buf.size(), 0);
|
||||
if (!EncodeValue(L, 1, &enc, 0)) {
|
||||
// If it was a buffer-size issue we'll catch it via the
|
||||
// extra-bytes-needed check below; otherwise this is a
|
||||
// genuine "value not representable" failure.
|
||||
const size_t extra = cbor_encoder_get_extra_bytes_needed(&enc);
|
||||
if (extra == 0)
|
||||
return 0;
|
||||
buf.resize(buf.size() + extra);
|
||||
continue;
|
||||
}
|
||||
if (!EncodeValue(L, 1, &enc, 0))
|
||||
return 0; // genuine "value not representable" failure
|
||||
const size_t extra = cbor_encoder_get_extra_bytes_needed(&enc);
|
||||
if (extra > 0) {
|
||||
buf.resize(buf.size() + extra);
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// Modern Region/Frame method backports.
|
||||
//
|
||||
// Modern addon ports routinely call these methods unconditionally —
|
||||
// they're the C-level frame surface later clients take for granted.
|
||||
// This module supplies the ones vanilla lacks (surfaced via
|
||||
// AI_VoiceOver's modern code path, but generic to every port):
|
||||
//
|
||||
// - `region:SetPoint("RIGHT")` — the one-arg form. Vanilla's parser
|
||||
// accepts every other modern form but errors when arg 3 is fully
|
||||
// omitted; a co-hook on Script_SetPoint normalizes it to
|
||||
// `(point, 0, 0)` (parent-relative, zero offsets — the exact modern
|
||||
// semantic).
|
||||
// - `region:SetSize(w, h)` / `region:GetSize()` — registered on the
|
||||
// REGION base method registry, so they resolve on frames, buttons,
|
||||
// textures, fontstrings — everything.
|
||||
// - `frame:SetShown(shown)` — Show/Hide are per-branch script functions
|
||||
// (each with its own object typecheck), so SetShown is registered
|
||||
// separately on Frame / Texture / FontString with matching delegates.
|
||||
// - `frame:SetResizeBounds(minW, minH [, maxW, maxH])` — the modern
|
||||
// rename of vanilla's SetMinResize/SetMaxResize pair.
|
||||
// - `frame:HookScript(scriptType, handler)` — absent in vanilla
|
||||
// entirely. Chains after any existing handler and invokes `handler`
|
||||
// with modern positional args (see the implementation comment).
|
||||
//
|
||||
// Implementation style: each new method delegates to the ENGINE's own
|
||||
// Script_* implementations by reshaping the Lua stack and calling them
|
||||
// (`int __fastcall(void *L)`, self at index 1) — no re-derived setters,
|
||||
// so pixel/UI-scale conversion, object resolution, and type checking are
|
||||
// all the engine's own code. Values are read out BEFORE any stack
|
||||
// reshaping.
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace Frame::Modern {
|
||||
|
||||
namespace {
|
||||
|
||||
using ScriptFn_t = int(__fastcall *)(void *L);
|
||||
|
||||
int CallScript(uintptr_t fn, void *L) {
|
||||
return reinterpret_cast<ScriptFn_t>(fn)(L);
|
||||
}
|
||||
|
||||
// ---- SetSize / GetSize (Region base — all region types) -------------------
|
||||
|
||||
// `region:SetSize(width, height)` → SetWidth + SetHeight.
|
||||
int __fastcall Script_SetSize(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 2) || !Game::Lua::IsNumber(L, 3)) {
|
||||
Game::Lua::Error(L, "Usage: region:SetSize(width, height)");
|
||||
return 0;
|
||||
}
|
||||
const double h = Game::Lua::ToNumber(L, 3);
|
||||
Game::Lua::SetTop(L, 2); // (self, width)
|
||||
CallScript(Offsets::FUN_SCRIPT_REGION_SETWIDTH, L);
|
||||
Game::Lua::SetTop(L, 1); // (self)
|
||||
Game::Lua::PushNumber(L, h);
|
||||
CallScript(Offsets::FUN_SCRIPT_REGION_SETHEIGHT, L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// `region:GetSize()` → width, height.
|
||||
int __fastcall Script_GetSize(void *L) {
|
||||
Game::Lua::SetTop(L, 1); // (self)
|
||||
CallScript(Offsets::FUN_SCRIPT_REGION_GETWIDTH, L); // (self, w)
|
||||
CallScript(Offsets::FUN_SCRIPT_REGION_GETHEIGHT, L); // (self, w, h)
|
||||
return 2;
|
||||
}
|
||||
|
||||
// ---- SetShown (per-branch Show/Hide delegates) -----------------------------
|
||||
|
||||
// `object:SetShown(shown)` — any falsy value hides, truthy shows,
|
||||
// matching modern semantics.
|
||||
template <uintptr_t ShowFn, uintptr_t HideFn>
|
||||
int __fastcall Script_SetShown(void *L) {
|
||||
const bool shown = Game::Lua::ToBoolean(L, 2) != 0;
|
||||
Game::Lua::SetTop(L, 1); // (self) — Show/Hide take no args
|
||||
CallScript(shown ? ShowFn : HideFn, L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- SetResizeBounds (Frame) -----------------------------------------------
|
||||
|
||||
// `frame:SetResizeBounds(minWidth, minHeight [, maxWidth, maxHeight])` —
|
||||
// modern rename of the vanilla SetMinResize/SetMaxResize pair.
|
||||
int __fastcall Script_SetResizeBounds(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 2) || !Game::Lua::IsNumber(L, 3)) {
|
||||
Game::Lua::Error(L, "Usage: frame:SetResizeBounds(minWidth, "
|
||||
"minHeight [, maxWidth, maxHeight])");
|
||||
return 0;
|
||||
}
|
||||
const bool haveMax = Game::Lua::IsNumber(L, 4) && Game::Lua::IsNumber(L, 5);
|
||||
const double maxW = haveMax ? Game::Lua::ToNumber(L, 4) : 0.0;
|
||||
const double maxH = haveMax ? Game::Lua::ToNumber(L, 5) : 0.0;
|
||||
Game::Lua::SetTop(L, 3); // (self, minW, minH)
|
||||
CallScript(Offsets::FUN_SCRIPT_FRAME_SETMINRESIZE, L);
|
||||
if (haveMax) {
|
||||
Game::Lua::SetTop(L, 1); // (self)
|
||||
Game::Lua::PushNumber(L, maxW);
|
||||
Game::Lua::PushNumber(L, maxH);
|
||||
CallScript(Offsets::FUN_SCRIPT_FRAME_SETMAXRESIZE, L);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- HookScript (Frame) ----------------------------------------------------
|
||||
|
||||
// `frame:HookScript(scriptType, handler)` — vanilla has no HookScript at
|
||||
// all. Chains onto any existing handler: the old handler runs first,
|
||||
// vanilla-style (no args — it reads the `this`/`event`/`argN` globals like
|
||||
// every 1.12 handler), then `handler` is invoked MODERN-style with
|
||||
// positional arguments `(frame, event, arg1..arg9)` for OnEvent and
|
||||
// `(frame, arg1..arg9)` otherwise — mirroring the compat convention
|
||||
// modern addon ports expect (and ship themselves when they detect a
|
||||
// legacy client). The chain is a C closure over (handler, old, isOnEvent).
|
||||
|
||||
// Pushes _G[name].
|
||||
void PushGlobal(void *L, const char *name) {
|
||||
Game::Lua::PushString(L, name);
|
||||
Game::Lua::GetTable(L, Game::Lua::GLOBALS_INDEX);
|
||||
}
|
||||
|
||||
// The chained handler the engine actually invokes (with no args, like any
|
||||
// vanilla script handler). Upvalues: 1 = hook handler, 2 = old handler
|
||||
// (or nil), 3 = isOnEvent (number). Errors inside lua_call propagate to
|
||||
// the engine's own protected script dispatch.
|
||||
int __fastcall HookThunk(void *L) {
|
||||
if (Game::Lua::Type(L, Game::Lua::UpvalueIndex(2)) ==
|
||||
Game::Lua::TYPE_FUNCTION) {
|
||||
Game::Lua::PushValue(L, Game::Lua::UpvalueIndex(2));
|
||||
Game::Lua::Call(L, 0, 0);
|
||||
}
|
||||
const bool isOnEvent =
|
||||
Game::Lua::ToNumber(L, Game::Lua::UpvalueIndex(3)) != 0;
|
||||
Game::Lua::PushValue(L, Game::Lua::UpvalueIndex(1));
|
||||
PushGlobal(L, "this");
|
||||
if (isOnEvent)
|
||||
PushGlobal(L, "event");
|
||||
static const char *const kArgs[] = {"arg1", "arg2", "arg3", "arg4",
|
||||
"arg5", "arg6", "arg7", "arg8",
|
||||
"arg9"};
|
||||
for (const char *a : kArgs)
|
||||
PushGlobal(L, a);
|
||||
Game::Lua::Call(L, (isOnEvent ? 2 : 1) + 9, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __fastcall Script_HookScript(void *L) {
|
||||
if (!Game::Lua::IsString(L, 2) ||
|
||||
Game::Lua::Type(L, 3) != Game::Lua::TYPE_FUNCTION) {
|
||||
Game::Lua::Error(L, "Usage: frame:HookScript(\"type\", function)");
|
||||
return 0;
|
||||
}
|
||||
const char *scriptName = Game::Lua::ToString(L, 2);
|
||||
const bool isOnEvent =
|
||||
scriptName != nullptr && std::strcmp(scriptName, "OnEvent") == 0;
|
||||
|
||||
Game::Lua::SetTop(L, 3); // (self, name, handler)
|
||||
// GetScript reads self/name at 1/2 and pushes the current handler
|
||||
// (or nil) — extra stack entries above are ignored by its reads.
|
||||
CallScript(Offsets::FUN_SCRIPT_FRAME_GETSCRIPT, L); // (.., old)
|
||||
// Closure upvalues, in upvalue order: handler, old, isOnEvent.
|
||||
Game::Lua::PushValue(L, 3); // handler
|
||||
Game::Lua::PushValue(L, 4); // old
|
||||
Game::Lua::PushNumber(L, isOnEvent ? 1.0 : 0.0); // flag
|
||||
Game::Lua::PushCClosure(L, &HookThunk, 3); // (self,name,handler,old,closure)
|
||||
Game::Lua::Remove(L, 4); // drop old
|
||||
Game::Lua::Remove(L, 3); // drop handler → (self,name,closure)
|
||||
CallScript(Offsets::FUN_SCRIPT_FRAME_SETSCRIPT, L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- IsEventRegistered (Frame) ---------------------------------------------
|
||||
|
||||
// `frame:IsEventRegistered("event")` — vanilla has RegisterEvent /
|
||||
// UnregisterEvent but not the query. There's no engine Script_* to
|
||||
// delegate to, so we replicate the membership check that lives inside
|
||||
// Frame::RegisterEvent (FUN_00702140): find the event by name in the live
|
||||
// event table, then walk that entry's subscriber chain for this frame.
|
||||
// The frame pointer we compare against is the same CFrameScriptObject*
|
||||
// the engine stores (Game::Lua::ResolveObject resolves self exactly as
|
||||
// Script_RegisterEvent does).
|
||||
using SStrCmpI_t = int(__stdcall *)(const char *a, const char *b, int n);
|
||||
|
||||
bool FrameHasEvent(void *frame, const char *eventName) {
|
||||
const uint32_t count = *reinterpret_cast<const uint32_t *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_EVENT_TABLE_COUNT));
|
||||
auto *base = *reinterpret_cast<const uint8_t *const *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_EVENT_TABLE_BASE_PTR));
|
||||
if (count == 0 || base == nullptr)
|
||||
return false;
|
||||
|
||||
auto sstrcmpi = reinterpret_cast<SStrCmpI_t>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_SSTR_CMP_I));
|
||||
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
const uint8_t *entry = base + i * Offsets::EVENT_ENTRY_STRIDE;
|
||||
const char *name = *reinterpret_cast<const char *const *>(
|
||||
entry + Offsets::OFF_EVENT_ENTRY_NAME);
|
||||
if (name == nullptr)
|
||||
continue;
|
||||
if (sstrcmpi(name, eventName, 0x7FFFFFFF) != 0)
|
||||
continue;
|
||||
// Names are unique, so this is the one entry — walk its chain.
|
||||
uintptr_t node = *reinterpret_cast<const uintptr_t *>(
|
||||
entry + Offsets::OFF_EVENT_ENTRY_HEAD);
|
||||
while ((node & 1) == 0 && node != 0) {
|
||||
if (*reinterpret_cast<void *const *>(
|
||||
node + Offsets::OFF_EVENT_NODE_FRAME) == frame)
|
||||
return true;
|
||||
node = *reinterpret_cast<const uintptr_t *>(
|
||||
node + Offsets::OFF_EVENT_NODE_NEXT);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int __fastcall Script_IsEventRegistered(void *L) {
|
||||
if (!Game::Lua::IsString(L, 2)) {
|
||||
Game::Lua::Error(L, "Usage: frame:IsEventRegistered(\"event\")");
|
||||
return 0;
|
||||
}
|
||||
void *frame = Game::Lua::ResolveObject(L, 1);
|
||||
const char *eventName = Game::Lua::ToString(L, 2);
|
||||
const bool registered =
|
||||
frame != nullptr && eventName != nullptr && FrameHasEvent(frame, eventName);
|
||||
Game::Lua::PushBool(L, registered);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ---- SetPoint one-arg form (Script_SetPoint co-hook) -----------------------
|
||||
|
||||
// Vanilla's Script_SetPoint accepts every modern form except the bare
|
||||
// one-arg call (`region:SetPoint("RIGHT")`) — a fully-omitted arg 3 is
|
||||
// LUA_TNONE, which fails its string/table/number/nil validation and
|
||||
// raises the usage error. Normalize to the vanilla (point, x, y) form
|
||||
// with zero offsets, which anchors relative to the parent at the same
|
||||
// point — exactly the modern one-arg semantic. All other call shapes
|
||||
// pass through untouched.
|
||||
ScriptFn_t g_origSetPoint = nullptr;
|
||||
|
||||
int __fastcall SetPoint_h(void *L) {
|
||||
if (Game::Lua::GetTop(L) == 2 && Game::Lua::IsString(L, 2)) {
|
||||
Game::Lua::PushNumber(L, 0.0);
|
||||
Game::Lua::PushNumber(L, 0.0);
|
||||
}
|
||||
return g_origSetPoint(L);
|
||||
}
|
||||
|
||||
const Game::HookAutoRegister _setPointHook{
|
||||
Offsets::FUN_SCRIPT_REGION_SETPOINT,
|
||||
reinterpret_cast<void *>(&SetPoint_h),
|
||||
reinterpret_cast<void **>(&g_origSetPoint)};
|
||||
|
||||
// ---- Registration ----------------------------------------------------------
|
||||
|
||||
const Game::Lua::FrameMethodEntry g_regionMethods[] = {
|
||||
{"SetSize", &Script_SetSize},
|
||||
{"GetSize", &Script_GetSize},
|
||||
};
|
||||
|
||||
const Game::Lua::FrameMethodEntry g_frameMethods[] = {
|
||||
{"SetShown", &Script_SetShown<Offsets::FUN_SCRIPT_FRAME_SHOW,
|
||||
Offsets::FUN_SCRIPT_FRAME_HIDE>},
|
||||
{"SetResizeBounds", &Script_SetResizeBounds},
|
||||
{"HookScript", &Script_HookScript},
|
||||
{"IsEventRegistered", &Script_IsEventRegistered},
|
||||
};
|
||||
|
||||
const Game::Lua::FrameMethodEntry g_textureMethods[] = {
|
||||
{"SetShown", &Script_SetShown<Offsets::FUN_SCRIPT_TEXTURE_SHOW,
|
||||
Offsets::FUN_SCRIPT_TEXTURE_HIDE>},
|
||||
};
|
||||
|
||||
const Game::Lua::FrameMethodEntry g_fontStringMethods[] = {
|
||||
{"SetShown", &Script_SetShown<Offsets::FUN_SCRIPT_FONTSTRING_SHOW,
|
||||
Offsets::FUN_SCRIPT_FONTSTRING_HIDE>},
|
||||
};
|
||||
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterFrameMethods(
|
||||
reinterpret_cast<void *>(Offsets::VAR_REGION_METHOD_REGISTRY),
|
||||
g_regionMethods,
|
||||
static_cast<int>(sizeof(g_regionMethods) / sizeof(g_regionMethods[0])));
|
||||
Game::Lua::RegisterFrameMethods(
|
||||
reinterpret_cast<void *>(Offsets::VAR_FRAME_METHOD_REGISTRY),
|
||||
g_frameMethods,
|
||||
static_cast<int>(sizeof(g_frameMethods) / sizeof(g_frameMethods[0])));
|
||||
Game::Lua::RegisterFrameMethods(
|
||||
reinterpret_cast<void *>(Offsets::VAR_TEXTURE_METHOD_REGISTRY),
|
||||
g_textureMethods,
|
||||
static_cast<int>(sizeof(g_textureMethods) / sizeof(g_textureMethods[0])));
|
||||
Game::Lua::RegisterFrameMethods(
|
||||
reinterpret_cast<void *>(Offsets::VAR_FONTSTRING_METHOD_REGISTRY),
|
||||
g_fontStringMethods,
|
||||
static_cast<int>(sizeof(g_fontStringMethods) /
|
||||
sizeof(g_fontStringMethods[0])));
|
||||
}
|
||||
|
||||
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Frame::Modern
|
||||
+159
-11
@@ -22,6 +22,24 @@
|
||||
// SMSG_GOSSIP_MESSAGE handler at `0x004E26E0` and cleared each open.
|
||||
// We read the same shape the engine's own `Script_GetGossip*` reads.
|
||||
//
|
||||
// Vanilla has a SECOND questgiver path this namespace also covers:
|
||||
// NPCs without a gossip menu send SMSG_QUESTGIVER_QUEST_LIST instead —
|
||||
// the QUEST_GREETING event and the QuestFrameGreetingPanel ("Current
|
||||
// Quests" / "Available Quests") — whose data lands in a storage
|
||||
// entirely separate from the gossip arrays (see the VAR_GREETING_*
|
||||
// block in Offsets.h). Retail keeps the two APIs disjoint, but for
|
||||
// backporting it's far more useful for `C_GossipInfo` to serve
|
||||
// whichever questgiver session is actually live:
|
||||
// - gossip session live (VAR_GOSSIP_NPC_GUID != 0) → gossip arrays
|
||||
// - greeting session live (VAR_QUESTGIVER_GUID != 0
|
||||
// and == VAR_GREETING_NPC_GUID) → greeting arrays
|
||||
// - neither → empty / ""
|
||||
// The GUID gates double as staleness protection: both storages persist
|
||||
// after their frames close (the engine never clears them until the
|
||||
// next open), so ungated reads would report the previous NPC.
|
||||
// `GetOptions`/`GetNumOptions` stay gossip-only — greetings have no
|
||||
// options.
|
||||
//
|
||||
// Missing modern fields — vanilla 1.12's server simply never sends
|
||||
// them, so there's nothing to surface:
|
||||
// - `rewards`, `spellID` (post-vanilla; merged in with the
|
||||
@@ -46,6 +64,57 @@ namespace {
|
||||
|
||||
using EngineScriptFn = int(__fastcall *)(void *L);
|
||||
|
||||
uint64_t ReadU64(uintptr_t va) {
|
||||
return *reinterpret_cast<const uint64_t *>(va);
|
||||
}
|
||||
|
||||
// A gossip session is live from SMSG_GOSSIP_MESSAGE until the close
|
||||
// worker (0x004E1FA0) zeroes the GUID and fires GOSSIP_CLOSED.
|
||||
bool GossipSessionActive() {
|
||||
return ReadU64(Offsets::VAR_GOSSIP_NPC_GUID) != 0;
|
||||
}
|
||||
|
||||
// A quest-greeting session is live while the quest-session GUID is set
|
||||
// AND the greeting arrays were filled for that same NPC. The second
|
||||
// check matters because a gossip-menu quest click opens a quest session
|
||||
// at panel 1 without ever touching the greeting arrays — without it,
|
||||
// leftovers from an older greeting NPC would leak through.
|
||||
bool GreetingSessionActive() {
|
||||
const uint64_t giver = ReadU64(Offsets::VAR_QUESTGIVER_GUID);
|
||||
return giver != 0 && giver == ReadU64(Offsets::VAR_GREETING_NPC_GUID);
|
||||
}
|
||||
|
||||
const uint8_t *GreetingEntry(bool active, int slot) {
|
||||
const uintptr_t base = active ? Offsets::VAR_GREETING_ACTIVE_ENTRIES
|
||||
: Offsets::VAR_GREETING_AVAILABLE_ENTRIES;
|
||||
return reinterpret_cast<const uint8_t *>(
|
||||
base + static_cast<uintptr_t>(slot) * Offsets::GREETING_QUESTS_STRIDE);
|
||||
}
|
||||
|
||||
int GreetingCount(bool active) {
|
||||
const int count = *reinterpret_cast<const int *>(
|
||||
active ? Offsets::VAR_GREETING_ACTIVE_COUNT
|
||||
: Offsets::VAR_GREETING_AVAILABLE_COUNT);
|
||||
return (count < 0) ? 0
|
||||
: (count > Offsets::GREETING_QUESTS_MAX) ? Offsets::GREETING_QUESTS_MAX
|
||||
: count;
|
||||
}
|
||||
|
||||
// The greeting arrays drop the per-quest dialog status, but the packet
|
||||
// handler's scratch arrays (packet order, zeroed per packet) keep it —
|
||||
// status 4 = complete/turn-in-ready, same sentinel as the gossip rows.
|
||||
bool GreetingQuestIsComplete(uint32_t questID) {
|
||||
const auto *ids = reinterpret_cast<const uint32_t *>(
|
||||
Offsets::VAR_GREETING_SCRATCH_IDS);
|
||||
const auto *status = reinterpret_cast<const uint32_t *>(
|
||||
Offsets::VAR_GREETING_SCRATCH_STATUS);
|
||||
for (int i = 0; i < Offsets::GREETING_QUESTS_MAX; ++i) {
|
||||
if (ids[i] == questID)
|
||||
return status[i] == 4;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint8_t *OptionEntry(int slot) {
|
||||
return reinterpret_cast<const uint8_t *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_GOSSIP_OPTIONS) +
|
||||
@@ -79,14 +148,21 @@ bool IsActiveQuest(uint32_t status) {
|
||||
return status == 3 || status == 4;
|
||||
}
|
||||
|
||||
// `C_GossipInfo.GetText()` — pushes the greeting string the engine
|
||||
// resolved for the gossip-giver's NPC_TEXT.dbc entry. Mirrors what
|
||||
// `Script_GetGossipText` does (one inline `lua_pushstring` of the
|
||||
// fixed buffer at `VAR_GOSSIP_GREETING_TEXT`).
|
||||
// `C_GossipInfo.GetText()` — the greeting string of whichever
|
||||
// questgiver session is live: the gossip buffer (what
|
||||
// `Script_GetGossipText` pushes) for a gossip session, the quest
|
||||
// greeting buffer (what `Script_GetGreetingText` pushes) for a
|
||||
// greeting session, "" when neither is open. Both buffers persist
|
||||
// after close, so the gates keep stale text from the previous NPC
|
||||
// out.
|
||||
int __fastcall Script_C_GossipInfo_GetText(void *L) {
|
||||
const char *text = reinterpret_cast<const char *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_GOSSIP_GREETING_TEXT));
|
||||
Game::Lua::PushString(L, text);
|
||||
uintptr_t buf = 0;
|
||||
if (GossipSessionActive())
|
||||
buf = Offsets::VAR_GOSSIP_GREETING_TEXT;
|
||||
else if (GreetingSessionActive())
|
||||
buf = Offsets::VAR_QUEST_GREETING_TEXT;
|
||||
Game::Lua::PushString(
|
||||
L, (buf != 0) ? reinterpret_cast<const char *>(buf) : "");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -108,6 +184,8 @@ int __fastcall Script_C_GossipInfo_GetText(void *L) {
|
||||
int __fastcall Script_C_GossipInfo_GetOptions(void *L) {
|
||||
Game::Lua::SetTop(L, 0);
|
||||
Game::Lua::NewTable(L);
|
||||
if (!GossipSessionActive())
|
||||
return 1; // greeting sessions have no options; stale data stays hidden
|
||||
|
||||
int outIdx = 0;
|
||||
for (int slot = 0; slot < Offsets::GOSSIP_OPTIONS_MAX; ++slot) {
|
||||
@@ -138,6 +216,36 @@ int __fastcall Script_C_GossipInfo_GetOptions(void *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Greeting-session variant: walks the pre-split greeting array for the
|
||||
// wanted side. Same table shape as the gossip rows (questID / title /
|
||||
// questLevel / isComplete) so consumers can't tell the sources apart.
|
||||
int PushGreetingQuestList(void *L, bool wantActive) {
|
||||
const int count = GreetingCount(wantActive);
|
||||
for (int slot = 0; slot < count; ++slot) {
|
||||
const uint8_t *entry = GreetingEntry(wantActive, slot);
|
||||
const uint32_t questID = *reinterpret_cast<const uint32_t *>(
|
||||
entry + Offsets::OFF_GREETING_QUEST_ID);
|
||||
|
||||
Game::Lua::PushNumber(L, static_cast<double>(slot + 1));
|
||||
Game::Lua::NewTable(L);
|
||||
|
||||
Game::Lua::SetFieldNumber(L, "questID",
|
||||
static_cast<double>(questID));
|
||||
Game::Lua::SetFieldString(L, "title", reinterpret_cast<const char *>(
|
||||
entry + Offsets::OFF_GREETING_QUEST_TITLE));
|
||||
const int32_t level = *reinterpret_cast<const int32_t *>(
|
||||
entry + Offsets::OFF_GREETING_QUEST_LEVEL);
|
||||
Game::Lua::SetFieldNumber(L, "questLevel",
|
||||
static_cast<double>(level));
|
||||
if (wantActive)
|
||||
Game::Lua::SetFieldBool(L, "isComplete",
|
||||
GreetingQuestIsComplete(questID));
|
||||
|
||||
Game::Lua::SetTable(L, -3);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Shared body for `GetAvailableQuests` / `GetActiveQuests`. Both walk
|
||||
// the same backing array and split by the `status` field — `wantActive`
|
||||
// inverts the filter.
|
||||
@@ -145,6 +253,12 @@ int PushQuestList(void *L, bool wantActive) {
|
||||
Game::Lua::SetTop(L, 0);
|
||||
Game::Lua::NewTable(L);
|
||||
|
||||
if (!GossipSessionActive()) {
|
||||
if (GreetingSessionActive())
|
||||
return PushGreetingQuestList(L, wantActive);
|
||||
return 1; // no questgiver session — empty table, never stale data
|
||||
}
|
||||
|
||||
int outIdx = 0;
|
||||
for (int slot = 0; slot < Offsets::GOSSIP_QUESTS_MAX; ++slot) {
|
||||
const uint8_t *entry = QuestEntry(slot);
|
||||
@@ -189,15 +303,19 @@ int __fastcall Script_C_GossipInfo_GetActiveQuests(void *L) {
|
||||
|
||||
int __fastcall Script_C_GossipInfo_GetNumOptions(void *L) {
|
||||
int count = 0;
|
||||
for (int slot = 0; slot < Offsets::GOSSIP_OPTIONS_MAX; ++slot) {
|
||||
if (OptionIndex(OptionEntry(slot)) >= 0)
|
||||
count += 1;
|
||||
if (GossipSessionActive()) {
|
||||
for (int slot = 0; slot < Offsets::GOSSIP_OPTIONS_MAX; ++slot) {
|
||||
if (OptionIndex(OptionEntry(slot)) >= 0)
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
Game::Lua::PushNumber(L, static_cast<double>(count));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CountQuests(bool wantActive) {
|
||||
if (!GossipSessionActive())
|
||||
return GreetingSessionActive() ? GreetingCount(wantActive) : 0;
|
||||
int count = 0;
|
||||
for (int slot = 0; slot < Offsets::GOSSIP_QUESTS_MAX; ++slot) {
|
||||
const uint8_t *entry = QuestEntry(slot);
|
||||
@@ -247,6 +365,17 @@ void EngineSelectActiveQuest(int idx0Based) {
|
||||
fn(idx0Based);
|
||||
}
|
||||
|
||||
// Greeting-session selectors — the workers vanilla's
|
||||
// Script_Select{Available,Active}Quest call. Index straight into the
|
||||
// corresponding greeting array (they validate the questgiver GUID
|
||||
// internally before sending the CMSG).
|
||||
void EngineSelectGreetingQuest(bool wantActive, int idx0Based) {
|
||||
auto fn = reinterpret_cast<SelectQuest_t>(
|
||||
wantActive ? Offsets::FUN_GREETING_SELECT_ACTIVE_QUEST
|
||||
: Offsets::FUN_GREETING_SELECT_AVAILABLE_QUEST);
|
||||
fn(idx0Based);
|
||||
}
|
||||
|
||||
// `C_GossipInfo.SelectOption(gossipOptionID[, text])` — wraps vanilla's
|
||||
// `SelectGossipOption(slotIndex)`. `text` is the boxCoded password,
|
||||
// passed through to the engine helper which gates on the
|
||||
@@ -260,6 +389,8 @@ int __fastcall Script_C_GossipInfo_SelectOption(void *L) {
|
||||
const int target = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
const char *password =
|
||||
Game::Lua::IsString(L, 2) ? Game::Lua::ToString(L, 2) : nullptr;
|
||||
if (!GossipSessionActive())
|
||||
return 0; // stale option slots must not send a CMSG
|
||||
|
||||
for (int slot = 0; slot < Offsets::GOSSIP_OPTIONS_MAX; ++slot) {
|
||||
const uint8_t *entry = OptionEntry(slot);
|
||||
@@ -284,7 +415,8 @@ int __fastcall Script_C_GossipInfo_SelectOptionByIndex(void *L) {
|
||||
return 0;
|
||||
}
|
||||
const int slot0Based = static_cast<int>(Game::Lua::ToNumber(L, 1)) - 1;
|
||||
if (slot0Based < 0 || slot0Based >= Offsets::GOSSIP_OPTIONS_MAX)
|
||||
if (slot0Based < 0 || slot0Based >= Offsets::GOSSIP_OPTIONS_MAX ||
|
||||
!GossipSessionActive())
|
||||
return 0;
|
||||
EngineSelectOption(slot0Based, nullptr);
|
||||
return 0;
|
||||
@@ -301,6 +433,22 @@ int SelectQuestByID(void *L, bool wantActive, const char *errUsage) {
|
||||
}
|
||||
const uint32_t target = static_cast<uint32_t>(Game::Lua::ToNumber(L, 1));
|
||||
|
||||
if (!GossipSessionActive()) {
|
||||
if (!GreetingSessionActive())
|
||||
return 0;
|
||||
const int count = GreetingCount(wantActive);
|
||||
for (int slot = 0; slot < count; ++slot) {
|
||||
const uint32_t questID = *reinterpret_cast<const uint32_t *>(
|
||||
GreetingEntry(wantActive, slot) +
|
||||
Offsets::OFF_GREETING_QUEST_ID);
|
||||
if (questID == target) {
|
||||
EngineSelectGreetingQuest(wantActive, slot);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int idx = 0;
|
||||
for (int slot = 0; slot < Offsets::GOSSIP_QUESTS_MAX; ++slot) {
|
||||
const uint8_t *entry = QuestEntry(slot);
|
||||
|
||||
@@ -0,0 +1,373 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// `C_LossOfControl` — active loss-of-control effects on the LOCAL PLAYER.
|
||||
// Vanilla 1.12 has no such aggregation layer (it's a MoP addition), so we
|
||||
// synthesize it from two sources:
|
||||
//
|
||||
// 1. SCHOOL_INTERRUPT — the Counterspell/Kick school lockout. The server
|
||||
// (Player::ProhibitSpellSchool) delivers it as a single
|
||||
// SMSG_SPELL_COOLDOWN carrying every spell of the interrupted school,
|
||||
// all with the same duration. That "player-GUID packet, >=2 spells, one
|
||||
// uniform duration" shape is produced by nothing else (normal cooldowns
|
||||
// are single-spell or applied client-side), so co-hooking the cooldown
|
||||
// handler and matching it yields an authoritative school + duration.
|
||||
// The interrupting spell isn't in the packet, so spellID is 0 and
|
||||
// displayText is a fixed "Interrupted" — the mechanically-relevant data
|
||||
// (school, duration, timing) is exact.
|
||||
//
|
||||
// 2. CC debuffs — stun / fear / root / confuse / charm / possess / silence /
|
||||
// pacify / disarm are real debuff auras. We scan the player's debuffs and
|
||||
// classify each by its spell's EffectApplyAuraName. Timing is best-effort
|
||||
// from the Aura::Source cache (nil when the cast wasn't observed — the
|
||||
// LoC timing fields are nullable, so that's contract-valid).
|
||||
//
|
||||
// Placeholders for fields with no vanilla equivalent: priority = 0,
|
||||
// displayType = 2 (show for full duration), auraInstanceID = nil. iconTexture
|
||||
// is the spell's icon PATH (vanilla has no FileDataIDs; a path is the
|
||||
// functional equivalent).
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "aura/Data.h"
|
||||
#include "aura/Source.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "event/Custom.h"
|
||||
#include "net/PacketReader.h"
|
||||
#include "spell/Lookup.h"
|
||||
#include "tick/WorldTick.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace LossOfControl {
|
||||
|
||||
namespace {
|
||||
|
||||
using TickMs_t = uint32_t(__fastcall *)();
|
||||
int NowMs() {
|
||||
return static_cast<int>(
|
||||
reinterpret_cast<TickMs_t>(Offsets::FUN_OS_TICKCOUNT_MS)());
|
||||
}
|
||||
|
||||
// Spell.dbc field readers (mirrors the small locals in Spell::Cast).
|
||||
constexpr int OFF_NAME = 0x1E0; // localized name[9]
|
||||
constexpr int OFF_ICON_ID = 0x1D4; // -> SpellIcon.dbc
|
||||
|
||||
const char *SpellName(const uint8_t *rec) {
|
||||
const int locale = *reinterpret_cast<int *>(Offsets::VAR_LOCALE_INDEX);
|
||||
const char *n =
|
||||
*reinterpret_cast<const char *const *>(rec + OFF_NAME + locale * 4);
|
||||
return (n != nullptr) ? n : "";
|
||||
}
|
||||
|
||||
const char *SpellIconPath(const uint8_t *rec) {
|
||||
const int iconID = *reinterpret_cast<const int *>(rec + OFF_ICON_ID);
|
||||
const uint8_t *iconRec = DBC::Record(Offsets::VAR_SPELL_ICON_RECORDS,
|
||||
Offsets::VAR_SPELL_ICON_COUNT,
|
||||
static_cast<uint32_t>(iconID));
|
||||
if (iconRec == nullptr)
|
||||
return "";
|
||||
const char *p = *reinterpret_cast<const char *const *>(iconRec + 0x04);
|
||||
return (p != nullptr) ? p : "";
|
||||
}
|
||||
|
||||
int SpellSchoolIndex(const uint8_t *rec) {
|
||||
return *reinterpret_cast<const int *>(rec + Offsets::OFF_SPELL_SCHOOL);
|
||||
}
|
||||
|
||||
// Classify a spell's control-loss type from its EffectApplyAuraName array, or
|
||||
// null if it applies no control-loss aura. Priority-ordered (strongest control
|
||||
// first) so a multi-effect spell resolves to one locType, matching retail.
|
||||
const char *ClassifyControlLoss(const uint8_t *rec) {
|
||||
const int32_t *aura = reinterpret_cast<const int32_t *>(
|
||||
rec + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME);
|
||||
auto has = [&](int type) {
|
||||
for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i)
|
||||
if (aura[i] == type)
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
if (has(Offsets::SPELL_AURA_MOD_POSSESS)) return "POSSESS";
|
||||
if (has(Offsets::SPELL_AURA_MOD_CHARM)) return "CHARM";
|
||||
if (has(Offsets::SPELL_AURA_MOD_STUN)) return "STUN";
|
||||
if (has(Offsets::SPELL_AURA_MOD_FEAR)) return "FEAR";
|
||||
if (has(Offsets::SPELL_AURA_MOD_CONFUSE)) return "CONFUSE";
|
||||
if (has(Offsets::SPELL_AURA_MOD_PACIFY_SILENCE)) return "PACIFYSILENCE";
|
||||
if (has(Offsets::SPELL_AURA_MOD_SILENCE)) return "SILENCE";
|
||||
if (has(Offsets::SPELL_AURA_MOD_PACIFY)) return "PACIFY";
|
||||
if (has(Offsets::SPELL_AURA_MOD_ROOT)) return "ROOT";
|
||||
if (has(Offsets::SPELL_AURA_MOD_DISARM)) return "DISARM";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ---- School-interrupt lockout state (fed by the SMSG_SPELL_COOLDOWN hook) --
|
||||
|
||||
// One active lockout per school index (0..6); active while now < endMs.
|
||||
// Self-expiring, per-process — a stale entry from before a relog is already
|
||||
// in the past on the shared uptime clock, so no reset is needed.
|
||||
struct SchoolLock {
|
||||
int startMs;
|
||||
int endMs;
|
||||
};
|
||||
SchoolLock g_schoolLock[Offsets::SPELL_SCHOOL_COUNT] = {};
|
||||
|
||||
using CooldownHandler_t = int(__stdcall *)(uint32_t *opCode,
|
||||
Net::CDataStore *packet);
|
||||
CooldownHandler_t g_origCooldown = nullptr;
|
||||
|
||||
int __stdcall Cooldown_h(uint32_t *opCode, Net::CDataStore *packet) {
|
||||
if (packet != nullptr) {
|
||||
const uint32_t saved = packet->m_read;
|
||||
const uint64_t guid = Net::Read<uint64_t>(packet);
|
||||
if (guid != 0 && guid == Unit::Identity::PlayerGuid()) {
|
||||
int count = 0;
|
||||
int firstDur = 0;
|
||||
bool uniform = true;
|
||||
int schoolIdx = -1;
|
||||
while (packet->m_read + 8 <= packet->m_size && count < 256) {
|
||||
const uint32_t spellID = Net::Read<uint32_t>(packet);
|
||||
const int dur = static_cast<int>(Net::Read<uint32_t>(packet));
|
||||
if (count == 0)
|
||||
firstDur = dur;
|
||||
else if (dur != firstDur)
|
||||
uniform = false;
|
||||
if (schoolIdx < 0) {
|
||||
const uint8_t *rec =
|
||||
Spell::Lookup::RecordForID(static_cast<int>(spellID));
|
||||
if (rec != nullptr) {
|
||||
const int s = SpellSchoolIndex(rec);
|
||||
if (s >= 0 && s < Offsets::SPELL_SCHOOL_COUNT)
|
||||
schoolIdx = s;
|
||||
}
|
||||
}
|
||||
++count;
|
||||
}
|
||||
// A uniform-duration batch of >=2 same-school spells is a school
|
||||
// lockout (ProhibitSpellSchool); single/varied packets are normal
|
||||
// cooldowns and ignored.
|
||||
if (count >= 2 && uniform && firstDur > 0 && schoolIdx >= 0) {
|
||||
const int now = NowMs();
|
||||
g_schoolLock[schoolIdx].startMs = now;
|
||||
g_schoolLock[schoolIdx].endMs = now + firstDur;
|
||||
}
|
||||
}
|
||||
packet->m_read = saved; // restore before the engine re-parses
|
||||
}
|
||||
return g_origCooldown(opCode, packet);
|
||||
}
|
||||
|
||||
const Game::HookAutoRegister _cooldownHook{
|
||||
Offsets::FUN_SPELL_COOLDOWN_HANDLER, reinterpret_cast<void *>(&Cooldown_h),
|
||||
reinterpret_cast<void **>(&g_origCooldown)};
|
||||
|
||||
// ---- Aggregated active-effect list ----------------------------------------
|
||||
|
||||
struct LocEntry {
|
||||
const char *locType;
|
||||
int spellID; // 0 = unknown (school interrupt)
|
||||
const uint8_t *rec; // spell record for name/icon; null for school interrupt
|
||||
int schoolMask; // lockoutSchool
|
||||
int startMs; // 0 = unknown
|
||||
int endMs; // 0 = unknown / no timing
|
||||
};
|
||||
|
||||
int BuildList(LocEntry *out, int maxOut) {
|
||||
const int now = NowMs();
|
||||
int n = 0;
|
||||
|
||||
// School-interrupt lockouts first.
|
||||
for (int s = 0; s < Offsets::SPELL_SCHOOL_COUNT && n < maxOut; ++s) {
|
||||
if (g_schoolLock[s].endMs != 0 && now < g_schoolLock[s].endMs) {
|
||||
LocEntry &e = out[n++];
|
||||
e.locType = "SCHOOL_INTERRUPT";
|
||||
e.spellID = 0;
|
||||
e.rec = nullptr;
|
||||
e.schoolMask = 1 << s;
|
||||
e.startMs = g_schoolLock[s].startMs;
|
||||
e.endMs = g_schoolLock[s].endMs;
|
||||
}
|
||||
}
|
||||
|
||||
// CC debuffs on the player.
|
||||
const uint8_t *player = Unit::Identity::PlayerObject();
|
||||
if (player != nullptr) {
|
||||
const uint64_t playerGuid = Unit::Identity::PlayerGuid();
|
||||
for (int i = 1; n < maxOut; ++i) {
|
||||
const int slot = Aura::Data::FindNthSlot(
|
||||
player, i, Aura::Data::Filter::Harmful, false);
|
||||
if (slot < 0)
|
||||
break;
|
||||
const uint32_t spellID = Aura::Data::ReadSpellID(player, slot);
|
||||
if (spellID == 0)
|
||||
continue;
|
||||
const uint8_t *rec =
|
||||
Spell::Lookup::RecordForID(static_cast<int>(spellID));
|
||||
if (rec == nullptr)
|
||||
continue;
|
||||
const char *locType = ClassifyControlLoss(rec);
|
||||
if (locType == nullptr)
|
||||
continue;
|
||||
|
||||
LocEntry &e = out[n++];
|
||||
e.locType = locType;
|
||||
e.spellID = static_cast<int>(spellID);
|
||||
e.rec = rec;
|
||||
e.schoolMask = 0;
|
||||
e.startMs = 0;
|
||||
e.endMs = 0;
|
||||
uint64_t caster = 0;
|
||||
uint32_t expMs = 0, durMs = 0;
|
||||
if (Aura::Source::Get(playerGuid, spellID, &caster, &expMs, &durMs) &&
|
||||
expMs != 0) {
|
||||
e.endMs = static_cast<int>(expMs);
|
||||
if (durMs != 0)
|
||||
e.startMs = static_cast<int>(expMs - durMs);
|
||||
}
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// ---- LOSS_OF_CONTROL_ADDED / _UPDATE events (WorldTick poll-and-diff) ------
|
||||
//
|
||||
// Effect *expiry* (a school lockout timing out, a CC aura falling off) has no
|
||||
// engine packet or callback, so a per-frame diff is the only complete signal.
|
||||
// Firing from the WorldTick tail also keeps the Lua handlers out of the
|
||||
// mid-packet contexts the state is updated in (the OnTooltipSetItem fire-safety
|
||||
// lesson). The scan is bounded (16 debuff slots) and early-outs when idle, so
|
||||
// the per-frame cost is negligible.
|
||||
|
||||
constexpr const char *kEventAdded = "LOSS_OF_CONTROL_ADDED";
|
||||
constexpr const char *kEventUpdate = "LOSS_OF_CONTROL_UPDATE";
|
||||
|
||||
// Identity of an active effect for frame-to-frame diffing: a CC is keyed by
|
||||
// spellID, a school interrupt by its school mask (spellID 0).
|
||||
struct EffectKey {
|
||||
int spellID;
|
||||
int schoolMask;
|
||||
};
|
||||
EffectKey g_prev[32];
|
||||
int g_prevCount = 0;
|
||||
|
||||
bool ContainsKey(const EffectKey *list, int count, EffectKey key) {
|
||||
for (int i = 0; i < count; ++i)
|
||||
if (list[i].spellID == key.spellID &&
|
||||
list[i].schoolMask == key.schoolMask)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void OnWorldTick() {
|
||||
LocEntry entries[32];
|
||||
const int n = BuildList(entries, 32);
|
||||
|
||||
EffectKey cur[32];
|
||||
for (int i = 0; i < n; ++i)
|
||||
cur[i] = EffectKey{entries[i].spellID, entries[i].schoolMask};
|
||||
|
||||
bool changed = false;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (!ContainsKey(g_prev, g_prevCount, cur[i])) {
|
||||
// A newly-applied effect -> LOSS_OF_CONTROL_ADDED(eventIndex).
|
||||
Event::Custom::Fire(Event::Custom::Lookup(kEventAdded), "%d", i + 1);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < g_prevCount && !changed; ++i) {
|
||||
if (!ContainsKey(cur, n, g_prev[i]))
|
||||
changed = true; // an effect ended (fell off / lockout expired)
|
||||
}
|
||||
// Any add or removal fires one coalesced "re-scan" signal. The payload is
|
||||
// the affected unit — always "player" here (vanilla only exposes the local
|
||||
// player's control-loss state), but passing it keeps the event shape
|
||||
// forward-compatible with per-unit tracking and matches modern WoW, whose
|
||||
// LOSS_OF_CONTROL_UPDATE carries the unit token.
|
||||
if (changed)
|
||||
Event::Custom::Fire(Event::Custom::Lookup(kEventUpdate), "%s", "player");
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
g_prev[i] = cur[i];
|
||||
g_prevCount = n;
|
||||
}
|
||||
|
||||
static const Event::Custom::AutoReserve _reserveAdded{kEventAdded};
|
||||
static const Event::Custom::AutoReserve _reserveUpdate{kEventUpdate};
|
||||
static const Tick::WorldTick::AutoSubscribe _tick{&OnWorldTick};
|
||||
|
||||
// `C_LossOfControl.GetActiveLossOfControlDataCount()` -> number.
|
||||
int __fastcall Script_GetActiveLossOfControlDataCount(void *L) {
|
||||
LocEntry entries[32];
|
||||
const int n = BuildList(entries, 32);
|
||||
Game::Lua::PushNumber(L, static_cast<double>(n));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// `C_LossOfControl.GetActiveLossOfControlData(index)` -> LossOfControlData, or
|
||||
// nil if index is out of range.
|
||||
int __fastcall Script_GetActiveLossOfControlData(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1)) {
|
||||
Game::Lua::Error(
|
||||
L, "Usage: C_LossOfControl.GetActiveLossOfControlData(index)");
|
||||
return 0;
|
||||
}
|
||||
const int index = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
LocEntry entries[32];
|
||||
const int n = BuildList(entries, 32);
|
||||
if (index < 1 || index > n)
|
||||
return 0; // nil
|
||||
|
||||
const LocEntry &e = entries[index - 1];
|
||||
const int now = NowMs();
|
||||
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetFieldString(L, "locType", e.locType);
|
||||
Game::Lua::SetFieldNumber(L, "spellID", static_cast<double>(e.spellID));
|
||||
Game::Lua::SetFieldString(
|
||||
L, "displayText", (e.rec != nullptr) ? SpellName(e.rec) : "Interrupted");
|
||||
Game::Lua::SetFieldString(
|
||||
L, "iconTexture", (e.rec != nullptr) ? SpellIconPath(e.rec) : "");
|
||||
|
||||
// Timing (seconds, GetTime() epoch). Nullable — leave a field unset (nil)
|
||||
// when we don't know it, per the modern contract.
|
||||
if (e.endMs != 0 && now < e.endMs) {
|
||||
Game::Lua::SetFieldNumber(L, "timeRemaining", (e.endMs - now) * 0.001);
|
||||
if (e.startMs != 0) {
|
||||
Game::Lua::SetFieldNumber(L, "startTime", e.startMs * 0.001);
|
||||
Game::Lua::SetFieldNumber(L, "duration",
|
||||
(e.endMs - e.startMs) * 0.001);
|
||||
}
|
||||
}
|
||||
|
||||
Game::Lua::SetFieldNumber(L, "lockoutSchool",
|
||||
static_cast<double>(e.schoolMask));
|
||||
Game::Lua::SetFieldNumber(L, "priority", 0);
|
||||
Game::Lua::SetFieldNumber(L, "displayType", 2); // show for full duration
|
||||
// auraInstanceID: nil (vanilla has no aura instance IDs) — field omitted.
|
||||
return 1;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
static void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction(
|
||||
"C_LossOfControl", "GetActiveLossOfControlDataCount",
|
||||
&Script_GetActiveLossOfControlDataCount);
|
||||
Game::Lua::RegisterTableFunction("C_LossOfControl",
|
||||
"GetActiveLossOfControlData",
|
||||
&Script_GetActiveLossOfControlData);
|
||||
}
|
||||
|
||||
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace LossOfControl
|
||||
@@ -0,0 +1,500 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// `C_Map.GetMapOverlays([areaID])` — every WorldMapOverlay.dbc entry for
|
||||
// a zone, regardless of exploration, with the tile grid fully resolved.
|
||||
//
|
||||
// The engine's own surface (GetNumMapOverlays / GetMapOverlayInfo) only
|
||||
// exposes DISCOVERED overlays — the exploration gate is a server-fed
|
||||
// list of discovered overlay IDs — which is why map addons (pfUI's
|
||||
// mapreveal, Cartographer …) ship hand-measured overlay tables to draw
|
||||
// unexplored areas. This reads the DBC directly instead: live data for
|
||||
// every zone, on any client, no per-server table drift.
|
||||
//
|
||||
// With no argument, returns overlays for the world map's CURRENT view
|
||||
// (mirroring the resolution the engine's GetMapInfo does: continent /
|
||||
// zone selection → WorldMapArea row). With a numeric `areaID`
|
||||
// (AreaTable id — the stable zone identity), resolves the WorldMapArea
|
||||
// row whose areaID column matches.
|
||||
//
|
||||
// ## Why the tile grid is resolved here (Octo data quirks)
|
||||
//
|
||||
// An overlay's art is `<textureName>1.blp, 2, …` numbered row-major on a
|
||||
// 256px grid, canonically `ceil(w/256) x ceil(h/256)` tiles with only
|
||||
// the last column/row allowed partial. On stock 1.12 data that formula
|
||||
// is always right; on Octo it is not, in three ways (established
|
||||
// empirically by the InkLab map generator, mirrored here):
|
||||
//
|
||||
// 1. FOREIGN TILES: unrelated art continues an overlay's number
|
||||
// sequence in the same folder (Icepoint Rock's folder carries
|
||||
// `kaneqnuun` tiles, Hyjal carries Tel Abim art). Anything derived
|
||||
// from "what files exist" draws duplicate landmass. The overlay
|
||||
// list must come ONLY from the DBC (which this module guarantees),
|
||||
// and tiles past the true grid must be dropped.
|
||||
// 2. SLIVER COLUMNS: the DBC rect can round away a narrow edge column
|
||||
// (kaneqnuun's real art has a third, 8px-wide column; its DBC `w`
|
||||
// yields 2 columns). Trusting ceil(w/256) both loses the sliver
|
||||
// and — worse — shears the row-major layout into diagonal strips.
|
||||
// The art itself reveals the truth: only a row's LAST tile may be
|
||||
// narrower than 256, so the first partial-width tile (searched one
|
||||
// past the DBC's column count) marks the real column count, and
|
||||
// the first partial-height tile marks the last row.
|
||||
// 3. UPSCALED RE-EXPORTS: the same rect re-exported at higher
|
||||
// resolution (Stonetalon's WindshearCrag: 4 tiles for a 1-tile
|
||||
// rect). All tiles are real and must be kept, drawn scaled to the
|
||||
// rect. Only distinguishable from quirk 1 when the art has NO
|
||||
// partial edge anywhere AND the DBC rect is a whole multiple of
|
||||
// 256 in both dimensions; the grid shape is then recovered from
|
||||
// the aspect ratio (cols ≈ round(sqrt(n·w/h))).
|
||||
//
|
||||
// Tile dimensions come from the BLP headers via the engine's own VFS
|
||||
// reader (`FUN_FILE_READ`, so patch-MPQ overrides are honored). Both
|
||||
// BLP1 and BLP2 keep width/height at header offsets +0x0C/+0x10.
|
||||
// Resolution runs once per overlay per session (cached).
|
||||
//
|
||||
// ## HD map patches (uniform tile upscale)
|
||||
//
|
||||
// A custom `patch-*.mpq` can replace the overlay art with higher-res tiles
|
||||
// (every 256px tile re-exported at 256*scale). Because we read the *file*
|
||||
// dimensions, that upscale must not be assumed to be 256: the resolver
|
||||
// detects the full-cell size `S` (the largest tile dimension = 256*scale)
|
||||
// and expresses both the partial-tile threshold and the texcoords relative
|
||||
// to it. Draw sizes/positions remain in logical map pixels (the patch changes
|
||||
// texture resolution, not the map canvas), so an interior tile reads texcoord
|
||||
// 1.0 at any scale and stock data (S == 256) is byte-identical to before.
|
||||
// The upscale factor need not be integral; only a uniform per-overlay scale
|
||||
// is assumed.
|
||||
//
|
||||
// ## Return shape
|
||||
//
|
||||
// Array of overlay tables:
|
||||
// textureName — bare DBC name ("GOLDSHIRE")
|
||||
// texturePath — "Interface\WorldMap\<dir>\GOLDSHIRE" (engine format)
|
||||
// textureWidth / textureHeight — the DBC placement rect (reliable for
|
||||
// placement; its IMPLIED tile count is what lies)
|
||||
// offsetX / offsetY — placement on the zone canvas
|
||||
// mapPointX / mapPointY
|
||||
// tileCols / tileRows / upscaled — the resolved grid
|
||||
// tiles — array of ready-to-draw tiles:
|
||||
// { file — texture path incl. number (SetTexture-ready)
|
||||
// width, height — draw size in map pixels
|
||||
// texCoordX, texCoordY — right/bottom texcoords
|
||||
// offsetX, offsetY } — absolute canvas position
|
||||
//
|
||||
// A consumer draws an overlay with a dumb loop: per tile SetTexture,
|
||||
// SetWidth/Height, SetTexCoord(0, texCoordX, 0, texCoordY), SetPoint.
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
|
||||
namespace Map::Overlays {
|
||||
|
||||
namespace {
|
||||
|
||||
using FileRead_t = int(__stdcall *)(int unused, const char *path, void **outBuf,
|
||||
unsigned int *outSize, unsigned int extraBytes,
|
||||
int flag1, int flag2);
|
||||
using SMemFree_t = void(__stdcall *)(void *ptr, const char *file, int line,
|
||||
int flags);
|
||||
|
||||
constexpr int kMaxTiles = 64;
|
||||
|
||||
// Smallest power of two >= v (min 16), matching the engine's own
|
||||
// WorldMapFrame tile-file-size loop. A tile's content fills content/NextPot
|
||||
// of its (power-of-two) file — a fraction that's identical whether the file
|
||||
// is stock or HD-upscaled, so texcoords derived from it are scale-invariant.
|
||||
int NextPot(int v) {
|
||||
int p = 16;
|
||||
while (p < v)
|
||||
p <<= 1;
|
||||
return p;
|
||||
}
|
||||
|
||||
// Resolved tile grid for one overlay, cached for the session (DBC and
|
||||
// MPQ contents are immutable per process).
|
||||
struct ResolvedOverlay {
|
||||
uint8_t cols;
|
||||
uint8_t rows;
|
||||
uint8_t count; // tiles to draw (foreign tail already dropped)
|
||||
bool upscaled;
|
||||
uint16_t cell; // full-cell file size (256 on stock, 256*scale on an HD patch)
|
||||
uint16_t fileW[kMaxTiles]; // BLP file dimensions per tile
|
||||
uint16_t fileH[kMaxTiles];
|
||||
};
|
||||
|
||||
ResolvedOverlay **g_cache = nullptr;
|
||||
int g_cacheSize = 0;
|
||||
|
||||
// Reads one BLP's header dimensions through the engine VFS. Returns
|
||||
// false when the file doesn't exist (end of the tile sequence) or isn't
|
||||
// a BLP.
|
||||
bool ReadBlpDims(const char *path, uint16_t *outW, uint16_t *outH) {
|
||||
auto FileRead = reinterpret_cast<FileRead_t>(Offsets::FUN_FILE_READ);
|
||||
auto SMemFree = reinterpret_cast<SMemFree_t>(Offsets::FUN_STORM_SMEM_FREE);
|
||||
void *buf = nullptr;
|
||||
unsigned int size = 0;
|
||||
if (FileRead(0, path, &buf, &size, 0, 1, 0) == 0 || buf == nullptr)
|
||||
return false;
|
||||
bool ok = false;
|
||||
const uint8_t *b = static_cast<const uint8_t *>(buf);
|
||||
if (size >= 0x14 && b[0] == 'B' && b[1] == 'L' && b[2] == 'P') {
|
||||
const uint32_t w = *reinterpret_cast<const uint32_t *>(b + 0x0C);
|
||||
const uint32_t h = *reinterpret_cast<const uint32_t *>(b + 0x10);
|
||||
if (w > 0 && w <= 4096 && h > 0 && h <= 4096) {
|
||||
*outW = static_cast<uint16_t>(w);
|
||||
*outH = static_cast<uint16_t>(h);
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
SMemFree(buf, __FILE__, __LINE__, 0);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// The quirk disambiguation (see module comment). `basePath` is the
|
||||
// numberless texture path; dbcW/dbcH the overlay's DBC rect.
|
||||
void ResolveTiles(ResolvedOverlay *out, const char *basePath, int dbcW,
|
||||
int dbcH) {
|
||||
char path[0x120];
|
||||
int n = 0;
|
||||
while (n < kMaxTiles) {
|
||||
std::snprintf(path, sizeof(path), "%s%d.blp", basePath, n + 1);
|
||||
if (!ReadBlpDims(path, &out->fileW[n], &out->fileH[n]))
|
||||
break;
|
||||
++n;
|
||||
}
|
||||
|
||||
int dbcCols = (dbcW + 255) / 256;
|
||||
int dbcRows = (dbcH + 255) / 256;
|
||||
if (dbcCols < 1)
|
||||
dbcCols = 1;
|
||||
if (dbcRows < 1)
|
||||
dbcRows = 1;
|
||||
|
||||
// Full-cell file size. On stock data a full (interior) tile is 256px; an
|
||||
// HD map patch (patch-*.mpq) upscales every tile uniformly, so a full cell
|
||||
// is 256*scale. Full tiles are the largest; edges/slivers are smaller — so
|
||||
// the max tile dimension is the full-cell size. Partial-tile detection
|
||||
// (and the texcoords in PushTiles) must compare against this S, not a
|
||||
// hardcoded 256, or an HD edge tile (e.g. a 200px edge upscaled to 400px)
|
||||
// reads as "full" and shears the row-major grid into diagonal strips.
|
||||
int S = 256;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (out->fileW[i] > S)
|
||||
S = out->fileW[i];
|
||||
if (out->fileH[i] > S)
|
||||
S = out->fileH[i];
|
||||
}
|
||||
out->cell = static_cast<uint16_t>(S);
|
||||
|
||||
// Real column count: the first partial-width tile is a row's right
|
||||
// edge. Search one past dbcCols so a sliver column the DBC width
|
||||
// rounds off is still found.
|
||||
int cols = dbcCols;
|
||||
bool widthEdge = false;
|
||||
for (int i = 0; i < n && i <= dbcCols; ++i) {
|
||||
if (out->fileW[i] < S) {
|
||||
cols = i + 1;
|
||||
widthEdge = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Real row count: the row holding the first partial-height tile is
|
||||
// the last row.
|
||||
int rows = dbcRows;
|
||||
bool heightEdge = false;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (out->fileH[i] < S) {
|
||||
rows = i / cols + 1;
|
||||
heightEdge = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int limit = cols * rows;
|
||||
bool upscaled = false;
|
||||
// Upscale exception: no partial edge anywhere and a whole-tile DBC
|
||||
// rect means the extras are higher-res art for the same rect, not
|
||||
// foreign — keep them all; recover the grid from the aspect ratio.
|
||||
if (!widthEdge && !heightEdge && dbcW % 256 == 0 && dbcH % 256 == 0 &&
|
||||
n > limit) {
|
||||
upscaled = true;
|
||||
cols = static_cast<int>(std::floor(
|
||||
std::sqrt(static_cast<double>(n) * dbcW / dbcH) + 0.5));
|
||||
if (cols < 1)
|
||||
cols = 1;
|
||||
if (cols > n)
|
||||
cols = n;
|
||||
limit = n;
|
||||
rows = (n + cols - 1) / cols;
|
||||
}
|
||||
if (limit > n)
|
||||
limit = n;
|
||||
if (cols < 1)
|
||||
cols = 1;
|
||||
if (rows < 1)
|
||||
rows = 1;
|
||||
|
||||
out->cols = static_cast<uint8_t>(cols);
|
||||
out->rows = static_cast<uint8_t>(rows);
|
||||
out->count = static_cast<uint8_t>(limit);
|
||||
out->upscaled = upscaled;
|
||||
}
|
||||
|
||||
const ResolvedOverlay *CachedResolve(int overlayId, const char *basePath,
|
||||
int dbcW, int dbcH) {
|
||||
const int count =
|
||||
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_OVERLAY_COUNT);
|
||||
if (g_cache == nullptr || g_cacheSize < count + 1) {
|
||||
auto **fresh = new ResolvedOverlay *[count + 1]();
|
||||
for (int i = 0; i < g_cacheSize; ++i)
|
||||
fresh[i] = g_cache[i];
|
||||
delete[] g_cache;
|
||||
g_cache = fresh;
|
||||
g_cacheSize = count + 1;
|
||||
}
|
||||
if (overlayId < 0 || overlayId >= g_cacheSize)
|
||||
return nullptr;
|
||||
if (g_cache[overlayId] == nullptr) {
|
||||
auto *r = new ResolvedOverlay();
|
||||
ResolveTiles(r, basePath, dbcW, dbcH);
|
||||
g_cache[overlayId] = r;
|
||||
}
|
||||
return g_cache[overlayId];
|
||||
}
|
||||
|
||||
// WorldMapArea row id for the world map's current view — the same
|
||||
// resolution the engine's current-map-name getter (FUN_004a6cf0, behind
|
||||
// GetMapInfo) performs: continent/zone selection indexes into the
|
||||
// per-continent data blob; no continent selected falls back to the
|
||||
// default row global.
|
||||
int CurrentWorldMapAreaRow() {
|
||||
const int continent =
|
||||
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_CONTINENT_INDEX);
|
||||
if (continent < 0)
|
||||
return *reinterpret_cast<const int *>(
|
||||
Offsets::VAR_WORLDMAP_DEFAULT_AREA_ROW);
|
||||
const uint8_t *blob = *reinterpret_cast<const uint8_t *const *>(
|
||||
Offsets::VAR_WORLDMAP_CONTINENT_DATA);
|
||||
if (blob == nullptr)
|
||||
return -1;
|
||||
const uint8_t *entry = blob + continent * Offsets::WORLDMAP_CONTINENT_STRIDE;
|
||||
const int zone =
|
||||
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_ZONE_INDEX);
|
||||
if (zone < 0)
|
||||
return *reinterpret_cast<const int *>(entry + 0x04);
|
||||
const int *zoneRows = *reinterpret_cast<const int *const *>(entry + 0x10);
|
||||
return (zoneRows != nullptr) ? zoneRows[zone] : -1;
|
||||
}
|
||||
|
||||
// WorldMapArea row id for an AreaTable areaID. Linear walk — the table
|
||||
// has ~175 rows; called once per Lua call.
|
||||
int WorldMapAreaRowForAreaID(uint32_t areaID) {
|
||||
const int count =
|
||||
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_AREA_COUNT);
|
||||
for (int id = 1; id <= count; ++id) {
|
||||
const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS,
|
||||
Offsets::VAR_WORLDMAP_AREA_COUNT,
|
||||
static_cast<uint32_t>(id));
|
||||
if (rec != nullptr &&
|
||||
*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_WMA_AREA_ID) ==
|
||||
areaID)
|
||||
return id;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Pushes the `tiles` array for one overlay (leaves it on the stack top).
|
||||
void PushTiles(void *L, const ResolvedOverlay *r, const char *basePath,
|
||||
int dbcW, int dbcH, int offX, int offY) {
|
||||
Game::Lua::NewTable(L);
|
||||
if (r == nullptr || r->count == 0)
|
||||
return;
|
||||
|
||||
const int cols = r->cols;
|
||||
char file[0x120];
|
||||
for (int i = 0; i < r->count; ++i) {
|
||||
const int col = i % cols;
|
||||
const int row = i / cols;
|
||||
std::snprintf(file, sizeof(file), "%s%d", basePath, i + 1);
|
||||
|
||||
double drawW, drawH, tcX, tcY, posX, posY;
|
||||
if (r->upscaled) {
|
||||
// Higher-res re-export of the same rect: tiles split the DBC
|
||||
// rect evenly, full texcoords.
|
||||
drawW = static_cast<double>(dbcW) / r->cols;
|
||||
drawH = static_cast<double>(dbcH) / r->rows;
|
||||
tcX = 1.0;
|
||||
tcY = 1.0;
|
||||
posX = offX + col * drawW;
|
||||
posY = offY + row * drawH;
|
||||
} else {
|
||||
// Canonical 256px logical grid. Draw sizes/positions stay in
|
||||
// logical map pixels; the texcoord is the content fraction of the
|
||||
// (possibly HD-upscaled) file. `scale` = file px per logical px
|
||||
// (1 on stock, 2/4 on an HD patch), so a full interior tile reads
|
||||
// texCoord 1.0 regardless of file size, and an edge's content
|
||||
// (remainder * scale) is measured against its actual file width.
|
||||
const int fileW = r->fileW[i];
|
||||
const int fileH = r->fileH[i];
|
||||
const double scale = (r->cell > 0) ? (r->cell / 256.0) : 1.0;
|
||||
|
||||
double logicalW = 256.0, logicalH = 256.0;
|
||||
tcX = 1.0;
|
||||
tcY = 1.0;
|
||||
if (col == r->cols - 1) {
|
||||
const int rem = dbcW - 256 * (r->cols - 1);
|
||||
if (rem <= 0) {
|
||||
// Sliver the DBC width rounded away: whole file is content
|
||||
// (its logical width is the file width de-scaled).
|
||||
logicalW = fileW / scale;
|
||||
} else {
|
||||
// Content fills rem/NextPot(rem) of the POT tile file.
|
||||
// Scale-invariant, so an HD-upscaled file (POT*scale)
|
||||
// reads the same fraction — using the raw file width here
|
||||
// would halve the texcoord on any tile the patch doubled.
|
||||
logicalW = rem;
|
||||
tcX = rem / static_cast<double>(NextPot(rem));
|
||||
}
|
||||
}
|
||||
if (row == r->rows - 1) {
|
||||
const int rem = dbcH - 256 * (r->rows - 1);
|
||||
if (rem <= 0) {
|
||||
logicalH = fileH / scale;
|
||||
} else {
|
||||
logicalH = rem;
|
||||
tcY = rem / static_cast<double>(NextPot(rem));
|
||||
}
|
||||
}
|
||||
drawW = logicalW;
|
||||
drawH = logicalH;
|
||||
posX = offX + col * 256;
|
||||
posY = offY + row * 256;
|
||||
}
|
||||
|
||||
Game::Lua::PushNumber(L, static_cast<double>(i + 1));
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetFieldString(L, "file", file);
|
||||
Game::Lua::SetFieldNumber(L, "width", drawW);
|
||||
Game::Lua::SetFieldNumber(L, "height", drawH);
|
||||
Game::Lua::SetFieldNumber(L, "texCoordX", tcX);
|
||||
Game::Lua::SetFieldNumber(L, "texCoordY", tcY);
|
||||
Game::Lua::SetFieldNumber(L, "offsetX", posX);
|
||||
Game::Lua::SetFieldNumber(L, "offsetY", posY);
|
||||
Game::Lua::SetTable(L, -3);
|
||||
}
|
||||
}
|
||||
|
||||
// `C_Map.GetMapOverlays([areaID])` — see the module comment.
|
||||
int __fastcall Script_GetMapOverlays(void *L) {
|
||||
int wmaRow = -1;
|
||||
if (Game::Lua::IsNumber(L, 1)) {
|
||||
wmaRow = WorldMapAreaRowForAreaID(
|
||||
static_cast<uint32_t>(Game::Lua::ToNumber(L, 1)));
|
||||
} else {
|
||||
wmaRow = CurrentWorldMapAreaRow();
|
||||
}
|
||||
|
||||
Game::Lua::SetTop(L, 0);
|
||||
Game::Lua::NewTable(L);
|
||||
if (wmaRow <= 0)
|
||||
return 1;
|
||||
|
||||
const uint8_t *wmaRec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS,
|
||||
Offsets::VAR_WORLDMAP_AREA_COUNT,
|
||||
static_cast<uint32_t>(wmaRow));
|
||||
const char *mapDir =
|
||||
(wmaRec != nullptr)
|
||||
? *reinterpret_cast<const char *const *>(wmaRec +
|
||||
Offsets::OFF_WMA_NAME)
|
||||
: nullptr;
|
||||
|
||||
const int count =
|
||||
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_OVERLAY_COUNT);
|
||||
int outIdx = 0;
|
||||
for (int id = 1; id <= count; ++id) {
|
||||
const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_OVERLAY_RECORDS,
|
||||
Offsets::VAR_WORLDMAP_OVERLAY_COUNT,
|
||||
static_cast<uint32_t>(id));
|
||||
if (rec == nullptr ||
|
||||
*reinterpret_cast<const int *>(rec + Offsets::OFF_WMO_WORLDMAP_AREA) !=
|
||||
wmaRow)
|
||||
continue;
|
||||
const char *texName = *reinterpret_cast<const char *const *>(
|
||||
rec + Offsets::OFF_WMO_TEXTURE_NAME);
|
||||
if (texName == nullptr || texName[0] == '\0')
|
||||
continue; // hit-rect-only rows have no drawable texture
|
||||
|
||||
// Full path, mirroring the engine's own GetMapOverlayInfo format
|
||||
// (unresolvable map dir falls back to the "World" folder).
|
||||
char basePath[0x104];
|
||||
if (mapDir != nullptr && mapDir[0] != '\0')
|
||||
std::snprintf(basePath, sizeof(basePath),
|
||||
"Interface\\WorldMap\\%s\\%s", mapDir, texName);
|
||||
else
|
||||
std::snprintf(basePath, sizeof(basePath),
|
||||
"Interface\\WorldMap\\World\\%s", texName);
|
||||
|
||||
const auto fieldInt = [rec](uintptr_t off) {
|
||||
return *reinterpret_cast<const int32_t *>(rec + off);
|
||||
};
|
||||
const int dbcW = fieldInt(Offsets::OFF_WMO_TEXTURE_WIDTH);
|
||||
const int dbcH = fieldInt(Offsets::OFF_WMO_TEXTURE_HEIGHT);
|
||||
const int offX = fieldInt(Offsets::OFF_WMO_OFFSET_X);
|
||||
const int offY = fieldInt(Offsets::OFF_WMO_OFFSET_Y);
|
||||
|
||||
const ResolvedOverlay *r = CachedResolve(id, basePath, dbcW, dbcH);
|
||||
|
||||
outIdx += 1;
|
||||
Game::Lua::PushNumber(L, static_cast<double>(outIdx));
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetFieldString(L, "textureName", texName);
|
||||
Game::Lua::SetFieldString(L, "texturePath", basePath);
|
||||
Game::Lua::SetFieldNumber(L, "textureWidth", dbcW);
|
||||
Game::Lua::SetFieldNumber(L, "textureHeight", dbcH);
|
||||
Game::Lua::SetFieldNumber(L, "offsetX", offX);
|
||||
Game::Lua::SetFieldNumber(L, "offsetY", offY);
|
||||
Game::Lua::SetFieldNumber(
|
||||
L, "mapPointX", fieldInt(Offsets::OFF_WMO_MAP_POINT_X));
|
||||
Game::Lua::SetFieldNumber(
|
||||
L, "mapPointY", fieldInt(Offsets::OFF_WMO_MAP_POINT_Y));
|
||||
if (r != nullptr) {
|
||||
Game::Lua::SetFieldNumber(L, "tileCols", r->cols);
|
||||
Game::Lua::SetFieldNumber(L, "tileRows", r->rows);
|
||||
Game::Lua::SetFieldBool(L, "upscaled", r->upscaled);
|
||||
}
|
||||
Game::Lua::PushString(L, "tiles");
|
||||
PushTiles(L, r, basePath, dbcW, dbcH, offX, offY);
|
||||
Game::Lua::SetTable(L, -3);
|
||||
|
||||
Game::Lua::SetTable(L, -3);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_Map", "GetMapOverlays",
|
||||
&Script_GetMapOverlays);
|
||||
}
|
||||
|
||||
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Map::Overlays
|
||||
@@ -0,0 +1,218 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// `PLAYER_EQUIPMENT_CHANGED(equipmentSlot, hasCurrent)` — the WotLK-era
|
||||
// per-slot paperdoll event. Vanilla only fires UNIT_INVENTORY_CHANGED for
|
||||
// the player, which doesn't say WHICH slot changed; gear trackers and stat
|
||||
// sheets built against 3.3+ gate their refresh on this event.
|
||||
//
|
||||
// Fully event-driven via the engine's own descriptor-field observer system
|
||||
// (see the FUN_DESC_OBSERVER_REGISTER block in Offsets.h). The engine's
|
||||
// inventory setup (FUN_INV_OBSERVER_SETUP, once per enter-world) registers
|
||||
// change observers for the bag/backpack/bank/keyring GUID fields of the
|
||||
// player descriptor — but never for the 19 equipment slots (0x4A8..0x538).
|
||||
// We co-hook that setup and register our own observer per equipment field,
|
||||
// mirroring the engine's registration shape exactly (bank 4, size 8). The
|
||||
// dispatcher invokes us only when a slot's item GUID actually changed
|
||||
// (per-node mirror memcmp), so there's no polling and no diff bookkeeping
|
||||
// on our side, and the nodes share the engine observers' lifetime (they
|
||||
// die with the player object; the setup re-runs each enter-world).
|
||||
//
|
||||
// `equipmentSlot` is the 1-based Lua inventory slot (1 = head … 19 =
|
||||
// tabard), matching modern. `hasCurrent` is 1 when the slot now holds an
|
||||
// item and nil when it's empty (the engine dispatcher has no `%b`; 1/nil
|
||||
// keeps the idiomatic `if hasCurrent then` working — see FireIdSuccess).
|
||||
//
|
||||
// Also `UPDATE_INVENTORY_DURABILITY` (no payload) — fires when any
|
||||
// equipped item's durability changes (combat damage, death, repairs) —
|
||||
// via a co-hook on the engine's inventory-alerts recompute
|
||||
// (FUN_INVENTORY_ALERTS_RECOMPUTE): the engine itself calls that whenever
|
||||
// an owned item's fields change (its item post-update handler FUN_005D9A90
|
||||
// routes every item values-update through it) and on equip/enter-world
|
||||
// paths, so it IS the engine's own "durability may have changed" signal.
|
||||
// Post-original we diff a per-slot {itemGuid, durability} snapshot and
|
||||
// fire only on a real change. NOT done with bank-1 (ITEM field) descriptor
|
||||
// observers: those register without error but are never invoked — the
|
||||
// registrar's internal wrapper lookup (FUN_00464890, the observer
|
||||
// registry, distinct from the object manager) silently no-ops for item
|
||||
// objects, verified empirically (item values-updates arrive and the
|
||||
// player-bank observers fire, item-bank ones never do).
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "equipmentset/Locations.h"
|
||||
#include "event/Custom.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Player::Equipment {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr const char *kEvtEquipmentChanged = "PLAYER_EQUIPMENT_CHANGED";
|
||||
const Event::Custom::AutoReserve _r{kEvtEquipmentChanged};
|
||||
constexpr const char *kEvtDurability = "UPDATE_INVENTORY_DURABILITY";
|
||||
const Event::Custom::AutoReserve _r2{kEvtDurability};
|
||||
|
||||
// Whether the slot currently holds an item — read from the player's
|
||||
// inventory-manager GUID array, the same source the engine's own bag
|
||||
// observer (FUN_004F8DB0) treats as the post-change truth when its field
|
||||
// observer fires. The player is resolved from the GUID the observer
|
||||
// callback receives, via the NON-THROWING object resolver — the same call
|
||||
// FUN_004F8DB0 makes. NOT via FUN_RESOLVE_UNIT_TOKEN("player"): that's the
|
||||
// assert-frame helper that raises a Lua error when the token doesn't
|
||||
// resolve, and this runs inside SMSG_UPDATE_OBJECT processing, where the
|
||||
// player object can be mid-create and momentarily unresolvable — a Lua
|
||||
// error thrown from there unwinds through raw engine code.
|
||||
bool SlotHasItem(uint32_t guidLo, uint32_t guidHi, int slot0Based) {
|
||||
using ResolveByGUID_t = void *(__fastcall *)(uint32_t typeMask,
|
||||
const char *debugName,
|
||||
uint32_t guidLo, uint32_t guidHi,
|
||||
int line);
|
||||
auto resolve =
|
||||
reinterpret_cast<ResolveByGUID_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
auto *player = static_cast<const uint8_t *>(resolve(
|
||||
Offsets::OBJ_TYPE_PLAYER, "ClassicAPI", guidLo, guidHi, 0x172));
|
||||
if (player == nullptr)
|
||||
return false;
|
||||
const uint8_t *invMgr = player + Offsets::OFF_PLAYER_INVENTORY_MANAGER;
|
||||
const uint32_t count = *reinterpret_cast<const uint32_t *>(
|
||||
invMgr + Offsets::OFF_INVMGR_SLOT_COUNT);
|
||||
if (static_cast<uint32_t>(slot0Based) >= count)
|
||||
return false;
|
||||
const uint64_t *guids = *reinterpret_cast<const uint64_t *const *>(
|
||||
invMgr + Offsets::OFF_INVMGR_GUID_ARRAY);
|
||||
return guids != nullptr && guids[slot0Based] != 0;
|
||||
}
|
||||
|
||||
// --- PLAYER_EQUIPMENT_CHANGED (player-descriptor observers) -------------
|
||||
|
||||
// Descriptor-field observer callback — ABI per the Offsets.h note:
|
||||
// __fastcall(fieldOffset /*ecx*/, size /*edx*/, guidLo, guidHi, oldValue*,
|
||||
// userArg), return 1, callee cleans 0x10. Invoked by the dispatcher only
|
||||
// when the watched equipment GUID field actually changed.
|
||||
int __fastcall EquipSlotChanged_cb(uint32_t fieldOffset, uint32_t /*size*/,
|
||||
uint32_t guidLo, uint32_t guidHi,
|
||||
const uint32_t * /*oldValue*/,
|
||||
void * /*userArg*/) {
|
||||
const int slot0 =
|
||||
static_cast<int>(fieldOffset - Offsets::OFF_DESC_PLAYER_EQUIP_FIRST) >> 3;
|
||||
if (slot0 >= 0 && slot0 < Offsets::DESC_PLAYER_EQUIP_SLOTS) {
|
||||
Event::Custom::FireIdSuccess(Event::Custom::Lookup(kEvtEquipmentChanged),
|
||||
slot0 + 1,
|
||||
SlotHasItem(guidLo, guidHi, slot0));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Co-hook on the engine's inventory observer setup: after it registers the
|
||||
// bag-range observers, register ours for the equipment range it skips.
|
||||
// Same registrar, same shape — only the field offsets differ.
|
||||
using RegisterObserver_t = void(__fastcall *)(
|
||||
int bank, uint32_t fieldOffset, uint32_t guidLo, uint32_t guidHi, int size,
|
||||
const void *callback, void *userArg1, void *userArg2);
|
||||
using ObserverSetup_t = void(__fastcall *)();
|
||||
ObserverSetup_t g_origSetup = nullptr;
|
||||
|
||||
// One-time (per process) seed latch for the durability diff below — the
|
||||
// very first recompute seeds the snapshot silently instead of firing for
|
||||
// the initial gear population. Deliberately NOT reset per enter-world:
|
||||
// death/release/graveyard teleports re-run the setup, and a per-setup
|
||||
// reset made the post-teleport recompute re-seed silently — swallowing
|
||||
// the death's own durability loss (verified in-game: repairs fired,
|
||||
// deaths didn't). Keeping the snapshot across loading screens means
|
||||
// changes that land around them diff normally; the cost is at most one
|
||||
// spurious fire on relog to a different character, which matches
|
||||
// modern's login-time fire anyway.
|
||||
bool g_durSnapValid = false;
|
||||
|
||||
void __fastcall ObserverSetup_h() {
|
||||
g_origSetup();
|
||||
|
||||
const uint64_t guid = Unit::Identity::PlayerGuid();
|
||||
if (guid == 0)
|
||||
return;
|
||||
auto reg = reinterpret_cast<RegisterObserver_t>(
|
||||
Offsets::FUN_DESC_OBSERVER_REGISTER);
|
||||
for (int slot = 0; slot < Offsets::DESC_PLAYER_EQUIP_SLOTS; ++slot) {
|
||||
reg(Offsets::DESC_OBSERVER_BANK_PLAYER,
|
||||
Offsets::OFF_DESC_PLAYER_EQUIP_FIRST + slot * 8,
|
||||
static_cast<uint32_t>(guid), static_cast<uint32_t>(guid >> 32),
|
||||
/*size*/ 8, reinterpret_cast<const void *>(&EquipSlotChanged_cb),
|
||||
nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
static const Game::HookAutoRegister _setupHook{
|
||||
Offsets::FUN_INV_OBSERVER_SETUP,
|
||||
reinterpret_cast<void *>(&ObserverSetup_h),
|
||||
reinterpret_cast<void **>(&g_origSetup)};
|
||||
|
||||
// --- UPDATE_INVENTORY_DURABILITY (alerts-recompute co-hook) --------------
|
||||
|
||||
struct SlotDurability {
|
||||
uint64_t guid; // equipped item, 0 = empty slot
|
||||
uint32_t durability; // ITEM_FIELD_DURABILITY, 0 when empty/unresolved
|
||||
};
|
||||
SlotDurability g_durSnap[EquipmentSet::SLOT_COUNT];
|
||||
|
||||
uint32_t ItemDurability(uint64_t guid) {
|
||||
if (guid == 0)
|
||||
return 0;
|
||||
const uint8_t *item = EquipmentSet::Locations::ResolveItemByGUID(guid);
|
||||
if (item == nullptr)
|
||||
return 0;
|
||||
const uint8_t *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
if (descriptor == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint32_t *>(
|
||||
descriptor + Offsets::OFF_DESCRIPTOR_DURABILITY);
|
||||
}
|
||||
|
||||
using AlertsRecompute_t = void(__fastcall *)();
|
||||
AlertsRecompute_t g_origAlertsRecompute = nullptr;
|
||||
|
||||
void __fastcall AlertsRecompute_h() {
|
||||
g_origAlertsRecompute();
|
||||
|
||||
uint64_t paperdoll[EquipmentSet::SLOT_COUNT];
|
||||
EquipmentSet::Locations::SnapshotPaperdoll(paperdoll);
|
||||
|
||||
bool changed = false;
|
||||
for (int i = 0; i < EquipmentSet::SLOT_COUNT; ++i) {
|
||||
const SlotDurability cur{paperdoll[i], ItemDurability(paperdoll[i])};
|
||||
if (g_durSnap[i].guid != cur.guid ||
|
||||
g_durSnap[i].durability != cur.durability) {
|
||||
changed = true;
|
||||
g_durSnap[i] = cur;
|
||||
}
|
||||
}
|
||||
|
||||
if (!g_durSnapValid) {
|
||||
g_durSnapValid = true; // first recompute of the session seeds only
|
||||
return;
|
||||
}
|
||||
if (changed)
|
||||
Event::Custom::Fire(Event::Custom::Lookup(kEvtDurability), "");
|
||||
}
|
||||
|
||||
static const Game::HookAutoRegister _alertsHook{
|
||||
Offsets::FUN_INVENTORY_ALERTS_RECOMPUTE,
|
||||
reinterpret_cast<void *>(&AlertsRecompute_h),
|
||||
reinterpret_cast<void **>(&g_origAlertsRecompute)};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Player::Equipment
|
||||
@@ -134,6 +134,43 @@ void PushRequirements(void *L, const uint8_t *data) {
|
||||
}
|
||||
}
|
||||
|
||||
// `C_QuestLog.GetNumQuestObjectives(questID)` — the quest's objective
|
||||
// count (the length `GetQuestDetails(questID).requirements` would have),
|
||||
// read straight from the cache block with zero Lua table/string
|
||||
// materialization. Exists so per-step validation loops (guide addons
|
||||
// bounds-checking objective indices at load time) stay O(1)-cheap even
|
||||
// with a warm quest cache — materializing full detail tables for hundreds
|
||||
// of quests inside a login-path loop can exhaust vanilla's fixed Lua
|
||||
// memory pool. Returns nil when the quest isn't cached (same contract as
|
||||
// GetQuestDetails).
|
||||
int __fastcall Script_GetNumQuestObjectives(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1)) {
|
||||
Game::Lua::Error(L,
|
||||
"Usage: C_QuestLog.GetNumQuestObjectives(questID)");
|
||||
return 0;
|
||||
}
|
||||
const int questID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
if (questID <= 0)
|
||||
return 0;
|
||||
const uint8_t *data = Quest::Cache::Peek(static_cast<uint32_t>(questID));
|
||||
if (data == nullptr)
|
||||
return 0;
|
||||
|
||||
int count = 0;
|
||||
auto *npcOrGo = reinterpret_cast<const int32_t *>(
|
||||
data + Quest::Cache::OFF_REQUIRED_NPC_OR_GO);
|
||||
auto *items = reinterpret_cast<const uint32_t *>(
|
||||
data + Quest::Cache::OFF_REQUIRED_ITEM);
|
||||
for (int i = 0; i < Quest::Cache::OBJECTIVE_COUNT; ++i) {
|
||||
if (npcOrGo[i] != 0)
|
||||
++count;
|
||||
if (items[i] != 0)
|
||||
++count;
|
||||
}
|
||||
Game::Lua::PushNumber(L, static_cast<double>(count));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int __fastcall Script_GetQuestDetails(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1)) {
|
||||
Game::Lua::Error(L, "Usage: C_QuestLog.GetQuestDetails(questID)");
|
||||
@@ -245,6 +282,8 @@ int __fastcall Script_GetQuestDetails(void *L) {
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_QuestLog", "GetQuestDetails",
|
||||
&Script_GetQuestDetails);
|
||||
Game::Lua::RegisterTableFunction("C_QuestLog", "GetNumQuestObjectives",
|
||||
&Script_GetNumQuestObjectives);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -11,18 +11,29 @@
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// `QUEST_ACCEPTED(questLogIndex, questID)` event — fires once per
|
||||
// new quest entering the local quest log. Polyfills modern WoW's
|
||||
// event of the same name (added in 3.1.0). Matches the Cata/WotLK
|
||||
// signature: `(questLogIndex, questID)`, 1-based log index.
|
||||
// Quest log delta events — polyfills two modern WoW events from one
|
||||
// pre-/post-rebuild diff:
|
||||
//
|
||||
// `QUEST_ACCEPTED(questLogIndex, questID)` — fires once per new quest
|
||||
// entering the local quest log. Matches the Cata/WotLK signature,
|
||||
// 1-based log index (event added in 3.1.0).
|
||||
//
|
||||
// `QUEST_REMOVED(questID)` — fires once per quest leaving the local
|
||||
// quest log, for both turn-ins and abandons (event added in 8.0.1;
|
||||
// Classic-era signature is the bare questID). For turn-ins this fires
|
||||
// *after* `QUEST_TURNED_IN`, matching retail ordering: the 0x191
|
||||
// complete packet doesn't touch the log; the removal arrives in the
|
||||
// follow-up quest-log update packets, whose rebuild we diff here.
|
||||
// Observed turn-in sequence: QUEST_TURNED_IN → UNIT_QUEST_LOG_CHANGED
|
||||
// → QUEST_LOG_UPDATE (fired inside the rebuild) → QUEST_REMOVED.
|
||||
//
|
||||
// Hook target: `FUN_QUEST_LOG_REBUILD` (`0x004DE510`) — the single
|
||||
// chokepoint the engine uses to refresh the Lua-visible quest log
|
||||
// from the player's authoritative slot data at `[CGPlayer + 0xE68 +
|
||||
// 0x28]`. Every state change that adds, removes, or updates a quest
|
||||
// flows through here. By snapshotting the log before and after the
|
||||
// original runs, we can compute the delta and fire QUEST_ACCEPTED
|
||||
// only for genuine additions.
|
||||
// original runs, we can compute the delta and fire only for genuine
|
||||
// additions / removals.
|
||||
//
|
||||
// Login suppression: the same function handles the initial bulk-sync
|
||||
// at character entry, which appears as a single rebuild call adding
|
||||
@@ -30,7 +41,10 @@
|
||||
// added in a single rebuild (which can only happen on login / reload
|
||||
// resync — human input speed can't accept multiple quests in the
|
||||
// same engine tick). A brand-new character's first accept is
|
||||
// `0 → 1` and fires correctly.
|
||||
// `0 → 1` and fires correctly. Removals apply the same rule (a user
|
||||
// action removes at most one quest per rebuild) and are additionally
|
||||
// suppressed when the rebuild also added multiple quests — a
|
||||
// mixed-delta rebuild is a cross-character resync, not gameplay.
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
@@ -39,13 +53,15 @@
|
||||
#include <cstdint>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace Quest::Accepted {
|
||||
namespace Quest::LogEvents {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr const char *kEventName = "QUEST_ACCEPTED";
|
||||
constexpr const char *kAcceptedEventName = "QUEST_ACCEPTED";
|
||||
constexpr const char *kRemovedEventName = "QUEST_REMOVED";
|
||||
|
||||
const Event::Custom::AutoReserve _reserve{kEventName};
|
||||
const Event::Custom::AutoReserve _reserveAccepted{kAcceptedEventName};
|
||||
const Event::Custom::AutoReserve _reserveRemoved{kRemovedEventName};
|
||||
|
||||
// Walk the live quest log and collect questIDs of real (non-header)
|
||||
// entries. Headers are 16-byte rows with a non-NULL pointer at +0x8;
|
||||
@@ -80,7 +96,7 @@ QuestLogRebuild_t QuestLogRebuild_o = nullptr;
|
||||
void __fastcall QuestLogRebuild_h(int param_1) {
|
||||
// `param_1 == 0` is the engine's "no-op rebuild" signal — just
|
||||
// refires QUEST_LOG_UPDATE without touching the entry array.
|
||||
// No diff possible, no accept happening, pass through.
|
||||
// No diff possible, no accept/remove happening, pass through.
|
||||
if (param_1 == 0) {
|
||||
QuestLogRebuild_o(param_1);
|
||||
return;
|
||||
@@ -93,14 +109,17 @@ void __fastcall QuestLogRebuild_h(int param_1) {
|
||||
|
||||
// Walk the post-state in index order so the fired event's
|
||||
// `questLogIndex` matches the 1-based slot the engine just
|
||||
// assigned. Skip questIDs already in `pre`.
|
||||
// assigned. Collect the full post-set on the way for the
|
||||
// removal diff.
|
||||
const int count = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_QUEST_LOG_ENTRY_COUNT));
|
||||
if (count <= 0)
|
||||
return;
|
||||
const auto *entries = reinterpret_cast<const uint8_t *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_QUEST_LOG_ENTRIES));
|
||||
|
||||
std::unordered_set<int> post;
|
||||
if (count > 0)
|
||||
post.reserve(static_cast<size_t>(count));
|
||||
|
||||
int newCount = 0;
|
||||
int firstNewIdx = 0;
|
||||
int firstNewID = 0;
|
||||
@@ -114,6 +133,7 @@ void __fastcall QuestLogRebuild_h(int param_1) {
|
||||
entry + Offsets::OFF_QUEST_LOG_ENTRY_QUEST_ID);
|
||||
if (questID <= 0)
|
||||
continue;
|
||||
post.insert(questID);
|
||||
if (pre.count(questID) != 0)
|
||||
continue;
|
||||
++newCount;
|
||||
@@ -123,14 +143,35 @@ void __fastcall QuestLogRebuild_h(int param_1) {
|
||||
}
|
||||
}
|
||||
|
||||
int removedCount = 0;
|
||||
int firstRemovedID = 0;
|
||||
for (const int questID : pre) {
|
||||
if (post.count(questID) != 0)
|
||||
continue;
|
||||
++removedCount;
|
||||
if (removedCount == 1)
|
||||
firstRemovedID = questID;
|
||||
}
|
||||
|
||||
// Single addition → user-driven accept. Multiple → bulk resync
|
||||
// (login or post-reload). Modern WoW's QUEST_ACCEPTED doesn't
|
||||
// fire on initial sync either; we match that.
|
||||
if (newCount == 1) {
|
||||
const int slot = Event::Custom::Lookup(kEventName);
|
||||
const int slot = Event::Custom::Lookup(kAcceptedEventName);
|
||||
if (slot >= 0)
|
||||
Event::Custom::Fire(slot, "%d%d", firstNewIdx, firstNewID);
|
||||
}
|
||||
|
||||
// Single removal → user-driven turn-in or abandon. The extra
|
||||
// `newCount <= 1` gate rejects the one resync shape the removal
|
||||
// count alone can't: switching to a character whose log shares
|
||||
// all but one of the previous character's quests (1 removal, N
|
||||
// additions in the same rebuild).
|
||||
if (removedCount == 1 && newCount <= 1) {
|
||||
const int slot = Event::Custom::Lookup(kRemovedEventName);
|
||||
if (slot >= 0)
|
||||
Event::Custom::Fire(slot, "%d", firstRemovedID);
|
||||
}
|
||||
}
|
||||
|
||||
static const Game::HookAutoRegister _hookreg{
|
||||
@@ -138,4 +179,4 @@ static const Game::HookAutoRegister _hookreg{
|
||||
reinterpret_cast<void *>(&QuestLogRebuild_h),
|
||||
reinterpret_cast<void **>(&QuestLogRebuild_o)};
|
||||
|
||||
} // namespace Quest::Accepted
|
||||
} // namespace Quest::LogEvents
|
||||
+48
-27
@@ -17,13 +17,12 @@
|
||||
//
|
||||
// Implementation chains the engine's existing primitives:
|
||||
//
|
||||
// 1. Initiate the cast the same way `Script_CastSpellByName` does:
|
||||
// resolve `spellID` (via our `Spell::CastByID` numeric-name hook)
|
||||
// to a spellbook slot through `FUN_RESOLVE_SPELL_NAME_TO_SLOT`,
|
||||
// then dispatch through `FUN_SPELL_CAST_DISPATCH`. For a ground-
|
||||
// target spell, the engine enters placement mode at this point
|
||||
// (sets `VAR_SPELL_PLACEMENT_STATE`); for a normal cast, it
|
||||
// fires immediately.
|
||||
// 1. Initiate the cast: resolve the *exact* `spellID` to its spellbook
|
||||
// slot (`Spell::Lookup::FindSpellbookSlot` — NOT name resolution, which
|
||||
// would cast the highest rank) and dispatch through
|
||||
// `FUN_SPELL_CAST_DISPATCH`. For a ground-target spell, the engine
|
||||
// enters placement mode at this point (sets `VAR_SPELL_PLACEMENT_STATE`);
|
||||
// for a normal cast, it fires immediately.
|
||||
//
|
||||
// 2. `Spell::AtCursor::Resolve()` then refreshes the cursor's world
|
||||
// raycast via `FUN_REFRESH_CURSOR_RAYCAST` and commits the
|
||||
@@ -41,10 +40,10 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "spell/Lookup.h"
|
||||
#include "spell/MacroPrimarySpell.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
namespace Spell::AtCursor {
|
||||
@@ -141,9 +140,16 @@ bool Resolve() {
|
||||
|
||||
namespace {
|
||||
|
||||
using NameToSlot_t = int(__fastcall *)(const char *name, void *out);
|
||||
using CastDispatch_t = void(__fastcall *)(unsigned slot, int bookType,
|
||||
unsigned targetGuidLo, float targetGuidHi);
|
||||
using NameToSlot_t = int(__fastcall *)(const char *name, void *out);
|
||||
|
||||
void DispatchSlot(int slot0Based, int bookType) {
|
||||
auto dispatch = reinterpret_cast<CastDispatch_t>(
|
||||
Offsets::FUN_SPELL_CAST_DISPATCH);
|
||||
// (0, 0) GUID = no implicit target; the engine handles placement.
|
||||
dispatch(static_cast<unsigned>(slot0Based), bookType, 0, 0.0f);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -151,39 +157,54 @@ bool DispatchSpellCast(int spellID) {
|
||||
if (spellID <= 0)
|
||||
return false;
|
||||
|
||||
// Hand the spellID off as a numeric string — our `Spell::CastByID`
|
||||
// hook on `FUN_RESOLVE_SPELL_NAME_TO_SLOT` translates pure-numeric
|
||||
// input into the locale-resolved spell name internally, so the
|
||||
// engine treats it just like `CastSpellByName("Blizzard")`.
|
||||
char numBuf[16];
|
||||
std::snprintf(numBuf, sizeof(numBuf), "%d", spellID);
|
||||
// Resolve the EXACT spellID to its spellbook slot. Every rank is its own
|
||||
// slot, so we must NOT go through name resolution — that walks to the
|
||||
// highest rank and would cast Blizzard(Rank 6) for a Rank 1 (spellID 10)
|
||||
// request. `FindSpellbookSlot` returns a 1-based slot; the dispatcher
|
||||
// wants the 0-based index into `VAR_PLAYER_SPELLBOOK`.
|
||||
int bookType = 0;
|
||||
const int slot1 = Spell::Lookup::FindSpellbookSlot(spellID, &bookType);
|
||||
if (slot1 <= 0)
|
||||
return false; // not in the player's spellbook
|
||||
|
||||
DispatchSlot(slot1 - 1, bookType);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DispatchSpellCastByName(const char *name) {
|
||||
if (name == nullptr || *name == '\0')
|
||||
return false;
|
||||
|
||||
// The engine's resolver strips a trailing `(Rank N)` and returns the
|
||||
// 0-based spellbook slot (highest rank when no rank is given). This is the
|
||||
// by-name path — for an exact rank prefer the numeric spellID overload.
|
||||
auto nameToSlot = reinterpret_cast<NameToSlot_t>(
|
||||
Offsets::FUN_RESOLVE_SPELL_NAME_TO_SLOT);
|
||||
int bookType = 0;
|
||||
const int slot = nameToSlot(numBuf, &bookType);
|
||||
const int slot = nameToSlot(name, &bookType);
|
||||
if (slot < 0)
|
||||
return false; // not in the player's spellbook
|
||||
|
||||
auto dispatch = reinterpret_cast<CastDispatch_t>(
|
||||
Offsets::FUN_SPELL_CAST_DISPATCH);
|
||||
dispatch(static_cast<unsigned>(slot), bookType,
|
||||
0, 0.0f); // no implicit target unit; engine handles placement
|
||||
DispatchSlot(slot, bookType);
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
int __fastcall Script_C_Spell_CastAtCursor(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1)) {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
// Accept a numeric spellID (exact rank) or a spell name (the engine's
|
||||
// resolver parses a trailing "(Rank N)"). IsNumber is checked first so a
|
||||
// numeric string like "10" still takes the exact-spellID path.
|
||||
bool dispatched = false;
|
||||
if (Game::Lua::IsNumber(L, 1)) {
|
||||
dispatched = DispatchSpellCast(static_cast<int>(Game::Lua::ToNumber(L, 1)));
|
||||
} else if (Game::Lua::IsString(L, 1)) {
|
||||
dispatched = DispatchSpellCastByName(Game::Lua::ToString(L, 1));
|
||||
}
|
||||
const int spellID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
|
||||
// Spell not in the player's spellbook → match `CastSpellByName`'s
|
||||
// silent failure.
|
||||
if (!DispatchSpellCast(spellID)) {
|
||||
// Bad input / spell not in the player's spellbook → match
|
||||
// `CastSpellByName`'s silent failure.
|
||||
if (!dispatched) {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,12 @@ bool CommitAtCoords(const float coords[3]);
|
||||
// `CommitAtCoords`); for a normal spell it fires immediately. Returns
|
||||
// true if the cast was dispatched (spell is in the player's
|
||||
// spellbook), false otherwise.
|
||||
//
|
||||
// The numeric form casts the *exact* spellID (a specific rank). The
|
||||
// name form defers to the engine's own resolver, which parses a
|
||||
// trailing `(Rank N)` — `"Blizzard"` casts the highest known rank,
|
||||
// `"Blizzard(Rank 6)"` casts that rank.
|
||||
bool DispatchSpellCast(int spellID);
|
||||
bool DispatchSpellCastByName(const char *name);
|
||||
|
||||
} // namespace Spell::AtCursor
|
||||
|
||||
+11
-3
@@ -43,11 +43,14 @@ namespace Spell::AtUnit {
|
||||
namespace {
|
||||
|
||||
int __fastcall Script_C_Spell_CastAtUnit(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1) || !Game::Lua::IsString(L, 2)) {
|
||||
// arg1: numeric spellID (exact rank) or spell name ("(Rank N)"-aware).
|
||||
// arg2: unit token.
|
||||
const bool byNumber = Game::Lua::IsNumber(L, 1);
|
||||
if ((!byNumber && !Game::Lua::IsString(L, 1)) ||
|
||||
!Game::Lua::IsString(L, 2)) {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
}
|
||||
const int spellID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
const char *token = Game::Lua::ToString(L, 2);
|
||||
|
||||
// Resolve the unit's position before dispatching — fail fast so a
|
||||
@@ -61,7 +64,12 @@ int __fastcall Script_C_Spell_CastAtUnit(void *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!Spell::AtCursor::DispatchSpellCast(spellID)) {
|
||||
const bool dispatched =
|
||||
byNumber
|
||||
? Spell::AtCursor::DispatchSpellCast(
|
||||
static_cast<int>(Game::Lua::ToNumber(L, 1)))
|
||||
: Spell::AtCursor::DispatchSpellCastByName(Game::Lua::ToString(L, 1));
|
||||
if (!dispatched) {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
+254
-30
@@ -32,26 +32,37 @@
|
||||
// time), dedup'd against a just-made client stamp so a normal cast's
|
||||
// confirming packet doesn't restart its bar. `g_castFromServer = true`;
|
||||
// since the global was never set for these, the WorldTick VAR==0 clear
|
||||
// must skip them — they expire on their computed endMs (and pfUI clears
|
||||
// on nampower's SPELL_FAILED_SELF for interrupts).
|
||||
// - channel: the player's broadcast `UNIT_FIELD_CHANNEL_SPELL`
|
||||
// (descriptor +0x228), polled on `WorldTick`. endMs = now + effective
|
||||
// channel duration.
|
||||
// must skip them — they expire on their computed endMs, or earlier via
|
||||
// the abort co-hooks (ClearCastingSpell / the failure packets) when the
|
||||
// engine learns the cast died.
|
||||
// - channel: stamped from `SMSG_SPELL_START` at packet receipt (instant
|
||||
// channels; engine-computed duration) and from `MSG_CHANNEL_START`
|
||||
// (server duration — and the ONLY start signal for cast-then-channel
|
||||
// spells like Mind Control, whose SpellStart covers just the cast
|
||||
// phase). The broadcast +0x228 field is NOT polled for the player —
|
||||
// it lags the channel start by ~1 tick.
|
||||
// `now` is the engine ms clock (`FUN_OS_TICKCOUNT_MS`), the same source
|
||||
// Lua's `GetTime()` scales by 0.001 — so startMs/endMs are directly
|
||||
// comparable to `GetTime()*1000` in addon progress math.
|
||||
//
|
||||
// Other units have no engine-stored cast record, so we capture their casts
|
||||
// from the `SMSG_SPELL_START` packet (the only place the client sees
|
||||
// another unit's cast + a server-authoritative cast time) into a per-caster
|
||||
// cache — see the SpellStart co-hook below. Scope:
|
||||
// Other units have no engine-stored cast TIMES (the engine does keep the
|
||||
// current-cast spellID at [unit+0xC8C], but nothing temporal), so we
|
||||
// capture their casts from the `SMSG_SPELL_START` packet (the only place
|
||||
// the client sees another unit's cast + a server-authoritative cast time)
|
||||
// into a per-caster cache — see the SpellStart co-hook below. Scope:
|
||||
// - Player casts/channels: full timing (self-tracked, exact engine math).
|
||||
// - Other units' regular CASTS: full timing while within the cast window,
|
||||
// from the SpellStart cache. No clean per-unit interrupt signal exists
|
||||
// in 1.12, so an interrupted remote cast lingers until its computed end.
|
||||
// from the SpellStart cache. Aborts (interrupt, death, movement,
|
||||
// cancel) evict the entry the moment the engine stops the unit's cast
|
||||
// — the CGUnit_C::ClearCastingSpell co-hook below, backstopped by
|
||||
// co-hooks on both failure packets — so no lingering ghost bar.
|
||||
// - Other units' CHANNELS: the broadcast +0x228 field gates "channeling
|
||||
// now"; the SpellStart cache adds real start/end times when we observed
|
||||
// the channel begin (else spellID/name/texture with nil times).
|
||||
// - Other units' PUSHBACK is invisible: SMSG_SPELL_DELAYED goes only to
|
||||
// the affected caster (empirically confirmed — during a melee-pushback
|
||||
// test only the victim's client received it), so a remote bar can't
|
||||
// stretch. Inherent 1.12 protocol gap, not recoverable client-side.
|
||||
//
|
||||
// Modern-signature fields vanilla can't fill are structurally-correct
|
||||
// placeholders: castID / castBarID = nil, notInterruptible = false,
|
||||
@@ -104,8 +115,44 @@ TrackedSpell g_channel{0, 0, 0, 0};
|
||||
// the WorldTick VAR==0 clear must not touch them.
|
||||
bool g_castFromServer = false;
|
||||
|
||||
// Armed once the broadcast UNIT_FIELD_CHANNEL_SPELL (+0x228) has been seen to
|
||||
// reflect g_channel's spell — the enable for OnWorldTick's channel-stop poll.
|
||||
// StampChannel re-arms it (false) on every channel stamp so that field's
|
||||
// ~1-tick start lag can't false-clear a channel we just stamped.
|
||||
bool g_channelConfirmed = false;
|
||||
|
||||
// Stamp the player's channel and re-arm the stop latch. A channel supersedes
|
||||
// any in-flight cast. Both channel-stamp sites (SMSG_SPELL_START's instant-
|
||||
// channel path and the MSG_CHANNEL_START handler) route through here so
|
||||
// neither can forget to reset the latch.
|
||||
void StampChannel(int spellID, int startMs, int endMs) {
|
||||
g_channel = TrackedSpell{spellID, startMs, endMs, 0};
|
||||
g_channelConfirmed = false;
|
||||
g_cast.spellID = 0;
|
||||
}
|
||||
|
||||
int NowMs() { return static_cast<int>(reinterpret_cast<TickMs_t>(Offsets::FUN_OS_TICKCOUNT_MS)()); }
|
||||
|
||||
// Pushes an engine-ms timestamp to Lua as an UNSIGNED 32-bit value.
|
||||
//
|
||||
// `FUN_OS_TICKCOUNT_MS` returns a 64-bit ms tick from one of two backends
|
||||
// (GetTickCount, or a scaled rdtsc — the latter survives warm reboots, so
|
||||
// the value can be well past 2^31 even right after a "restart"). We keep
|
||||
// ticks in a signed int internally, which is fine for the small deltas and
|
||||
// window compares (they cancel), but a direct int->double push surfaces a
|
||||
// NEGATIVE startTimeMs/endTimeMs once the tick's high bit is set.
|
||||
//
|
||||
// The contract is that these match `GetTime()*1000`. Script_GetTime
|
||||
// (0x00515EA0) does `(double)(tick & 0xFFFFFFFF) * 0.001` — i.e. it masks
|
||||
// the tick to the low 32 bits UNSIGNED, then scales. So reinterpreting our
|
||||
// stored tick as uint32 reproduces GetTime()'s exact value for the whole
|
||||
// range, including across the ~49.7-day 2^32 wrap (both wrap together).
|
||||
// Carrying 64-bit precision here would be WRONG: it would diverge from
|
||||
// GetTime() past 2^32 and break addons' (now-start)/(end-start) math.
|
||||
void PushMs(void *L, int ms) {
|
||||
Game::Lua::PushNumber(L, static_cast<double>(static_cast<uint32_t>(ms)));
|
||||
}
|
||||
|
||||
void *Resolve(const char *token) {
|
||||
return reinterpret_cast<ResolveUnitToken_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN)(token);
|
||||
}
|
||||
@@ -173,8 +220,8 @@ int PushCastInfo(void *L, const TrackedSpell &c) {
|
||||
Game::Lua::PushString(L, name); // 1 name
|
||||
Game::Lua::PushString(L, name); // 2 displayName
|
||||
Game::Lua::PushString(L, SpellIconPath(rec)); // 3 textureID (path)
|
||||
Game::Lua::PushNumber(L, static_cast<double>(c.startMs)); // 4 startTimeMs
|
||||
Game::Lua::PushNumber(L, static_cast<double>(c.endMs)); // 5 endTimeMs
|
||||
PushMs(L, c.startMs); // 4 startTimeMs
|
||||
PushMs(L, c.endMs); // 5 endTimeMs
|
||||
Game::Lua::PushBool(L, IsTradeskill(rec)); // 6 isTradeskill
|
||||
Game::Lua::PushNil(L); // 7 castID
|
||||
Game::Lua::PushBool(L, false); // 8 notInterruptible
|
||||
@@ -203,8 +250,8 @@ int PushChannelInfo(void *L, int spellID, int startMs, int endMs, bool haveTimes
|
||||
Game::Lua::PushString(L, name); // 2 text / displayName
|
||||
Game::Lua::PushString(L, SpellIconPath(rec)); // 3 textureID (path)
|
||||
if (haveTimes) {
|
||||
Game::Lua::PushNumber(L, static_cast<double>(startMs)); // 4 startTimeMs
|
||||
Game::Lua::PushNumber(L, static_cast<double>(endMs)); // 5 endTimeMs
|
||||
PushMs(L, startMs); // 4 startTimeMs
|
||||
PushMs(L, endMs); // 5 endTimeMs
|
||||
} else {
|
||||
Game::Lua::PushNil(L);
|
||||
Game::Lua::PushNil(L);
|
||||
@@ -332,7 +379,7 @@ void HandleSpellStart(uint64_t caster, int spellID, uint32_t castTime) {
|
||||
const bool channel = IsChannelSpell(rec);
|
||||
|
||||
if (caster == Unit::Identity::PlayerGuid()) {
|
||||
if (channel) {
|
||||
if (channel && castTime == 0) {
|
||||
// Player channel start. The broadcast +0x228 field that signals
|
||||
// "channeling" is server-pushed and lands ~1 tick (~1s) after the
|
||||
// channel actually begins, so a +0x228 poll shows the bar far too
|
||||
@@ -341,14 +388,19 @@ void HandleSpellStart(uint64_t caster, int spellID, uint32_t castTime) {
|
||||
// now with the engine-computed duration. We run before the
|
||||
// original handler that fires SPELLCAST_CHANNEL_START, so the data
|
||||
// is fresh when addons poll. Cleared by self-expiry (PushChannel-
|
||||
// Info) at endMs.
|
||||
// Info) at endMs. (MSG_CHANNEL_START re-stamps moments later with
|
||||
// the server's duration — see ChannelStart_h.)
|
||||
const int dur = ChannelDurationMs(spellID);
|
||||
if (dur > 0) {
|
||||
g_channel = TrackedSpell{spellID, now, now + dur, 0};
|
||||
g_cast.spellID = 0; // a channel supersedes any cast
|
||||
}
|
||||
if (dur > 0)
|
||||
StampChannel(spellID, now, now + dur);
|
||||
return;
|
||||
}
|
||||
// channel && castTime > 0 → a CAST-THEN-CHANNEL spell (Mind Control:
|
||||
// 3 s cast, then a 60 s channel). This packet is the cast phase —
|
||||
// the channel begins only when the cast completes, signaled by
|
||||
// MSG_CHANNEL_START (ChannelStart_h). Fall through to regular cast
|
||||
// handling so the bar shows the 3 s cast, not a premature 60 s
|
||||
// channel (pfUI #9).
|
||||
if (castTime == 0)
|
||||
return; // instant — no cast bar
|
||||
// Backstop for chained same-spell recasts: the engine short-circuits
|
||||
@@ -367,9 +419,14 @@ void HandleSpellStart(uint64_t caster, int spellID, uint32_t castTime) {
|
||||
g_channel.spellID = 0; // a cast supersedes any channel
|
||||
return;
|
||||
}
|
||||
const int endMs = channel ? now + RemoteChannelDurationMs(rec)
|
||||
: now + static_cast<int>(castTime);
|
||||
StoreRemoteCast(caster, spellID, now, endMs, channel);
|
||||
// A channeled spell with a cast time (Mind Control) is in its CAST phase
|
||||
// here — store it as a regular cast so observers see the 3 s bar. The
|
||||
// remote channel phase has no packet (MSG_CHANNEL_START is caster-only);
|
||||
// it surfaces through the unit's broadcast +0x228 field as usual.
|
||||
const bool instantChannel = channel && castTime == 0;
|
||||
const int endMs = instantChannel ? now + RemoteChannelDurationMs(rec)
|
||||
: now + static_cast<int>(castTime);
|
||||
StoreRemoteCast(caster, spellID, now, endMs, instantChannel);
|
||||
}
|
||||
|
||||
// Co-hook on the SMSG_SPELL_START handler. Gated on opCode 0x131 so every
|
||||
@@ -427,6 +484,151 @@ const Game::HookAutoRegister _spellDelayedHook{
|
||||
Offsets::FUN_SPELL_DELAYED, reinterpret_cast<void *>(&SpellDelayed_h),
|
||||
reinterpret_cast<void **>(&g_origSpellDelayed)};
|
||||
|
||||
// Co-hook on the MSG_CHANNEL_START handler — the server tells the caster a
|
||||
// channel has begun, with the server-authoritative (modifier-applied)
|
||||
// duration. Sent only to the caster, so it's always the local player. This
|
||||
// is what makes CAST-THEN-CHANNEL spells (Mind Control: 3 s cast, then a
|
||||
// 60 s channel) show both phases: their SMSG_SPELL_START carries the cast
|
||||
// (castTime > 0, handled as a regular cast in HandleSpellStart) and only
|
||||
// this packet marks the channel actually starting. For instant channels it
|
||||
// re-stamps what the SpellStart path just wrote (same moment, server
|
||||
// duration) — harmless. We stamp before the original runs so the data is
|
||||
// fresh when the engine fires SPELLCAST_CHANNEL_START. Packet layout
|
||||
// mirrored from nampower's SpellChannelStartHandlerHook:
|
||||
// spellId(u32), durationMs(u32).
|
||||
using ChannelStart_t = int(__stdcall *)(uint32_t *opCode,
|
||||
Net::CDataStore *packet);
|
||||
ChannelStart_t g_origChannelStart = nullptr;
|
||||
|
||||
int __stdcall ChannelStart_h(uint32_t *opCode, Net::CDataStore *packet) {
|
||||
if (packet != nullptr) {
|
||||
const uint32_t saved = packet->m_read;
|
||||
const int spellID = static_cast<int>(Net::Read<uint32_t>(packet));
|
||||
const uint32_t duration = Net::Read<uint32_t>(packet);
|
||||
packet->m_read = saved;
|
||||
if (spellID != 0 && duration > 0) {
|
||||
const int now = NowMs();
|
||||
StampChannel(spellID, now, now + static_cast<int>(duration));
|
||||
}
|
||||
}
|
||||
return g_origChannelStart(opCode, packet);
|
||||
}
|
||||
|
||||
const Game::HookAutoRegister _channelStartHook{
|
||||
Offsets::FUN_SPELL_CHANNEL_START,
|
||||
reinterpret_cast<void *>(&ChannelStart_h),
|
||||
reinterpret_cast<void **>(&g_origChannelStart)};
|
||||
|
||||
// Shared abort handling for the two sibling failure packets. Servers
|
||||
// derived from (v)mangos broadcast BOTH `SMSG_SPELL_FAILURE` and
|
||||
// `SMSG_SPELL_FAILED_OTHER` from Spell::SendInterrupted, but which one a
|
||||
// given core emits per abort path varies — so both handlers are co-hooked
|
||||
// and both feed this. Idempotent, so the both-arrive case is harmless.
|
||||
void HandleCastAborted(uint64_t guid, int spellID) {
|
||||
if (guid == 0 || spellID == 0)
|
||||
return;
|
||||
// Remote units: invalidate the cached cast/channel so
|
||||
// UnitCastingInfo/UnitChannelInfo stop reporting it this tick.
|
||||
for (auto &e : g_remoteCasts) {
|
||||
if (e.used && e.casterGuid == guid && e.spellID == spellID) {
|
||||
e.used = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Local player: a server-stamped chained recast (g_castFromServer)
|
||||
// never set VAR_CURRENT_CAST_SPELL, so the WorldTick VAR==0 poll can't
|
||||
// clear it on interrupt — this packet is the only signal. Whether the
|
||||
// caster receives their own broadcast is server-dependent; if it never
|
||||
// fires, the endMs self-expiry backstop still applies.
|
||||
if (guid == Unit::Identity::PlayerGuid() && g_cast.spellID == spellID)
|
||||
g_cast.spellID = 0;
|
||||
}
|
||||
|
||||
// Co-hook on the SMSG_SPELL_FAILED_OTHER handler — the server broadcasts it
|
||||
// to observers whenever a started cast aborts (interrupt, death, movement,
|
||||
// fizzle). It's what lets us drop a remote cast the moment it dies instead
|
||||
// of letting the ghost bar run to its computed end (the documented
|
||||
// remote-unit limitation above). Packet body is plain (not packed):
|
||||
// casterGuid(u64), spellId(u32).
|
||||
using SpellFailedOther_t = int(__stdcall *)(uint32_t *opCode,
|
||||
Net::CDataStore *packet);
|
||||
SpellFailedOther_t g_origSpellFailedOther = nullptr;
|
||||
|
||||
int __stdcall SpellFailedOther_h(uint32_t *opCode, Net::CDataStore *packet) {
|
||||
if (packet != nullptr) {
|
||||
const uint32_t saved = packet->m_read;
|
||||
const uint64_t guid = Net::Read<uint64_t>(packet);
|
||||
const int spellID = static_cast<int>(Net::Read<uint32_t>(packet));
|
||||
packet->m_read = saved;
|
||||
HandleCastAborted(guid, spellID);
|
||||
}
|
||||
return g_origSpellFailedOther(opCode, packet);
|
||||
}
|
||||
|
||||
const Game::HookAutoRegister _spellFailedOtherHook{
|
||||
Offsets::FUN_SPELL_FAILED_OTHER,
|
||||
reinterpret_cast<void *>(&SpellFailedOther_h),
|
||||
reinterpret_cast<void **>(&g_origSpellFailedOther)};
|
||||
|
||||
// Co-hook on the SMSG_SPELL_FAILURE handler — FAILED_OTHER's sibling, with
|
||||
// a trailing result(u8) after the same casterGuid(u64), spellId(u32) head
|
||||
// (we don't read the result). This is the packet that actually stops the
|
||||
// caster's cast VISUAL in the engine's own handler, so it demonstrably
|
||||
// arrives for interrupts; hooking both siblings makes the eviction
|
||||
// independent of which one the server chose to send.
|
||||
using SpellFailure_t = int(__stdcall *)(uint32_t *opCode,
|
||||
Net::CDataStore *packet);
|
||||
SpellFailure_t g_origSpellFailure = nullptr;
|
||||
|
||||
int __stdcall SpellFailure_h(uint32_t *opCode, Net::CDataStore *packet) {
|
||||
if (packet != nullptr) {
|
||||
const uint32_t saved = packet->m_read;
|
||||
const uint64_t guid = Net::Read<uint64_t>(packet);
|
||||
const int spellID = static_cast<int>(Net::Read<uint32_t>(packet));
|
||||
packet->m_read = saved;
|
||||
HandleCastAborted(guid, spellID);
|
||||
}
|
||||
return g_origSpellFailure(opCode, packet);
|
||||
}
|
||||
|
||||
const Game::HookAutoRegister _spellFailureHook{
|
||||
Offsets::FUN_SPELL_FAILURE, reinterpret_cast<void *>(&SpellFailure_h),
|
||||
reinterpret_cast<void **>(&g_origSpellFailure)};
|
||||
|
||||
// Co-hook on CGUnit_C::ClearCastingSpell — the engine choke point every
|
||||
// "unit stopped casting" path funnels through (failure packets, SPELL_GO,
|
||||
// movement, death, animation events, local cancel — see Offsets.h). The
|
||||
// original is gated on `spellID == [unit+0xC8C]` (the unit's live
|
||||
// current-cast field), so a real stop only happens when the gate passes;
|
||||
// we mirror the gate and evict then. This is the PRIMARY interrupt signal
|
||||
// on Turtle: its core doesn't broadcast either failure packet — interrupt
|
||||
// propagation to observers happens via SuperWoW, whose code calls this
|
||||
// method directly (verified by return-address tracing: interrupted remote
|
||||
// casts clear with a caller inside a sibling DLL, natural completions
|
||||
// clear from the SPELL_GO handler). Verified in-game: Kick / Earth Shock /
|
||||
// Counterspell each evict the victim's cast, while non-interrupting damage
|
||||
// (pushback flinch) does NOT route through here — no false eviction.
|
||||
using ClearCastingSpell_t = void(__fastcall *)(void *unit, void *edx,
|
||||
int spellID, char notify,
|
||||
char cleanup);
|
||||
ClearCastingSpell_t g_origClearCastingSpell = nullptr;
|
||||
|
||||
void __fastcall ClearCastingSpell_h(void *unit, void *edx, int spellID,
|
||||
char notify, char cleanup) {
|
||||
if (unit != nullptr && spellID != 0) {
|
||||
const int current = *reinterpret_cast<const int *>(
|
||||
static_cast<const uint8_t *>(unit) + Offsets::OFF_UNIT_CAST_SPELL);
|
||||
if (current != 0 && current == spellID)
|
||||
HandleCastAborted(Unit::Identity::GuidForObject(unit), spellID);
|
||||
}
|
||||
g_origClearCastingSpell(unit, edx, spellID, notify, cleanup);
|
||||
}
|
||||
|
||||
const Game::HookAutoRegister _clearCastingHook{
|
||||
Offsets::FUN_UNIT_CLEAR_CASTING_SPELL,
|
||||
reinterpret_cast<void *>(&ClearCastingSpell_h),
|
||||
reinterpret_cast<void **>(&g_origClearCastingSpell)};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Per-frame upkeep for the player. The regular cast is stamped by the
|
||||
@@ -445,10 +647,32 @@ void OnWorldTick() {
|
||||
*reinterpret_cast<const int *>(Offsets::VAR_CURRENT_CAST_SPELL) == 0)
|
||||
g_cast.spellID = 0;
|
||||
|
||||
// Channels are stamped from SMSG_SPELL_START (HandleSpellStart) and expire
|
||||
// on their computed endMs (self-expiry in PushChannelInfo). We don't poll
|
||||
// the broadcast +0x228 field for the player — it lags the channel start by
|
||||
// ~1 tick, so the bar would show ~1s late.
|
||||
// Detect a player CHANNEL that ended before its computed endMs — the
|
||||
// summon-ritual case (UNIT_FIELD_CHANNEL_SPELL = 698, cleared when the
|
||||
// summon fills), and equally an interrupted / cancelled / LoS-broken
|
||||
// channel. Without this, g_channel only clears at endMs (self-expiry in
|
||||
// PushChannelInfo) or when a later TIMED cast supersedes it — so an early
|
||||
// end followed by an INSTANT cast (which supersedes nothing) leaves a
|
||||
// ghost bar counting down to a duration that no longer reflects reality.
|
||||
//
|
||||
// We deliberately don't use +0x228 to START the bar — it's a broadcast
|
||||
// UpdateField that lags the channel start by ~1 tick (HandleSpellStart
|
||||
// stamps from the packet instead). For the STOP that lag is harmless, but a
|
||||
// naive "clear when field == 0" would wipe a channel we just stamped during
|
||||
// the lag window. Guard with a latch: only honor the 0 once the field has
|
||||
// been seen to reflect our channel spell at least once. A channel too short
|
||||
// to ever appear in the field just self-expires at endMs.
|
||||
if (g_channel.spellID != 0) {
|
||||
const uint8_t *desc = Unit::Identity::PlayerDescriptor();
|
||||
if (desc != nullptr) {
|
||||
const int chan = *reinterpret_cast<const int *>(
|
||||
desc + Offsets::OFF_UNIT_FIELD_CHANNEL_SPELL);
|
||||
if (chan == g_channel.spellID)
|
||||
g_channelConfirmed = true;
|
||||
else if (chan == 0 && g_channelConfirmed)
|
||||
g_channel.spellID = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const Tick::WorldTick::AutoSubscribe _tickSub{&OnWorldTick};
|
||||
@@ -458,8 +682,8 @@ static int __fastcall Script_CastingInfo(void *L) { return PushCastInfo(L, g_cas
|
||||
|
||||
// `UnitCastingInfo(unit)` — local player from self-tracking; other units
|
||||
// from the SMSG_SPELL_START cache (regular casts still within their cast
|
||||
// window). An interrupted remote cast lingers until its computed end time
|
||||
// (no clean per-unit interrupt signal in 1.12) — acceptable best-effort.
|
||||
// window; aborted casts are evicted by the ClearCastingSpell / failure-
|
||||
// packet co-hooks).
|
||||
static int __fastcall Script_UnitCastingInfo(void *L) {
|
||||
if (!Game::Lua::IsString(L, 1)) {
|
||||
Game::Lua::Error(L, "Usage: C_Spell.UnitCastingInfo(\"unit\")");
|
||||
|
||||
@@ -0,0 +1,449 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// Trade-skill *list* links (`|Htrade:...|h`) — the shareable "here's my
|
||||
// profession and which recipes I know" link. Vanilla 1.12 has NO such link
|
||||
// type (the engine's SetHyperlink parser only knows `item:` and `enchant:`);
|
||||
// 2.x introduced it. We backport the whole thing: the link is built entirely
|
||||
// in C here; only the click-to-display viewer lives in the embedded addon
|
||||
// (Util/TradeSkillLink.lua), since that's UI.
|
||||
//
|
||||
// Wire format (a ClassicAPI-private shape — nothing native emits/reads it, so
|
||||
// we're free to define it; modeled on the 2.x/3.3.5 `trade:` link, with the
|
||||
// linker's name in the slot 2.x used for the GUID):
|
||||
//
|
||||
// |cffffd000|Htrade:<skillLineID>:<curRank>:<maxRank>:<linkerName>:<base64 bits>|h[Name]|h|r
|
||||
//
|
||||
// - skillLineID — SkillLine.dbc row (e.g. 164 = Blacksmithing)
|
||||
// - curRank/maxRank — the linker's skill level (cosmetic; viewer title)
|
||||
// - linkerName — the linking character's name
|
||||
// - base64 bits — a bitfield over the skill line's *canonical recipe list*:
|
||||
// one bit per possible recipe, set = the linker knows it.
|
||||
//
|
||||
// The canonical recipe list is every SkillLineAbility.dbc row for the skill
|
||||
// line whose spell actually produces a craft (see IsCraftRecipe — an item,
|
||||
// enchant, or Turtle LEARN_SPELL recipe; this excludes profession abilities
|
||||
// like Disenchant), in ascending record-ID order. That ordering is
|
||||
// deterministic and identical on every client with the same DBC, so builder
|
||||
// and reader agree on the bit-index space without any handshake. "Which
|
||||
// recipes does the linker know" comes from the player-spell bitmap
|
||||
// (VAR_PLAYER_SPELL_BITMAP — the same store IsPlayerSpell reads, which covers
|
||||
// profession recipes), NOT from the trade-skill window's server list.
|
||||
//
|
||||
// The TradeSkill and Craft windows are separate frames with separate storage
|
||||
// and can both be open at once, so each gets its own builder (matching
|
||||
// WotLK) — each reads only its own window's open-state global (both zeroed by
|
||||
// the engine on close), so "both open" is unambiguous and neither guesses:
|
||||
//
|
||||
// - `C_TradeSkillUI.GetTradeSkillListLink()` — the TradeSkill window
|
||||
// - `C_TradeSkillUI.GetCraftListLink()` — the Craft window (Enchanting)
|
||||
// - `C_TradeSkillUI.GetTradeSkillListRecipes(skillLineID, bits)` — decoder
|
||||
// for the viewer.
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "spell/Lookup.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
namespace TradeSkill::Link {
|
||||
|
||||
namespace {
|
||||
|
||||
// 6 recipes per character, LSB-first (mirrors 3.x's encoder).
|
||||
constexpr char kBase64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
constexpr int kRecipesPerChar = 6;
|
||||
constexpr int kMaxRecipes = 1024; // largest vanilla skill line is ~340
|
||||
constexpr int kBitsBufSize = kMaxRecipes / kRecipesPerChar + 2;
|
||||
|
||||
int Base64Value(char c) {
|
||||
for (int i = 0; i < 64; ++i)
|
||||
if (kBase64[i] == c)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// A spell is a craftable recipe (vs. a profession ability like Disenchant, or
|
||||
// a rank-up / skill-grant spell) iff one of its effects produces a craft: an
|
||||
// item (CREATE_ITEM), an enchant (ENCHANT_ITEM / _TEMPORARY), or Turtle's
|
||||
// custom recipes (LEARN_SPELL). Filtering on the skill-up threshold alone
|
||||
// wrongly kept Disenchant (which carries thresholds but isn't a recipe).
|
||||
bool IsCraftRecipe(int spellID) {
|
||||
const uint8_t *rec = Spell::Lookup::RecordForID(spellID);
|
||||
if (rec == nullptr)
|
||||
return false;
|
||||
const int32_t *eff = reinterpret_cast<const int32_t *>(
|
||||
rec + Offsets::OFF_SPELL_RECORD_EFFECT);
|
||||
for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) {
|
||||
const int e = eff[i];
|
||||
if (e == Offsets::SPELL_EFFECT_CREATE_ITEM ||
|
||||
e == Offsets::SPELL_EFFECT_LEARN_SPELL ||
|
||||
e == Offsets::SPELL_EFFECT_ENCHANT_ITEM ||
|
||||
e == Offsets::SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fills `outSpell` with the recipe spellIDs for `skillLineID`, in canonical
|
||||
// (ascending record-ID) order, and — when non-null — `outGrey`/`outGreen` with
|
||||
// the skill levels the recipe turns grey / green at (its difficulty tiers; the
|
||||
// required-skill field 7 is uselessly 1 for nearly every trainer-taught
|
||||
// recipe). Returns the count (capped at `maxOut`). Same walk builder and reader
|
||||
// use, so the bit-index space is identical.
|
||||
int BuildRecipeList(uint32_t skillLineID, int *outSpell, int *outGrey,
|
||||
int *outGreen, int maxOut) {
|
||||
auto *const *records = *reinterpret_cast<const uint8_t *const *const *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_RECORDS));
|
||||
const int count = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_COUNT));
|
||||
if (records == nullptr || count <= 0)
|
||||
return 0;
|
||||
|
||||
int n = 0;
|
||||
for (int i = 1; i <= count && n < maxOut; ++i) {
|
||||
const uint8_t *rec = records[i];
|
||||
if (rec == nullptr)
|
||||
continue;
|
||||
if (static_cast<uint32_t>(*reinterpret_cast<const int *>(
|
||||
rec + Offsets::OFF_SLA_SKILL_ID)) != skillLineID)
|
||||
continue;
|
||||
const int spellID =
|
||||
*reinterpret_cast<const int *>(rec + Offsets::OFF_SLA_SPELL_ID);
|
||||
if (!IsCraftRecipe(spellID))
|
||||
continue;
|
||||
if (outGrey != nullptr)
|
||||
outGrey[n] = *reinterpret_cast<const int *>(
|
||||
rec + Offsets::OFF_SLA_TRIVIAL_SKILL_HIGH);
|
||||
if (outGreen != nullptr)
|
||||
outGreen[n] = *reinterpret_cast<const int *>(
|
||||
rec + Offsets::OFF_SLA_TRIVIAL_SKILL_LOW);
|
||||
outSpell[n++] = spellID;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// Same bit the engine (and our IsPlayerSpell) reads — covers profession
|
||||
// recipes, not just trained abilities.
|
||||
bool IsKnownSpell(int spellID) {
|
||||
if (spellID <= 0)
|
||||
return false;
|
||||
auto *bitmap = *reinterpret_cast<const uint32_t *const *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_PLAYER_SPELL_BITMAP));
|
||||
if (bitmap == nullptr)
|
||||
return false;
|
||||
return (bitmap[static_cast<uint32_t>(spellID) >> 5] &
|
||||
(1u << (spellID & 31))) != 0;
|
||||
}
|
||||
|
||||
// Skill line (SkillLine.dbc row) of the first SLA row that teaches `spellID`,
|
||||
// or 0 if none. Used to identify the Craft window's profession, which — unlike
|
||||
// the TradeSkill window — has no skill-line global (the engine derives it from
|
||||
// the recipe, see `GetCraftDisplaySkillLine` at `0x004F6CB0`).
|
||||
uint32_t SkillForSpell(int spellID) {
|
||||
if (spellID <= 0)
|
||||
return 0;
|
||||
auto *const *records = *reinterpret_cast<const uint8_t *const *const *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_RECORDS));
|
||||
const int count = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_COUNT));
|
||||
if (records == nullptr || count <= 0)
|
||||
return 0;
|
||||
for (int i = 1; i <= count; ++i) {
|
||||
const uint8_t *rec = records[i];
|
||||
if (rec != nullptr &&
|
||||
*reinterpret_cast<const int *>(rec + Offsets::OFF_SLA_SPELL_ID) ==
|
||||
spellID)
|
||||
return static_cast<uint32_t>(
|
||||
*reinterpret_cast<const int *>(rec + Offsets::OFF_SLA_SKILL_ID));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Skill line of the open Craft window (Enchanting, pet training) — derived
|
||||
// from its first real recipe entry, mirroring the engine. 0 if none open.
|
||||
uint32_t CraftSkillLine() {
|
||||
const int count = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CRAFT_COUNT));
|
||||
if (count <= 0)
|
||||
return 0;
|
||||
const int cap = (count < kMaxRecipes) ? count : kMaxRecipes;
|
||||
for (int slot = 0; slot < cap; ++slot) {
|
||||
const int spellID = Spell::Lookup::RecipeSlotSpellID(
|
||||
Offsets::VAR_CRAFT_ENTRIES, Offsets::VAR_CRAFT_COUNT, slot);
|
||||
if (spellID > 0) {
|
||||
const uint32_t skill = SkillForSpell(spellID);
|
||||
if (skill != 0)
|
||||
return skill;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Encodes the local player's known-recipe bitfield for `skillLineID` into
|
||||
// `out` (must hold kBitsBufSize). Returns the recipe count, or -1 if the skill
|
||||
// line has no recipes.
|
||||
int EncodeKnownBits(uint32_t skillLineID, char *out) {
|
||||
int spells[kMaxRecipes];
|
||||
const int n = BuildRecipeList(skillLineID, spells, nullptr, nullptr,
|
||||
kMaxRecipes);
|
||||
if (n <= 0)
|
||||
return -1;
|
||||
|
||||
int nb = 0;
|
||||
unsigned acc = 0;
|
||||
int used = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (IsKnownSpell(spells[i]))
|
||||
acc |= (1u << used);
|
||||
if (++used == kRecipesPerChar) {
|
||||
out[nb++] = kBase64[acc];
|
||||
acc = 0;
|
||||
used = 0;
|
||||
}
|
||||
}
|
||||
if (used != 0)
|
||||
out[nb++] = kBase64[acc];
|
||||
out[nb] = '\0';
|
||||
return n;
|
||||
}
|
||||
|
||||
// Current / max skill rank for the local player in `skillLine`, read from the
|
||||
// CGPlayer `+0xE68` sub-struct exactly as the engine's own accessors do (see
|
||||
// the FUN_SKILL_LINE_TO_SLOT block in Offsets.h). Leaves 0/0 when the player
|
||||
// isn't resolvable or doesn't have the skill.
|
||||
void ReadPlayerSkillRank(int skillLine, int *outCur, int *outMax) {
|
||||
*outCur = 0;
|
||||
*outMax = 0;
|
||||
const uint8_t *player = Unit::Identity::PlayerObject();
|
||||
if (player == nullptr)
|
||||
return;
|
||||
using SlotFn = int(__thiscall *)(const void *, int);
|
||||
const int slot = reinterpret_cast<SlotFn>(
|
||||
Offsets::FUN_SKILL_LINE_TO_SLOT)(player, skillLine);
|
||||
if (slot < 0)
|
||||
return;
|
||||
const uint8_t *base = *reinterpret_cast<const uint8_t *const *>(
|
||||
player + Offsets::OFF_CGPLAYER_INFO);
|
||||
if (base == nullptr)
|
||||
return;
|
||||
const uint8_t *rec =
|
||||
base + Offsets::OFF_SKILL_INFO_TABLE + slot * Offsets::SKILL_INFO_STRIDE;
|
||||
uint32_t cur = *reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_CUR);
|
||||
uint32_t mx = *reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_MAX);
|
||||
const uint32_t bonus =
|
||||
*reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_BONUS);
|
||||
if (cur != 0)
|
||||
cur += bonus;
|
||||
if (mx != 0)
|
||||
mx += bonus;
|
||||
*outCur = static_cast<int>(cur);
|
||||
*outMax = static_cast<int>(mx);
|
||||
}
|
||||
|
||||
// The local player's character name via the engine's object name getter.
|
||||
const char *PlayerCharacterName() {
|
||||
const uint8_t *player = Unit::Identity::PlayerObject();
|
||||
if (player == nullptr)
|
||||
return "";
|
||||
using GetName_t = const char *(__thiscall *)(const void *, int *);
|
||||
const char *name = reinterpret_cast<GetName_t>(
|
||||
Offsets::FUN_OBJECT_GET_NAME)(player, nullptr);
|
||||
return (name != nullptr) ? name : "";
|
||||
}
|
||||
|
||||
// Builds the full `|Htrade:...|h` link for whichever window `useCraft`
|
||||
// selects. Pushes the link string (returns 1), or nothing (returns 0 → nil)
|
||||
// when that window is closed or has no recipes.
|
||||
int BuildLink(void *L, bool useCraft) {
|
||||
int skillLine;
|
||||
if (useCraft) {
|
||||
// Craft-window open-state flag; zeroed by the engine on close.
|
||||
if (*reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CRAFT_WINDOW_STATE)) == 0)
|
||||
return 0;
|
||||
skillLine = static_cast<int>(CraftSkillLine());
|
||||
} else {
|
||||
// TradeSkill skill-line global; zeroed by the engine on close.
|
||||
skillLine = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CURRENT_TRADESKILL_LINE));
|
||||
}
|
||||
if (skillLine <= 0)
|
||||
return 0;
|
||||
|
||||
char bits[kBitsBufSize];
|
||||
if (EncodeKnownBits(static_cast<uint32_t>(skillLine), bits) < 0)
|
||||
return 0;
|
||||
|
||||
const char *prof = DBC::LocalizedField(
|
||||
Offsets::VAR_SKILL_LINE_RECORDS, Offsets::VAR_SKILL_LINE_COUNT,
|
||||
static_cast<uint32_t>(skillLine), Offsets::OFF_SKILL_LINE_NAME);
|
||||
if (prof == nullptr || *prof == '\0')
|
||||
return 0;
|
||||
|
||||
int cur = 0, mx = 0;
|
||||
ReadPlayerSkillRank(skillLine, &cur, &mx);
|
||||
const char *who = PlayerCharacterName();
|
||||
|
||||
char link[512];
|
||||
std::snprintf(link, sizeof link,
|
||||
"|cffffd000|Htrade:%d:%d:%d:%s:%s|h[%s]|h|r", skillLine, cur,
|
||||
mx, who, bits, prof);
|
||||
Game::Lua::PushString(L, link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// `C_TradeSkillUI.GetTradeSkillListLink()` -> link for the open TradeSkill
|
||||
// window, or nil.
|
||||
int __fastcall Script_GetTradeSkillListLink(void *L) {
|
||||
return BuildLink(L, /*useCraft=*/false);
|
||||
}
|
||||
|
||||
// `C_TradeSkillUI.GetCraftListLink()` -> link for the open Craft window, or nil.
|
||||
int __fastcall Script_GetCraftListLink(void *L) {
|
||||
return BuildLink(L, /*useCraft=*/true);
|
||||
}
|
||||
|
||||
// `C_TradeSkillUI.GetTradeSkillListRecipes(skillLineID, bits)`
|
||||
// -> { { spellID, isKnown, trivialLevel, greenLevel, createdItem,
|
||||
// numMade, reagents = { { itemID, count }, ... } }, ... }
|
||||
// `trivialLevel` / `greenLevel` are the skill levels the recipe turns
|
||||
// grey / green at — its difficulty tiers, for sorting and colouring.
|
||||
// `createdItem` is the crafted item's ID (0 for enchants) — the viewer
|
||||
// derives its subclass filter from it. `numMade` is how many the recipe
|
||||
// yields (CREATE_ITEM base points + dice; 0 for enchants). `reagents` lists
|
||||
// each consumed item + required count in DBC slot order (stopping at the
|
||||
// first empty slot, the engine's own convention), for the detail pane.
|
||||
//
|
||||
// Rebuilds the canonical recipe list for `skillLineID` and decodes `bits`
|
||||
// against it. Recipes past the end of `bits` (shorter/garbled string) decode
|
||||
// as not-known rather than erroring. The Lua caller (the viewer) turns each
|
||||
// spellID into a name/icon via GetSpellInfo and each reagent itemID into
|
||||
// name/texture/on-hand-count via GetItemInfo / GetItemCount.
|
||||
//
|
||||
// The real 3.3.5 reagent API (GetTradeSkillReagentInfo etc.) can't serve this:
|
||||
// it's indexed by position in the player's *own* open trade window, so it
|
||||
// can't describe a linked recipe from someone else's profession. We read the
|
||||
// reagents straight from Spell.dbc instead.
|
||||
int __fastcall Script_GetTradeSkillListRecipes(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1) || !Game::Lua::IsString(L, 2)) {
|
||||
Game::Lua::Error(
|
||||
L, "Usage: C_TradeSkillUI.GetTradeSkillListRecipes(skillLineID, bits)");
|
||||
return 0;
|
||||
}
|
||||
const uint32_t skillLine =
|
||||
static_cast<uint32_t>(Game::Lua::ToNumber(L, 1));
|
||||
const char *bits = Game::Lua::ToString(L, 2);
|
||||
const int blen = (bits != nullptr) ? static_cast<int>(std::strlen(bits)) : 0;
|
||||
|
||||
int spells[kMaxRecipes];
|
||||
int greys[kMaxRecipes];
|
||||
int greens[kMaxRecipes];
|
||||
const int n = BuildRecipeList(skillLine, spells, greys, greens, kMaxRecipes);
|
||||
|
||||
Game::Lua::NewTable(L);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
const int ci = i / kRecipesPerChar;
|
||||
const int bi = i % kRecipesPerChar;
|
||||
bool known = false;
|
||||
if (ci < blen) {
|
||||
const int v = Base64Value(bits[ci]);
|
||||
if (v >= 0)
|
||||
known = (v & (1 << bi)) != 0;
|
||||
}
|
||||
|
||||
// The recipe's crafted item (0 for enchants) — the viewer groups the
|
||||
// subclass filter by this item's subclass — plus its yield count.
|
||||
const uint8_t *srec = Spell::Lookup::RecordForID(spells[i]);
|
||||
int createdItem = 0;
|
||||
int numMade = 0;
|
||||
if (srec != nullptr) {
|
||||
createdItem = *reinterpret_cast<const int *>(
|
||||
srec + Offsets::OFF_SPELL_RECORD_CREATED_ITEM);
|
||||
// Yield: the CREATE_ITEM effect's magnitude (base points + dice),
|
||||
// mirroring the engine's item-creation math. 0 for enchants.
|
||||
const int32_t *eff = reinterpret_cast<const int32_t *>(
|
||||
srec + Offsets::OFF_SPELL_RECORD_EFFECT);
|
||||
const int32_t *basePts = reinterpret_cast<const int32_t *>(
|
||||
srec + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS);
|
||||
const int32_t *baseDice = reinterpret_cast<const int32_t *>(
|
||||
srec + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE);
|
||||
for (int e = 0; e < Offsets::SPELL_RECORD_EFFECT_COUNT; ++e) {
|
||||
if (eff[e] == Offsets::SPELL_EFFECT_CREATE_ITEM) {
|
||||
numMade = basePts[e] + baseDice[e];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Game::Lua::PushNumber(L, static_cast<double>(i + 1));
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetFieldNumber(L, "spellID", static_cast<double>(spells[i]));
|
||||
Game::Lua::SetFieldBool(L, "isKnown", known);
|
||||
Game::Lua::SetFieldNumber(L, "trivialLevel",
|
||||
static_cast<double>(greys[i]));
|
||||
Game::Lua::SetFieldNumber(L, "greenLevel",
|
||||
static_cast<double>(greens[i]));
|
||||
Game::Lua::SetFieldNumber(L, "createdItem",
|
||||
static_cast<double>(createdItem));
|
||||
Game::Lua::SetFieldNumber(L, "numMade", static_cast<double>(numMade));
|
||||
|
||||
// reagents = { {itemID, count}, ... } — nested array under "reagents"
|
||||
// (no SetField helper takes a table value, so push key + build + SetTable).
|
||||
Game::Lua::PushString(L, "reagents");
|
||||
Game::Lua::NewTable(L);
|
||||
if (srec != nullptr) {
|
||||
const int32_t *rids = reinterpret_cast<const int32_t *>(
|
||||
srec + Offsets::OFF_SPELL_REAGENT_ID);
|
||||
const int32_t *rcounts = reinterpret_cast<const int32_t *>(
|
||||
srec + Offsets::OFF_SPELL_REAGENT_COUNT);
|
||||
int outIdx = 0;
|
||||
for (int r = 0; r < Offsets::SPELL_MAX_REAGENTS; ++r) {
|
||||
if (rids[r] == 0)
|
||||
break; // first empty slot ends the list
|
||||
Game::Lua::PushNumber(L, static_cast<double>(++outIdx));
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetFieldNumber(L, "itemID",
|
||||
static_cast<double>(rids[r]));
|
||||
Game::Lua::SetFieldNumber(L, "count",
|
||||
static_cast<double>(rcounts[r]));
|
||||
Game::Lua::SetTable(L, -3); // reagents[outIdx] = {itemID,count}
|
||||
}
|
||||
}
|
||||
Game::Lua::SetTable(L, -3); // entry.reagents = { ... }
|
||||
|
||||
Game::Lua::SetTable(L, -3);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_TradeSkillUI", "GetTradeSkillListLink",
|
||||
&Script_GetTradeSkillListLink);
|
||||
Game::Lua::RegisterTableFunction("C_TradeSkillUI", "GetCraftListLink",
|
||||
&Script_GetCraftListLink);
|
||||
Game::Lua::RegisterTableFunction("C_TradeSkillUI",
|
||||
"GetTradeSkillListRecipes",
|
||||
&Script_GetTradeSkillListRecipes);
|
||||
}
|
||||
|
||||
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace TradeSkill::Link
|
||||
@@ -96,6 +96,37 @@ uint64_t PlayerGuid() {
|
||||
return g_charSelectGuid; // early-login fallback (0 until char-select)
|
||||
}
|
||||
|
||||
const uint8_t *PlayerObject() {
|
||||
// Resolve the player's CGObject straight from the object manager by GUID —
|
||||
// one hash lookup, no token-string parsing, and non-throwing: the resolver
|
||||
// returns null when the GUID isn't loaded (pre-world) instead of raising,
|
||||
// so this is safe from any context (world tick, packet send hook, Lua
|
||||
// callback). The GUID comes from PlayerGuid() — 0 before char-select, which
|
||||
// short-circuits to null here. NOT VAR_LOCAL_PLAYER_PTR: its +0xC0 is only
|
||||
// the GUID, not the canonical CGPlayer whose descriptor is readable.
|
||||
const uint64_t guid = PlayerGuid();
|
||||
if (guid == 0)
|
||||
return nullptr;
|
||||
using ResolveByGuid_t = void *(__fastcall *)(uint32_t typeMask,
|
||||
const char *debugName,
|
||||
uint32_t guidLo, uint32_t guidHi,
|
||||
int line);
|
||||
auto resolve =
|
||||
reinterpret_cast<ResolveByGuid_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
return static_cast<const uint8_t *>(
|
||||
resolve(Offsets::OBJ_TYPE_PLAYER, "ClassicAPI",
|
||||
static_cast<uint32_t>(guid), static_cast<uint32_t>(guid >> 32),
|
||||
/*line*/ 0));
|
||||
}
|
||||
|
||||
const uint8_t *PlayerDescriptor() {
|
||||
const uint8_t *player = PlayerObject();
|
||||
if (player == nullptr)
|
||||
return nullptr;
|
||||
return *reinterpret_cast<const uint8_t *const *>(
|
||||
player + Offsets::OFF_UNIT_DESCRIPTOR);
|
||||
}
|
||||
|
||||
uint64_t GuidForObject(const void *unitObject) {
|
||||
if (unitObject == nullptr)
|
||||
return 0;
|
||||
|
||||
@@ -28,6 +28,22 @@ namespace Unit::Identity {
|
||||
// re-dereferencing the globals inline.
|
||||
uint64_t PlayerGuid();
|
||||
|
||||
// The local player's in-world object pointer, resolved straight from the
|
||||
// object manager by GUID (`FUN_OBJECT_RESOLVE_BY_GUID`) — the fastest path we
|
||||
// have (one hash lookup, no token-string work) and naturally non-throwing:
|
||||
// null before the player object exists (pre-world) or before char-select,
|
||||
// never a raise. Safe from any context — Lua callback, world tick, packet
|
||||
// hook. Deliberately NOT `VAR_LOCAL_PLAYER_PTR`: that global carries the
|
||||
// player GUID at +0xC0 but is NOT the CGPlayer whose descriptor and
|
||||
// CGPlayer-local fields are readable (see Offsets.h).
|
||||
const uint8_t *PlayerObject();
|
||||
|
||||
// The local player's `m_objectFields` descriptor (`PlayerObject() +
|
||||
// OFF_UNIT_DESCRIPTOR`), or null. This is the broadcast UpdateField block
|
||||
// (health / power / flags / UNIT_FIELD_CHANNEL_SPELL / …). Prefer this over
|
||||
// re-deriving the player object + descriptor offset in each module.
|
||||
const uint8_t *PlayerDescriptor();
|
||||
|
||||
// The 64-bit GUID of a resolved CGUnit/CGObject pointer, read through the
|
||||
// pointer at `+0x08` to an instance block whose first 8 bytes are the GUID
|
||||
// (verified in `Script_GetInventoryItemLink`; see `OFF_UNIT_GUID_PTR`).
|
||||
|
||||
+55
-51
@@ -21,6 +21,7 @@
|
||||
#include "Offsets.h"
|
||||
#include "aura/Data.h"
|
||||
#include "spell/Lookup.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -28,24 +29,10 @@ namespace Unit::State {
|
||||
|
||||
namespace {
|
||||
|
||||
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
|
||||
using CancelAuraSend_t = void(__fastcall *)(int spellID);
|
||||
|
||||
const uint8_t *Player() {
|
||||
auto fn = reinterpret_cast<ResolveUnitToken_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN);
|
||||
return static_cast<const uint8_t *>(fn("player"));
|
||||
}
|
||||
|
||||
const uint8_t *PlayerDescriptor() {
|
||||
auto *player = Player();
|
||||
if (player == nullptr)
|
||||
return nullptr;
|
||||
return *reinterpret_cast<const uint8_t *const *>(
|
||||
player + Offsets::OFF_UNIT_DESCRIPTOR);
|
||||
}
|
||||
|
||||
uint32_t PlayerMovementFlags() {
|
||||
auto *player = Player();
|
||||
auto *player = Unit::Identity::PlayerObject();
|
||||
if (player == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint32_t *>(
|
||||
@@ -59,11 +46,39 @@ uint32_t MountDisplayID(const uint8_t *desc) {
|
||||
desc + Offsets::OFF_UNIT_FIELD_MOUNTDISPLAYID);
|
||||
}
|
||||
|
||||
// Scans the player's helpful-aura (buff) slots for the first spell whose
|
||||
// Spell.dbc record lists `auraEffect` (a `SPELL_AURA_*` code) in any of
|
||||
// its three effect slots, and returns that spellID (0 if none). Used by
|
||||
// `Dismount` to find the active mount aura to cancel — the engine's
|
||||
// `CMSG_CANCEL_AURA` needs the spellID, not a slot index.
|
||||
uint32_t FindPlayerBuffWithEffect(int auraEffect) {
|
||||
auto *player = Unit::Identity::PlayerObject();
|
||||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
for (int slot = 0; slot < Offsets::UNIT_AURA_BUFF_COUNT; ++slot) {
|
||||
if (!Aura::Data::IsSlotPopulated(player, slot))
|
||||
continue;
|
||||
const uint32_t spellID = Aura::Data::ReadSpellID(player, slot);
|
||||
const uint8_t *record = Spell::Lookup::RecordForID(static_cast<int>(spellID));
|
||||
if (record == nullptr)
|
||||
continue;
|
||||
|
||||
auto *auraTypes = reinterpret_cast<const int32_t *>(
|
||||
record + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME);
|
||||
for (int eff = 0; eff < Offsets::SPELL_RECORD_EFFECT_COUNT; ++eff) {
|
||||
if (auraTypes[eff] == auraEffect)
|
||||
return spellID;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// `IsMounted()` — true iff the player is currently mounted. Reads
|
||||
// `UNIT_FIELD_MOUNTDISPLAYID` from the descriptor; non-zero means
|
||||
// the engine is rendering a mount under the player.
|
||||
int __fastcall Script_IsMounted(void *L) {
|
||||
auto *desc = PlayerDescriptor();
|
||||
auto *desc = Unit::Identity::PlayerDescriptor();
|
||||
Game::Lua::PushBool(L, MountDisplayID(desc) != 0);
|
||||
return 1;
|
||||
}
|
||||
@@ -80,50 +95,39 @@ int __fastcall Script_IsMounted(void *L) {
|
||||
// No-op if the player isn't mounted (early-outs on the
|
||||
// `UNIT_FIELD_MOUNTDISPLAYID` check before walking auras).
|
||||
int __fastcall Script_Dismount(void *L) {
|
||||
auto *desc = PlayerDescriptor();
|
||||
auto *desc = Unit::Identity::PlayerDescriptor();
|
||||
if (MountDisplayID(desc) == 0)
|
||||
return 0;
|
||||
|
||||
auto *player = Player();
|
||||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
for (int slot = 0; slot < Offsets::UNIT_AURA_BUFF_COUNT; ++slot) {
|
||||
if (!Aura::Data::IsSlotPopulated(player, slot))
|
||||
continue;
|
||||
const uint32_t spellID = Aura::Data::ReadSpellID(player, slot);
|
||||
const uint8_t *record = Spell::Lookup::RecordForID(static_cast<int>(spellID));
|
||||
if (record == nullptr)
|
||||
continue;
|
||||
|
||||
auto *auraTypes = reinterpret_cast<const int32_t *>(
|
||||
record + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME);
|
||||
for (int eff = 0; eff < Offsets::SPELL_RECORD_EFFECT_COUNT; ++eff) {
|
||||
if (auraTypes[eff] != Offsets::SPELL_AURA_MOUNTED)
|
||||
continue;
|
||||
auto fn = reinterpret_cast<CancelAuraSend_t>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_CANCEL_AURA_SEND));
|
||||
fn(static_cast<int>(spellID));
|
||||
return 0;
|
||||
}
|
||||
const uint32_t spellID = FindPlayerBuffWithEffect(Offsets::SPELL_AURA_MOUNTED);
|
||||
if (spellID != 0) {
|
||||
auto fn = reinterpret_cast<CancelAuraSend_t>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_CANCEL_AURA_SEND));
|
||||
fn(static_cast<int>(spellID));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// `IsStealthed()` — true iff the player is currently stealthed
|
||||
// (Rogue Stealth / Druid Prowl). Checks `PLAYER_FIELD_VIS_BYTES`
|
||||
// bit 0x02. Mount also sets that bit, so we AND-gate with
|
||||
// `mountDisplayID == 0` to disambiguate. See the comment on
|
||||
// `OFF_PLAYER_FIELD_VIS_BYTES` in Offsets.h for the full bit map
|
||||
// and known limitations (untested for shapeshift forms).
|
||||
// (Rogue Stealth / Druid Prowl / Night Elf Shadowmeld / etc.). Reads
|
||||
// the sneak flag in `UNIT_FIELD_BYTES_1` byte 3 (mask
|
||||
// `UNIT_BYTES_1_STEALTH_FLAG`) — the same broadcast bit the client's
|
||||
// render path uses to draw a stealthed unit semi-transparent.
|
||||
//
|
||||
// Derived via `_classicapi_DiffAll`: a Prowl toggle from a Cat-Form
|
||||
// baseline flips byte 3 `0x00 -> 0x02` and touches nothing else but
|
||||
// aura-array slot metadata, so this is the one standalone descriptor
|
||||
// bit that means "stealthed" (the earlier `0x17C & 0x02` read was
|
||||
// actually AURALEVELS and only worked by coincidence). Being a unit
|
||||
// anim-tier flag rather than a class field, it covers every stealth
|
||||
// source and rank without a spellID list or an aura scan.
|
||||
int __fastcall Script_IsStealthed(void *L) {
|
||||
auto *desc = PlayerDescriptor();
|
||||
auto *desc = Unit::Identity::PlayerDescriptor();
|
||||
bool stealthed = false;
|
||||
if (desc != nullptr) {
|
||||
const uint32_t visBytes = *reinterpret_cast<const uint32_t *>(
|
||||
desc + Offsets::OFF_PLAYER_FIELD_VIS_BYTES);
|
||||
stealthed = (visBytes & Offsets::PLAYER_VIS_BIT_STEALTH) != 0
|
||||
&& MountDisplayID(desc) == 0;
|
||||
const uint32_t bytes1 = *reinterpret_cast<const uint32_t *>(
|
||||
desc + Offsets::OFF_UNIT_FIELD_BYTES_1);
|
||||
stealthed = (bytes1 & Offsets::UNIT_BYTES_1_STEALTH_FLAG) != 0;
|
||||
}
|
||||
Game::Lua::PushBool(L, stealthed);
|
||||
return 1;
|
||||
@@ -177,12 +181,12 @@ int __fastcall Script_IsSwimming(void *L) {
|
||||
// vanilla's summoning ritual has no UI surface, which is what
|
||||
// motivates this function.
|
||||
int __fastcall Script_IsAssistingRitual(void *L) {
|
||||
auto *player = Player();
|
||||
auto *player = Unit::Identity::PlayerObject();
|
||||
if (player == nullptr) {
|
||||
Game::Lua::PushBool(L, 0);
|
||||
return 1;
|
||||
}
|
||||
auto *desc = PlayerDescriptor();
|
||||
auto *desc = Unit::Identity::PlayerDescriptor();
|
||||
if (desc == nullptr) {
|
||||
Game::Lua::PushBoolean(L, 0);
|
||||
return 1;
|
||||
|
||||
@@ -0,0 +1,594 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// Text-to-speech — a Windows SAPI backend behind modern WoW's C_VoiceChat /
|
||||
// C_TTSSettings Lua surface. Ported from awesome_wotlk's VoiceChat.cpp (the
|
||||
// 3.3.5 implementation); the SAPI core is client-version-agnostic, so only
|
||||
// the three integration seams are ClassicAPI-native:
|
||||
// - namespaces → Game::Lua::RegisterTableFunction
|
||||
// - events → Event::Custom (AutoReserve + Fire)
|
||||
// - settings → CVar::Factory (ttsVoice / ttsSpeed / ttsVolume, persisted
|
||||
// to Config.wtf, clamped via change callbacks)
|
||||
//
|
||||
// Lua surface:
|
||||
// C_VoiceChat
|
||||
// GetTtsVoices() -> { {voiceID=, name=}, ... }
|
||||
// GetRemoteTtsVoices() -> same (vanilla has no real voice chat)
|
||||
// SpeakText(voiceID, text[, destination[, rate[, volume]]])
|
||||
// StopSpeakingText()
|
||||
// C_TTSSettings
|
||||
// GetSpeechRate() / GetSpeechVolume() / GetSpeechVoiceID()
|
||||
// GetVoiceOptionName()
|
||||
// SetDefaultSettings()
|
||||
// SetSpeechRate(v) / SetSpeechVolume(v)
|
||||
// SetVoiceOption(id) / SetVoiceOptionByName(name)
|
||||
// RefreshVoices()
|
||||
//
|
||||
// Events: VOICE_CHAT_TTS_PLAYBACK_STARTED/FINISHED/FAILED,
|
||||
// VOICE_CHAT_TTS_SPEAK_TEXT_UPDATE (reserved, unused),
|
||||
// VOICE_CHAT_TTS_VOICES_UPDATE.
|
||||
//
|
||||
// Threading: SAPI is created on the main (game) thread under an STA, and
|
||||
// SetNotifyCallbackFunction marshals the notify back to that thread's message
|
||||
// pump (WoW pumps messages every frame), so OnSpeechNotify runs on the main
|
||||
// thread and may touch the Lua event dispatcher safely.
|
||||
//
|
||||
// Coexistence: the same TTS surface also ships as the standalone VanillaTTS
|
||||
// DLL (which adds a pluggable backend — software synth under Wine). When
|
||||
// that DLL is injected alongside us, this module stands down entirely — see
|
||||
// StandaloneTtsPresent below.
|
||||
|
||||
#include "Game.h"
|
||||
#include "cvar/Factory.h"
|
||||
#include "event/Custom.h"
|
||||
|
||||
#include <initguid.h> // instantiate the SAPI GUIDs in this TU (no sapi.lib)
|
||||
#include <sapi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cwctype>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace VoiceChat::Tts {
|
||||
|
||||
namespace {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Standalone-DLL coexistence
|
||||
// ---------------------------------------------------------------------------
|
||||
// The dedicated VanillaTTS DLL provides this exact Lua surface (same
|
||||
// C_VoiceChat / C_TTSSettings functions, same VOICE_CHAT_TTS_* events, same
|
||||
// ttsVoice/ttsSpeed/ttsVolume cvars) with a more capable backend. If both
|
||||
// registered, the damage wouldn't be limited to "last one wins":
|
||||
// - Each DLL claims its OWN event-table slot for the same event name, so
|
||||
// the table ends up with duplicate-name entries. frame:RegisterEvent
|
||||
// binds listeners to whichever slot the engine's scan finds first, while
|
||||
// the other DLL fires the other slot — events silently lost depending on
|
||||
// load order.
|
||||
// - The cvar registrar dedups by name but REPLACES the change callback on
|
||||
// re-register, so one DLL's clamp callbacks (and userData) go dead.
|
||||
// - Both would init COM/SAPI and answer SpeakText → double playback risk.
|
||||
// So when VanillaTTS.dll is in the process, this module registers nothing —
|
||||
// no Lua functions, no cvars, no event reservations, no SAPI init.
|
||||
//
|
||||
// The check runs at RegisterLuaFunctions time (first login), which is
|
||||
// load-order-independent: VanillaFixes loads every DLL at process attach,
|
||||
// long before FUN_LOAD_SCRIPT_FUNCTIONS first fires. Latched once — modules
|
||||
// can't appear or vanish mid-session.
|
||||
bool StandaloneTtsPresent() {
|
||||
static const bool present = GetModuleHandleA("VanillaTTS.dll") != nullptr;
|
||||
return present;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Event names — reserved lazily in RegisterLuaFunctions (NOT via file-scope
|
||||
// AutoReserve statics, which would run unconditionally at DLL load and claim
|
||||
// slots even when we're standing down for VanillaTTS).
|
||||
// ---------------------------------------------------------------------------
|
||||
constexpr const char *kEvtPlaybackFailed = "VOICE_CHAT_TTS_PLAYBACK_FAILED";
|
||||
constexpr const char *kEvtPlaybackFinished = "VOICE_CHAT_TTS_PLAYBACK_FINISHED";
|
||||
constexpr const char *kEvtPlaybackStarted = "VOICE_CHAT_TTS_PLAYBACK_STARTED";
|
||||
constexpr const char *kEvtSpeakTextUpdate = "VOICE_CHAT_TTS_SPEAK_TEXT_UPDATE";
|
||||
constexpr const char *kEvtVoicesUpdate = "VOICE_CHAT_TTS_VOICES_UPDATE";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CVar names + handles (registered in RegisterLuaFunctions)
|
||||
// ---------------------------------------------------------------------------
|
||||
constexpr const char *kCVarVoice = "ttsVoice";
|
||||
constexpr const char *kCVarSpeed = "ttsSpeed";
|
||||
constexpr const char *kCVarVolume = "ttsVolume";
|
||||
|
||||
CVar::Factory::Handle g_cvarVoice = nullptr;
|
||||
CVar::Factory::Handle g_cvarSpeed = nullptr;
|
||||
CVar::Factory::Handle g_cvarVolume = nullptr;
|
||||
|
||||
// Destination constants (kept for API parity; no special handling — SAPI
|
||||
// queues FIFO either way).
|
||||
enum : int {
|
||||
DEST_LOCAL_PLAYBACK = 1,
|
||||
DEST_QUEUED_LOCAL_PLAYBACK = 4,
|
||||
};
|
||||
int ClampDestination(int d) {
|
||||
return d == DEST_QUEUED_LOCAL_PLAYBACK ? DEST_QUEUED_LOCAL_PLAYBACK
|
||||
: DEST_LOCAL_PLAYBACK;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAPI state
|
||||
// ---------------------------------------------------------------------------
|
||||
ISpVoice *g_pVoice = nullptr;
|
||||
bool g_comInit = false;
|
||||
|
||||
int g_nextUtteranceID = 1;
|
||||
int NextUtteranceID() {
|
||||
if (g_nextUtteranceID >= 0x7fffffff)
|
||||
g_nextUtteranceID = 1;
|
||||
return g_nextUtteranceID++;
|
||||
}
|
||||
|
||||
struct UtteranceMeta {
|
||||
int id;
|
||||
int destination;
|
||||
bool startedEmitted;
|
||||
};
|
||||
std::mutex g_streamMx;
|
||||
std::unordered_map<ULONG, UtteranceMeta> g_streamMap;
|
||||
|
||||
struct VoiceEntry {
|
||||
int voiceID;
|
||||
std::wstring name;
|
||||
};
|
||||
std::vector<VoiceEntry> g_cachedVoices;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UTF-8 / wide conversion
|
||||
// ---------------------------------------------------------------------------
|
||||
std::string WideToUtf8(const std::wstring &w) {
|
||||
if (w.empty())
|
||||
return {};
|
||||
int need = WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||
if (need <= 1)
|
||||
return {};
|
||||
std::string out(static_cast<size_t>(need - 1), '\0');
|
||||
WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, &out[0], need - 1, nullptr, nullptr);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::wstring Utf8ToWide(const char *s) {
|
||||
if (s == nullptr || *s == '\0')
|
||||
return {};
|
||||
int need = MultiByteToWideChar(CP_UTF8, 0, s, -1, nullptr, 0);
|
||||
if (need <= 1)
|
||||
return {};
|
||||
std::wstring out(static_cast<size_t>(need - 1), L'\0');
|
||||
MultiByteToWideChar(CP_UTF8, 0, s, -1, &out[0], need);
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Event fire helpers (engine dispatcher via Event::Custom)
|
||||
// ---------------------------------------------------------------------------
|
||||
void FireVoicesUpdate() {
|
||||
Event::Custom::Fire(Event::Custom::Lookup(kEvtVoicesUpdate), "");
|
||||
}
|
||||
void FirePlaybackStarted(int numConsumers, int utteranceID, int durationMS, int dest) {
|
||||
Event::Custom::Fire(Event::Custom::Lookup(kEvtPlaybackStarted), "%d%d%d%d",
|
||||
numConsumers, utteranceID, durationMS, dest);
|
||||
}
|
||||
void FirePlaybackFinished(int numConsumers, int utteranceID, int dest) {
|
||||
Event::Custom::Fire(Event::Custom::Lookup(kEvtPlaybackFinished), "%d%d%d",
|
||||
numConsumers, utteranceID, dest);
|
||||
}
|
||||
void FirePlaybackFailed(const char *status, int utteranceID, int dest) {
|
||||
Event::Custom::Fire(Event::Custom::Lookup(kEvtPlaybackFailed), "%s%d%d",
|
||||
status, utteranceID, dest);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// COM / SAPI lifecycle
|
||||
// ---------------------------------------------------------------------------
|
||||
void InitCom() {
|
||||
if (g_comInit)
|
||||
return;
|
||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
// S_FALSE = already initialized on this thread; treat as success.
|
||||
if (SUCCEEDED(hr) || hr == RPC_E_CHANGED_MODE)
|
||||
g_comInit = true;
|
||||
}
|
||||
|
||||
void __stdcall OnSpeechNotify(WPARAM, LPARAM) {
|
||||
if (g_pVoice == nullptr)
|
||||
return;
|
||||
SPEVENT ev = {};
|
||||
ULONG fetched = 0;
|
||||
while (SUCCEEDED(g_pVoice->GetEvents(1, &ev, &fetched)) && fetched == 1) {
|
||||
if (ev.eEventId == SPEI_START_INPUT_STREAM) {
|
||||
std::lock_guard<std::mutex> lock(g_streamMx);
|
||||
auto it = g_streamMap.find(ev.ulStreamNum);
|
||||
if (it != g_streamMap.end() && !it->second.startedEmitted) {
|
||||
FirePlaybackStarted(1, it->second.id, /*durationMS*/ 0,
|
||||
it->second.destination);
|
||||
it->second.startedEmitted = true;
|
||||
}
|
||||
} else if (ev.eEventId == SPEI_END_INPUT_STREAM) {
|
||||
UtteranceMeta meta{0, DEST_LOCAL_PLAYBACK, false};
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_streamMx);
|
||||
auto it = g_streamMap.find(ev.ulStreamNum);
|
||||
if (it != g_streamMap.end()) {
|
||||
meta = it->second;
|
||||
g_streamMap.erase(it);
|
||||
}
|
||||
}
|
||||
FirePlaybackFinished(1, meta.id, meta.destination);
|
||||
}
|
||||
// Only START/END stream events are requested; neither carries an
|
||||
// allocated lParam, so no SpClearEvent (sphelper) is needed.
|
||||
ev = SPEVENT{};
|
||||
}
|
||||
}
|
||||
|
||||
void InitVoice() {
|
||||
if (g_pVoice != nullptr)
|
||||
return;
|
||||
InitCom();
|
||||
HRESULT hr = CoCreateInstance(CLSID_SpVoice, nullptr, CLSCTX_ALL,
|
||||
IID_ISpVoice, reinterpret_cast<void **>(&g_pVoice));
|
||||
if (FAILED(hr) || g_pVoice == nullptr) {
|
||||
g_pVoice = nullptr;
|
||||
return;
|
||||
}
|
||||
g_pVoice->SetNotifyCallbackFunction(&OnSpeechNotify, 0, 0);
|
||||
const ULONGLONG interest =
|
||||
SPFEI(SPEI_START_INPUT_STREAM) | SPFEI(SPEI_END_INPUT_STREAM);
|
||||
g_pVoice->SetInterest(interest, interest);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Voice enumeration (CLSID_SpObjectTokenCategory; no sphelper)
|
||||
// ---------------------------------------------------------------------------
|
||||
std::vector<VoiceEntry> EnumerateVoices() {
|
||||
InitCom();
|
||||
std::vector<VoiceEntry> voices;
|
||||
|
||||
ISpObjectTokenCategory *cat = nullptr;
|
||||
if (FAILED(CoCreateInstance(CLSID_SpObjectTokenCategory, nullptr, CLSCTX_ALL,
|
||||
IID_ISpObjectTokenCategory,
|
||||
reinterpret_cast<void **>(&cat))) ||
|
||||
cat == nullptr)
|
||||
return voices;
|
||||
|
||||
if (SUCCEEDED(cat->SetId(SPCAT_VOICES, FALSE))) {
|
||||
IEnumSpObjectTokens *en = nullptr;
|
||||
if (SUCCEEDED(cat->EnumTokens(nullptr, nullptr, &en)) && en != nullptr) {
|
||||
ISpObjectToken *tok = nullptr;
|
||||
ULONG fetched = 0;
|
||||
int index = 0;
|
||||
while (en->Next(1, &tok, &fetched) == S_OK && fetched == 1) {
|
||||
LPWSTR desc = nullptr;
|
||||
if (SUCCEEDED(tok->GetStringValue(nullptr, &desc)) && desc != nullptr) {
|
||||
voices.push_back({index, desc});
|
||||
CoTaskMemFree(desc);
|
||||
}
|
||||
tok->Release();
|
||||
++index;
|
||||
}
|
||||
en->Release();
|
||||
}
|
||||
}
|
||||
cat->Release();
|
||||
return voices;
|
||||
}
|
||||
|
||||
int VoiceCount() {
|
||||
return static_cast<int>(EnumerateVoices().size());
|
||||
}
|
||||
|
||||
void RefreshVoices() {
|
||||
auto fresh = EnumerateVoices();
|
||||
bool changed = fresh.size() != g_cachedVoices.size();
|
||||
if (!changed) {
|
||||
for (size_t i = 0; i < fresh.size(); ++i) {
|
||||
if (fresh[i].name != g_cachedVoices[i].name) {
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_cachedVoices = std::move(fresh);
|
||||
if (changed)
|
||||
FireVoicesUpdate();
|
||||
}
|
||||
|
||||
// Select the voice at enumeration index `voiceID` on g_pVoice.
|
||||
bool SelectVoice(int voiceID) {
|
||||
ISpObjectTokenCategory *cat = nullptr;
|
||||
if (FAILED(CoCreateInstance(CLSID_SpObjectTokenCategory, nullptr, CLSCTX_ALL,
|
||||
IID_ISpObjectTokenCategory,
|
||||
reinterpret_cast<void **>(&cat))) ||
|
||||
cat == nullptr)
|
||||
return false;
|
||||
|
||||
bool set = false;
|
||||
if (SUCCEEDED(cat->SetId(SPCAT_VOICES, FALSE))) {
|
||||
IEnumSpObjectTokens *en = nullptr;
|
||||
if (SUCCEEDED(cat->EnumTokens(nullptr, nullptr, &en)) && en != nullptr) {
|
||||
ISpObjectToken *tok = nullptr;
|
||||
ULONG fetched = 0;
|
||||
int index = 0;
|
||||
while (en->Next(1, &tok, &fetched) == S_OK && fetched == 1) {
|
||||
if (index == voiceID) {
|
||||
set = SUCCEEDED(g_pVoice->SetVoice(tok));
|
||||
tok->Release();
|
||||
break;
|
||||
}
|
||||
tok->Release();
|
||||
++index;
|
||||
}
|
||||
en->Release();
|
||||
}
|
||||
}
|
||||
cat->Release();
|
||||
return set;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Speak / stop
|
||||
// ---------------------------------------------------------------------------
|
||||
void SpeakText(int voiceID, const std::wstring &text, int destination, int rate,
|
||||
int volume) {
|
||||
const int utteranceID = NextUtteranceID();
|
||||
const int dest = ClampDestination(destination);
|
||||
|
||||
InitVoice();
|
||||
if (g_pVoice == nullptr) {
|
||||
FirePlaybackFailed("EngineAllocationFailed", utteranceID, dest);
|
||||
return;
|
||||
}
|
||||
if (!SelectVoice(voiceID)) {
|
||||
FirePlaybackFailed("InternalError", utteranceID, dest);
|
||||
return;
|
||||
}
|
||||
|
||||
g_pVoice->SetRate(std::clamp(rate, -10, 10));
|
||||
g_pVoice->SetVolume(static_cast<USHORT>(std::clamp(volume, 0, 100)));
|
||||
|
||||
ULONG streamNum = 0;
|
||||
if (FAILED(g_pVoice->Speak(text.c_str(), SPF_ASYNC, &streamNum))) {
|
||||
FirePlaybackFailed("InternalError", utteranceID, dest);
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(g_streamMx);
|
||||
g_streamMap[streamNum] = UtteranceMeta{utteranceID, dest, false};
|
||||
}
|
||||
|
||||
void StopAll() {
|
||||
InitVoice();
|
||||
if (g_pVoice == nullptr)
|
||||
return;
|
||||
g_pVoice->Speak(nullptr, SPF_PURGEBEFORESPEAK, nullptr);
|
||||
std::lock_guard<std::mutex> lock(g_streamMx);
|
||||
g_streamMap.clear();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Lua helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
// Push a { {voiceID=, name=}, ... } array built from g_cachedVoices.
|
||||
void PushVoicesTable(void *L) {
|
||||
Game::Lua::NewTable(L); // outer array at top
|
||||
for (size_t i = 0; i < g_cachedVoices.size(); ++i) {
|
||||
Game::Lua::PushNumber(L, static_cast<double>(i + 1)); // 1-based array key
|
||||
Game::Lua::NewTable(L); // sub-table
|
||||
Game::Lua::SetFieldNumber(L, "voiceID", g_cachedVoices[i].voiceID);
|
||||
Game::Lua::SetFieldString(L, "name",
|
||||
WideToUtf8(g_cachedVoices[i].name).c_str());
|
||||
// stack: [outer, key, sub] → outer[key] = sub
|
||||
Game::Lua::RawSet(L, -3);
|
||||
}
|
||||
}
|
||||
|
||||
int OptInt(void *L, int idx, int fallback) {
|
||||
return Game::Lua::IsNumber(L, idx)
|
||||
? static_cast<int>(Game::Lua::ToNumber(L, idx))
|
||||
: fallback;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// C_VoiceChat
|
||||
// ---------------------------------------------------------------------------
|
||||
int __fastcall Script_GetTtsVoices(void *L) {
|
||||
RefreshVoices();
|
||||
PushVoicesTable(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int __fastcall Script_GetRemoteTtsVoices(void *L) {
|
||||
RefreshVoices();
|
||||
PushVoicesTable(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int __fastcall Script_SpeakText(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1) || !Game::Lua::IsString(L, 2)) {
|
||||
Game::Lua::Error(L, "Usage: C_VoiceChat.SpeakText(voiceID, text "
|
||||
"[, destination, rate, volume])");
|
||||
return 0;
|
||||
}
|
||||
const int voiceID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
const std::wstring text = Utf8ToWide(Game::Lua::ToString(L, 2));
|
||||
const int dest = OptInt(L, 3, DEST_LOCAL_PLAYBACK);
|
||||
const int rate = OptInt(L, 4, 0);
|
||||
const int volume = OptInt(L, 5, 100);
|
||||
SpeakText(voiceID, text, dest, rate, volume);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __fastcall Script_StopSpeakingText(void *) {
|
||||
StopAll();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// C_TTSSettings
|
||||
// ---------------------------------------------------------------------------
|
||||
int __fastcall Script_GetSpeechRate(void *L) {
|
||||
Game::Lua::PushNumber(L, CVar::Factory::GetInt(g_cvarSpeed, 0));
|
||||
return 1;
|
||||
}
|
||||
int __fastcall Script_GetSpeechVolume(void *L) {
|
||||
Game::Lua::PushNumber(L, CVar::Factory::GetInt(g_cvarVolume, 100));
|
||||
return 1;
|
||||
}
|
||||
int __fastcall Script_GetSpeechVoiceID(void *L) {
|
||||
Game::Lua::PushNumber(L, CVar::Factory::GetInt(g_cvarVoice, 0));
|
||||
return 1;
|
||||
}
|
||||
int __fastcall Script_GetVoiceOptionName(void *L) {
|
||||
const int id = CVar::Factory::GetInt(g_cvarVoice, 0);
|
||||
auto voices = EnumerateVoices();
|
||||
if (id >= 0 && id < static_cast<int>(voices.size()))
|
||||
Game::Lua::PushString(L, WideToUtf8(voices[id].name).c_str());
|
||||
else
|
||||
Game::Lua::PushString(L, "");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int __fastcall Script_SetSpeechRate(void *L) {
|
||||
if (Game::Lua::IsNumber(L, 1))
|
||||
CVar::Factory::SetInt(g_cvarSpeed, static_cast<int>(Game::Lua::ToNumber(L, 1)));
|
||||
return 0;
|
||||
}
|
||||
int __fastcall Script_SetSpeechVolume(void *L) {
|
||||
if (Game::Lua::IsNumber(L, 1))
|
||||
CVar::Factory::SetInt(g_cvarVolume, static_cast<int>(Game::Lua::ToNumber(L, 1)));
|
||||
return 0;
|
||||
}
|
||||
int __fastcall Script_SetVoiceOption(void *L) {
|
||||
if (Game::Lua::IsNumber(L, 1))
|
||||
CVar::Factory::SetInt(g_cvarVoice, static_cast<int>(Game::Lua::ToNumber(L, 1)));
|
||||
return 0;
|
||||
}
|
||||
int __fastcall Script_SetVoiceOptionByName(void *L) {
|
||||
if (!Game::Lua::IsString(L, 1))
|
||||
return 0;
|
||||
const std::wstring want = Utf8ToWide(Game::Lua::ToString(L, 1));
|
||||
auto voices = EnumerateVoices();
|
||||
for (const auto &v : voices) {
|
||||
if (v.name.size() == want.size()) {
|
||||
bool eq = true;
|
||||
for (size_t i = 0; i < want.size(); ++i) {
|
||||
if (towlower(v.name[i]) != towlower(want[i])) {
|
||||
eq = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (eq) {
|
||||
CVar::Factory::SetInt(g_cvarVoice, v.voiceID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int __fastcall Script_SetDefaultSettings(void *) {
|
||||
const int maxVoice = VoiceCount();
|
||||
CVar::Factory::SetInt(g_cvarVoice, maxVoice > 1 ? 1 : 0);
|
||||
CVar::Factory::SetInt(g_cvarSpeed, 0);
|
||||
CVar::Factory::SetInt(g_cvarVolume, 100);
|
||||
FireVoicesUpdate();
|
||||
return 0;
|
||||
}
|
||||
int __fastcall Script_RefreshVoices(void *) {
|
||||
RefreshVoices();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CVar clamp callbacks (re-entrant SetString to clamp; reject out-of-range)
|
||||
// ---------------------------------------------------------------------------
|
||||
int __fastcall ClampRange(CVar::Factory::Handle cvar, const char *, const char *next,
|
||||
int lo, int hi) {
|
||||
if (next == nullptr)
|
||||
return 1;
|
||||
const int v = std::atoi(next);
|
||||
const int c = std::clamp(v, lo, hi);
|
||||
if (c != v) {
|
||||
char buf[16];
|
||||
std::snprintf(buf, sizeof buf, "%d", c);
|
||||
CVar::Factory::SetString(cvar, buf);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int __fastcall OnSpeedChanged(CVar::Factory::Handle c, const char *p, const char *n, void *) {
|
||||
return ClampRange(c, p, n, -10, 10);
|
||||
}
|
||||
int __fastcall OnVolumeChanged(CVar::Factory::Handle c, const char *p, const char *n, void *) {
|
||||
return ClampRange(c, p, n, 0, 100);
|
||||
}
|
||||
int __fastcall OnVoiceChanged(CVar::Factory::Handle c, const char *p, const char *n, void *) {
|
||||
const int maxIdx = VoiceCount() - 1;
|
||||
return ClampRange(c, p, n, 0, maxIdx < 0 ? 0 : maxIdx);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Registration
|
||||
// ---------------------------------------------------------------------------
|
||||
void RegisterLuaFunctions() {
|
||||
if (StandaloneTtsPresent())
|
||||
return; // VanillaTTS owns the TTS surface this session — see above.
|
||||
|
||||
// Reserve the events on first (real) registration. AutoReserve only
|
||||
// appends to Event::Custom's reservation list — the actual slot claims
|
||||
// happen later via the usual RetryClaims walk — so reserving here instead
|
||||
// of at static-init time changes nothing but the conditionality.
|
||||
static const Event::Custom::AutoReserve _r1{kEvtPlaybackFailed};
|
||||
static const Event::Custom::AutoReserve _r2{kEvtPlaybackFinished};
|
||||
static const Event::Custom::AutoReserve _r3{kEvtPlaybackStarted};
|
||||
static const Event::Custom::AutoReserve _r4{kEvtSpeakTextUpdate};
|
||||
static const Event::Custom::AutoReserve _r5{kEvtVoicesUpdate};
|
||||
|
||||
g_cvarVoice = CVar::Factory::Register(kCVarVoice, "0", 0, &OnVoiceChanged);
|
||||
g_cvarSpeed = CVar::Factory::Register(kCVarSpeed, "0", 0, &OnSpeedChanged);
|
||||
g_cvarVolume = CVar::Factory::Register(kCVarVolume, "100", 0, &OnVolumeChanged);
|
||||
|
||||
Game::Lua::RegisterTableFunction("C_VoiceChat", "GetTtsVoices", &Script_GetTtsVoices);
|
||||
Game::Lua::RegisterTableFunction("C_VoiceChat", "GetRemoteTtsVoices", &Script_GetRemoteTtsVoices);
|
||||
Game::Lua::RegisterTableFunction("C_VoiceChat", "SpeakText", &Script_SpeakText);
|
||||
Game::Lua::RegisterTableFunction("C_VoiceChat", "StopSpeakingText", &Script_StopSpeakingText);
|
||||
|
||||
Game::Lua::RegisterTableFunction("C_TTSSettings", "GetSpeechRate", &Script_GetSpeechRate);
|
||||
Game::Lua::RegisterTableFunction("C_TTSSettings", "GetSpeechVolume", &Script_GetSpeechVolume);
|
||||
Game::Lua::RegisterTableFunction("C_TTSSettings", "GetSpeechVoiceID", &Script_GetSpeechVoiceID);
|
||||
Game::Lua::RegisterTableFunction("C_TTSSettings", "GetVoiceOptionName", &Script_GetVoiceOptionName);
|
||||
Game::Lua::RegisterTableFunction("C_TTSSettings", "SetDefaultSettings", &Script_SetDefaultSettings);
|
||||
Game::Lua::RegisterTableFunction("C_TTSSettings", "SetSpeechRate", &Script_SetSpeechRate);
|
||||
Game::Lua::RegisterTableFunction("C_TTSSettings", "SetSpeechVolume", &Script_SetSpeechVolume);
|
||||
Game::Lua::RegisterTableFunction("C_TTSSettings", "SetVoiceOption", &Script_SetVoiceOption);
|
||||
Game::Lua::RegisterTableFunction("C_TTSSettings", "SetVoiceOptionByName", &Script_SetVoiceOptionByName);
|
||||
Game::Lua::RegisterTableFunction("C_TTSSettings", "RefreshVoices", &Script_RefreshVoices);
|
||||
}
|
||||
|
||||
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace VoiceChat::Tts
|
||||
@@ -0,0 +1,232 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// `C_XMLUtil.GetTemplates()` — enumerate every registered virtual XML frame
|
||||
// template as `{ name = <string>, type = <frameType> }`.
|
||||
//
|
||||
// The engine keeps virtual templates (the `<Frame virtual="true">` etc. that
|
||||
// `inherits=` targets) in a Storm hash table. The XML parser (FUN_006ede10)
|
||||
// registers each one via FUN_006ee500, and the inherits resolver reads the
|
||||
// same table via FUN_006ee6f0 — so it's the authoritative template store, and
|
||||
// walking it yields exactly what modern `C_XMLUtil.GetTemplates` returns.
|
||||
// Fonts are a separate registry and are (correctly) not included; non-virtual
|
||||
// named frames take a different instantiate path and never enter this table.
|
||||
//
|
||||
// Table shape (see Offsets.h): a POINTER to a bucket array at
|
||||
// VAR_XML_TEMPLATE_TABLE, a bucket-count mask at VAR_XML_TEMPLATE_MASK
|
||||
// (0xFFFFFFFF until the first template registers). Each bucket is a Storm
|
||||
// intrusive list; each node carries the template name (+0x14) and the parsed
|
||||
// definition node (+0x18), whose element tag string (+0x8) is the frame type.
|
||||
// Contents reflect the currently-loaded XML and are rebuilt on `/reload`.
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace Xml::Templates {
|
||||
|
||||
namespace {
|
||||
|
||||
// ---- Node-DOM helpers (shared by GetTemplateInfo / DoesTemplateExist) -----
|
||||
|
||||
using TemplateLookup_t = const uint8_t *(__fastcall *)(const char *name);
|
||||
using GetAttr_t = const char *(__thiscall *)(const void *node, const char *name);
|
||||
using SStrCmpI_t = int(__stdcall *)(const char *a, const char *b, int n);
|
||||
|
||||
// The engine's by-name template lookup (FUN_006ee6f0) — the same path
|
||||
// `inherits=` resolves through. Returns the parsed definition node, or null
|
||||
// if no template of that name is registered (case-insensitive, hashed).
|
||||
const uint8_t *LookupTemplate(const char *name) {
|
||||
return reinterpret_cast<TemplateLookup_t>(
|
||||
Offsets::FUN_XML_TEMPLATE_LOOKUP)(name);
|
||||
}
|
||||
|
||||
// Value of `node`'s attribute `name`, or null if absent.
|
||||
const char *Attr(const uint8_t *node, const char *name) {
|
||||
return reinterpret_cast<GetAttr_t>(Offsets::FUN_XML_NODE_GET_ATTRIBUTE)(
|
||||
node, name);
|
||||
}
|
||||
|
||||
const uint8_t *FirstChild(const uint8_t *node) {
|
||||
return *reinterpret_cast<const uint8_t *const *>(
|
||||
node + Offsets::OFF_XML_NODE_CHILD);
|
||||
}
|
||||
const uint8_t *NextSibling(const uint8_t *node) {
|
||||
return *reinterpret_cast<const uint8_t *const *>(
|
||||
node + Offsets::OFF_XML_NODE_SIBLING);
|
||||
}
|
||||
|
||||
// Case-insensitive tag match, using the engine's own comparator (the same one
|
||||
// FUN_006f1eb0 uses to recognize "AbsDimension" etc.).
|
||||
bool TagEquals(const uint8_t *node, const char *tag) {
|
||||
const char *t = *reinterpret_cast<const char *const *>(
|
||||
node + Offsets::OFF_XML_NODE_TAG);
|
||||
if (t == nullptr)
|
||||
return false;
|
||||
return reinterpret_cast<SStrCmpI_t>(Offsets::FUN_SSTR_CMP_I)(
|
||||
t, tag, 0x7FFFFFFF) == 0;
|
||||
}
|
||||
|
||||
const uint8_t *FindChild(const uint8_t *node, const char *tag) {
|
||||
for (const uint8_t *c = FirstChild(node); c != nullptr; c = NextSibling(c))
|
||||
if (TagEquals(c, tag))
|
||||
return c;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The statically-declared width/height from a `<Size>` child (0 if none).
|
||||
// Handles the inline `<Size x= y=>` form and the `<Size><AbsDimension x= y=>`
|
||||
// (or RelDimension) child form. Returns the RAW values from the XML — retail's
|
||||
// GetTemplateInfo reports the declared value, so unlike the engine's own Size
|
||||
// parser (FUN_006f1eb0) we deliberately skip the UI-scale conversion.
|
||||
void ReadSize(const uint8_t *node, double *outW, double *outH) {
|
||||
*outW = 0.0;
|
||||
*outH = 0.0;
|
||||
const uint8_t *size = FindChild(node, "Size");
|
||||
if (size == nullptr)
|
||||
return;
|
||||
const char *sx = Attr(size, "x");
|
||||
const char *sy = Attr(size, "y");
|
||||
const uint8_t *dim = FirstChild(size);
|
||||
if (dim != nullptr &&
|
||||
(TagEquals(dim, "AbsDimension") || TagEquals(dim, "RelDimension"))) {
|
||||
const char *dx = Attr(dim, "x");
|
||||
const char *dy = Attr(dim, "y");
|
||||
if (dx != nullptr && *dx != '\0')
|
||||
sx = dx;
|
||||
if (dy != nullptr && *dy != '\0')
|
||||
sy = dy;
|
||||
}
|
||||
if (sx != nullptr && *sx != '\0')
|
||||
*outW = std::strtod(sx, nullptr);
|
||||
if (sy != nullptr && *sy != '\0')
|
||||
*outH = std::strtod(sy, nullptr);
|
||||
}
|
||||
|
||||
// `C_XMLUtil.GetTemplates()` -> XMLTemplateListInfo[] of { name, type }.
|
||||
int __fastcall Script_GetTemplates(void *L) {
|
||||
Game::Lua::NewTable(L); // the result array
|
||||
|
||||
const uint32_t mask =
|
||||
*reinterpret_cast<const uint32_t *>(Offsets::VAR_XML_TEMPLATE_MASK);
|
||||
if (mask == 0xFFFFFFFFu)
|
||||
return 1; // no template has ever registered — empty array
|
||||
|
||||
const uint8_t *base = *reinterpret_cast<const uint8_t *const *>(
|
||||
Offsets::VAR_XML_TEMPLATE_TABLE);
|
||||
if (base == nullptr)
|
||||
return 1;
|
||||
|
||||
int outIdx = 0;
|
||||
for (uint32_t b = 0; b <= mask; ++b) {
|
||||
const uint8_t *bucket = base + b * Offsets::XML_TEMPLATE_BUCKET_STRIDE;
|
||||
const int linkOff = *reinterpret_cast<const int *>(
|
||||
bucket + Offsets::OFF_XML_TEMPLATE_BUCKET_LINKOFF);
|
||||
const uint8_t *node = *reinterpret_cast<const uint8_t *const *>(
|
||||
bucket + Offsets::OFF_XML_TEMPLATE_BUCKET_HEAD);
|
||||
|
||||
// Walk the intrusive chain; the tail sentinel has its low bit set
|
||||
// (mirrors the engine's own traversal in FUN_006ee6f0).
|
||||
while (node != nullptr && (reinterpret_cast<uintptr_t>(node) & 1) == 0) {
|
||||
const char *name = *reinterpret_cast<const char *const *>(
|
||||
node + Offsets::OFF_XML_TEMPLATE_NODE_NAME);
|
||||
const uint8_t *def = *reinterpret_cast<const uint8_t *const *>(
|
||||
node + Offsets::OFF_XML_TEMPLATE_NODE_DEF);
|
||||
const char *type =
|
||||
(def != nullptr)
|
||||
? *reinterpret_cast<const char *const *>(
|
||||
def + Offsets::OFF_XML_NODE_TAG)
|
||||
: nullptr;
|
||||
|
||||
++outIdx;
|
||||
Game::Lua::PushNumber(L, static_cast<double>(outIdx));
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetFieldString(L, "name", name != nullptr ? name : "");
|
||||
Game::Lua::SetFieldString(L, "type", type != nullptr ? type : "");
|
||||
Game::Lua::SetTable(L, -3);
|
||||
|
||||
node = *reinterpret_cast<const uint8_t *const *>(node + linkOff + 4);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// `C_XMLUtil.GetTemplateInfo(name)` -> XMLTemplateInfo table, or nil if the
|
||||
// template doesn't exist.
|
||||
int __fastcall Script_GetTemplateInfo(void *L) {
|
||||
if (!Game::Lua::IsString(L, 1)) {
|
||||
Game::Lua::Error(L, "Usage: C_XMLUtil.GetTemplateInfo(\"name\")");
|
||||
return 0;
|
||||
}
|
||||
const char *name = Game::Lua::ToString(L, 1);
|
||||
const uint8_t *node = (name != nullptr) ? LookupTemplate(name) : nullptr;
|
||||
if (node == nullptr)
|
||||
return 0; // nil — no such template
|
||||
|
||||
Game::Lua::NewTable(L); // XMLTemplateInfo
|
||||
|
||||
const char *type = *reinterpret_cast<const char *const *>(
|
||||
node + Offsets::OFF_XML_NODE_TAG);
|
||||
Game::Lua::SetFieldString(L, "type", type != nullptr ? type : "");
|
||||
|
||||
double w = 0.0, h = 0.0;
|
||||
ReadSize(node, &w, &h);
|
||||
Game::Lua::SetFieldNumber(L, "width", w);
|
||||
Game::Lua::SetFieldNumber(L, "height", h);
|
||||
|
||||
// keyValues: vanilla's XML schema has no <KeyValues> element, so this is
|
||||
// always an empty table (parity with retail's "empty if none defined").
|
||||
Game::Lua::PushString(L, "keyValues");
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetTable(L, -3);
|
||||
|
||||
// inherits: the comma-delimited `inherits=` attribute, or nil (field left
|
||||
// unset) when the template inherits nothing.
|
||||
const char *inherits = Attr(node, "inherits");
|
||||
if (inherits != nullptr && *inherits != '\0')
|
||||
Game::Lua::SetFieldString(L, "inherits", inherits);
|
||||
|
||||
// sourceLocation is intentionally omitted (nil): vanilla records no
|
||||
// file/line for XML nodes — a 10.2.0 addition gated behind the
|
||||
// enableSourceLocationLookup CVar even on retail.
|
||||
return 1;
|
||||
}
|
||||
|
||||
// `C_XMLUtil.DoesTemplateExist(name)` -> bool.
|
||||
int __fastcall Script_DoesTemplateExist(void *L) {
|
||||
if (!Game::Lua::IsString(L, 1)) {
|
||||
Game::Lua::Error(L, "Usage: C_XMLUtil.DoesTemplateExist(\"name\")");
|
||||
return 0;
|
||||
}
|
||||
const char *name = Game::Lua::ToString(L, 1);
|
||||
const uint8_t *node = (name != nullptr) ? LookupTemplate(name) : nullptr;
|
||||
Game::Lua::PushBool(L, node != nullptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
static void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_XMLUtil", "GetTemplates",
|
||||
&Script_GetTemplates);
|
||||
Game::Lua::RegisterTableFunction("C_XMLUtil", "GetTemplateInfo",
|
||||
&Script_GetTemplateInfo);
|
||||
Game::Lua::RegisterTableFunction("C_XMLUtil", "DoesTemplateExist",
|
||||
&Script_DoesTemplateExist);
|
||||
}
|
||||
|
||||
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace Xml::Templates
|
||||
Reference in New Issue
Block a user