feat: add MelonLoader version check to prevent crashes (#36)#59
feat: add MelonLoader version check to prevent crashes (#36)#59siakinnik wants to merge 3 commits into
Conversation
审阅者指南(在小型 PR 中折叠)审阅者指南在启动器中实现游戏启动前的 MelonLoader.dll 产品版本检查:如果检测到的版本不是 0.6.4,就显示阻塞式警告对话框,并允许用户中止启动游戏。 游戏启动时 MelonLoader 版本检查的时序图sequenceDiagram
actor User
participant Launcher
participant FileSystem
participant MelonLoaderDll as MelonLoader_dll
participant MessageBox
User->>Launcher: Click Start
Launcher->>FileSystem: Build mlDllPath
Launcher->>FileSystem: File.Exists(mlDllPath)
alt MelonLoader.dll exists
Launcher->>MelonLoaderDll: GetVersionInfo(mlDllPath)
MelonLoaderDll-->>Launcher: ProductVersion
alt Version is null or not starting with 0.6.4
Launcher->>MessageBox: Show warning dialog
MessageBox-->>Launcher: DialogResult
alt DialogResult is No
Launcher-->>User: Abort launch
else DialogResult is Yes
Launcher-->>User: Continue launch
end
else Version starts with 0.6.4
Launcher-->>User: Continue launch
end
else MelonLoader.dll missing
Launcher-->>User: Continue launch
end
文件级变更
与关联 Issue 的对应情况评估
提示与命令与 Sourcery 交互
自定义你的体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideImplements a pre-launch MelonLoader.dll product version check in the launcher and shows a blocking warning dialog if the detected version is not 0.6.4, allowing the user to abort starting the game. Sequence diagram for MelonLoader version check on game launchsequenceDiagram
actor User
participant Launcher
participant FileSystem
participant MelonLoaderDll as MelonLoader_dll
participant MessageBox
User->>Launcher: Click Start
Launcher->>FileSystem: Build mlDllPath
Launcher->>FileSystem: File.Exists(mlDllPath)
alt MelonLoader.dll exists
Launcher->>MelonLoaderDll: GetVersionInfo(mlDllPath)
MelonLoaderDll-->>Launcher: ProductVersion
alt Version is null or not starting with 0.6.4
Launcher->>MessageBox: Show warning dialog
MessageBox-->>Launcher: DialogResult
alt DialogResult is No
Launcher-->>User: Abort launch
else DialogResult is Yes
Launcher-->>User: Continue launch
end
else Version starts with 0.6.4
Launcher-->>User: Continue launch
end
else MelonLoader.dll missing
Launcher-->>User: Continue launch
end
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我发现了两个问题,并给出了一些总体反馈:
- 通过
Path.Combine(GamePath, "..", "MelonLoader", ...)使用硬编码的MelonLoader.dll相对路径,如果预期的文件夹结构发生变化,可能会比较脆弱;建议以更健壮的方式推导 MelonLoader 目录(例如基于已知的根路径或配置)。 - 当
ProductVersion为 null 或格式不符合预期时,警告信息中会显示空的或奇怪的版本字符串;建议对这种情况进行规范化处理(例如显示 "unknown" 或使用单独的信息),以避免让用户感到困惑。 - 新的警告对话框文本和标题目前是硬编码的英文;为与应用的其他部分保持一致,建议通过现有的 i18n/本地化机制来使用这些字符串,而不是在代码中直接写字面量。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The hardcoded relative path to `MelonLoader.dll` using `Path.Combine(GamePath, "..", "MelonLoader", ...)` may be fragile if the expected folder structure changes; consider deriving the MelonLoader directory more robustly (e.g., from a known root path or configuration).
- When `ProductVersion` is null or not in the expected format, the warning message will display an empty or odd version string; consider normalizing this case (e.g., showing "unknown" or a separate message) to avoid confusing users.
- The new warning dialog text and title are currently hardcoded in English; to match the rest of the app’s localization approach, wire these strings through the existing i18n/locale mechanism instead of inline literals.
## Individual Comments
### Comment 1
<location path="MaiChartManager/Launcher.cs" line_range="161-162" />
<code_context>
return;
}
+ string mlDllPath = Path.Combine(StaticSettings.GamePath, "..", "MelonLoader", "MelonLoader.dll");
+ if (File.Exists(mlDllPath))
+ {
+ var versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(mlDllPath);
</code_context>
<issue_to_address>
**suggestion (bug_risk):** 考虑在访问 MelonLoader DLL 版本信息的逻辑周围增加异常处理,以提升健壮性。
在 `File.Exists` 与 `GetVersionInfo` 之间,DLL 可能被删除或被锁定,从而抛出异常并中止启动流程。请将版本检查包裹在 try/catch 中,并进行优雅降级处理(例如记录警告日志并继续执行),以应对瞬时的文件系统/权限问题。
</issue_to_address>
### Comment 2
<location path="MaiChartManager/Launcher.cs" line_range="169-176" />
<code_context>
+
+ if (version == null || !version.StartsWith("0.6.4"))
+ {
+ var dialougResult = MessageBox.Show(
+ // Add i8n pls :)
+ $"Detected MelonLoader version {version}, but 0.6.4 is recommended for stability. Continue anyway?",
+ "MelonLoader Version Warning",
+ MessageBoxButtons.YesNo,
+ MessageBoxIcon.Warning);
+
+ if (dialougResult == DialogResult.No) return;
+ }
+ }
</code_context>
<issue_to_address>
**nitpick (typo):** 请修正变量名 `dialougResult` 中的拼写错误,以提高清晰度与一致性。
使用拼写正确的名称(例如 `dialogResult`)可以提升可读性,也更方便在代码中进行搜索。
Suggested implementation:
```csharp
var dialogResult = MessageBox.Show(
```
```csharp
if (dialogResult == DialogResult.No) return;
```
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- The hardcoded relative path to
MelonLoader.dllusingPath.Combine(GamePath, "..", "MelonLoader", ...)may be fragile if the expected folder structure changes; consider deriving the MelonLoader directory more robustly (e.g., from a known root path or configuration). - When
ProductVersionis null or not in the expected format, the warning message will display an empty or odd version string; consider normalizing this case (e.g., showing "unknown" or a separate message) to avoid confusing users. - The new warning dialog text and title are currently hardcoded in English; to match the rest of the app’s localization approach, wire these strings through the existing i18n/locale mechanism instead of inline literals.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The hardcoded relative path to `MelonLoader.dll` using `Path.Combine(GamePath, "..", "MelonLoader", ...)` may be fragile if the expected folder structure changes; consider deriving the MelonLoader directory more robustly (e.g., from a known root path or configuration).
- When `ProductVersion` is null or not in the expected format, the warning message will display an empty or odd version string; consider normalizing this case (e.g., showing "unknown" or a separate message) to avoid confusing users.
- The new warning dialog text and title are currently hardcoded in English; to match the rest of the app’s localization approach, wire these strings through the existing i18n/locale mechanism instead of inline literals.
## Individual Comments
### Comment 1
<location path="MaiChartManager/Launcher.cs" line_range="161-162" />
<code_context>
return;
}
+ string mlDllPath = Path.Combine(StaticSettings.GamePath, "..", "MelonLoader", "MelonLoader.dll");
+ if (File.Exists(mlDllPath))
+ {
+ var versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(mlDllPath);
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider handling exceptions around accessing the MelonLoader DLL version info for robustness.
Between `File.Exists` and `GetVersionInfo`, the DLL might be removed or locked, causing an exception that aborts launch. Please wrap the version check in a try/catch and degrade gracefully (e.g., log a warning and continue) to handle transient filesystem/permission issues.
</issue_to_address>
### Comment 2
<location path="MaiChartManager/Launcher.cs" line_range="169-176" />
<code_context>
+
+ if (version == null || !version.StartsWith("0.6.4"))
+ {
+ var dialougResult = MessageBox.Show(
+ // Add i8n pls :)
+ $"Detected MelonLoader version {version}, but 0.6.4 is recommended for stability. Continue anyway?",
+ "MelonLoader Version Warning",
+ MessageBoxButtons.YesNo,
+ MessageBoxIcon.Warning);
+
+ if (dialougResult == DialogResult.No) return;
+ }
+ }
</code_context>
<issue_to_address>
**nitpick (typo):** Fix the `dialougResult` variable name typo for clarity and consistency.
Using a correctly spelled name like `dialogResult` improves readability and makes the variable easier to find in searches.
Suggested implementation:
```csharp
var dialogResult = MessageBox.Show(
```
```csharp
if (dialogResult == DialogResult.No) return;
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces a version check for MelonLoader.dll to ensure compatibility, recommending version 0.6.4 for stability. Feedback suggests improving the robustness of the DLL path resolution to support various installation layouts and implementing internationalization for the warning message to avoid hardcoded strings and fix a typo.
| return; | ||
| } | ||
|
|
||
| string mlDllPath = Path.Combine(StaticSettings.GamePath, "..", "MelonLoader", "MelonLoader.dll"); |
There was a problem hiding this comment.
The path construction for MelonLoader.dll using .. assumes the game files are always in a subfolder (e.g., Package). In a standard installation where Sinmai_Data is in the root folder, StaticSettings.GamePath will be the root, and .. will point to the parent directory of the game, causing the check to fail. Consider checking both the current GamePath and its parent to support both installation layouts.
string mlDllPath = Path.Combine(StaticSettings.GamePath, "MelonLoader", "MelonLoader.dll");
if (!File.Exists(mlDllPath))
{
mlDllPath = Path.Combine(StaticSettings.GamePath, "..", "MelonLoader", "MelonLoader.dll");
}| var dialougResult = MessageBox.Show( | ||
| // Add i8n pls :) | ||
| $"Detected MelonLoader version {version}, but 0.6.4 is recommended for stability. Continue anyway?", | ||
| "MelonLoader Version Warning", | ||
| MessageBoxButtons.YesNo, | ||
| MessageBoxIcon.Warning); | ||
|
|
||
| if (dialougResult == DialogResult.No) return; |
There was a problem hiding this comment.
The MessageBox strings are hardcoded in English, and there is a typo in the variable name dialougResult. Since the project supports multiple languages and you've explicitly requested i18n, these strings should be moved to the Locale.resx resource file.
Note: You will need to add the keys MelonLoaderVersionWarning and MelonLoaderVersionWarningTitle to your resource files.
var dialogResult = MessageBox.Show(
string.Format(Locale.MelonLoaderVersionWarning, version ?? "unknown"),
Locale.MelonLoaderVersionWarningTitle,
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (dialogResult == DialogResult.No) return;There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="MaiChartManager/Launcher.cs">
<violation number="1" location="MaiChartManager/Launcher.cs:187">
P2: MelonLoader version-check failures are swallowed and only logged to console, so the launcher can proceed with no user-visible warning when compatibility cannot be verified.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
…eprocessor directive
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Requires human review: This is a new feature that modifies the launch flow with a version check and warning dialog, which could alter user behavior and requires human review to ensure correctness and safety.
| if (!version.StartsWith("0.6.4")) | ||
| { | ||
| // i8n pls | ||
| var dialogResult = MessageBox.Show( |
There was a problem hiding this comment.
this is not very important and no need to msgbox on startup. banner in mod setting page is ok
Description
This PR implements a version check for MelonLoader as requested in #36.
It checks
MelonLoader.dllin the game directory. If the version is not 0.6.4 (which is known to be stable for MCM), a warning dialog is displayed, allowing the user to either cancel the launch or proceed at their own risk.Changes
Launcher.csAdd i8n pls)))
Closes #36
Summary by Sourcery
在启动器中添加 MelonLoader 版本检查功能,在启动游戏前提醒用户当前版本可能不稳定。
新功能:
MelonLoader.dll实现对已安装 MelonLoader 版本的运行时检测。Original summary in English
Summary by Sourcery
Add a MelonLoader version check in the launcher to warn users about potentially unstable versions before starting the game.
New Features: