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.
This commit is contained in:
Brues
2026-11-09 11:51:27 -06:00
parent f0f784bd70
commit b08d2fe813
17 changed files with 129 additions and 117 deletions
+7 -8
View File
@@ -45,6 +45,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/Layout.h"
#include "text/InlineTexture.h"
#include <cstdint>
@@ -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<uint8_t *>(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<ClearAllPoints_t>(Offsets::FUN_LAYOUT_CLEAR_ALL_POINTS)(anchor);
reinterpret_cast<SetPoint_t>(Offsets::FUN_REGION_SET_POINT)(anchor, Offsets::FRAMEPOINT_TOPLEFT, AnchorOf(rows.fs),
reinterpret_cast<SetPoint_t>(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<GetRect_t>(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<float>(line) - shift;
Anchor(rows, piece, relPoint, x, y, 0);
reinterpret_cast<Resize_t>(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<void ***>(anchor);
const float width = reinterpret_cast<Extent_t>(vtable[7])(anchor, nullptr); // +0x1C GetWidth
const float height = reinterpret_cast<Extent_t>(vtable[8])(anchor, nullptr); // +0x20 GetHeight
+2 -5
View File
@@ -15,6 +15,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/Layout.h"
#include <cstdint>
@@ -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<void *>(fs, Offsets::OFF_FONTSTRING_TEXT_BLOCK) = nullptr;
}
Game::Ref<uint32_t>(fs, Offsets::OFF_FONTSTRING_DIRTY_FLAGS) &= ~1u;
void *region = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(fs) + 0x24);
reinterpret_cast<LayoutInvalidate_t>(Offsets::FUN_LAYOUT_RESIZE)(region, nullptr, 0);
Frame::Layout::Resize(fs, false);
}
} // namespace FontString::Layout
+2 -3
View File
@@ -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<uint8_t *>(static_cast<const uint8_t *>(frame) + Offsets::OFF_REGION_ANCHOR);
if (reinterpret_cast<GetRect_t>(Offsets::FUN_REGION_GET_RECT)(layout, nullptr, rect) == 0)
if (!Frame::Layout::GetRect(frame, rect))
return n;
const float scale = Game::Read<float>(frame, Offsets::OFF_REGION_EFFECTIVE_SCALE);
const auto toNdc = reinterpret_cast<Convert_t>(Offsets::FUN_COORD_DDC_TO_NDC);
+4 -11
View File
@@ -30,6 +30,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/Layout.h"
#include <cfloat>
#include <cstdint>
@@ -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<uint8_t *>(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<LayoutDirty_t>(Offsets::FUN_REGION_LAYOUT_DIRTY)(layout) != 0)
reinterpret_cast<Resize_t>(Offsets::FUN_LAYOUT_RESIZE)(layout, nullptr, 1);
Rect own{};
if (reinterpret_cast<GetRect_t>(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;
+3 -5
View File
@@ -34,6 +34,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/Layout.h"
#include <cstdint>
#include <unordered_map>
@@ -54,10 +55,7 @@ std::unordered_map<void *, Insets> 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<uint8_t *>(frame) + Offsets::OFF_REGION_ANCHOR; }
void *FrameOf(void *layout) { return static_cast<uint8_t *>(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<uint32_t>(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<Invalidate_t>(Offsets::FUN_LAYOUT_RESIZE)(LayoutOf(frame), 0);
Frame::Layout::Resize(frame, false);
return 0;
}
+6 -5
View File
@@ -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<Rect>(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<OnFrameSizeChanged_t>(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<SetAllPoints_t>(Offsets::FUN_LAYOUT_SET_ALL_POINTS)(layout, nullptr, parent,
1);
Hide(FrameOfLayout(layout));
Hide(OwnerOf(layout));
}
// A texture element's <Color> 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<LoadXML_t>(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<TextureSlot>(slot),
SetSlotTexture(OwnerOf(layout), static_cast<TextureSlot>(slot),
Xml::Attr(c, "file"),
XmlTextureColor(c, status, color) ? &color : nullptr);
}
+70
View File
@@ -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 <https://www.gnu.org/licenses/>.
#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 <cstdint>
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<uint8_t *>(static_cast<const uint8_t *>(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<uint8_t *>(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<Fn>(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<Fn>(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<Fn>(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
+3 -8
View File
@@ -72,6 +72,7 @@
#include "Game.h"
#include "HookSecureFunc.h"
#include "Offsets.h"
#include "frame/Layout.h"
#include "frame/ScriptBindings.h"
#include <cstdint>
@@ -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<uint8_t *>(self) + Offsets::OFF_REGION_ANCHOR;
void *layout = Frame::Layout::Of(self);
auto *vtable = Game::Read<uintptr_t *>(layout, 0);
return reinterpret_cast<LayoutExtent_t>(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<uint8_t *>(self) + Offsets::OFF_REGION_ANCHOR;
float extent = ExplicitExtent(self, slot);
if (extent == 0.0f && !ignoreRect) {
if (reinterpret_cast<LayoutDirty_t>(Offsets::FUN_REGION_LAYOUT_DIRTY)(layout) != 0)
reinterpret_cast<LayoutResize_t>(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<LayoutGetRect_t>(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<float>(self, Offsets::OFF_REGION_EFFECTIVE_SCALE);
}
+2 -8
View File
@@ -44,6 +44,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/GetPointGuard.h"
#include "frame/Layout.h"
#include <cstdint>
@@ -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<uint8_t *>(region) + Offsets::OFF_REGION_ANCHOR;
if (reinterpret_cast<LayoutDirty_t>(Offsets::FUN_REGION_LAYOUT_DIRTY)(layout) != 0)
reinterpret_cast<Resize_t>(Offsets::FUN_LAYOUT_RESIZE)(layout, nullptr, 1);
float rect[4];
Game::Lua::PushBoolean(
L, reinterpret_cast<GetRect_t>(Offsets::FUN_REGION_GET_RECT)(layout, nullptr, rect) != 0);
Game::Lua::PushBoolean(L, Frame::Layout::GetResolvedRect(region, rect));
return 1;
}
+2 -6
View File
@@ -20,6 +20,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/Layout.h"
#include <cstddef>
#include <cstdint>
@@ -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<uint8_t *>(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 <typename Fn>
@@ -131,7 +127,7 @@ void *__fastcall DeletingDestructor(void *self, void *, uint32_t flags) {
template <auto &C>
void *__fastcall LayoutDeletingDestructor(void *layout, void *, uint32_t flags) {
return DeletingDestructor<C>(FrameOfLayout(layout), nullptr, flags);
return DeletingDestructor<C>(Layout::OwnerOf(layout), nullptr, flags);
}
// The class's methods, then a Frame's: none of the engine class's own
+5 -10
View File
@@ -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<GetRect_t>(Offsets::FUN_REGION_GET_RECT)(
Game::Ptr<uint8_t>(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<GetRect_t>(Offsets::FUN_REGION_GET_RECT)(
Game::Ptr<uint8_t>(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<LayerFromName_t>(Offsets::FUN_XML_DRAW_LAYER_FROM_NAME)(layer, &F(frame).drawLayer);
float value = 0.0f;
+7 -7
View File
@@ -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<void *> g_topFrames;
bool IsTop(void *smf) { return g_topFrames.count(smf) != 0; }
void *AnchorOf(void *region) { return static_cast<uint8_t *>(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<uint8_t *>(anchor) - Offsets::OFF_REGION_ANCHOR;
void *line = Frame::Layout::OwnerOf(anchor);
SetLinePoint(Game::Read<void *>(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<int>(smf, Offsets::OFF_SMF_LINE_COUNT);
for (int i = 0; i < count; ++i) {
AnchorLine(smf, i);
reinterpret_cast<Resize_t>(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<ClearAllPoints_t>(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<float>(smf, Offsets::OFF_SCROLLINGMESSAGEFRAME_INSET_LEFT),
Game::Read<float>(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<PixelAlignY_t>(Offsets::FUN_PIXEL_ALIGN_Y)(
Game::Read<float>(line, Offsets::OFF_FONTSTRING_SPACING)),
+5 -24
View File
@@ -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<void *>(reinterpret_cast<uintptr_t>(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<RegionDirty_t>(Offsets::FUN_REGION_LAYOUT_DIRTY)(anchor) != 0)
reinterpret_cast<RegionResolve_t>(Offsets::FUN_LAYOUT_RESIZE)(anchor, 1);
return reinterpret_cast<RegionGetRect_t>(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);
+2 -3
View File
@@ -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<GetRect_t>(Offsets::FUN_REGION_GET_RECT)(
Game::Ptr<uint8_t>(texture, Offsets::OFF_REGION_ANCHOR), nullptr, rect) == 0)
if (!Frame::Layout::GetRect(texture, rect))
return;
const float scale = Game::Read<float>(texture, Offsets::OFF_REGION_EFFECTIVE_SCALE);
if (!(scale > 0.0f))
+3 -7
View File
@@ -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<void *, Xf> 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<char *>(region) + Offsets::OFF_REGION_ANCHOR;
if (reinterpret_cast<GetRect_t>(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<char *>(tex) + Offsets::OFF_REGION_ANCHOR;
reinterpret_cast<GetRect_t>(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;
+2 -3
View File
@@ -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<GetRect_t>(Offsets::FUN_REGION_GET_RECT)(
static_cast<uint8_t *>(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];
}
+4 -4
View File
@@ -37,6 +37,7 @@
#include "Common.h"
#include "Game.h"
#include "Offsets.h"
#include "frame/Layout.h"
#include <cstdint>
@@ -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<uint32_t>(layout, Offsets::OFF_LAYOUT_FLAGS) &=
~static_cast<uint32_t>(Offsets::LAYOUT_FLAG_DEFERRED);
if (reinterpret_cast<LayoutDirty_t>(Offsets::FUN_REGION_LAYOUT_DIRTY)(layout) != 0)
reinterpret_cast<Resize_t>(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() {