Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[+] GameSystem.KeyMap.{DisableIO4, DisableDebugInput} #19

Merged
merged 3 commits into from
Jan 31, 2025

Conversation

Menci
Copy link
Contributor

@Menci Menci commented Jan 28, 2025

Summary by Sourcery

新功能:

  • 允许单独禁用 IO4 输入和 DebugInput。
Original summary in English

Summary by Sourcery

New Features:

  • Allow disabling IO4 input and DebugInput separately.

Copy link

sourcery-ai bot commented Jan 28, 2025

审阅者指南 by Sourcery

此拉取请求引入了禁用 IO4 和 DebugInput 的能力,提供了更灵活的输入配置。它还包括对 DebugInput 处理方式的更改。

显示 KeyMap 和 Common 类修改的类图

classDiagram
    class KeyMap {
        -bool disableIO4
        +bool disableDebugInput
        +KeyCodeID Test
        +PreJvsSwitchConstructor(ref bool invert)
        +PreGetIsOn(ref bool __result)
        +PreGetHasOnNow(ref bool __result)
    }
    note for KeyMap "输入源控制的
新配置选项"

    class Common {
        +GetKey(ref bool __result, KeyCode name)
        +GetKeyDown(ref bool __result, KeyCode name)
    }
    note for Common "修改以遵守
disableDebugInput 设置"

    KeyMap -- Common : uses
Loading

输入系统配置的状态图

stateDiagram-v2
    [*] --> InputConfig
    InputConfig --> IO4_Only: 禁用 DebugInput
    InputConfig --> DebugInput_Only: 禁用 IO4
    InputConfig --> Both_Enabled: 两者都启用
    InputConfig --> No_Input: 两者都禁用

    note right of IO4_Only: 使用 IO4 兼容板
或 segatools 仿真
    note right of DebugInput_Only: 通过 Unity 输入系统
使用键盘输入
    note right of Both_Enabled: 可能会导致问题
    note right of No_Input: 按钮输入完全禁用
Loading

文件级更改

更改 详情 文件
添加禁用 IO4 和 DebugInput 的配置。
  • 添加 disableIO4disableDebugInput 配置选项。
  • 为新的配置选项添加描述。
  • 添加 Harmony 补丁,根据 disableIO4 配置禁用 IO4 输入。
AquaMai.Mods/GameSystem/KeyMap.cs
修改 DebugInput 以遵守 disableDebugInput 配置。
  • 修改 DebugInput.GetKeyDebugInput.GetKeyDown,仅在 disableDebugInput 为 false 时返回输入。
AquaMai.Mods/Fix/Common.cs

提示和命令

