audio_patches: implemented Music and SE volume

This commit is contained in:
Hyper 2024-11-20 04:24:19 +00:00
parent ac28db9480
commit 6d6c4fad1f
7 changed files with 56 additions and 19 deletions

View file

@ -66,7 +66,7 @@ set(SWA_HID_CXX_SOURCES
set(SWA_PATCHES_CXX_SOURCES set(SWA_PATCHES_CXX_SOURCES
"patches/ui/CHudPause_patches.cpp" "patches/ui/CHudPause_patches.cpp"
"patches/ui/CTitleMenu_patches.cpp" "patches/ui/CTitleStateMenu_patches.cpp"
"patches/ui/frontend_listener.cpp" "patches/ui/frontend_listener.cpp"
"patches/audio_patches.cpp" "patches/audio_patches.cpp"
"patches/camera_patches.cpp" "patches/camera_patches.cpp"
@ -84,6 +84,7 @@ set(SWA_UI_CXX_SOURCES
) )
set(SWA_CXX_SOURCES set(SWA_CXX_SOURCES
"app.cpp"
"exports.cpp" "exports.cpp"
"main.cpp" "main.cpp"
"misc_impl.cpp" "misc_impl.cpp"

21
UnleashedRecomp/app.cpp Normal file
View file

@ -0,0 +1,21 @@
#include <kernel/function.h>
#include <ui/window.h>
#include <app.h>
#include <patches/audio_patches.h>
double g_deltaTime;
// CApplication::Update
PPC_FUNC_IMPL(__imp__sub_822C1130);
PPC_FUNC(sub_822C1130)
{
g_deltaTime = ctx.f1.f64;
SDL_PumpEvents();
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
Window::Update();
audio_patches::Update(g_deltaTime);
__imp__sub_822C1130(ctx, base);
}

3
UnleashedRecomp/app.h Normal file
View file

@ -0,0 +1,3 @@
#pragma once
extern double g_deltaTime;

View file

@ -1,12 +1,30 @@
#include <cpu/guest_code.h> #include <cpu/guest_code.h>
#include <cfg/config.h> #include <cfg/config.h>
#include <kernel/function.h>
#include <patches/audio_patches.h>
PPC_FUNC_IMPL(__imp__sub_82B4E130); be<float>* GetVolume(bool isMusic = true)
PPC_FUNC(sub_82B4E130)
{ {
auto pMusicVolume = (be<float>*)g_memory.Translate(ctx.r3.u32); auto ppUnkClass = (be<uint32_t>*)g_memory.Translate(0x83362FFC);
*pMusicVolume = Config::MusicVolume; if (!ppUnkClass->get())
return nullptr;
__imp__sub_82B4E130(ctx, base); // NOTE (Hyper): This is fine, trust me. See 0x82E58728.
return (be<float>*)g_memory.Translate(4 * ((int)isMusic + 0x1C) + ((be<uint32_t>*)g_memory.Translate(ppUnkClass->get() + 4))->get());
} }
void audio_patches::Update(float deltaTime)
{
auto pMusicVolume = GetVolume();
auto pSEVolume = GetVolume(false);
if (!pMusicVolume || !pSEVolume)
return;
*pSEVolume = Config::SEVolume;
*pMusicVolume = Config::MusicVolume;
}
// Stub volume setter.
GUEST_FUNCTION_STUB(sub_82E58728);

View file

@ -0,0 +1,7 @@
#pragma once
class audio_patches
{
public:
static void Update(float deltaTime);
};

View file

@ -1,7 +1,6 @@
#include "window.h" #include "window.h"
#include "sdl_listener.h" #include "sdl_listener.h"
#include <cfg/config.h> #include <cfg/config.h>
#include <kernel/function.h>
#include <SDL_syswm.h> #include <SDL_syswm.h>
bool m_isFullscreenKeyReleased = true; bool m_isFullscreenKeyReleased = true;
@ -175,15 +174,3 @@ void Window::Update()
Config::WindowHeight = Window::s_height; Config::WindowHeight = Window::s_height;
} }
} }
// CApplication::Update
PPC_FUNC_IMPL(__imp__sub_822C1130);
PPC_FUNC(sub_822C1130)
{
SDL_PumpEvents();
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
Window::Update();
__imp__sub_822C1130(ctx, base);
}