Browse Source

【文档】注释与文本改为中英双语

对齐参考仓库 PJ-568/spt-potato-graphics 的双语约定。

- README:中文整段 + 分隔线 + English 整段。
- C# 注释与 XML 文档:中文行 + English 行;分节注释用「中文 · English」。
- 配置节名用「中文 · English」,键名用「中文 | English」,描述与日志用中文行加英文行。
- 配置键名变更后,旧 cfg 中的同名旧键会变为孤立项,会按新默认重建。
- 模板自带文件 scripts/check-grammar.mjs 与 .githooks 按惯例保持中文单语。
- 脚本注释与输出、工作流注释同样双语化。
PJ568 1 month ago
parent
commit
98c9fa05c2

+ 6 - 3
.github/workflows/test.yml

@@ -1,4 +1,7 @@
-name: 测试
+# ── 测试 · Tests ──
+# 纯逻辑层无游戏依赖,可在公共 runner 直接测试
+# The pure-logic layer has no game dependency and can be tested on a public runner
+name: 测试 · Tests
 
 on:
   push:
@@ -14,6 +17,6 @@ jobs:
       - uses: actions/setup-dotnet@v4
         with:
           dotnet-version: "10.0.x"
-      # 纯逻辑层无游戏依赖,可在 CI 直接测试
-      - name: 运行单元测试
+      # 运行单元测试 / Run unit tests
+      - name: 运行单元测试 · Run unit tests
         run: dotnet test tests/PerformanceScope.Tests/PerformanceScope.Tests.csproj -c Release

+ 146 - 7
README.md

@@ -1,3 +1,5 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 # PerformanceScope
 
 > 调整《逃离塔科夫》光学瞄具**镜内放大(PiP)相机**渲染分辨率的 SPT 客户端插件。
@@ -40,13 +42,13 @@
 
 | 节 | 键 | 默认值 | 说明 |
 | --- | --- | --- | --- |
-| 1. 通用 | 启用模组 | `true` | 总开关,关闭后恢复游戏默认分辨率。 |
-| 1. 通用 | 启用日志 | `false` | 输出常规/诊断/警告日志(错误日志始终输出)。 |
-| 1. 通用 | 详细日志 | `false` | 更详细的诊断信息。 |
-| 2. 镜内分辨率 | 取值方式 | `游戏默认` | 游戏默认 / 屏幕高度比例 / 绝对像素。 |
-| 2. 镜内分辨率 | 屏幕高度比例 | `0.5` | 镜内边长 = round(屏幕高度 × 该值)。 |
-| 2. 镜内分辨率 | 绝对像素 | `1024` | 镜内方形 RenderTexture 的边长。 |
-| 2. 镜内分辨率 | 瞄准中立即应用 | `true` | 关闭时,瞄准期间的改动推迟到退出镜内后应用。 |
+| 1. 通用 · General | 启用模组 \| Enable Mod | `true` | 总开关,关闭后恢复游戏默认分辨率。 |
+| 1. 通用 · General | 启用日志 \| Enable Logging | `false` | 输出常规/诊断/警告日志(错误日志始终输出)。 |
+| 1. 通用 · General | 详细日志 \| Verbose Logging | `false` | 更详细的诊断信息。 |
+| 2. 镜内分辨率 · Scope Resolution | 取值方式 \| Resolution Mode | `游戏默认` | 游戏默认 / 屏幕高度比例 / 绝对像素。 |
+| 2. 镜内分辨率 · Scope Resolution | 屏幕高度比例 \| Screen Height Ratio | `0.5` | 镜内边长 = round(屏幕高度 × 该值)。 |
+| 2. 镜内分辨率 · Scope Resolution | 绝对像素 \| Absolute Pixels | `1024` | 镜内方形 RenderTexture 的边长。 |
+| 2. 镜内分辨率 · Scope Resolution | 瞄准中立即应用 \| Apply While Scoped | `true` | 关闭时,瞄准期间的改动推迟到退出镜内后应用。 |
 
 > 默认取值方式为「游戏默认」,即安装后不改变游戏行为;请显式选择模式。
 > 注意:`屏幕高度比例` 在 4K(2160p)下 `0.7` 会得到 1512,**高于**游戏默认 1024,反而增加负载。
@@ -131,3 +133,140 @@ scripts/package.sh
 ## 许可证
 
 (待定)
