mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
feat(model): aura visuals play their state kit's sound
A 1.12.1 kit plays its sound (+0x34) once per play: the first effect it makes carries the play's flag word, and PlayUnitSpellVisualKit (0x0060EDF0) ORs 0x400, "no kit sound", into its own word after that, so only that effect's one-time arm pass sounds (0x00620C10 to 0x006210B9); a kit that made no effect plays it at the end of 0x0060EDF0 (0x0060F434 to 0x0060F4BC). For a lasting kit (kinds 2 to 4) whose definition has bit 0x200 (GetSoundDefFlag200 0x00458830) the sound loops on the unit (AddEffectSound 0x0061FEC0 -> PlaySoundLoop3D) until CEffect::Stop stops it with a 0.15 s fade (push 0x3E19999A before Sound::Stop2 at 0x006204B6). A definition with bit 0x20 asks every play path for the duplicate check (0x00458F40, called from InternalPlaySoundAt at 0x0045CF5B and from PlaySoundLoop3D), so it plays once however many units show it at once. AddAuraVisual now plays its state kit's sound at the actor when the aura shows, or loops it there for a 0x200 sound, following the actor, quiet while the scene or actor is paused and while the scene is hidden, and fading out with the aura. The loop test and the fade move to the scene's Sounds module (Sounds::KitLoops, Sounds::kStopFadeSec), which the casts' channel and missile sounds share.
This commit is contained in:
+4
-1
@@ -20642,7 +20642,10 @@ aura visual. The effects of the aura stay on the actor until
|
||||
actor. Some auras also leave an effect on the ground where the actor
|
||||
stands. The ground effect of a spell that roots, for example the ice of
|
||||
Frost Nova, moves with the actor. Some auras also change the color of the
|
||||
actor.
|
||||
actor. The sound of the aura plays when it shows, from the actor. A few
|
||||
auras repeat their sound until they end. A sound that does not play twice
|
||||
at once in the world, for example the crack of Frost Nova's ice, plays one
|
||||
time when many actors get the aura together.
|
||||
|
||||
Some auras also have an animation, for example the stun of a stun aura.
|
||||
While the actor does not move, it plays the animation of its newest aura
|
||||
|
||||
@@ -1080,6 +1080,7 @@ int __fastcall Hide(void *self, void *) {
|
||||
for (Actor *actor : *F(self).actors) {
|
||||
Casts::Silence(*actor);
|
||||
Areas::Silence(*actor);
|
||||
AuraVisuals::Silence(*actor);
|
||||
}
|
||||
return g_class.Base<Hide_t>(Offsets::VTBL_FRAME_HIDE)(self, nullptr);
|
||||
}
|
||||
|
||||
+15
-1
@@ -160,6 +160,10 @@ struct AuraVisual {
|
||||
float worldYaw = 0.0f;
|
||||
float worldScale = 1.0f;
|
||||
bool worldFollows = false;
|
||||
// The kit's sound when it loops (Sounds::KitLoops): its ID, and the loop
|
||||
// playing at the actor (null while the scene is paused or hidden).
|
||||
int loopSoundID = 0;
|
||||
void *loopSound = nullptr;
|
||||
};
|
||||
|
||||
// The area kit of a spell's ground area while it runs: the shard emitter
|
||||
@@ -495,10 +499,13 @@ void ApplyColors(Actor &actor);
|
||||
// kit's, ApplyEffectAnimation 0x005FDE80), or -1.
|
||||
int PinnedAnimation(const Actor &actor);
|
||||
// From the actor's update, link and place: the world effects' light,
|
||||
// visibility and placement.
|
||||
// visibility and placement, and the loop sounds' place and pause.
|
||||
void Update(Actor &actor, float elapsedSec);
|
||||
void Link(Actor &actor);
|
||||
void Place(Actor &actor);
|
||||
// Stops the loop sounds (the scene hid; its update stops). The update starts
|
||||
// them again.
|
||||
void Silence(Actor &actor);
|
||||
} // namespace AuraVisuals
|
||||
|
||||
// The area kit of an actor that shows a spell's ground area
|
||||
@@ -700,6 +707,13 @@ void Heard(void *sceneFrame, const float (&point)[3], float (&out)[3]);
|
||||
void *Play(void *sceneFrame, int soundKitID, const float (&point)[3]);
|
||||
void *Loop(void *sceneFrame, int soundKitID, const float (&point)[3]);
|
||||
void Move(void *sceneFrame, void *sound, const float (&point)[3]);
|
||||
// A sound's fade when its effect or missile stops: CEffect::Stop's `push
|
||||
// 0x3E19999A` before Sound::Stop2 (0x006204B6) and the missile's free
|
||||
// (0x0061CD70).
|
||||
constexpr float kStopFadeSec = 0.15f;
|
||||
// Whether a lasting kit (kinds 2 to 4) loops the sound rather than playing
|
||||
// it once: bit 0x200 of its SoundEntries flags (FUN_SOUND_DEFINITION_KIT_LOOP).
|
||||
bool KitLoops(int soundID);
|
||||
} // namespace Sounds
|
||||
|
||||
// The scene camera (model/Scene.cpp).
|
||||
|
||||
+43
-2
@@ -38,8 +38,14 @@
|
||||
// stunned actor stands stunned. An aura's end does not pick again; its
|
||||
// animation plays on until its sequence ends, as on a unit.
|
||||
//
|
||||
// What the world does and this does not: the state kit's sound, and the
|
||||
// auras' priorities and visions (a scene shows every aura it is given).
|
||||
// The kit's sound plays once per play at the actor (the first effect's arm
|
||||
// pass, 0x00620C10 to 0x006210B9), or loops on it when its definition has
|
||||
// bit 0x200 (AddEffectSound 0x0061FEC0) until the aura's end stops it with
|
||||
// CEffect::Stop's fade. A definition with no-duplicates (0x20), as Frost
|
||||
// Nova's and Fear's, plays once however many actors show it at once.
|
||||
//
|
||||
// What the world does and this does not: the auras' priorities and visions
|
||||
// (a scene shows every aura it is given).
|
||||
|
||||
#include "model/Scene.h"
|
||||
|
||||
@@ -48,6 +54,7 @@
|
||||
#include "dbc/Lookup.h"
|
||||
#include "model/M2.h"
|
||||
#include "model/VisualKit.h"
|
||||
#include "sound/Play.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
@@ -87,6 +94,15 @@ void ShowOne(Actor &actor, AuraVisual &aura) {
|
||||
aura.shown = true;
|
||||
void *frame = actor.SceneFrame();
|
||||
Model::VisualKit::Apply(frame, actor.model, aura.kit, false, &aura.effects);
|
||||
// The kit's sound, once per play: a looping one stays on the unit until
|
||||
// the aura's effects stop.
|
||||
const auto sound = Game::Read<int32_t>(aura.kit, Offsets::OFF_SPELLVISUALKIT_SOUND);
|
||||
if (Sounds::KitLoops(sound)) {
|
||||
aura.loopSoundID = sound;
|
||||
aura.loopSound = Sounds::Loop(frame, sound, actor.position);
|
||||
} else if (sound > 0) {
|
||||
Sounds::Play(frame, sound, actor.position);
|
||||
}
|
||||
const uint8_t *effect =
|
||||
DBC::Record(Offsets::VAR_SPELLVISUALEFFECTNAME_RECORDS, Offsets::VAR_SPELLVISUALEFFECTNAME_COUNT,
|
||||
Game::Read<uint32_t>(aura.kit, Offsets::OFF_SPELLVISUALKIT_WORLD_EFFECT));
|
||||
@@ -109,6 +125,10 @@ void ShowOne(Actor &actor, AuraVisual &aura) {
|
||||
// model.
|
||||
void HideOne(Actor &actor, AuraVisual &aura, bool stop) {
|
||||
void *frame = actor.SceneFrame();
|
||||
if (aura.loopSound != nullptr)
|
||||
Sound::Play::Stop(aura.loopSound, stop ? Sounds::kStopFadeSec : 0.0f);
|
||||
aura.loopSound = nullptr;
|
||||
aura.loopSoundID = 0;
|
||||
for (void *effect : aura.effects) {
|
||||
if (stop) {
|
||||
Model::VisualKit::Stop(frame, effect);
|
||||
@@ -211,10 +231,30 @@ void ApplyColors(Actor &actor) {
|
||||
}
|
||||
}
|
||||
|
||||
// The world has no pause; a paused scene (or actor) silences the loops, which
|
||||
// start again when the pause ends, as a hidden scene's do when it shows.
|
||||
void Update(Actor &actor, float elapsedSec) {
|
||||
const bool held = IsPaused(actor.SceneFrame()) || actor.paused || actor.globalPaused;
|
||||
for (AuraVisual &aura : actor.auraVisuals) {
|
||||
if (aura.worldEffect != nullptr)
|
||||
SettleLight(aura.worldEffect, aura.worldLight.get(), elapsedSec);
|
||||
if (aura.loopSoundID == 0)
|
||||
continue;
|
||||
if (held && aura.loopSound != nullptr) {
|
||||
Sound::Play::Stop(aura.loopSound, 0.0f);
|
||||
aura.loopSound = nullptr;
|
||||
} else if (!held && aura.loopSound == nullptr) {
|
||||
aura.loopSound = Sounds::Loop(actor.SceneFrame(), aura.loopSoundID, actor.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Silence(Actor &actor) {
|
||||
for (AuraVisual &aura : actor.auraVisuals) {
|
||||
if (aura.loopSound != nullptr) {
|
||||
Sound::Play::Stop(aura.loopSound, 0.0f);
|
||||
aura.loopSound = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +270,7 @@ void Link(Actor &actor) {
|
||||
void Place(Actor &actor) {
|
||||
const float axisZ[3] = {0.0f, 0.0f, 1.0f};
|
||||
for (AuraVisual &aura : actor.auraVisuals) {
|
||||
Sounds::Move(actor.SceneFrame(), aura.loopSound, actor.position);
|
||||
if (aura.worldEffect == nullptr)
|
||||
continue;
|
||||
if (aura.worldFollows) {
|
||||
|
||||
@@ -141,6 +141,14 @@ void *Loop(void *sceneFrame, int soundKitID, const float (&point)[3]) {
|
||||
return Sound::Play::PlayKitLoopedAt(soundKitID, heard);
|
||||
}
|
||||
|
||||
bool KitLoops(int soundID) {
|
||||
using Flag_t = bool(__fastcall *)(uint32_t id, char *out);
|
||||
char loops = 0;
|
||||
return soundID > 0 &&
|
||||
reinterpret_cast<Flag_t>(Offsets::FUN_SOUND_DEFINITION_KIT_LOOP)(static_cast<uint32_t>(soundID), &loops) &&
|
||||
loops != 0;
|
||||
}
|
||||
|
||||
void Move(void *sceneFrame, void *sound, const float (&point)[3]) {
|
||||
if (sound == nullptr)
|
||||
return;
|
||||
|
||||
@@ -155,7 +155,6 @@ constexpr int kAnimCombatWound = 9;
|
||||
constexpr int kAnimInFlight = 144;
|
||||
constexpr float kReleaseTimeoutSec = 2.0f; // 0x0060A814
|
||||
constexpr float kMaxSpeed = 100.0f; // 0x0080C854
|
||||
constexpr float kSoundFadeSec = 0.15f; // the missile's free, 0x0061CD70
|
||||
const Game::Live<float> kAimHeight{Offsets::VAR_THREE_QUARTERS};
|
||||
constexpr uint32_t kFallbackAttachments[] = {15, 19};
|
||||
constexpr char kErrorCube[] = "Spells\\ErrorCube.mdx";
|
||||
@@ -188,15 +187,6 @@ bool ChainLoaded(void *model) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Whether a kit's sound loops with a lasting kit (FUN_SOUND_DEFINITION_KIT_LOOP).
|
||||
bool KitSoundLoops(int soundID) {
|
||||
using Flag_t = bool(__fastcall *)(uint32_t id, char *out);
|
||||
char loops = 0;
|
||||
return soundID > 0 &&
|
||||
reinterpret_cast<Flag_t>(Offsets::FUN_SOUND_DEFINITION_KIT_LOOP)(static_cast<uint32_t>(soundID), &loops) &&
|
||||
loops != 0;
|
||||
}
|
||||
|
||||
// The world's kit player on a unit, for a model: the effects (looping into
|
||||
// `effects`, or once and owned by the model), the animation and the sound.
|
||||
// A lasting kit (`loop`) records the animation it made the caster's loop,
|
||||
@@ -213,7 +203,7 @@ void PlayKit(Actor &actor, const uint8_t *kit, std::vector<void *> *effects, Spe
|
||||
loop->animation = anim;
|
||||
}
|
||||
const int sound = Game::Read<int32_t>(kit, Offsets::OFF_SPELLVISUALKIT_SOUND);
|
||||
if (lasting && KitSoundLoops(sound)) {
|
||||
if (lasting && Sounds::KitLoops(sound)) {
|
||||
loop->soundID = sound;
|
||||
loop->sound = Sounds::Loop(actor.SceneFrame(), sound, actor.position);
|
||||
} else {
|
||||
@@ -411,7 +401,7 @@ void FreeStuck(StuckMissile &stuck) {
|
||||
// over it (a wound) plays on.
|
||||
void EndKitLoop(Actor &caster, std::vector<void *> &effects, bool &tinted, SpellCast::KitLoop &loop) {
|
||||
if (loop.sound != nullptr) {
|
||||
Sound::Play::Stop(loop.sound, kSoundFadeSec);
|
||||
Sound::Play::Stop(loop.sound, Sounds::kStopFadeSec);
|
||||
loop.sound = nullptr;
|
||||
}
|
||||
loop.soundID = 0;
|
||||
@@ -451,7 +441,7 @@ void EndChannel(Actor &caster, SpellCast &cast) {
|
||||
|
||||
void StopMissileSound(SpellCast &cast) {
|
||||
if (cast.missileSound != nullptr) {
|
||||
Sound::Play::Stop(cast.missileSound, kSoundFadeSec);
|
||||
Sound::Play::Stop(cast.missileSound, Sounds::kStopFadeSec);
|
||||
cast.missileSound = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user