1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2026-02-04 15:12:17 +08:00

minor fix

This commit is contained in:
2026-01-27 23:31:16 +08:00
parent aa775bd05f
commit 71c0fe75db
3 changed files with 61 additions and 48 deletions

View File

@@ -1,11 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using BepInEx; using BepInEx;
using BepInEx.Logging; using BepInEx.Logging;
using HarmonyLib; using HarmonyLib;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NLua; using NLua;
using OBSWebsocketDotNet; using OBSWebsocketDotNet;
@@ -50,6 +48,7 @@ public class LuaScriptEngine : BaseUnityPlugin
private readonly long _repeatInterval = repeatInterval; private readonly long _repeatInterval = repeatInterval;
private long _nextTick = GameMain.gameTick + startInterval; private long _nextTick = GameMain.gameTick + startInterval;
} }
public new static readonly ManualLogSource Logger = public new static readonly ManualLogSource Logger =
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME); BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
@@ -98,31 +97,30 @@ public class LuaScriptEngine : BaseUnityPlugin
break; 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); var timer = new Timer(func, firstInterval, repeatInterval);
Timers.Add(timer); Timers.Add(timer);
return timer; return timer;
}; };
LuaState["remove_timer"] = void (Timer timer) => LuaState["remove_timer"] = void (Timer timer) => { Timers.Remove(timer); };
{
Timers.Remove(timer);
};
LuaState["obs_connect"] = void (string server, string password) => LuaState["obs_connect"] = void (string server, string password) =>
{ {
_obs.Connected += (sender, e) => _obs.Connected += (_, _) =>
{ {
Logger.LogDebug("Connected to OBS"); Logger.LogDebug("Connected to OBS");
foreach (var (sourceName, text) in _scheduledText) foreach (var (sourceName, text) in _scheduledText)
{ {
_obs.SetInputSettings(sourceName, _obs.SetInputSettings(sourceName,
new JObject { new JObject
{"text", text} {
{ "text", text }
}); });
} }
_scheduledText.Clear(); _scheduledText.Clear();
}; };
_obs.Disconnected += (sender, e) => _obs.Disconnected += (_, _) =>
{ {
Logger.LogDebug("Disconnected from OBS"); Logger.LogDebug("Disconnected from OBS");
_obs.ConnectAsync(server, password); _obs.ConnectAsync(server, password);
@@ -135,8 +133,9 @@ public class LuaScriptEngine : BaseUnityPlugin
{ {
try try
{ {
_obs.SetInputSettings(sourceName, new JObject { _obs.SetInputSettings(sourceName, new JObject
{"text", text} {
{ "text", text }
}); });
} }
catch (Exception e) catch (Exception e)
@@ -162,6 +161,7 @@ public class LuaScriptEngine : BaseUnityPlugin
Logger.LogInfo($"Loading Lua script: {file}"); Logger.LogInfo($"Loading Lua script: {file}");
LuaState.DoFile(file); LuaState.DoFile(file);
} }
_harmony = Harmony.CreateAndPatchAll(typeof(Patches)); _harmony = Harmony.CreateAndPatchAll(typeof(Patches));
} }
@@ -215,12 +215,14 @@ public class LuaScriptEngine : BaseUnityPlugin
if (timer == null || !timer.Check(gameTick)) continue; if (timer == null || !timer.Check(gameTick)) continue;
TimersToRemove.Add(timer); TimersToRemove.Add(timer);
} }
if (TimersToRemove.Count > 0) if (TimersToRemove.Count > 0)
{ {
foreach (var timer in TimersToRemove) foreach (var timer in TimersToRemove)
{ {
Timers.Remove(timer); Timers.Remove(timer);
} }
TimersToRemove.Clear(); TimersToRemove.Clear();
} }
} }
@@ -247,14 +249,17 @@ public class LuaScriptEngine : BaseUnityPlugin
TimersToRemove.Add(timer); TimersToRemove.Add(timer);
} }
} }
if (TimersToRemove.Count > 0) if (TimersToRemove.Count > 0)
{ {
foreach (var timer in TimersToRemove) foreach (var timer in TimersToRemove)
{ {
Timers.Remove(timer); Timers.Remove(timer);
} }
TimersToRemove.Clear(); TimersToRemove.Clear();
} }
LoopCall(PreGameBeginFuncs); LoopCall(PreGameBeginFuncs);
} }