与 Sourcery 交互

  • 触发新的审阅: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub 问题: 通过回复审阅评论要求 Sourcery 创建问题。您也可以用 @sourcery-ai issue 回复审阅评论来创建问题。
  • 生成拉取请求标题: 在拉取请求标题中的任何位置写 @sourcery-ai 以随时生成标题。您也可以在拉取请求中评论 @sourcery-ai title 以随时(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中的任何位置写 @sourcery-ai summary 以在您想要的确切位置生成 PR 摘要。您也可以在拉取请求中评论 @sourcery-ai summary 以随时(重新)生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide 以随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已经处理了所有评论并且不想再看到它们,这很有用。
  • 取消所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss 以取消所有现有的 Sourcery 审阅。特别是在您想要重新开始审阅时很有用 - 别忘了评论 @sourcery-ai review 以触发新的审阅!
  • 为问题生成行动计划: 在问题中评论 @sourcery-ai plan 以生成该问题的行动计划。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审阅功能,如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This pull request introduces the ability to disable IO4 and DebugInput, providing more flexibility in input configurations. It also includes changes to how DebugInput is handled.

Class diagram showing KeyMap and Common class modifications

classDiagram
    class KeyMap {
        -bool disableIO4
        +bool disableDebugInput
        +KeyCodeID Test
        +PreJvsSwitchConstructor(ref bool invert)
        +PreGetIsOn(ref bool __result)
        +PreGetHasOnNow(ref bool __result)
    }
    note for KeyMap "New configuration options for
input source control"

    class Common {
        +GetKey(ref bool __result, KeyCode name)
        +GetKeyDown(ref bool __result, KeyCode name)
    }
    note for Common "Modified to respect
disableDebugInput setting"

    KeyMap -- Common : uses
Loading

State diagram for input system configuration

stateDiagram-v2
    [*] --> InputConfig
    InputConfig --> IO4_Only: disable DebugInput
    InputConfig --> DebugInput_Only: disable IO4
    InputConfig --> Both_Enabled: both enabled
    InputConfig --> No_Input: both disabled

    note right of IO4_Only: Uses IO4-compatible board
or segatools emulation
    note right of DebugInput_Only: Uses keyboard input
via Unity Input system
    note right of Both_Enabled: May cause issues
    note right of No_Input: Button input completely disabled
Loading

File-Level Changes

Change Details Files
Added configurations to disable IO4 and DebugInput.
  • Added disableIO4 and disableDebugInput configuration options.
  • Added descriptions for the new configuration options.
  • Added Harmony patches to disable IO4 input based on the disableIO4 configuration.
AquaMai.Mods/GameSystem/KeyMap.cs
Modified DebugInput to respect the disableDebugInput configuration.
  • Modified DebugInput.GetKey and DebugInput.GetKeyDown to only return input if disableDebugInput is false.
AquaMai.Mods/Fix/Common.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

@Menci - 我已经审查了你的更改,看起来非常棒!

以下是我在审查期间关注的内容
  • 🟢 一般性问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟡 复杂性:发现1个问题
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目是免费的 - 如果你喜欢我们的评论,请考虑分享 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English

Hey @Menci - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

(你应该至少启用一个输入源,推荐仅启用其中一个而禁用另一个。)
(同时禁用两者将完全禁用外键输入,同时启用两者可以工作但可能会导致问题。)
""",
defaultOn: true)]
public class KeyMap
Copy link

Choose a reason for hiding this comment

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

问题(复杂性): 考虑使用枚举而不是两个布尔标志来表示输入模式,这可以简化逻辑并防止无效状态。

考虑将两个布尔标志替换为枚举,以明确有效的输入配置并降低复杂性:

public enum InputMode 
{
    IO4Only,        // 传统 IO4 板/segatools
    DebugInputOnly, // 键盘/调试输入
    Both,           // 两者都启用(不建议用于生产)
    None            // 无输入(用于特殊情况)
}

[ConfigEntry(
    en: """
        选择输入模式。IO4Only 使用 IO4 兼容板/segatools。
        DebugInputOnly 使用下面定义的键盘映射。
        Both 不建议用于生产使用。
        """)]
public static InputMode inputMode = InputMode.IO4Only;

这允许合并 IO4 禁用补丁:

[EnableIf(nameof(inputMode), InputMode.DebugInputOnly, InputMode.None)]
[HarmonyPatch(typeof(SwitchInput))]
public class SwitchInputPatch 
{
    [HarmonyPatch("get_IsOn")]
    [HarmonyPrefix]
    public static bool PreGetIsOn(ref bool __result)
    {
        __result = false;
        return false;
    }
    // 其他方法类似合并
}

这种方法:

  1. 明确有效配置
  2. 防止模糊状态
  3. 降低补丁复杂性
  4. 保持所有当前功能
Original comment in English

issue (complexity): Consider using an enum instead of two boolean flags to represent input modes, which simplifies the logic and prevents invalid states.

Consider replacing the two boolean flags with an enum to make the valid input configurations explicit and reduce complexity:

public enum InputMode 
{
    IO4Only,        // Traditional IO4 board/segatools
    DebugInputOnly, // Keyboard/debug input only
    Both,           // Both enabled (not recommended for production)
    None            // No input (for special cases)
}

[ConfigEntry(
    en: """
        Select input mode. IO4Only uses IO4-compatible board/segatools.
        DebugInputOnly uses keyboard mapping defined below.
        Both is not recommended for production use.
        """)]
public static InputMode inputMode = InputMode.IO4Only;

This allows consolidating the IO4 disable patches:

[EnableIf(nameof(inputMode), InputMode.DebugInputOnly, InputMode.None)]
[HarmonyPatch(typeof(SwitchInput))]
public class SwitchInputPatch 
{
    [HarmonyPatch("get_IsOn")]
    [HarmonyPrefix]
    public static bool PreGetIsOn(ref bool __result)
    {
        __result = false;
        return false;
    }
    // Other methods consolidated similarly
}

This approach:

  1. Makes valid configurations explicit
  2. Prevents ambiguous states
  3. Reduces patch complexity
  4. Maintains all current functionality

@clansty
Copy link
Contributor

clansty commented Jan 28, 2025

所以这个的意义何在
默认不就是同时开两个,而且也没见过有问题的
然后 hid 输入之类的也不冲突

@Menci
Copy link
Contributor Author

Menci commented Jan 28, 2025

如果是键盘输入的话,都开着,就会被两个同时影响?

@Menci
Copy link
Contributor Author

Menci commented Jan 28, 2025

然后调试的时候我也不希望 amdaemon 那边会影响,因为 amdaemon 那边的模拟 io4 会无论在不在游戏窗口里都捕获按键,打字就会后台乱按

@clansty
Copy link
Contributor

clansty commented Jan 28, 2025

如果是键盘输入的话,都开着,就会被两个同时影响?

不会,是同时触发的

然后调试的时候我也不希望 amdaemon 那边会影响,因为 amdaemon 那边的模拟 io4 会无论在不在游戏窗口里都捕获按键,打字就会后台乱按

segatools 里面全都改成不存在的键位

@Menci
Copy link
Contributor Author

Menci commented Jan 28, 2025

键位全改一遍也比较麻烦,加一个配置直接禁用比较省事

@@ -34,7 +34,10 @@ private static bool PreIniFileClear()
[HarmonyPatch(typeof(DebugInput), "GetKey")]
private static bool GetKey(ref bool __result, KeyCode name)
{
__result = UnityEngine.Input.GetKey(name);
if (!KeyMap.disableDebugInput)
Copy link
Contributor

Choose a reason for hiding this comment

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

我觉得这里不如不 hook debuginput 了
如果直接 return false 的话,可能会和别的 hook debuginput 的自定义输入冲突
如果你说那些 assembly 里面直接做上 debug input 的包的话,那就是脏脏包的问题

@clansty clansty merged commit c74f25a into main Jan 31, 2025
2 checks passed
@clansty clansty deleted the disable-io4-or-debuginput branch January 31, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants