(SiLoader) Fix restoration of juke box state for HD music (#706)

* (SiLoader) Fix restoration of juke box state for HD music

* Fix
This commit is contained in:
Christian Semmler 2025-09-04 15:57:34 -07:00 committed by GitHub
parent cbc51e8148
commit effa6ffabb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 9 deletions

View File

@ -343,7 +343,7 @@ MxLong Infocenter::HandleEndAction(MxEndActionNotificationParam& p_param)
MxLong result = m_radio.Notify(p_param); MxLong result = m_radio.Notify(p_param);
if (result || (action->GetAtomId() != m_atomId && action->GetAtomId() != *g_introScript && if (result || (action->GetAtomId() != m_atomId && action->GetAtomId() != *g_introScript &&
!Extension<SiLoader>::Call(ReplacedIn, *action, m_atomId, *g_introScript).value_or(false))) { !Extension<SiLoader>::Call(ReplacedIn, *action, m_atomId, *g_introScript).value_or(std::nullopt))) {
return result; return result;
} }

View File

@ -5,6 +5,7 @@
#include "bike.h" #include "bike.h"
#include "carrace.h" #include "carrace.h"
#include "dunebuggy.h" #include "dunebuggy.h"
#include "extensions/siloader.h"
#include "helicopter.h" #include "helicopter.h"
#include "isle_actions.h" #include "isle_actions.h"
#include "islepathactor.h" #include "islepathactor.h"
@ -42,6 +43,8 @@ DECOMP_SIZE_ASSERT(Act1State, 0x26c)
DECOMP_SIZE_ASSERT(LegoNamedPlane, 0x4c) DECOMP_SIZE_ASSERT(LegoNamedPlane, 0x4c)
DECOMP_SIZE_ASSERT(Isle, 0x140) DECOMP_SIZE_ASSERT(Isle, 0x140)
using namespace Extensions;
// GLOBAL: LEGO1 0x100f1198 // GLOBAL: LEGO1 0x100f1198
MxU32 g_isleFlags = 0x7f; MxU32 g_isleFlags = 0x7f;
@ -213,6 +216,14 @@ MxLong Isle::HandleEndAction(MxEndActionNotificationParam& p_param)
result = 1; result = 1;
} }
} }
else if (auto replacedObject = Extension<SiLoader>::Call(ReplacedIn, *p_param.GetAction(), *g_jukeboxScript).value_or(std::nullopt)) {
MxS32 script = replacedObject->second;
if (script >= JukeboxScript::c_JBMusic1 && script <= JukeboxScript::c_JBMusic6) {
m_jukebox->StopAction((JukeboxScript::Script) script);
result = 1;
}
}
else if (m_act1state->m_planeActive) { else if (m_act1state->m_planeActive) {
MxS32 script = p_param.GetAction()->GetObjectId(); MxS32 script = p_param.GetAction()->GetObjectId();

View File

@ -29,7 +29,7 @@ class SiLoader {
static MxBool HandleEndAction(MxEndActionNotificationParam& p_param); static MxBool HandleEndAction(MxEndActionNotificationParam& p_param);
template <typename... Args> template <typename... Args>
static bool ReplacedIn(MxDSAction& p_action, Args... p_args); static std::optional<StreamObject> ReplacedIn(MxDSAction& p_action, Args... p_args);
static std::map<std::string, std::string> options; static std::map<std::string, std::string> options;
static std::vector<std::string> files; static std::vector<std::string> files;
@ -53,20 +53,22 @@ class SiLoader {
#ifdef EXTENSIONS #ifdef EXTENSIONS
template <typename... Args> template <typename... Args>
bool SiLoader::ReplacedIn(MxDSAction& p_action, Args... p_args) std::optional<SiLoader::StreamObject> SiLoader::ReplacedIn(MxDSAction& p_action, Args... p_args)
{ {
StreamObject object{p_action.GetAtomId(), p_action.GetObjectId()}; StreamObject object{p_action.GetAtomId(), p_action.GetObjectId()};
auto checkAtomId = [&p_action, &object](const auto& p_atomId) -> bool { auto checkAtomId = [&p_action, &object](const auto& p_atomId) -> std::optional<StreamObject> {
for (const auto& key : replace) { for (const auto& key : replace) {
if (key.second == object && key.first.first == p_atomId) { if (key.second == object && key.first.first == p_atomId) {
return true; return key.first;
} }
} }
return false; return std::nullopt;
}; };
return (checkAtomId(p_args) || ...); std::optional<StreamObject> result;
((void) (!result.has_value() && (result = checkAtomId(p_args), true)), ...);
return result;
} }
constexpr auto Load = &SiLoader::Load; constexpr auto Load = &SiLoader::Load;
@ -85,9 +87,9 @@ constexpr decltype(&SiLoader::HandleWorld) HandleWorld = nullptr;
constexpr decltype(&SiLoader::HandleRemove) HandleRemove = nullptr; constexpr decltype(&SiLoader::HandleRemove) HandleRemove = nullptr;
constexpr decltype(&SiLoader::HandleDelete) HandleDelete = nullptr; constexpr decltype(&SiLoader::HandleDelete) HandleDelete = nullptr;
constexpr decltype(&SiLoader::HandleEndAction) HandleEndAction = nullptr; constexpr decltype(&SiLoader::HandleEndAction) HandleEndAction = nullptr;
constexpr auto ReplacedIn = [](auto&&... args) { constexpr auto ReplacedIn = [](auto&&... args) -> std::optional<SiLoader::StreamObject> {
((void) args, ...); ((void) args, ...);
return false; return std::nullopt;
}; };
#endif #endif
}; // namespace Extensions }; // namespace Extensions