From f07e81a341cd3cd01e983091a718762bfa396cd5 Mon Sep 17 00:00:00 2001 From: zhicheng233 Date: Fri, 22 May 2026 18:55:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20AmDaemonError=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=99=A8=20=E9=98=BB=E6=AD=A2=E6=B8=B8=E6=88=8F=E5=90=91AMDaem?= =?UTF-8?q?on=E6=8A=A5=E5=91=8A=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AquaMai.Mods/Tweaks/BlockAmDaemonError.cs | 156 ++++++++++++++++++++++ AquaMai/configSort.yaml | 2 + 2 files changed, 158 insertions(+) create mode 100644 AquaMai.Mods/Tweaks/BlockAmDaemonError.cs diff --git a/AquaMai.Mods/Tweaks/BlockAmDaemonError.cs b/AquaMai.Mods/Tweaks/BlockAmDaemonError.cs new file mode 100644 index 00000000..f6e8dd4a --- /dev/null +++ b/AquaMai.Mods/Tweaks/BlockAmDaemonError.cs @@ -0,0 +1,156 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection.Emit; +using AquaMai.Config.Attributes; +using AquaMai.Core.Attributes; +using HarmonyLib; +using IO; +using Manager; +using PartyLink; +using Process; + +namespace AquaMai.Mods.Tweaks; +[ConfigSection( + "拦截AMDaemon错误", + zh: """ + 阻止游戏在不使用Dummy时向AMDaemon发送错误状态,避免AMDaemon锁点数以及忽略Coin Signal等问题 + """, + en: """ + Prevents the game from sending error states to AMDaemon when Dummy is not in use, thereby avoiding issues such as AMDaemon locking points and ignoring Coin Signals. + """)] + +public class BlockAmDaemonError +{ + [ConfigEntry( + "拦截触摸错误", + "Do not send touch panel errors to AMDaemon.", + "不向AMDaemon发送触摸错误" + )] + public static readonly bool TouchPanel = false; + + [ConfigEntry( + "拦截相机管理器错误", + "Do not send camera manager errors to AMDaemon.", + "不向AMDaemon发送相机管理器错误" + )] + public static readonly bool CameraManager = false; + + [ConfigEntry( + "拦截QrCamera错误", + "No error reported from the QR camera to AMDaemon.", + "不向AMDaemon发送二维码相机的错误" + )] + public static readonly bool QrCamera = false; + + [ConfigEntry( + "拦截PhotoCamera错误", + "Do not send photo camera errors to AMDaemon.", + "不向AMDaemon发送照片相机错误" + )] + public static readonly bool PhotoCamera = false; + + [ConfigEntry( + "拦截基准机错误", + "Do not send error 3201 related to the benchmark machine to AMDaemon.", + "不向AMDaemon发送基准机相关的错误(3201)" + )] + public static readonly bool Error3201 = false; + + [EnableIf(nameof(TouchPanel))] + [HarmonyTranspiler] + [HarmonyPatch(typeof(StartupProcess), "OnUpdate")] + public static IEnumerable TouchPanelTranspiler(IEnumerable instructions) + { + var codeMatcher = new CodeMatcher(instructions); + + codeMatcher.MatchStartForward( + new CodeMatch(i => i.Calls(AccessTools.Method( + typeof(NewTouchPanel), + nameof(NewTouchPanel.GetLastErrorPs)))), + new CodeMatch(i => i.Calls(AccessTools.Method( + typeof(AMDaemon.Error), "Set", new[] { typeof(int) }))) + ) + .ThrowIfInvalid("Could not find call to TouchPanel AMDeamon.Error.Set") + .SetOpcodeAndAdvance(OpCodes.Nop) + .SetOpcodeAndAdvance(OpCodes.Nop); + + return codeMatcher.Instructions(); + } + + [EnableIf(nameof(CameraManager))] + [HarmonyTranspiler] + [HarmonyPatch(typeof(StartupProcess), "OnUpdate")] + public static IEnumerable CameraManagerTranspiler(IEnumerable instructions) + { + var errorSet = AccessTools.Method( + typeof(AMDaemon.Error), + "Set", + new[] { typeof(int) }); + + var startMethod = AccessTools.Method( + typeof(Stopwatch), + nameof(Stopwatch.Start)); + + var matcher = new CodeMatcher(instructions); + + matcher.MatchStartForward( + new CodeMatch(i => i.Calls(startMethod)) + ); + if (!matcher.IsValid) + return instructions; + matcher.Advance(1); + matcher.MatchStartForward( + new CodeMatch(i => i.Calls(errorSet)) + ); + if (!matcher.IsValid) + return instructions; + matcher.SetOpcodeAndAdvance(OpCodes.Nop); + + return matcher.Instructions(); + } + + [EnableIf(nameof(Error3201))] + [HarmonyTranspiler] + [HarmonyPatch(typeof(StartupProcess), "OnUpdate")] + [HarmonyPatch(typeof(AdvertiseProcess), "UpdateSetting")] + public static IEnumerable Error3201Transpiler(IEnumerable instructions) + { + var errorSet = AccessTools.Method( + typeof(AMDaemon.Error), + "Set", + new[] { typeof(int) }); + + var startMethod = AccessTools.Method( + typeof(Setting.IManager), + nameof(Setting.IManager.terminate)); + + var matcher = new CodeMatcher(instructions); + + matcher.MatchStartForward( + new CodeMatch(i => i.Calls(startMethod)) + ); + if (!matcher.IsValid) + return instructions; + matcher.Advance(1); + matcher.MatchStartForward( + new CodeMatch(i => i.Calls(errorSet)) + ); + if (!matcher.IsValid) + return instructions; + matcher.SetOpcodeAndAdvance(OpCodes.Nop); + + return matcher.Instructions(); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AMDaemon.Error), "Set", new[] { typeof(int) })] + public static bool CameraPrefix(int __0) + { + if (__0 == 3101 || QrCamera) + return false; + if (__0 == 3102 || PhotoCamera) + return false; + return true; + } + +} \ No newline at end of file diff --git a/AquaMai/configSort.yaml b/AquaMai/configSort.yaml index df44fe51..ed60b2d4 100644 --- a/AquaMai/configSort.yaml +++ b/AquaMai/configSort.yaml @@ -140,6 +140,7 @@ - Utils.ShowErrorLog - GameSettings.ForceAsServer - GameSystem.RemoveEncryption + - Tweaks.BlockAmDaemonError 社区功能: - GameSystem.VolumeSync @@ -177,3 +178,4 @@ - Fancy.ResourcesOverride - GameSystem.OldCabLightBoardSupport - GameSystem.VirtualCoin + - Tweaks.BlockAmDaemonError From 1da4f2ded3def00972e4e91da3af79476570b61a Mon Sep 17 00:00:00 2001 From: zhicheng233 Date: Sat, 23 May 2026 01:29:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E4=BF=AE=E6=AD=A3TouchPanelTranspiler?= =?UTF-8?q?=E5=9C=A8=E4=B8=8D=E5=8C=B9=E9=85=8D=E6=97=B6=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=96=B9=E5=BC=8F,=E6=9B=B4=E6=AD=A3=E6=8B=BC?= =?UTF-8?q?=E5=86=99=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AquaMai.Mods/Tweaks/BlockAmDaemonError.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/AquaMai.Mods/Tweaks/BlockAmDaemonError.cs b/AquaMai.Mods/Tweaks/BlockAmDaemonError.cs index f6e8dd4a..aeaafe54 100644 --- a/AquaMai.Mods/Tweaks/BlockAmDaemonError.cs +++ b/AquaMai.Mods/Tweaks/BlockAmDaemonError.cs @@ -69,8 +69,11 @@ public static IEnumerable TouchPanelTranspiler(IEnumerable i.Calls(AccessTools.Method( typeof(AMDaemon.Error), "Set", new[] { typeof(int) }))) - ) - .ThrowIfInvalid("Could not find call to TouchPanel AMDeamon.Error.Set") + ); + if (!codeMatcher.IsValid) + return instructions; + + codeMatcher.ThrowIfInvalid("Could not find call to TouchPanel AMDaemon.Error.Set") .SetOpcodeAndAdvance(OpCodes.Nop) .SetOpcodeAndAdvance(OpCodes.Nop);