From 4d18fb833ff35c53cefcdb7825e0bfda731e9776 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 7 Nov 2026 10:16:18 -0600 Subject: [PATCH] refactor(model): call the M2 tint, alpha and child lookup through M2.h CM2Model's SetDiffuseColor (FUN_M2MODEL_SET_DIFFUSE_COLOR, 0x00710CF0) was wrapped by hand in VisualKit and SceneActor, FindChild (FUN_M2MODEL_FIND_CHILD, 0x00712F00) in Outfit and SceneActor, and VisualKit called SetAlpha (FUN_M2MODEL_SET_ALPHA, 0x00710CB0) directly next to the M2::SetAlpha wrapper. M2.h gains SetDiffuse and FindChild, and the three files call M2:: for all three. --- src/model/M2.h | 12 ++++++++++++ src/model/Outfit.cpp | 4 +--- src/model/SceneActor.cpp | 8 +++----- src/model/VisualKit.cpp | 6 ++---- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/model/M2.h b/src/model/M2.h index 8810a686..a52dfad2 100644 --- a/src/model/M2.h +++ b/src/model/M2.h @@ -102,6 +102,18 @@ inline void Attach(void *child, void *parent, uint32_t id) { reinterpret_cast(Offsets::FUN_M2MODEL_ATTACH)(child, parent, id); } +// The tint the model is drawn with, {r, g, b}; white is none. +inline void SetDiffuse(void *model, const float (&rgb)[3]) { + using Fn = void(__thiscall *)(void *, const float *); + reinterpret_cast(Offsets::FUN_M2MODEL_SET_DIFFUSE_COLOR)(model, rgb); +} + +// CM2Model::FindChild: the model hung at attachment `attachId`, or null. +inline void *FindChild(void *model, int attachId) { + using Fn = void *(__thiscall *)(void *, int); + return reinterpret_cast(Offsets::FUN_M2MODEL_FIND_CHILD)(model, attachId); +} + // CM2Model::Detach, when the model is attached: off its parent, which drops // its reference on it. Detach itself drops that reference unconditionally, // so the world's Dismount (0x00607CE0) tests the parent first, as this does. diff --git a/src/model/Outfit.cpp b/src/model/Outfit.cpp index e3330f9c..d7e19207 100644 --- a/src/model/Outfit.cpp +++ b/src/model/Outfit.cpp @@ -37,7 +37,6 @@ using AttachItemModel_t = int(__fastcall *)(void *model, const void *record, uin bool ranged); using GetHeldItemDisplay_t = const void *(__thiscall *)(void *unit, uint32_t hand); using GetHeldItemLane_t = const HeldLane *(__thiscall *)(void *unit, uint32_t hand, int one); -using FindChild_t = void *(__thiscall *)(void *model, int attachId); using GetVisibleItem_t = const void *(__thiscall *)(void *player, uint32_t slot); using GetDescVisual_t = int(__thiscall *)(const void *visibleItem); using CharCompCreate_t = void *(__cdecl *)(); @@ -136,8 +135,7 @@ void *CloneComponent(void *model, void *unit) { void HangVisual(void *model, int attachId, uint32_t visual) { if (visual == 0 || attachId < 0) return; - if (void *item = reinterpret_cast(Offsets::FUN_M2MODEL_FIND_CHILD)(model, - attachId)) + if (void *item = M2::FindChild(model, attachId)) M2::AttachItemVisuals(item, visual); } diff --git a/src/model/SceneActor.cpp b/src/model/SceneActor.cpp index 92f41906..58d465cc 100644 --- a/src/model/SceneActor.cpp +++ b/src/model/SceneActor.cpp @@ -154,7 +154,6 @@ void __fastcall OnAnimDone(void * /*model*/, uint32_t /*keyBone*/, uint32_t /*an // Takes the kit's effects off the model and undoes its tint. void DropKitEffects(Actor &actor) { - using SetDiffuse_t = void(__thiscall *)(void *model, const float *rgb); for (void *effect : actor.kitEffects) { M2::Detach(effect); M2::Release(effect); @@ -162,7 +161,7 @@ void DropKitEffects(Actor &actor) { actor.kitEffects.clear(); if (actor.model != nullptr) { const float white[3] = {1.0f, 1.0f, 1.0f}; - reinterpret_cast(Offsets::FUN_M2MODEL_SET_DIFFUSE_COLOR)(actor.model, white); + M2::SetDiffuse(actor.model, white); actor.ApplyAlpha(); } } @@ -241,11 +240,10 @@ bool Actor::SetUnitModel(uint64_t guid) { dresser = Outfit::CloneComponent(copy, unit); Outfit::ReadLanes(unit, lanes); Outfit::ReadWeapons(guid, weapons); - const auto findChild = reinterpret_cast(Offsets::FUN_M2MODEL_FIND_CHILD); const auto closeHand = reinterpret_cast(Offsets::FUN_CLOSE_HAND); - if (findChild(copy, 2) != nullptr) + if (M2::FindChild(copy, 2) != nullptr) closeHand(copy, 1); - if (findChild(copy, 1) != nullptr) + if (M2::FindChild(copy, 1) != nullptr) closeHand(copy, 0); if (autoDress) Outfit::HangWeapons(copy, lanes, weapons, sheathed, hideWeapons); diff --git a/src/model/VisualKit.cpp b/src/model/VisualKit.cpp index 291f5220..c87c0ed8 100644 --- a/src/model/VisualKit.cpp +++ b/src/model/VisualKit.cpp @@ -62,8 +62,6 @@ namespace Model::VisualKit { namespace { using HasAttachment_t = int(__thiscall *)(void *model, uint32_t id); -using SetAlpha_t = void(__thiscall *)(void *model, float alpha); -using SetDiffuse_t = void(__thiscall *)(void *model, const float *rgb); using HasLiveParticles_t = int(__thiscall *)(void *model); // The attachment of each effect column, in the ghost kit's order. @@ -154,10 +152,10 @@ void ApplyProcedures(void *model, const uint8_t *kit) { const float rgb[3] = {static_cast((color >> 16) & 0xFF) * kByteScale, static_cast((color >> 8) & 0xFF) * kByteScale, static_cast(color & 0xFF) * kByteScale}; - reinterpret_cast(Offsets::FUN_M2MODEL_SET_DIFFUSE_COLOR)(model, rgb); + M2::SetDiffuse(model, rgb); } else if (kind == kProcAlpha) { const float alpha = value < 0.0f ? 0.0f : value > 1.0f ? 1.0f : value; - reinterpret_cast(Offsets::FUN_M2MODEL_SET_ALPHA)(model, alpha); + M2::SetAlpha(model, alpha); } } }