[+] able to switch off WindowState

This commit is contained in:
Clansty
2024-10-01 15:50:00 +08:00
parent 07817b04fb
commit 9ead7a413e
5 changed files with 22 additions and 15 deletions

View File

@@ -92,6 +92,7 @@ public class PractiseMode
SetSpeed();
}
# if DEBUG
[HarmonyPrefix]
[HarmonyPatch(typeof(GenericProcess), "OnUpdate")]
public static void OnGenericProcessUpdate(GenericMonitor[] ____monitors)
@@ -101,6 +102,7 @@ public class PractiseMode
____monitors[0].gameObject.AddComponent<PractiseModeUI>();
}
}
# endif
[HarmonyPatch(typeof(GameProcess), "OnUpdate")]
[HarmonyPostfix]

View File

@@ -1,82 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using UnityEngine;
namespace AquaMai.Utils;
public class WindowState
{
private const int GWL_STYLE = -16;
private const int WS_WHATEVER = 0x14CF0000;
private static IntPtr hwnd = IntPtr.Zero;
public static void Execute()
{
if (AquaMai.AppConfig.Utils.Windowed)
{
var alreadyWindowed = Screen.fullScreenMode == FullScreenMode.Windowed;
if (AquaMai.AppConfig.Utils.Width == 0 || AquaMai.AppConfig.Utils.Height == 0)
{
Screen.fullScreenMode = FullScreenMode.Windowed;
}
else
{
alreadyWindowed = false;
Screen.SetResolution(AquaMai.AppConfig.Utils.Width, AquaMai.AppConfig.Utils.Height, FullScreenMode.Windowed);
}
hwnd = GetWindowHandle();
if(alreadyWindowed)
{
SetResizeable();
}
else
{
Task.Run(async () =>
{
await Task.Delay(3000);
// Screen.SetResolution has delay
SetResizeable();
});
}
}
else
{
var width = AquaMai.AppConfig.Utils.Width == 0 ? Display.main.systemWidth : AquaMai.AppConfig.Utils.Width;
var height = AquaMai.AppConfig.Utils.Height == 0 ? Display.main.systemHeight : AquaMai.AppConfig.Utils.Height;
Screen.SetResolution(width, height, FullScreenMode.FullScreenWindow);
}
}
public static void SetResizeable()
{
if (hwnd == IntPtr.Zero) return;
SetWindowLongPtr(hwnd, GWL_STYLE, WS_WHATEVER);
}
private delegate bool EnumThreadDelegate(IntPtr hwnd, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam);
[DllImport("Kernel32.dll")]
static extern int GetCurrentThreadId();
static IntPtr GetWindowHandle()
{
IntPtr returnHwnd = IntPtr.Zero;
var threadId = GetCurrentThreadId();
EnumThreadWindows(threadId,
(hWnd, lParam) =>
{
if (returnHwnd == IntPtr.Zero) returnHwnd = hWnd;
return true;
}, IntPtr.Zero);
return returnHwnd;
}
[DllImport("user32.dll")]
static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, int dwNewLong);
}