video_patches: aspect ratio support for CPlayMovieWrapper

This commit is contained in:
Hyper 2025-01-03 21:42:29 +00:00
parent b9cffba14d
commit 7735f3fcf5

View file

@ -2,6 +2,8 @@
#include <api/SWA.h>
#include <ui/game_window.h>
SWA::Sequence::Utility::CPlayMovieWrapper::CRender* g_pPlayMovieWrapperRender;
// TODO: to be removed.
constexpr float m_baseAspectRatio = 16.0f / 9.0f;
@ -27,3 +29,66 @@ bool MotionBlurMidAsmHook()
{
return Config::MotionBlur != EMotionBlur::Off;
}
// SWA::Sequence::Utility::CPlayMovieWrapper::CRender
PPC_FUNC_IMPL(__imp__sub_82B732F8);
PPC_FUNC(sub_82B732F8)
{
g_pPlayMovieWrapperRender = (SWA::Sequence::Utility::CPlayMovieWrapper::CRender*)g_memory.Translate(ctx.r3.u32);
__imp__sub_82B732F8(ctx, base);
}
// SWA::Sequence::Utility::CPlayMovieWrapper::~CRender
PPC_FUNC_IMPL(__imp__sub_82B71FB0);
PPC_FUNC(sub_82B71FB0)
{
g_pPlayMovieWrapperRender = nullptr;
__imp__sub_82B71FB0(ctx, base);
}
// Update movie player dimensions.
PPC_FUNC_IMPL(__imp__sub_82AE2F08);
PPC_FUNC(sub_82AE2F08)
{
__imp__sub_82AE2F08(ctx, base);
if (!g_pPlayMovieWrapperRender)
return;
// Disable aspect ratio changes so we can do our own.
g_pPlayMovieWrapperRender->m_MaintainAspectRatio = false;
auto videoAspectRatio = g_pPlayMovieWrapperRender->m_MovieWidth / g_pPlayMovieWrapperRender->m_MovieHeight;
auto windowAspectRatio = (float)GameWindow::s_width / (float)GameWindow::s_height;
float sx, sy, x, y;
if (windowAspectRatio > videoAspectRatio)
{
// Pillarbox.
sy = 1.0f;
sx = sy * videoAspectRatio / windowAspectRatio;
x = (1.0f - sx) / 2.0f;
y = 0.0f;
}
else
{
// Letterbox.
sx = 1.0f;
sy = sx * windowAspectRatio / videoAspectRatio;
x = 0.0f;
y = (1.0f - sy) / 2.0f;
}
// TODO: use ImGui element to draw letter/pillarbox over screen edges.
g_pPlayMovieWrapperRender->m_TopLeftX = -1.0f + x * 2.0f;
g_pPlayMovieWrapperRender->m_TopLeftY = 1.0f - y * 2.0f;
g_pPlayMovieWrapperRender->m_TopRightX = -1.0f + (x + sx) * 2.0f;
g_pPlayMovieWrapperRender->m_TopRightY = 1.0f - y * 2.0f;
g_pPlayMovieWrapperRender->m_BottomLeftX = -1.0f + x * 2.0f;
g_pPlayMovieWrapperRender->m_BottomLeftY = 1.0f - (y + sy) * 2.0f;
g_pPlayMovieWrapperRender->m_BottomRightX = -1.0f + (x + sx) * 2.0f;
g_pPlayMovieWrapperRender->m_BottomRightY = 1.0f - (y + sy) * 2.0f;
}