Ver código fonte

【更改】镜内细节改为逐项开关并升至 0.2.0

原实现是「镜内细节模式:游戏默认/自定义」的整体开关,改为四个互相独立的
开关,可按需只关其中若干项。

- 新配置:关闭镜内泛光、关闭镜内终极泛光、关闭镜内色散、关闭镜内鱼眼,默认均不勾选。
- 逐项按瞄具实例缓存原始值,取消勾选只还原被关掉的那几项,不影响其余。
- 版本号升至 0.2.0(csproj 与 BepInPlugin 两处一致)。
- docs/configuration.md 与 docs/principle.md 同步改写。
PJ568 1 mês atrás
pai
commit
57bebd6f85

+ 24 - 18
docs/configuration.md

@@ -17,7 +17,10 @@
 | 2. 镜内分辨率 · Scope Resolution | 瞄准中立即应用 \| Apply While Scoped | `true` | 关闭时,瞄准期间的改动推迟到退出镜内后应用。 |
 | 3. 镜内贴图与细节 · Scope Textures & Details | 镜内贴图 mip 模式 \| Scope Mip Mode | `游戏默认` | 游戏默认 / 自定义。自定义时覆盖镜内相机的贴图 mip 偏差。 |
 | 3. 镜内贴图与细节 · Scope Textures & Details | Mip 偏差 \| Mip Bias | `3` | `-2`…`8`;绝对值覆盖镜内 `streamingMipmapBias`,越大纹理越糊、越省带宽。 |
-| 3. 镜内贴图与细节 · Scope Textures & Details | 镜内细节模式 \| Scope Detail Mode | `游戏默认` | 游戏默认 / 自定义。自定义时关闭镜内泛光、终极泛光、色散与鱼眼。 |
+| 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内泛光 \| Disable Scope Bloom | `false` | 勾选则关闭镜内相机的泛光(`bloomOptimized`)。 |
+| 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内终极泛光 \| Disable Scope Ultimate Bloom | `false` | 勾选则关闭镜内相机的终极泛光(`ultimateBloom`)。 |
+| 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内色散 \| Disable Scope Chromatic Aberration | `false` | 勾选则关闭镜内相机的色散(`chromaticAberration`)。 |
+| 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内鱼眼 \| Disable Scope Fisheye | `false` | 勾选则关闭镜内相机的鱼眼(`fisheye`)。 |
 
 ## 三种取值方式
 
@@ -43,20 +46,20 @@
 
 覆盖对象是镜内相机上由 `EFT.CameraControl.OpticComponentUpdater.CopyComponentFromOptic(OpticSight)` 按每瞄具 `ScopeEffectsData` 设置的组件开关;游戏**不会**每帧重写这些开关,因此插件在该方法的 postfix 里覆盖一次即可持久。
 
-「镜内细节模式」设为「自定义」时,插件关闭镜内相机的以下四个组件:
+四个开关各自独立:勾选即关闭对应组件,取消勾选则还原为该瞄具的授权值;全部不勾选时完全保持游戏行为。
 
-| 组件 | 含义 |
+| 开关 | 关闭的组件 |
 | --- | --- |
-| `chromaticAberration` | 色散 |
-| `bloomOptimized` | 泛光 |
-| `ultimateBloom` | 终极泛光 |
-| `fisheye` | 鱼眼 |
+| 关闭镜内泛光 | `bloomOptimized` |
+| 关闭镜内终极泛光 | `ultimateBloom` |
+| 关闭镜内色散 | `chromaticAberration` |
+| 关闭镜内鱼眼 | `fisheye` |
 
-应用时机:每次换镜(`CopyComponentFromOptic` 因瞄具实例变化而执行)时在其 postfix 覆盖,配置变更时也重新应用一次。刻意不暴露 `tonemapping`,因为关掉它会破坏镜内色彩与曝光。
+应用时机:每次换镜(`CopyComponentFromOptic` 因瞄具实例变化而执行)时在其 postfix 应用,配置变更时也重新应用一次。插件按瞄具实例缓存各开关的原始值,因此取消勾选能正确还原——游戏的 `cachedOpticId` 守卫会让同一瞄具重复进镜时跳过写入,若不按实例判断缓存,就会把我们关掉的值误当成原始值。刻意不暴露 `tonemapping`,因为关掉它会破坏镜内色彩与曝光。
 
 ### 为什么不提供体积光与散射
 
