Skip to content

fix: 修复Shim无法匹配某些版本的PacketUpsertUserAll#125

Open
zhicheng233 wants to merge 1 commit intoMuNET-OSS:mainfrom
zhicheng233:fix-shim
Open

fix: 修复Shim无法匹配某些版本的PacketUpsertUserAll#125
zhicheng233 wants to merge 1 commit intoMuNET-OSS:mainfrom
zhicheng233:fix-shim

Conversation

@zhicheng233
Copy link
Copy Markdown

@zhicheng233 zhicheng233 commented Apr 6, 2026

由 Sourcery 提供的总结

错误修复:

  • 修复了在数据包使用包含由游戏玩法状态派生的 maxTrackNo 参数的构造函数时,Shim 无法匹配并构造 PacketUpsertUserAll 的问题。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Fix Shim failing to match and construct PacketUpsertUserAll when the packet uses a constructor that includes a maxTrackNo parameter derived from gameplay state.

Copilot AI review requested due to automatic review settings April 6, 2026 11:45
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 6, 2026

审阅者指南

扩展 Shim 对 PacketUpsertUserAll 构造函数的匹配能力,以支持一个额外的重载版本,该版本包含 maxTrackNo 参数,从而确保与更多游戏版本兼容。

Shim 使用带 maxTrackNo 构造函数创建 PacketUpsertUserAll 的时序图

sequenceDiagram
    participant Caller
    participant Shim
    participant Singleton_GamePlayManager_ as Singleton_GamePlayManager
    participant GamePlayManager
    participant PacketUpsertUserAll

    Caller->>Shim: CreatePacketUpsertUserAll(index, src, onDone, onError)
    activate Shim
    Shim->>Shim: Reflect PacketUpsertUserAll constructors
    alt Constructor with maxTrackNo found
        Shim->>Singleton_GamePlayManager_: get Instance
        Singleton_GamePlayManager_->>GamePlayManager: access Instance
        activate GamePlayManager
        GamePlayManager-->>Shim: GamePlayManager instance
        Shim->>GamePlayManager: IsEmpty()
        GamePlayManager-->>Shim: isEmpty
        alt src.IsEntry and not isEmpty
            Shim->>GamePlayManager: GetScoreListCount()
            GamePlayManager-->>Shim: maxTrackNo
        else otherwise
            Shim->>Shim: maxTrackNo = 0
        end
        Shim->>PacketUpsertUserAll: ctor(index, src, maxTrackNo, onDone, onError)
        PacketUpsertUserAll-->>Shim: instance
    else Other constructor overload
        Shim->>PacketUpsertUserAll: ctor(index, src, onDone, onError)
        PacketUpsertUserAll-->>Shim: instance
    end
    Shim-->>Caller: PacketUpsertUserAll instance
    deactivate Shim
Loading

更新后的 Shim 处理 PacketUpsertUserAll 构造函数的类图

classDiagram
    class Shim {
        +EncryptNetPacketBody(byte[] data) byte[]
        +CreatePacketUpsertUserAll(int index, UserData src, Action~int~ onDone, Action~PacketStatus~ onError) PacketUpsertUserAll
    }

    class PacketUpsertUserAll {
        +PacketUpsertUserAll(int index, UserData src, Action~int~ onDone, Action~PacketStatus~ onError)
        +PacketUpsertUserAll(int index, UserData src, int maxTrackNo, Action~int~ onDone, Action~PacketStatus~ onError)
    }

    class UserData {
    }

    class PacketStatus {
    }

    class GamePlayManager {
        +IsEmpty() bool
        +GetScoreListCount() int
    }

    class Singleton_GamePlayManager_ {
        +Instance GamePlayManager
    }

    Shim ..> PacketUpsertUserAll : uses via reflection
    Shim ..> UserData
    Shim ..> PacketStatus
    Shim ..> Singleton_GamePlayManager_ : queries Instance
    Singleton_GamePlayManager_ *-- GamePlayManager

    note for Singleton_GamePlayManager_ "Represents Singleton<GamePlayManager>"
Loading

文件级变更

变更 详情 文件
增加对第三个 PacketUpsertUserAll 构造函数重载的支持,该重载包含由游戏状态推导出的 maxTrackNo 参数。
  • 检测具有参数 (int, UserData, int, Action<int>, Action<PacketStatus>)PacketUpsertUserAll 构造函数,并在可用时将其记录为 ctor3
  • 基于用户数据是否为入口(entry)以及 GamePlayManager 是否非空来计算 maxTrackNo:在适用情况下使用 GetScoreListCount,否则默认为 0。
  • 使用 indexsrc、计算出的 maxTrackNoonDoneonError 调用检测到的构造函数,并返回构造出的 PacketUpsertUserAll 实例。
  • 若未找到任何已知的构造函数重载,则回退为抛出 MissingMethodException,以保留之前的错误行为。
AquaMai.Core/Helpers/Shim.cs

技巧与命令

与 Sourcery 交互

  • 触发新的代码审查: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub Issue: 在审查评论下回复请求 Sourcery 根据该评论创建 issue。你也可以直接回复 @sourcery-ai issue 来基于该评论创建 issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中任意位置写上 @sourcery-ai 即可随时生成标题。你也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 正文中任意位置写上 @sourcery-ai summary,即可在该位置生成 PR 摘要。你也可以在 Pull Request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 一键解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可标记解决所有 Sourcery 评论。如果你已经处理完所有评论,又不想再看到它们,这会很有用。
  • 忽略所有 Sourcery 审查: 在 Pull Request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。特别适用于你希望基于全新的一轮审查重新开始的情况——别忘了随后评论 @sourcery-ai review 来触发新的审查!

