diff --git a/src/model/M2.h b/src/model/M2.h index a52dfad2..281cd73c 100644 --- a/src/model/M2.h +++ b/src/model/M2.h @@ -50,6 +50,19 @@ inline void *CreateModel(void *scene, const char *path) { return reinterpret_cast(Offsets::FUN_M2SCENE_CREATE_MODEL)(scene, path, 0); } +// A new instance of `source`'s model in `scene` without its item attachments +// (helm, shoulders, held items), the way the portrait bake copies a unit: +// CreateModelFromModel (FUN_M2SCENE_COPY_MODEL), then DetachAllItemModels +// (FUN_DETACH_ALL_ITEM_MODELS). The caller owns one reference, or null. +inline void *CopyWithoutItems(void *scene, void *source) { + using Copy_t = void *(__thiscall *)(void *, void *, uint32_t); + using DetachAll_t = void(__fastcall *)(void *); + void *copy = reinterpret_cast(Offsets::FUN_M2SCENE_COPY_MODEL)(scene, source, 0); + if (copy != nullptr) + reinterpret_cast(Offsets::FUN_DETACH_ALL_ITEM_MODELS)(copy); + return copy; +} + inline void PlayAnimation(void *model, int keyBone, uint32_t id, int variation, int offset, float speed, int blend, int primary) { using Fn = void(__thiscall *)(void *, int, uint32_t, int, int, float, int, int); @@ -89,6 +102,18 @@ inline void SetAlpha(void *model, float alpha) { reinterpret_cast(Offsets::FUN_M2MODEL_SET_ALPHA)(model, alpha); } +// 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); +} + // The model this one is attached to, or null. inline void *Parent(const void *model) { return Game::Read(model, Offsets::OFF_M2MODEL_PARENT); @@ -102,18 +127,6 @@ 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/Portrait.cpp b/src/model/Portrait.cpp index 7703adaa..79ccefa0 100644 --- a/src/model/Portrait.cpp +++ b/src/model/Portrait.cpp @@ -71,8 +71,6 @@ constexpr uint32_t kTexels = kSize * kSize; using CreateScene_t = void *(__cdecl *)(); using ReleaseScene_t = void(__thiscall *)(void *scene); -using CopyModel_t = void *(__thiscall *)(void *scene, void *source, uint32_t flags); -using DetachAll_t = void(__fastcall *)(void *model); using DrawScene_t = void(__thiscall *)(void *scene, uint32_t pass); using SetTransforms_t = void(__fastcall *)(void *camera, const float *rect, uint32_t unused); using GetMatrix_t = void(__fastcall *)(float *m); @@ -149,12 +147,11 @@ bool Bake(Portrait &p) { void *scene = reinterpret_cast(Offsets::FUN_M2_CREATE_SCENE)(); if (scene == nullptr) return false; - void *copy = reinterpret_cast(Offsets::FUN_M2SCENE_COPY_MODEL)(scene, source, 0); + void *copy = M2::CopyWithoutItems(scene, source); if (copy == nullptr) { reinterpret_cast(Offsets::FUN_M2SCENE_RELEASE)(scene); return false; } - reinterpret_cast(Offsets::FUN_DETACH_ALL_ITEM_MODELS)(copy); void *camera = Model::Camera::CameraById(copy, 0); M2::PlayAnimation(copy, -1, 0, 0, 0, 1.0f, 0, 1); diff --git a/src/model/SceneActor.cpp b/src/model/SceneActor.cpp index 58d465cc..a70a3e7d 100644 --- a/src/model/SceneActor.cpp +++ b/src/model/SceneActor.cpp @@ -220,9 +220,6 @@ void Actor::SetModel(void *newModel, const char *path, const uint8_t *newDressRe } bool Actor::SetUnitModel(uint64_t guid) { - using CopyModel_t = void *(__thiscall *)(void *scene, void *source, uint32_t flags); - using DetachAll_t = void(__fastcall *)(void *model); - using FindChild_t = void *(__thiscall *)(void *model, int attachId); using CloseHand_t = void(__fastcall *)(void *model, uint32_t hand); ClearModel(); void *unit = guid != 0 ? ::Object::ByGuid(Offsets::TYPEMASK_UNIT, guid) : nullptr; @@ -231,11 +228,9 @@ bool Actor::SetUnitModel(uint64_t guid) { return false; if (void *own = Game::Read(unit, Offsets::OFF_CGUNIT_CHARACTER_COMPONENT)) Model::DisplayInfo::PumpDresser(own, true); - void *copy = reinterpret_cast(Offsets::FUN_M2SCENE_COPY_MODEL)( - Model::Pane::Scene(SceneFrame()), source, 0); + void *copy = M2::CopyWithoutItems(Model::Pane::Scene(SceneFrame()), source); if (copy == nullptr) return false; - reinterpret_cast(Offsets::FUN_DETACH_ALL_ITEM_MODELS)(copy); unitGuid = guid; dresser = Outfit::CloneComponent(copy, unit); Outfit::ReadLanes(unit, lanes);