From e2174e16567dec206c836a31f3cbd369dd970151 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 7 Nov 2026 10:35:51 -0600 Subject: [PATCH] refactor(frame): one wrapper for the layout sub-object's calls Every region and frame carries a layout sub-object at +0x24 (4.3.4's CLayoutFrame; OFF_REGION_ANCHOR, OFF_FRAME_LAYOUT_SUBOBJECT for a frame), and three engine calls on it were wrapped by hand in sixteen files, each with its own typedef and often its own AnchorOf / LayoutOf / FrameOf helper: - CLayoutFrame::GetRect (FUN_REGION_GET_RECT, 0x00768320), the {bottom, left, top, right} rect, false before layout; - IsResizePending (FUN_REGION_LAYOUT_DIRTY, 0x00768310); - CLayoutFrame::Resize (FUN_LAYOUT_RESIZE, 0x007680E0), 1 to lay out now, 0 to mark for the layout pass. frame/Layout.h now holds them, taking the region or frame itself, with Of and OwnerOf for the sub-object and back, and GetResolvedRect for the read the edge getters make (Script GetLeft 0x007A1A19: a pending resize run now, then the rect). Frame::Subclass::FrameOfLayout is replaced by OwnerOf. --- src/editbox/IconRows.cpp | 15 +++-- src/fontstring/Layout.cpp | 7 +-- src/frame/AlphaGradient.cpp | 5 +- src/frame/BoundsRect.cpp | 15 ++--- src/frame/ClampRectInsets.cpp | 8 +-- src/frame/Cooldown.cpp | 11 ++-- src/frame/Layout.h | 70 ++++++++++++++++++++++++ src/frame/Modern.cpp | 11 +--- src/frame/Points.cpp | 10 +--- src/frame/Subclass.h | 8 +-- src/model/Scene.cpp | 15 ++--- src/scrollingmessageframe/InsertMode.cpp | 14 ++--- src/texture/Mask.cpp | 29 ++-------- src/texture/Tile.cpp | 5 +- src/texture/Transform.cpp | 10 +--- src/tooltip/FrameStack.cpp | 5 +- src/xml/PostLoad.cpp | 8 +-- 17 files changed, 129 insertions(+), 117 deletions(-) create mode 100644 src/frame/Layout.h diff --git a/src/editbox/IconRows.cpp b/src/editbox/IconRows.cpp index 0a146e93..3991b15b 100644 --- a/src/editbox/IconRows.cpp +++ b/src/editbox/IconRows.cpp @@ -45,6 +45,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/Layout.h" #include "text/InlineTexture.h" #include @@ -59,11 +60,9 @@ using IndexAtPoint_t = void(__fastcall *)(void *editBox, void *edx, float x, flo using FontHeight_t = float(__fastcall *)(void *fs, void *edx, int mode); using MeasureRun_t = float(__fastcall *)(void *fs, void *edx, const uint8_t *text, int len); using PixelAlignY_t = float(__stdcall *)(float length); -using GetRect_t = int(__fastcall *)(void *anchor, void *edx, float *out); using ClearAllPoints_t = void(__fastcall *)(void *anchor); using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, float x, float y, int flag); -using Resize_t = void(__fastcall *)(void *anchor, void *edx, int force); using Extent_t = float(__fastcall *)(void *anchor, void *edx); using FireVariadic_t = void(__cdecl *)(void *frame, uint32_t *slotPtr, const char *fmt, ...); @@ -71,7 +70,7 @@ PlaceCaret_t g_origPlaceCaret = nullptr; PlaceSelectionPiece_t g_origPlaceSelectionPiece = nullptr; IndexAtPoint_t g_origIndexAtPoint = nullptr; -void *AnchorOf(void *region) { return static_cast(region) + Offsets::OFF_REGION_ANCHOR; } +using Frame::Layout::Of; // A multi-line box's rows: its label, the buffer the line table indexes (the // '*' copy of a password box) and the table — each line's first byte, the @@ -177,9 +176,9 @@ bool AnchorX(const Rows &rows, int line, uint32_t pos, float &x, int &relPoint) // Anchors `region` as the placer did, at `y`. void Anchor(const Rows &rows, void *region, int relPoint, float x, float y, int flag) { - void *anchor = AnchorOf(region); + void *anchor = Of(region); reinterpret_cast(Offsets::FUN_LAYOUT_CLEAR_ALL_POINTS)(anchor); - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)(anchor, Offsets::FRAMEPOINT_TOPLEFT, AnchorOf(rows.fs), + reinterpret_cast(Offsets::FUN_REGION_SET_POINT)(anchor, Offsets::FRAMEPOINT_TOPLEFT, Of(rows.fs), relPoint, x, y, flag); } @@ -190,7 +189,7 @@ void __fastcall IndexAtPoint_h(void *editBox, void *edx, float x, float y, int * if (!MultiLineRows(editBox, rows)) return g_origIndexAtPoint(editBox, edx, x, y, index); float rect[4] = {0.0f, 0.0f, 0.0f, 0.0f}; // bottom, left, top, right - if (reinterpret_cast(Offsets::FUN_REGION_GET_RECT)(AnchorOf(rows.fs), nullptr, rect) == 0) + if (!Frame::Layout::GetRect(rows.fs, rect)) return g_origIndexAtPoint(editBox, edx, x, y, index); // The engine walks rows down from the label's top while the click is // below the row (strictly), stopping at the last line. Walk the rows as @@ -238,7 +237,7 @@ void __fastcall PlaceSelectionPiece_h(void *editBox, void *edx, void *piece, int return; const float y = -(RowHeight(rows) / rows.scale) * static_cast(line) - shift; Anchor(rows, piece, relPoint, x, y, 0); - reinterpret_cast(Offsets::FUN_LAYOUT_RESIZE)(AnchorOf(piece), nullptr, 1); + Frame::Layout::Resize(piece, true); } // --- the caret ---------------------------------------------------------------- @@ -274,7 +273,7 @@ void __fastcall PlaceCaret_h(void *editBox) { return; // OnCursorChanged(x, y, width, height) as the engine fires it: each // value by the anchor→script factor, pushed as a double. - void *anchor = AnchorOf(caret); + void *anchor = Of(caret); void **vtable = *static_cast(anchor); const float width = reinterpret_cast(vtable[7])(anchor, nullptr); // +0x1C GetWidth const float height = reinterpret_cast(vtable[8])(anchor, nullptr); // +0x20 GetHeight diff --git a/src/fontstring/Layout.cpp b/src/fontstring/Layout.cpp index dd83edfd..028015f8 100644 --- a/src/fontstring/Layout.cpp +++ b/src/fontstring/Layout.cpp @@ -15,6 +15,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/Layout.h" #include @@ -24,9 +25,6 @@ namespace { // FUN_HANDLE_RELEASE — DecRef a ref-counted handle. __fastcall(handle). using HandleRelease_t = void(__fastcall *)(void *handle); -// FUN_LAYOUT_RESIZE — region layout resize (0 = invalidate). __thiscall(region, -// int); dummy-EDX form. -using LayoutInvalidate_t = void(__fastcall *)(void *region, void *edx, int arg); } // namespace @@ -39,8 +37,7 @@ void Invalidate(void *fs) { Game::Ref(fs, Offsets::OFF_FONTSTRING_TEXT_BLOCK) = nullptr; } Game::Ref(fs, Offsets::OFF_FONTSTRING_DIRTY_FLAGS) &= ~1u; - void *region = reinterpret_cast(reinterpret_cast(fs) + 0x24); - reinterpret_cast(Offsets::FUN_LAYOUT_RESIZE)(region, nullptr, 0); + Frame::Layout::Resize(fs, false); } } // namespace FontString::Layout diff --git a/src/frame/AlphaGradient.cpp b/src/frame/AlphaGradient.cpp index 2226fabd..14dbfa4a 100644 --- a/src/frame/AlphaGradient.cpp +++ b/src/frame/AlphaGradient.cpp @@ -54,6 +54,7 @@ #include "Offsets.h" #include "frame/ClipChildren.h" #include "frame/Destruction.h" +#include "frame/Layout.h" #include "gx/Device.h" #include "texture/Load.h" @@ -67,7 +68,6 @@ namespace { using SetProjection_t = void(__fastcall *)(const float *m); using SetViewport_t = void(__stdcall *)(float minX, float maxX, float minY, float maxY, float minZ, float maxZ); using Convert_t = void(__fastcall *)(float *outX, float *outY, float x, float y); -using GetRect_t = int(__fastcall *)(void *layout, void *edx, float *out); using GetRenderable_t = void *(__fastcall *)(void *hTex, int force, void *); using RsSet_t = void(__fastcall *)(int selector, int value); using RsSetPtr_t = void(__fastcall *)(int selector, const void *value); @@ -177,8 +177,7 @@ int AddStages(const void *frame, int n, int lastUnit) { if (it == g_gradients.end()) return n; float rect[4]; - void *layout = const_cast(static_cast(frame) + Offsets::OFF_REGION_ANCHOR); - if (reinterpret_cast(Offsets::FUN_REGION_GET_RECT)(layout, nullptr, rect) == 0) + if (!Frame::Layout::GetRect(frame, rect)) return n; const float scale = Game::Read(frame, Offsets::OFF_REGION_EFFECTIVE_SCALE); const auto toNdc = reinterpret_cast(Offsets::FUN_COORD_DDC_TO_NDC); diff --git a/src/frame/BoundsRect.cpp b/src/frame/BoundsRect.cpp index 78fb75f9..17fd7463 100644 --- a/src/frame/BoundsRect.cpp +++ b/src/frame/BoundsRect.cpp @@ -30,6 +30,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/Layout.h" #include #include @@ -43,20 +44,12 @@ struct Rect { float bottom, left, top, right; }; -using GetRect_t = int(__fastcall *)(void *layout, void *edx, Rect *out); -using LayoutDirty_t = int(__fastcall *)(void *layout); -using Resize_t = void(__fastcall *)(void *layout, void *edx, int force); - -void *LayoutOf(void *region) { return static_cast(region) + Offsets::OFF_REGION_ANCHOR; } - // Grows `rect` by a region's own rect, resolving a pending layout first. void AddRegionRect(void *region, Rect &rect) { - void *layout = LayoutOf(region); - if (reinterpret_cast(Offsets::FUN_REGION_LAYOUT_DIRTY)(layout) != 0) - reinterpret_cast(Offsets::FUN_LAYOUT_RESIZE)(layout, nullptr, 1); - Rect own{}; - if (reinterpret_cast(Offsets::FUN_REGION_GET_RECT)(layout, nullptr, &own) == 0) + float r[4]; + if (!Frame::Layout::GetResolvedRect(region, r)) return; + const Rect own{r[0], r[1], r[2], r[3]}; rect.left = own.left < rect.left ? own.left : rect.left; rect.right = own.right > rect.right ? own.right : rect.right; rect.bottom = own.bottom < rect.bottom ? own.bottom : rect.bottom; diff --git a/src/frame/ClampRectInsets.cpp b/src/frame/ClampRectInsets.cpp index 15a099ca..570152e2 100644 --- a/src/frame/ClampRectInsets.cpp +++ b/src/frame/ClampRectInsets.cpp @@ -34,6 +34,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/Layout.h" #include #include @@ -54,10 +55,7 @@ std::unordered_map g_insets; using CalcRect_t = int(__thiscall *)(void *layout, float *rect); CalcRect_t g_origCalcRect = nullptr; -using Invalidate_t = void(__thiscall *)(void *layout, int arg); -void *LayoutOf(void *frame) { return static_cast(frame) + Offsets::OFF_REGION_ANCHOR; } -void *FrameOf(void *layout) { return static_cast(layout) - Offsets::OFF_REGION_ANCHOR; } // A length in the frame's own units (what GetLeft returns) in layout units: // the inverse of Script GetLeft's conversion. @@ -70,7 +68,7 @@ int __fastcall CalcRect_h(void *layout, void * /*edx*/, float *rect) { const uint32_t flags = Game::Read(layout, Offsets::OFF_LAYOUT_FLAGS); if ((flags & Offsets::LAYOUT_FLAG_CLAMPED) == 0 || g_insets.empty()) return g_origCalcRect(layout, rect); - void *frame = FrameOf(layout); + void *frame = Frame::Layout::OwnerOf(layout); const auto it = g_insets.find(frame); if (it == g_insets.end()) return g_origCalcRect(layout, rect); @@ -144,7 +142,7 @@ int __fastcall Script_SetClampRectInsets(void *L) { else g_insets[frame] = in; // Re-lay the frame out, as SetClampedToScreen does after changing the clamp. - reinterpret_cast(Offsets::FUN_LAYOUT_RESIZE)(LayoutOf(frame), 0); + Frame::Layout::Resize(frame, false); return 0; } diff --git a/src/frame/Cooldown.cpp b/src/frame/Cooldown.cpp index d4f9543b..37d8b4d8 100644 --- a/src/frame/Cooldown.cpp +++ b/src/frame/Cooldown.cpp @@ -84,6 +84,7 @@ #include "cvar/Factory.h" #include "frame/ExtraScripts.h" #include "frame/LayerChange.h" +#include "frame/Layout.h" #include "frame/Region.h" #include "frame/RenderBatch.h" #include "frame/ScriptArgs.h" @@ -187,7 +188,7 @@ struct Rect { }; const Rect &RectOf(void *frame) { return *Game::Ptr(frame, Offsets::OFF_REGION_RECT); } -using Frame::Subclass::FrameOfLayout; +using Frame::Layout::OwnerOf; // The alpha the frame draws with — 4.3.4's m_alpha * m_parentAlpha / 255. // 1.12's alpha setter copies one byte down the tree instead of multiplying. @@ -728,7 +729,7 @@ void __fastcall EmitLayer(void *self, void *, void *batch, int layer) { void __fastcall OnFrameSizeChanged(void *layout, void *, const float *oldRect) { g_class.LayoutBase(Offsets::VTBL_LAYOUT_ON_FRAME_SIZE_CHANGED)(layout, nullptr, oldRect); - ResetVerts(FrameOfLayout(layout)); + ResetVerts(OwnerOf(layout)); } // The stock CooldownFrameTemplate: a Model template (Cooldown.xml, 1.12). @@ -749,7 +750,7 @@ void LoadModernTemplate(void *layout) { nullptr); reinterpret_cast(Offsets::FUN_LAYOUT_SET_ALL_POINTS)(layout, nullptr, parent, 1); - Hide(FrameOfLayout(layout)); + Hide(OwnerOf(layout)); } // A texture element's child into `color`, read as CSimpleTexture:: @@ -778,7 +779,7 @@ uintptr_t __fastcall LoadXML(void *layout, void *, const void *node, void *statu g_class.LayoutBase(Offsets::VTBL_XML_NODE_LOADER)(layout, nullptr, node, status); if (node == nullptr) return result; - Fields &f = F(FrameOfLayout(layout)); + Fields &f = F(OwnerOf(layout)); if (const char *reverse = Xml::Attr(node, "reverse")) f.reverse = Game::StringToFlag(reverse); if (const char *drawEdge = Xml::Attr(node, "drawEdge")) @@ -802,7 +803,7 @@ uintptr_t __fastcall LoadXML(void *layout, void *, const void *node, void *statu if (!Xml::TagIs(c, kSlotTag[slot])) continue; uint32_t color = 0; - SetSlotTexture(FrameOfLayout(layout), static_cast(slot), + SetSlotTexture(OwnerOf(layout), static_cast(slot), Xml::Attr(c, "file"), XmlTextureColor(c, status, color) ? &color : nullptr); } diff --git a/src/frame/Layout.h b/src/frame/Layout.h new file mode 100644 index 00000000..02ebf17a --- /dev/null +++ b/src/frame/Layout.h @@ -0,0 +1,70 @@ +// 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 + +// The layout sub-object every region and frame has (4.3.4's CLayoutFrame, at +// OFF_REGION_ANCHOR, which is OFF_FRAME_LAYOUT_SUBOBJECT for a frame) and the +// engine calls on it. Each call here takes the region or frame itself. + +#include "Offsets.h" + +#include + +namespace Frame::Layout { + +static_assert(Offsets::OFF_REGION_ANCHOR == Offsets::OFF_FRAME_LAYOUT_SUBOBJECT, + "a frame's layout sub-object is where a region's is"); + +// The layout sub-object: `this` for SetPoint and the calls below. +inline void *Of(const void *object) { + return const_cast(static_cast(object) + Offsets::OFF_REGION_ANCHOR); +} + +// The region or frame a layout sub-object belongs to, for the layout +// vtable's overrides and hooks. +inline void *OwnerOf(void *layout) { + return static_cast(layout) - Offsets::OFF_REGION_ANCHOR; +} + +// CLayoutFrame::GetRect (FUN_REGION_GET_RECT): {bottom, left, top, right} in +// layout units. False while the object has no valid rect. +inline bool GetRect(const void *object, float (&rect)[4]) { + using Fn = int(__thiscall *)(void *, float *); + return reinterpret_cast(Offsets::FUN_REGION_GET_RECT)(Of(object), rect) != 0; +} + +// IsResizePending (FUN_REGION_LAYOUT_DIRTY): a layout change waits for the +// layout pass. +inline bool IsResizePending(const void *object) { + using Fn = int(__thiscall *)(void *); + return reinterpret_cast(Offsets::FUN_REGION_LAYOUT_DIRTY)(Of(object)) != 0; +} + +// CLayoutFrame::Resize (FUN_LAYOUT_RESIZE): `now` lays the object out at +// once; otherwise it is marked to be laid out later, the path SetPoint takes. +inline void Resize(void *object, bool now) { + using Fn = void(__thiscall *)(void *, int); + reinterpret_cast(Offsets::FUN_LAYOUT_RESIZE)(Of(object), now ? 1 : 0); +} + +// The edge getters' read (Script GetLeft 0x007A1A19): a pending resize run +// now, then the rect. A hidden object, which the layout pass skips, gets a +// rect this way. +inline bool GetResolvedRect(void *object, float (&rect)[4]) { + if (IsResizePending(object)) + Resize(object, true); + return GetRect(object, rect); +} + +} // namespace Frame::Layout diff --git a/src/frame/Modern.cpp b/src/frame/Modern.cpp index af510aff..9403ce70 100644 --- a/src/frame/Modern.cpp +++ b/src/frame/Modern.cpp @@ -72,6 +72,7 @@ #include "Game.h" #include "HookSecureFunc.h" #include "Offsets.h" +#include "frame/Layout.h" #include "frame/ScriptBindings.h" #include @@ -104,13 +105,10 @@ int __fastcall Script_SetSize(void *L) { } using LayoutExtent_t = float(__thiscall *)(void *layout); -using LayoutDirty_t = int(__fastcall *)(void *layout); -using LayoutResize_t = void(__fastcall *)(void *layout, void *edx, int force); -using LayoutGetRect_t = int(__fastcall *)(void *layout, void *edx, float *out); // The explicit size of `self` in layout `slot`; 0 when none is set. float ExplicitExtent(void *self, int slot) { - void *layout = static_cast(self) + Offsets::OFF_REGION_ANCHOR; + void *layout = Frame::Layout::Of(self); auto *vtable = Game::Read(layout, 0); return reinterpret_cast(vtable[slot / sizeof(uintptr_t)])(layout); } @@ -145,13 +143,10 @@ void PushUnscaledExtent(void *L, bool ignoreRect, int slot, bool vertical) { void *self = Game::Lua::ResolveRegion(L); if (self == nullptr) return; - void *layout = static_cast(self) + Offsets::OFF_REGION_ANCHOR; float extent = ExplicitExtent(self, slot); if (extent == 0.0f && !ignoreRect) { - if (reinterpret_cast(Offsets::FUN_REGION_LAYOUT_DIRTY)(layout) != 0) - reinterpret_cast(Offsets::FUN_LAYOUT_RESIZE)(layout, nullptr, 1); float rect[4] = {0.0f, 0.0f, 0.0f, 0.0f}; // {bottom, left, top, right} - if (reinterpret_cast(Offsets::FUN_REGION_GET_RECT)(layout, nullptr, rect) != 0) + if (Frame::Layout::GetResolvedRect(self, rect)) extent = (vertical ? rect[2] - rect[0] : rect[3] - rect[1]) / Game::Read(self, Offsets::OFF_REGION_EFFECTIVE_SCALE); } diff --git a/src/frame/Points.cpp b/src/frame/Points.cpp index 4252c2a4..5ed5c7a3 100644 --- a/src/frame/Points.cpp +++ b/src/frame/Points.cpp @@ -44,6 +44,7 @@ #include "Game.h" #include "Offsets.h" #include "frame/GetPointGuard.h" +#include "frame/Layout.h" #include @@ -55,9 +56,6 @@ using StringToPoint_t = int(__fastcall *)(const char *name, int *point); using RemoveDependent_t = void(__fastcall *)(void *relative, void *edx, void *layout, int mask); using GetRelative_t = void *(__thiscall *)(void *node); using DeleteNode_t = void(__thiscall *)(void *node, int flags); -using LayoutDirty_t = int(__fastcall *)(void *layout); -using Resize_t = void(__fastcall *)(void *layout, void *edx, int force); -using GetRect_t = int(__fastcall *)(void *layout, void *edx, float *out); using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, float x, float y, int flag); @@ -154,12 +152,8 @@ int __fastcall Script_IsRectValid(void *L) { void *region = Game::Lua::ResolveRegion(L); if (region == nullptr) return 0; - void *layout = static_cast(region) + Offsets::OFF_REGION_ANCHOR; - if (reinterpret_cast(Offsets::FUN_REGION_LAYOUT_DIRTY)(layout) != 0) - reinterpret_cast(Offsets::FUN_LAYOUT_RESIZE)(layout, nullptr, 1); float rect[4]; - Game::Lua::PushBoolean( - L, reinterpret_cast(Offsets::FUN_REGION_GET_RECT)(layout, nullptr, rect) != 0); + Game::Lua::PushBoolean(L, Frame::Layout::GetResolvedRect(region, rect)); return 1; } diff --git a/src/frame/Subclass.h b/src/frame/Subclass.h index 4d564126..23218626 100644 --- a/src/frame/Subclass.h +++ b/src/frame/Subclass.h @@ -20,6 +20,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/Layout.h" #include #include @@ -42,11 +43,6 @@ struct VTable { void Set(uintptr_t slot, const void *fn) { slots[slot / 4] = fn; } }; -// The frame a layout sub-object (layout-vtable `this`) belongs to. -inline void *FrameOfLayout(void *layout) { - return static_cast(layout) - Offsets::OFF_FRAME_LAYOUT_SUBOBJECT; -} - // The function in byte offset `slot` of the engine vtable at `address`, for // an override's base call. template @@ -131,7 +127,7 @@ void *__fastcall DeletingDestructor(void *self, void *, uint32_t flags) { template void *__fastcall LayoutDeletingDestructor(void *layout, void *, uint32_t flags) { - return DeletingDestructor(FrameOfLayout(layout), nullptr, flags); + return DeletingDestructor(Layout::OwnerOf(layout), nullptr, flags); } // The class's methods, then a Frame's: none of the engine class's own diff --git a/src/model/Scene.cpp b/src/model/Scene.cpp index ec13cd71..84204df9 100644 --- a/src/model/Scene.cpp +++ b/src/model/Scene.cpp @@ -100,6 +100,7 @@ #include "Offsets.h" #include "api/Documentation.h" #include "frame/LayerChange.h" +#include "frame/Layout.h" #include "frame/Subclass.h" #include "gx/Device.h" #include "model/Camera.h" @@ -115,7 +116,7 @@ namespace Model::Scene { namespace { -using Frame::Subclass::FrameOfLayout; +using Frame::Layout::OwnerOf; using Model::Camera::Vec3; // Retail's camera defaults (probe, docs/notes/model-scene.md). @@ -325,7 +326,6 @@ void FitProjection(const float rect[4], const float view[4]) { } void __fastcall Paint(void *frame) { - using GetRect_t = int(__thiscall *)(void *layout, float *rect); using SetupOrtho_t = void(__fastcall *)(const float *rect, const float *point, int unused); using DdcToNdc_t = void(__fastcall *)(float *x, float *y, float inX, float inY); using Clear_t = void(__fastcall *)(uint32_t mask); @@ -333,8 +333,7 @@ void __fastcall Paint(void *frame) { // {bottom, left, top, right} float rect[4] = {}; - if (!reinterpret_cast(Offsets::FUN_REGION_GET_RECT)( - Game::Ptr(frame, Offsets::OFF_FRAME_LAYOUT_SUBOBJECT), rect)) + if (!Frame::Layout::GetRect(frame, rect)) return; const Gx::SavedTransforms saved; const Gx::Viewport &vp = saved.SavedViewport(); @@ -395,13 +394,9 @@ void __fastcall Paint(void *frame) { // source for. Depth here is the same form without it (1 at the near clip, // 0 at the far); retail's callers all discard it. bool Project(void *frame, const Vec3 &point, double out[3]) { - using GetRect_t = int(__thiscall *)(void *layout, float *rect); - void *camera = CameraOf(frame); float rect[4] = {}; // {bottom, left, top, right} - if (camera == nullptr || - !reinterpret_cast(Offsets::FUN_REGION_GET_RECT)( - Game::Ptr(frame, Offsets::OFF_FRAME_LAYOUT_SUBOBJECT), rect)) + if (camera == nullptr || !Frame::Layout::GetRect(frame, rect)) return false; Gx::Matrix projection, view; { @@ -501,7 +496,7 @@ uintptr_t __fastcall LoadXML(void *layout, void *, const void *node, void *statu Offsets::VTBL_SIMPLEFRAME_LAYOUT, Offsets::VTBL_XML_NODE_LOADER)(layout, nullptr, node, status); if (node == nullptr) return result; - void *frame = FrameOfLayout(layout); + void *frame = OwnerOf(layout); if (const char *layer = Xml::Attr(node, "drawLayer"); layer != nullptr && *layer != '\0') reinterpret_cast(Offsets::FUN_XML_DRAW_LAYER_FROM_NAME)(layer, &F(frame).drawLayer); float value = 0.0f; diff --git a/src/scrollingmessageframe/InsertMode.cpp b/src/scrollingmessageframe/InsertMode.cpp index 5fbf2fa7..2c9cbd2d 100644 --- a/src/scrollingmessageframe/InsertMode.cpp +++ b/src/scrollingmessageframe/InsertMode.cpp @@ -38,6 +38,7 @@ #include "Game.h" #include "Offsets.h" #include "frame/Destruction.h" +#include "frame/Layout.h" #include "scrollingmessageframe/DisplayRefreshed.h" #include "scrollingmessageframe/InsertMode.h" @@ -55,7 +56,6 @@ constexpr int kInsertModeBottom = 2; using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, float x, float y, int flag); using ClearAllPoints_t = void(__fastcall *)(void *anchor); -using Resize_t = void(__fastcall *)(void *anchor, void *edx, int force); using PixelAlignY_t = float(__stdcall *)(float length); // The frames in TOP mode. Every frame is rebuilt on /reload, so the set is @@ -64,7 +64,7 @@ std::unordered_set g_topFrames; bool IsTop(void *smf) { return g_topFrames.count(smf) != 0; } -void *AnchorOf(void *region) { return static_cast(region) + Offsets::OFF_REGION_ANCHOR; } +using Frame::Layout::Of; // Sets a line's anchor as the layout gives it - (BOTTOMLEFT, the frame, // BOTTOMLEFT, x, y) for the first line, (BOTTOMLEFT, the line before, TOPLEFT, @@ -88,7 +88,7 @@ void SetLinePoint(void *smf, void *anchor, int point, void *relative, int relati // the frame. void __fastcall AnchorNewLine(void *anchor, void *, int point, void *relative, int relativePoint, float x, float y, int flag) { - void *line = static_cast(anchor) - Offsets::OFF_REGION_ANCHOR; + void *line = Frame::Layout::OwnerOf(anchor); SetLinePoint(Game::Read(line, Offsets::OFF_REGION_PARENT), anchor, point, relative, relativePoint, x, y, flag); } @@ -104,7 +104,7 @@ void AnchorLines(void *smf) { const int count = Game::Read(smf, Offsets::OFF_SMF_LINE_COUNT); for (int i = 0; i < count; ++i) { AnchorLine(smf, i); - reinterpret_cast(Offsets::FUN_LAYOUT_RESIZE)(AnchorOf(LineOf(smf, i)), nullptr, 1); + Frame::Layout::Resize(LineOf(smf, i), true); } } @@ -185,14 +185,14 @@ const Frame::Destruction::AutoSubscribe _destructionSub{&OnFrameDestroyed}; void AnchorLine(void *smf, int index) { void *line = LineOf(smf, index); - void *anchor = AnchorOf(line); + void *anchor = Of(line); reinterpret_cast(Offsets::FUN_LAYOUT_CLEAR_ALL_POINTS)(anchor); if (index == 0) - SetLinePoint(smf, anchor, Offsets::FRAMEPOINT_BOTTOMLEFT, AnchorOf(smf), Offsets::FRAMEPOINT_BOTTOMLEFT, + SetLinePoint(smf, anchor, Offsets::FRAMEPOINT_BOTTOMLEFT, Of(smf), Offsets::FRAMEPOINT_BOTTOMLEFT, Game::Read(smf, Offsets::OFF_SCROLLINGMESSAGEFRAME_INSET_LEFT), Game::Read(smf, Offsets::OFF_SCROLLINGMESSAGEFRAME_INSET_BOTTOM), 1); else - SetLinePoint(smf, anchor, Offsets::FRAMEPOINT_BOTTOMLEFT, AnchorOf(LineOf(smf, index - 1)), + SetLinePoint(smf, anchor, Offsets::FRAMEPOINT_BOTTOMLEFT, Of(LineOf(smf, index - 1)), Offsets::FRAMEPOINT_TOPLEFT, 0.0f, reinterpret_cast(Offsets::FUN_PIXEL_ALIGN_Y)( Game::Read(line, Offsets::OFF_FONTSTRING_SPACING)), diff --git a/src/texture/Mask.cpp b/src/texture/Mask.cpp index 216da1cb..ac83bf9f 100644 --- a/src/texture/Mask.cpp +++ b/src/texture/Mask.cpp @@ -57,6 +57,7 @@ #include "Game.h" #include "Offsets.h" #include "frame/AlphaGradient.h" +#include "frame/Layout.h" #include "texture/Construct.h" #include "texture/Load.h" #include "texture/Mask.h" @@ -167,28 +168,8 @@ using PrimStreams_t = void(__fastcall *)(int count, const void *pos, int posStri PrimStreams_t g_primStreamsOriginal = nullptr; -// --- region rect resolution --------------------------------------------------- - -using RegionGetRect_t = int(__thiscall *)(void *anchor, float *outTLBR); -using RegionResolve_t = void(__thiscall *)(void *anchor, int flag); -using RegionDirty_t = int(__thiscall *)(void *anchor); - -void *AnchorOf(void *region) { - return reinterpret_cast(reinterpret_cast(region) + - Offsets::OFF_REGION_ANCHOR); -} - -// Reads a region's resolved rect {top,left,bottom,right}. Mirrors the engine's -// own GetLeft: if the layout is dirty, force a synchronous resolve with flag 1 -// (the read-time path that resolves NOW; flag 0 instead defers to the render's -// layout pass, which never runs for a hidden mask). Only resolves when dirty, so -// steady-state frames are a pure read. Returns false if it still can't resolve. -bool RegionRect(void *region, float outTLBR[4]) { - void *anchor = AnchorOf(region); - if (reinterpret_cast(Offsets::FUN_REGION_LAYOUT_DIRTY)(anchor) != 0) - reinterpret_cast(Offsets::FUN_LAYOUT_RESIZE)(anchor, 1); - return reinterpret_cast(Offsets::FUN_REGION_GET_RECT)(anchor, outTLBR) != 0; -} +// A hidden mask's rect comes from Frame::Layout::GetResolvedRect: the layout +// pass skips hidden regions, so a mask would otherwise have none. // --- texgen: every mask samples on its own unit, 1..N ------------------------- // @@ -301,7 +282,7 @@ bool MaskedRegionDrawImpl(void *base, void *pathMaskH, void *const *masks, int m return false; float br[4]; // base rect {top, left, bottom, right} - if (!RegionRect(base, br)) + if (!Frame::Layout::GetResolvedRect(base, br)) return false; // Mirror the engine corner store's input rect: the texcoord crop applies // only when the region opted in (SetTexCoordModifiesRect) — same gate as @@ -342,7 +323,7 @@ bool MaskedRegionDrawImpl(void *base, void *pathMaskH, void *const *masks, int m if (cgx[units] == nullptr) return false; float mr[4]; - if (!RegionRect(masks[i], mr)) + if (!Frame::Layout::GetResolvedRect(masks[i], mr)) return false; float angle = 0.0f, cxN = 0.5f, cyN = 0.5f; const bool rotated = Texture::Transform::GetRotation(masks[i], &angle, &cxN, &cyN); diff --git a/src/texture/Tile.cpp b/src/texture/Tile.cpp index e567d819..c1f524c4 100644 --- a/src/texture/Tile.cpp +++ b/src/texture/Tile.cpp @@ -52,6 +52,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/Layout.h" #include "texture/Atlas.h" #include "texture/CornerStore.h" #include "texture/Wrap.h" @@ -64,7 +65,6 @@ namespace Texture::Tile { namespace { -using GetRect_t = int(__fastcall *)(void *anchor, void *edx, float *outRect); using SetTexCoord_t = void(__fastcall *)(void *texture, void *edx, const float *values); using Emit_t = void(__fastcall *)(void *texture, void *edx, void *batch); @@ -95,8 +95,7 @@ void Apply(void *texture) { if (device == nullptr) return; // the emit of the next batch build counts it float rect[4]; // bottom, left, top, right - if (reinterpret_cast(Offsets::FUN_REGION_GET_RECT)( - Game::Ptr(texture, Offsets::OFF_REGION_ANCHOR), nullptr, rect) == 0) + if (!Frame::Layout::GetRect(texture, rect)) return; const float scale = Game::Read(texture, Offsets::OFF_REGION_EFFECTIVE_SCALE); if (!(scale > 0.0f)) diff --git a/src/texture/Transform.cpp b/src/texture/Transform.cpp index 171ac6f3..0ea9df08 100644 --- a/src/texture/Transform.cpp +++ b/src/texture/Transform.cpp @@ -58,6 +58,7 @@ #include "texture/Transform.h" #include "animation/Region.h" +#include "frame/Layout.h" #include "texture/CornerStore.h" #include "xml/FrameLoad.h" #include "xml/TypeLoad.h" @@ -88,8 +89,6 @@ struct Xf { std::unordered_map g_xf; -// FUN_REGION_GET_RECT — __thiscall(region+OFF_REGION_ANCHOR, float out[4]) -> int. -using GetRect_t = int(__fastcall *)(void *anchor, void *edx, float *outRect); // FUN_REGION_TEXCOORD_CROP — __thiscall(region, float rect[4]) (rect in/out). using Crop_t = void(__fastcall *)(void *region, void *edx, float *rect); @@ -173,9 +172,7 @@ void WriteCorners(void *region, float *base, float left, float right, float top, // first real store. An identity transform restores the plain axis-aligned quad. bool ApplyFromRect(void *region, const Xf &xf) { float rect[4]; - void *anchor = reinterpret_cast(region) + Offsets::OFF_REGION_ANCHOR; - if (reinterpret_cast(Offsets::FUN_REGION_GET_RECT)(anchor, nullptr, - rect) == 0) + if (!Frame::Layout::GetRect(region, rect)) return false; // Apply the texcoord crop (FUN_REGION_TEXCOORD_CROP) exactly as the // engine's own store paths do: gated on the region's @@ -645,8 +642,7 @@ int __fastcall Script_GetCorners(void *L) { Game::Lua::PushNumber(L, base[i * 3 + 1]); } float rect[4] = {0, 0, 0, 0}; - void *anchor = reinterpret_cast(tex) + Offsets::OFF_REGION_ANCHOR; - reinterpret_cast(Offsets::FUN_REGION_GET_RECT)(anchor, nullptr, rect); + Frame::Layout::GetRect(tex, rect); for (int i = 0; i < 4; ++i) Game::Lua::PushNumber(L, rect[i]); return 12; diff --git a/src/tooltip/FrameStack.cpp b/src/tooltip/FrameStack.cpp index 47e030fd..3d6f361f 100644 --- a/src/tooltip/FrameStack.cpp +++ b/src/tooltip/FrameStack.cpp @@ -66,6 +66,7 @@ #include "Game.h" #include "Offsets.h" #include "frame/GetPointGuard.h" +#include "frame/Layout.h" #include "frame/SourceLocation.h" #include "tooltip/Lines.h" #include "tooltip/SetEvents.h" @@ -81,7 +82,6 @@ namespace Tooltip::FrameStack { namespace { using GetName_t = const char *(__thiscall *)(void *object); -using GetRect_t = int(__thiscall *)(void *layout, float *rect); using NDCToDDC_t = void(__fastcall *)(float *outX, float *outY, float x, float y); using StrataToString_t = const char *(__fastcall *)(int strata); using PointToString_t = const char *(__fastcall *)(int point); @@ -159,8 +159,7 @@ void FormatName(void *L, void *object, char *out, size_t size) { // rect cannot be resolved. bool UnderCursor(void *object, float x, float y) { float rect[4]; // {minY, minX, maxY, maxX} - if (reinterpret_cast(Offsets::FUN_REGION_GET_RECT)( - static_cast(object) + Offsets::OFF_REGION_ANCHOR, rect) == 0) + if (!Frame::Layout::GetRect(object, rect)) return false; return x >= rect[1] && x <= rect[3] && y <= rect[2] && y >= rect[0]; } diff --git a/src/xml/PostLoad.cpp b/src/xml/PostLoad.cpp index a3d0d9d4..33814376 100644 --- a/src/xml/PostLoad.cpp +++ b/src/xml/PostLoad.cpp @@ -37,6 +37,7 @@ #include "Common.h" #include "Game.h" #include "Offsets.h" +#include "frame/Layout.h" #include @@ -44,15 +45,14 @@ namespace Xml::PostLoad { namespace { -using LayoutDirty_t = int(__fastcall *)(void *layout); -using Resize_t = void(__fastcall *)(void *layout, void *edx, int force); // Stands in for FUN_REGION_LAYOUT_REALIZE(0): `__thiscall(layout, int)`, `ret 4`. void __fastcall EndLoadDeferral(void *layout, void * /*edx*/, int /*deferred*/) { Game::Ref(layout, Offsets::OFF_LAYOUT_FLAGS) &= ~static_cast(Offsets::LAYOUT_FLAG_DEFERRED); - if (reinterpret_cast(Offsets::FUN_REGION_LAYOUT_DIRTY)(layout) != 0) - reinterpret_cast(Offsets::FUN_LAYOUT_RESIZE)(layout, nullptr, 0); + void *object = Frame::Layout::OwnerOf(layout); + if (Frame::Layout::IsResizePending(object)) + Frame::Layout::Resize(object, false); } void PatchCode() {