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.
This commit is contained in:
Brues
2026-11-08 11:41:00 -06:00
parent b35bbd1be4
commit 4d18fb833f
4 changed files with 18 additions and 12 deletions
+12
View File
@@ -102,6 +102,18 @@ inline void Attach(void *child, void *parent, uint32_t id) {
reinterpret_cast<Fn>(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<Fn>(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<Fn>(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.
+1 -3
View File
@@ -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<FindChild_t>(Offsets::FUN_M2MODEL_FIND_CHILD)(model,
attachId))
if (void *item = M2::FindChild(model, attachId))
M2::AttachItemVisuals(item, visual);
}
+3 -5
View File
@@ -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<SetDiffuse_t>(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<FindChild_t>(Offsets::FUN_M2MODEL_FIND_CHILD);
const auto closeHand = reinterpret_cast<CloseHand_t>(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);
+2 -4
View File
@@ -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<float>((color >> 16) & 0xFF) * kByteScale,
static_cast<float>((color >> 8) & 0xFF) * kByteScale,
static_cast<float>(color & 0xFF) * kByteScale};
reinterpret_cast<SetDiffuse_t>(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<SetAlpha_t>(Offsets::FUN_M2MODEL_SET_ALPHA)(model, alpha);
M2::SetAlpha(model, alpha);
}
}
}