From adcce8e2989a6dde68c919203e49f689a1553bc0 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Tue, 25 Mar 2025 21:36:22 +0800 Subject: [PATCH] UXAssist: add profile based option --- UXAssist/Functions/WindowFunctions.cs | 3 +++ UXAssist/Patches/GamePatch.cs | 30 ++++++++++++++++++++++++--- UXAssist/UIConfigWindow.cs | 8 ++++++- UXAssist/UXAssist.cs | 2 ++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/UXAssist/Functions/WindowFunctions.cs b/UXAssist/Functions/WindowFunctions.cs index faeb26b..f5cd34c 100644 --- a/UXAssist/Functions/WindowFunctions.cs +++ b/UXAssist/Functions/WindowFunctions.cs @@ -9,6 +9,7 @@ namespace UXAssist.Functions; public static class WindowFunctions { + private static bool _initialized; public static string ProfileName { get; private set; } private const string GameWindowClass = "UnityWndClass"; @@ -34,6 +35,8 @@ public static class WindowFunctions public static void Init() { + 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}"); diff --git a/UXAssist/Patches/GamePatch.cs b/UXAssist/Patches/GamePatch.cs index 202ff9c..a113639 100644 --- a/UXAssist/Patches/GamePatch.cs +++ b/UXAssist/Patches/GamePatch.cs @@ -22,6 +22,7 @@ public class GamePatch : PatchImpl public static ConfigEntry ConvertSavesFromPeaceEnabled; public static ConfigEntry LastWindowRect; public static ConfigEntry ProfileBasedSaveFolderEnabled; + public static ConfigEntry ProfileBasedOptionEnabled; public static ConfigEntry DefaultProfileName; public static ConfigEntry GameUpsFactor; @@ -85,6 +86,7 @@ public class GamePatch : PatchImpl // AutoSaveOptEnabled.SettingChanged += (_, _) => AutoSaveOpt.Enable(AutoSaveOptEnabled.Value); ConvertSavesFromPeaceEnabled.SettingChanged += (_, _) => ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value); ProfileBasedSaveFolderEnabled.SettingChanged += (_, _) => RefreshSavePath(); + ProfileBasedOptionEnabled.SettingChanged += (_, _) => RefreshSavePath(); DefaultProfileName.SettingChanged += (_, _) => RefreshSavePath(); GameUpsFactor.SettingChanged += (_, _) => { @@ -97,6 +99,7 @@ public class GamePatch : PatchImpl FPSController.SetFixUPS(GameMain.tickPerSec * GameUpsFactor.Value); }; + RefreshSavePath(); } public static void Start() @@ -140,7 +143,13 @@ public class GamePatch : PatchImpl private static void RefreshSavePath() { var profileName = WindowFunctions.ProfileName; - if (profileName == null) return; + if (profileName == null) + { + // We should initialize WindowFunctions before using WindowFunctions.ProfileName + WindowFunctions.Init(); + profileName = WindowFunctions.ProfileName; + if (profileName == null) return; + } if (UIRoot.instance.loadGameWindow.gameObject.activeSelf) { @@ -154,15 +163,30 @@ public class GamePatch : PatchImpl string gameSavePath; if (ProfileBasedSaveFolderEnabled.Value && string.Compare(DefaultProfileName.Value, profileName, StringComparison.OrdinalIgnoreCase) != 0) - gameSavePath = $"{GameConfig.overrideDocumentFolder}{GameConfig.gameName}/Save/{profileName}/"; + gameSavePath = $"{GameConfig.gameDocumentFolder}Save/{profileName}/"; else - gameSavePath = $"{GameConfig.overrideDocumentFolder}{GameConfig.gameName}/Save/"; + gameSavePath = $"{GameConfig.gameDocumentFolder}Save/"; if (string.Compare(GameConfig.gameSavePath, gameSavePath, StringComparison.OrdinalIgnoreCase) == 0) return; GameConfig.gameSavePath = gameSavePath; if (!Directory.Exists(GameConfig.gameSavePath)) { Directory.CreateDirectory(GameConfig.gameSavePath); } + + string optionPath; + if (ProfileBasedOptionEnabled.Value && string.Compare(DefaultProfileName.Value, profileName, StringComparison.OrdinalIgnoreCase) != 0) + { + var path = $"{GameConfig.gameDocumentFolder}Option"; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + optionPath = $"{path}/{profileName}.xml"; + } + else + optionPath = $"{GameConfig.gameDocumentFolder}options.xml"; + if (string.Compare(GameConfig.gameXMLOption, optionPath, StringComparison.OrdinalIgnoreCase) == 0) return; + GameConfig.gameXMLOption = optionPath; } [HarmonyPrefix, HarmonyPatch(typeof(GameMain), nameof(GameMain.HandleApplicationQuit))] diff --git a/UXAssist/UIConfigWindow.cs b/UXAssist/UIConfigWindow.cs index 098c067..bad0ec2 100644 --- a/UXAssist/UIConfigWindow.cs +++ b/UXAssist/UIConfigWindow.cs @@ -34,6 +34,9 @@ public static class UIConfigWindow I18N.Add("Profile-based save folder", "Mod manager profile based save folder", "基于mod管理器配置档案名的存档文件夹"); I18N.Add("Profile-based save folder tips", "Save files are stored in 'Save\\' folder.\nWill use original save location if matching default profile name", "存档文件会存储在'Save\\'文件夹中\n如果匹配默认配置档案名则使用原始存档位置"); + I18N.Add("Profile-based option", "Mod manager profile based option", "基于mod管理器配置档案名的选项设置"); + I18N.Add("Profile-based option tips", "Options are stored in 'Option\\.xml'.\nWill use original save location if matching default profile name", + "配置选项会存储在'Option\\.xml'里\n如果匹配默认配置档案名则使用原始存档位置"); I18N.Add("Default profile name", "Default profile name", "默认配置档案名"); I18N.Add("Logical Frame Rate", "Logical Frame Rate", "逻辑帧倍率"); I18N.Add("Reset", "Reset", "重置"); @@ -179,7 +182,10 @@ public static class UIConfigWindow y += 36f; checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab1, GamePatch.ProfileBasedSaveFolderEnabled, "Profile-based save folder"); wnd.AddTipsButton2(checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab1, "Profile-based save folder", "Profile-based save folder tips", "btn-profile-based-save-folder-tips"); - y += 30f; + y += 36f; + checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab1, GamePatch.ProfileBasedOptionEnabled, "Profile-based option"); + wnd.AddTipsButton2(checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab1, "Profile-based option", "Profile-based option tips", "btn-profile-based-option-tips"); + y += 36f; wnd.AddText2(x + 2f, y, tab1, "Default profile name", 15, "text-default-profile-name"); y += 24f; wnd.AddInputField(x + 2f, y, 200f, tab1, GamePatch.DefaultProfileName, 15, "input-profile-save-folder"); diff --git a/UXAssist/UXAssist.cs b/UXAssist/UXAssist.cs index cfe67ad..f6d9fc0 100644 --- a/UXAssist/UXAssist.cs +++ b/UXAssist/UXAssist.cs @@ -78,6 +78,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave "Mouse cursor scale up multiplier"); GamePatch.ProfileBasedSaveFolderEnabled = Config.Bind("Game", "ProfileBasedSaveFolder", false, "Profile-based save folder"); + GamePatch.ProfileBasedOptionEnabled = Config.Bind("Game", "ProfileBasedOption", false, + "Profile-based option"); GamePatch.DefaultProfileName = Config.Bind("Game", "DefaultProfileName", "Default", "Default profile name, used when profile-based save folder is enabled. Use original game save folder if matched"); /*