+
+===============================================================
+
+# PerformanceScope
+
+> An SPT client plugin that adjusts the render resolution of the **in-scope (PiP) camera** for magnified optics in Escape from Tarkov.
+
+Picture-in-picture (PiP) is the most GPU-hungry part of a magnified optic: the game creates a dedicated camera and renders an `N×N` square RenderTexture (default `1024²`) onto the lens. This plugin makes that `N` configurable, so you can trade image quality for frame rate.
+
+## How it works
+
+Client decompilation (EFT 0.16 / SPT 4.1.x) confirms:
+
+- `EFT.CameraControl.OpticCameraManager` has `public int OpticFinalResolution = 1024;`. Its `SetResolution(int)` destroys and recreates an `N×N` square `RenderTexture` (`name = "SSAAOpticCurrent"`), assigns it to `Camera.targetTexture`, and sets the global `Shader.SetGlobalTexture("_CamTex")`.
+- In the current version this value is **not exposed by any setting**; its only call site is `Init()`.
+- Volumetric lighting (`VolumetricLightRenderer`), grass motion vectors (`GPUInstancer`), distant shadows (`DistantShadow`) and MBOIT (`WindowsManager`) all detect the size change on the next frame and rebuild automatically — no plugin intervention needed.
+
+The plugin therefore uses a Harmony **prefix** to override the `resolution` argument of `SetResolution`, so the game's own `Init()` creates the RT at the target size directly, avoiding a double-rebuild flicker.
+
+The scoped image is finally upscaled to the screen together with the whole frame by the main camera's `SSAA`/`SSAAImpl` — **this plugin does not change any upscaler (DLSS/FSR) setting**; it only adjusts the in-scope source resolution.
+
+## Supported versions
+
+- SPT `4.1.x` (EFT client `0.16`).
+- The client plugin depends on specific types and methods in `Assembly-CSharp.dll`, so it may break across versions.
+
+## Installation
+
+1. Build or download `PerformanceScope-v{version}.zip`.
+2. Extract it into the game root so the dll lands at
+   `BepInEx/plugins/PerformanceScope/PerformanceScope.dll`.
+3. Launch the game.
+
+## Tuning
+
+Install [BepInEx ConfigurationManager](https://github.com/BepInEx/BepInEx.ConfigurationManager), then press **F1** in game (rebindable in its config) and adjust the `PerformanceScope` sections.
+**This plugin ships no custom UI or hotkeys**; changes apply immediately in game (synced every frame by the service layer).
+
+## Configuration
+
+Config file: `BepInEx/config/com.pj568.performancescope.cfg` (or edit through ConfigurationManager).
+
+| Section | Key | Default | Notes |
+| --- | --- | --- | --- |
+| 1. 通用 · General | 启用模组 \| Enable Mod | `true` | Master switch; when off the game default is restored. |
+| 1. 通用 · General | 启用日志 \| Enable Logging | `false` | Writes info/verbose/warning logs (errors are always logged). |
+| 1. 通用 · General | 详细日志 \| Verbose Logging | `false` | More detailed diagnostics. |
+| 2. 镜内分辨率 · Scope Resolution | 取值方式 \| Resolution Mode | `游戏默认` | Game default / screen-height ratio / absolute pixels. |
+| 2. 镜内分辨率 · Scope Resolution | 屏幕高度比例 \| Screen Height Ratio | `0.5` | Scope edge = round(screen height × value). |
+| 2. 镜内分辨率 · Scope Resolution | 绝对像素 \| Absolute Pixels | `1024` | Edge length of the square scope RenderTexture. |
+| 2. 镜内分辨率 · Scope Resolution | 瞄准中立即应用 \| Apply While Scoped | `true` | When off, changes made while scoped are deferred until you unscope. |
+
+> The default mode is "game default", so installing the plugin does not change anything until you pick a mode.
+> Note: with `屏幕高度比例`, `0.7` on a 4K (2160p) display yields 1512, which is **higher** than the game default 1024 and therefore costs more.
+
+## Build
+
+Prerequisite: a local SPT client install (the client assemblies are proprietary and not distributed with this repository).
+
+```shellscript
+# Point at the game root (falls back to the local Lutris prefix by default)
+export SPT_DIR="/path/to/Escape from Tarkov"
+dotnet build src/PerformanceScope.Plugin/PerformanceScope.Plugin.csproj -c Release
+```
+
+A Release build copies the dll to `$SPT_DIR/BepInEx/plugins/PerformanceScope/` automatically;
+disable with `-p:DeployToGame=false`.
+
+## Test
+
+The pure-logic layer (resolution math and apply decisions) has no game dependency and can be tested directly:
+
+```shellscript
+dotnet test tests/PerformanceScope.Tests/PerformanceScope.Tests.csproj
+```
+
+## Packaging and release
+
+```shellscript
+# Package only
+scripts/package.sh
+# Output: artifacts/PerformanceScope-v{version}.zip
+
+# One-command release: build → package → tag → push → create GitHub Release
+scripts/release.sh
+# Dry run (builds/packages and prints the commands; requires a clean work tree)
+scripts/release.sh --dry-run
+```
+
+Release prerequisites: GitHub CLI (`gh`) installed and logged in, and a configured `remote origin`.
+`release.sh` verifies a clean work tree and a fresh tag, then creates a Release with the zip attached.
+
+## Deploy (local)
+
+```shellscript
+scripts/package.sh
+# Extract the zip into the game root, or rely on the automatic copy of Release builds
+```
+
+On startup `BepInEx/LogOutput.log` should show:
+
+```
+[Info   :PerformanceScope] PerformanceScope 已加载(在 ConfigurationManager 菜单中调参)
+[Info   :PerformanceScope] 镜内分辨率 1024 → 720
+```
+
+## Verification
+
+1. Enable "启用日志 | Enable Logging" in ConfigurationManager.
+2. Enter a raid and aim down sights through a magnified optic.
+3. Open ConfigurationManager (default F1) and switch "取值方式 | Resolution Mode" to "屏幕高度比例" or "绝对像素".
+4. Watch `BepInEx/LogOutput.log` for `镜内分辨率 1024 → …`, and check the scoped image quality / frame rate.
+5. Turn off "瞄准中立即应用 | Apply While Scoped", change the value while scoped, and confirm the change only applies after you unscope.
+
+## Interaction with other mods
+
+- **PiP-Disabler** (`com.fiodor.pipdisabler`): it is a **postfix gate** on `SetResolution` (it neither rewrites the argument nor the field), so it coexists with this plugin; suppressed scoped rendering does not trigger this plugin's conflict retry.
+- **Fontaine's FOV Fix / Amands's Graphics**: they patch targets (`OpticComponentUpdater`, etc.) that do not overlap this plugin, so there is no direct conflict.
+- **DERP (Dynamic External Resolution Patch)**: it changes the **main camera / global** resolution and upscaler mode, a different mechanism from this plugin (in-scope square RT size). Both can be used together, but note that their effects stack.
+- **DLSS / FSR**: this plugin **does not switch upscaler modes**; however, changing the scoped RT size while an upscaler is active may cause a one-frame flicker — turn off "瞄准中立即应用" to avoid it. SPT officially documents a black flicker when switching modes under DLSS/FSR.
+
+> Every game symbol used here (`OpticCameraManager.SetResolution`, `OpticFinalResolution`, `_CamTex`, `SSAAOpticCurrent`, …) was taken directly from decompiling the **SPT 4.1.x `Assembly-CSharp.dll` installed on this machine**, not from public sources.
+
+## Known limitations and risks
+
+- **No independent in-scope upscaler setting**: the game has a single `SSAA`/`SSAAImpl` on the main camera and the scoped image is part of it; a truly independent in-scope FSR/DLSS would require attaching a second component, which this plugin does not do.
+- **Changing resolution while scoped may flash for one frame** because the RenderTexture is destroyed and recreated; turn off "瞄准中立即应用" to avoid it.
+- **Texture aliasing becomes more visible at low in-scope resolutions**: the scope camera's mipmap bias is only set once in `Init()`, and the plugin does not compensate.
+- **Possible conflict with other mods that patch `SetResolution`**: if a third-party prefix rewrites the same argument, the plugin detects the target not taking effect and pauses retries until you change the target, avoiding per-frame RenderTexture rebuilds.
+- **Version sensitive**: it depends on specific types and methods and may break after an EFT update.
+- **CI limitation**: a client plugin must reference proprietary assemblies, which public runners cannot build, so the repository keeps only `test.yml` (pure-logic unit tests); release packages are produced locally with `scripts/release.sh`.
+
+## License
+
+(TBD)
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

+ 11 - 5
scripts/package.sh

@@ -1,7 +1,10 @@
 #!/usr/bin/env bash
-# 本地打包:构建 Release 并把 dll 按游戏根目录结构打成 zip
-# 用法:scripts/package.sh
-# 前置:本机已安装 SPT 客户端(用 SPT_DIR 指定其根目录)
+# ── 本地打包 · Local packaging ──
+# 构建 Release 并把 dll 按游戏根目录结构打成 zip
+# Build Release and zip the dll using the game-root layout
+# 用法 / Usage:scripts/package.sh
+# 前置 / Prerequisite:本机已安装 SPT 客户端(用 SPT_DIR 指定其根目录)
+#   A local SPT client install (point SPT_DIR at its root)
 set -euo pipefail
 
 ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -10,15 +13,18 @@ cd "$ROOT"
 export DOTNET_ROOT="${DOTNET_ROOT:-$HOME/.dotnet}"
 export PATH="$DOTNET_ROOT:$DOTNET_ROOT/tools:$PATH"
 
+# 从 csproj 读取版本号 / Read the version from the csproj
 VERSION="$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' src/PerformanceScope.Plugin/PerformanceScope.Plugin.csproj | head -1)"
-[ -n "$VERSION" ] || { echo "错误:未能从 csproj 读取 Version" >&2; exit 1; }
+[ -n "$VERSION" ] || { echo "错误:未能从 csproj 读取 Version | Error: cannot read Version from csproj" >&2; exit 1; }
 
 OUT="artifacts"
 STAGE="$OUT/PerformanceScope"
 
+# 清理旧产物 / Clean previous output
 rm -rf "$OUT"
 mkdir -p "$STAGE/BepInEx/plugins/PerformanceScope"
 
+# 构建但不自动部署,改由 zip 分发 / Build without auto-deploy; the zip is the deliverable
 dotnet build src/PerformanceScope.Plugin/PerformanceScope.Plugin.csproj -c Release -p:DeployToGame=false
 
 cp "src/PerformanceScope.Plugin/bin/Release/PerformanceScope.dll" \
@@ -30,4 +36,4 @@ cp "src/PerformanceScope.Plugin/bin/Release/PerformanceScope.dll" \
 )
 rm -rf "$STAGE"
 
-echo "已生成 artifacts/PerformanceScope-v${VERSION}.zip"
+echo "已生成 artifacts/PerformanceScope-v${VERSION}.zip | Generated artifacts/PerformanceScope-v${VERSION}.zip"

+ 20 - 13
scripts/release.sh

@@ -1,7 +1,10 @@
 #!/usr/bin/env bash
-# 本地一条命令发布:构建 → 打包 → 打 tag → 推送 → 创建 GitHub Release
-# 用法:scripts/release.sh [--dry-run]
-# 前置:已安装并登录 gh,且仓库已配置 remote origin
+# ── 本地一键发布 · One-command local release ──
+# 构建 → 打包 → 打 tag → 推送 → 创建 GitHub Release
+# build → package → tag → push → create GitHub Release
+# 用法 / Usage:scripts/release.sh [--dry-run]
+# 前置 / Prerequisites:已安装并登录 gh,且仓库已配置 remote origin
+#   GitHub CLI (gh) installed and logged in, with a configured remote origin
 set -euo pipefail
 
 ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -12,37 +15,41 @@ if [ "${1:-}" = "--dry-run" ]; then
   DRY_RUN=1
 fi
 
+# 从 csproj 读取版本号 / Read the version from the csproj
 VERSION="$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' src/PerformanceScope.Plugin/PerformanceScope.Plugin.csproj | head -1)"
-[ -n "$VERSION" ] || { echo "错误:未能从 csproj 读取 Version" >&2; exit 1; }
+[ -n "$VERSION" ] || { echo "错误:未能从 csproj 读取 Version | Error: cannot read Version from csproj" >&2; exit 1; }
 TAG="v$VERSION"
 
 # 工作区必须干净,避免发布内容与提交不一致
+# Require a clean work tree so the release matches the commit
 if [ -n "$(git status --porcelain)" ]; then
-  echo "错误:工作区有未提交改动,请先提交" >&2
+  echo "错误:工作区有未提交改动,请先提交 | Error: uncommitted changes; commit them first" >&2
   git status --short
   exit 1
 fi
 
 BRANCH="$(git rev-parse --abbrev-ref HEAD)"
 if [ "$BRANCH" = "HEAD" ]; then
-  echo "错误:处于游离 HEAD,无法发布" >&2
+  echo "错误:处于游离 HEAD,无法发布 | Error: detached HEAD, cannot release" >&2
   exit 1
 fi
 
+# tag 不能已存在 / The tag must not already exist
 if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
-  echo "错误:tag $TAG 已存在" >&2
+  echo "错误:tag $TAG 已存在 | Error: tag $TAG already exists" >&2
   exit 1
 fi
 
-echo "版本:$VERSION   标签:$TAG   分支:$BRANCH"
+echo "版本 / Version:$VERSION   标签 / Tag:$TAG   分支 / Branch:$BRANCH"
 
 # 构建并打包(--dry-run 也会执行,以校验构建与产物)
+# Build and package (also runs under --dry-run to validate the build and artifact)
 bash scripts/package.sh
 ZIP="artifacts/PerformanceScope-v${VERSION}.zip"
-[ -f "$ZIP" ] || { echo "错误:未找到产物 $ZIP" >&2; exit 1; }
+[ -f "$ZIP" ] || { echo "错误:未找到产物 $ZIP | Error: artifact not found: $ZIP" >&2; exit 1; }
 
 if [ "$DRY_RUN" = "1" ]; then
-  echo "[dry-run] 将执行:"
+  echo "[dry-run] 将执行 / would run:"
   echo "  git tag -a $TAG -m \"$TAG\""
   echo "  git push origin $BRANCH"
   echo "  git push origin $TAG"
@@ -50,12 +57,12 @@ if [ "$DRY_RUN" = "1" ]; then
   exit 0
 fi
 
-command -v gh >/dev/null 2>&1 || { echo "错误:未安装 GitHub CLI(gh)" >&2; exit 1; }
-git remote get-url origin >/dev/null 2>&1 || { echo "错误:未配置 git remote origin" >&2; exit 1; }
+command -v gh >/dev/null 2>&1 || { echo "错误:未安装 GitHub CLI(gh)| Error: GitHub CLI (gh) not installed" >&2; exit 1; }
+git remote get-url origin >/dev/null 2>&1 || { echo "错误:未配置 git remote origin | Error: no git remote 'origin' configured" >&2; exit 1; }
 
 git tag -a "$TAG" -m "PerformanceScope $TAG"
 git push origin "$BRANCH"
 git push origin "$TAG"
 gh release create "$TAG" "$ZIP" --title "PerformanceScope $TAG" --generate-notes
 
-echo "已发布 $TAG(产物:$ZIP)"
+echo "已发布 $TAG(产物:$ZIP)| Released $TAG (artifact: $ZIP)"

+ 23 - 8
src/PerformanceScope.Core/OpticResolutionDecision.cs

