1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 21:33:28 +08:00

UXAssist 1.2.6

This commit is contained in:
2024-09-26 21:23:01 +08:00
parent 9668fda718
commit f897c0d9ec
5 changed files with 43 additions and 20 deletions

View File

@@ -1,5 +1,9 @@
## Changlog ## 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 * 1.2.5
+ New feature: `Set process priority` + New feature: `Set process priority`
+ New feature: `Set enabled CPU threads` + New feature: `Set enabled CPU threads`
@@ -202,6 +206,10 @@
## 更新日志 ## 更新日志
* 1.2.6
+ `记住上次退出时的窗口位置和大小`
- 修复了即使选项被禁用也恢复窗口位置的问题
- 修复了窗口最小化时关闭游戏导致窗口位置被错误记录的问题
* 1.2.5 * 1.2.5
+ 新功能:`设置进程优先级` + 新功能:`设置进程优先级`
+ 新功能:`设置使用的CPU线程` + 新功能:`设置使用的CPU线程`

View File

@@ -39,6 +39,7 @@ public static class WindowFunctions
I18N.Add("\nEnabled CPUs: ", "\nEnabled CPUs: ", "\n使用的CPU: "); I18N.Add("\nEnabled CPUs: ", "\nEnabled CPUs: ", "\n使用的CPU: ");
I18N.Add("Unknown", "Unknown", "未知"); I18N.Add("Unknown", "Unknown", "未知");
ProcessorDetails = WinApi.GetLogicalProcessorDetails(); ProcessorDetails = WinApi.GetLogicalProcessorDetails();
SetWindowTitle();
} }
public static void Start() public static void Start()
@@ -50,7 +51,8 @@ public static class WindowFunctions
{ {
_oldWndProc = WinApi.SetWindowLongPtr(gameWnd, WinApi.GWLP_WNDPROC, Marshal.GetFunctionPointerForDelegate(wndProc)); _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]); ProcessPriority.SettingChanged += (_, _) => WinApi.SetPriorityClass(WinApi.GetCurrentProcess(), ProrityFlags[ProcessPriority.Value]);
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) switch ((long)wParam & 0xFFF0L)
{ {
case WinApi.SC_MOVE: case WinApi.SC_MOVE:
if (!_gameLoaded) return (IntPtr)1L; if (GamePatch.LoadLastWindowRectEnabled.Value && !_gameLoaded) return (IntPtr)1L;
break; break;
} }
break; break;
case WinApi.WM_MOVING: case WinApi.WM_MOVING:
if (_gameLoaded) break; if (!GamePatch.LoadLastWindowRectEnabled.Value || _gameLoaded) break;
var rect = GamePatch.LastWindowRect.Value; var rect = GamePatch.LastWindowRect.Value;
if (rect is { z: 0f, w: 0f }) break; if (rect is { z: 0f, w: 0f }) break;
var x = Mathf.RoundToInt(rect.x); var x = Mathf.RoundToInt(rect.x);
@@ -119,7 +121,7 @@ public static class WindowFunctions
Marshal.StructureToPtr(rect2, lParam, false); Marshal.StructureToPtr(rect2, lParam, false);
break; break;
case WinApi.WM_SIZING: case WinApi.WM_SIZING:
if (_gameLoaded) break; if (!GamePatch.LoadLastWindowRectEnabled.Value || _gameLoaded) break;
rect = GamePatch.LastWindowRect.Value; rect = GamePatch.LastWindowRect.Value;
if (rect is { z: 0f, w: 0f }) break; if (rect is { z: 0f, w: 0f }) break;
x = Mathf.RoundToInt(rect.x); x = Mathf.RoundToInt(rect.x);

View File

@@ -11,11 +11,13 @@ using UXAssist.Functions;
namespace UXAssist.Patches; namespace UXAssist.Patches;
public class GamePatch: PatchImpl<GamePatch> public class GamePatch : PatchImpl<GamePatch>
{ {
public static ConfigEntry<bool> EnableWindowResizeEnabled; public static ConfigEntry<bool> EnableWindowResizeEnabled;
public static ConfigEntry<bool> LoadLastWindowRectEnabled; public static ConfigEntry<bool> LoadLastWindowRectEnabled;
public static ConfigEntry<int> MouseCursorScaleUpMultiplier; public static ConfigEntry<int> MouseCursorScaleUpMultiplier;
// public static ConfigEntry<bool> AutoSaveOptEnabled; // public static ConfigEntry<bool> AutoSaveOptEnabled;
public static ConfigEntry<bool> ConvertSavesFromPeaceEnabled; public static ConfigEntry<bool> ConvertSavesFromPeaceEnabled;
public static ConfigEntry<Vector4> LastWindowRect; public static ConfigEntry<Vector4> LastWindowRect;
@@ -26,6 +28,7 @@ public class GamePatch: PatchImpl<GamePatch>
private static PressKeyBind _speedDownKey; private static PressKeyBind _speedDownKey;
private static PressKeyBind _speedUpKey; private static PressKeyBind _speedUpKey;
private static bool _enableGameUpsFactor = true; private static bool _enableGameUpsFactor = true;
public static bool EnableGameUpsFactor public static bool EnableGameUpsFactor
{ {
get => _enableGameUpsFactor; get => _enableGameUpsFactor;
@@ -40,6 +43,7 @@ public class GamePatch: PatchImpl<GamePatch>
GameUpsFactor.Value = 1.0; GameUpsFactor.Value = 1.0;
return; return;
} }
GameUpsFactor.Value = Maths.Clamp(FPSController.instance.fixUPS / GameMain.tickPerSec, 0.1, 10.0); GameUpsFactor.Value = Maths.Clamp(FPSController.instance.fixUPS / GameMain.tickPerSec, 0.1, 10.0);
} }
else else
@@ -71,8 +75,6 @@ public class GamePatch: PatchImpl<GamePatch>
I18N.Add("KEYUPSSpeedUp", "Increase logical frame rate", "提升逻辑帧率"); I18N.Add("KEYUPSSpeedUp", "Increase logical frame rate", "提升逻辑帧率");
I18N.Add("Logical frame rate: {0}x", "Logical frame rate: {0}x", "逻辑帧速率: {0}x"); I18N.Add("Logical frame rate: {0}x", "Logical frame rate: {0}x", "逻辑帧速率: {0}x");
WindowFunctions.SetWindowTitle();
EnableWindowResizeEnabled.SettingChanged += (_, _) => EnableWindowResize.Enable(EnableWindowResizeEnabled.Value); EnableWindowResizeEnabled.SettingChanged += (_, _) => EnableWindowResize.Enable(EnableWindowResizeEnabled.Value);
LoadLastWindowRectEnabled.SettingChanged += (_, _) => LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value); LoadLastWindowRectEnabled.SettingChanged += (_, _) => LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value);
MouseCursorScaleUpMultiplier.SettingChanged += (_, _) => MouseCursorScaleUpMultiplier.SettingChanged += (_, _) =>
@@ -92,6 +94,7 @@ public class GamePatch: PatchImpl<GamePatch>
FPSController.SetFixUPS(0.0); FPSController.SetFixUPS(0.0);
return; return;
} }
FPSController.SetFixUPS(GameMain.tickPerSec * GameUpsFactor.Value); FPSController.SetFixUPS(GameMain.tickPerSec * GameUpsFactor.Value);
}; };
} }
@@ -126,6 +129,7 @@ public class GamePatch: PatchImpl<GamePatch>
GameUpsFactor.Value = Maths.Clamp(Math.Round((GameUpsFactor.Value - 0.5) * 2.0) / 2.0, 0.1, 10.0); 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)); UIRoot.instance.uiGame.generalTips.InvokeRealtimeTipAhead(string.Format("Logical frame rate: {0}x".Translate(), GameUpsFactor.Value));
} }
if (_speedUpKey.keyValue) if (_speedUpKey.keyValue)
{ {
GameUpsFactor.Value = Maths.Clamp(Math.Round((GameUpsFactor.Value + 0.5) * 2.0) / 2.0, 0.1, 10.0); 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<GamePatch>
{ {
UIRoot.instance.loadGameWindow._Close(); UIRoot.instance.loadGameWindow._Close();
} }
if (UIRoot.instance.saveGameWindow.gameObject.activeSelf) if (UIRoot.instance.saveGameWindow.gameObject.activeSelf)
{ {
UIRoot.instance.saveGameWindow._Close(); UIRoot.instance.saveGameWindow._Close();
@@ -166,12 +171,11 @@ public class GamePatch: PatchImpl<GamePatch>
var wnd = WindowFunctions.FindGameWindow(); var wnd = WindowFunctions.FindGameWindow();
if (wnd == IntPtr.Zero) return; if (wnd == IntPtr.Zero) return;
WinApi.GetWindowRect(wnd, out var rect); 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<EnableWindowResize> private class EnableWindowResize : PatchImpl<EnableWindowResize>
{ {
private static bool _enabled; private static bool _enabled;
protected override void OnEnable() protected override void OnEnable()
@@ -214,7 +218,7 @@ public class GamePatch: PatchImpl<GamePatch>
} }
} }
public class LoadLastWindowRect: PatchImpl<LoadLastWindowRect> public class LoadLastWindowRect : PatchImpl<LoadLastWindowRect>
{ {
private static bool _loaded; private static bool _loaded;
@@ -234,11 +238,13 @@ public class GamePatch: PatchImpl<GamePatch>
w = 1280; w = 1280;
needFix = true; needFix = true;
} }
if (h < 100) if (h < 100)
{ {
h = 720; h = 720;
needFix = true; needFix = true;
} }
var sw = Screen.currentResolution.width; var sw = Screen.currentResolution.width;
var sh = Screen.currentResolution.height; var sh = Screen.currentResolution.height;
if (x + w > sw) if (x + w > sw)
@@ -246,26 +252,31 @@ public class GamePatch: PatchImpl<GamePatch>
x = sw - w; x = sw - w;
needFix = true; needFix = true;
} }
if (y + h > sh) if (y + h > sh)
{ {
y = sh - h; y = sh - h;
needFix = true; needFix = true;
} }
if (x < 0) if (x < 0)
{ {
x = 0; x = 0;
needFix = true; needFix = true;
} }
if (y < 0) if (y < 0)
{ {
y = 0; y = 0;
needFix = true; needFix = true;
} }
if (needFix) if (needFix)
{ {
LastWindowRect.Value = new Vector4(x, y, w, h); LastWindowRect.Value = new Vector4(x, y, w, h);
} }
} }
MoveWindowPosition(); MoveWindowPosition();
} }
@@ -289,6 +300,7 @@ public class GamePatch: PatchImpl<GamePatch>
var h = Mathf.RoundToInt(rect.w); var h = Mathf.RoundToInt(rect.w);
Screen.SetResolution(w, h, false); Screen.SetResolution(w, h, false);
} }
WinApi.SetWindowPos(wnd, IntPtr.Zero, x, y, 0, 0, 0x0235); WinApi.SetWindowPos(wnd, IntPtr.Zero, x, y, 0, 0, 0x0235);
} }
@@ -332,13 +344,14 @@ public class GamePatch: PatchImpl<GamePatch>
} }
private static GameOption _gameOption; private static GameOption _gameOption;
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(UIOptionWindow), nameof(UIOptionWindow._OnOpen))] [HarmonyPatch(typeof(UIOptionWindow), nameof(UIOptionWindow._OnOpen))]
private static void UIOptionWindow__OnOpen_Postfix() private static void UIOptionWindow__OnOpen_Postfix()
{ {
_gameOption = DSPGame.globalOption; _gameOption = DSPGame.globalOption;
} }
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(GameOption), nameof(GameOption.Apply))] [HarmonyPatch(typeof(GameOption), nameof(GameOption.Apply))]
private static IEnumerable<CodeInstruction> UIOptionWindow_ApplyOptions_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> UIOptionWindow_ApplyOptions_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
@@ -496,10 +509,10 @@ public class GamePatch: PatchImpl<GamePatch>
} }
*/ */
private class ConvertSavesFromPeace: PatchImpl<ConvertSavesFromPeace> private class ConvertSavesFromPeace : PatchImpl<ConvertSavesFromPeace>
{ {
private static bool _needConvert; private static bool _needConvert;
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(GameDesc), nameof(GameDesc.Import))] [HarmonyPatch(typeof(GameDesc), nameof(GameDesc.Import))]
private static void GameDesc_Import_Postfix(GameDesc __instance) private static void GameDesc_Import_Postfix(GameDesc __instance)
@@ -509,7 +522,7 @@ public class GamePatch: PatchImpl<GamePatch>
__instance.isPeaceMode = false; __instance.isPeaceMode = false;
_needConvert = true; _needConvert = true;
} }
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(GameData), nameof(GameData.Import))] [HarmonyPatch(typeof(GameData), nameof(GameData.Import))]
private static IEnumerable<CodeInstruction> GameData_Import_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> GameData_Import_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
@@ -535,7 +548,7 @@ public class GamePatch: PatchImpl<GamePatch>
} }
[PatchSetCallbackFlag(PatchCallbackFlag.CallOnDisableAfterUnpatch)] [PatchSetCallbackFlag(PatchCallbackFlag.CallOnDisableAfterUnpatch)]
private class MouseCursorScaleUp: PatchImpl<MouseCursorScaleUp> private class MouseCursorScaleUp : PatchImpl<MouseCursorScaleUp>
{ {
public static bool NeedReloadCursors; public static bool NeedReloadCursors;
@@ -554,7 +567,7 @@ public class GamePatch: PatchImpl<GamePatch>
UICursor.loaded = false; UICursor.loaded = false;
UICursor.LoadCursors(); UICursor.LoadCursors();
} }
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(UICursor), nameof(UICursor.LoadCursors))] [HarmonyPatch(typeof(UICursor), nameof(UICursor.LoadCursors))]
private static IEnumerable<CodeInstruction> UICursor_LoadCursors_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> UICursor_LoadCursors_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
@@ -647,7 +660,7 @@ public class GamePatch: PatchImpl<GamePatch>
return result; return result;
} }
} }
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(UICursor), nameof(UICursor.cursorIndexApply), MethodType.Setter)] [HarmonyPatch(typeof(UICursor), nameof(UICursor.cursorIndexApply), MethodType.Setter)]
private static IEnumerable<CodeInstruction> UICursor_set_cursorIndexApply_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> UICursor_set_cursorIndexApply_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)

View File

@@ -4,7 +4,7 @@
<TargetFramework>net472</TargetFramework> <TargetFramework>net472</TargetFramework>
<BepInExPluginGuid>org.soardev.uxassist</BepInExPluginGuid> <BepInExPluginGuid>org.soardev.uxassist</BepInExPluginGuid>
<Description>DSP MOD - UXAssist</Description> <Description>DSP MOD - UXAssist</Description>
<Version>1.2.5</Version> <Version>1.2.6</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<PackageId>UXAssist</PackageId> <PackageId>UXAssist</PackageId>

View File

@@ -1,6 +1,6 @@
{ {
"name": "UXAssist", "name": "UXAssist",
"version_number": "1.2.5", "version_number": "1.2.6",
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UXAssist", "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UXAssist",
"description": "Some functions and patches for better user experience / 一些提升用户体验的功能和补丁", "description": "Some functions and patches for better user experience / 一些提升用户体验的功能和补丁",
"dependencies": [ "dependencies": [