mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
refactor(model): one copy of a unit's model without its items
The portrait bake and the ModelScene actor's SetModelByUnit both copied a unit's model with CreateModelFromModel (FUN_M2SCENE_COPY_MODEL, 0x00707400, flags 0) and stripped the copy's helm, shoulders and held items with DetachAllItemModels (FUN_DETACH_ALL_ITEM_MODELS, 0x0047A230), each with its own typedefs. M2::CopyWithoutItems does the two steps; both callers use it.
This commit is contained in:
+25
-12
@@ -50,6 +50,19 @@ inline void *CreateModel(void *scene, const char *path) {
|
||||
return reinterpret_cast<Fn>(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<Copy_t>(Offsets::FUN_M2SCENE_COPY_MODEL)(scene, source, 0);
|
||||
if (copy != nullptr)
|
||||
reinterpret_cast<DetachAll_t>(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<Fn>(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<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);
|
||||
}
|
||||
|
||||
// The model this one is attached to, or null.
|
||||
inline void *Parent(const void *model) {
|
||||
return Game::Read<void *>(model, Offsets::OFF_M2MODEL_PARENT);
|
||||
@@ -102,18 +127,6 @@ 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.
|
||||
|
||||
@@ -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<CreateScene_t>(Offsets::FUN_M2_CREATE_SCENE)();
|
||||
if (scene == nullptr)
|
||||
return false;
|
||||
void *copy = reinterpret_cast<CopyModel_t>(Offsets::FUN_M2SCENE_COPY_MODEL)(scene, source, 0);
|
||||
void *copy = M2::CopyWithoutItems(scene, source);
|
||||
if (copy == nullptr) {
|
||||
reinterpret_cast<ReleaseScene_t>(Offsets::FUN_M2SCENE_RELEASE)(scene);
|
||||
return false;
|
||||
}
|
||||
reinterpret_cast<DetachAll_t>(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);
|
||||
|
||||
|
||||
@@ -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<void *>(unit, Offsets::OFF_CGUNIT_CHARACTER_COMPONENT))
|
||||
Model::DisplayInfo::PumpDresser(own, true);
|
||||
void *copy = reinterpret_cast<CopyModel_t>(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<DetachAll_t>(Offsets::FUN_DETACH_ALL_ITEM_MODELS)(copy);
|
||||
unitGuid = guid;
|
||||
dresser = Outfit::CloneComponent(copy, unit);
|
||||
Outfit::ReadLanes(unit, lanes);
|
||||
|
||||
Reference in New Issue
Block a user