@@ -1,31 +1,46 @@
 namespace PerformanceScope.Core
 {
-    /// <summary>一次决策应执行的动作。</summary>
+    /// <summary>
+    /// 一次决策应执行的动作。
+    /// The action a single decision should perform.
+    /// </summary>
     public enum OpticApplyAction
     {
-        /// <summary>无需动作。</summary>
+        /// <summary>
+        /// 无需动作。
+        /// No action needed.
+        /// </summary>
         None = 0,
 
-        /// <summary>立即应用目标分辨率。</summary>
+        /// <summary>
+        /// 立即应用目标分辨率。
+        /// Apply the target resolution immediately.
+        /// </summary>
         Apply = 1,
 
-        /// <summary>推迟到退出镜内后再应用。</summary>
+        /// <summary>
+        /// 推迟到退出镜内后再应用。
+        /// Defer until after leaving the scope.
+        /// </summary>
         Defer = 2
     }
 
     /// <summary>
     /// 镜内分辨率应用的纯决策逻辑:输入游戏当前状态,输出该做什么。
     /// 与游戏 API 解耦,便于单元测试。
+    /// Pure decision logic for applying the scope resolution: takes the current game state and returns what to do.
+    /// Decoupled from the game API, easy to unit test.
     /// </summary>
     public static class OpticResolutionDecision
     {
         /// <summary>
         /// 决策。
+        /// Decides.
         /// </summary>
-        /// <param name="current">游戏当前镜内分辨率。</param>
-        /// <param name="target">配置目标分辨率。</param>
-        /// <param name="isScoped">是否正在镜内瞄准。</param>
-        /// <param name="applyWhileScoped">是否允许瞄准中立即应用。</param>
+        /// <param name="current">游戏当前镜内分辨率 / Current in-game scope resolution.</param>
+        /// <param name="target">配置目标分辨率 / Configured target resolution.</param>
+        /// <param name="isScoped">是否正在镜内瞄准 / Whether the player is currently scoped.</param>
+        /// <param name="applyWhileScoped">是否允许瞄准中立即应用 / Whether applying while scoped is allowed.</param>
         public static OpticApplyAction Decide(int current, int target, bool isScoped, bool applyWhileScoped)
         {
             if (current == target)

+ 13 - 3
src/PerformanceScope.Core/OpticResolutionMode.cs

@@ -2,16 +2,26 @@ namespace PerformanceScope.Core
 {
     /// <summary>
     /// 镜内(PiP)渲染分辨率的取值方式。
+    /// How the in-scope (PiP) render resolution is chosen.
     /// </summary>
     public enum OpticResolutionMode
     {
-        /// <summary>使用游戏默认值(当前版本为 1024)。</summary>
+        /// <summary>
+        /// 使用游戏默认值(当前版本为 1024)。
+        /// Uses the game default (1024 in the current version).
+        /// </summary>
         GameDefault = 0,
 
-        /// <summary>按屏幕高度的比例取值:round(屏幕高度 × 比例)。</summary>
+        /// <summary>
+        /// 按屏幕高度的比例取值:round(屏幕高度 × 比例)。
+        /// Takes a fraction of the screen height: round(screen height × ratio).
+        /// </summary>
         ScreenHeightRatio = 1,
 
-        /// <summary>取固定的绝对像素值。</summary>
+        /// <summary>
+        /// 取固定的绝对像素值。
+        /// Uses a fixed absolute pixel value.
+        /// </summary>
         AbsolutePixels = 2
     }
 }

+ 35 - 12
src/PerformanceScope.Core/ResolutionMath.cs

@@ -4,25 +4,44 @@ namespace PerformanceScope.Core
 {
     /// <summary>
     /// 镜内渲染分辨率换算:纯函数,无游戏依赖,便于单元测试。
+    /// In-scope render resolution math: pure functions with no game dependency, easy to unit test.
     /// </summary>
     public static class ResolutionMath
     {
-        /// <summary>游戏当前版本的镜内方形 RenderTexture 默认边长。</summary>
+        /// <summary>
+        /// 游戏当前版本的镜内方形 RenderTexture 默认边长。
+        /// Default edge length of the square scope RenderTexture in the current game version.
+        /// </summary>
         public const int GameDefaultResolution = 1024;
 
-        /// <summary>允许的最小边长。</summary>
+        /// <summary>
+        /// 允许的最小边长。
+        /// Minimum allowed edge length.
+        /// </summary>
         public const int MinResolution = 64;
 
-        /// <summary>允许的最大边长。</summary>
+        /// <summary>
+        /// 允许的最大边长。
+        /// Maximum allowed edge length.
+        /// </summary>
         public const int MaxResolution = 4096;
 
-        /// <summary>允许的最小比例。</summary>
+        /// <summary>
+        /// 允许的最小比例。
+        /// Minimum allowed ratio.
+        /// </summary>
         public const float MinRatio = 0.05f;
 
-        /// <summary>允许的最大比例。</summary>
+        /// <summary>
+        /// 允许的最大比例。
+        /// Maximum allowed ratio.
+        /// </summary>
         public const float MaxRatio = 4f;
 
-        /// <summary>把边长夹取到 [MinResolution, MaxResolution]。</summary>
+        /// <summary>
+        /// 把边长夹取到 [MinResolution, MaxResolution]。
+        /// Clamps an edge length to [MinResolution, MaxResolution].
+        /// </summary>
         public static int ClampResolution(int value)
         {
             if (value < MinResolution)
@@ -33,7 +52,10 @@ namespace PerformanceScope.Core
             return value > MaxResolution ? MaxResolution : value;
         }
 
-        /// <summary>比例是否有效(有限且落在允许区间内)。</summary>
+        /// <summary>
+        /// 比例是否有效(有限且落在允许区间内)。
+        /// Whether a ratio is valid (finite and within the allowed range).
+        /// </summary>
         public static bool IsValidRatio(float ratio)
         {
             return !float.IsNaN(ratio) && !float.IsInfinity(ratio) && ratio >= MinRatio && ratio <= MaxRatio;
@@ -41,12 +63,13 @@ namespace PerformanceScope.Core
 
         /// <summary>
         /// 计算镜内渲染分辨率边长。非法或缺失输入一律回退到 <paramref name="gameDefault"/>。
+        /// Computes the in-scope render resolution edge length. Invalid or missing inputs fall back to <paramref name="gameDefault"/>.
         /// </summary>
-        /// <param name="mode">取值方式。</param>
-        /// <param name="screenHeight">当前屏幕高度(像素)。</param>
-        /// <param name="gameDefault">游戏默认边长,默认 <see cref="GameDefaultResolution"/>。</param>
-        /// <param name="screenHeightRatio">屏幕高度比例(仅 <see cref="OpticResolutionMode.ScreenHeightRatio"/> 用)。</param>
-        /// <param name="absolutePixels">绝对像素边长(仅 <see cref="OpticResolutionMode.AbsolutePixels"/> 用)。</param>
+        /// <param name="mode">取值方式 / Resolution mode.</param>
+        /// <param name="screenHeight">当前屏幕高度(像素)/ Current screen height in pixels.</param>
+        /// <param name="gameDefault">游戏默认边长,默认 <see cref="GameDefaultResolution"/> / Game default edge length, defaults to <see cref="GameDefaultResolution"/>.</param>
+        /// <param name="screenHeightRatio">屏幕高度比例(仅 <see cref="OpticResolutionMode.ScreenHeightRatio"/> 用)/ Screen-height ratio (used only by <see cref="OpticResolutionMode.ScreenHeightRatio"/>).</param>
+        /// <param name="absolutePixels">绝对像素边长(仅 <see cref="OpticResolutionMode.AbsolutePixels"/> 用)/ Absolute pixel edge length (used only by <see cref="OpticResolutionMode.AbsolutePixels"/>).</param>
         public static int Resolve(
             OpticResolutionMode mode,
             int screenHeight,

+ 21 - 5
src/PerformanceScope.Plugin/Log.cs

@@ -4,18 +4,25 @@ namespace PerformanceScope
 {
     /// <summary>
     /// 统一的日志出口。普通日志受配置开关控制,错误日志始终输出以便排障。
+    /// Unified logging outlet. Normal logs are gated by config switches; error logs are always emitted for troubleshooting.
     /// </summary>
     internal static class Log
     {
         private static ManualLogSource _logger;
 
-        /// <summary>注入 BepInEx 提供的日志源。</summary>
+        /// <summary>
+        /// 注入 BepInEx 提供的日志源。
+        /// Injects the BepInEx-provided log source.
+        /// </summary>
         public static void Init(ManualLogSource logger)
         {
             _logger = logger;
         }
 
-        /// <summary>常规信息,仅在启用日志时输出。</summary>
+        /// <summary>
+        /// 常规信息,仅在启用日志时输出。
+        /// Informational message, emitted only when logging is enabled.
+        /// </summary>
         public static void Info(string message)
         {
             if (_logger == null || PluginConfig.EnableLogging?.Value != true)
@@ -26,7 +33,10 @@ namespace PerformanceScope
             _logger.LogInfo(message);
         }
 
-        /// <summary>诊断信息,需同时启用日志与详细日志。</summary>
+        /// <summary>
+        /// 诊断信息,需同时启用日志与详细日志。
+        /// Diagnostic message, requires both Enable Logging and Verbose Logging.
+        /// </summary>
         public static void Verbose(string message)
         {
             if (_logger == null
@@ -39,7 +49,10 @@ namespace PerformanceScope
             _logger.LogInfo(message);
         }
 
-        /// <summary>警告,仅在启用日志时输出。</summary>
+        /// <summary>
+        /// 警告,仅在启用日志时输出。
+        /// Warning, emitted only when logging is enabled.
+        /// </summary>
         public static void Warn(string message)
         {
             if (_logger == null || PluginConfig.EnableLogging?.Value != true)
@@ -50,7 +63,10 @@ namespace PerformanceScope
             _logger.LogWarning(message);
         }
 
-        /// <summary>错误,始终输出。</summary>
+        /// <summary>
+        /// 错误,始终输出。
+        /// Error, always emitted.
+        /// </summary>
         public static void Error(string message)
         {
             if (_logger == null)

+ 37 - 11
src/PerformanceScope.Plugin/OpticResolutionService.cs

@@ -9,6 +9,9 @@ namespace PerformanceScope
     /// 镜内 PiP 分辨率的决策与应用。每帧由插件调用 <see cref="Tick"/>,
     /// 根据配置与当前游戏状态决定何时调用 <see cref="OpticCameraManager.SetResolution"/>。
     /// 普通类,由插件在 Awake 中创建并注册到 <see cref="Instance"/>。
+    /// Decision and application of the in-scope PiP resolution. The plugin calls <see cref="Tick"/> every frame,
+    /// which decides when to call <see cref="OpticCameraManager.SetResolution"/> based on config and game state.
+    /// A plain class, created by the plugin in Awake and assigned to <see cref="Instance"/>.
     /// </summary>
     internal sealed class OpticResolutionService
     {
@@ -18,21 +21,35 @@ namespace PerformanceScope
 
         private int _conflictTarget = int.MinValue;
 
-        /// <summary>当前服务实例;插件未加载时为 null,补丁据此透传原值。</summary>
+        /// <summary>
+        /// 当前服务实例;插件未加载时为 null,补丁据此透传原值。
+        /// Current service instance; null when the plugin is not loaded, in which case patches pass the original value through.
+        /// </summary>
         public static OpticResolutionService Instance { get; set; }
 
-        /// <summary>最近一次解析出的目标边长,供叠加显示。</summary>
+        /// <summary>
+        /// 最近一次解析出的目标边长,供叠加显示。
+        /// Most recently resolved target edge length, used for overlay display.
+        /// </summary>
         public int LastTarget { get; private set; } = ResolutionMath.GameDefaultResolution;
 
-        /// <summary>是否有因瞄准中而推迟应用的目标。</summary>
+        /// <summary>
+        /// 是否有因瞄准中而推迟应用的目标。
+        /// Whether a target is currently deferred because the player is scoped.
+        /// </summary>
         public bool PendingApply { get; private set; }
 
-        /// <summary>是否因第三方改写导致目标无法生效而暂停重试。</summary>
+        /// <summary>
+        /// 是否因第三方改写导致目标无法生效而暂停重试。
+        /// Whether retries are paused because a third-party rewrite kept the target from taking effect.
+        /// </summary>
         public bool ConflictLocked { get; private set; }
 
         /// <summary>
         /// 计算当前配置对应的目标边长。模组关闭时返回游戏默认值,
         /// 从而让游戏恢复其原生 1024。
+        /// Computes the target edge length for the current config. Returns the game default when the mod is off,
+        /// so the game falls back to its native 1024.
         /// </summary>
         public int ComputeTarget()
         {
@@ -48,7 +65,10 @@ namespace PerformanceScope
                 PluginConfig.AbsolutePixels.Value);
         }
 
-        /// <summary>每帧调用:在相机就绪时把配置分辨率同步给游戏。</summary>
+        /// <summary>
+        /// 每帧调用:在相机就绪时把配置分辨率同步给游戏。
+        /// Called every frame: syncs the configured resolution to the game once the camera is ready.
+        /// </summary>
         public void Tick()
         {
             OpticCameraManager ocm = GetOpticCameraManager();
@@ -57,7 +77,7 @@ namespace PerformanceScope
                 if (!_loggedNoCamera)
                 {
                     _loggedNoCamera = true;
-                    Log.Verbose("镜内相机尚未就绪,暂不应用。");
+                    Log.Verbose("镜内相机尚未就绪,暂不应用 | Optic camera not ready, skipping.");
                 }
 
                 return;
@@ -71,6 +91,7 @@ namespace PerformanceScope
             if (ConflictLocked)
             {
                 // 仅在目标变化(例如玩家改了配置)时解除锁定,避免每帧重建。
+                // Unlock only when the target changes (e.g. the player edits config) to avoid per-frame rebuilds.
                 if (target == _conflictTarget)
                 {
                     return;
@@ -96,7 +117,7 @@ namespace PerformanceScope
                     {
                         _pendingTarget = target;
                         PendingApply = true;
-                        Log.Info($"镜内瞄准中,推迟应用分辨率 {ocm.OpticFinalResolution} → {target}");
+                        Log.Info($"镜内瞄准中,推迟应用分辨率 | scoped, deferring resolution {ocm.OpticFinalResolution} → {target}");
                     }
 
                     break;
@@ -107,7 +128,10 @@ namespace PerformanceScope
             }
         }
 
-        /// <summary>安全地调用游戏接口重建镜内 RenderTexture。</summary>
+        /// <summary>
+        /// 安全地调用游戏接口重建镜内 RenderTexture。
+        /// Safely calls the game API to rebuild the scope RenderTexture.
+        /// </summary>
         private void Apply(OpticCameraManager ocm, int target)
         {
             int old = ocm.OpticFinalResolution;
@@ -124,26 +148,28 @@ namespace PerformanceScope
             }
             catch (Exception e)
             {
-                Log.Error($"设置镜内分辨率失败({old} → {target}):{e}");
+                Log.Error($"设置镜内分辨率失败({old} → {target}) | Failed to set scope resolution: {e}");
                 return;
             }
 
             PendingApply = false;
             LastTarget = target;
-            Log.Info($"镜内分辨率 {old} → {target}");
+            Log.Info($"镜内分辨率 | scope resolution {old} → {target}");
 
             if (ocm.OpticFinalResolution != target)
             {
                 // 第三方 prefix/postfix 可能改写了结果;锁定以避免每帧重建 RenderTexture。
+                // A third-party prefix/postfix may have rewritten the result; lock to avoid rebuilding the RenderTexture every frame.
                 ConflictLocked = true;
                 _conflictTarget = target;
-                Log.Warn($"镜内分辨率未生效(仍为 {ocm.OpticFinalResolution}),可能存在冲突模组;已暂停重试直至目标变化。");
+                Log.Warn($"镜内分辨率未生效(仍为 {ocm.OpticFinalResolution}),可能存在冲突模组;已暂停重试直至目标变化 | Scope resolution did not take effect (still {ocm.OpticFinalResolution}); a conflicting mod may exist. Retrying paused until target changes.");
             }
         }
 
         private static OpticCameraManager GetOpticCameraManager()
         {
             // 读取静态字段而非 Instance 属性:避免在菜单等场景中触发 CameraManager 的懒创建。
+            // Read the static field instead of the Instance property to avoid triggering CameraManager's lazy creation in menus.
             CameraManager manager = CameraManager.instance;
             return manager == null ? null : manager.OpticCameraManager;
         }

+ 8 - 3
src/PerformanceScope.Plugin/Plugin.cs

@@ -8,6 +8,9 @@ namespace PerformanceScope
     /// 插件入口:初始化配置、日志、Harmony 补丁与分辨率服务。
     /// 所有调参通过 BepInEx ConfigurationManager 在游戏内完成(默认 F1,可在其配置中改键),
     /// 服务层每帧读取配置并即时生效;本插件不提供自定义 UI 或热键。
+    /// Plugin entry point: initializes config, logging, Harmony patches and the resolution service.
+    /// All tweaking is done in-game via BepInEx ConfigurationManager (F1 by default; rebindable in its config);
+    /// the service reads config every frame and applies it immediately. This plugin offers no custom UI or hotkey.
     /// </summary>
     [BepInPlugin("com.pj568.performancescope", "PerformanceScope", "0.1.0")]
     public class PerformanceScopePlugin : BaseUnityPlugin
@@ -24,12 +27,14 @@ namespace PerformanceScope
 
             OpticResolutionService.Instance = new OpticResolutionService();
 
-            Log.Info("PerformanceScope 已加载(在 ConfigurationManager 菜单中调参)");
+            Log.Info("PerformanceScope 已加载 | loaded(在 ConfigurationManager 菜单中调参 / configure via ConfigurationManager)");
         }
 
         private void Update()
         {
             // 每帧同步:ConfigurationManager 里改动配置后立即生效,并处理瞄准中的延迟应用。
+            // Per-frame sync: apply ConfigurationManager changes immediately and handle
+            // deferred in-scope applies.
             OpticResolutionService.Instance?.Tick();
         }
 
@@ -46,7 +51,7 @@ namespace PerformanceScope
             }
             catch (Exception e)
             {
-                Log.Error("卸载 Harmony 补丁失败:" + e);
+                Log.Error("卸载 Harmony 补丁失败 | Failed to unpatch Harmony patches: " + e);
             }
         }
 
@@ -59,7 +64,7 @@ namespace PerformanceScope
             }
             catch (Exception e)
             {
-                Log.Error("应用 Harmony 补丁失败:" + e);
+                Log.Error("应用 Harmony 补丁失败 | Failed to apply Harmony patches: " + e);
             }
         }
     }

+ 26 - 17
src/PerformanceScope.Plugin/PluginConfig.cs

@@ -6,11 +6,14 @@ namespace PerformanceScope
     /// <summary>
     /// 插件配置项定义。所有绑定项以静态属性暴露,供服务层直接读取。
     /// 配置界面由 BepInEx ConfigurationManager 提供(默认 F1,可在其配置中改键)。
+    /// Plugin configuration definitions. All bindings are exposed as static properties
+    /// for the service layer to read directly.
+    /// The config UI is provided by BepInEx ConfigurationManager (F1 by default; rebindable in its config).
     /// </summary>
     internal static class PluginConfig
     {
-        private const string SectionGeneral = "1. 通用";
-        private const string SectionResolution = "2. 镜内分辨率";
+        private const string SectionGeneral = "1. 通用 · General";
+        private const string SectionResolution = "2. 镜内分辨率 · Scope Resolution";
 
         public static ConfigEntry<bool> EnableMod { get; private set; }
 
@@ -26,71 +29,77 @@ namespace PerformanceScope
 
         public static ConfigEntry<bool> ApplyWhileScoped { get; private set; }
 
-        /// <summary>绑定全部配置项并立即落盘,生成带注释的初始配置文件。</summary>
+        /// <summary>
+        /// 绑定全部配置项并立即落盘,生成带注释的初始配置文件。
+        /// Binds all config entries and saves immediately, generating the initial annotated config file.
+        /// </summary>
         public static void Init(ConfigFile config)
         {
             EnableMod = config.Bind(
                 SectionGeneral,
-                "启用模组",
+                "启用模组 | Enable Mod",
                 true,
                 new ConfigDescription(
-                    "总开关。关闭后恢复游戏默认镜内分辨率。",
+                    "总开关。关闭后恢复游戏默认镜内分辨率。\nMaster switch. When off, restores the game's default scope resolution.",
                     null,
                     new ConfigurationManagerAttributes { Order = 1 }));
 
             EnableLogging = config.Bind(
                 SectionGeneral,
-                "启用日志",
+                "启用日志 | Enable Logging",
                 false,
                 new ConfigDescription(
-                    "输出本模组的常规/诊断/警告日志(错误日志始终输出)。",
+                    "输出本模组的常规/诊断/警告日志(错误日志始终输出)。\nWrites info/verbose/warning logs (errors are always logged).",
                     null,
                     new ConfigurationManagerAttributes { Order = 2 }));
 
             VerboseLogging = config.Bind(
                 SectionGeneral,
-                "详细日志",
+                "详细日志 | Verbose Logging",
                 false,
                 new ConfigDescription(
-                    "在启用日志的基础上输出更详细的诊断信息。",
+                    "在启用日志的基础上输出更详细的诊断信息。\nAdds more detailed diagnostics on top of Enable Logging.",
                     null,
                     new ConfigurationManagerAttributes { IsAdvanced = true, Order = 3 }));
 
             Mode = config.Bind(
                 SectionResolution,
-                "取值方式",
+                "取值方式 | Resolution Mode",
                 // 默认不改变游戏行为;玩家显式选择后再生效(4K 下 0.7 反而会高于默认 1024)。
+                // Default leaves game behaviour unchanged; it applies only after the player picks explicitly
+                // (at 4K, 0.7 is actually higher than the default 1024).
                 OpticResolutionMode.GameDefault,
                 new ConfigDescription(
-                    "游戏默认 / 屏幕高度比例 / 绝对像素。",
+                    "游戏默认 / 屏幕高度比例 / 绝对像素。\nGame default / screen-height ratio / absolute pixels.",
                     // 枚举无需 AcceptableValueList(ConfigurationManager 会自动渲染为下拉框)
+                    // No AcceptableValueList needed for enums (ConfigurationManager renders a dropdown automatically)
                     null,
                     new ConfigurationManagerAttributes { Order = 1 }));
 
             ScreenHeightRatio = config.Bind(
                 SectionResolution,
-                "屏幕高度比例",
+                "屏幕高度比例 | Screen Height Ratio",
                 0.5f,
                 new ConfigDescription(
-                    "镜内边长 = round(屏幕高度 × 该值)。",
+                    "镜内边长 = round(屏幕高度 × 该值)。\nScope edge length = round(screen height × this value).",
                     new AcceptableValueRange<float>(ResolutionMath.MinRatio, ResolutionMath.MaxRatio),
                     new ConfigurationManagerAttributes { ShowRangeAsPercent = true, Order = 2 }));
 
             AbsolutePixels = config.Bind(
                 SectionResolution,
-                "绝对像素",
+                "绝对像素 | Absolute Pixels",
                 ResolutionMath.GameDefaultResolution,
                 new ConfigDescription(
-                    "镜内方形 RenderTexture 的边长(像素)。",
+                    "镜内方形 RenderTexture 的边长(像素)。\nEdge length of the square scope RenderTexture, in pixels.",
                     new AcceptableValueRange<int>(ResolutionMath.MinResolution, ResolutionMath.MaxResolution),
                     new ConfigurationManagerAttributes { Order = 3 }));
 
             ApplyWhileScoped = config.Bind(
                 SectionResolution,
-                "瞄准中立即应用",
+                "瞄准中立即应用 | Apply While Scoped",
                 true,
                 new ConfigDescription(
-                    "关闭时,瞄准镜内期间的改动会推迟到退出镜内后应用,以避免画面闪烁。",
+                    "关闭时,瞄准镜内期间的改动会推迟到退出镜内后应用,以避免画面闪烁。\nWhen off, changes made while scoped are deferred until you leave the scope, to avoid a one-frame flicker.",
                     null,
                     new ConfigurationManagerAttributes { Order = 4 }));
 

+ 5 - 0
src/PerformanceScope.Plugin/SetResolutionPatch.cs

@@ -7,11 +7,15 @@ namespace PerformanceScope
     /// 覆盖游戏传入的镜内分辨率参数。游戏自身 Init() 调用
     /// <c>SetResolution(OpticFinalResolution)</c>(初值 1024)时,prefix 会直接改成目标值,
     /// 从而避免先建 1024 再重建造成的闪烁。
+    /// Overrides the scope resolution argument passed by the game. When the game's own Init() calls
+    /// <c>SetResolution(OpticFinalResolution)</c> (initial value 1024), the prefix replaces it with the target value,
+    /// avoiding the flicker caused by creating 1024 first and then rebuilding.
     /// </summary>
     [HarmonyPatch(typeof(OpticCameraManager), nameof(OpticCameraManager.SetResolution))]
     internal static class SetResolutionPatch
     {
         // HarmonyWrapSafe:prefix 抛异常时包裹并跳过原方法而非中断游戏 Init 流程。
+        // HarmonyWrapSafe: if the prefix throws, wrap it and skip the original method instead of aborting the game's Init flow.
         [HarmonyWrapSafe]
         [HarmonyPrefix]
         private static void Prefix(ref int resolution)
@@ -20,6 +24,7 @@ namespace PerformanceScope
             if (service == null)
             {
                 // 插件尚未初始化完成,保持游戏原值透传。
+                // The plugin has not finished initializing; pass the game's original value through.
                 return;
             }
 

+ 1 - 1
tests/PerformanceScope.Tests/ResolutionMathTests.cs

@@ -9,7 +9,7 @@ namespace PerformanceScope.Tests
         [InlineData(0.5f, 1440, 720)]
         [InlineData(0.7f, 1080, 756)]
         [InlineData(1.0f, 1080, 1080)]
-        [InlineData(0.666f, 1440, 959)] // 959.04 → 四舍五入 959
+        [InlineData(0.666f, 1440, 959)] // 959.04 → 四舍五入 959 · 959.04 → rounded to 959
         public void ScreenHeightRatio_按屏幕高度换算(float ratio, int screenHeight, int expected)
         {
             int actual = ResolutionMath.Resolve(OpticResolutionMode.ScreenHeightRatio, screenHeight, ratio, 0);