diff --git a/src/animation/Anim.cpp b/src/animation/Anim.cpp index e7f84f46..6096fbf9 100644 --- a/src/animation/Anim.cpp +++ b/src/animation/Anim.cpp @@ -34,6 +34,7 @@ #include "Game.h" #include "Offsets.h" #include "baselib/Ascii.h" +#include "frame/Layout.h" #include #include @@ -317,8 +318,6 @@ void Anim::PostLoadXML() { namespace { -using StringToPoint_t = int(__fastcall *)(const char *name, int *point); -using PointToString_t = const char *(__fastcall *)(int point); Anim *Self(void *L) { return static_cast(Resolve(L, 1, Anim::s_class)); } Anim *SelfOf(void *L, Class &cls) { return static_cast(Resolve(L, 1, cls)); } @@ -699,7 +698,7 @@ int __fastcall Script_SetOrigin(void *L) { return 0; } int point = Offsets::FRAMEPOINT_CENTER; - if (!reinterpret_cast(Offsets::FUN_STRING_TO_FRAME_POINT)(Game::Lua::ToString(L, 2), &point)) + if (!Frame::Layout::StringToPoint(Game::Lua::ToString(L, 2), &point)) point = Offsets::FRAMEPOINT_CENTER; a->originPoint = point; a->originX = Game::PixelToInternal(static_cast(Game::Lua::ToNumber(L, 3))); @@ -711,7 +710,7 @@ int __fastcall Script_GetOrigin(void *L) { Anim *a = OriginSelf(L); if (a == nullptr) return 0; - Game::Lua::PushString(L, reinterpret_cast(Offsets::FUN_FRAME_POINT_TO_STRING)(a->originPoint)); + Game::Lua::PushString(L, Frame::Layout::PointToString(a->originPoint)); Game::Lua::PushNumber(L, a->originX); Game::Lua::PushNumber(L, a->originY); return 3; diff --git a/src/animation/Xml.cpp b/src/animation/Xml.cpp index 04461944..2d225b3c 100644 --- a/src/animation/Xml.cpp +++ b/src/animation/Xml.cpp @@ -29,6 +29,7 @@ #include "Game.h" #include "Offsets.h" #include "baselib/Ascii.h" +#include "frame/Layout.h" #include "xml/FrameLoad.h" #include "xml/KeyValues.h" #include "xml/Mixin.h" @@ -42,7 +43,6 @@ namespace Animation::Xml { namespace { using SetScriptText_t = bool(__fastcall *)(void *object, void *edx, const char *name, const char *text); -using StringToPoint_t = int(__fastcall *)(const char *name, int *point); const void *FindChild(const void *node, const char *tag) { for (const void *c = ::Xml::FirstChild(node); c != nullptr; c = ::Xml::NextSibling(c)) @@ -158,7 +158,7 @@ void LoadOrigin(Anim *anim, const void *node) { float x = 0.0f, y = 0.0f; const char *pointName = ::Xml::Attr(origin, "point"); if (pointName != nullptr && - reinterpret_cast(Offsets::FUN_STRING_TO_FRAME_POINT)(pointName, &point)) { + Frame::Layout::StringToPoint(pointName, &point)) { if (const void *offset = FindChild(origin, "Offset")) { const void *abs = FindChild(offset, "AbsDimension"); const void *dim = abs != nullptr ? abs : offset; diff --git a/src/editbox/IconRows.cpp b/src/editbox/IconRows.cpp index 3991b15b..4d1b5bfc 100644 --- a/src/editbox/IconRows.cpp +++ b/src/editbox/IconRows.cpp @@ -60,9 +60,6 @@ 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 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 Extent_t = float(__fastcall *)(void *anchor, void *edx); using FireVariadic_t = void(__cdecl *)(void *frame, uint32_t *slotPtr, const char *fmt, ...); @@ -176,10 +173,8 @@ 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 = Of(region); - reinterpret_cast(Offsets::FUN_LAYOUT_CLEAR_ALL_POINTS)(anchor); - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)(anchor, Offsets::FRAMEPOINT_TOPLEFT, Of(rows.fs), - relPoint, x, y, flag); + Frame::Layout::ClearAllPoints(region); + Frame::Layout::SetPoint(region, Offsets::FRAMEPOINT_TOPLEFT, Of(rows.fs), relPoint, x, y, flag != 0); } // --- the click --------------------------------------------------------------- diff --git a/src/frame/Cooldown.cpp b/src/frame/Cooldown.cpp index c991c8ae..bbfd57fb 100644 --- a/src/frame/Cooldown.cpp +++ b/src/frame/Cooldown.cpp @@ -542,18 +542,14 @@ CVar::Factory::Handle g_countdownForCooldowns = nullptr; void *CreateCountdown(void *frame) { using SetFont_t = uint32_t(__thiscall *)(void *fs, const char *path, float height, uint32_t flags, uint8_t force); - using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, - float x, float y, int flag); void *fs = Frame::Region::CreateFontString(frame, Offsets::DRAWLAYER_OVERLAY, 0); if (fs == nullptr) return nullptr; if (reinterpret_cast(Offsets::FUN_SIMPLEFONTSTRING_SET_FONT)( fs, "Fonts\\FRIZQT__.TTF", Game::PixelToInternal(16.0f), Offsets::FONT_FLAG_OUTLINE, 0)) Game::Ref(fs, Offsets::OFF_FONTSTRING_FONT_FLAGS) &= ~1u; - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)( - Game::Ptr(fs, Offsets::OFF_REGION_ANCHOR), Offsets::FRAMEPOINT_CENTER, - Game::Ptr(frame, Offsets::OFF_FRAME_LAYOUT_SUBOBJECT), Offsets::FRAMEPOINT_CENTER, - 0.0f, Game::PixelToInternal(-1.0f), 1); + Frame::Layout::SetPoint(fs, Offsets::FRAMEPOINT_CENTER, Frame::Layout::Of(frame), + Offsets::FRAMEPOINT_CENTER, 0.0f, Game::PixelToInternal(-1.0f)); // Built before the frame is shown, the region starts unshown (live: // IsShown() nil), where a script-created one on a shown frame is drawn. // Shown as the engine's callers show a region: the desired flag, then Show. diff --git a/src/frame/GetPointGuard.cpp b/src/frame/GetPointGuard.cpp index d464bf67..1e73e1c5 100644 --- a/src/frame/GetPointGuard.cpp +++ b/src/frame/GetPointGuard.cpp @@ -64,6 +64,7 @@ #include "Game.h" #include "Offsets.h" #include "debug/Log.h" +#include "frame/Layout.h" #include @@ -75,8 +76,6 @@ namespace { using ClearPointByRelative_t = void(__thiscall *)(void *layout, void *relativeTo, int doRelayout); -using GetRelative_t = void *(__thiscall *)(void *node); -using PointToString_t = const char *(__fastcall *)(int point); // SEH-guarded readability probe. Standalone with only raw pointers and no // C++ objects in scope, per the MSVC __try/__except constraint. A fault on @@ -104,8 +103,7 @@ void CleanDanglingAnchors(void *region) { auto *base = static_cast(region); auto *top = Game::Read(Offsets::VAR_UI_CONTEXT_PTR); for (int i = 0; i < Offsets::REGION_ANCHOR_SLOT_COUNT; ++i) { - auto *node = Game::Read( - base, Offsets::OFF_REGION_ANCHOR_ARRAY + i * 4); + auto *node = static_cast(Frame::Layout::PointNode(region, i)); if (node == nullptr) continue; // Only relativeTo-carrying nodes can dangle; the rel-less node type @@ -140,16 +138,14 @@ void CleanDanglingAnchors(void *region) { } int PushPoint(void *L, void *region, int point) { - auto *node = Game::Read(region, Offsets::OFF_REGION_ANCHOR_ARRAY + point * 4); - if (node == nullptr) + Frame::Layout::Point p; + if (!Frame::Layout::GetPoint(region, point, &p)) return 0; - auto pointName = reinterpret_cast(Offsets::FUN_FRAME_POINT_TO_STRING); - auto *vtable = Game::Read(node, 0); - auto *relative = static_cast(reinterpret_cast( - vtable[Offsets::VTBL_ANCHOR_NODE_GET_RELATIVE / sizeof(uintptr_t)])(node)); - const double x = Game::InternalToPixel(Game::Read(node, Offsets::OFF_ANCHOR_NODE_X)); - const double y = Game::InternalToPixel(Game::Read(node, Offsets::OFF_ANCHOR_NODE_Y)); + const auto pointName = &Frame::Layout::PointToString; + auto *relative = static_cast(p.relativeLayout); + const double x = Game::InternalToPixel(p.x); + const double y = Game::InternalToPixel(p.y); Game::Lua::PushString(L, pointName(point)); if (relative == nullptr) { @@ -161,8 +157,7 @@ int PushPoint(void *L, void *region, int point) { Game::Lua::PushNil(L); // anchored to the screen else Game::Lua::PushObject(L, relative - Offsets::OFF_REGION_ANCHOR); - Game::Lua::PushString( - L, pointName(Game::Read(node, Offsets::OFF_ANCHOR_NODE_RELATIVE_POINT))); + Game::Lua::PushString(L, pointName(p.relPoint)); Game::Lua::PushNumber(L, x); Game::Lua::PushNumber(L, y); return 5; @@ -183,7 +178,7 @@ int __fastcall GetPoint_h(void *L) { // The index-th set slot, in point order (TOPLEFT .. BOTTOMRIGHT). for (int point = 0, found = 0; point < Offsets::REGION_ANCHOR_SLOT_COUNT; ++point) { - if (Game::Read(region, Offsets::OFF_REGION_ANCHOR_ARRAY + point * 4) == nullptr) + if (Frame::Layout::PointNode(region, point) == nullptr) continue; if (found >= index) return PushPoint(L, region, point); diff --git a/src/frame/Layout.h b/src/frame/Layout.h index 876b6db5..f8ba54e1 100644 --- a/src/frame/Layout.h +++ b/src/frame/Layout.h @@ -79,4 +79,74 @@ inline bool GetResolvedRect(void *object, float (&rect)[4]) { return GetRect(object, rect); } +// The anchor node in `point`'s slot (FRAMEPOINT_*), or nullptr when the slot +// is unset. +inline void *PointNode(const void *object, int point) { + return *reinterpret_cast(static_cast(object) + + Offsets::OFF_REGION_ANCHOR_ARRAY + + point * static_cast(sizeof(void *))); +} + +// One anchor, as the engine's GetPoint reads it. `relativeLayout` comes from +// the node's own getter (vtable +0x0C): a layout sub-object, the screen's +// (VAR_UI_CONTEXT_PTR) for a point on the screen, or null for the node type +// with no relative. `relPoint` is set only with a relative: that 12-byte +// node {vtable, x, y} has no field for it. Offsets are in layout units. +struct Point { + void *relativeLayout; + int relPoint; + float x; + float y; +}; + +// Reads `point`'s anchor. False when the slot is unset. +inline bool GetPoint(const void *object, int point, Point *out) { + using GetRelative_t = void *(__thiscall *)(void *node); + auto *node = static_cast(PointNode(object, point)); + if (node == nullptr) + return false; + const auto *vtable = *reinterpret_cast(node); + out->relativeLayout = reinterpret_cast( + vtable[Offsets::VTBL_ANCHOR_NODE_GET_RELATIVE / sizeof(uintptr_t)])(node); + out->relPoint = out->relativeLayout != nullptr + ? *reinterpret_cast(node + Offsets::OFF_ANCHOR_NODE_RELATIVE_POINT) + : 0; + out->x = *reinterpret_cast(node + Offsets::OFF_ANCHOR_NODE_X); + out->y = *reinterpret_cast(node + Offsets::OFF_ANCHOR_NODE_Y); + return true; +} + +// CLayoutFrame::SetPoint (FUN_REGION_SET_POINT): `point` of `object` to +// `relPoint` of `relativeLayout`, offsets in layout units. The relative is a +// layout sub-object, as the engine stores it: `Of(relative)`, or one an +// anchor node or the XML loader already holds. The engine refuses a null +// relative or the object itself (error 0x57), and `resize` lays the object +// out at once (benilla-re ui/anchors). +inline void SetPoint(void *object, int point, void *relativeLayout, int relPoint, float x, + float y, bool resize = true) { + using Fn = void(__thiscall *)(void *, int, void *, int, float, float, int); + reinterpret_cast(Offsets::FUN_REGION_SET_POINT)(Of(object), point, relativeLayout, + relPoint, x, y, resize ? 1 : 0); +} + +// CLayoutFrame::ClearAllPoints (FUN_LAYOUT_CLEAR_ALL_POINTS): frees all nine +// anchor slots and unlinks the object from each relative. +inline void ClearAllPoints(void *object) { + using Fn = void(__fastcall *)(void *); + reinterpret_cast(Offsets::FUN_LAYOUT_CLEAR_ALL_POINTS)(Of(object)); +} + +// The engine's point names (FUN_STRING_TO_FRAME_POINT): "TOPLEFT" and the +// rest to FRAMEPOINT_*. False for a string that names no point. +inline bool StringToPoint(const char *name, int *point) { + using Fn = int(__fastcall *)(const char *, int *); + return reinterpret_cast(Offsets::FUN_STRING_TO_FRAME_POINT)(name, point) != 0; +} + +// FUN_FRAME_POINT_TO_STRING: a FRAMEPOINT_* value's name. +inline const char *PointToString(int point) { + using Fn = const char *(__fastcall *)(int); + return reinterpret_cast(Offsets::FUN_FRAME_POINT_TO_STRING)(point); +} + } // namespace Frame::Layout diff --git a/src/frame/Points.cpp b/src/frame/Points.cpp index 5ed5c7a3..11b88beb 100644 --- a/src/frame/Points.cpp +++ b/src/frame/Points.cpp @@ -52,19 +52,14 @@ namespace Frame::Points { namespace { -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 SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, - float x, float y, int flag); // The point named by argument 2, or -1 after raising the usage error. int PointArg(void *L, void *region, const char *usage) { int point = 0; if (!Game::Lua::IsString(L, 2) || - !reinterpret_cast(Offsets::FUN_STRING_TO_FRAME_POINT)( - Game::Lua::ToString(L, 2), &point)) { + !Frame::Layout::StringToPoint(Game::Lua::ToString(L, 2), &point)) { Game::Lua::Error(L, usage, Game::Lua::ObjectDisplayName(region)); return -1; } @@ -93,16 +88,15 @@ int __fastcall Script_ClearPoint(void *L) { auto **slot = reinterpret_cast(static_cast(region) + Offsets::OFF_REGION_ANCHOR_ARRAY + point * 4); uint8_t *node = *slot; - if (node == nullptr) + Frame::Layout::Point p; + if (!Frame::Layout::GetPoint(region, point, &p)) return 0; - auto *vtable = Game::Read(node, 0); - void *relative = reinterpret_cast( - vtable[Offsets::VTBL_ANCHOR_NODE_GET_RELATIVE / sizeof(uintptr_t)])(node); + void *relative = p.relativeLayout; if (relative != nullptr) reinterpret_cast(Offsets::FUN_LAYOUT_REMOVE_DEPENDENT)( relative, nullptr, static_cast(region) + Offsets::OFF_REGION_ANCHOR, 1 << point); - reinterpret_cast(vtable[0])(node, 1); + reinterpret_cast(Game::Read(node, 0)[0])(node, 1); *slot = nullptr; return 0; } @@ -112,18 +106,11 @@ int __fastcall Script_ClearPoint(void *L) { void ShiftPoints(void *region, float dx, float dy, bool zero) { Frame::GetPointGuard::CleanDanglingAnchors(region); for (int point = 0; point < Offsets::REGION_ANCHOR_SLOT_COUNT; ++point) { - uint8_t *node = Game::Read(region, Offsets::OFF_REGION_ANCHOR_ARRAY + point * 4); - if (node == nullptr) + Frame::Layout::Point p; + if (!Frame::Layout::GetPoint(region, point, &p)) continue; - auto *vtable = Game::Read(node, 0); - void *relative = reinterpret_cast( - vtable[Offsets::VTBL_ANCHOR_NODE_GET_RELATIVE / sizeof(uintptr_t)])(node); - const int relativePoint = Game::Read(node, Offsets::OFF_ANCHOR_NODE_RELATIVE_POINT); - const float x = zero ? 0.0f : Game::Read(node, Offsets::OFF_ANCHOR_NODE_X) + dx; - const float y = zero ? 0.0f : Game::Read(node, Offsets::OFF_ANCHOR_NODE_Y) + dy; - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)( - static_cast(region) + Offsets::OFF_REGION_ANCHOR, point, relative, - relativePoint, x, y, 1); + Frame::Layout::SetPoint(region, point, p.relativeLayout, p.relPoint, + zero ? 0.0f : p.x + dx, zero ? 0.0f : p.y + dy); } } diff --git a/src/scrollingmessageframe/InsertMode.cpp b/src/scrollingmessageframe/InsertMode.cpp index 2c9cbd2d..4cfff40a 100644 --- a/src/scrollingmessageframe/InsertMode.cpp +++ b/src/scrollingmessageframe/InsertMode.cpp @@ -53,9 +53,6 @@ namespace { constexpr int kInsertModeTop = 1; 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 PixelAlignY_t = float(__stdcall *)(float length); // The frames in TOP mode. Every frame is rebuilt on /reload, so the set is @@ -81,7 +78,7 @@ void SetLinePoint(void *smf, void *anchor, int point, void *relative, int relati y = -y; } } - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)(anchor, point, relative, relativePoint, x, y, flag); + Frame::Layout::SetPoint(Frame::Layout::OwnerOf(anchor), point, relative, relativePoint, x, y, flag != 0); } // The layout's SetPoint for a line it has just made; the line's parent is @@ -186,7 +183,7 @@ const Frame::Destruction::AutoSubscribe _destructionSub{&OnFrameDestroyed}; void AnchorLine(void *smf, int index) { void *line = LineOf(smf, index); void *anchor = Of(line); - reinterpret_cast(Offsets::FUN_LAYOUT_CLEAR_ALL_POINTS)(anchor); + Frame::Layout::ClearAllPoints(line); if (index == 0) SetLinePoint(smf, anchor, Offsets::FRAMEPOINT_BOTTOMLEFT, Of(smf), Offsets::FRAMEPOINT_BOTTOMLEFT, Game::Read(smf, Offsets::OFF_SCROLLINGMESSAGEFRAME_INSET_LEFT), diff --git a/src/statusbar/Fill.cpp b/src/statusbar/Fill.cpp index 0d1e8ff1..7f391b8e 100644 --- a/src/statusbar/Fill.cpp +++ b/src/statusbar/Fill.cpp @@ -55,6 +55,7 @@ #include "Offsets.h" #include "baselib/Ascii.h" #include "frame/Destruction.h" +#include "frame/Layout.h" #include "statusbar/Display.h" #include "texture/Wrap.h" #include "xml/FrameLoad.h" @@ -97,8 +98,6 @@ struct State { std::unordered_map g_state; using Update_t = void(__fastcall *)(void *bar, void *edx, float elapsed); -using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relative, int relativePoint, float x, - float y, int doResize); using SetTexCoordRect_t = void(__thiscall *)(void *texture, const float *rect); using SetTexCoordCorners_t = void(__thiscall *)(void *texture, const float *corners); using GetFillFraction_t = float(__fastcall *)(void *bar, void *edx); @@ -134,9 +133,7 @@ float FillFraction(void *bar, int fillStyle) { void Uncrop(void *texture) { Game::Ref(texture, Offsets::OFF_REGION_TEXCOORD_MODIFIES_RECT) = 0; } void SetPoint(void *texture, int point, void *bar, float x, float y) { - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)( - Game::Ptr(texture, Offsets::OFF_REGION_ANCHOR), point, - Game::Ptr(bar, Offsets::OFF_REGION_ANCHOR), point, x, y, 1); + Frame::Layout::SetPoint(texture, point, Frame::Layout::Of(bar), point, x, y); } // The image's full coordinates, as 4.3.4's SetRotatesTexture sets them. diff --git a/src/target/SoftTargetIcon.cpp b/src/target/SoftTargetIcon.cpp index c74c34e3..90a91cf1 100644 --- a/src/target/SoftTargetIcon.cpp +++ b/src/target/SoftTargetIcon.cpp @@ -50,6 +50,7 @@ #include "Offsets.h" #include "cursor/Hover.h" #include "cvar/Factory.h" +#include "frame/Layout.h" #include "frame/Region.h" #include "object/Resolve.h" #include "target/SoftInteract.h" @@ -66,8 +67,6 @@ namespace { using SetTexture_t = uint32_t(__thiscall *)(void *tex, const char *path, int a, uint32_t blend, int b); -using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, - float x, float y, int flag); using SetSize_t = void(__thiscall *)(void *anchor, float internal); using ShowHide_t = void(__fastcall *)(void *tex); using PlateScreenPos_t = bool(__fastcall *)(void *unit, void *worldFrame, float *screen); @@ -151,9 +150,8 @@ void Show(Icon &icon, uint64_t guid, void *worldFrame) { reinterpret_cast(Offsets::FUN_LAYOUT_SET_HEIGHT)(Anchor(icon.tex), size); icon.shownSize = size; } - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)( - Anchor(icon.tex), Offsets::FRAMEPOINT_BOTTOM, Anchor(worldFrame), - Offsets::FRAMEPOINT_BOTTOMLEFT, screen[0], screen[1], 1); + Frame::Layout::SetPoint(icon.tex, Offsets::FRAMEPOINT_BOTTOM, Anchor(worldFrame), + Offsets::FRAMEPOINT_BOTTOMLEFT, screen[0], screen[1]); SetShown(icon, true); } diff --git a/src/text/InlineTexturePool.cpp b/src/text/InlineTexturePool.cpp index d4154d27..6be2d4a0 100644 --- a/src/text/InlineTexturePool.cpp +++ b/src/text/InlineTexturePool.cpp @@ -16,6 +16,7 @@ // fontstring itself (Emit_h below), so the texture is resident by // construction, moves with its line and shows exactly when its line does. +#include "frame/Layout.h" #include "text/InlineTexturePool.h" #include "Game.h" @@ -40,8 +41,6 @@ namespace { using SetTexture_t = uint32_t(__thiscall *)(void *tex, const char *path, int a, uint32_t blend, int b); using SetColor_t = void(__thiscall *)(void *tex, const void *colorBGRA); -using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, - float x, float y, int flag); using Realize_t = void(__thiscall *)(void *anchor, int flag); using SetTexCoord_t = void(__thiscall *)(void *tex, const float *coords4); using DeletingDestructor_t = void(__thiscall *)(void *region, int flags); @@ -196,14 +195,12 @@ void ApplyPlacement(IconRegion &r, void *fs, const Placement &p, uint32_t fsColo // has no frame, so nothing changes the ctor's scale of 1 (CLayoutFrame // 0x00767680) and the offsets land exactly as given, as 4.3.4's // CSimpleEmbeddedTexture's do. - auto setPoint = reinterpret_cast(Offsets::FUN_REGION_SET_POINT); - void *texAnchor = reinterpret_cast(r.tex) + Offsets::OFF_REGION_ANCHOR; - void *fsAnchor = f + Offsets::OFF_REGION_ANCHOR; - setPoint(texAnchor, Offsets::FRAMEPOINT_BOTTOMLEFT, fsAnchor, Offsets::FRAMEPOINT_BOTTOMLEFT, - p.x0, p.y0, 1); - setPoint(texAnchor, Offsets::FRAMEPOINT_TOPRIGHT, fsAnchor, Offsets::FRAMEPOINT_BOTTOMLEFT, - p.x1, p.y1, 1); - reinterpret_cast(Offsets::FUN_REGION_LAYOUT_REALIZE)(texAnchor, 0); + void *fsAnchor = Frame::Layout::Of(f); + Frame::Layout::SetPoint(r.tex, Offsets::FRAMEPOINT_BOTTOMLEFT, fsAnchor, + Offsets::FRAMEPOINT_BOTTOMLEFT, p.x0, p.y0); + Frame::Layout::SetPoint(r.tex, Offsets::FRAMEPOINT_TOPRIGHT, fsAnchor, + Offsets::FRAMEPOINT_BOTTOMLEFT, p.x1, p.y1); + reinterpret_cast(Offsets::FUN_REGION_LAYOUT_REALIZE)(Frame::Layout::Of(r.tex), 0); } // Applies `want` to the fontstring's textures: create and configure each. The diff --git a/src/tooltip/Clear.cpp b/src/tooltip/Clear.cpp index 90f83b80..0a5dd4f6 100644 --- a/src/tooltip/Clear.cpp +++ b/src/tooltip/Clear.cpp @@ -41,6 +41,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/Layout.h" #include @@ -51,8 +52,6 @@ namespace { using Clear_t = void(__fastcall *)(void *self); Clear_t g_clearOriginal = nullptr; -using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, - float x, float y, int flag); constexpr uint32_t kMaxTextures = 3; @@ -66,9 +65,8 @@ void RestoreLineBelow(uint8_t *tooltip, uint32_t line) { if (left == nullptr || left[line] == nullptr || left[line + 1] == nullptr) return; const float gap = Game::PixelToInternal(Game::Read(Offsets::VAR_TOOLTIP_LINE_GAP)); - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)( - left[line + 1] + Offsets::OFF_REGION_ANCHOR, Offsets::FRAMEPOINT_TOPLEFT, - left[line] + Offsets::OFF_REGION_ANCHOR, Offsets::FRAMEPOINT_BOTTOMLEFT, 0.0f, gap, 1); + Frame::Layout::SetPoint(left[line + 1], Offsets::FRAMEPOINT_TOPLEFT, + Frame::Layout::Of(left[line]), Offsets::FRAMEPOINT_BOTTOMLEFT, 0.0f, gap); } // True when the texture routine has re-anchored `line` since the clear: a diff --git a/src/tooltip/FrameStack.cpp b/src/tooltip/FrameStack.cpp index 9e546010..64842503 100644 --- a/src/tooltip/FrameStack.cpp +++ b/src/tooltip/FrameStack.cpp @@ -83,8 +83,6 @@ namespace { using GetName_t = const char *(__thiscall *)(void *object); using StrataToString_t = const char *(__fastcall *)(int strata); -using PointToString_t = const char *(__fastcall *)(int point); -using GetRelative_t = void *(__thiscall *)(void *node); // 4.3.4's line colors, packed {b,g,r,a} like every add-line color; two of each // so neighbouring frame levels alternate (s_frameStack*Colors). Regions take @@ -186,20 +184,18 @@ void AddRegions(void *L, const Entry &frame, float x, float y, bool showHidden, void AddDetails(void *L, void *self, void *object, const uint32_t &color, const uint32_t &headerColor) { Frame::GetPointGuard::CleanDanglingAnchors(object); - auto pointName = reinterpret_cast(Offsets::FUN_FRAME_POINT_TO_STRING); + const auto pointName = &Frame::Layout::PointToString; char text[1024]; int n = 0; for (int slot = 0; slot < Offsets::REGION_ANCHOR_SLOT_COUNT; ++slot) { - auto *node = Game::Read(object, Offsets::OFF_REGION_ANCHOR_ARRAY + slot * 4); - if (node == nullptr) + Frame::Layout::Point p; + if (!Frame::Layout::GetPoint(object, slot, &p)) continue; if (n++ == 0) Lines::Add(self, "ANCHORS", headerColor); - auto *vtable = Game::Read(node, 0); - auto *relative = static_cast(reinterpret_cast( - vtable[Offsets::VTBL_ANCHOR_NODE_GET_RELATIVE / sizeof(uintptr_t)])(node)); - const double x = Game::InternalToPixel(Game::Read(node, Offsets::OFF_ANCHOR_NODE_X)); - const double y = Game::InternalToPixel(Game::Read(node, Offsets::OFF_ANCHOR_NODE_Y)); + auto *relative = static_cast(p.relativeLayout); + const double x = Game::InternalToPixel(p.x); + const double y = Game::InternalToPixel(p.y); // A screen anchor's target is the top itself, a bare CLayoutFrame with // no region in front of it (Offsets VAR_UI_CONTEXT_PTR): no name to // show, and `relative - OFF_REGION_ANCHOR` must not be formed. @@ -210,7 +206,7 @@ void AddDetails(void *L, void *self, void *object, const uint32_t &color, FormatName(L, relative - Offsets::OFF_REGION_ANCHOR, relativeName, sizeof(relativeName)); std::snprintf(text, sizeof(text), " <%d> %s %s %s %.2f %.2f", n, pointName(slot), relativeName, - pointName(Game::Read(node, Offsets::OFF_ANCHOR_NODE_RELATIVE_POINT)), + pointName(p.relPoint), x, y); } else { std::snprintf(text, sizeof(text), " <%d> %s %.2f %.2f", n, pointName(slot), x, y); diff --git a/src/tooltip/Layout.cpp b/src/tooltip/Layout.cpp index f6d3c46e..862c652f 100644 --- a/src/tooltip/Layout.cpp +++ b/src/tooltip/Layout.cpp @@ -60,6 +60,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/Layout.h" #include #include @@ -69,9 +70,6 @@ namespace Tooltip::Layout { namespace { using ResetPosition_t = void(__fastcall *)(void *tooltip, void *edx, int force); -using ClearAllPoints_t = void(__fastcall *)(void *layout); -using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, - float x, float y, int flag); using Script_t = int(__fastcall *)(void *L); ResetPosition_t g_resetPositionOriginal = nullptr; @@ -122,15 +120,13 @@ void __fastcall ResetPosition_h(void *self, void *edx, int force) { return; } - void *layout = tooltip + Offsets::OFF_FRAME_LAYOUT_SUBOBJECT; - reinterpret_cast(Offsets::FUN_LAYOUT_CLEAR_ALL_POINTS)(layout); + Frame::Layout::ClearAllPoints(tooltip); const bool top = type == Offsets::TOOLTIP_ANCHOR_TOP; - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)( - layout, top ? Offsets::FRAMEPOINT_BOTTOM : Offsets::FRAMEPOINT_TOP, owner, - top ? Offsets::FRAMEPOINT_TOP : Offsets::FRAMEPOINT_BOTTOM, - Game::Read(tooltip, Offsets::OFF_TOOLTIP_OFFSET_X), - Game::Read(tooltip, Offsets::OFF_TOOLTIP_OFFSET_Y), 1); + Frame::Layout::SetPoint(tooltip, top ? Offsets::FRAMEPOINT_BOTTOM : Offsets::FRAMEPOINT_TOP, + owner, top ? Offsets::FRAMEPOINT_TOP : Offsets::FRAMEPOINT_BOTTOM, + Game::Read(tooltip, Offsets::OFF_TOOLTIP_OFFSET_X), + Game::Read(tooltip, Offsets::OFF_TOOLTIP_OFFSET_Y)); } const Game::HookAutoRegister _resetPositionHook{ diff --git a/src/tooltip/LinePool.cpp b/src/tooltip/LinePool.cpp index 01bc3c94..8dc65c19 100644 --- a/src/tooltip/LinePool.cpp +++ b/src/tooltip/LinePool.cpp @@ -36,6 +36,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/Layout.h" #include "frame/Region.h" #include @@ -49,8 +50,6 @@ namespace { using GetName_t = const char *(__thiscall *)(void *self); using SetName_t = void(__thiscall *)(void *region, const char *name); using SetFont_t = void(__thiscall *)(void *fontHolder, void *fontObject); -using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, - float x, float y, int flag); using HideFontString_t = void(__fastcall *)(void *fs); using AddFontStrings_t = void(__thiscall *)(void *tooltip, void *left, void *right); @@ -88,10 +87,8 @@ void *CreateLine(void *parent, const char *name, void *fontSource, int point, reinterpret_cast(Offsets::FUN_FONTSTRING_SET_FONT)( fsBytes + Offsets::OFF_FONTSTRING_FONT_HOLDER, fontObject); - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)( - fsBytes + Offsets::OFF_REGION_ANCHOR, point, - reinterpret_cast(relRegion) + Offsets::OFF_REGION_ANCHOR, relPoint, - Game::PixelToInternal(x), Game::PixelToInternal(y), 1); + Frame::Layout::SetPoint(fsBytes, point, Frame::Layout::Of(relRegion), relPoint, + Game::PixelToInternal(x), Game::PixelToInternal(y)); // The clear only hides lines below `numLines`, so a spare line has to // start hidden — the same `+0xC4 = 0` + hide the clear does. diff --git a/src/xml/Anchors.cpp b/src/xml/Anchors.cpp index 5738b1d7..38ce0da2 100644 --- a/src/xml/Anchors.cpp +++ b/src/xml/Anchors.cpp @@ -37,6 +37,7 @@ // a frame's children are built (RetryUnder, before its OnLoad) and once more // when the outermost frame build returns (Flush), which reports what is left. +#include "frame/Layout.h" #include "xml/Anchors.h" #include "Game.h" @@ -51,11 +52,7 @@ namespace Xml::Anchors { namespace { -using StringToPoint_t = int(__fastcall *)(const char *name, int *point); using ReadDimension_t = int(__fastcall *)(const void *node, float *x, float *y, void *status); -using GetRelative_t = void *(__thiscall *)(void *anchorNode); -using SetPoint_t = void(__thiscall *)(void *anchor, int point, void *relAnchor, int relPoint, - float x, float y, int flag); bool HasValue(const char *s) { return s != nullptr && *s != '\0'; } @@ -115,12 +112,8 @@ namespace { // LayoutFrame inner, the setter's relAnchor), or nullptr when the point is // unset or has no target. void *EngineTarget(void *object, int point) { - void *anchorNode = Game::Read( - object, Offsets::OFF_REGION_ANCHOR_ARRAY + point * static_cast(sizeof(void *))); - if (anchorNode == nullptr) - return nullptr; - const void *vtable = Game::Read(anchorNode, 0); - return Game::Read(vtable, Offsets::VTBL_ANCHOR_NODE_GET_RELATIVE)(anchorNode); + Frame::Layout::Point p; + return Frame::Layout::GetPoint(object, point, &p) ? p.relativeLayout : nullptr; } // Sets one anchor. False only when its relativeKey does not resolve (yet). @@ -132,7 +125,7 @@ bool ApplyAnchor(void *object, const void *anchor, void *status) { if (!HasValue(relativeKey) && !inlineOffset) return true; - auto toPoint = reinterpret_cast(Offsets::FUN_STRING_TO_FRAME_POINT); + const auto toPoint = &Frame::Layout::StringToPoint; int point = 0; const char *pointName = Xml::Attr(anchor, "point"); if (!HasValue(pointName) || !toPoint(pointName, &point)) @@ -159,9 +152,7 @@ bool ApplyAnchor(void *object, const void *anchor, void *status) { if (dimension != nullptr) reinterpret_cast(Offsets::FUN_XML_READ_DIMENSION)(dimension, &x, &y, status); - reinterpret_cast(Offsets::FUN_REGION_SET_POINT)( - Game::Ptr(object, Offsets::OFF_REGION_ANCHOR), point, relAnchor, relativePoint, x, - y, 1); + Frame::Layout::SetPoint(object, point, relAnchor, relativePoint, x, y); return true; }