diff --git a/src/Offsets.h b/src/Offsets.h index 2cf9cdef..88895fc6 100644 --- a/src/Offsets.h +++ b/src/Offsets.h @@ -891,6 +891,15 @@ enum Offsets { // which adds the built string (+0xF8) when the rect is valid and not // wholly off screen. FUN_FONTSTRING_EMIT = 0x00772E50, + // CSimpleFontString::OnColorChanged — `void __thiscall(fs, int changed)`, + // `ret 4`, the font string's region slot 8 (VTBL_REGION_RECOLOR): calls the + // region colour fold 0x0077FAC0, then, with a built string, hands + // colors[0] (or white when the count is not 1) to TextBlockUpdateColor + // 0x0044D650 and redoes the shadow. SetVertexColor (0x0077F750) calls it + // after storing a colour, and the frame alpha setter (0x0076A690) on each + // region, so every change of OFF_FONTSTRING_COLOR_ARRAY ends here. + // Verified by disassembly. + FUN_FONTSTRING_ON_COLOR_CHANGED = 0x00772180, // A layer batch's entry count: the quad append and the text append each // add one (0x00772FD0, 0x00773080). OFF_LAYER_BATCH_COUNT = 0x4, @@ -1013,12 +1022,10 @@ enum Offsets { // {rgba@+4, shown@+8, timeVisibleLeft@+0xC, fadeLeft@+0x10} in the // stride-0x10 line array at smf+0x3A4) animates each visible line // fontstring's alpha byte through this same SetColor every frame, then - // hides the fs at fade end. Text::InlineTexturePool mirrors this byte onto - // the line's icon regions each tick so inline icons fade with their line - // (regions parent to the CHAT FRAME, so the frame's own alpha byte — - // frame+0xC8, per Script_GetAlpha 0x00774DC0 — already modulates them via - // the engine's parent×region product; only the fs's own component needs - // mirroring). + // hides the fs at fade end. The byte also carries the frame's alpha + // (folded by 0x0077FAC0). Text::InlineTexturePool copies it onto the + // line's icon textures from FUN_FONTSTRING_ON_COLOR_CHANGED; the textures + // have no frame, so it is the only alpha they get. OFF_FONTSTRING_COLOR_COUNT = 0xB4, OFF_FONTSTRING_COLOR_ARRAY = 0xB8, OFF_TEXTBLOCK_NODE = 0x8, // the gxu text node inside the handle diff --git a/src/text/InlineTexture.cpp b/src/text/InlineTexture.cpp index 34149367..56e07ac8 100644 --- a/src/text/InlineTexture.cpp +++ b/src/text/InlineTexture.cpp @@ -2019,9 +2019,9 @@ void FlushLayout(void *layout) { // put while the icons faded. Mirror the live alpha into every // baked colour, change-detected on each page's first entry (all // baked alphas are uniform — the engine's own |c splice writes the - // node alpha too). One-frame lag (flush runs post-paint), same as - // the icon fade mirror. Chat (bit-3 clear) is excluded: the engine - // re-bakes those on colour change itself. + // node alpha too). One-frame lag (flush runs post-paint). Chat + // (bit-3 clear) is excluded: the engine re-bakes those on colour + // change itself. if ((Game::Read(n, Offsets::OFF_TEXT_NODE_FLAGS) & 8u) != 0) { const uint32_t liveColor = Game::Read(n, Offsets::OFF_TEXT_NODE_COLOR); auto baked = g_nodeBakedColor.find(node); diff --git a/src/text/InlineTexturePool.cpp b/src/text/InlineTexturePool.cpp index 09ae77b5..bb704a20 100644 --- a/src/text/InlineTexturePool.cpp +++ b/src/text/InlineTexturePool.cpp @@ -45,6 +45,7 @@ using SetTexCoord_t = void(__thiscall *)(void *tex, const float *coords4); using DeletingDestructor_t = void(__thiscall *)(void *region, int flags); using Emit_t = void(__fastcall *)(void *region, void *edx, void *batch); using NotifyLayerChanged_t = void(__fastcall *)(void *region); +using OnColorChanged_t = void(__fastcall *)(void *fs, void *edx, int changed); // LAA-aware pointer sanity probe: Text::LooksReadable (text/PtrProbe.h). @@ -63,10 +64,6 @@ struct FsPlacements { std::vector want; // the placements the textures carry std::vector regions; // textures currently serving this fs int shown = 0; // how many of `regions` the fs draws - // The fs colour key (folded BGRA colors[0] dword) last applied to the - // drawn textures (the fade mirror — see FsColorKey below). Re-applied on - // change only. - uint32_t appliedColor = 0xFFFFFFFFu; }; std::unordered_map g_fsIcons; @@ -96,7 +93,7 @@ void OnRegionDestroyed(void *region) { const Frame::RegionDestruction::AutoSubscribe _regionDestructionSub{&OnRegionDestroyed}; -// Latched off by Maintain's SEH guard on a fault; re-armed on /reload (see +// Latched off by the pool's SEH guards on a fault; re-armed on /reload (see // PrepareForReload). Mirrors InlineTexture.cpp's g_inlineEnabled paint latch. bool g_maintainDisabled = false; @@ -105,7 +102,8 @@ bool g_maintainDisabled = false; // fader animates each visible line fontstring's alpha through the fs SetColor // every frame (see OFF_FONTSTRING_COLOR_ARRAY's derivation), and the engine // keeps the byte folded with the frame-chain effective alpha. Count 0 = never -// coloured = opaque white default. +// coloured = opaque white default. The icons have no frame, so this is the +// only alpha they get (see OnColorChanged_h). uint32_t FsColorKey(const void *fs) { if (Game::Read(fs, Offsets::OFF_FONTSTRING_COLOR_COUNT) < 1u) return 0xFFFFFFFFu; @@ -227,41 +225,20 @@ void ApplyPlacements(void *fs, FsPlacements &np, uint32_t fsColor) { np.shown = (want < static_cast(np.regions.size())) ? want : static_cast(np.regions.size()); - np.appliedColor = fsColor; reinterpret_cast(Offsets::FUN_REGION_NOTIFY_LAYER_CHANGED)(fs); } -// Per-frame tick (FrameTick — glue AND world): deletes orphaned textures and -// mirrors the line's fade. Wrapped by Maintain() below; kept -// destructor-holding C++ objects out of the SEH frame (MSVC won't allow __try -// in a function that needs object unwinding). +// Per-frame tick (FrameTick — glue AND world): deletes orphaned textures. +// Wrapped by Maintain() below; kept destructor-holding C++ objects out of the +// SEH frame (MSVC won't allow __try in a function that needs object +// unwinding). void MaintainImpl() { - if (!g_orphans.empty()) { - std::vector orphans; - orphans.swap(g_orphans); - for (void *tex : orphans) - DeleteRegion(tex); - } - - for (auto &entry : g_fsIcons) { - FsPlacements &np = entry.second; - // FADE MIRROR: the ScrollingMessageFrame fader animates the line - // fontstring's color alpha every frame, and the glue AddonList swaps - // title RGB on toggle; keep the icon textures' colour in lockstep - // (alpha everywhere, value-follow on glue — see FadedColor) so inline - // icons fade/dim with their text. The batch reads the colour through a - // pointer, so no rebuild. Change-driven — steady state costs one dword - // compare. - const uint32_t fsColor = FsColorKey(entry.first); - if (np.shown == 0 || fsColor == np.appliedColor) - continue; - np.appliedColor = fsColor; - for (int i = 0; i < np.shown; ++i) { - const uint32_t color = FadedColor(np.want[static_cast(i)], fsColor); - reinterpret_cast(Offsets::FUN_FONTSTRING_SET_COLOR)( - np.regions[static_cast(i)].tex, &color); - } - } + if (g_orphans.empty()) + return; + std::vector orphans; + orphans.swap(g_orphans); + for (void *tex : orphans) + DeleteRegion(tex); } // SEH latch mirroring InlineTexture.cpp's SafeFlush: the pool drives engine @@ -334,6 +311,47 @@ void __fastcall Emit_h(void *fs, void *edx, void *batch) { const Game::HookAutoRegister _emitHook{Offsets::FUN_FONTSTRING_EMIT, reinterpret_cast(&Emit_h), reinterpret_cast(&g_origEmit)}; +// The fontstring's colour change (FUN_FONTSTRING_ON_COLOR_CHANGED), where +// 4.3.4's CSimpleFontString::OnColorChanged copies the string's alpha into its +// embedded textures. Every change of the fs colour ends here, folded by the +// time the original returns, so the icons take the line's fade (and, on glue, +// its value — see FadedColor) in the same call. The batch reads the colour +// through a pointer, so no rebuild. +OnColorChanged_t g_origOnColorChanged = nullptr; + +void MirrorFade(void *fs) { + const auto it = g_fsIcons.find(fs); + if (it == g_fsIcons.end()) + return; + const FsPlacements &np = it->second; + const uint32_t fsColor = FsColorKey(fs); + for (int i = 0; i < np.shown; ++i) { + const uint32_t color = FadedColor(np.want[static_cast(i)], fsColor); + reinterpret_cast(Offsets::FUN_FONTSTRING_SET_COLOR)( + np.regions[static_cast(i)].tex, &color); + } +} + +// SEH split mirroring Maintain/MaintainImpl, on the same kill switch. +void SafeMirrorFade(void *fs) { + if (g_maintainDisabled) + return; + __try { + MirrorFade(fs); + } __except (EXCEPTION_EXECUTE_HANDLER) { + g_maintainDisabled = true; + } +} + +void __fastcall OnColorChanged_h(void *fs, void *edx, int changed) { + g_origOnColorChanged(fs, edx, changed); + SafeMirrorFade(fs); +} + +const Game::HookAutoRegister _colorHook{Offsets::FUN_FONTSTRING_ON_COLOR_CHANGED, + reinterpret_cast(&OnColorChanged_h), + reinterpret_cast(&g_origOnColorChanged)}; + } // namespace void Apply(void *fs, std::vector &&icons) {