CTitleStateMenu: implemented rebooting into installer

This commit is contained in:
Hyper
2024-12-08 02:57:27 +00:00
parent fc9c7ffb3a
commit d69f0442a7
16 changed files with 123 additions and 25 deletions

View File

@@ -67,6 +67,11 @@ set(SWA_KERNEL_CXX_SOURCES
"kernel/io/file_system.cpp"
)
set(SWA_OS_CXX_SOURCES
"os/win32/process_win32.cpp"
"os/process.cpp"
)
set(SWA_CPU_CXX_SOURCES
"cpu/guest_thread.cpp"
"cpu/code_cache.cpp"
@@ -163,6 +168,7 @@ set(SWA_CXX_SOURCES
"stdafx.cpp"
${SWA_KERNEL_CXX_SOURCES}
${SWA_OS_CXX_SOURCES}
${SWA_CPU_CXX_SOURCES}
${SWA_GPU_CXX_SOURCES}
${SWA_APU_CXX_SOURCES}

View File

@@ -3,18 +3,24 @@
#include <kernel/function.h>
#include <ui/window.h>
#include <patches/audio_patches.h>
#include <os/process.h>
bool g_isAppInit = false;
bool g_isMissingDLC = false;
void App::Exit(std::vector<std::string> restartArgs)
{
if (restartArgs.size())
os::process::StartProcess(os::process::GetExecutablePath(), restartArgs, os::process::GetWorkingDirectory());
double g_deltaTime;
#if _WIN32
ExitProcess(0);
#endif
}
// CApplication::Ctor
PPC_FUNC_IMPL(__imp__sub_824EB490);
PPC_FUNC(sub_824EB490)
{
g_isAppInit = true;
g_isMissingDLC = !Installer::checkAllDLC(GetGamePath());
App::s_isInit = true;
App::s_isMissingDLC = !Installer::checkAllDLC(GetGamePath());
__imp__sub_824EB490(ctx, base);
}
@@ -23,13 +29,13 @@ PPC_FUNC(sub_824EB490)
PPC_FUNC_IMPL(__imp__sub_822C1130);
PPC_FUNC(sub_822C1130)
{
g_deltaTime = ctx.f1.f64;
App::s_deltaTime = ctx.f1.f64;
SDL_PumpEvents();
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
Window::Update();
AudioPatches::Update(g_deltaTime);
AudioPatches::Update(App::s_deltaTime);
__imp__sub_822C1130(ctx, base);
}

View File

@@ -1,6 +1,12 @@
#pragma once
extern bool g_isAppInit;
extern bool g_isMissingDLC;
class App
{
public:
inline static bool s_isInit;
inline static bool s_isMissingDLC;
extern double g_deltaTime;
inline static double s_deltaTime;
static void Exit(std::vector<std::string> restartArgs = {});
};

View File

@@ -222,7 +222,7 @@ void ImFontAtlasSnapshot::GenerateGlyphRanges()
}
}
if (g_isAppInit)
if (App::s_isInit)
{
for (size_t i = XDBF_LANGUAGE_ENGLISH; i <= XDBF_LANGUAGE_ITALIAN; i++)
{

1
UnleashedRecomp/os/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
![Ww][Ii][Nn]32/

View File

@@ -0,0 +1,17 @@
#include "process.h"
#include "process_detail.h"
std::filesystem::path os::process::GetExecutablePath()
{
return detail::GetExecutablePath();
}
std::filesystem::path os::process::GetWorkingDirectory()
{
return detail::GetWorkingDirectory();
}
bool os::process::StartProcess(const std::filesystem::path path, const std::vector<std::string> args, std::filesystem::path work)
{
return detail::StartProcess(path, args, work);
}

View File

@@ -0,0 +1,8 @@
#pragma once
namespace os::process
{
std::filesystem::path GetExecutablePath();
std::filesystem::path GetWorkingDirectory();
bool StartProcess(const std::filesystem::path path, const std::vector<std::string> args, std::filesystem::path work = {});
}

View File

@@ -0,0 +1,8 @@
#pragma once
namespace os::process::detail
{
std::filesystem::path GetExecutablePath();
std::filesystem::path GetWorkingDirectory();
bool StartProcess(const std::filesystem::path path, const std::vector<std::string> args, std::filesystem::path work = {});
}

View File

@@ -0,0 +1,45 @@
#include <os/process_detail.h>
std::filesystem::path os::process::detail::GetExecutablePath()
{
char exePath[MAX_PATH];
if (!GetModuleFileNameA(nullptr, exePath, MAX_PATH))
return std::filesystem::path();
return std::filesystem::path(exePath);
}
std::filesystem::path os::process::detail::GetWorkingDirectory()
{
char workPath[MAX_PATH];
if (!GetCurrentDirectoryA(MAX_PATH, workPath))
return std::filesystem::path();
return std::filesystem::path(workPath);
}
bool os::process::detail::StartProcess(const std::filesystem::path path, const std::vector<std::string> args, std::filesystem::path work)
{
if (path.empty())
return false;
if (work.empty())
work = path.parent_path();
auto cli = path.string();
for (auto& arg : args)
cli += " " + arg;
STARTUPINFOA startInfo{ sizeof(STARTUPINFOA) };
PROCESS_INFORMATION procInfo{};
if (!CreateProcessA(path.string().c_str(), cli.data(), nullptr, nullptr, false, 0, nullptr, work.string().c_str(), &startInfo, &procInfo))
return false;
CloseHandle(procInfo.hProcess);
CloseHandle(procInfo.hThread);
return true;
}

View File

@@ -41,12 +41,12 @@ static double ComputeLerpFactor(double t, double deltaTime)
// delta time, as it might be time scaled and not match with 30 FPS behavior.
void CameraLerpFixMidAsmHook(PPCRegister& t)
{
t.f64 = ComputeLerpFactor(t.f64, g_deltaTime);
t.f64 = ComputeLerpFactor(t.f64, App::s_deltaTime);
}
void CameraTargetSideOffsetLerpFixMidAsmHook(PPCVRegister& v13, PPCVRegister& v62)
{
float factor = float(ComputeLerpFactor(double(v13.f32[0] * v62.f32[0]), g_deltaTime));
float factor = float(ComputeLerpFactor(double(v13.f32[0] * v62.f32[0]), App::s_deltaTime));
for (size_t i = 0; i < 4; i++)
{

View File

@@ -117,11 +117,11 @@ PPC_FUNC(sub_824B0930)
auto pHudPause = (SWA::CHudPause*)g_memory.Translate(ctx.r3.u32);
auto pInputState = SWA::CInputState::GetInstance();
g_achievementMenuIntroTime += g_deltaTime;
g_achievementMenuIntroTime += App::s_deltaTime;
if (g_isAchievementMenuOutro)
{
g_achievementMenuOutroTime += g_deltaTime;
g_achievementMenuOutroTime += App::s_deltaTime;
// Re-open pause menu after achievement menu closes with delay.
if (g_achievementMenuOutroTime >= g_achievementMenuOutroThreshold)

View File

@@ -3,6 +3,7 @@
#include <locale/locale.h>
#include <ui/fader.h>
#include <ui/message_window.h>
#include <app.h>
static bool g_quitMessageOpen = false;
static bool g_quitMessageFaderBegun = false;
@@ -23,7 +24,7 @@ static bool ProcessQuitMessage()
switch (g_quitMessageResult)
{
case 0:
Fader::FadeOut(1, []() { ExitProcess(0); });
Fader::FadeOut(1, []() { App::Exit(); });
g_quitMessageFaderBegun = true;
break;

View File

@@ -20,7 +20,7 @@ static bool ProcessInstallMessage()
if (g_installMessageFaderBegun)
return true;
auto& str = g_isMissingDLC
auto& str = App::s_isMissingDLC
? Localise("Installer_Message_TitleMissingDLC")
: Localise("Installer_Message_Title");
@@ -31,8 +31,7 @@ static bool ProcessInstallMessage()
switch (g_installMessageResult)
{
case 0:
// TODO: replace ExitProcess with restart method using --install-dlc argument.
Fader::FadeOut(1, []() { ExitProcess(0); });
Fader::FadeOut(1, []() { App::Exit({ "--install-dlc" }); });
g_installMessageFaderBegun = true;
break;

View File

@@ -63,7 +63,7 @@ std::tuple<std::tuple<ImVec2, ImVec2>, GuestTexture*> GetButtonIcon(EButtonIcon
std::tuple<ImVec2, ImVec2> btn;
GuestTexture* texture;
auto isPlayStation = g_isAppInit
auto isPlayStation = App::s_isInit
? Config::ControllerIcons == EControllerIcons::PlayStation
: hid::detail::g_inputDevice == hid::detail::EInputDevice::PlayStation;

View File

@@ -65,7 +65,7 @@ public:
{
case SDL_KEYDOWN:
{
if (g_isAppInit)
if (App::s_isInit)
break;
switch (event->key.keysym.scancode)
@@ -93,7 +93,7 @@ public:
case SDL_MOUSEBUTTONDOWN:
{
if (g_isAppInit)
if (App::s_isInit)
break;
g_isAccepted = true;
@@ -273,8 +273,8 @@ void MessageWindow::Draw()
auto textMarginX = Scale(37);
auto textMarginY = Scale(45);
bool isController = g_isAppInit ? true : hid::detail::IsInputDeviceController();
bool isKeyboard = g_isAppInit ? false : hid::detail::g_inputDevice == hid::detail::EInputDevice::Keyboard;
bool isController = App::s_isInit ? true : hid::detail::IsInputDeviceController();
bool isKeyboard = App::s_isInit ? false : hid::detail::g_inputDevice == hid::detail::EInputDevice::Keyboard;
if (DrawContainer(g_appearTime, centre, { textSize.x / 2 + textMarginX, textSize.y / 2 + textMarginY }, !g_isControlsVisible))
{

View File

@@ -2,6 +2,7 @@
#include "sdl_listener.h"
#include <user/config.h>
#include <SDL_syswm.h>
#include <app.h>
bool m_isFullscreenKeyReleased = true;
bool m_isResizing = false;
@@ -18,7 +19,7 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
{
case SDL_QUIT:
Config::Save();
ExitProcess(0);
App::Exit();
break;
case SDL_KEYDOWN: