Skip to content

Commit a7ddd0d

Browse files
committed
[+] Maybe FixTouchPanelLeak
1 parent 78f9449 commit a7ddd0d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.IO.Ports;
2+
using AquaMai.Config.Attributes;
3+
using HarmonyLib;
4+
using IO;
5+
using MAI2System;
6+
using MelonLoader;
7+
8+
namespace AquaMai.Mods.Fix;
9+
10+
[ConfigSection(exampleHidden: true, defaultOn: true)]
11+
public class FixTouchPanelLeak
12+
{
13+
[HarmonyPostfix]
14+
[HarmonyPatch(typeof(NewTouchPanel), "Open")]
15+
public static void PostOpen(SerialPort ____serialPort, NewTouchPanel __instance, uint ____monitorIndex)
16+
{
17+
____serialPort.ErrorReceived += (_, e) =>
18+
{
19+
MelonLogger.Error($"[TouchPanel {____monitorIndex}] SerialPort error: {e.EventType}");
20+
var t = Traverse.Create(__instance);
21+
t.Field<ConstParameter.ErrorID>("_psError").Value = (____monitorIndex == 0)
22+
? ConstParameter.ErrorID.TouchPanel_Left_OpenError
23+
: ConstParameter.ErrorID.TouchPanel_Right_OpenError;
24+
t.Field<bool>("_isRunning").Value = false;
25+
__instance.Status = NewTouchPanel.StatusEnum.GotoError;
26+
// t.Method("Close").GetValue();
27+
// __instance.Status = NewTouchPanel.StatusEnum.Error;
28+
};
29+
}
30+
}

0 commit comments

Comments
 (0)