Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions AquaMai.Mods/GameSystem/ReviveFinaleVSlide.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.Collections.Generic;
using System.Reflection.Emit;
using AquaMai.Core.Attributes;
using AquaMai.Config.Attributes;
using HarmonyLib;
using Manager;
using MelonLoader;

namespace AquaMai.Mods.GameSystem;

[ConfigSection(
en: "Allow v-shaped slide with the same starting and ending point, such as \"1v1\" in Simai notation",
zh: "允许形如 \"1v1\" 的,起点和终点相同的 v 型星星")]
public static class ReviveFinaleVSlide
{
public static List<string> InsertData(List<string> list)
{
MelonLogger.Msg("[ReviveFinaleVSlide] Insert SVG data");

list[0] = "V_1.svg";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: 直接覆盖 list[0] 可能会在列表为空时导致问题。

在不检查列表是否非空的情况下赋值给 list[0] 将会引发异常。请添加长度检查或使用安全处理空列表的方法。

Original comment in English

issue: Directly overwriting list[0] may cause issues if the list is empty.

Assigning to list[0] without checking if the list is non-empty will raise an exception. Add a length check or use a method that safely handles empty lists.

return list;
}

public static List<List<SlideManager.HitArea>> InsertHitArea(List<List<SlideManager.HitArea>> list)
{
MelonLogger.Msg("[ReviveFinaleVSlide] Insert hit area list");;

list[0] = [
new SlideManager.HitArea
{
HitPoints = [InputManager.TouchPanelArea.A1],
PushDistance = 156.42124938964844,
ReleaseDistance = 43.27423858642578
},
new SlideManager.HitArea
{
HitPoints = [InputManager.TouchPanelArea.B1],
PushDistance = 128.9917755126953,
ReleaseDistance = 42.19921875
},
new SlideManager.HitArea
{
HitPoints = [InputManager.TouchPanelArea.C1],
PushDistance = 218.6302947998047,
ReleaseDistance = 42.19921875
},
new SlideManager.HitArea
{
HitPoints = [InputManager.TouchPanelArea.B1],
PushDistance = 128.9917755126953,
ReleaseDistance = 43.27423858642578
},
new SlideManager.HitArea
{
HitPoints = [InputManager.TouchPanelArea.A1],
PushDistance = 156.42124938964844,
ReleaseDistance = 0.0
}
];
return list;
}

[HarmonyPatch(typeof(SlideManager), MethodType.Constructor)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): 修补所有构造函数可能会产生意外的副作用。

如果 SlideManager 有多个构造函数,修补所有构造函数可能会导致问题。请指定构造函数签名以仅针对预期的构造函数。

建议的实现:

    // Example: If the intended constructor is SlideManager(int a, string b), use:
    [HarmonyPatch(typeof(SlideManager), MethodType.Constructor, new Type[] { typeof(int), typeof(string) })]
    public static class SlideDataPatch
    {

你必须更新 new Type[] { ... } 数组以匹配你想要修补的特定 SlideManager 构造函数的参数类型。例如,如果构造函数是 SlideManager(float x, bool y),请使用 new Type[] { typeof(float), typeof(bool) }

Original comment in English

suggestion (bug_risk): Patching all constructors may have unintended side effects.

If SlideManager has multiple constructors, patching all of them may cause issues. Specify the constructor signature to target only the intended one.

Suggested implementation:

    // Example: If the intended constructor is SlideManager(int a, string b), use:
    [HarmonyPatch(typeof(SlideManager), MethodType.Constructor, new Type[] { typeof(int), typeof(string) })]
    public static class SlideDataPatch
    {

You must update the new Type[] { ... } array to match the parameter types of the specific SlideManager constructor you want to patch. For example, if the constructor is SlideManager(float x, bool y), use new Type[] { typeof(float), typeof(bool) }.

public static class SlideDataPatch
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var vDataList = AccessTools.Field(typeof(SlideManager), "_vDataList");
var vHitAreaList = AccessTools.Field(typeof(SlideManager), "_vHitAreaList");

foreach (var insn in instructions)
{
if (insn.StoresField(vDataList))
{
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ReviveFinaleVSlide), "InsertData"));
}
else if (insn.StoresField(vHitAreaList))
Comment on lines +73 to +77
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): 用方法调用替换字段存储指令可能会扰乱预期的堆栈行为。

请验证 InsertData 和 InsertHitArea 返回的值是否适合字段赋值,并确认这些方法调用后堆栈保持一致。

Original comment in English

issue (bug_risk): Replacing field store instructions with method calls may disrupt expected stack behavior.

Verify that InsertData and InsertHitArea return values suitable for field assignment, and confirm the stack remains consistent after these method calls.

{
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ReviveFinaleVSlide), "InsertHitArea"));
}

yield return insn;
}
}
}
}
Loading