From ac28db9480b65fd9a90aa3d4db451be056272426 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Wed, 20 Nov 2024 01:59:33 +0000 Subject: [PATCH] CTitleMenu: added open/close sounds to the options menu --- UnleashedRecomp/exports.cpp | 22 +++++++++++ UnleashedRecomp/exports.h | 1 + .../patches/ui/CTitleMenu_patches.cpp | 10 ++++- UnleashedRecomp/ui/options_menu.cpp | 39 +++++-------------- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/UnleashedRecomp/exports.cpp b/UnleashedRecomp/exports.cpp index 65dbae7a..1befe499 100644 --- a/UnleashedRecomp/exports.cpp +++ b/UnleashedRecomp/exports.cpp @@ -1,5 +1,27 @@ +#include +#include +#include #include +extern "C" void Game_PlaySound(const char* pName) +{ + void* soundPlayerSharedPtr = g_userHeap.Alloc(8); + GuestToHostFunction(0x82B4DF50, soundPlayerSharedPtr, ((be*)g_memory.Translate(0x83367900))->get(), 7, 0, 0); + + auto soundPlayer = (be*)g_memory.Translate(*(be*)soundPlayerSharedPtr); + auto soundPlayerVtable = (be*)g_memory.Translate(*soundPlayer); + uint32_t virtualFunction = *(soundPlayerVtable + 1); + + size_t strLen = strlen(pName); + void* strAllocation = g_userHeap.Alloc(strLen + 1); + memcpy(strAllocation, pName, strLen + 1); + GuestToHostFunction(virtualFunction, soundPlayer, strAllocation, 0); + g_userHeap.Free(strAllocation); + + GuestToHostFunction(0x822C0890, *((be*)soundPlayerSharedPtr + 1)); + g_userHeap.Free(soundPlayerSharedPtr); +} + extern "C" void Window_SetFullscreen(bool isEnabled) { Window::SetFullscreen(isEnabled); diff --git a/UnleashedRecomp/exports.h b/UnleashedRecomp/exports.h index a19eea6a..feef2bae 100644 --- a/UnleashedRecomp/exports.h +++ b/UnleashedRecomp/exports.h @@ -1,3 +1,4 @@ #pragma once +extern "C" void Game_PlaySound(const char* pName); extern "C" void Window_SetFullscreen(bool isEnabled); diff --git a/UnleashedRecomp/patches/ui/CTitleMenu_patches.cpp b/UnleashedRecomp/patches/ui/CTitleMenu_patches.cpp index a123ed9d..bbf232c2 100644 --- a/UnleashedRecomp/patches/ui/CTitleMenu_patches.cpp +++ b/UnleashedRecomp/patches/ui/CTitleMenu_patches.cpp @@ -1,6 +1,7 @@ #include #include #include +#include // SWA::CTitleStateMenu::Update PPC_FUNC_IMPL(__imp__sub_825882B8); @@ -12,9 +13,12 @@ PPC_FUNC(sub_825882B8) if (!OptionsMenu::s_isVisible && pInputState && isOptionsIndex) { - // TODO: play sys_worldmap_decide. if (pInputState->GetPadState().IsTapped(SWA::eKeyState_A)) + { + Game_PlaySound("sys_worldmap_window"); + Game_PlaySound("sys_worldmap_decide"); OptionsMenu::Open(); + } } if (!OptionsMenu::s_isVisible) @@ -22,8 +26,10 @@ PPC_FUNC(sub_825882B8) if (pInputState && isOptionsIndex) { - // TODO: play sys_worldmap_cancel (could be "cansel" instead). if (OptionsMenu::CanClose() && pInputState->GetPadState().IsTapped(SWA::eKeyState_B)) + { + Game_PlaySound("sys_worldmap_cansel"); OptionsMenu::Close(); + } } } diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index 089fe49e..08db827a 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -1,5 +1,6 @@ #include "options_menu.h" #include "window.h" +#include "exports.h" #include #include @@ -328,26 +329,6 @@ static void ResetSelection() g_downWasHeld = false; } -#undef PlaySound -static void PlaySound(const char* name) -{ - void* soundPlayerSharedPtr = g_userHeap.Alloc(8); - GuestToHostFunction(0x82B4DF50, soundPlayerSharedPtr, ((be*)g_memory.Translate(0x83367900))->get(), 7, 0, 0); - - auto soundPlayer = (be*)g_memory.Translate(*(be*)soundPlayerSharedPtr); - auto soundPlayerVtable = (be*)g_memory.Translate(*soundPlayer); - uint32_t virtualFunction = *(soundPlayerVtable + 1); - - size_t strLen = strlen(name); - void* strAllocation = g_userHeap.Alloc(strLen + 1); - memcpy(strAllocation, name, strLen + 1); - GuestToHostFunction(virtualFunction, soundPlayer, strAllocation, 0); - g_userHeap.Free(strAllocation); - - GuestToHostFunction(0x822C0890, *((be*)soundPlayerSharedPtr + 1)); - g_userHeap.Free(soundPlayerSharedPtr); -} - static constexpr double CONTAINER_CATEGORY_TIME = (CONTAINER_INNER_TIME + CONTAINER_BACKGROUND_TIME) / 2.0; static constexpr double CONTAINER_CATEGORY_DURATION = 12.0; @@ -381,7 +362,7 @@ static bool DrawCategories() if (moveLeft || moveRight) { ResetSelection(); - PlaySound("sys_actstg_score"); + Game_PlaySound("sys_actstg_score"); } auto drawList = ImGui::GetForegroundDrawList(); @@ -555,7 +536,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf VideoConfigValueChangedCallback(config); - PlaySound("sys_worldmap_finaldecide"); + Game_PlaySound("sys_worldmap_finaldecide"); } } else @@ -572,7 +553,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf // remember value s_oldValue = config->Value; - PlaySound("sys_worldmap_decide"); + Game_PlaySound("sys_worldmap_decide"); } else { @@ -580,7 +561,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf if (config->Value != s_oldValue) VideoConfigValueChangedCallback(config); - PlaySound("sys_worldmap_finaldecide"); + Game_PlaySound("sys_worldmap_finaldecide"); } } else if (padState.IsTapped(SWA::eKeyState_B)) @@ -589,7 +570,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf config->Value = s_oldValue; g_lockedOnOption = false; - PlaySound("sys_worldmap_cansel"); + Game_PlaySound("sys_worldmap_cansel"); } lockedOnOption = g_lockedOnOption; @@ -740,7 +721,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf config->Value = it->first; if (increment || decrement) - PlaySound("sys_actstg_pausecursor"); + Game_PlaySound("sys_actstg_pausecursor"); } else if constexpr (std::is_same_v || std::is_same_v) { @@ -767,7 +748,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf } while (fastIncrement && deltaTime > 0.0f); if ((increment || decrement) && (config->Value >= valueMin && config->Value <= valueMax)) - PlaySound("sys_actstg_twn_speechbutton"); + Game_PlaySound("sys_actstg_twn_speechbutton"); config->Value = std::clamp(config->Value, valueMin, valueMax); } @@ -835,7 +816,7 @@ static void DrawConfigOptions() DrawConfigOption(rowCount++, yOffset, &Config::WerehogHubTransformVideo); DrawConfigOption(rowCount++, yOffset, &Config::LogoSkip); break; - case 1: // CONTROLS + case 1: // INPUT DrawConfigOption(rowCount++, yOffset, &Config::CameraXInvert); DrawConfigOption(rowCount++, yOffset, &Config::CameraYInvert); DrawConfigOption(rowCount++, yOffset, &Config::XButtonHoming); @@ -898,7 +879,7 @@ static void DrawConfigOptions() { g_rowSelectionTime = ImGui::GetTime(); g_prevSelectedRowIndex = prevSelectedRowIndex; - PlaySound("sys_worldmap_cursor"); + Game_PlaySound("sys_worldmap_cursor"); } g_upWasHeld = upIsHeld;