From ac7f2ef63c2413ca125cab6263f39c05c956ebf1 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Tue, 15 Apr 2025 21:04:22 +0800 Subject: [PATCH] UXAssist WIP: finished shortcuts for show stars' name --- UXAssist/Patches/PlayerPatch.cs | 215 +++++++++++++++++++++++++++----- UXAssist/UIConfigWindow.cs | 3 + UXAssist/UXAssist.cs | 2 + 3 files changed, 186 insertions(+), 34 deletions(-) diff --git a/UXAssist/Patches/PlayerPatch.cs b/UXAssist/Patches/PlayerPatch.cs index 79d2d21..6e097e2 100644 --- a/UXAssist/Patches/PlayerPatch.cs +++ b/UXAssist/Patches/PlayerPatch.cs @@ -8,19 +8,41 @@ using UXAssist.Common; namespace UXAssist.Patches; -public class PlayerPatch: PatchImpl +public static class PlayerPatch { public static ConfigEntry EnhancedMechaForgeCountControlEnabled; public static ConfigEntry HideTipsForSandsChangesEnabled; + public static ConfigEntry ShortcutKeysForStarsNameEnabled; public static ConfigEntry AutoNavigationEnabled; public static ConfigEntry AutoCruiseEnabled; public static ConfigEntry AutoBoostEnabled; public static ConfigEntry DistanceToWarp; + private static PressKeyBind _showAllStarsNameKey; + private static PressKeyBind _toggleAllStarsNameKey; private static PressKeyBind _autoDriveKey; - private static PressKeyBind _showAllAstrosNameKey; public static void Init() { + _showAllStarsNameKey = KeyBindings.RegisterKeyBinding(new BuiltinKey + { + key = new CombineKey(0, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false), + conflictGroup = KeyBindConflict.UI | KeyBindConflict.KEYBOARD_KEYBIND, + name = "ShowAllStarsName", + canOverride = true + } + ); + I18N.Add("KEYShowAllStarsName", "Keep pressing to show all Stars' name", "按住显示所有星系名称"); + + _toggleAllStarsNameKey = KeyBindings.RegisterKeyBinding(new BuiltinKey + { + key = new CombineKey((int)KeyCode.Tab, 0, ECombineKeyAction.OnceClick, false), + conflictGroup = KeyBindConflict.UI | KeyBindConflict.KEYBOARD_KEYBIND, + name = "ToggleAllStarsName", + canOverride = true + } + ); + I18N.Add("KEYToggleAllStarsName", "Toggle display of all Stars' name", "切换所有星系名称显示状态"); + _autoDriveKey = KeyBindings.RegisterKeyBinding(new BuiltinKey { key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true), @@ -32,18 +54,9 @@ public class PlayerPatch: PatchImpl I18N.Add("AutoCruiseOn", "Auto-cruise enabled", "已启用自动巡航"); I18N.Add("AutoCruiseOff", "Auto-cruise disabled", "已禁用自动巡航"); - _showAllAstrosNameKey = KeyBindings.RegisterKeyBinding(new BuiltinKey - { - key = new CombineKey(0, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false), - conflictGroup = KeyBindConflict.UI | KeyBindConflict.KEYBOARD_KEYBIND, - name = "ShowAllAstrosName", - canOverride = true - } - ); - I18N.Add("KEYShowAllAstrosName", "Keep pressing to show all astros' name", "按住显示所有星球名称"); - EnhancedMechaForgeCountControlEnabled.SettingChanged += (_, _) => EnhancedMechaForgeCountControl.Enable(EnhancedMechaForgeCountControlEnabled.Value); HideTipsForSandsChangesEnabled.SettingChanged += (_, _) => HideTipsForSandsChanges.Enable(HideTipsForSandsChangesEnabled.Value); + ShortcutKeysForStarsNameEnabled.SettingChanged += (_, _) => ShortcutKeysForStarsName.Enable(ShortcutKeysForStarsNameEnabled.Value); AutoNavigationEnabled.SettingChanged += (_, _) => AutoNavigation.Enable(AutoNavigationEnabled.Value); } @@ -51,12 +64,16 @@ public class PlayerPatch: PatchImpl { EnhancedMechaForgeCountControl.Enable(EnhancedMechaForgeCountControlEnabled.Value); HideTipsForSandsChanges.Enable(HideTipsForSandsChangesEnabled.Value); + ShortcutKeysForStarsName.Enable(ShortcutKeysForAstrosNameEnabled.Value); AutoNavigation.Enable(AutoNavigationEnabled.Value); - Enable(true); } public static void OnUpdate() { + if (_toggleAllStarsNameKey.keyValue) + { + ShortcutKeysForStarsName.ToggleAllStarsName(); + } if (_autoDriveKey.keyValue) { AutoNavigation.ToggleAutoCruise(); @@ -65,32 +82,12 @@ public class PlayerPatch: PatchImpl public static void Uninit() { - Enable(false); EnhancedMechaForgeCountControl.Enable(false); HideTipsForSandsChanges.Enable(false); + ShortcutKeysForStarsName.Enable(false); AutoNavigation.Enable(false); } - [HarmonyTranspiler] - [HarmonyPatch(typeof(UIStarmapStar), nameof(UIStarmapStar._OnLateUpdate))] - private static IEnumerable UIStarmapStar__OnLateUpdate_Transpiler(IEnumerable instructions, ILGenerator generator) - { - var matcher = new CodeMatcher(instructions, generator); - Label? br = null; - matcher.MatchForward(false, - new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(UIStarmapStar), nameof(UIStarmapStar.projectedCoord))), - new CodeMatch(ci => ci.IsLdloc()), - new CodeMatch(ci => ci.Branches(out br)) - ); - matcher.Advance(3); - matcher.InsertAndAdvance( - new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PlayerPatch), nameof(_showAllAstrosNameKey))), - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(KeyBindings), nameof(KeyBindings.IsKeyPressing))), - new CodeInstruction(OpCodes.Brtrue, br.Value) - ); - return matcher.InstructionEnumeration(); - } - private class EnhancedMechaForgeCountControl: PatchImpl { [HarmonyTranspiler] @@ -156,6 +153,156 @@ public class PlayerPatch: PatchImpl } } + public class ShortcutKeysForStarsName: PatchImpl + { + private static int _showAllStarsNameStatus; + + public static void ToggleAllStarsName() + { + _showAllStarsNameStatus = (_showAllStarsNameStatus + 1) % 3; + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(UIStarmapStar), nameof(UIStarmapStar._OnLateUpdate))] + private static IEnumerable UIStarmapStar__OnLateUpdate_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldloc_1), + new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(UIStarmapStar), nameof(UIStarmapStar.projected))) + ); + matcher.Advance(3); + matcher.CreateLabel(out var jumpPos1); + matcher.InsertAndAdvance( + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(ShortcutKeysForStarsName), nameof(_showAllStarsNameStatus))), + new CodeInstruction(OpCodes.Ldc_I4_2), + new CodeInstruction(OpCodes.Ceq), + new CodeInstruction(OpCodes.Brfalse, jumpPos1), + new CodeInstruction(OpCodes.Ldc_I4_0), + new CodeInstruction(OpCodes.Stloc_1) + ); + Label? jumpPos2 = null; + matcher.MatchForward(false, + new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(UIStarmapStar), nameof(UIStarmapStar.projectedCoord))), + new CodeMatch(ci => ci.IsLdloc()), + new CodeMatch(ci => ci.Branches(out jumpPos2)) + ); + matcher.Advance(3); + var labels = matcher.Labels; + matcher.Labels = null; + matcher.InsertAndAdvance( + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(ShortcutKeysForStarsName), nameof(_showAllStarsNameStatus))).WithLabels(labels), + new CodeInstruction(OpCodes.Ldc_I4_1), + new CodeInstruction(OpCodes.Ceq), + new CodeInstruction(OpCodes.Brtrue, jumpPos2.Value), + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PlayerPatch), nameof(_showAllStarsNameKey))), + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(KeyBindings), nameof(KeyBindings.IsKeyPressing))), + new CodeInstruction(OpCodes.Brtrue, jumpPos2.Value) + ); + return matcher.InstructionEnumeration(); + } +/* + [HarmonyTranspiler] + [HarmonyPatch(typeof(UIStarmapPlanet), nameof(UIStarmapPlanet._OnLateUpdate))] + private static IEnumerable UIStarmapPlanet__OnLateUpdate_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldloc_3), + new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(UIStarmapPlanet), nameof(UIStarmapPlanet.projected))) + ); + matcher.Advance(3); + matcher.CreateLabel(out var jumpPos1); + matcher.InsertAndAdvance( + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(ShortcutKeysForStarsName), nameof(_showAllStarsNameStatus))), + new CodeInstruction(OpCodes.Ldc_I4_2), + new CodeInstruction(OpCodes.Ceq), + new CodeInstruction(OpCodes.Brfalse, jumpPos1), + new CodeInstruction(OpCodes.Ldc_I4_0), + new CodeInstruction(OpCodes.Stloc_3) + ); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStarmapPlanet), nameof(UIStarmapPlanet.gameHistory))), + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStarmapPlanet), nameof(UIStarmapPlanet.planet))), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PlanetData), nameof(PlanetData.id))), + new CodeMatch(OpCodes.Callvirt, AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.GetPlanetPin))), + new CodeMatch(OpCodes.Ldc_I4_1), + new CodeMatch(ci => ci.Branches(out _)), + new CodeMatch(OpCodes.Ldc_I4_1), + new CodeMatch(ci => ci.IsStloc()), + new CodeMatch(ci => ci.Branches(out _)) + ); + matcher.CreateLabelAt(matcher.Pos + 8, out var jumpPos); + var labels = matcher.Labels; + matcher.Labels = null; + matcher.InsertAndAdvance( + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(ShortcutKeysForStarsName), nameof(_showAllStarsNameStatus))).WithLabels(labels), + new CodeInstruction(OpCodes.Ldc_I4_1), + new CodeInstruction(OpCodes.Ceq), + new CodeInstruction(OpCodes.Brtrue, jumpPos), + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PlayerPatch), nameof(_showAllStarsNameKey))), + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(KeyBindings), nameof(KeyBindings.IsKeyPressing))), + new CodeInstruction(OpCodes.Brtrue, jumpPos) + ); + return matcher.InstructionEnumeration(); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(UIStarmapDFHive), nameof(UIStarmapDFHive._OnLateUpdate))] + private static IEnumerable UIStarmapDFHive__OnLateUpdate_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(ci => ci.IsLdloc()), + new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(UIStarmapDFHive), nameof(UIStarmapDFHive.projected))) + ); + matcher.Advance(3); + matcher.CreateLabel(out var jumpPos1); + matcher.InsertAndAdvance( + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(ShortcutKeysForStarsName), nameof(_showAllStarsNameStatus))), + new CodeInstruction(OpCodes.Ldc_I4_2), + new CodeInstruction(OpCodes.Ceq), + new CodeInstruction(OpCodes.Brfalse, jumpPos1), + new CodeInstruction(OpCodes.Ldc_I4_0), + new CodeInstruction(OpCodes.Stloc_S, 4) + ); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStarmapDFHive), nameof(UIStarmapDFHive.gameHistory))), + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStarmapDFHive), nameof(UIStarmapDFHive.hive))), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(EnemyDFHiveSystem), nameof(EnemyDFHiveSystem.hiveStarId))), + new CodeMatch(OpCodes.Ldc_I4, 1000000), + new CodeMatch(OpCodes.Sub), + new CodeMatch(OpCodes.Callvirt, AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.GetHivePin))), + new CodeMatch(OpCodes.Ldc_I4_1), + new CodeMatch(ci => ci.Branches(out _)), + new CodeMatch(OpCodes.Ldc_I4_1), + new CodeMatch(ci => ci.IsStloc()), + new CodeMatch(ci => ci.Branches(out _)) + ); + matcher.CreateLabelAt(matcher.Pos + 10, out var jumpPos); + var labels = matcher.Labels; + matcher.Labels = null; + matcher.InsertAndAdvance( + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(ShortcutKeysForStarsName), nameof(_showAllStarsNameStatus))).WithLabels(labels), + new CodeInstruction(OpCodes.Ldc_I4_1), + new CodeInstruction(OpCodes.Ceq), + new CodeInstruction(OpCodes.Brtrue, jumpPos), + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PlayerPatch), nameof(_showAllStarsNameKey))), + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(KeyBindings), nameof(KeyBindings.IsKeyPressing))), + new CodeInstruction(OpCodes.Brtrue, jumpPos) + ); + return matcher.InstructionEnumeration(); + } +*/ + } + public class AutoNavigation: PatchImpl { private static bool _canUseWarper; diff --git a/UXAssist/UIConfigWindow.cs b/UXAssist/UIConfigWindow.cs index 31a2088..200e825 100644 --- a/UXAssist/UIConfigWindow.cs +++ b/UXAssist/UIConfigWindow.cs @@ -93,6 +93,7 @@ public static class UIConfigWindow I18N.Add("Assembler buffer time multiplier(in seconds)", "Assembler buffer time multiplier(in seconds)", "工厂配方缓冲时间倍率(秒)"); I18N.Add("Assembler buffer minimum multiplier", "Assembler buffer minimum multiplier", "工厂配方缓冲最小倍率"); I18N.Add("Ray Receiver Graviton Lens buffer count", "Ray Receiver Graviton Lens buffer count", "射线接收器透镜缓冲数量"); + I18N.Add("Shortcut keys for showing stars' name", "Shortcut keys for showing stars' name", "启用显示所有星系名称的快捷键"); I18N.Add("Auto navigation on sailings", "Auto navigation on sailings", "宇宙航行时自动导航"); I18N.Add("Enable auto-cruise", "Enable auto-cruise", "启用自动巡航"); I18N.Add("Auto boost", "Auto boost", "自动加速"); @@ -398,6 +399,8 @@ public static class UIConfigWindow y += 36f; checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab3, PlayerPatch.EnhancedMechaForgeCountControlEnabled, "Enhanced count control for hand-make"); wnd.AddTipsButton2(x + checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab3, "Enhanced count control for hand-make", "Enhanced count control for hand-make tips", "enhanced-count-control-tips"); + y += 36f; + wnd.AddCheckBox(x, y, tab3, PlayerPatch.ShortcutKeysForStarsNameEnabled, "Shortcut keys for showing stars' name"); { y += 36f; diff --git a/UXAssist/UXAssist.cs b/UXAssist/UXAssist.cs index fa0846a..ca08301 100644 --- a/UXAssist/UXAssist.cs +++ b/UXAssist/UXAssist.cs @@ -158,6 +158,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave "Enhanced count control for hand-make, increases maximum of count to 1000, and you can hold Ctrl/Shift/Alt to change the count rapidly"); PlayerPatch.HideTipsForSandsChangesEnabled = Config.Bind("Player", "HideTipsForGettingSands", false, "Hide tips for getting soil piles"); + PlayerPatch.ShortcutKeysForStarsNameEnabled = Config.Bind("Player", "ShortcutKeysForStarsName", false, + "Shortcut keys for showing stars' name"); PlayerPatch.AutoNavigationEnabled = Config.Bind("Player", "AutoNavigation", false, "Auto navigation"); PlayerPatch.AutoCruiseEnabled = Config.Bind("Player", "AutoCruise", false,