自定义你的体验

前往你的 控制面板 以:

  • 启用或禁用审查功能,例如 Sourcery 自动生成的 Pull Request 摘要、审阅者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查指令。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

Extend Shim's constructor matching for PacketUpsertUserAll to support an additional constructor overload that includes a maxTrackNo parameter, ensuring compatibility with more game versions.

Sequence diagram for Shim creating PacketUpsertUserAll with maxTrackNo constructor

sequenceDiagram
    participant Caller
    participant Shim
    participant Singleton_GamePlayManager_ as Singleton_GamePlayManager
    participant GamePlayManager
    participant PacketUpsertUserAll

    Caller->>Shim: CreatePacketUpsertUserAll(index, src, onDone, onError)
    activate Shim
    Shim->>Shim: Reflect PacketUpsertUserAll constructors
    alt Constructor with maxTrackNo found
        Shim->>Singleton_GamePlayManager_: get Instance
        Singleton_GamePlayManager_->>GamePlayManager: access Instance
        activate GamePlayManager
        GamePlayManager-->>Shim: GamePlayManager instance
        Shim->>GamePlayManager: IsEmpty()
        GamePlayManager-->>Shim: isEmpty
        alt src.IsEntry and not isEmpty
            Shim->>GamePlayManager: GetScoreListCount()
            GamePlayManager-->>Shim: maxTrackNo
        else otherwise
            Shim->>Shim: maxTrackNo = 0
        end
        Shim->>PacketUpsertUserAll: ctor(index, src, maxTrackNo, onDone, onError)
        PacketUpsertUserAll-->>Shim: instance
    else Other constructor overload
        Shim->>PacketUpsertUserAll: ctor(index, src, onDone, onError)
        PacketUpsertUserAll-->>Shim: instance
    end
    Shim-->>Caller: PacketUpsertUserAll instance
    deactivate Shim
Loading

Class diagram for updated Shim handling of PacketUpsertUserAll constructors

classDiagram
    class Shim {
        +EncryptNetPacketBody(byte[] data) byte[]
        +CreatePacketUpsertUserAll(int index, UserData src, Action~int~ onDone, Action~PacketStatus~ onError) PacketUpsertUserAll
    }

    class PacketUpsertUserAll {
        +PacketUpsertUserAll(int index, UserData src, Action~int~ onDone, Action~PacketStatus~ onError)
        +PacketUpsertUserAll(int index, UserData src, int maxTrackNo, Action~int~ onDone, Action~PacketStatus~ onError)
    }

    class UserData {
    }

    class PacketStatus {
    }

    class GamePlayManager {
        +IsEmpty() bool
        +GetScoreListCount() int
    }

    class Singleton_GamePlayManager_ {
        +Instance GamePlayManager
    }

    Shim ..> PacketUpsertUserAll : uses via reflection
    Shim ..> UserData
    Shim ..> PacketStatus
    Shim ..> Singleton_GamePlayManager_ : queries Instance
    Singleton_GamePlayManager_ *-- GamePlayManager

    note for Singleton_GamePlayManager_ "Represents Singleton<GamePlayManager>"
Loading

File-Level Changes

Change Details Files
Add support for a third PacketUpsertUserAll constructor overload that includes a maxTrackNo parameter derived from gameplay state.
  • Detect a PacketUpsertUserAll constructor with parameters (int, UserData, int, Action, Action) and capture it as ctor3 when available.
  • Compute maxTrackNo based on whether the user data is an entry and the GamePlayManager is non-empty, using GetScoreListCount when applicable, otherwise defaulting to 0.
  • Invoke the detected constructor with index, src, computed maxTrackNo, onDone, and onError, returning the constructed PacketUpsertUserAll instance.
  • Fall back to throwing MissingMethodException if no known constructor overload is found, preserving previous error behavior.
AquaMai.Core/Helpers/Shim.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!

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
Copy Markdown

@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.

Hey - 我已经审查了你的更改,一切看起来都很棒!


Sourcery 对开源项目是免费的——如果你觉得我们的审查有帮助,欢迎分享给更多人 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进以后的审查。
Original comment in English

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


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.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for an additional constructor signature for PacketUpsertUserAll in Shim.cs, which includes logic to determine the maximum track number based on the current GamePlayManager state. The review feedback suggests using C# 12 collection expressions for the constructor parameter types to maintain consistency with the existing codebase and improve readability.

Comment on lines +192 to +199
else if (type.GetConstructor(new[]
{
typeof(int),
typeof(UserData),
typeof(int),
typeof(Action<int>),
typeof(Action<PacketStatus>)
}) is ConstructorInfo ctor3)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

为了保持代码风格的一致性,建议使用 C# 12 的集合表达式 [] 来代替 new[] { ... }。这与该方法中前面 ctor1ctor2 的获取方式保持一致,且代码更加简洁易读。

        else if (type.GetConstructor([typeof(int), typeof(UserData), typeof(int), typeof(Action<int>), typeof(Action<PacketStatus>)]) is ConstructorInfo ctor3)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Shim reflection-based constructor selection to support additional PacketUpsertUserAll constructor signatures seen in some game versions, improving compatibility across builds.

Changes:

  • Add a new PacketUpsertUserAll constructor match for the (int, UserData, int, Action<int>, Action<PacketStatus>) signature.
  • When using that signature, derive the third int argument from GamePlayManager score list count (when applicable).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-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.

No issues found across 1 file

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