From d711dd25ef30372cee23441501a1872c3a48b160 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Tue, 23 Sep 2025 01:34:42 +0800 Subject: [PATCH] remove cpu affinity settings, as they are officially supported --- UXAssist/CHANGELOG.md | 4 + UXAssist/Common/WinApi.cs | 128 -------------------------- UXAssist/Functions/WindowFunctions.cs | 84 ----------------- UXAssist/README.md | 6 -- UXAssist/UIConfigWindow.cs | 27 ------ UXAssist/UXAssist.cs | 6 -- 6 files changed, 4 insertions(+), 251 deletions(-) diff --git a/UXAssist/CHANGELOG.md b/UXAssist/CHANGELOG.md index aa22abd..184ac22 100644 --- a/UXAssist/CHANGELOG.md +++ b/UXAssist/CHANGELOG.md @@ -3,6 +3,10 @@ ## Changlog +* 1.4.0 + + Support game version 0.10.33 (does not support older versions now) + + Remove `Scale up mouse cursor`: Unity 2022 set cursor size from system settings, software rendering does not affect its size now. + + Remove `Set enabled CPU threads` as they are officially supported. * 1.3.7 + `Re-initialize planet`: Fix a possible crash. + `Auto-config logistic stations`: Add `Set default remote logic to storage` diff --git a/UXAssist/Common/WinApi.cs b/UXAssist/Common/WinApi.cs index a345f90..3b30e74 100644 --- a/UXAssist/Common/WinApi.cs +++ b/UXAssist/Common/WinApi.cs @@ -131,9 +131,6 @@ public static class WinApi [DllImport("user32", ExactSpelling = true)] public static extern IntPtr MonitorFromRect([In] ref Rect lpRect, uint dwFlags); - [DllImport("kernel32", ExactSpelling = true, SetLastError = true)] - public static extern bool GetProcessAffinityMask(IntPtr hProcess, out ulong lpProcessAffinityMask, out ulong lpSystemAffinityMask); - [DllImport("kernel32", ExactSpelling = true, SetLastError = true)] public static extern IntPtr GetCurrentProcess(); @@ -143,9 +140,6 @@ public static class WinApi [DllImport("kernel32", ExactSpelling = true)] public static extern IntPtr GetConsoleWindow(); - [DllImport("kernel32", ExactSpelling = true, SetLastError = true)] - public static extern bool SetProcessAffinityMask(IntPtr hProcess, ulong dwProcessAffinityMask); - // GetPriorityClass and SetPriorityClass [DllImport("kernel32", ExactSpelling = true, SetLastError = true)] public static extern int GetPriorityClass(IntPtr hProcess); @@ -160,126 +154,4 @@ public static class WinApi public static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam); #endregion - - #region GetLogicalProcessorInformationEx - - [Flags] - private enum LOGICAL_PROCESSOR_RELATIONSHIP - { - RelationProcessorCore, - RelationNumaNode, - RelationCache, - RelationProcessorPackage, - RelationGroup, - RelationAll = 0xffff - } - - [StructLayout(LayoutKind.Sequential, Pack = 4)] - private struct GROUP_AFFINITY - { - public nuint Mask; - public ushort Group; - public ushort Reserved0; - public ushort Reserved1; - public ushort Reserved3; - } - - [StructLayout(LayoutKind.Sequential, Pack = 4)] - private struct PROCESSOR_RELATIONSHIP - { - public byte Flags; - public byte EfficiencyClass; - public ushort Reserved0; - public uint Reserved1; - public uint Reserved2; - public uint Reserved3; - public uint Reserved4; - public ushort Reserved5; - public ushort GroupCount; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] - public GROUP_AFFINITY[] GroupMask; - } - - [StructLayout(LayoutKind.Sequential)] - private struct SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX - { - public LOGICAL_PROCESSOR_RELATIONSHIP Relationship; - public uint Size; - public PROCESSOR_RELATIONSHIP Processor; - } - - [DllImport("kernel32", SetLastError = true)] - private static extern bool GetLogicalProcessorInformationEx( - LOGICAL_PROCESSOR_RELATIONSHIP relationshipType, - IntPtr buffer, - ref uint returnLength - ); - - public struct LogicalProcessorDetails - { - public int CoreCount; - public int ThreadCount; - public int PerformanceCoreCount; - public int EfficiencyCoreCount; - public ulong PerformanceCoreMask; - public ulong EfficiencyCoreMask; - public bool HybridArchitecture => PerformanceCoreCount > 0 && EfficiencyCoreCount > 0; - } - - public static LogicalProcessorDetails GetLogicalProcessorDetails() - { - uint returnLength = 0; - GetLogicalProcessorInformationEx(LOGICAL_PROCESSOR_RELATIONSHIP.RelationProcessorCore, IntPtr.Zero, ref returnLength); - var result = new LogicalProcessorDetails(); - if (Marshal.GetLastWin32Error() != ERROR_INSUFFICIENT_BUFFER) return result; - var ptr = Marshal.AllocHGlobal((int)returnLength); - try - { - if (!GetLogicalProcessorInformationEx(LOGICAL_PROCESSOR_RELATIONSHIP.RelationProcessorCore, ptr, ref returnLength)) - return result; - uint offset = 0; - var item = ptr; - while (offset < returnLength) - { - var buffer = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)Marshal.PtrToStructure(item, typeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)); - offset += buffer.Size; - item += (int)buffer.Size; - if (buffer.Relationship != LOGICAL_PROCESSOR_RELATIONSHIP.RelationProcessorCore) continue; - result.CoreCount++; - var mask = buffer.Processor.GroupMask[0].Mask; - var tcount = CountBitsSet(mask); - result.ThreadCount += tcount; - if (buffer.Processor.EfficiencyClass > 0) - { - result.PerformanceCoreCount++; - result.PerformanceCoreMask |= mask; - } - else - { - result.EfficiencyCoreCount++; - result.EfficiencyCoreMask |= mask; - } - } - } - finally - { - Marshal.FreeHGlobal(ptr); - } - - return result; - - static int CountBitsSet(ulong mask) - { - var count = 0; - while (mask != 0) - { - mask &= mask - 1; - count++; - } - - return count; - } - } - - #endregion } \ No newline at end of file diff --git a/UXAssist/Functions/WindowFunctions.cs b/UXAssist/Functions/WindowFunctions.cs index 9d6f3ff..dcb1ae1 100644 --- a/UXAssist/Functions/WindowFunctions.cs +++ b/UXAssist/Functions/WindowFunctions.cs @@ -16,10 +16,7 @@ public static class WindowFunctions private static IntPtr _oldWndProc = IntPtr.Zero; private static IntPtr _gameWindowHandle = IntPtr.Zero; - public static WinApi.LogicalProcessorDetails ProcessorDetails { get; private set; } - public static ConfigEntry ProcessPriority; - public static ConfigEntry ProcessAffinity; private static readonly int[] ProrityFlags = [ @@ -34,12 +31,6 @@ public static class WindowFunctions { if (_initialized) return; _initialized = true; - I18N.Add("Cores: {0}\nThreads: {1}", "Cores: {0}\nThreads: {1}", "核心数: {0}\n线程数: {1}"); - I18N.Add("\nP-Cores: {0}\nE-Cores: {1}", "\nP-Cores: {0}\nE-Cores: {1}", "\n性能核心: {0}\n能效核心: {1}"); - I18N.Add("\nPriority: {0}", "\nProcess priority: {0}", "\n进程优先级: {0}"); - I18N.Add("\nEnabled CPUs: ", "\nEnabled CPUs: ", "\n使用的CPU: "); - I18N.Add("Unknown", "Unknown", "未知"); - ProcessorDetails = WinApi.GetLogicalProcessorDetails(); SetWindowTitle(); } @@ -54,37 +45,6 @@ public static class WindowFunctions ProcessPriority.SettingChanged += (_, _) => WinApi.SetPriorityClass(WinApi.GetCurrentProcess(), ProrityFlags[ProcessPriority.Value]); WinApi.SetPriorityClass(WinApi.GetCurrentProcess(), ProrityFlags[ProcessPriority.Value]); - ProcessAffinity.SettingChanged += (_, _) => UpdateAffinity(); - UpdateAffinity(); - return; - - static void UpdateAffinity() - { - var process = WinApi.GetCurrentProcess(); - if (!WinApi.GetProcessAffinityMask(process, out _, out var systemMask)) - { - systemMask = ulong.MaxValue; - } - - switch (ProcessAffinity.Value) - { - case 0: - WinApi.SetProcessAffinityMask(process, systemMask); - break; - case 1: - WinApi.SetProcessAffinityMask(process, systemMask & ((1UL << (ProcessorDetails.ThreadCount / 2)) - 1UL)); - break; - case 2: - WinApi.SetProcessAffinityMask(process, systemMask & (ProcessorDetails.ThreadCount > 16 ? 0xFFUL : 1UL)); - break; - case 3: - WinApi.SetProcessAffinityMask(process, systemMask & ProcessorDetails.PerformanceCoreMask); - break; - case 4: - WinApi.SetProcessAffinityMask(process, systemMask & ProcessorDetails.EfficiencyCoreMask); - break; - } - } } private static IntPtr GameWndProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam) @@ -118,50 +78,6 @@ public static class WindowFunctions }; } - public static void ShowCPUInfo() - { - var details = ProcessorDetails; - var msg = string.Format("Cores: {0}\nThreads: {1}".Translate(), details.CoreCount, details.ThreadCount); - var hybrid = details.HybridArchitecture; - if (hybrid) - { - msg += string.Format("\nP-Cores: {0}\nE-Cores: {1}".Translate(), details.PerformanceCoreCount, details.EfficiencyCoreCount); - } - - var handle = WinApi.GetCurrentProcess(); - var prio = GetPriorityName(WinApi.GetPriorityClass(handle)); - msg += string.Format("\nPriority: {0}".Translate(), prio); - - var aff = 0UL; - if (WinApi.GetProcessAffinityMask(handle, out var processMask, out var systemMask)) - aff = processMask & systemMask; - - msg += "\nEnabled CPUs: ".Translate(); - var first = true; - for (var i = 0; aff != 0UL; i++) - { - if ((aff & 1UL) != 0) - { - if (first) - first = false; - else - msg += ","; - msg += i; - if (hybrid) - { - if ((details.PerformanceCoreMask & (1UL << i)) != 0) - msg += "(P)"; - else if ((details.EfficiencyCoreMask & (1UL << i)) != 0) - msg += "(E)"; - } - } - - aff >>= 1; - } - - UIMessageBox.Show("CPU Info".Translate(), msg, "确定".Translate(), -1); - } - public static void SetWindowTitle() { // Get profile name from command line arguments, and set window title accordingly diff --git a/UXAssist/README.md b/UXAssist/README.md index a111226..ec7c31a 100644 --- a/UXAssist/README.md +++ b/UXAssist/README.md @@ -22,8 +22,6 @@ * Enable game window resize * Remember window position and size on last exit * Convert Peace-Mode saves to Combat-Mode on loading - * Scale up mouse cursor - * Note: This will enable software cursor mode, which may cause mouse movement lag on heavy load. * Mod manager profile based save folder * Save files are stored in `Save\` folder. * Will use original save location if matching default profile name. @@ -38,7 +36,6 @@ * When set game speed in mod `Auxilaryfunction`, this feature will be disabled. * When mod `BulletTime` is installed, this feature will be hidden, but patch `BulletTime`'s speed control, to make its maximum speed 10x. * Set process priority - * Set enabled CPU threads * Increase maximum count of Metadata Instantiations to 20000 (from 2000) * Increase capacity of player order queue to 128 (from 16) * Starmap view: @@ -179,8 +176,6 @@ * 可调整游戏窗口大小(可最大化和拖动边框) * 记住上次退出时的窗口位置和大小 * 在加载和平模式存档时将其转换为战斗模式 - * 放大鼠标指针 - * 注意:这将启用软件指针模式,可能会在CPU负载较重时导致鼠标移动延迟 * 基于mod管理器配置档案名的存档文件夹 * 存档文件会存储在`Save\`文件夹中 * 如果匹配默认配置档案名则使用原始存档位置 @@ -195,7 +190,6 @@ * 当在`Auxilaryfunction`mod中设置游戏速度时,此功能将被禁用 * 当安装了`BulletTime`mod时,此功能将被隐藏,但会对`BulletTime`的速度控制打补丁,使其最大速度变为10倍 * 设置进程优先级 - * 设置使用的CPU线程 * 将元数据提取的最大数量增加到20000(原来为2000) * 将玩家指令队列的容量增加到128(原来为16) * 星图: diff --git a/UXAssist/UIConfigWindow.cs b/UXAssist/UIConfigWindow.cs index 50214e6..6f9c84a 100644 --- a/UXAssist/UIConfigWindow.cs +++ b/UXAssist/UIConfigWindow.cs @@ -47,14 +47,6 @@ public static class UIConfigWindow I18N.Add("Normal", "Normal", "正常"); I18N.Add("Below Normal", "Below Normal", "低于正常"); I18N.Add("Idle", "Idle", "空闲"); - I18N.Add("Enabled CPUs", "Enabled CPU Threads", "使用CPU线程"); - I18N.Add("All CPUs", "All CPUs", "所有CPU"); - I18N.Add("First {0} CPUs", "First {0} CPUs", "前{0}个CPU"); - I18N.Add("First 8 CPUs", "First 8 CPUs", "前8个CPU"); - I18N.Add("First CPU only", "First CPU only", "仅第一个CPU"); - I18N.Add("All P-Cores", "All P-Cores", "所有性能(P)核心"); - I18N.Add("All E-Cores", "All E-Cores", "所有能效(E)核心"); - I18N.Add("CPU Info", "CPU Info", "CPU信息"); I18N.Add("Unlimited interactive range", "Unlimited interactive range", "无限交互距离"); I18N.Add("Night Light", "Sunlight at night", "夜间日光灯"); I18N.Add("Angle X:", "Angle X:", "入射角度X:"); @@ -339,25 +331,6 @@ public static class UIConfigWindow } y += 36f; wnd.AddComboBox(x + 2f, y, tab1, "Process priority").WithItems("High", "Above Normal", "Normal", "Below Normal", "Idle").WithSize(100f, 0f).WithConfigEntry(WindowFunctions.ProcessPriority); - var details = WindowFunctions.ProcessorDetails; - string[] affinities; - if (details.HybridArchitecture) - { - affinities = new string[5]; - affinities[3] = "All P-Cores"; - affinities[4] = "All E-Cores"; - } - else - { - affinities = new string[3]; - } - affinities[0] = "All CPUs"; - affinities[1] = string.Format("First {0} CPUs".Translate(), details.ThreadCount / 2); - affinities[2] = details.ThreadCount > 16 ? "First 8 CPUs" : "First CPU only"; - y += 36f; - wnd.AddComboBox(x + 2f, y, tab1, "Enabled CPUs").WithItems(affinities).WithSize(200f, 0f).WithConfigEntry(WindowFunctions.ProcessAffinity); - y += 36f; - ((RectTransform)wnd.AddButton(x, y, tab1, "CPU Info", 16, "button-show-cpu-info", WindowFunctions.ShowCPUInfo).transform).sizeDelta = new Vector2(100f, 25f); var tab2 = wnd.AddTab(trans, "Factory"); x = 0f; diff --git a/UXAssist/UXAssist.cs b/UXAssist/UXAssist.cs index 0289ddd..d1cda83 100644 --- a/UXAssist/UXAssist.cs +++ b/UXAssist/UXAssist.cs @@ -86,12 +86,6 @@ public class UXAssist : BaseUnityPlugin, IModCanSave "Game UPS factor (1.0 for normal speed)"); WindowFunctions.ProcessPriority = Config.Bind("Game", "ProcessPriority", 2, new ConfigDescription("Game process priority\n 0: High 1: Above Normal 2: Normal 3: Below Normal 4: Idle", new AcceptableValueRange(0, 4))); - WindowFunctions.ProcessAffinity = Config.Bind("Game", "CPUAffinity", -1, - new ConfigDescription(""" - Game process CPU affinity - 0: All 1: First-half CPUs 2. First 8 CPUs (if total CPUs are greater than 16) - 3. All Performance Cores(If Intel 13th or greater) 4. All Efficiency Cores(If Intel 13th or greater) - """, new AcceptableValueRange(0, 4))); FactoryPatch.UnlimitInteractiveEnabled = Config.Bind("Factory", "UnlimitInteractive", false, "Unlimit interactive range");