Fix achievement sound not playing in cutscenes.

This commit is contained in:
Skyth 2025-02-11 19:35:18 +03:00
parent 99d6cebf92
commit eb639e3fc5
3 changed files with 15 additions and 8 deletions

View file

@ -5,6 +5,7 @@
#include <kernel/heap.h>
#include <kernel/memory.h>
#include <ui/game_window.h>
#include <patches/inspire_patches.h>
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<boost::anonymous_shared_ptr> soundPlayer;
GuestToHostFunction<void>(sub_82B4DF50, soundPlayer.get(), ((be<uint32_t>*)g_memory.Translate(0x83367900))->get(), 7, 0, 0);
GuestToHostFunction<void>(sub_82B4DF50, soundPlayer.get(), ((be<uint32_t>*)g_memory.Translate(0x83367900))->get(), category, 0, 0);
auto soundPlayerVtable = (be<uint32_t>*)g_memory.Translate(*(be<uint32_t>*)soundPlayer->get());
uint32_t virtualFunction = *(soundPlayerVtable + 1);

View file

@ -5,8 +5,9 @@
#include <app.h>
#include <sdl_events.h>
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())
{

View file

@ -3,6 +3,8 @@
class InspirePatches
{
public:
static std::string s_sceneName;
static void DrawDebug();
static void Update();
};