From eb639e3fc566b4b679c048729b1cb37ac86dbc3d Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Tue, 11 Feb 2025 19:35:18 +0300 Subject: [PATCH] Fix achievement sound not playing in cutscenes. --- UnleashedRecomp/exports.cpp | 6 +++++- UnleashedRecomp/patches/inspire_patches.cpp | 15 ++++++++------- UnleashedRecomp/patches/inspire_patches.h | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/UnleashedRecomp/exports.cpp b/UnleashedRecomp/exports.cpp index 15980ae0..e5162436 100644 --- a/UnleashedRecomp/exports.cpp +++ b/UnleashedRecomp/exports.cpp @@ -5,6 +5,7 @@ #include #include #include +#include void Game_PlaySound(const char* pName) { @@ -14,8 +15,11 @@ void Game_PlaySound(const char* pName) } else { + // Use EVENT category in cutscenes since SYSTEM gets muted by the game. + uint32_t category = !InspirePatches::s_sceneName.empty() ? 10 : 7; + guest_stack_var soundPlayer; - GuestToHostFunction(sub_82B4DF50, soundPlayer.get(), ((be*)g_memory.Translate(0x83367900))->get(), 7, 0, 0); + GuestToHostFunction(sub_82B4DF50, soundPlayer.get(), ((be*)g_memory.Translate(0x83367900))->get(), category, 0, 0); auto soundPlayerVtable = (be*)g_memory.Translate(*(be*)soundPlayer->get()); uint32_t virtualFunction = *(soundPlayerVtable + 1); diff --git a/UnleashedRecomp/patches/inspire_patches.cpp b/UnleashedRecomp/patches/inspire_patches.cpp index f7cfcf66..a9189364 100644 --- a/UnleashedRecomp/patches/inspire_patches.cpp +++ b/UnleashedRecomp/patches/inspire_patches.cpp @@ -5,8 +5,9 @@ #include #include +std::string InspirePatches::s_sceneName; + static SWA::Inspire::CScene* g_pScene; -static std::string g_sceneName; static bool g_isFirstFrameChecked; static uint32_t g_eventDispatchCount; @@ -49,7 +50,7 @@ PPC_FUNC(sub_82B98D30) __imp__sub_82B98D30(ctx, base); g_pScene = nullptr; - g_sceneName.clear(); + InspirePatches::s_sceneName.clear(); SDL_User_EvilSonic(App::s_isWerehog); } @@ -59,7 +60,7 @@ PPC_FUNC(sub_82B9BA98) { auto sceneName = (Hedgehog::Base::CSharedString*)g_memory.Translate(ctx.r5.u32); - g_sceneName = sceneName->c_str(); + InspirePatches::s_sceneName = sceneName->c_str(); __imp__sub_82B9BA98(ctx, base); } @@ -72,7 +73,7 @@ void InspirePatches::DrawDebug() return; } - ImGui::Text("Name: %s", g_sceneName.c_str()); + ImGui::Text("Name: %s", InspirePatches::s_sceneName.c_str()); ImGui::Text("Frame: %f", g_pScene->m_pData->Frame.get()); ImGui::Text("Cut: %d", g_pScene->m_pData->Cut.get()); @@ -97,17 +98,17 @@ void InspirePatches::DrawDebug() void InspirePatches::Update() { - if (!g_pScene || !g_sceneName.size()) + if (!g_pScene || !InspirePatches::s_sceneName.size()) return; - if (!g_isFirstFrameChecked && std::find(g_alwaysEvilSonic.begin(), g_alwaysEvilSonic.end(), g_sceneName) != g_alwaysEvilSonic.end()) + if (!g_isFirstFrameChecked && std::find(g_alwaysEvilSonic.begin(), g_alwaysEvilSonic.end(), InspirePatches::s_sceneName) != g_alwaysEvilSonic.end()) { SDL_User_EvilSonic(true); g_isFirstFrameChecked = true; return; } - auto findResult = g_evilSonicTimings.find(g_sceneName); + auto findResult = g_evilSonicTimings.find(InspirePatches::s_sceneName); if (findResult != g_evilSonicTimings.end()) { diff --git a/UnleashedRecomp/patches/inspire_patches.h b/UnleashedRecomp/patches/inspire_patches.h index 2ff4f75e..f5537599 100644 --- a/UnleashedRecomp/patches/inspire_patches.h +++ b/UnleashedRecomp/patches/inspire_patches.h @@ -3,6 +3,8 @@ class InspirePatches { public: + static std::string s_sceneName; + static void DrawDebug(); static void Update(); };