-`OpticComponentUpdater.LateUpdate()` **每帧**把主相机的 `volumetricLightRenderer.enabled` / `.Resolution`、`undithering.enabled`、`tod_Scattering`、`mboit_Scattering` 覆盖到镜内相机;要修改它们必须在每帧强制覆盖。本插件选择不做,因此只提供第一类的三项配置。
+`OpticComponentUpdater.LateUpdate()` **每帧**把主相机的 `volumetricLightRenderer.enabled` / `.Resolution`、`undithering.enabled`、`tod_Scattering`、`mboit_Scattering` 覆盖到镜内相机;要修改它们必须在每帧强制覆盖。本插件选择不做,因此只提供第一类的四个开关。
 
 ## 注意
 
@@ -83,7 +86,10 @@ The plugin ships no custom UI or hotkeys. Install [BepInEx ConfigurationManager]
 | 2. 镜内分辨率 · Scope Resolution | 瞄准中立即应用 \| Apply While Scoped | `true` | When off, changes made while scoped are deferred until you unscope. |
 | 3. 镜内贴图与细节 · Scope Textures & Details | 镜内贴图 mip 模式 \| Scope Mip Mode | `游戏默认` | Game default / custom. Custom overrides the scope camera's texture mip bias. |
 | 3. 镜内贴图与细节 · Scope Textures & Details | Mip 偏差 \| Mip Bias | `3` | `-2`…`8`; an absolute override of the scope `streamingMipmapBias`; higher = blurrier textures and less bandwidth. |
-| 3. 镜内贴图与细节 · Scope Textures & Details | 镜内细节模式 \| Scope Detail Mode | `游戏默认` | Game default / custom. Custom disables in-scope bloom, ultimate bloom, chromatic aberration and fisheye. |
+| 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内泛光 \| Disable Scope Bloom | `false` | Check to disable the scope camera's bloom (`bloomOptimized`). |
+| 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内终极泛光 \| Disable Scope Ultimate Bloom | `false` | Check to disable the scope camera's ultimate bloom (`ultimateBloom`). |
+| 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内色散 \| Disable Scope Chromatic Aberration | `false` | Check to disable the scope camera's chromatic aberration (`chromaticAberration`). |
+| 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内鱼眼 \| Disable Scope Fisheye | `false` | Check to disable the scope camera's fisheye (`fisheye`). |
 
 ## The Three Resolution Modes
 
@@ -109,20 +115,20 @@ When "镜内贴图 mip 模式 | Scope Mip Mode" is set to "自定义" (custom),
 
 What is overridden are the component toggles that `EFT.CameraControl.OpticComponentUpdater.CopyComponentFromOptic(OpticSight)` sets on the scope camera according to each optic's `ScopeEffectsData`; the game does **not** rewrite these toggles every frame, so the plugin overrides them once in that method's postfix and the result persists.
 
-When "镜内细节模式 | Scope Detail Mode" is set to "自定义" (custom), the plugin disables the following four components on the scope camera:
+The four toggles are independent: checking one disables the matching component, unchecking it restores that optic's authored value, and leaving all of them unchecked keeps the game behavior entirely.
 
-| Component | Meaning |
+| Toggle | Component disabled |
 | --- | --- |
-| `chromaticAberration` | chromatic aberration |
-| `bloomOptimized` | bloom |
-| `ultimateBloom` | ultimate bloom |
-| `fisheye` | fisheye |
+| 关闭镜内泛光 (disable bloom) | `bloomOptimized` |
+| 关闭镜内终极泛光 (disable ultimate bloom) | `ultimateBloom` |
+| 关闭镜内色散 (disable chromatic aberration) | `chromaticAberration` |
+| 关闭镜内鱼眼 (disable fisheye) | `fisheye` |
 
