From 703b8652371ba1e29e76d04fd91099b2e1905e8e Mon Sep 17 00:00:00 2001 From: fallenoak Date: Wed, 26 Nov 2025 20:21:31 -0600 Subject: [PATCH] feat(sound): implement SI2::StartGlueMusic --- src/sound/SI2.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++- src/sound/SI2.hpp | 2 ++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/sound/SI2.cpp b/src/sound/SI2.cpp index 9475f05..ffee27d 100644 --- a/src/sound/SI2.cpp +++ b/src/sound/SI2.cpp @@ -1,5 +1,6 @@ #include "sound/SI2.hpp" #include "console/CVar.hpp" +#include "event/Event.hpp" #include "sound/CVarHandlers.hpp" #include "sound/SESound.hpp" #include "sound/SI2USERDATA.hpp" @@ -33,6 +34,15 @@ char SI2::s_SoundCategory[32][18] = { "SFX", }; +static char s_CreditsMusicName[128]; +static SOUNDKITOBJECT s_CreditsMusicObject; +static char s_GlueMusicName[128]; +static SOUNDKITOBJECT s_GlueMusicObject; + +int32_t SI2::CreditsMusicUpdate(const void* data, void* param) { + // TODO +} + SOUNDKITDEF* SI2::GetSoundKitDef(int32_t id) { if (id >= SI2::s_SoundKitDefs.Count() || id <= 0) { return nullptr; @@ -51,6 +61,10 @@ int32_t SI2::GetSoundKitID(const char* name) { return 0; } +int32_t SI2::GlueMusicUpdate(const void* data, void* param) { + // TODO +} + int32_t SI2::Init(int32_t a1) { // TODO // if (CmdLineGetBool(26)) { @@ -923,5 +937,55 @@ void SI2::RegisterScriptFunctions() { } void SI2::StartGlueMusic(const char* name) { - // TODO + // Currently playing + + if (SI2::IsPlaying(&s_GlueMusicObject)) { + return; + } + + auto id = SI2::GetSoundKitID(name); + + if (!id) { + return; + } + + auto def = SI2::GetSoundKitDef(id); + + if (!def) { + return; + } + + auto userData = static_cast(s_GlueMusicObject.m_sound.GetUserData()); + + if (userData && userData->m_ID == id) { + return; + } + + // Stop playing credits music + + EventUnregister(EVENT_ID_POLL, &SI2::CreditsMusicUpdate); + // TODO SI2::Sub4C6390(&s_CreditsMusicObject, 0, 3.0, 1); + + if (!name) { + return; + } + + if (!SStrCmpI(name, s_GlueMusicName)) { + return; + } + + // Start playing glue music + + // TODO SI2::Sub9860E0(-1.0); + + SStrCopy(s_GlueMusicName, name, sizeof(s_GlueMusicName)); + + SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_type = 1; + properties.uint28 = 0; + + SI2::PlaySoundKit(s_GlueMusicName, 0, &s_GlueMusicObject, &properties); + + EventRegister(EVENT_ID_POLL, &SI2::GlueMusicUpdate); } diff --git a/src/sound/SI2.hpp b/src/sound/SI2.hpp index 5c1519b..957c78a 100644 --- a/src/sound/SI2.hpp +++ b/src/sound/SI2.hpp @@ -21,8 +21,10 @@ class SI2 { static char s_SoundCategory[32][18]; // Static functions + static int32_t CreditsMusicUpdate(const void* data, void* param); static SOUNDKITDEF* GetSoundKitDef(int32_t id); static int32_t GetSoundKitID(const char* name); + static int32_t GlueMusicUpdate(const void* data, void* param); static int32_t Init(int32_t a1); static void InitSoundKitDefs(); static void InitSoundKitGroups();