mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 17:43:52 +00:00
Wire SMSG_PLAY_MUSIC to MusicManager via SoundEntries.dbc lookup
Add PlayMusicCallback to GameHandler so SMSG_PLAY_MUSIC (and the vanilla 0x0103 alias) dispatch a soundId to the registered handler instead of being silently consumed. Application.cpp registers the callback, loads SoundEntries.dbc, resolves the first non-empty Name+DirectoryBase into an MPQ path, and passes it to MusicManager for non-looping playback. Resolves the TODO in the SMSG_PLAY_MUSIC handler.
This commit is contained in:
parent
ab32ec8933
commit
4e3d50fc20
3 changed files with 37 additions and 2 deletions
|
|
@ -937,6 +937,12 @@ public:
|
||||||
using AchievementEarnedCallback = std::function<void(uint32_t achievementId)>;
|
using AchievementEarnedCallback = std::function<void(uint32_t achievementId)>;
|
||||||
void setAchievementEarnedCallback(AchievementEarnedCallback cb) { achievementEarnedCallback_ = std::move(cb); }
|
void setAchievementEarnedCallback(AchievementEarnedCallback cb) { achievementEarnedCallback_ = std::move(cb); }
|
||||||
|
|
||||||
|
// Server-triggered music callback — fires when SMSG_PLAY_MUSIC is received.
|
||||||
|
// The soundId corresponds to a SoundEntries.dbc record. The receiver is
|
||||||
|
// responsible for looking up the file path and forwarding to MusicManager.
|
||||||
|
using PlayMusicCallback = std::function<void(uint32_t soundId)>;
|
||||||
|
void setPlayMusicCallback(PlayMusicCallback cb) { playMusicCallback_ = std::move(cb); }
|
||||||
|
|
||||||
// Mount state
|
// Mount state
|
||||||
using MountCallback = std::function<void(uint32_t mountDisplayId)>; // 0 = dismount
|
using MountCallback = std::function<void(uint32_t mountDisplayId)>; // 0 = dismount
|
||||||
void setMountCallback(MountCallback cb) { mountCallback_ = std::move(cb); }
|
void setMountCallback(MountCallback cb) { mountCallback_ = std::move(cb); }
|
||||||
|
|
@ -2088,6 +2094,9 @@ private:
|
||||||
|
|
||||||
// ---- Forced faction reactions (SMSG_SET_FORCED_REACTIONS) ----
|
// ---- Forced faction reactions (SMSG_SET_FORCED_REACTIONS) ----
|
||||||
std::unordered_map<uint32_t, uint8_t> forcedReactions_; // factionId -> reaction tier
|
std::unordered_map<uint32_t, uint8_t> forcedReactions_; // factionId -> reaction tier
|
||||||
|
|
||||||
|
// ---- Server-triggered music ----
|
||||||
|
PlayMusicCallback playMusicCallback_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
|
|
|
||||||
|
|
@ -2096,6 +2096,31 @@ void Application::setupUICallbacks() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Server-triggered music callback (SMSG_PLAY_MUSIC)
|
||||||
|
// Resolves soundId → SoundEntries.dbc → MPQ path → MusicManager.
|
||||||
|
gameHandler->setPlayMusicCallback([this](uint32_t soundId) {
|
||||||
|
if (!assetManager || !renderer) return;
|
||||||
|
auto* music = renderer->getMusicManager();
|
||||||
|
if (!music) return;
|
||||||
|
|
||||||
|
auto dbc = assetManager->loadDBC("SoundEntries.dbc");
|
||||||
|
if (!dbc || !dbc->isLoaded()) return;
|
||||||
|
|
||||||
|
int32_t idx = dbc->findRecordById(soundId);
|
||||||
|
if (idx < 0) return;
|
||||||
|
|
||||||
|
// SoundEntries.dbc (WotLK): fields 2-11 = Name[0..9], field 22 = DirectoryBase
|
||||||
|
const uint32_t row = static_cast<uint32_t>(idx);
|
||||||
|
std::string dir = dbc->getString(row, 22);
|
||||||
|
for (uint32_t f = 2; f <= 11; ++f) {
|
||||||
|
std::string name = dbc->getString(row, f);
|
||||||
|
if (name.empty()) continue;
|
||||||
|
std::string path = dir.empty() ? name : dir + "\\" + name;
|
||||||
|
music->playMusic(path, /*loop=*/false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Other player level-up callback — trigger 3D effect + chat notification
|
// Other player level-up callback — trigger 3D effect + chat notification
|
||||||
gameHandler->setOtherPlayerLevelUpCallback([this](uint64_t guid, uint32_t newLevel) {
|
gameHandler->setOtherPlayerLevelUpCallback([this](uint64_t guid, uint32_t newLevel) {
|
||||||
if (!gameHandler || !renderer) return;
|
if (!gameHandler || !renderer) return;
|
||||||
|
|
|
||||||
|
|
@ -1174,6 +1174,7 @@ void GameHandler::handlePacket(network::Packet& packet) {
|
||||||
if (packet.getSize() - packet.getReadPos() == 4) {
|
if (packet.getSize() - packet.getReadPos() == 4) {
|
||||||
uint32_t soundId = packet.readUInt32();
|
uint32_t soundId = packet.readUInt32();
|
||||||
LOG_INFO("SMSG_PLAY_MUSIC (0x0103 alias): soundId=", soundId);
|
LOG_INFO("SMSG_PLAY_MUSIC (0x0103 alias): soundId=", soundId);
|
||||||
|
if (playMusicCallback_) playMusicCallback_(soundId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (opcode == 0x0480) {
|
} else if (opcode == 0x0480) {
|
||||||
|
|
@ -4496,8 +4497,8 @@ void GameHandler::handlePacket(network::Packet& packet) {
|
||||||
// ---- Play music (WotLK standard opcode) ----
|
// ---- Play music (WotLK standard opcode) ----
|
||||||
case Opcode::SMSG_PLAY_MUSIC: {
|
case Opcode::SMSG_PLAY_MUSIC: {
|
||||||
if (packet.getSize() - packet.getReadPos() >= 4) {
|
if (packet.getSize() - packet.getReadPos() >= 4) {
|
||||||
/*uint32_t soundId =*/ packet.readUInt32();
|
uint32_t soundId = packet.readUInt32();
|
||||||
// TODO: hook into music manager when in-world music is reworked
|
if (playMusicCallback_) playMusicCallback_(soundId);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue