Skip to content

fix(launch): match IsGBKEncoding behavior with Framework - #3605

Open
fakeboboliu wants to merge 1 commit into
PCL-Community:devfrom
fakeboboliu:dev
Open

fix(launch): match IsGBKEncoding behavior with Framework#3605
fakeboboliu wants to merge 1 commit into
PCL-Community:devfrom
fakeboboliu:dev

Conversation

@fakeboboliu

@fakeboboliu fakeboboliu commented Sep 9, 2026

Copy link
Copy Markdown

问题

private static string GetNativesFolder()
{
var result = Path.Combine(ModInstanceList.McMcInstanceSelected.PathInstance, ModInstanceList.McMcInstanceSelected.Name + "-natives");
if (SystemInfo.IsGBKEncoding || result.IsASCII())
return result;
result = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".minecraft", "bin", "natives");
if (result.IsASCII())
return result;
return Path.Combine(SystemPaths.DriveLetter, "ProgramData", "PCL", "natives");
}

在启动过程中,此处使用运行时常量 IsGBKEncoding 确定当前 Active CodePage 是否是 GBK,
但在此项目迁移到非 Framework 后,Encoding.Default.CodePage 现在永远为 UTF-8,使 IsGBKEncoding 永远为 false

这一问题造成原本可以在 GBK 系统上运行多版本隔离实例的启动过程错误跳过分支,
从而总是使用同一 natives 目录解压 lwjgl 等,并造成启动多个不同依赖版本实例时,后续实例无法启动。

目的

此修复使启动过程尊重原始开发人员意图。

权衡

此处有两个接近等价的方案,使用:

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding.GetEncoding(0).CodePage == 936;

此方法需要预先修改全局状态,依赖执行顺序,如分离引入 Provider 过程到 Program.cs 易被误删或影响行为,故放弃。

目前的从 kernel32.dll 获取 ACP 的操作可完全等价于 .NET Framework 中代码的行为,且确保相对原子化的可靠工具常量,故选择。

Sourcery 摘要

恢复准确的活动代码页检测,以防止 GBK 系统上多个隔离实例启动失败。

错误修复:

  • 修正应用程序启动期间对 GBK 系统的检测,使隔离的 Minecraft 实例能够选择适当的原生依赖目录并可靠启动。

增强功能:

  • 通过直接确定 Windows 活动代码页,使 IsGBKEncoding 的行为与 .NET Framework 保持一致。
Original summary in English

Sourcery 摘要

恢复与 Framework 兼容的活动代码页检测,以防止独立的 Minecraft 实例在 GBK 系统上启动失败。

Bug 修复:

  • 在应用程序启动期间恢复准确的 GBK 系统检测,使独立的 Minecraft 实例能够选择正确的本机依赖目录并可靠启动。

增强功能:

  • 通过直接确定 Windows 活动代码页,使 IsGBKEncoding 的行为与 .NET Framework 保持一致。
Original summary in English

Summary by Sourcery

Restore Framework-compatible active code page detection to prevent isolated Minecraft instances from failing on GBK systems.

Bug Fixes:

  • Restore accurate GBK system detection during application startup so isolated Minecraft instances select the correct native dependency directories and can launch reliably.

Enhancements:

  • Align IsGBKEncoding behavior with .NET Framework by determining the Windows active code page directly.

@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: XS PR 大小评估:微型 labels Sep 9, 2026
@sourcery-ai

sourcery-ai Bot commented Sep 9, 2026

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

审查者指南

该 PR 通过直接调用 kernel32.dll 查询 Windows 的活动代码页,修复了非 .NET Framework 运行时上的 GBK 检测问题,同时保留了 GBK 系统上隔离实例的预期启动行为。

启动期间原生 GBK 检测的时序图

sequenceDiagram
    participant Launch as Launch process
    participant SystemInfo
    participant KernelInterop
    participant Windows as Windows kernel32.dll

    Launch->>SystemInfo: IsGBKEncoding
    SystemInfo->>KernelInterop: GetACP()
    KernelInterop->>Windows: GetACP()
    Windows-->>KernelInterop: Active code page
    KernelInterop-->>SystemInfo: 936 or other code page
    SystemInfo-->>Launch: true when code page is 936
Loading

文件级变更

变更 详细信息 文件
根据 Windows 活动代码页而不是运行时的默认编码来确定是否使用 GBK。
  • 为 kernel32.dll GetACP() 添加源代码生成的 P/Invoke 声明。
  • 更新 IsGBKEncoding,使其将原生活动代码页与 936 进行比较。
  • 移除之前 Encoding.Default 检查所使用的 System.Text 依赖。
PCL.Core/Utils/OS/KernelInterop.cs
PCL.Core/Utils/OS/SystemInfo.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

The PR fixes GBK detection on non-.NET Framework runtimes by querying Windows’ active code page directly via kernel32.dll, preserving the intended launch behavior for isolated instances on GBK systems.

Sequence diagram for native GBK detection during launch

sequenceDiagram
    participant Launch as Launch process
    participant SystemInfo
    participant KernelInterop
    participant Windows as Windows kernel32.dll

    Launch->>SystemInfo: IsGBKEncoding
    SystemInfo->>KernelInterop: GetACP()
    KernelInterop->>Windows: GetACP()
    Windows-->>KernelInterop: Active code page
    KernelInterop-->>SystemInfo: 936 or other code page
    SystemInfo-->>Launch: true when code page is 936
Loading

File-Level Changes

Change Details Files
Determine GBK usage from the Windows active code page instead of the runtime’s default encoding.
  • Add a source-generated P/Invoke declaration for kernel32.dll GetACP().
  • Update IsGBKEncoding to compare the native active code page with 936.
  • Remove the System.Text dependency used by the previous Encoding.Default check.
PCL.Core/Utils/OS/KernelInterop.cs
PCL.Core/Utils/OS/SystemInfo.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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T07:09:16.873937Z 03e8c4c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

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


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 ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XS PR 大小评估:微型 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants