CTitleMenu: added open/close sounds to the options menu

This commit is contained in:
Hyper 2024-11-20 01:59:33 +00:00
parent ab6f29ebd4
commit ac28db9480
4 changed files with 41 additions and 31 deletions

View file

@ -1,5 +1,27 @@
#include <kernel/function.h>
#include <kernel/heap.h>
#include <kernel/memory.h>
#include <ui/window.h> #include <ui/window.h>
extern "C" void Game_PlaySound(const char* pName)
{
void* soundPlayerSharedPtr = g_userHeap.Alloc(8);
GuestToHostFunction<void>(0x82B4DF50, soundPlayerSharedPtr, ((be<uint32_t>*)g_memory.Translate(0x83367900))->get(), 7, 0, 0);
auto soundPlayer = (be<uint32_t>*)g_memory.Translate(*(be<uint32_t>*)soundPlayerSharedPtr);
auto soundPlayerVtable = (be<uint32_t>*)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<void>(virtualFunction, soundPlayer, strAllocation, 0);
g_userHeap.Free(strAllocation);
GuestToHostFunction<void>(0x822C0890, *((be<uint32_t>*)soundPlayerSharedPtr + 1));
g_userHeap.Free(soundPlayerSharedPtr);
}
extern "C" void Window_SetFullscreen(bool isEnabled) extern "C" void Window_SetFullscreen(bool isEnabled)
{ {
Window::SetFullscreen(isEnabled); Window::SetFullscreen(isEnabled);

View file

@ -1,3 +1,4 @@
#pragma once #pragma once
extern "C" void Game_PlaySound(const char* pName);
extern "C" void Window_SetFullscreen(bool isEnabled); extern "C" void Window_SetFullscreen(bool isEnabled);

View file

@ -1,6 +1,7 @@
#include <cpu/guest_code.h> #include <cpu/guest_code.h>
#include <api/SWA.h> #include <api/SWA.h>
#include <ui/options_menu.h> #include <ui/options_menu.h>
#include <exports.h>
// SWA::CTitleStateMenu::Update // SWA::CTitleStateMenu::Update
PPC_FUNC_IMPL(__imp__sub_825882B8); PPC_FUNC_IMPL(__imp__sub_825882B8);
@ -12,18 +13,23 @@ PPC_FUNC(sub_825882B8)
if (!OptionsMenu::s_isVisible && pInputState && isOptionsIndex) if (!OptionsMenu::s_isVisible && pInputState && isOptionsIndex)
{ {
// TODO: play sys_worldmap_decide.
if (pInputState->GetPadState().IsTapped(SWA::eKeyState_A)) if (pInputState->GetPadState().IsTapped(SWA::eKeyState_A))
{
Game_PlaySound("sys_worldmap_window");
Game_PlaySound("sys_worldmap_decide");
OptionsMenu::Open(); OptionsMenu::Open();
} }
}
if (!OptionsMenu::s_isVisible) if (!OptionsMenu::s_isVisible)
__imp__sub_825882B8(ctx, base); __imp__sub_825882B8(ctx, base);
if (pInputState && isOptionsIndex) if (pInputState && isOptionsIndex)
{ {
// TODO: play sys_worldmap_cancel (could be "cansel" instead).
if (OptionsMenu::CanClose() && pInputState->GetPadState().IsTapped(SWA::eKeyState_B)) if (OptionsMenu::CanClose() && pInputState->GetPadState().IsTapped(SWA::eKeyState_B))
{
Game_PlaySound("sys_worldmap_cansel");
OptionsMenu::Close(); OptionsMenu::Close();
} }
}
} }

View file

@ -1,5 +1,6 @@
#include "options_menu.h" #include "options_menu.h"
#include "window.h" #include "window.h"
#include "exports.h"
#include <api/SWA/System/InputState.h> #include <api/SWA/System/InputState.h>
#include <gpu/imgui_common.h> #include <gpu/imgui_common.h>
@ -328,26 +329,6 @@ static void ResetSelection()
g_downWasHeld = false; g_downWasHeld = false;
} }
#undef PlaySound
static void PlaySound(const char* name)
{
void* soundPlayerSharedPtr = g_userHeap.Alloc(8);
GuestToHostFunction<void>(0x82B4DF50, soundPlayerSharedPtr, ((be<uint32_t>*)g_memory.Translate(0x83367900))->get(), 7, 0, 0);
auto soundPlayer = (be<uint32_t>*)g_memory.Translate(*(be<uint32_t>*)soundPlayerSharedPtr);
auto soundPlayerVtable = (be<uint32_t>*)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<void>(virtualFunction, soundPlayer, strAllocation, 0);
g_userHeap.Free(strAllocation);
GuestToHostFunction<void>(0x822C0890, *((be<uint32_t>*)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_TIME = (CONTAINER_INNER_TIME + CONTAINER_BACKGROUND_TIME) / 2.0;
static constexpr double CONTAINER_CATEGORY_DURATION = 12.0; static constexpr double CONTAINER_CATEGORY_DURATION = 12.0;
@ -381,7 +362,7 @@ static bool DrawCategories()
if (moveLeft || moveRight) if (moveLeft || moveRight)
{ {
ResetSelection(); ResetSelection();
PlaySound("sys_actstg_score"); Game_PlaySound("sys_actstg_score");
} }
auto drawList = ImGui::GetForegroundDrawList(); auto drawList = ImGui::GetForegroundDrawList();
@ -555,7 +536,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
VideoConfigValueChangedCallback(config); VideoConfigValueChangedCallback(config);
PlaySound("sys_worldmap_finaldecide"); Game_PlaySound("sys_worldmap_finaldecide");
} }
} }
else else
@ -572,7 +553,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
// remember value // remember value
s_oldValue = config->Value; s_oldValue = config->Value;
PlaySound("sys_worldmap_decide"); Game_PlaySound("sys_worldmap_decide");
} }
else else
{ {
@ -580,7 +561,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
if (config->Value != s_oldValue) if (config->Value != s_oldValue)
VideoConfigValueChangedCallback(config); VideoConfigValueChangedCallback(config);
PlaySound("sys_worldmap_finaldecide"); Game_PlaySound("sys_worldmap_finaldecide");
} }
} }
else if (padState.IsTapped(SWA::eKeyState_B)) else if (padState.IsTapped(SWA::eKeyState_B))
@ -589,7 +570,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
config->Value = s_oldValue; config->Value = s_oldValue;
g_lockedOnOption = false; g_lockedOnOption = false;
PlaySound("sys_worldmap_cansel"); Game_PlaySound("sys_worldmap_cansel");
} }
lockedOnOption = g_lockedOnOption; lockedOnOption = g_lockedOnOption;
@ -740,7 +721,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
config->Value = it->first; config->Value = it->first;
if (increment || decrement) if (increment || decrement)
PlaySound("sys_actstg_pausecursor"); Game_PlaySound("sys_actstg_pausecursor");
} }
else if constexpr (std::is_same_v<T, float> || std::is_same_v<T, int32_t>) else if constexpr (std::is_same_v<T, float> || std::is_same_v<T, int32_t>)
{ {
@ -767,7 +748,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
} while (fastIncrement && deltaTime > 0.0f); } while (fastIncrement && deltaTime > 0.0f);
if ((increment || decrement) && (config->Value >= valueMin && config->Value <= valueMax)) 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); config->Value = std::clamp(config->Value, valueMin, valueMax);
} }
@ -835,7 +816,7 @@ static void DrawConfigOptions()
DrawConfigOption(rowCount++, yOffset, &Config::WerehogHubTransformVideo); DrawConfigOption(rowCount++, yOffset, &Config::WerehogHubTransformVideo);
DrawConfigOption(rowCount++, yOffset, &Config::LogoSkip); DrawConfigOption(rowCount++, yOffset, &Config::LogoSkip);
break; break;
case 1: // CONTROLS case 1: // INPUT
DrawConfigOption(rowCount++, yOffset, &Config::CameraXInvert); DrawConfigOption(rowCount++, yOffset, &Config::CameraXInvert);
DrawConfigOption(rowCount++, yOffset, &Config::CameraYInvert); DrawConfigOption(rowCount++, yOffset, &Config::CameraYInvert);
DrawConfigOption(rowCount++, yOffset, &Config::XButtonHoming); DrawConfigOption(rowCount++, yOffset, &Config::XButtonHoming);
@ -898,7 +879,7 @@ static void DrawConfigOptions()
{ {
g_rowSelectionTime = ImGui::GetTime(); g_rowSelectionTime = ImGui::GetTime();
g_prevSelectedRowIndex = prevSelectedRowIndex; g_prevSelectedRowIndex = prevSelectedRowIndex;
PlaySound("sys_worldmap_cursor"); Game_PlaySound("sys_worldmap_cursor");
} }
g_upWasHeld = upIsHeld; g_upWasHeld = upIsHeld;