diff --git a/UXAssist/CHANGELOG.md b/UXAssist/CHANGELOG.md index 705c82d..2ad9d4c 100644 --- a/UXAssist/CHANGELOG.md +++ b/UXAssist/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changlog +* 1.2.6 + + `Remember window position and size on last exit` + - Fix a bug that window position is restored even the option is disabled. + - Fix a bug that the last window position is wrongly remembere when game is closed at minimized state. * 1.2.5 + New feature: `Set process priority` + New feature: `Set enabled CPU threads` @@ -202,6 +206,10 @@ ## 更新日志 +* 1.2.6 + + `记住上次退出时的窗口位置和大小` + - 修复了即使选项被禁用也恢复窗口位置的问题 + - 修复了窗口最小化时关闭游戏导致窗口位置被错误记录的问题 * 1.2.5 + 新功能:`设置进程优先级` + 新功能:`设置使用的CPU线程` diff --git a/UXAssist/Functions/WindowFunctions.cs b/UXAssist/Functions/WindowFunctions.cs index 680ce0f..7b941d4 100644 --- a/UXAssist/Functions/WindowFunctions.cs +++ b/UXAssist/Functions/WindowFunctions.cs @@ -39,6 +39,7 @@ public static class WindowFunctions I18N.Add("\nEnabled CPUs: ", "\nEnabled CPUs: ", "\n使用的CPU: "); I18N.Add("Unknown", "Unknown", "未知"); ProcessorDetails = WinApi.GetLogicalProcessorDetails(); + SetWindowTitle(); } public static void Start() @@ -50,7 +51,8 @@ public static class WindowFunctions { _oldWndProc = WinApi.SetWindowLongPtr(gameWnd, WinApi.GWLP_WNDPROC, Marshal.GetFunctionPointerForDelegate(wndProc)); } - GamePatch.LoadLastWindowRect.MoveWindowPosition(true); + if (GamePatch.LoadLastWindowRectEnabled.Value) + GamePatch.LoadLastWindowRect.MoveWindowPosition(true); ProcessPriority.SettingChanged += (_, _) => WinApi.SetPriorityClass(WinApi.GetCurrentProcess(), ProrityFlags[ProcessPriority.Value]); WinApi.SetPriorityClass(WinApi.GetCurrentProcess(), ProrityFlags[ProcessPriority.Value]); @@ -103,12 +105,12 @@ public static class WindowFunctions switch ((long)wParam & 0xFFF0L) { case WinApi.SC_MOVE: - if (!_gameLoaded) return (IntPtr)1L; + if (GamePatch.LoadLastWindowRectEnabled.Value && !_gameLoaded) return (IntPtr)1L; break; } break; case WinApi.WM_MOVING: - if (_gameLoaded) break; + if (!GamePatch.LoadLastWindowRectEnabled.Value || _gameLoaded) break; var rect = GamePatch.LastWindowRect.Value; if (rect is { z: 0f, w: 0f }) break; var x = Mathf.RoundToInt(rect.x); @@ -119,7 +121,7 @@ public static class WindowFunctions Marshal.StructureToPtr(rect2, lParam, false); break; case WinApi.WM_SIZING: - if (_gameLoaded) break; + if (!GamePatch.LoadLastWindowRectEnabled.Value || _gameLoaded) break; rect = GamePatch.LastWindowRect.Value; if (rect is { z: 0f, w: 0f }) break; x = Mathf.RoundToInt(rect.x); diff --git a/UXAssist/Patches/GamePatch.cs b/UXAssist/Patches/GamePatch.cs index 344701c..0453d63 100644 --- a/UXAssist/Patches/GamePatch.cs +++ b/UXAssist/Patches/GamePatch.cs @@ -11,11 +11,13 @@ using UXAssist.Functions; namespace UXAssist.Patches; -public class GamePatch: PatchImpl +public class GamePatch : PatchImpl { public static ConfigEntry EnableWindowResizeEnabled; public static ConfigEntry LoadLastWindowRectEnabled; + public static ConfigEntry MouseCursorScaleUpMultiplier; + // public static ConfigEntry AutoSaveOptEnabled; public static ConfigEntry ConvertSavesFromPeaceEnabled; public static ConfigEntry LastWindowRect; @@ -26,6 +28,7 @@ public class GamePatch: PatchImpl private static PressKeyBind _speedDownKey; private static PressKeyBind _speedUpKey; private static bool _enableGameUpsFactor = true; + public static bool EnableGameUpsFactor { get => _enableGameUpsFactor; @@ -40,6 +43,7 @@ public class GamePatch: PatchImpl GameUpsFactor.Value = 1.0; return; } + GameUpsFactor.Value = Maths.Clamp(FPSController.instance.fixUPS / GameMain.tickPerSec, 0.1, 10.0); } else @@ -71,8 +75,6 @@ public class GamePatch: PatchImpl I18N.Add("KEYUPSSpeedUp", "Increase logical frame rate", "提升逻辑帧率"); I18N.Add("Logical frame rate: {0}x", "Logical frame rate: {0}x", "逻辑帧速率: {0}x"); - WindowFunctions.SetWindowTitle(); - EnableWindowResizeEnabled.SettingChanged += (_, _) => EnableWindowResize.Enable(EnableWindowResizeEnabled.Value); LoadLastWindowRectEnabled.SettingChanged += (_, _) => LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value); MouseCursorScaleUpMultiplier.SettingChanged += (_, _) => @@ -92,6 +94,7 @@ public class GamePatch: PatchImpl FPSController.SetFixUPS(0.0); return; } + FPSController.SetFixUPS(GameMain.tickPerSec * GameUpsFactor.Value); }; } @@ -126,6 +129,7 @@ public class GamePatch: PatchImpl GameUpsFactor.Value = Maths.Clamp(Math.Round((GameUpsFactor.Value - 0.5) * 2.0) / 2.0, 0.1, 10.0); UIRoot.instance.uiGame.generalTips.InvokeRealtimeTipAhead(string.Format("Logical frame rate: {0}x".Translate(), GameUpsFactor.Value)); } + if (_speedUpKey.keyValue) { GameUpsFactor.Value = Maths.Clamp(Math.Round((GameUpsFactor.Value + 0.5) * 2.0) / 2.0, 0.1, 10.0); @@ -142,6 +146,7 @@ public class GamePatch: PatchImpl { UIRoot.instance.loadGameWindow._Close(); } + if (UIRoot.instance.saveGameWindow.gameObject.activeSelf) { UIRoot.instance.saveGameWindow._Close(); @@ -166,12 +171,11 @@ public class GamePatch: PatchImpl var wnd = WindowFunctions.FindGameWindow(); if (wnd == IntPtr.Zero) return; WinApi.GetWindowRect(wnd, out var rect); - LastWindowRect.Value = new Vector4(rect.Left, rect.Top, Screen.width, Screen.height); + LastWindowRect.Value = new Vector4(rect.Left < 20 - Screen.width ? 0 : rect.Left, rect.Top < 20 - Screen.height ? 0 : rect.Top, Screen.width, Screen.height); } - private class EnableWindowResize: PatchImpl + private class EnableWindowResize : PatchImpl { - private static bool _enabled; protected override void OnEnable() @@ -214,7 +218,7 @@ public class GamePatch: PatchImpl } } - public class LoadLastWindowRect: PatchImpl + public class LoadLastWindowRect : PatchImpl { private static bool _loaded; @@ -234,11 +238,13 @@ public class GamePatch: PatchImpl w = 1280; needFix = true; } + if (h < 100) { h = 720; needFix = true; } + var sw = Screen.currentResolution.width; var sh = Screen.currentResolution.height; if (x + w > sw) @@ -246,26 +252,31 @@ public class GamePatch: PatchImpl x = sw - w; needFix = true; } + if (y + h > sh) { y = sh - h; needFix = true; } + if (x < 0) { x = 0; needFix = true; } + if (y < 0) { y = 0; needFix = true; } + if (needFix) { LastWindowRect.Value = new Vector4(x, y, w, h); } } + MoveWindowPosition(); } @@ -289,6 +300,7 @@ public class GamePatch: PatchImpl var h = Mathf.RoundToInt(rect.w); Screen.SetResolution(w, h, false); } + WinApi.SetWindowPos(wnd, IntPtr.Zero, x, y, 0, 0, 0x0235); } @@ -332,13 +344,14 @@ public class GamePatch: PatchImpl } private static GameOption _gameOption; + [HarmonyPostfix] [HarmonyPatch(typeof(UIOptionWindow), nameof(UIOptionWindow._OnOpen))] private static void UIOptionWindow__OnOpen_Postfix() { _gameOption = DSPGame.globalOption; } - + [HarmonyTranspiler] [HarmonyPatch(typeof(GameOption), nameof(GameOption.Apply))] private static IEnumerable UIOptionWindow_ApplyOptions_Transpiler(IEnumerable instructions, ILGenerator generator) @@ -496,10 +509,10 @@ public class GamePatch: PatchImpl } */ - private class ConvertSavesFromPeace: PatchImpl + private class ConvertSavesFromPeace : PatchImpl { private static bool _needConvert; - + [HarmonyPostfix] [HarmonyPatch(typeof(GameDesc), nameof(GameDesc.Import))] private static void GameDesc_Import_Postfix(GameDesc __instance) @@ -509,7 +522,7 @@ public class GamePatch: PatchImpl __instance.isPeaceMode = false; _needConvert = true; } - + [HarmonyTranspiler] [HarmonyPatch(typeof(GameData), nameof(GameData.Import))] private static IEnumerable GameData_Import_Transpiler(IEnumerable instructions, ILGenerator generator) @@ -535,7 +548,7 @@ public class GamePatch: PatchImpl } [PatchSetCallbackFlag(PatchCallbackFlag.CallOnDisableAfterUnpatch)] - private class MouseCursorScaleUp: PatchImpl + private class MouseCursorScaleUp : PatchImpl { public static bool NeedReloadCursors; @@ -554,7 +567,7 @@ public class GamePatch: PatchImpl UICursor.loaded = false; UICursor.LoadCursors(); } - + [HarmonyTranspiler] [HarmonyPatch(typeof(UICursor), nameof(UICursor.LoadCursors))] private static IEnumerable UICursor_LoadCursors_Transpiler(IEnumerable instructions, ILGenerator generator) @@ -647,7 +660,7 @@ public class GamePatch: PatchImpl return result; } } - + [HarmonyTranspiler] [HarmonyPatch(typeof(UICursor), nameof(UICursor.cursorIndexApply), MethodType.Setter)] private static IEnumerable UICursor_set_cursorIndexApply_Transpiler(IEnumerable instructions, ILGenerator generator) diff --git a/UXAssist/UXAssist.csproj b/UXAssist/UXAssist.csproj index bfb1922..ba485f6 100644 --- a/UXAssist/UXAssist.csproj +++ b/UXAssist/UXAssist.csproj @@ -4,7 +4,7 @@ net472 org.soardev.uxassist DSP MOD - UXAssist - 1.2.5 + 1.2.6 true latest UXAssist diff --git a/UXAssist/package/manifest.json b/UXAssist/package/manifest.json index 93f944a..652dbbf 100644 --- a/UXAssist/package/manifest.json +++ b/UXAssist/package/manifest.json @@ -1,6 +1,6 @@ { "name": "UXAssist", - "version_number": "1.2.5", + "version_number": "1.2.6", "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UXAssist", "description": "Some functions and patches for better user experience / 一些提升用户体验的功能和补丁", "dependencies": [