From 67478ca9f537c46c9fc8dc29c1f08c36d9f75c10 Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:58:30 +0300 Subject: [PATCH] Add sound effects to options menu. --- UnleashedRecomp/kernel/heap.h | 1 - UnleashedRecomp/stdafx.h | 1 + UnleashedRecomp/ui/options_menu.cpp | 50 ++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/UnleashedRecomp/kernel/heap.h b/UnleashedRecomp/kernel/heap.h index 90da8e64..4e583be5 100644 --- a/UnleashedRecomp/kernel/heap.h +++ b/UnleashedRecomp/kernel/heap.h @@ -1,7 +1,6 @@ #pragma once #include "mutex.h" -#include struct Heap { diff --git a/UnleashedRecomp/stdafx.h b/UnleashedRecomp/stdafx.h index 96152f7b..4eabefad 100644 --- a/UnleashedRecomp/stdafx.h +++ b/UnleashedRecomp/stdafx.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "framework.h" #include "mutex.h" diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index 1fe8c3c3..79219106 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -1,8 +1,10 @@ #include "options_menu.h" #include "window.h" -#include -#include + #include +#include +#include +#include constexpr float COMMON_PADDING_POS_Y = 118.0f; constexpr float COMMON_PADDING_POS_X = 30.0f; @@ -276,6 +278,26 @@ 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 void DrawCategories() { auto inputState = SWA::CInputState::GetInstance(); @@ -300,7 +322,10 @@ static void DrawCategories() } if (moveLeft || moveRight) + { ResetSelection(); + PlaySound("sys_worldmap_cursor"); + } auto drawList = ImGui::GetForegroundDrawList(); auto clipRectMin = drawList->GetClipRectMin(); @@ -422,6 +447,8 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf config->Callback(config); VideoConfigValueChangedCallback(config); + + PlaySound("sys_worldmap_cursor"); } } else @@ -437,12 +464,16 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf g_rightWasHeld = false; // remember value s_oldValue = config->Value; + + PlaySound("sys_worldmap_decide"); } else { // released lock, call video callbacks if value is different if (config->Value != s_oldValue) VideoConfigValueChangedCallback(config); + + PlaySound("sys_worldmap_finaldecide"); } } else if (padState.IsTapped(SWA::eKeyState_B)) @@ -450,6 +481,8 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf // released lock, restore old value config->Value = s_oldValue; g_lockedOnOption = false; + + PlaySound("sys_worldmap_cansel"); } lockedOnOption = g_lockedOnOption; @@ -543,8 +576,8 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf { max.x + trianglePadding + triangleWidth, (min.y + max.y) / 2.0f }, COLOR); - bool leftIsHeld = padState.IsTapped(SWA::eKeyState_DpadLeft) || padState.LeftStickHorizontal < -0.5f; - bool rightIsHeld = padState.IsTapped(SWA::eKeyState_DpadRight) || padState.LeftStickHorizontal > 0.5f; + bool leftIsHeld = padState.IsDown(SWA::eKeyState_DpadLeft) || padState.LeftStickHorizontal < -0.5f; + bool rightIsHeld = padState.IsDown(SWA::eKeyState_DpadRight) || padState.LeftStickHorizontal > 0.5f; bool leftTapped = !g_leftWasHeld && leftIsHeld; bool rightTapped = !g_rightWasHeld && rightIsHeld; @@ -597,6 +630,9 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf } config->Value = it->first; + + if (increment || decrement) + PlaySound("sys_worldmap_cursor"); } else if constexpr (std::is_same_v) { @@ -613,6 +649,9 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf } while (fastIncrement && deltaTime > 0.0f); config->Value = std::clamp(config->Value, valueMin, valueMax); + + if (increment || decrement) + PlaySound("sys_actstg_twn_speechbutton"); } if (config->Callback) @@ -730,7 +769,10 @@ static void DrawConfigOptions() } if (scrollUp || scrollDown) + { g_rowSelectionTime = ImGui::GetTime(); + PlaySound("sys_worldmap_cursor"); + } g_upWasHeld = upIsHeld; g_downWasHeld = downIsHeld;