Skip to content

fix(config): look sections up by type in ReflectionManager.GetSection(Type) - #158

Merged
clansty merged 2 commits into
MuNET-OSS:mainfrom
Cleroth:fix/config-section-lookup
Oct 9, 2026
Merged

clansty merged 2 commits into
MuNET-OSS:mainfrom
Cleroth:fix/config-section-lookup

Conversation

@Cleroth

@Cleroth Cleroth commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

ReflectionManager.GetSection(Type) called TryGetSection(type.FullName, ...). That resolves to the string overload, which looks the name up as a section path (GameSettings.JudgeAdjust), not as a full type name (AquaMai.Mods.GameSettings.JudgeAdjust). So it never found anything and always threw KeyNotFoundException: Section <FullName> not found. It now calls the Type overload, TryGetSection(type, ...), which already looks up sectionsByFullName.

There is no caller in this repo today, but GetSection(Type) is part of the public IReflectionManager interface. I hit it in a fork where a mod writes its own section back to the config: config.ReflectionManager.GetSection(typeof(JudgeAdjust)), called when saving from an in-game settings page. That crashed the game.

Verification

The headless MonoCecilReflectionProvider and ReflectionManager run over the upstream AquaMai.Mods.dll:

GetSection("GameSettings.JudgeAdjust") GetSection(typeof(AquaMai.Mods.GameSettings.JudgeAdjust))
Before found Section AquaMai.Mods.GameSettings.JudgeAdjust not found
After found found (GameSettings.JudgeAdjust)

ReflectionManager.GetSection(Type) 调用的是 TryGetSection(type.FullName, ...),匹配到 string 重载,按节路径(如 GameSettings.JudgeAdjust)而不是完整类型名查找,因此总是抛出 Section <FullName> not found。现改为调用已有的 Type 重载 TryGetSection(type, ...)(按 sectionsByFullName 查找)。

本仓库目前没有调用者,但它是公开接口 IReflectionManager 的一部分。我在一个分支里让 mod 用 GetSection(typeof(JudgeAdjust)) 把自身配置写回文件时,游戏因此崩溃。验证:对上游 AquaMai.Mods.dll,修复前按类型查找失败,修复后成功。

View guided diff

Sourcery 摘要

错误修复:

  • 修复基于类型的节检索,使公共反射 API 能够通过配置节的完整类型名称定位这些节。
Original summary in English

Sourcery 摘要

错误修复:

  • 修复基于类型的配置节查找,使公共反射 API 根据类型的完整名称解析配置节,而不是将类型名称视为配置节路径。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Fix type-based configuration section lookup so the public reflection API resolves sections by their full type name instead of treating the type name as a section path.

…(Type)

It passed type.FullName to TryGetSection(string), which looks up section paths, so it never found anything. JudgeAdjust.Save1P uses it: saving from the practice-mode offset or calibration page crashed the game with 'Section AquaMai.Mods.GameSettings.JudgeAdjust not found'.
@sourcery-ai

sourcery-ai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
审查者指南(小型 PR 中折叠显示)

审查者指南

此 PR 修复了公共 GetSection(Type) API,使其能够通过完全限定的 CLR 类型名称成功解析配置节,同时保持基于路径的字符串查找行为不变。这一行实现改动由解释性注释支持,并已针对上游程序集中的基于路径和基于类型的查找进行了验证。

按类型查找配置节的时序图

sequenceDiagram
    participant Mod
    participant ReflectionManager
    participant TypeLookup as sectionsByFullName
    participant Section

    Mod->>ReflectionManager: GetSection(type)
    ReflectionManager->>ReflectionManager: TryGetSection(type)
    ReflectionManager->>TypeLookup: lookup by type.FullName
    TypeLookup-->>ReflectionManager: Section
    ReflectionManager-->>Mod: ISection
Loading

文件级改动

改动 详情 文件
修正基于类型的节查找:使用现有的 Type 重载,而不是将完全限定的类型名称解释为节路径。
  • 通过 TryGetSection(Type, ...) 和 sectionsByFullName 索引路由 GetSection(Type)。
  • 当不存在匹配节时,保留现有的 KeyNotFoundException 行为。
  • 记录各重载之间的区别,以及字符串查找不正确的原因。
AquaMai.Config/Reflection/ReflectionManager.cs

提示和命令

与 Sourcery 互动

  • 触发新的审查: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 回复审查评论,请 Sourcery 根据该评论创建 issue。你也可以回复审查评论并使用 @sourcery-ai issue,根据该评论创建 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 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes the public GetSection(Type) API so it successfully resolves configuration sections by their fully qualified CLR type name, while leaving path-based string lookup unchanged. The one-line implementation change is supported by an explanatory comment and was verified against the upstream assembly for both path- and type-based lookups.

Sequence diagram for configuration section lookup by type

sequenceDiagram
    participant Mod
    participant ReflectionManager
    participant TypeLookup as sectionsByFullName
    participant Section

    Mod->>ReflectionManager: GetSection(type)
    ReflectionManager->>ReflectionManager: TryGetSection(type)
    ReflectionManager->>TypeLookup: lookup by type.FullName
    TypeLookup-->>ReflectionManager: Section
    ReflectionManager-->>Mod: ISection
Loading

File-Level Changes

Change Details Files
Correct type-based section lookup to use the existing Type overload instead of interpreting a fully qualified type name as a section path.
  • Route GetSection(Type) through TryGetSection(Type, ...) and the sectionsByFullName index.
  • Preserve the existing KeyNotFoundException behavior when no matching section exists.
  • Document the overload distinction and why the string-based lookup is incorrect.
AquaMai.Config/Reflection/ReflectionManager.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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

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

View guided diff | Re-trigger cubic

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

嘿——我已经审阅了你的更改,看起来很棒!

Sourcery 评估

已批准。


Sourcery 对开源项目免费——如果你喜欢我们的审查,请考虑分享它们 ✨
Original comment in English

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

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread AquaMai.Config/Reflection/ReflectionManager.cs Outdated
@clansty
clansty merged commit 43c3fa0 into MuNET-OSS:main Oct 9, 2026
2 checks passed
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