-When it applies: once per optic change (when `CopyComponentFromOptic` runs because the optic instance changed) in its postfix, and again on a config change. `tonemapping` is deliberately not exposed, because disabling it would break the in-scope color and exposure.
+When it applies: once per optic change (when `CopyComponentFromOptic` runs because the optic instance changed) in its postfix, and again on a config change. The plugin caches the original values per optic instance so that unchecking a toggle restores correctly — the game's `cachedOpticId` guard skips the writes when you re-enter with the same optic, and without an instance-keyed cache our disabled values would be mistaken for the originals. `tonemapping` is deliberately not exposed, because disabling it would break the in-scope color and exposure.
 
 ### Why Volumetric Light and Scattering Are Not Offered
 
-`OpticComponentUpdater.LateUpdate()` copies the main camera's `volumetricLightRenderer.enabled` / `.Resolution`, `undithering.enabled`, `tod_Scattering` and `mboit_Scattering` onto the scope camera **every frame**; changing them would require forcing an override every frame. This plugin chooses not to do so, and therefore offers only the three configs of the first kind.
+`OpticComponentUpdater.LateUpdate()` copies the main camera's `volumetricLightRenderer.enabled` / `.Resolution`, `undithering.enabled`, `tod_Scattering` and `mboit_Scattering` onto the scope camera **every frame**; changing them would require forcing an override every frame. This plugin chooses not to do so, and therefore offers only the four toggles of the first kind.
 
 ## Note
 

+ 4 - 4
docs/principle.md

@@ -82,11 +82,11 @@
 
 ### 镜内细节
 
-`EFT.CameraControl.OpticComponentUpdater.CopyComponentFromOptic(OpticSight)` 会按每瞄具的 `ScopeEffectsData` 设置镜内相机上的组件开关(`chromaticAberration`、`bloomOptimized`、`ultimateBloom`、`fisheye`、`cc_FastVignette`、`tonemapping` 等)。**这些不会被每帧覆盖**,所以插件用该方法的 postfix 覆盖一次即可持久。
+`EFT.CameraControl.OpticComponentUpdater.CopyComponentFromOptic(OpticSight)` 会按每瞄具的 `ScopeEffectsData` 设置镜内相机上的组件开关(`chromaticAberration`、`bloomOptimized`、`ultimateBloom`、`fisheye`、`cc_FastVignette`、`tonemapping` 等)。**这些不会被每帧覆盖**,所以插件用该方法的 postfix 覆盖一次即可持久。插件对其中四个提供**逐项开关**(泛光、终极泛光、色散、鱼眼),并按瞄具实例缓存原始值,使取消勾选能正确还原。
 
 ### 刻意不做体积光与散射
 
-`OpticComponentUpdater.LateUpdate()` **每帧**把主相机的 `volumetricLightRenderer.enabled` / `.Resolution`、`undithering.enabled`、`tod_Scattering`、`mboit_Scattering` 覆盖到镜内相机,要改它们必须每帧强制覆盖;本插件选择不做,只提供第一类的三项(外加不暴露 `tonemapping`,因为关掉它会破坏镜内色彩与曝光)。
+`OpticComponentUpdater.LateUpdate()` **每帧**把主相机的 `volumetricLightRenderer.enabled` / `.Resolution`、`undithering.enabled`、`tod_Scattering`、`mboit_Scattering` 覆盖到镜内相机,要改它们必须每帧强制覆盖;本插件选择不做,只为第一类提供四个开关(外加不暴露 `tonemapping`,因为关掉它会破坏镜内色彩与曝光)。
 
 新增的 Harmony 目标是 `OpticComponentUpdater.CopyComponentFromOptic`(postfix);**不 patch** `LateUpdate` 或 `Awake`。
 
@@ -202,11 +202,11 @@ There are two write points for the in-scope texture mip and the in-scope details
 
 ### In-scope details
 
-`EFT.CameraControl.OpticComponentUpdater.CopyComponentFromOptic(OpticSight)` sets the component toggles on the scope camera according to each optic's `ScopeEffectsData` (`chromaticAberration`, `bloomOptimized`, `ultimateBloom`, `fisheye`, `cc_FastVignette`, `tonemapping`, etc.). **These are not overwritten every frame**, so the plugin overrides them once in that method's postfix and the result persists.
+`EFT.CameraControl.OpticComponentUpdater.CopyComponentFromOptic(OpticSight)` sets the component toggles on the scope camera according to each optic's `ScopeEffectsData` (`chromaticAberration`, `bloomOptimized`, `ultimateBloom`, `fisheye`, `cc_FastVignette`, `tonemapping`, etc.). **These are not overwritten every frame**, so the plugin overrides them once in that method's postfix and the result persists. The plugin exposes **individual toggles** for four of them (bloom, ultimate bloom, chromatic aberration, fisheye) and caches the original values per optic instance so that unchecking a toggle restores correctly.
 
 ### Volumetric light and scattering deliberately excluded
 
-`OpticComponentUpdater.LateUpdate()` copies the main camera's `volumetricLightRenderer.enabled` / `.Resolution`, `undithering.enabled`, `tod_Scattering` and `mboit_Scattering` onto the scope camera **every frame**; changing them would require forcing an override every frame. This plugin chooses not to do so and offers only the three of the first kind (and it does not expose `tonemapping`, because disabling it would break the in-scope color and exposure).
+`OpticComponentUpdater.LateUpdate()` copies the main camera's `volumetricLightRenderer.enabled` / `.Resolution`, `undithering.enabled`, `tod_Scattering` and `mboit_Scattering` onto the scope camera **every frame**; changing them would require forcing an override every frame. This plugin chooses not to do so and offers individual toggles only for the first kind (and it does not expose `tonemapping`, because disabling it would break the in-scope color and exposure).
 
 The new Harmony target is `OpticComponentUpdater.CopyComponentFromOptic` (postfix); it does **not** patch `LateUpdate` or `Awake`.
 

+ 83 - 25
src/PerformanceScope.Plugin/OpticQualityService.cs

@@ -29,6 +29,16 @@ namespace PerformanceScope
             "fisheye"
         };
 
+        /// <summary>与 DetailFieldNames 对应的可读名称,用于日志。</summary>
+        /// <summary>Human-readable names matching DetailFieldNames, used for logging.</summary>
+        private static readonly string[] DetailLabels =
+        {
+            "泛光 / bloom",
+            "终极泛光 / ultimate bloom",
+            "色散 / chromatic aberration",
+            "鱼眼 / fisheye"
+        };
+
         private readonly FieldInfo[] _detailFields = new FieldInfo[DetailFieldNames.Length];
 
         private readonly bool[] _detailOriginal = new bool[DetailFieldNames.Length];
@@ -41,7 +51,9 @@ namespace PerformanceScope
 
         private int _detailOpticId = int.MinValue;
 
-        private bool _detailOverridden;
+        private readonly bool[] _detailOverridden = new bool[DetailFieldNames.Length];
+
+        private int _detailAppliedMask;
 
         /// <summary>
         /// 当前服务实例;插件未加载时为 null,补丁据此透传原值。
@@ -228,8 +240,8 @@ namespace PerformanceScope
         }
 
         /// <summary>
-        /// 自定义模式下关闭镜内细节;否则把此前关掉的组件还原为游戏原始值。
-        /// In custom mode, disable the in-scope detail components; otherwise restore whatever we disabled.
+        /// 按逐项开关应用镜内细节:勾选则关闭对应组件,取消勾选则还原为游戏原始值。
+        /// Apply the in-scope detail toggles: a checked effect is disabled, an unchecked one is restored to the game's original value.
         /// </summary>
         private void ApplyDetails(OpticComponentUpdater updater)
         {
@@ -238,50 +250,96 @@ namespace PerformanceScope
                 return;
             }
 
-            if (PluginConfig.DetailMode?.Value != ScopeSettingMode.Custom)
-            {
-                RestoreDetails(updater);
-                return;
-            }
-
             for (int i = 0; i < _detailFields.Length; i++)
             {
                 Behaviour behaviour = GetDetailBehaviour(updater, i);
-                if (behaviour != null)
+                if (behaviour == null)
                 {
-                    behaviour.enabled = false;
+                    continue;
+                }
+
+                if (IsDetailDisabled(i))
+                {
+                    if (behaviour.enabled)
+                    {
+                        behaviour.enabled = false;
+                    }
+
+                    _detailOverridden[i] = true;
+                }
+                else if (_detailOverridden[i])
+                {
+                    // 只还原「我们关掉过」的项,避免在从未覆盖时误写游戏的默认值。
+                    // Restore only effects we actually disabled, so a never-overridden state never writes the game's defaults.
+                    behaviour.enabled = _detailOriginal[i];
+                    _detailOverridden[i] = false;
                 }
             }
 
-            if (!_detailOverridden)
+            int mask = DesiredDetailMask();
+            if (mask != _detailAppliedMask)
             {
-                _detailOverridden = true;
-                Log.Info("镜内细节已精简:关闭泛光、终极泛光、色散与鱼眼 | In-scope detail reduced: bloom, ultimate bloom, chromatic aberration and fisheye disabled");
+                _detailAppliedMask = mask;
+                Log.Info(mask == 0
+                    ? "镜内细节已还原为游戏默认 | In-scope detail restored to game default"
+                    : $"镜内细节覆盖已更新:关闭 {DescribeDisabled(mask)} | In-scope detail overrides updated: {DescribeDisabled(mask)}");
             }
         }
 
         /// <summary>
-        /// 仅还原「我们关掉过」的组件,避免在从未覆盖时误写游戏的默认值。
-        /// Restore only components we actually disabled, so a never-overridden state never writes the game's defaults.
+        /// 逐项开关是否勾选(勾选表示关闭该效果)。
+        /// Whether an individual detail toggle is checked (checked means the effect is disabled).
         /// </summary>
-        private void RestoreDetails(OpticComponentUpdater updater)
+        private static bool IsDetailDisabled(int index)
         {
-            if (!_detailOverridden)
+            switch (index)
             {
-                return;
+                case 0:
+                    return PluginConfig.DisableBloom?.Value == true;
+                case 1:
+                    return PluginConfig.DisableUltimateBloom?.Value == true;
+                case 2:
+                    return PluginConfig.DisableChromaticAberration?.Value == true;
+                case 3:
+                    return PluginConfig.DisableFisheye?.Value == true;
+                default:
+                    return false;
             }
+        }
 
-            for (int i = 0; i < _detailFields.Length; i++)
+        private static int DesiredDetailMask()
+        {
+            int mask = 0;
+            for (int i = 0; i < DetailFieldNames.Length; i++)
             {
-                Behaviour behaviour = GetDetailBehaviour(updater, i);
-                if (behaviour != null)
+                if (IsDetailDisabled(i))
                 {
-                    behaviour.enabled = _detailOriginal[i];
+                    mask |= 1 << i;
+                }
+            }
+
+            return mask;
+        }
+
+        private static string DescribeDisabled(int mask)
+        {
+            string text = string.Empty;
+            for (int i = 0; i < DetailLabels.Length; i++)
+            {
+                if ((mask & (1 << i)) == 0)
+                {
+                    continue;
                 }
+
+                if (text.Length > 0)
+                {
+                    text += "、";
+                }
+
+                text += DetailLabels[i];
             }
 
-            _detailOverridden = false;
-            Log.Info("镜内细节已还原为游戏默认 | In-scope detail restored to game default");
+            return text;
         }
 
         private Behaviour GetDetailBehaviour(OpticComponentUpdater updater, int index)

+ 1 - 1
src/PerformanceScope.Plugin/PerformanceScope.Plugin.csproj

@@ -5,7 +5,7 @@
     <AssemblyName>PerformanceScope</AssemblyName>
     <RootNamespace>PerformanceScope</RootNamespace>
     <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
-    <Version>0.1.1</Version>
+    <Version>0.2.0</Version>
   </PropertyGroup>
 
   <!-- 共享纯逻辑:与测试工程同源编译,避免多出一个运行时依赖 dll -->

+ 1 - 1
src/PerformanceScope.Plugin/Plugin.cs

@@ -16,7 +16,7 @@ namespace PerformanceScope
     /// config changes are debounced here before being handed to the service, while events such as scope exit are
     /// subscribed by the service itself. This plugin offers no custom UI or hotkey.
     /// </summary>
-    [BepInPlugin("com.pj568.performancescope", "PerformanceScope", "0.1.1")]
+    [BepInPlugin("com.pj568.performancescope", "PerformanceScope", "0.2.0")]
     public class PerformanceScopePlugin : BaseUnityPlugin
     {
         private const string HarmonyId = "com.pj568.performancescope";

+ 38 - 5
src/PerformanceScope.Plugin/PluginConfig.cs

@@ -41,7 +41,13 @@ namespace PerformanceScope
 
         public static ConfigEntry<float> MipBias { get; private set; }
 
-        public static ConfigEntry<ScopeSettingMode> DetailMode { get; private set; }
+        public static ConfigEntry<bool> DisableBloom { get; private set; }
+
+        public static ConfigEntry<bool> DisableUltimateBloom { get; private set; }
+
+        public static ConfigEntry<bool> DisableChromaticAberration { get; private set; }
+
+        public static ConfigEntry<bool> DisableFisheye { get; private set; }
 
         /// <summary>
         /// 绑定全部配置项并立即落盘,生成带注释的初始配置文件。
@@ -137,15 +143,42 @@ namespace PerformanceScope
                     new AcceptableValueRange<float>(ScopeMipMath.MinBias, ScopeMipMath.MaxBias),
                     new ConfigurationManagerAttributes { Order = 2 }));
 
-            DetailMode = config.Bind(
+            DisableBloom = config.Bind(
                 SectionDetails,
-                "镜内细节模式 | Scope Detail Mode",
-                ScopeSettingMode.GameDefault,
+                "关闭镜内泛光 | Disable Scope Bloom",
+                false,
                 new ConfigDescription(
-                    "游戏默认 / 自定义。自定义时关闭镜内泛光、终极泛光、色散与鱼眼(一次性覆盖,不动体积光与散射)。\nGame default / custom. When custom, disables in-scope bloom, ultimate bloom, chromatic aberration and fisheye (a one-shot override; volumetric light and scattering are left alone).",
+                    "勾选后关闭镜内相机的泛光(bloomOptimized)。不勾选则保持游戏行为。\nCheck to disable the optic camera's bloom (bloomOptimized). Unchecked keeps the game default.",
                     null,
                     new ConfigurationManagerAttributes { Order = 3 }));
 
+            DisableUltimateBloom = config.Bind(
+                SectionDetails,
+                "关闭镜内终极泛光 | Disable Scope Ultimate Bloom",
+                false,
+                new ConfigDescription(
+                    "勾选后关闭镜内相机的终极泛光(ultimateBloom)。\nCheck to disable the optic camera's ultimate bloom (ultimateBloom).",
+                    null,
+                    new ConfigurationManagerAttributes { Order = 4 }));
+
+            DisableChromaticAberration = config.Bind(
+                SectionDetails,
+                "关闭镜内色散 | Disable Scope Chromatic Aberration",
+                false,
+                new ConfigDescription(
+                    "勾选后关闭镜内相机的色散(chromaticAberration)。\nCheck to disable the optic camera's chromatic aberration (chromaticAberration).",
+                    null,
+                    new ConfigurationManagerAttributes { Order = 5 }));
+
+            DisableFisheye = config.Bind(
+                SectionDetails,
+                "关闭镜内鱼眼 | Disable Scope Fisheye",
+                false,
+                new ConfigDescription(
+                    "勾选后关闭镜内相机的鱼眼(fisheye)。\nCheck to disable the optic camera's fisheye (fisheye).",
+                    null,
+                    new ConfigurationManagerAttributes { Order = 6 }));
+
             config.Save();
         }
     }