Skip to content

Commit 0432889

Browse files
committed
Update EnableResize and GraphicsSettings
1 parent e5ee957 commit 0432889

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

EnableResizeIL2CPP_netFm/EnableResize.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class EnableResizeComponent : MonoBehaviour
5151
public EnableResizeComponent(IntPtr handle) : base(handle) { }
5252

5353

54-
//Old code from mono version starts here
54+
//MonoBehaviour code starts here
5555
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
5656

5757
[DllImport("user32.dll")]
@@ -84,12 +84,10 @@ public EnableResizeComponent(IntPtr handle) : base(handle) { }
8484

8585
private int windowStyle = 0;
8686
private bool fullScreen = false;
87-
private bool prevFullScreen = true;
88-
private int resolutionCheck = 0;
89-
private int prevResolutionCheck = 1;
9087
private int borderlessStyle = 1;
91-
private int prevBorderlessStyle = 0;
92-
private int borderlessMask = WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_THICKFRAME;
88+
private const int borderlessMask = WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_THICKFRAME;
89+
private int resizableStyle = 1;
90+
private const int resizableMask = WS_THICKFRAME | WS_MAXIMIZEBOX;
9391

9492
private WaitForSecondsRealtime oneSecond = new WaitForSecondsRealtime(1f);
9593
private bool isInitialized = false;
@@ -124,9 +122,7 @@ private void Initialize()
124122
}, IntPtr.Zero);
125123

126124
if (WindowHandle == IntPtr.Zero) return;
127-
128125
isInitialized = true;
129-
130126
StartCoroutine(TestScreen().WrapToIl2Cpp());
131127
}
132128

@@ -137,22 +133,21 @@ private IEnumerator TestScreen()
137133
if (!EnableResize.ConfigEnableResize.Value) yield break;
138134

139135
fullScreen = Screen.fullScreen;
140-
resolutionCheck = Screen.width + Screen.height;
141136
windowStyle = GetWindowLong(WindowHandle, GWL_STYLE);
142137

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

146-
if (!fullScreen && prevFullScreen ||
147-
resolutionCheck != prevResolutionCheck ||
148-
borderlessStyle != 0 && prevBorderlessStyle == 0)
141+
// if zero, is not resizable
142+
resizableStyle = windowStyle & resizableMask;
143+
144+
if (resizableStyle == 0 &&
145+
borderlessStyle != 0 &&
146+
fullScreen == false)
149147
{
150148
ResizeWindow();
151149
}
152150

153-
prevBorderlessStyle = borderlessStyle;
154-
prevFullScreen = fullScreen;
155-
prevResolutionCheck = resolutionCheck;
156151
yield return oneSecond;
157152
}
158153
}

GraphicsSettingsIL2CPP_netFm/GraphicsSettings.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ public class GraphicsSettings : BasePlugin
2323
private static ConfigEntry<int> Framerate;
2424
private static ConfigEntry<vSyncList> vSync;
2525

26-
private static ConfigEntry<bool> Apply;
26+
private static ConfigEntry<bool> AutoApply;
2727

2828
public override void Load()
2929
{
30-
Apply = Config.Bind("Apply Settings", "Apply All Graphics Settings Bellow", false, "If disabled, settings will not be applied even when clicking on \"Save Preferences\" button");
31-
Apply.SettingChanged += (sender, args) => ApplySettings();
30+
AutoApply = Config.Bind("Apply on Startup", "Apply on Startup", false, "Apply graphics settings when you start the game. May also force the resolution when the game is running");
31+
AutoApply.SettingChanged += (sender, args) => ApplySettings();
3232

33-
Width = Config.Bind("Resolution", "Width", 1280);
33+
Width = Config.Bind("Resolution", "Width", 1280, "Set Resolution Width. Minimum is 800");
3434
Width.SettingChanged += (sender, args) => ApplySettings();
35-
Height = Config.Bind("Resolution", "Height", 720);
35+
Height = Config.Bind("Resolution", "Height", 720, "Set Resolution Height. Minimum is 600");
3636
Height.SettingChanged += (sender, args) => ApplySettings();
3737
DisplayMode = Config.Bind("Resolution", "Display Mode", DisplayModeList.Windowed);
3838
DisplayMode.SettingChanged += (sender, args) => ApplySettings();
@@ -42,7 +42,10 @@ public override void Load()
4242
Framerate = Config.Bind("Framerate", "Target Framerate", -1, "Target Framerate only works if vSync is Off. Set -1 to unlimited");
4343
Framerate.SettingChanged += (sender, args) => ApplySettings();
4444

45-
SceneManager.add_sceneLoaded(new Action<Scene, LoadSceneMode>((s, lsm) => GetResolution()));
45+
SceneManager.add_sceneLoaded(new Action<Scene, LoadSceneMode>((s, lsm) =>
46+
{
47+
if (AutoApply.Value) ApplySettings();
48+
}));
4649
}
4750

4851
private enum DisplayModeList
@@ -59,18 +62,11 @@ private enum vSyncList
5962
Half = 2
6063
}
6164

62-
private void GetResolution()
63-
{
64-
Apply.Value = false;
65-
Width.Value = Screen.width;
66-
Height.Value = Screen.height;
67-
if (Screen.fullScreen) DisplayMode.Value = DisplayModeList.FullScreen;
68-
if (!Screen.fullScreen) DisplayMode.Value = DisplayModeList.Windowed;
69-
}
70-
7165
private void ApplySettings()
7266
{
73-
if (!Apply.Value) return;
67+
if (Width.Value < 800) Width.Value = 800;
68+
if (Height.Value < 600) Height.Value = 600;
69+
7470
if (DisplayMode.Value == DisplayModeList.FullScreen)
7571
Screen.SetResolution(Width.Value, Height.Value, FullScreenMode.ExclusiveFullScreen);
7672

GraphicsSettingsIL2CPP_netFm/GraphicsSettingsIL2CPP_netFm.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555
</ItemGroup>
5656
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5757
<PropertyGroup>
58-
<PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)bin\BepInEx\Plugins\" /s /i /y
59-
60-
</PostBuildEvent>
58+
<PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)bin\BepInEx\Plugins\" /s /i /y</PostBuildEvent>
6159
</PropertyGroup>
6260
</Project>

0 commit comments

Comments
 (0)