From e27d1e5849e9117ca392686f224fdc142cce14cd Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 7 Nov 2026 10:11:01 -0600 Subject: [PATCH] refactor(frame): one wrapper for each draw-layer invalidate CSimpleFrame::NotifyLayerChanged (FUN_FRAME_NOTIFY_LAYER_CHANGED, 0x0076A990, __thiscall (frame, layer)) was wrapped by hand in Cooldown, ModelScene and ClipChildren, and CScriptRegion::NotifyLayerChanged (FUN_REGION_NOTIFY_LAYER_CHANGED, 0x0077FDF0, __thiscall (region)) in the inline-texture pool and the texture wrap. Each file carried its own typedef for the same engine call. frame/LayerChange.h now holds the two: NotifyFrame and NotifyRegion. All five files call them. --- src/frame/ClipChildren.cpp | 4 ++-- src/frame/Cooldown.cpp | 12 +++++------ src/frame/LayerChange.h | 37 ++++++++++++++++++++++++++++++++++ src/model/Scene.cpp | 10 +++------ src/text/InlineTexturePool.cpp | 4 ++-- src/texture/Wrap.cpp | 4 ++-- 6 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 src/frame/LayerChange.h diff --git a/src/frame/ClipChildren.cpp b/src/frame/ClipChildren.cpp index dd771a44..cf3c894c 100644 --- a/src/frame/ClipChildren.cpp +++ b/src/frame/ClipChildren.cpp @@ -69,6 +69,7 @@ #include "frame/AlphaGradient.h" #include "frame/ClipChildren.h" #include "frame/Destruction.h" +#include "frame/LayerChange.h" #include "frame/ParentChange.h" #include "xml/FrameLoad.h" @@ -85,7 +86,6 @@ using BatchOp_t = void(__fastcall *)(void *batch); using Callback_t = void(__fastcall *)(void *arg); using AddCallback_t = void(__fastcall *)(void *batch, void *edx, Callback_t fn, void *arg); using SetFrameFlag_t = void(__fastcall *)(void *frame, void *edx, uint32_t mask, int on); -using NotifyLayerChanged_t = void(__fastcall *)(void *frame, void *edx, int layer); using HitTest_t = int(__fastcall *)(void *frame, void *edx, const float *point); using Matrix_t = void(__fastcall *)(float *m); using GetViewport_t = void(__fastcall *)(float *minX, float *maxX, float *minY, float *maxY, float *minZ, @@ -345,7 +345,7 @@ const Game::HookAutoRegister _hitTestHook{Offsets::FUN_FRAME_HIT_TEST, reinterpr void MarkLayers(void *frame) { for (int layer = 0; layer < Offsets::FRAME_LAYER_COUNT; ++layer) - reinterpret_cast(Offsets::FUN_FRAME_NOTIFY_LAYER_CHANGED)(frame, nullptr, layer); + Frame::LayerChange::NotifyFrame(frame, layer); } // Marks every layer of each frame under `frame` changed. diff --git a/src/frame/Cooldown.cpp b/src/frame/Cooldown.cpp index ac26c483..d4f9543b 100644 --- a/src/frame/Cooldown.cpp +++ b/src/frame/Cooldown.cpp @@ -83,6 +83,7 @@ #include "api/Documentation.h" #include "cvar/Factory.h" #include "frame/ExtraScripts.h" +#include "frame/LayerChange.h" #include "frame/Region.h" #include "frame/RenderBatch.h" #include "frame/ScriptArgs.h" @@ -259,10 +260,7 @@ void Hide(void *frame) { Game::Read(Game::Read(frame, 0), Offsets::VTBL_FRAME_HIDE)(frame, nullptr); } -void NotifyLayerChanged(void *frame, int layer) { - using Fn_t = void(__fastcall *)(void *self, void *edx, int layer); - reinterpret_cast(Offsets::FUN_FRAME_NOTIFY_LAYER_CHANGED)(frame, nullptr, layer); -} +using Frame::LayerChange::NotifyFrame; // ---- textures --------------------------------------------------------------- @@ -482,7 +480,7 @@ void SetSlotTexture(void *frame, TextureSlot slot, const char *file, const uint3 if (base != nullptr) s.base = *base; f.texturesSet |= 1u << slot; - NotifyLayerChanged(frame, kSlotLayer[slot]); + NotifyFrame(frame, kSlotLayer[slot]); UpdateColors(frame); } @@ -976,7 +974,7 @@ int __fastcall Script_SetDrawSwipe(void *L) { const uint32_t drawSwipe = Game::Lua::ToFlag(L, 2, true); if (drawSwipe != f.drawSwipe) { f.drawSwipe = drawSwipe; - NotifyLayerChanged(frame, kSlotLayer[SLOT_SWIPE]); + NotifyFrame(frame, kSlotLayer[SLOT_SWIPE]); } return 0; } @@ -1238,7 +1236,7 @@ int __fastcall Script_SetDrawEdge(void *L) { const uint32_t drawEdge = Game::Lua::ToFlag(L, 2, true); if (drawEdge != f.drawEdge) { f.drawEdge = drawEdge; - NotifyLayerChanged(frame, kSlotLayer[SLOT_EDGE]); + NotifyFrame(frame, kSlotLayer[SLOT_EDGE]); } return 0; } diff --git a/src/frame/LayerChange.h b/src/frame/LayerChange.h new file mode 100644 index 00000000..ebf29d8f --- /dev/null +++ b/src/frame/LayerChange.h @@ -0,0 +1,37 @@ +// 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 engine's two draw-layer invalidates: what to call after a change to +// what a frame or a region draws, so the next batch rebuild picks it up. + +#include "Offsets.h" + +namespace Frame::LayerChange { + +// CSimpleFrame::NotifyLayerChanged (FUN_FRAME_NOTIFY_LAYER_CHANGED): one of +// the frame's own draw layers. +inline void NotifyFrame(void *frame, int layer) { + using Fn_t = void(__fastcall *)(void *frame, void *edx, int layer); + reinterpret_cast(Offsets::FUN_FRAME_NOTIFY_LAYER_CHANGED)(frame, nullptr, layer); +} + +// CScriptRegion::NotifyLayerChanged (FUN_REGION_NOTIFY_LAYER_CHANGED): the +// layer the region draws in. +inline void NotifyRegion(void *region) { + using Fn_t = void(__fastcall *)(void *region); + reinterpret_cast(Offsets::FUN_REGION_NOTIFY_LAYER_CHANGED)(region); +} + +} // namespace Frame::LayerChange diff --git a/src/model/Scene.cpp b/src/model/Scene.cpp index 9ddaa084..5db1e0e0 100644 --- a/src/model/Scene.cpp +++ b/src/model/Scene.cpp @@ -99,6 +99,7 @@ #include "Game.h" #include "Offsets.h" #include "api/Documentation.h" +#include "frame/LayerChange.h" #include "frame/Subclass.h" #include "model/Camera.h" #include "model/M2.h" @@ -719,11 +720,6 @@ int __fastcall GetCameraScalar(void *L) { return 1; } -void NotifyLayerChanged(void *frame, int layer) { - using Fn_t = void(__fastcall *)(void *self, void *edx, int layer); - reinterpret_cast(Offsets::FUN_FRAME_NOTIFY_LAYER_CHANGED)(frame, nullptr, layer); -} - int __fastcall Script_SetDrawLayer(void *L) { using LayerFromName_t = int(__fastcall *)(const char *name, int *layer); void *frame = Self(L); @@ -741,8 +737,8 @@ int __fastcall Script_SetDrawLayer(void *L) { return 0; const int old = f.drawLayer; f.drawLayer = layer; - NotifyLayerChanged(frame, old); - NotifyLayerChanged(frame, layer); + Frame::LayerChange::NotifyFrame(frame, old); + Frame::LayerChange::NotifyFrame(frame, layer); return 0; } diff --git a/src/text/InlineTexturePool.cpp b/src/text/InlineTexturePool.cpp index bb704a20..39a5578d 100644 --- a/src/text/InlineTexturePool.cpp +++ b/src/text/InlineTexturePool.cpp @@ -20,6 +20,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/LayerChange.h" #include "frame/Region.h" #include "frame/RegionDestruction.h" #include "text/PtrProbe.h" @@ -44,7 +45,6 @@ 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); 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). @@ -225,7 +225,7 @@ void ApplyPlacements(void *fs, FsPlacements &np, uint32_t fsColor) { np.shown = (want < static_cast(np.regions.size())) ? want : static_cast(np.regions.size()); - reinterpret_cast(Offsets::FUN_REGION_NOTIFY_LAYER_CHANGED)(fs); + Frame::LayerChange::NotifyRegion(fs); } // Per-frame tick (FrameTick — glue AND world): deletes orphaned textures. diff --git a/src/texture/Wrap.cpp b/src/texture/Wrap.cpp index 2ca7b40d..82f82fb8 100644 --- a/src/texture/Wrap.cpp +++ b/src/texture/Wrap.cpp @@ -43,6 +43,7 @@ #include "Game.h" #include "Offsets.h" +#include "frame/LayerChange.h" #include "texture/Atlas.h" #include "texture/Construct.h" #include "texture/Load.h" @@ -75,7 +76,6 @@ using SetTexture_t = uint32_t(__fastcall *)(void *texture, void *edx, const char uint32_t filter, uint32_t shader); using NameMatch_t = int(__fastcall *)(void *hTexture, const char *name); using GetUiPixelShader_t = void *(__fastcall *)(uint32_t index); -using NotifyLayerChanged_t = void(__fastcall *)(void *region); SetTexture_t g_origSetTexture = nullptr; @@ -108,7 +108,7 @@ uint32_t Load(void *texture, const char *name, bool repeatH, bool repeatV, uint3 reinterpret_cast(Offsets::FUN_UI_GET_PIXEL_SHADER)(shader); Texture::ReleaseHandle(held); Game::Ref(texture, Offsets::OFF_SIMPLETEXTURE_HTEXTURE) = image; - reinterpret_cast(Offsets::FUN_REGION_NOTIFY_LAYER_CHANGED)(texture); + Frame::LayerChange::NotifyRegion(texture); return 1; }