View File

@@ -464,6 +464,16 @@ public class GamePatch : PatchImpl<GamePatch>
_needConvert = true; _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] [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)

View File

@@ -12,35 +12,25 @@ public class MyKeyBinder : MonoBehaviour
private ConfigEntry<KeyboardShortcut> _config; private ConfigEntry<KeyboardShortcut> _config;
protected event Action OnFree; protected event Action OnFree;
[SerializeField] [SerializeField] public Text functionText;
public Text functionText;
[SerializeField] [SerializeField] public Text keyText;
public Text keyText;
[SerializeField] [SerializeField] public InputField setTheKeyInput;
public InputField setTheKeyInput;
[SerializeField] [SerializeField] public Toggle setTheKeyToggle;
public Toggle setTheKeyToggle;
[SerializeField] [SerializeField] public RectTransform rectTrans;
public RectTransform rectTrans;
[SerializeField] [SerializeField] public UIButton inputUIButton;
public UIButton inputUIButton;
[SerializeField] [SerializeField] public Text conflictText;
public Text conflictText;
[SerializeField] [SerializeField] public Text waitingText;
public Text waitingText;
[SerializeField] [SerializeField] public UIButton setDefaultUIButton;
public UIButton setDefaultUIButton;
[SerializeField] [SerializeField] public UIButton setNoneKeyUIButton;
public UIButton setNoneKeyUIButton;
private bool _nextNotOn; private bool _nextNotOn;
@@ -135,10 +125,12 @@ public class MyKeyBinder : MonoBehaviour
VFInput.UseEscape(); VFInput.UseEscape();
return true; return true;
} }
if (Input.GetKey(KeyCode.Mouse0) || Input.GetKey(KeyCode.Mouse1)) if (Input.GetKey(KeyCode.Mouse0) || Input.GetKey(KeyCode.Mouse1))
{ {
return true; return true;
} }
var anyKey = GetIunptKeys(); var anyKey = GetIunptKeys();
if (anyKey || _lastKey == KeyCode.None) return false; if (anyKey || _lastKey == KeyCode.None) return false;
var k = GetPressedKey(); var k = GetPressedKey();
@@ -146,20 +138,24 @@ public class MyKeyBinder : MonoBehaviour
{ {
return false; return false;
} }
_lastKey = KeyCode.None; _lastKey = KeyCode.None;
_config.Value = KeyboardShortcut.Deserialize(k); _config.Value = KeyboardShortcut.Deserialize(k);
//keyText.text = k; //keyText.text = k;
return true; return true;
} }
private KeyCode _lastKey; private KeyCode _lastKey;
private static readonly KeyCode[] ModKeys = { KeyCode.RightShift, KeyCode.LeftShift,
private static readonly KeyCode[] ModKeys =
[
KeyCode.RightShift, KeyCode.LeftShift,
KeyCode.RightControl, KeyCode.LeftControl, KeyCode.RightControl, KeyCode.LeftControl,
KeyCode.RightAlt, KeyCode.LeftAlt, KeyCode.RightAlt, KeyCode.LeftAlt,
KeyCode.LeftCommand, KeyCode.LeftApple, KeyCode.LeftWindows, KeyCode.LeftCommand, KeyCode.LeftApple, KeyCode.LeftWindows,
KeyCode.RightCommand, KeyCode.RightApple, KeyCode.RightWindows }; KeyCode.RightCommand, KeyCode.RightApple, KeyCode.RightWindows
];
private string GetPressedKey() private string GetPressedKey()
{ {
@@ -168,6 +164,7 @@ public class MyKeyBinder : MonoBehaviour
{ {
return null; return null;
} }
var mod = ""; var mod = "";
foreach (var modKey in ModKeys) foreach (var modKey in ModKeys)
{ {
@@ -181,6 +178,7 @@ public class MyKeyBinder : MonoBehaviour
{ {
key += mod; key += mod;
} }
return key; return key;
} }
@@ -195,8 +193,8 @@ public class MyKeyBinder : MonoBehaviour
_lastKey = item; _lastKey = item;
anyKey = true; anyKey = true;
} }
return anyKey;
return anyKey;
} }
public void Reset() public void Reset()