Skip to content

Commit f07e81a

Browse files
committed
feat: AmDaemonError拦截器
阻止游戏向AMDaemon报告错误
1 parent 61df140 commit f07e81a

2 files changed

Lines changed: 158 additions & 0 deletions

File tree

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics;
3+
using System.Reflection.Emit;
4+
using AquaMai.Config.Attributes;
5+
using AquaMai.Core.Attributes;
6+
using HarmonyLib;
7+
using IO;
8+
using Manager;
9+
using PartyLink;
10+
using Process;
11+
12+
namespace AquaMai.Mods.Tweaks;
13+
[ConfigSection(
14+
"拦截AMDaemon错误",
15+
zh: """
16+
阻止游戏在不使用Dummy时向AMDaemon发送错误状态,避免AMDaemon锁点数以及忽略Coin Signal等问题
17+
""",
18+
en: """
19+
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.
20+
""")]
21+
22+
public class BlockAmDaemonError
23+
{
24+
[ConfigEntry(
25+
"拦截触摸错误",
26+
"Do not send touch panel errors to AMDaemon.",
27+
"不向AMDaemon发送触摸错误"
28+
)]
29+
public static readonly bool TouchPanel = false;
30+
31+
[ConfigEntry(
32+
"拦截相机管理器错误",
33+
"Do not send camera manager errors to AMDaemon.",
34+
"不向AMDaemon发送相机管理器错误"
35+
)]
36+
public static readonly bool CameraManager = false;
37+
38+
[ConfigEntry(
39+
"拦截QrCamera错误",
40+
"No error reported from the QR camera to AMDaemon.",
41+
"不向AMDaemon发送二维码相机的错误"
42+
)]
43+
public static readonly bool QrCamera = false;
44+
45+
[ConfigEntry(
46+
"拦截PhotoCamera错误",
47+
"Do not send photo camera errors to AMDaemon.",
48+
"不向AMDaemon发送照片相机错误"
49+
)]
50+
public static readonly bool PhotoCamera = false;
51+
52+
[ConfigEntry(
53+
"拦截基准机错误",
54+
"Do not send error 3201 related to the benchmark machine to AMDaemon.",
55+
"不向AMDaemon发送基准机相关的错误(3201)"
56+
)]
57+
public static readonly bool Error3201 = false;
58+
59+
[EnableIf(nameof(TouchPanel))]
60+
[HarmonyTranspiler]
61+
[HarmonyPatch(typeof(StartupProcess), "OnUpdate")]
62+
public static IEnumerable<CodeInstruction> TouchPanelTranspiler(IEnumerable<CodeInstruction> instructions)
63+
{
64+
var codeMatcher = new CodeMatcher(instructions);
65+
66+
codeMatcher.MatchStartForward(
67+
new CodeMatch(i => i.Calls(AccessTools.Method(
68+
typeof(NewTouchPanel),
69+
nameof(NewTouchPanel.GetLastErrorPs)))),
70+
new CodeMatch(i => i.Calls(AccessTools.Method(
71+
typeof(AMDaemon.Error), "Set", new[] { typeof(int) })))
72+
)
73+
.ThrowIfInvalid("Could not find call to TouchPanel AMDeamon.Error.Set")
74+
.SetOpcodeAndAdvance(OpCodes.Nop)
75+
.SetOpcodeAndAdvance(OpCodes.Nop);
76+
77+
return codeMatcher.Instructions();
78+
}
79+
80+
[EnableIf(nameof(CameraManager))]
81+
[HarmonyTranspiler]
82+
[HarmonyPatch(typeof(StartupProcess), "OnUpdate")]
83+
public static IEnumerable<CodeInstruction> CameraManagerTranspiler(IEnumerable<CodeInstruction> instructions)
84+
{
85+
var errorSet = AccessTools.Method(
86+
typeof(AMDaemon.Error),
87+
"Set",
88+
new[] { typeof(int) });
89+
90+
var startMethod = AccessTools.Method(
91+
typeof(Stopwatch),
92+
nameof(Stopwatch.Start));
93+
94+
var matcher = new CodeMatcher(instructions);
95+
96+
matcher.MatchStartForward(
97+
new CodeMatch(i => i.Calls(startMethod))
98+
);
99+
if (!matcher.IsValid)
100+
return instructions;
101+
matcher.Advance(1);
102+
matcher.MatchStartForward(
103+
new CodeMatch(i => i.Calls(errorSet))
104+
);
105+
if (!matcher.IsValid)
106+
return instructions;
107+
matcher.SetOpcodeAndAdvance(OpCodes.Nop);
108+
109+
return matcher.Instructions();
110+
}
111+
112+
[EnableIf(nameof(Error3201))]
113+
[HarmonyTranspiler]
114+
[HarmonyPatch(typeof(StartupProcess), "OnUpdate")]
115+
[HarmonyPatch(typeof(AdvertiseProcess), "UpdateSetting")]
116+
public static IEnumerable<CodeInstruction> Error3201Transpiler(IEnumerable<CodeInstruction> instructions)
117+
{
118+
var errorSet = AccessTools.Method(
119+
typeof(AMDaemon.Error),
120+
"Set",
121+
new[] { typeof(int) });
122+
123+
var startMethod = AccessTools.Method(
124+
typeof(Setting.IManager),
125+
nameof(Setting.IManager.terminate));
126+
127+
var matcher = new CodeMatcher(instructions);
128+
129+
matcher.MatchStartForward(
130+
new CodeMatch(i => i.Calls(startMethod))
131+
);
132+
if (!matcher.IsValid)
133+
return instructions;
134+
matcher.Advance(1);
135+
matcher.MatchStartForward(
136+
new CodeMatch(i => i.Calls(errorSet))
137+
);
138+
if (!matcher.IsValid)
139+
return instructions;
140+
matcher.SetOpcodeAndAdvance(OpCodes.Nop);
141+
142+
return matcher.Instructions();
143+
}
144+
145+
[HarmonyPrefix]
146+
[HarmonyPatch(typeof(AMDaemon.Error), "Set", new[] { typeof(int) })]
147+
public static bool CameraPrefix(int __0)
148+
{
149+
if (__0 == 3101 || QrCamera)
150+
return false;
151+
if (__0 == 3102 || PhotoCamera)
152+
return false;
153+
return true;
154+
}
155+
156+
}

‎AquaMai/configSort.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
- Utils.ShowErrorLog
141141
- GameSettings.ForceAsServer
142142
- GameSystem.RemoveEncryption
143+
- Tweaks.BlockAmDaemonError
143144

144145
社区功能:
145146
- GameSystem.VolumeSync
@@ -177,3 +178,4 @@
177178
- Fancy.ResourcesOverride
178179
- GameSystem.OldCabLightBoardSupport
179180
- GameSystem.VirtualCoin
181+
- Tweaks.BlockAmDaemonError

0 commit comments

Comments
 (0)