Fix crash (fullscreen dont work)

This commit is contained in:
GabsPuNs
2026-05-23 01:09:38 -04:00
parent d243b9ef24
commit d53b1d576a

View File

@@ -72,16 +72,10 @@ static bool g_bResizeReady = false;
char g_Win64Username[17] = { 0 };
wchar_t g_Win64UsernameW[17] = { 0 };
// Fullscreen toggle state
static bool g_isFullscreen = false;
static WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) };
// ---------- Persistent options (options.txt next to exe) ----------
static void GetOptionsFilePath(char *out, size_t outSize)
{
GetModuleFileNameA(nullptr, out, static_cast<DWORD>(outSize));
char *p = strrchr(out, '\\');
if (p) *(p + 1) = '\0';
strncat_s(out, outSize, "options.txt", _TRUNCATE);
}
// ------------------------------------------------------------------
void DefineActions(void)
@@ -987,33 +981,32 @@ postReset:
//--------------------------------------------------------------------------------------
// Toggle borderless fullscreen
//--------------------------------------------------------------------------------------
void ToggleFullscreen()
void EnableFullscreen()
{
const DWORD dwStyle = GetWindowLong(g_hWnd, GWL_STYLE);
const int primaryPad = ProfileManager.GetPrimaryPad();
const unsigned char fullscreen = app.GetGameSettings(primaryPad, eGameSetting_Fullscreen);
if (!fullscreen)
MONITORINFO mi = {};
mi.cbSize = sizeof(mi);
if (GetWindowPlacement(g_hWnd, &g_wpPrev) && GetMonitorInfo(MonitorFromWindow(g_hWnd, MONITOR_DEFAULTTOPRIMARY), &mi))
{
MONITORINFO mi = {};
mi.cbSize = sizeof(mi);
if (GetWindowPlacement(g_hWnd, &g_wpPrev) && GetMonitorInfo(MonitorFromWindow(g_hWnd, MONITOR_DEFAULTTOPRIMARY), &mi))
{
SetWindowLong(g_hWnd, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);
SetWindowPos(g_hWnd, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
}
else
{
SetWindowLong(g_hWnd, GWL_STYLE, dwStyle | WS_OVERLAPPEDWINDOW);
SetWindowPlacement(g_hWnd, &g_wpPrev);
SetWindowPos(g_hWnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
SetWindowLong(g_hWnd, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);
SetWindowPos(g_hWnd, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
app.SetGameSettings(primaryPad, eGameSetting_Fullscreen, fullscreen ? 0 : 1);
g_isFullscreen = true;
}
if (g_KBMInput.IsWindowFocused())
g_KBMInput.SetWindowFocused(true);
void DisableFullscreen()
{
const DWORD dwStyle = GetWindowLong(g_hWnd, GWL_STYLE);
MONITORINFO mi = {};
mi.cbSize = sizeof(mi);
SetWindowLong(g_hWnd, GWL_STYLE, dwStyle | WS_OVERLAPPEDWINDOW);
SetWindowPlacement(g_hWnd, &g_wpPrev);
SetWindowPos(g_hWnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
g_isFullscreen = false;
}
//--------------------------------------------------------------------------------------
@@ -1270,10 +1263,19 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
return 0;
}
// Restore fullscreen state from previous session
if (app.GetGameSettings(ProfileManager.GetPrimaryPad(), eGameSetting_Fullscreen))
// Fullscreen state
if (app.GetGameStarted())
{
ToggleFullscreen();
const int primaryPad = ProfileManager.GetPrimaryPad();
const unsigned char fullscreen = app.GetGameSettings(primaryPad, eGameSetting_Fullscreen);
if (fullscreen && !g_isFullscreen)
{
EnableFullscreen();
}
if (!fullscreen && g_isFullscreen)
{
DisableFullscreen();
}
}
#if 0
@@ -1654,7 +1656,9 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
// toggle fullscreen
if (g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_FULLSCREEN))
{
ToggleFullscreen();
const int primaryPad = ProfileManager.GetPrimaryPad();
const unsigned char fullscreen = app.GetGameSettings(primaryPad, eGameSetting_Fullscreen);
app.SetGameSettings(primaryPad, eGameSetting_Fullscreen, fullscreen ? 0 : 1);
}
// Open chat