From c173b2a2302f56fd31adf59327d9e62c0adadd6f Mon Sep 17 00:00:00 2001 From: Minepig <30530115+Minepig@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:41:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9E=E9=94=81Slide?= =?UTF-8?q?=E7=9A=84=E8=AF=BB=E5=8F=96=E9=80=BB=E8=BE=91=EF=BC=88=E5=88=B9?= =?UTF-8?q?=E9=82=A3=E6=97=85=E7=A8=8B=E7=88=86=E6=9C=BAbug=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AquaMai/Fix/FixConnSlide.cs | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 AquaMai/Fix/FixConnSlide.cs diff --git a/AquaMai/Fix/FixConnSlide.cs b/AquaMai/Fix/FixConnSlide.cs new file mode 100644 index 00000000..138716ad --- /dev/null +++ b/AquaMai/Fix/FixConnSlide.cs @@ -0,0 +1,64 @@ +using System.Collections.Generic; +using System.Reflection; +using HarmonyLib; +using Manager; +using MelonLoader; +using Monitor; + +namespace AquaMai.Fix; + +public class FixConnSlide +{ + /* 这个 Patch 用于修复以下 bug: + * 非 ConnSlide 被错误解析为 ConnSlide (Fes 首日刹那旅程爆机 bug) + * 原 method 逻辑如下: + * + * if (this.IsSlideAll(noteData1.type) && (index1 + 1 < this._note._noteData.Count ? 1 : 0) != 0) + * { + * int targetNote = noteData1.slideData.targetNote; + * if (noteData1.slideData != null) + * targetNote = noteData1.slideData.targetNote; + * for (int index3 = index1; index3 < this._note._noteData.Count; ++index3) + * { + * NoteData noteData3 = this._note._noteData[index3]; + * if (this.IsSlideAll(noteData3.type) && noteData3.time == noteData1.end && noteData3.startButtonPos == targetNote && noteData3.parent == null) + * { + * noteData3.parent = noteData1.parent; + * noteData1.child.Add(noteData3); + * noteData3.isUsed = true; + * noteData3.isJudged = true; + * break; + * } + * } + * } + * + * 修复 bug 需要把第二次调用 this.IsSlideAll() 更改为 this.IsConnectNote(), 这里使用 Transpiler 解决 + */ + [HarmonyTranspiler] + [HarmonyPatch(typeof(NotesReader), "calcSlide")] + private static IEnumerable Fix(IEnumerable instructions) + { + List instList = new List(instructions); + bool found = false; + MethodInfo methodIsSlideAll = AccessTools.Method(typeof(NotesReader), "IsSlideAll"); + MethodInfo methodIsConnectNote = AccessTools.Method(typeof(NotesReader), "IsConnectNote"); + + for (int i = 0; i < instList.Count; i++) + { + CodeInstruction inst = instList[i]; + if (!found && inst.Calls(methodIsSlideAll)) + { + found = true; + continue; + } + + if (found && inst.Calls(methodIsSlideAll)) + { + inst.operand = methodIsConnectNote; + // MelonLogger.Msg($"[FixConnSlide] Successfully patched NotesReader::calcSlide"); + break; + } + } + return instList; + } +} \ No newline at end of file