diff --git a/LuaScriptEngine/LuaScriptEngine.cs b/LuaScriptEngine/LuaScriptEngine.cs index 50f2293..d42928e 100644 --- a/LuaScriptEngine/LuaScriptEngine.cs +++ b/LuaScriptEngine/LuaScriptEngine.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; using System.Text; - using BepInEx; using BepInEx.Logging; using HarmonyLib; - using Newtonsoft.Json.Linq; using NLua; using OBSWebsocketDotNet; @@ -50,6 +48,7 @@ public class LuaScriptEngine : BaseUnityPlugin private readonly long _repeatInterval = repeatInterval; private long _nextTick = GameMain.gameTick + startInterval; } + public new static readonly ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME); @@ -98,31 +97,30 @@ public class LuaScriptEngine : BaseUnityPlugin break; } }; - LuaState["add_timer"] = Timer(LuaFunction func, long firstInterval, long repeatInterval) => + LuaState["add_timer"] = Timer (LuaFunction func, long firstInterval, long repeatInterval) => { var timer = new Timer(func, firstInterval, repeatInterval); Timers.Add(timer); return timer; }; - LuaState["remove_timer"] = void (Timer timer) => - { - Timers.Remove(timer); - }; + LuaState["remove_timer"] = void (Timer timer) => { Timers.Remove(timer); }; LuaState["obs_connect"] = void (string server, string password) => { - _obs.Connected += (sender, e) => + _obs.Connected += (_, _) => { Logger.LogDebug("Connected to OBS"); foreach (var (sourceName, text) in _scheduledText) { - _obs.SetInputSettings(sourceName, - new JObject { - {"text", text} + _obs.SetInputSettings(sourceName, + new JObject + { + { "text", text } }); } + _scheduledText.Clear(); }; - _obs.Disconnected += (sender, e) => + _obs.Disconnected += (_, _) => { Logger.LogDebug("Disconnected from OBS"); _obs.ConnectAsync(server, password); @@ -135,8 +133,9 @@ public class LuaScriptEngine : BaseUnityPlugin { try { - _obs.SetInputSettings(sourceName, new JObject { - {"text", text} + _obs.SetInputSettings(sourceName, new JObject + { + { "text", text } }); } catch (Exception e) @@ -162,9 +161,10 @@ public class LuaScriptEngine : BaseUnityPlugin Logger.LogInfo($"Loading Lua script: {file}"); LuaState.DoFile(file); } + _harmony = Harmony.CreateAndPatchAll(typeof(Patches)); } - + private void OnDestroy() { Timers.Clear(); @@ -215,26 +215,28 @@ public class LuaScriptEngine : BaseUnityPlugin if (timer == null || !timer.Check(gameTick)) continue; TimersToRemove.Add(timer); } + if (TimersToRemove.Count > 0) { foreach (var timer in TimersToRemove) { Timers.Remove(timer); } + TimersToRemove.Clear(); } } LoopCall(PreUpdateFuncs); } - + [HarmonyPostfix] [HarmonyPatch(typeof(GameMain), nameof(GameMain.FixedUpdate))] private static void GameMain_FixedUpdate_Postfix() { LoopCall(PostUpdateFuncs); } - + [HarmonyPrefix] [HarmonyPatch(typeof(GameMain), nameof(GameMain.Begin))] private static void GameMain_Begin_Prefix() @@ -247,31 +249,34 @@ public class LuaScriptEngine : BaseUnityPlugin TimersToRemove.Add(timer); } } + if (TimersToRemove.Count > 0) { foreach (var timer in TimersToRemove) { Timers.Remove(timer); } + TimersToRemove.Clear(); } + LoopCall(PreGameBeginFuncs); } - + [HarmonyPostfix] [HarmonyPatch(typeof(GameMain), nameof(GameMain.Begin))] private static void GameMain_Begin_Postfix() { LoopCall(PostGameBeginFuncs); } - + [HarmonyPrefix] [HarmonyPatch(typeof(GameMain), nameof(GameMain.End))] private static void GameMain_End_Prefix() { LoopCall(PreGameEndFuncs); } - + [HarmonyPostfix] [HarmonyPatch(typeof(GameMain), nameof(GameMain.End))] private static void GameMain_End_Postfix() diff --git a/UXAssist/Patches/GamePatch.cs b/UXAssist/Patches/GamePatch.cs index f801705..a1a5971 100644 --- a/UXAssist/Patches/GamePatch.cs +++ b/UXAssist/Patches/GamePatch.cs @@ -464,6 +464,16 @@ public class GamePatch : PatchImpl _needConvert = true; } + [HarmonyPostfix] + [HarmonyPatch(typeof(GameHistoryData), nameof(GameHistoryData.Import))] + private static void GameHistoryData_Import_Postfix(GameHistoryData __instance) + { + if (_needConvert) + { + __instance.combatSettings = UIRoot.instance.galaxySelect.uiCombat.combatSettings; + } + } + [HarmonyTranspiler] [HarmonyPatch(typeof(GameData), nameof(GameData.Import))] private static IEnumerable GameData_Import_Transpiler(IEnumerable instructions, ILGenerator generator) diff --git a/UXAssist/UI/MyKeyBinder.cs b/UXAssist/UI/MyKeyBinder.cs index 9ae9440..5d1e220 100644 --- a/UXAssist/UI/MyKeyBinder.cs +++ b/UXAssist/UI/MyKeyBinder.cs @@ -12,35 +12,25 @@ public class MyKeyBinder : MonoBehaviour private ConfigEntry _config; protected event Action OnFree; - [SerializeField] - public Text functionText; + [SerializeField] public Text functionText; - [SerializeField] - public Text keyText; + [SerializeField] public Text keyText; - [SerializeField] - public InputField setTheKeyInput; + [SerializeField] public InputField setTheKeyInput; - [SerializeField] - public Toggle setTheKeyToggle; + [SerializeField] public Toggle setTheKeyToggle; - [SerializeField] - public RectTransform rectTrans; + [SerializeField] public RectTransform rectTrans; - [SerializeField] - public UIButton inputUIButton; + [SerializeField] public UIButton inputUIButton; - [SerializeField] - public Text conflictText; + [SerializeField] public Text conflictText; - [SerializeField] - public Text waitingText; + [SerializeField] public Text waitingText; - [SerializeField] - public UIButton setDefaultUIButton; + [SerializeField] public UIButton setDefaultUIButton; - [SerializeField] - public UIButton setNoneKeyUIButton; + [SerializeField] public UIButton setNoneKeyUIButton; private bool _nextNotOn; @@ -135,10 +125,12 @@ public class MyKeyBinder : MonoBehaviour VFInput.UseEscape(); return true; } + if (Input.GetKey(KeyCode.Mouse0) || Input.GetKey(KeyCode.Mouse1)) { return true; } + var anyKey = GetIunptKeys(); if (anyKey || _lastKey == KeyCode.None) return false; var k = GetPressedKey(); @@ -146,20 +138,24 @@ public class MyKeyBinder : MonoBehaviour { return false; } + _lastKey = KeyCode.None; _config.Value = KeyboardShortcut.Deserialize(k); //keyText.text = k; return true; - } private KeyCode _lastKey; - private static readonly KeyCode[] ModKeys = { KeyCode.RightShift, KeyCode.LeftShift, - KeyCode.RightControl, KeyCode.LeftControl, - KeyCode.RightAlt, KeyCode.LeftAlt, - KeyCode.LeftCommand, KeyCode.LeftApple, KeyCode.LeftWindows, - KeyCode.RightCommand, KeyCode.RightApple, KeyCode.RightWindows }; + + private static readonly KeyCode[] ModKeys = + [ + KeyCode.RightShift, KeyCode.LeftShift, + KeyCode.RightControl, KeyCode.LeftControl, + KeyCode.RightAlt, KeyCode.LeftAlt, + KeyCode.LeftCommand, KeyCode.LeftApple, KeyCode.LeftWindows, + KeyCode.RightCommand, KeyCode.RightApple, KeyCode.RightWindows + ]; private string GetPressedKey() { @@ -168,6 +164,7 @@ public class MyKeyBinder : MonoBehaviour { return null; } + var mod = ""; foreach (var modKey in ModKeys) { @@ -181,6 +178,7 @@ public class MyKeyBinder : MonoBehaviour { key += mod; } + return key; } @@ -195,8 +193,8 @@ public class MyKeyBinder : MonoBehaviour _lastKey = item; anyKey = true; } - return anyKey; + return anyKey; } public void Reset() @@ -234,4 +232,4 @@ public class MyKeyBinder : MonoBehaviour { keyText.text = _config.Value.Serialize(); } -} +} \ No newline at end of file