refactor(texture): shared hooks for the texture constructor and corner store

MinHook takes one hook per address. Texture::Mask hooked the
CSimpleTexture constructor (0x0076FC40) to drop its state when pool memory
is reused, and Texture::Transform hooked the corner store (0x007705B0) to
turn the quad again after each layout. Texture wrap modes and tiling need
both hooks too, so each hook now has an owner that fans out to listeners:

- Texture::Construct runs its listeners before the constructor, on the
  memory it is about to build. Mask listens.
- Texture::CornerStore runs its listeners after the store. Transform
  listens.

The store writes only the corners. The layer batch reads them through a
pointer on every draw, so nothing marks the layer changed.

The XML number parse through SStrToFloat (0x0064AAA0) moves into
Xml::FloatAttr, which NativeSetters and Transform's rotation attributes
now share.
This commit is contained in:
Brues
2026-11-01 18:30:32 -06:00
parent eb0b70bc5e
commit b032dc09ac
11 changed files with 206 additions and 66 deletions
+19 -27
View File
@@ -49,7 +49,7 @@
// co-hook on the indexed submit pops the matrices and the state journal after
// the draw, exactly the op order of the engine's own disc draw.
//
// A cold co-hook on the region ctor clears a region's mask state when its
// A Texture::Construct listener clears a region's mask state when its
// pooled memory is reused, so a recycled region can never inherit (or serve) a
// stale mask. Kill switch `_classicapi_TextureMaskEnable`; an SEH latch trips
// it on a draw fault.
@@ -57,6 +57,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/AlphaGradient.h"
#include "texture/Construct.h"
#include "texture/Load.h"
#include "texture/Mask.h"
#include "texture/Transform.h"
@@ -437,37 +438,28 @@ static const Game::HookAutoRegister _primIdxHook{
Offsets::FUN_GX_PRIM_INDEXED, reinterpret_cast<void *>(&PrimIndexed_h),
reinterpret_cast<void **>(&g_primIndexedOriginal)};
// --- region ctor co-hook: drop a stale mask on pooled reuse ------------------
// --- region construction: drop a stale mask on pooled reuse ------------------
// __thiscall(mem, parent, layer, sublayer) -> region; dummy-EDX __fastcall.
using Ctor_t = void *(__fastcall *)(void *mem, void *edx, void *parent, int layer, int sublayer);
Ctor_t g_ctorOriginal = nullptr;
void *__fastcall Ctor_h(void *mem, void *edx, void *parent, int layer, int sublayer) {
if (mem != nullptr) {
// A (re)constructed region owns no mask and is no longer a mask source.
ClearPathMask(mem);
g_baseMasks.erase(mem);
// If the recycled memory WAS a mask region, detach it from every base
// still holding it — otherwise the draw hook would read the recycled
// region as a mask (stale rect/texture at best, garbage at worst).
if (g_maskRegions.erase(mem) != 0 && !g_baseMasks.empty()) {
for (auto it = g_baseMasks.begin(); it != g_baseMasks.end();) {
auto &v = it->second;
v.erase(std::remove(v.begin(), v.end(), mem), v.end());
if (v.empty())
it = g_baseMasks.erase(it);
else
++it;
}
void OnTextureConstructed(void *mem) {
// A (re)constructed region owns no mask and is no longer a mask source.
ClearPathMask(mem);
g_baseMasks.erase(mem);
// If the recycled memory WAS a mask region, detach it from every base
// still holding it — otherwise the draw hook would read the recycled
// region as a mask (stale rect/texture at best, garbage at worst).
if (g_maskRegions.erase(mem) != 0 && !g_baseMasks.empty()) {
for (auto it = g_baseMasks.begin(); it != g_baseMasks.end();) {
auto &v = it->second;
v.erase(std::remove(v.begin(), v.end(), mem), v.end());
if (v.empty())
it = g_baseMasks.erase(it);
else
++it;
}
}
return g_ctorOriginal(mem, edx, parent, layer, sublayer);
}
static const Game::HookAutoRegister _ctorHook{Offsets::FUN_SIMPLETEXTURE_CTOR,
reinterpret_cast<void *>(&Ctor_h),
reinterpret_cast<void **>(&g_ctorOriginal)};
static const Texture::Construct::AutoSubscribe _constructSub{&OnTextureConstructed};
// --- Lua surface -------------------------------------------------------------