Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EnableResize.cs #5

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions BepInEx.EnableResize/EnableResize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@ public class EnableResize : BaseUnityPlugin

private int windowStyle = 0;
private bool fullScreen = false;
private bool prevFullScreen = true;
private int resolutionCheck = 0;
private int prevResolutionCheck = 1;
private int borderlessStyle = 1;
private int prevBorderlessStyle = 0;
private int borderlessMask = WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_THICKFRAME;

private const int borderlessMask = WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_THICKFRAME;
private int resizableStyle = 1;
private const int resizableMask = WS_THICKFRAME | WS_MAXIMIZEBOX;
private WaitForSecondsRealtime oneSecond = new WaitForSecondsRealtime(1f);
private bool isInitialized = false;

Expand Down Expand Up @@ -104,22 +101,21 @@ private IEnumerator TestScreen()
if (!ConfigEnableResize.Value) yield break;

fullScreen = Screen.fullScreen;
resolutionCheck = Screen.width + Screen.height;
windowStyle = GetWindowLong(WindowHandle, GWL_STYLE);

// If zero, is in borderless mode
borderlessStyle = windowStyle & borderlessMask;

if (!fullScreen && prevFullScreen ||
resolutionCheck != prevResolutionCheck ||
(borderlessStyle != 0) && (prevBorderlessStyle == 0))
// if zero, is not resizable
resizableStyle = windowStyle & resizableMask;

if (resizableStyle == 0 &&
borderlessStyle != 0 &&
fullScreen == false)
{
ResizeWindow();
}

prevBorderlessStyle = borderlessStyle;
prevFullScreen = fullScreen;
prevResolutionCheck = resolutionCheck;
yield return oneSecond;
}
}
Expand Down