diff --git a/README.md b/README.md
index f1b2d884..939131bf 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ The flagship feature: run modern Lua 5.1 addon code on 1.12's Lua 5.0 VM.
|---------|--------|
| Inline textures | Draws inline texture markup (`\|T…\|t`) and atlas markup (`\|A…\|a`) as icons in FontStrings, chat, and tooltips. This covers item and spell icons, raid-target markers, and the coin icons in money strings. `GetStringWidth` and `GetStringHeight` count the icons, so measured width and text wrapping stay correct. Done in pure C++ by hooking the engine's text pipeline — no addon. |
| Tooltip line cap | Lifts `GameTooltip`'s hard 30-line limit to 60 for every `GameTooltipTemplate` frame (`GameTooltip`, `ShoppingTooltip1/2`, `ItemRefTooltip`, AtlasLoot, …). Stat-heavy tooltips and comparison blocks (e.g. pfUI's eqcompare) no longer have their extra lines silently dropped. Done in pure C++ by growing the engine's FontString pool at tooltip-creation time. |
-| [XML attributes](docs/API.md#parentkey-in-xml) | More XML attributes work: `parentKey="Name"` makes `parent.Name` point to a frame, texture or font string, `` uses a global function as a script handler, and a button's `` sets its font. |
+| [XML attributes](docs/API.md#parentkey-in-xml) | More XML attributes work: `parentKey="Name"` makes `parent.Name` point to a frame, texture or font string, `` uses a global function as a script handler, a button's `` sets its font, and `inherits="A, B"` applies more than one template. |
| [Macro conditions](docs/API.md#more-commands-with-conditions) | `[conditions]` and `@unit` work on 38 slash commands, from `/cast` and `/use` to `/target`, `/follow`, `/cancelaura` and the `/pet` family. With `/cast [@mouseover,harm][] Fireball`, the spell goes to the mouseover unit. With no mouseover unit, it goes to your target. `@cursor` places a ground-target spell or item under the mouse and `@player` places it at your feet. A character name works where a unit token does (`[target=Feral]`). Addons read the same rules through `SecureCmdOptionParse`. |
| [`#showtooltip`](docs/API.md#showtooltip-and-show) | A macro button shows what the macro does. The icon, tooltip, cooldown, range, usable state and auto-repeat glow all follow the spell or item that the directive resolves to, conditions included. They update as the conditions change. The result goes into the engine field that action-bar addons already read, so they need no code of their own. An addon with its own macro parser can publish its result through `C_Macro.SetMacroDisplay`. It then does not need to replace the action globals. |
| [Event-driven nameplates](docs/API.md#nameplate) | The modern `C_NamePlate` API, driven by real events. `NAME_PLATE_UNIT_ADDED` / `NAME_PLATE_UNIT_REMOVED` fire as plates appear and vanish, `nameplate1`..`nameplateN` tokens resolve with every `UnitX` function (and fire `UNIT_HEALTH`, `UNIT_AURA`, … as `arg1 == "nameplateN"`), and `C_NamePlate.GetNamePlateForUnit` / `GetNamePlates` hand back the live frames. |
@@ -81,7 +81,7 @@ reference in **[docs/API.md](docs/API.md)**.
| [Expansion](docs/API.md#expansion) | `ClassicExpansionAtLeast`, `ClassicExpansionAtMost`, `GetClassicExpansionLevel` |
| [Faction](docs/API.md#faction) | `C_Reputation.GetFactionDataByID`, `C_Reputation.GetFactionDataByIndex`, `C_Reputation.GetFactionStandings`, `C_Reputation.GetLastStandingChange`, `C_Reputation.GetWatchedFactionData`, `C_Reputation.IsFactionActive`, `C_Reputation.IsFactionActiveByID`, `C_Reputation.IsFactionInactive`, `C_Reputation.SetFactionActive`, `C_Reputation.SetFactionActiveByID`, `C_Reputation.SetFactionInactive`, `C_Reputation.SetFactionInactiveByID`, `C_Reputation.SetSelectedFaction`, `C_Reputation.SetSelectedFactionByID`, `C_Reputation.SetWatchedFactionByID`, `C_Reputation.ToggleFactionAtWar`, `C_Reputation.ToggleFactionAtWarByID`, `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`, `region:IsMouseOver`, `region:GetRect`, `region:IsDragging`, `GetMouseFoci`, `CreateFrame("Cooldown")`, `cooldown:SetCooldown`, `cooldown:SetReverse`, `cooldown:GetReverse`, `cooldown:SetDrawEdge`, `cooldown:GetDrawEdge`, `frame:SetShown`, `frame:SetClampRectInsets`, `frame:GetClampRectInsets`, `smf:SetHyperlinksEnabled`, `smf:GetHyperlinksEnabled`, `editBox:SetCountInvisibleLetters`, `editBox:IsCountInvisibleLetters`, `fontstring:GetStringHeight`, `fontstring:GetUnboundedStringWidth`, `fontstring:GetWrappedWidth`, `fontstring:GetNumLines`, `fontstring:GetLineHeight`, `fontstring:IsTruncated`, `fontstring:SetMaxLines`, `fontstring:GetMaxLines`, `fontstring:SetFormattedText`, `texture:SetRotation`, `texture:GetRotation`, `texture:SetVertexOffset`, `texture:GetVertexOffset`, `texture:SetColorTexture`, `texture:SetAtlas`, `texture:GetAtlas`, `texture:ResetTexCoord`, `texture:SetSpriteSheetCell`, `texture:SetDesaturation`, `texture:GetDesaturation`, `texture:SetMask`, `frame:CreateMaskTexture`, `texture:AddMaskTexture`, `texture:RemoveMaskTexture`, `texture:GetNumMaskTextures`, `texture:GetMaskTexture`, `fontstring:SetRotation`, `fontstring:GetRotation`, `editBox:SetCursorPosition`, `editBox:GetCursorPosition`, `editBox:GetUTF8CursorPosition`, `editBox:ClearHighlightText`, `editBox:HasFocus`, `editBox:HasText`, `editBox:SetHighlightColor`, `editBox:GetHighlightColor`, `editBox:ClearHistory`, `frame:SetResizeBounds`, `frame:HookScript`, `frame:IsProtected`, `button:SetNormalFontObject`, `button:GetNormalFontObject`, `frame:IsEventRegistered`, `frame:RegisterUnitEvent`, `frame:GetEffectiveAlpha`, `frame:SetAttribute`, `frame:SetAttributeNoHandler`, `frame:ClearAttribute`, `frame:GetAttribute`, `OnAttributeChanged` (script), `SetModernScriptArgs`, `GetModernScriptArgs`, `PreClick` (script), `PostClick` (script), `button:RegisterForClicks("AnyUp"/"AnyDown")`, `GetClickFrame` |
+| [Frame](docs/API.md#frame) | `region:SetPoint("point")` (one-arg form), `region:SetSize`, `region:GetSize`, `region:IsMouseOver`, `region:GetRect`, `region:IsDragging`, `GetMouseFoci`, `CreateFrame` template lists and `id`, `CreateFrame("Cooldown")`, `cooldown:SetCooldown`, `cooldown:SetReverse`, `cooldown:GetReverse`, `cooldown:SetDrawEdge`, `cooldown:GetDrawEdge`, `frame:SetShown`, `frame:SetClampRectInsets`, `frame:GetClampRectInsets`, `smf:SetHyperlinksEnabled`, `smf:GetHyperlinksEnabled`, `editBox:SetCountInvisibleLetters`, `editBox:IsCountInvisibleLetters`, `fontstring:GetStringHeight`, `fontstring:GetUnboundedStringWidth`, `fontstring:GetWrappedWidth`, `fontstring:GetNumLines`, `fontstring:GetLineHeight`, `fontstring:IsTruncated`, `fontstring:SetMaxLines`, `fontstring:GetMaxLines`, `fontstring:SetFormattedText`, `texture:SetRotation`, `texture:GetRotation`, `texture:SetVertexOffset`, `texture:GetVertexOffset`, `texture:SetColorTexture`, `texture:SetAtlas`, `texture:GetAtlas`, `texture:ResetTexCoord`, `texture:SetSpriteSheetCell`, `texture:SetDesaturation`, `texture:GetDesaturation`, `texture:SetMask`, `frame:CreateMaskTexture`, `texture:AddMaskTexture`, `texture:RemoveMaskTexture`, `texture:GetNumMaskTextures`, `texture:GetMaskTexture`, `fontstring:SetRotation`, `fontstring:GetRotation`, `editBox:SetCursorPosition`, `editBox:GetCursorPosition`, `editBox:GetUTF8CursorPosition`, `editBox:ClearHighlightText`, `editBox:HasFocus`, `editBox:HasText`, `editBox:SetHighlightColor`, `editBox:GetHighlightColor`, `editBox:ClearHistory`, `frame:SetResizeBounds`, `frame:HookScript`, `frame:IsProtected`, `button:SetNormalFontObject`, `button:GetNormalFontObject`, `frame:IsEventRegistered`, `frame:RegisterUnitEvent`, `frame:GetEffectiveAlpha`, `frame:SetAttribute`, `frame:SetAttributeNoHandler`, `frame:ClearAttribute`, `frame:GetAttribute`, `OnAttributeChanged` (script), `SetModernScriptArgs`, `GetModernScriptArgs`, `PreClick` (script), `PostClick` (script), `button:RegisterForClicks("AnyUp"/"AnyDown")`, `GetClickFrame` |
| [FriendList](docs/API.md#friendlist) | `C_FriendList.GetFriendInfo`, `C_FriendList.GetFriendInfoByIndex`, `C_FriendList.GetNumFriends`, `C_FriendList.GetNumOnlineFriends`, `C_FriendList.GetNumWhoResults`, `C_FriendList.GetWhoInfo`, `C_FriendList.IsFriend`, `C_FriendList.IsIgnored`, `C_FriendList.IsIgnoredByGuid`, `C_FriendList.IsWhoQueryPending`, `C_FriendList.SendWhoQueryByName`, `C_FriendList.SetFriendNotes`, `C_FriendList.SetFriendNotesByIndex` |
| [GameObject](docs/API.md#gameobject) | `C_GameObjectInfo.GetGameObjectInfoByID`, `C_GameObjectInfo.RequestLoadGameObjectByID`, `ClosestGameObjectPosition` |
| [Glue](docs/API.md#glue) | `C_Glue.IsOnGlueScreen` |
diff --git a/docs/API.md b/docs/API.md
index 6e29ca09..9c9a6ac9 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -235,6 +235,7 @@ build instructions.
- [`region:GetRect()`](#regiongetrect)
- [`region:IsDragging()`](#regionisdragging)
- [`GetMouseFoci()`](#getmousefoci)
+ - [`CreateFrame(frameType [, name, parent, template, id])`](#createframeframetype--name-parent-template-id)
- [`CreateFrame("Cooldown" [, name, parent, template])`](#createframecooldown--name-parent-template)
- [`frame:SetShown(shown)`](#framesetshownshown)
- [A frame moved to a new parent takes its children along](#a-frame-moved-to-a-new-parent-takes-its-children-along)
@@ -841,6 +842,7 @@ build instructions.
- [`C_XMLUtil.GetTemplates()`](#c_xmlutilgettemplates)
- [`C_XMLUtil.GetTemplateInfo(name)`](#c_xmlutilgettemplateinfoname)
- [`C_XMLUtil.DoesTemplateExist(name)`](#c_xmlutildoestemplateexistname)
+ - [`inherits` with more than one template](#inherits-with-more-than-one-template)
- [`parentKey` in XML](#parentkey-in-xml)
- [`function` on XML script handlers](#function-on-xml-script-handlers)
- [`style` on button font elements](#style-on-button-font-elements)
@@ -5715,6 +5717,26 @@ for i = 1, table.getn(foci) do
end
```
+### `CreateFrame(frameType [, name, parent, template, id])`
+
+`template` can be a list of templates. Commas or spaces divide the names.
+The templates apply from left to right, so a later template overrides an
+earlier one. All of the templates apply before the frame's `OnLoad` runs.
+
+```lua
+local b = CreateFrame("Button", nil, UIParent,
+ "UIPanelButtonTemplate, MyButtonTemplate", 3)
+b:GetID() -- 3
+```
+
+Each name in the list must be a template. If one name is not a template,
+`CreateFrame` gives the error
+`CreateFrame(): Couldn't find inherited node ""`.
+
+`id` is a number or a string. It sets the frame ID before `OnLoad` runs.
+As a result, `self:GetID()` in `OnLoad` returns this value. The frame
+ignores a negative `id`.
+
### `CreateFrame("Cooldown" [, name, parent, template])`
Creates a cooldown frame. The frame shows a cooldown sweep.
@@ -20026,6 +20048,25 @@ end
Case-insensitive, resolved through the same registry as `inherits=`.
+### `inherits` with more than one template
+
+A frame element can name a list of templates in `inherits`. Commas or
+spaces divide the names. The templates apply from left to right, so a
+later template overrides an earlier one. The element's own attributes and
+children apply last.
+
+```xml
+
+```
+
+If a name in the list is not a template, `FrameXML.log` gets the line
+`Couldn't find inherited node: `. The other templates still apply.
+
+A frame element without a `parent` attribute gets its parent from the
+templates. The first template in the list that names a parent gives it.
+
+Textures and font strings use only one template.
+
### `parentKey` in XML
`parentKey="Name"` on a frame, texture or font string element sets
diff --git a/src/Offsets.h b/src/Offsets.h
index b2ff6aad..acb396c3 100644
--- a/src/Offsets.h
+++ b/src/Offsets.h
@@ -9545,6 +9545,28 @@ enum Offsets {
OFF_XML_NODE_CHILD = 0x4,
OFF_XML_NODE_SIBLING = 0x1C,
FUN_XML_NODE_GET_ATTRIBUTE = 0x006F2CF0,
+ // Attributes are a flat array of `{char *name, char *value}` pairs at
+ // +0x14, count at +0x10: the getter above scans it with SStrCmpI and
+ // returns the first match's value; the setter replaces that value (or
+ // appends a pair). Both strings are heap copies the destructor frees.
+ OFF_XML_NODE_ATTR_COUNT = 0x10,
+ OFF_XML_NODE_ATTRS = 0x14,
+ XML_NODE_ATTR_STRIDE = 0x8,
+ // `XMLNode *__thiscall(node, XMLNode *parent, const char *tag)` — the
+ // node constructor (copies `tag`); the node is XML_NODE_SIZE bytes.
+ // `void __fastcall(node)` — the destructor (frees tag, attributes, the
+ // child and sibling subtrees). `void __thiscall(node, name, value)`,
+ // ret 8 — the attribute setter (copies both). Script_CreateFrame builds
+ // its request node with exactly these three (0x00706211, 0x0070622D..55,
+ // 0x0070630C).
+ FUN_XML_NODE_CTOR = 0x006F2B10,
+ FUN_XML_NODE_DTOR = 0x006F2B70,
+ FUN_XML_NODE_SET_ATTRIBUTE = 0x006F2D40,
+ XML_NODE_SIZE = 0x20,
+ // `XMLNode *__thiscall(node, const char *tag)` — the first child whose
+ // tag matches (SStrCmpI), or null. The child-frames builder finds
+ // `` with it (0x0076A09E).
+ FUN_XML_NODE_GET_CHILD = 0x006F2C50,
// XMLTree_Load — `XMLTree *__fastcall(const char *data, uint32_t size)`,
// null when the text does not parse; the root node is `*(XMLNode **)tree`.
// XMLTree_Free — `void __fastcall(XMLTree *)`. The bindings loader's own
@@ -9606,6 +9628,23 @@ enum Offsets {
// which runs it before firing OnLoad (+0x118) - so a parent's OnLoad
// sees its children built.
FUN_XML_FRAME_LOAD_CHILD_FRAMES = 0x0076A060,
+ // The frame builder — `CSimpleFrame *__fastcall(node, parent, status)`,
+ // ret 4 (disassembly: ECX = node, EDX = parent saved to [ebp-8]). Looks
+ // the node's tag up in the frame-type factory table, picks the parent,
+ // calls the factory, then pre-load (vtable +0x20), the node loader
+ // (sub-object vtable +8) and finalize (+0x24: child , OnLoad).
+ // Parent: the node's `parent` attribute; with none, it follows the
+ // `inherits` chain (one name per node, FUN_XML_TEMPLATE_LOOKUP) until a
+ // template has one. A non-empty name resolves through
+ // FUN_FRAMESCRIPT_OBJECT_BY_NAME; a miss logs "Couldn't find frame
+ // parent: %s" and builds unparented. No name keeps EDX.
+ FUN_XML_FRAME_BUILD = 0x006EE280,
+ // `CFrameScriptObject *__fastcall(const char *name, int typeId)` —
+ // `_G[name][0]`, kept only when its IsA(typeId) passes. The builder's
+ // parent resolver (0x006EE3E8, EDX = the Frame type id).
+ FUN_FRAMESCRIPT_OBJECT_BY_NAME = 0x0076C760,
+ // The node-loader slot on the layout sub-object's vtable (see above).
+ VTBL_XML_NODE_LOADER = 0x08,
// The Button node loader (same sub-object convention). It calls
// FUN_XML_FRAME_LOAD first, then loads the button's own children: each
// font element into a font object embedded in the button - NormalFont
@@ -9620,19 +9659,20 @@ enum Offsets {
// `CreateFrame(type [, name, parent, template])` — the global FrameScript
// function at table 0x00872E74 slot 3. Standard `int __fastcall(void *L)`
- // shape. Vanilla accepts only a SINGLE template name; the hook in
- // `Frame::CreateFrame` splits comma-separated inherits strings so modern
- // multi-template calls work (e.g. "UIPanelButtonTemplate,
- // SecureActionButtonTemplate"). It builds the frame with the first
- // resolved template through the engine, then applies each remaining
- // template onto the created object with the two steps the builder
- // FUN_006ee280 itself runs for a node: the frame's node loader
- // `(frameObj+0x24)->vtable[+8](templateDefNode, status)` for content
- // (FUN_XML_FRAME_LOAD for a plain Frame, the derived loader otherwise),
- // then FUN_XML_FRAME_LOAD_CHILD_FRAMES for the `` children. Both
- // recurse the template's own `inherits`. The rest of finalize/OnLoad
- // (`vtable[+0x24]`) runs once during the engine build and is NOT re-run.
+ // shape. Checks args 1/3, resolves the parent (rawgeti [0] + IsA Frame),
+ // checks arg 4 as ONE template name, then builds an XMLNode with `name`,
+ // `parent` "" and `inherits` (FUN_XML_NODE_CTOR / _SET_ATTRIBUTE), runs
+ // FUN_XML_FRAME_BUILD(node, parent, status), script-registers the frame
+ // if needed, and pushes its wrapper. Replaced by `Frame::CreateFrame`
+ // with 4.3.4's version (0x0083FB40): list templates and the 5th `id`.
FUN_SCRIPT_CREATEFRAME = 0x007060B0,
+ // Its error strings, and the builder's / frame loader's warnings.
+ STR_CREATEFRAME_UNKNOWN_TYPE = 0x00872FA8, // "CreateFrame: Unknown frame type '%s'"
+ STR_CREATEFRAME_NO_INHERITED = 0x00872FD0, // "CreateFrame(): Couldn't find inherited node \"%s\""
+ STR_CREATEFRAME_WRONG_PARENT = 0x00873004, // "CreateFrame: Wrong parent object type, expected frame"
+ STR_CREATEFRAME_PARENT_NO_THIS = 0x0087303C, // "CreateFrame: Couldn't find 'this' in parent object"
+ STR_XML_NO_INHERITED_NODE = 0x008786A8, // "Couldn't find inherited node: %s"
+ STR_XML_NO_FRAME_PARENT = 0x008710F0, // "Couldn't find frame parent: %s"
// XML-build "status" object — a printf-style error/warning accumulator the
// appliers log through (`status->vtable[+0xc](status, level, fmt, ...)`,
diff --git a/src/frame/CreateFrame.cpp b/src/frame/CreateFrame.cpp
index 920277ad..505c4394 100644
--- a/src/frame/CreateFrame.cpp
+++ b/src/frame/CreateFrame.cpp
@@ -11,58 +11,40 @@
// You should have received a copy of the GNU General Public License along with
// ClassicAPI. If not, see .
-// Multi-template `CreateFrame` support, plus the "Cooldown" frame type.
+// `CreateFrame(frameType [, name] [, parent] [, template] [, id])` — 4.3.4's
+// Script_CreateFrame (0x0083FB40) on vanilla's frame builder.
+//
+// 4.3.4 differs from vanilla's Script_CreateFrame (0x007060B0) in two places:
+// - `template` is a list. Each name, tokenized on " ," as `inherits=` is,
+// must resolve or CreateFrame raises "Couldn't find inherited node"; the
+// whole string then goes on the request node, and the builder reads it
+// as a list (Xml::Inherits — the same path an XML `inherits="A, B"`
+// takes). Vanilla looks the whole string up as one name.
+// - `id` (5th): a string, or a number, set as the node's `id` attribute,
+// which the frame pre-load (0x00769770) stores before OnLoad runs.
+// Vanilla ignores the 5th argument.
+// The id has to be on the request node before the builder runs, and vanilla
+// builds and frees that node inside its own body, so this replaces the
+// function rather than wrapping it: the same steps, in the same order, with
+// the engine's own node constructor, attribute setter, builder, status
+// object and script registration (Offsets FUN_SCRIPT_CREATEFRAME).
//
// Cooldown: 4.3.4 has a native "Cooldown" frame type (CGCooldown) with
// SetCooldown / SetReverse / GetReverse / SetDrawEdge / GetDrawEdge.
// Vanilla draws cooldown sweeps with a Model built from FrameXML's
// CooldownFrameTemplate (the UI-Cooldown-Indicator model, driven by
-// CooldownFrame_SetTimer), and its CreateFrame rejects the type name
+// CooldownFrame_SetTimer), and its frame factory has no "Cooldown"
// ("Unknown frame type 'Cooldown'"). So a "Cooldown" request is built as
-// that Model -- the type becomes "Model", and a missing template defaults
+// that Model -- the node's tag is "Model", and a missing template defaults
// to CooldownFrameTemplate -- and then marked with
// `Frame::Cooldown::Mark`, which gives it 4.3.4's five methods and makes
// it report its type as "Cooldown". See src/frame/Cooldown.cpp.
-//
-// Modern WoW (2.0+) allows a comma-separated template list in CreateFrame's
-// 4th argument:
-//
-// CreateFrame("Button", nil, parent,
-// "UIPanelButtonTemplate, SecureActionButtonTemplate")
-//
-// Vanilla 1.12's `Script_CreateFrame` (0x007060B0) resolves the 4th arg as a
-// SINGLE template name — the whole comma string is one lookup, which fails.
-// 1.12 has no native multi-inheritance: the frame builder `FUN_006ee280`
-// applies exactly one `inherits` name.
-//
-// This hook adds real multi-inheritance by mirroring the engine's OWN inherit
-// mechanism. It:
-// 1. Splits the 4th arg on commas and trims each entry.
-// 2. Resolves each name in the XML template registry, keeping the resolvable
-// ones in list order (typos / not-yet-loaded optional deps are skipped).
-// 3. Builds the frame through the original `Script_CreateFrame` using the
-// FIRST resolved template — the engine does the object creation, that
-// template's full inherit chain, ref/name setup, and OnLoad.
-// 4. Grafts each REMAINING resolved template onto the created frame with the
-// two `__thiscall` steps the builder `FUN_006ee280` runs for a node:
-// content : (frameObj+0x24)->vtable[+8](templateDefNode, status)
-// (FUN_XML_FRAME_LOAD, or the derived type's loader)
-// child : FUN_XML_FRAME_LOAD_CHILD_FRAMES(frameObj, templateDefNode, status)
-// The first adds the template's attributes, regions, backdrop and script
-// handlers; the second creates its child frames, parented to frameObj.
-// Both recurse the grafted template's own `inherits`, exactly as if the
-// frame had inherited it. Later templates override earlier ones, matching
-// modern left-to-right inherit order.
-//
-// OnLoad runs once, during the engine build of the first template (step 3).
-// Secondary templates' `` handlers are registered (they fire on the
-// next relevant event) but not re-run at creation, and the frame's OnLoad is
-// not re-fired. `status` is the engine's XML-build error accumulator, built
-// and reset exactly as `Script_CreateFrame` does.
#include "Game.h"
#include "Offsets.h"
#include "frame/Cooldown.h"
+#include "xml/FrameLoad.h"
+#include "xml/Inherits.h"
#include
#include
@@ -72,51 +54,36 @@ namespace Frame::CreateFrame {
namespace {
using ScriptFn_t = int(__fastcall *)(void *L);
-using TemplateLookup_t = const uint8_t *(__fastcall *)(const char *name);
-
-// Applies `node` (and its `inherits` chain) to `self`:
-// __thiscall(self /*ecx*/, node, status). Both the frame's node loader (its
-// sub-object's vtable +8) and FUN_XML_FRAME_LOAD_CHILD_FRAMES have this shape.
-using ApplyNodeFn = void(__thiscall *)(void *self, const void *node, void *status);
-
-// Empties / re-initializes the XML-build status object. __thiscall(this).
+using NodeCtor_t = void *(__thiscall *)(void *node, void *parent, const char *tag);
+using NodeDtor_t = void(__fastcall *)(void *node);
+using SetAttr_t = void(__thiscall *)(void *node, const char *name, const char *value);
+using Build_t = void *(__fastcall *)(const void *node, void *parent, void *status);
using StatusReset_t = void(__thiscall *)(void *self);
-// The original Script_CreateFrame function, populated by MinHook.
+// LUA_TNONE: lua_type of an index past the top.
+constexpr int kTypeNone = -1;
+
+// 4.3.4's usage line; vanilla's (0x00872F60) has no `id`.
+constexpr const char *kUsage =
+ "Usage: CreateFrame(\"frameType\" [, \"name\"] [, parent] [, \"template\"] [, id])";
+
+// Kept only because HookAutoRegister needs a trampoline slot; the
+// replacement never calls it.
ScriptFn_t g_origCreateFrame = nullptr;
-// ---- helpers ---------------------------------------------------------------
-
-// Returns the definition node if `name` resolves in the engine's XML template
-// registry, else nullptr.
-const uint8_t *LookupTemplate(const char *name) {
- return reinterpret_cast(
- static_cast(Offsets::FUN_XML_TEMPLATE_LOOKUP))(name);
+const char *EngineString(uintptr_t address) {
+ return reinterpret_cast(address);
}
-// The builder FUN_006ee280's sequence per node (from 0x006ee4ca):
-// MOV EDX,[EDI] CALL [EDX+0x20] ; pre-load (name, id)
-// MOV EAX,[EDI+0x24] LEA ECX,[EDI+0x24] CALL [EAX+0x8] ; node loader (content)
-// MOV EDX,[EDI] CALL [EDX+0x24] ; finalize: child , OnLoad
-// The node loader is the vmethod at vtable +8 of the sub-object at
-// OFF_XML_LOADER_SUBOBJECT; its `inherits` recursion calls the same slot.
-// Finalize (FUN_0076a2f0) builds the children through
-// FUN_XML_FRAME_LOAD_CHILD_FRAMES before firing OnLoad; the graft calls that
-// directly so OnLoad is not re-run. (The MAIN vtable's +8 is the Lua method
-// lookup FUN_00778590, not a node applier.)
-constexpr int kNodeLoaderVtableSlot = 2; // byte offset +8 / sizeof(void*)
-
// The XML-build status object: the 5-dword error accumulator Script_CreateFrame
-// stack-builds ({vtable, 8, &self+8, (&self+8)|1, 0}). The appliers only ever
-// call its vtable[+0xc] (a __cdecl printf-style logger); building the engine's
-// real one absorbs any sub-node warning exactly as the engine does and is safe
-// against every slot.
+// stack-builds ({vtable, 8, &self+8, (&self+8)|1, 0}, 0x0070625A..77) and
+// resets with FUN_FRAMESCRIPT_STATUS_RESET.
struct BuildStatus {
const void *vtable;
- int kind;
- void *head;
- uintptr_t tail;
- int count;
+ int kind;
+ void *head;
+ uintptr_t tail;
+ int count;
};
void InitStatus(BuildStatus *s) {
@@ -133,173 +100,83 @@ void ResetStatus(BuildStatus *s) {
static_cast(Offsets::FUN_FRAMESCRIPT_STATUS_RESET))(s);
}
-// Grafts template definition `node` onto the already-created frame `frameObj`,
-// applying its content and its child the same way the engine applies
-// an inherited node.
-void ApplyTemplateNode(void *frameObj, const void *node, void *status) {
- void *loader = reinterpret_cast(frameObj) + Offsets::OFF_XML_LOADER_SUBOBJECT;
- void **loaderVtbl = *reinterpret_cast(loader);
- reinterpret_cast(loaderVtbl[kNodeLoaderVtableSlot])(loader, node, status);
-
- reinterpret_cast(
- static_cast(Offsets::FUN_XML_FRAME_LOAD_CHILD_FRAMES))(frameObj, node, status);
-}
-
-// Maximum templates in a single comma-separated list.
-constexpr int kMaxTemplates = 8;
-
-// Splits `input` on commas into `out[]`, writing NUL terminators into the
-// mutable buffer `buf`. Each entry is whitespace-trimmed. Returns the count.
-int SplitTemplates(char *buf, size_t bufLen, const char *input,
- const char *out[kMaxTemplates]) {
- size_t len = std::strlen(input);
- if (len >= bufLen) len = bufLen - 1;
- std::memcpy(buf, input, len);
- buf[len] = '\0';
-
- int count = 0;
- char *p = buf;
- while (*p && count < kMaxTemplates) {
- while (*p == ' ' || *p == '\t') ++p;
- if (*p == '\0') break;
-
- char *start = p;
- while (*p && *p != ',') ++p;
-
- // Note whether we stopped on a comma BEFORE writing the terminator:
- // when there is no trailing whitespace, `end` lands on the comma
- // itself, so `*end = '\0'` would clobber it and the advance below
- // would then miss it — dropping every entry after the first.
- const bool atComma = (*p == ',');
-
- char *end = p;
- while (end > start && (*(end - 1) == ' ' || *(end - 1) == '\t'))
- --end;
- *end = '\0';
-
- if (*start != '\0')
- out[count++] = start;
-
- if (atComma) ++p;
- }
- return count;
-}
-
-// ---- the hook --------------------------------------------------------------
-
-// Case-insensitive, like the engine's own frame-type lookup.
-bool IsCooldownType(void *L) {
- if (!Game::Lua::IsString(L, 1))
- return false;
- const char *type = Game::Lua::ToString(L, 1);
- return type != nullptr && _stricmp(type, "Cooldown") == 0;
-}
-
-// Rewrites a "Cooldown" request in place as vanilla's cooldown Model.
-void RemapCooldown(void *L) {
- Game::Lua::PushString(L, "Model");
- Game::Lua::Insert(L, 1);
- Game::Lua::Remove(L, 2); // drop the original "Cooldown"
- if (Game::Lua::GetTop(L) < 4 || !Game::Lua::IsString(L, 4) ||
- *Game::Lua::ToString(L, 4) == '\0') {
- while (Game::Lua::GetTop(L) < 3)
- Game::Lua::PushNil(L);
- Game::Lua::SetTop(L, 3);
- Game::Lua::PushString(L, "CooldownFrameTemplate");
- }
-}
-
-// Marks the frame a successful Cooldown build left on top of the stack.
-int FinishCreate(void *L, int rc, bool isCooldown) {
- if (isCooldown && rc == 1) {
- void *frameObj = Game::Lua::ResolveObject(L, Game::Lua::GetTop(L));
- if (frameObj != nullptr)
- Frame::Cooldown::Mark(frameObj);
- }
- return rc;
+void SetAttr(void *node, const char *name, const char *value) {
+ reinterpret_cast(Offsets::FUN_XML_NODE_SET_ATTRIBUTE)(node, name, value);
}
int __fastcall CreateFrame_h(void *L) {
- const bool isCooldown = IsCooldownType(L);
- if (isCooldown)
- RemapCooldown(L);
+ using namespace Game::Lua;
- // No 4th arg or not a string → pass through.
- if (Game::Lua::GetTop(L) < 4 || !Game::Lua::IsString(L, 4))
- return FinishCreate(L, g_origCreateFrame(L), isCooldown);
+ const int parentType = Type(L, 3);
+ if (!IsString(L, 1) ||
+ (parentType != kTypeNone && parentType != TYPE_NIL && parentType != TYPE_TABLE)) {
+ Error(L, kUsage);
+ return 0;
+ }
+ const char *frameType = ToString(L, 1);
+ const char *name = ToString(L, 2);
+ const char *inherits = ToString(L, 4);
- const char *inherits = Game::Lua::ToString(L, 4);
- if (inherits == nullptr || *inherits == '\0')
- return FinishCreate(L, g_origCreateFrame(L), isCooldown);
-
- // Fast path: no comma → single template, engine handles it natively.
- if (std::strchr(inherits, ',') == nullptr)
- return FinishCreate(L, g_origCreateFrame(L), isCooldown);
-
- // ---- comma-delimited: split, resolve, combine --------------------------
-
- char buf[1024];
- const char *names[kMaxTemplates];
- const int count = SplitTemplates(buf, sizeof buf, inherits, names);
- if (count == 0)
- return FinishCreate(L, g_origCreateFrame(L), isCooldown);
-
- // Resolve each token; keep the resolvable definition nodes in list order.
- const char *resolvedNames[kMaxTemplates];
- const void *resolvedNodes[kMaxTemplates];
- int resolved = 0;
- for (int i = 0; i < count; ++i) {
- const uint8_t *node = LookupTemplate(names[i]);
- if (node != nullptr) {
- resolvedNames[resolved] = names[i];
- resolvedNodes[resolved] = node;
- ++resolved;
+ void *parent = nullptr;
+ if (parentType == TYPE_TABLE) {
+ parent = ResolveObject(L, 3);
+ if (parent == nullptr) {
+ Error(L, EngineString(Offsets::STR_CREATEFRAME_PARENT_NO_THIS));
+ return 0;
+ }
+ if (!IsA(parent, Offsets::VAR_FRAME_LUA_TYPE_ID)) {
+ Error(L, EngineString(Offsets::STR_CREATEFRAME_WRONG_PARENT));
+ return 0;
}
}
- // 0 or 1 resolvable: nothing to combine. Hand the engine a single name —
- // the first resolved one, or (if none resolved) the first token so the
- // engine emits its normal "couldn't find inherited node" error rather than
- // silently building a template-less frame.
- if (resolved <= 1) {
- Game::Lua::SetTop(L, 3);
- Game::Lua::PushString(L, resolved == 1 ? resolvedNames[0] : names[0]);
- return FinishCreate(L, g_origCreateFrame(L), isCooldown);
+ if (Type(L, 4) == TYPE_STRING) {
+ char missing[Xml::Inherits::kTokenSize] = {};
+ Xml::Inherits::ForEach(inherits, [&](const char *t) {
+ if (missing[0] == '\0' && Xml::Template(t) == nullptr)
+ strcpy_s(missing, t);
+ });
+ if (missing[0] != '\0') {
+ Error(L, EngineString(Offsets::STR_CREATEFRAME_NO_INHERITED), missing);
+ return 0;
+ }
}
- // Build with the first resolved template through the engine (object
- // creation + its full inherit chain + ref/name setup + OnLoad).
- Game::Lua::SetTop(L, 3);
- Game::Lua::PushString(L, resolvedNames[0]);
- const int rc = g_origCreateFrame(L);
- if (rc != 1)
- return rc; // creation failed (e.g. unknown frame type) — leave as-is.
+ const bool isCooldown = _stricmp(frameType, "Cooldown") == 0;
+ if (isCooldown && (inherits == nullptr || *inherits == '\0'))
+ inherits = "CooldownFrameTemplate";
+ const char *id = IsString(L, 5) ? ToString(L, 5) : nullptr;
- // Recover the created frame object (top of stack) and graft the remaining
- // templates onto it with the engine's own inherit primitive. Snapshot the
- // stack the engine left (frame at `savedTop`) and restore it afterward, so
- // anything a grafted template's appliers touch on the Lua stack (a child
- // frame's OnLoad, `$parent` name resolution) can't shift the return value
- // the caller reads back — the Tooltip::SetEvents save/restore discipline,
- // which matters in this hook-saturated environment.
- const int savedTop = Game::Lua::GetTop(L);
- void *frameObj = Game::Lua::ResolveObject(L, savedTop);
- if (isCooldown && frameObj != nullptr)
- Frame::Cooldown::Mark(frameObj);
- if (frameObj != nullptr) {
- BuildStatus status;
- InitStatus(&status);
- for (int i = 1; i < resolved; ++i)
- ApplyTemplateNode(frameObj, resolvedNodes[i], &status);
- ResetStatus(&status);
- Game::Lua::SetTop(L, savedTop);
+ alignas(4) uint8_t node[Offsets::XML_NODE_SIZE];
+ reinterpret_cast(Offsets::FUN_XML_NODE_CTOR)(node, nullptr,
+ isCooldown ? "Model" : frameType);
+ if (name != nullptr)
+ SetAttr(node, "name", name);
+ if (parent != nullptr)
+ SetAttr(node, "parent", "");
+ if (inherits != nullptr)
+ SetAttr(node, "inherits", inherits);
+ if (id != nullptr)
+ SetAttr(node, "id", id);
+
+ BuildStatus status;
+ InitStatus(&status);
+ void *frame = reinterpret_cast(Offsets::FUN_XML_FRAME_BUILD)(node, parent, &status);
+ if (frame != nullptr) {
+ PushObject(L, frame);
+ if (isCooldown)
+ Frame::Cooldown::Mark(frame);
}
+ ResetStatus(&status);
+ reinterpret_cast(Offsets::FUN_XML_NODE_DTOR)(node);
- return rc;
+ if (frame == nullptr) {
+ Error(L, EngineString(Offsets::STR_CREATEFRAME_UNKNOWN_TYPE), frameType);
+ return 0;
+ }
+ return 1;
}
-// ---- registration ----------------------------------------------------------
-
const Game::HookAutoRegister _createFrameHook{
Offsets::FUN_SCRIPT_CREATEFRAME,
reinterpret_cast(&CreateFrame_h),
diff --git a/src/xml/FrameLoad.cpp b/src/xml/FrameLoad.cpp
index 17b54db7..3fc72c58 100644
--- a/src/xml/FrameLoad.cpp
+++ b/src/xml/FrameLoad.cpp
@@ -14,6 +14,7 @@
#include "xml/FrameLoad.h"
#include "Game.h"
+#include "xml/Inherits.h"
#include "Offsets.h"
#include
@@ -23,6 +24,7 @@ namespace Xml {
namespace {
using GetAttr_t = const char *(__thiscall *)(const void *node, const char *name);
+using TemplateLookup_t = const void *(__fastcall *)(const char *name);
using SStrCmpI_t = int(__stdcall *)(const char *a, const char *b, int n);
using StatusAdd_t = void(__cdecl *)(void *status, int level, const char *fmt, ...);
@@ -50,6 +52,10 @@ const char *Attr(const void *node, const char *name) {
return reinterpret_cast(Offsets::FUN_XML_NODE_GET_ATTRIBUTE)(node, name);
}
+const void *Template(const char *name) {
+ return reinterpret_cast(Offsets::FUN_XML_TEMPLATE_LOOKUP)(name);
+}
+
void Warn(void *status, const char *fmt, const char *a, const char *b) {
if (status == nullptr)
return;
@@ -94,7 +100,7 @@ Loader_t g_orig = nullptr;
// `__thiscall` modelled as `__fastcall` with a dummy edx.
uintptr_t __fastcall Hook(void *self, void *edx, const void *node, void *status) {
- const uintptr_t r = g_orig(self, edx, node, status);
+ const uintptr_t r = Inherits::LoadFrame(g_orig, self, edx, node, status);
if (self != nullptr && node != nullptr) {
void *object = static_cast(self) - Offsets::OFF_XML_LOADER_SUBOBJECT;
for (AutoSubscribe *s = g_head; s != nullptr; s = s->next)
diff --git a/src/xml/FrameLoad.h b/src/xml/FrameLoad.h
index f69fd2e1..85127db9 100644
--- a/src/xml/FrameLoad.h
+++ b/src/xml/FrameLoad.h
@@ -24,7 +24,8 @@
// `Frame::Attributes`' ``), so — like `Frame::RunnerHook` and
// `Tick::WorldTick` — this module owns the hook and fans out. Subscribers run
// after the engine has loaded the node, in static-init order, which must not
-// matter. Declare a file-scope
+// matter. The hook also runs the loader through `Xml::Inherits::LoadFrame`,
+// which reads `inherits` as a list. Declare a file-scope
// static const Xml::FrameLoad::AutoSubscribe _sub{&OnFrameNode};
namespace Xml {
@@ -36,6 +37,9 @@ const char *Tag(const void *node);
bool TagIs(const void *node, const char *tag); // case-insensitive, like the engine's
// The engine's attribute getter; nullptr when the attribute is absent.
const char *Attr(const void *node, const char *name);
+// The template definition node `inherits=` resolves `name` to
+// (FUN_XML_TEMPLATE_LOOKUP); nullptr when no template has that name.
+const void *Template(const char *name);
// The engine's load-status sink: `status->Add(STATUS_WARNING, fmt, ...)`,
// the same warning the loaders log ("Couldn't find inherited node: %s").
diff --git a/src/xml/Inherits.cpp b/src/xml/Inherits.cpp
new file mode 100644
index 00000000..e965564b
--- /dev/null
+++ b/src/xml/Inherits.cpp
@@ -0,0 +1,215 @@
+// 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 .
+
+// `inherits="A, B"` on XML frames and in CreateFrame's template argument.
+//
+// 4.3.4 reads `inherits` as a list: CSimpleFrame::LoadXML (0x00506BA0)
+// tokenizes it with SStrTokenize on " ," and loads each named template, in
+// order, through the frame's own virtual LoadXML before the node's own
+// content, so later templates override earlier ones; FindParent (0x004ECD80)
+// walks the same list for a `parent`. Vanilla has the same three steps, each
+// resolving the whole string as ONE name through FUN_XML_TEMPLATE_LOOKUP, so
+// a list is "Couldn't find inherited node":
+//
+// content FUN_XML_FRAME_LOAD (0x00769820) — inherits first, through the
+// object's node loader `(*self)->vtable[+8]` (the derived type's
+// loader, which calls this one first), then the node's attributes,
+// Layers, Scripts, ...
+// children FUN_XML_FRAME_LOAD_CHILD_FRAMES (0x0076A060) — recurses the
+// inherited node, then builds each of the node's
+// parent FUN_XML_FRAME_BUILD (0x006EE280) — `parent`, else the inherits
+// chain until a template has one
+//
+// Each step is extended the same way: names in list order through the
+// engine's own step, then the node itself. A single name (no separator)
+// takes the engine's path untouched.
+//
+// content each name through `(*self)->vtable[+8]`, a missing one logged
+// with the loader's own warning; then the original loader with
+// the node's `inherits` value swapped to "" for the call, so it
+// loads only the node's own content. No Lua runs inside the
+// content loader (child frames and OnLoad come later, from the
+// builder's finalize), so nothing can observe the swap.
+// children each name through this hook (so a template's own list
+// recurses), then the node's through the builder, as the
+// engine's loop does (0x0076A097..BF). The loop is called
+// directly instead of swapping `inherits`, because each child's
+// OnLoad runs Lua inside it, and a CreateFrame there with this
+// template must still see the whole list.
+// parent 4.3.4's FindParent: the first name, in list order, whose chain
+// has a `parent`. When the walk met a list, the hook resolves the
+// name exactly as the builder does and passes the frame in EDX;
+// the builder's own walk stops at the same list (its lookup of
+// the whole string finds nothing) and keeps EDX.
+//
+// Textures and font strings keep one template, as in 4.3.4.
+
+#include "xml/Inherits.h"
+
+#include "Game.h"
+#include "Offsets.h"
+#include "xml/FrameLoad.h"
+
+#include
+
+namespace Xml::Inherits {
+
+namespace {
+
+using Tokenize_t = void(__stdcall *)(const char **cursor, char *out, unsigned outSize,
+ const char *delims, int *outQuoted);
+using NodeLoader_t = uintptr_t(__thiscall *)(void *self, const void *node, void *status);
+using ChildFrames_t = void(__fastcall *)(void *frame, void *edx, const void *node, void *status);
+using Build_t = void *(__fastcall *)(const void *node, void *parent, void *status);
+using GetChild_t = const void *(__thiscall *)(const void *node, const char *tag);
+using ObjectByName_t = void *(__fastcall *)(const char *name, int typeId);
+using SStrCmpI_t = int(__stdcall *)(const char *a, const char *b, int n);
+
+constexpr const char *kSeparators = " ,";
+
+ChildFrames_t g_origChildFrames = nullptr;
+Build_t g_origBuild = nullptr;
+
+// Loads `node` (with its own `inherits`) onto the object whose layout
+// sub-object is `self`, the call the frame loader makes for an inherited node.
+void ApplyNode(void *self, const void *node, void *status) {
+ const void *vtable = Game::Read(self, 0);
+ Game::Read(vtable, Offsets::VTBL_XML_NODE_LOADER)(self, node, status);
+}
+
+// The node's first `inherits` value swapped to "" for the guard's lifetime —
+// the pair the attribute getter returns, compared the way it compares.
+class SuppressInherits {
+public:
+ explicit SuppressInherits(const void *node) {
+ const int count = Game::Read(node, Offsets::OFF_XML_NODE_ATTR_COUNT);
+ auto *attrs = Game::Read(node, Offsets::OFF_XML_NODE_ATTRS);
+ auto cmp = reinterpret_cast(Offsets::FUN_SSTR_CMP_I);
+ for (int i = 0; i < count; ++i) {
+ uint8_t *pair = attrs + i * Offsets::XML_NODE_ATTR_STRIDE;
+ if (cmp(*reinterpret_cast(pair), "inherits", 0x7FFFFFFF) == 0) {
+ m_value = reinterpret_cast(pair + sizeof(const char *));
+ m_saved = *m_value;
+ *m_value = "";
+ return;
+ }
+ }
+ }
+ ~SuppressInherits() {
+ if (m_value != nullptr)
+ *m_value = m_saved;
+ }
+ SuppressInherits(const SuppressInherits &) = delete;
+ SuppressInherits &operator=(const SuppressInherits &) = delete;
+
+private:
+ const char **m_value = nullptr;
+ const char *m_saved = nullptr;
+};
+
+// ---- children --------------------------------------------------------------
+
+void __fastcall ChildFrames_h(void *frame, void *edx, const void *node, void *status) {
+ const char *inherits = node != nullptr ? Attr(node, "inherits") : nullptr;
+ if (inherits == nullptr || !IsList(inherits)) {
+ g_origChildFrames(frame, edx, node, status);
+ return;
+ }
+ ForEach(inherits, [&](const char *name) {
+ if (const void *t = Template(name))
+ ChildFrames_h(frame, edx, t, status);
+ });
+ const void *frames = reinterpret_cast(Offsets::FUN_XML_NODE_GET_CHILD)(node, "Frames");
+ if (frames == nullptr)
+ return;
+ auto build = reinterpret_cast(Offsets::FUN_XML_FRAME_BUILD);
+ for (const void *c = FirstChild(frames); c != nullptr; c = NextSibling(c))
+ build(c, frame, status);
+}
+
+// ---- parent ----------------------------------------------------------------
+
+// 4.3.4's FindParent: the node's `parent` (even ""), else the first name in
+// `inherits`, in list order, whose chain has one. Sets `*sawList` when the
+// walk met a list, where vanilla's single-name walk stops.
+const char *FindParent(const void *node, bool *sawList) {
+ if (const char *parent = Attr(node, "parent"))
+ return parent;
+ const char *inherits = Attr(node, "inherits");
+ if (inherits == nullptr || *inherits == '\0')
+ return nullptr;
+ if (!IsList(inherits)) {
+ const void *t = Template(inherits);
+ return t != nullptr ? FindParent(t, sawList) : nullptr;
+ }
+ *sawList = true;
+ const char *found = nullptr;
+ ForEach(inherits, [&](const char *name) {
+ if (found != nullptr)
+ return;
+ if (const void *t = Template(name))
+ found = FindParent(t, sawList);
+ });
+ return found;
+}
+
+void *__fastcall Build_h(const void *node, void *parent, void *status) {
+ if (node != nullptr && Attr(node, "parent") == nullptr) {
+ bool sawList = false;
+ const char *name = FindParent(node, &sawList);
+ if (sawList && name != nullptr && *name != '\0') {
+ parent = reinterpret_cast(Offsets::FUN_FRAMESCRIPT_OBJECT_BY_NAME)(
+ name, Game::Lua::FrameScriptTypeId(Offsets::VAR_FRAME_LUA_TYPE_ID));
+ if (parent == nullptr)
+ Warn(status, reinterpret_cast(Offsets::STR_XML_NO_FRAME_PARENT), name);
+ }
+ }
+ return g_origBuild(node, parent, status);
+}
+
+const Game::HookAutoRegister _childFramesHook{
+ Offsets::FUN_XML_FRAME_LOAD_CHILD_FRAMES, reinterpret_cast(&ChildFrames_h),
+ reinterpret_cast(&g_origChildFrames)};
+
+const Game::HookAutoRegister _buildHook{
+ Offsets::FUN_XML_FRAME_BUILD, reinterpret_cast(&Build_h),
+ reinterpret_cast(&g_origBuild)};
+
+} // namespace
+
+bool IsList(const char *inherits) {
+ return std::strpbrk(inherits, kSeparators) != nullptr;
+}
+
+void NextName(const char **cursor, char *out) {
+ reinterpret_cast(Offsets::FUN_STORM_STR_TOKENIZE)(cursor, out, kTokenSize,
+ kSeparators, nullptr);
+}
+
+// ---- content ---------------------------------------------------------------
+
+uintptr_t LoadFrame(Loader original, void *self, void *edx, const void *node, void *status) {
+ const char *inherits = node != nullptr ? Attr(node, "inherits") : nullptr;
+ if (inherits == nullptr || !IsList(inherits))
+ return original(self, edx, node, status);
+ ForEach(inherits, [&](const char *name) {
+ if (const void *t = Template(name))
+ ApplyNode(self, t, status);
+ else
+ Warn(status, reinterpret_cast(Offsets::STR_XML_NO_INHERITED_NODE), name);
+ });
+ SuppressInherits suppress(node);
+ return original(self, edx, node, status);
+}
+
+} // namespace Xml::Inherits
diff --git a/src/xml/Inherits.h b/src/xml/Inherits.h
new file mode 100644
index 00000000..a32d57c1
--- /dev/null
+++ b/src/xml/Inherits.h
@@ -0,0 +1,53 @@
+// 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 .
+
+#pragma once
+
+// `inherits="A, B"` — a list of templates on one frame, as 4.3.4 reads it.
+// See Inherits.cpp for the engine steps this extends.
+
+#include
+
+namespace Xml::Inherits {
+
+// 4.3.4 tokenizes `inherits` with SStrTokenize on " ," into a 1024-byte
+// buffer (CSimpleFrame::LoadXML, FindParent, Script_CreateFrame).
+constexpr unsigned kTokenSize = 1024;
+
+// True when `inherits` holds a separator, i.e. vanilla's whole-string
+// lookup would not find it but 4.3.4's tokenizer reads names out of it.
+bool IsList(const char *inherits);
+
+// Copies the next name at `*cursor` into `out` (empty at the end) and
+// advances the cursor — the engine's own Storm tokenizer.
+void NextName(const char **cursor, char *out);
+
+// Calls `fn(name)` for each name in list order.
+template
+void ForEach(const char *inherits, Fn &&fn) {
+ char name[kTokenSize];
+ const char *cursor = inherits;
+ while (cursor != nullptr && *cursor != '\0') {
+ NextName(&cursor, name);
+ if (name[0] == '\0')
+ break;
+ fn(static_cast(name));
+ }
+}
+
+// The frame node loader FUN_XML_FRAME_LOAD with list support. `Xml::FrameLoad`
+// owns that hook and routes the engine's loader through here.
+using Loader = uintptr_t(__fastcall *)(void *self, void *edx, const void *node, void *status);
+uintptr_t LoadFrame(Loader original, void *self, void *edx, const void *node, void *status);
+
+} // namespace Xml::Inherits