Explorar o código

【文档】更新原理与钩子实现说明

记录实际判定与拦截点:战斗走 GameWorld.OnGameStarted,藏身处走 HideoutController.HideoutAwake(藏身处不经过 GameWorld 流程),并修正骨架阶段的相关错误描述;README 补充被禁入口含重连、藏身处入口不受限。
PJ568 hai 1 mes
pai
achega
b3e37b8e36
Modificáronse 2 ficheiros con 18 adicións e 28 borrados
  1. 2 2
      README.md
  2. 16 26
      docs/principle.md

+ 2 - 2
README.md

@@ -17,7 +17,7 @@
 
 - **会话级**:标记只存于内存,SPT 进程结束后自然消失,重启即恢复。
 - **触发条件**:成功进入过至少一次战局或藏身处(判定钩子见 `docs/principle.md`)。
-- **被禁入口**:在已有标记时,开始战局的入口会被拦截(仅前端限制,见“已知限制”)。
+- **被禁入口**:在已有标记时,主菜单的“开始战局”与“重连”入口会被置灰并显示提示(仅前端限制,见“已知限制”);藏身处入口不受限,仍可进入。
 
 ## 安装
 
@@ -77,7 +77,7 @@ Once a raid (or the hideout) has been entered, the plugin blocks starting anothe
 
 - **Session-scoped**: the flag is in-memory only and disappears when the SPT process ends.
 - **Trigger**: at least one raid or hideout entry has succeeded (hook points in `docs/principle.md`).
-- **Blocked entry**: once flagged, the raid-start entry is intercepted (client-side only, see limitations).
+- **Blocked entry**: once flagged, the main-menu "Play" and "Reconnect" entries are greyed out with a tooltip (client-side only, see limitations); the hideout entry stays available.
 
 ## Installation
 

+ 16 - 26
docs/principle.md

@@ -1,6 +1,6 @@
 # 原理与钩子设计
 
-> 本文记录判定点与拦截钩子的设计。当前仓库为骨架,钩子尚未实现;实现时以本文为准。
+> 本文记录判定点与拦截钩子的实际实现。
 
 ## 总体思路
 
@@ -15,21 +15,16 @@
 
 ## 判定点:进入
 
-计划钩子点:`EFT.GameWorld.OnGameStarted`。
-
-- 当 `GameWorld` 启动完成,即视为“已进入一次战局”。
-- 藏身处同样经由 `GameWorld` 流程,故一并覆盖。
-- 置位动作幂等:重复进入只保持标记为真。
+- **战斗战局**:`Patches/EnterRaidPatch.cs` 挂钩 `EFT.GameWorld.OnGameStarted()`(`[HarmonyPostfix]`)。该方法在离线/在线战局加载完成时触发一次。
+- **藏身处**:`Patches/EnterHideoutPatch.cs` 挂钩 `EFT.Hideout.HideoutController.HideoutAwake()`。藏身处**不经过** `GameWorld.OnGameStarted`,故必须单独挂钩 `HideoutController`(注意不要与嵌套类 `EFT.TarkovApplication.HideoutController` 混淆)。
+- 两者命中后均调用 `SessionGate.MarkEnteredScene()`;置位幂等:重复进入只保持标记为真。
+- 各补丁用 `[HarmonyPrepare]` + `AccessTools.Method` 做目标方法存在性检查,缺失时安全跳过、保持游戏原行为。
 
 ## 拦截点:开始战局
 
-计划钩子点:`EFT.MainMenuShowOperation` / `EFT.UI.MenuScreen`。
-
-- 在主菜单开始战局的入口(`MainMenuShowOperation`)拦截:
-  当 `ShouldBlockStart(PluginConfig.Enabled.Value)` 为真时阻止流程继续。
-- 视图层(`EFT.UI.MenuScreen`)可用于展示“已被限制”提示;文案取自 `OneShotText.Get(...)`,按系统区域选择中/英文。
-
-> 具体钩子的目标签名需随 EFT 版本逆向确认;本骨架不实现钩子,只固定 `Patches/` 目录与纯逻辑接口。
+- **流程拦截**:`Patches/BlockStartPatch.cs` 以 `[HarmonyPrefix]` 挂钩 `EFT.MainMenuShowOperation.ShowScreen(EFT.UI.EMenuType screen, bool turnOn)`。当 `screen` 为 `Play`(0) 或 `Reconnect`(12) 且 `ShouldBlockStart(PluginConfig.Enabled.Value)` 为真时 `return false`,静默跳过整段界面切换;`Hideout`(11) 等其它界面一律放行,不弹窗。
+- **视图反馈**:`Patches/PlayButtonStatePatch.cs` 以 `[HarmonyPostfix]` 挂钩 `EFT.UI.MenuScreen.Show(Profile, MatchmakerPlayersController, ESessionMode)` 与 `MenuScreen.OnMatchingTypeUpdate`,在它们之后调用原生 `_playButton.SetDisabledTooltip(...)` 并置 `Interactable = false`:原生实现会把按钮 alpha 降到 0.3 且禁用点击,悬停显示提示。非限制态**不干预**按钮,交由游戏原生逻辑(如组队匹配禁用态)决定。
+- 文案取自 `OneShotText.Get(...)`,按 `LocalizationManager.Instance.Culture` 经 `LocaleSelector.Resolve` 选择中/英文。
 
 ## 复位
 
@@ -45,7 +40,7 @@
 
 # Design: Detection and Hook Points
 
-> This document records the detection point and interception hooks. The repository is currently a skeleton and the hooks are not implemented yet; implement against this document.
+> This document records the detection points and interception hooks as implemented.
 
 ## Approach
 
@@ -60,21 +55,16 @@ try to start raid   →  query (SessionGate.ShouldBlockStart)  →  block or all
 
 ## Detection: entering
 
-Planned hook: `EFT.GameWorld.OnGameStarted`.
-
-- Once `GameWorld` finishes starting, treat it as "a raid has been entered".
-- The hideout goes through the same `GameWorld` flow, so it is covered as well.
-- Setting the flag is idempotent: repeated entries keep it true.
+- **Combat raid**: `Patches/EnterRaidPatch.cs` hooks `EFT.GameWorld.OnGameStarted()` (`[HarmonyPostfix]`), which fires once when an offline/online raid finishes loading.
+- **Hideout**: `Patches/EnterHideoutPatch.cs` hooks `EFT.Hideout.HideoutController.HideoutAwake()`. The hideout does **not** go through `GameWorld.OnGameStarted`, so it must be hooked separately on `HideoutController` (do not confuse it with the nested `EFT.TarkovApplication.HideoutController`).
+- Both call `SessionGate.MarkEnteredScene()` on hit; setting is idempotent.
+- Each patch guards with `[HarmonyPrepare]` + `AccessTools.Method` and skips safely (keeping vanilla behavior) when the target method is missing.
 
 ## Interception: starting a raid
 
-Planned hooks: `EFT.MainMenuShowOperation` / `EFT.UI.MenuScreen`.
-
-- Intercept the raid-start entry on the main menu (`MainMenuShowOperation`):
-  when `ShouldBlockStart(PluginConfig.Enabled.Value)` is true, stop the flow.
-- The view layer (`EFT.UI.MenuScreen`) can show the "blocked" message; text comes from `OneShotText.Get(...)`, chosen by system locale.
-
-> Exact hook signatures must be verified against the EFT build; this skeleton does not implement hooks and only fixes the `Patches/` directory and the pure-logic interface.
+- **Flow interception**: `Patches/BlockStartPatch.cs` hooks `EFT.MainMenuShowOperation.ShowScreen(EFT.UI.EMenuType screen, bool turnOn)` via `[HarmonyPrefix]`. When `screen` is `Play` (0) or `Reconnect` (12) and `ShouldBlockStart(PluginConfig.Enabled.Value)` is true, it returns `false` to silently skip the whole screen-switch flow; `Hideout` (11) and other screens pass through with no popup.
+- **View feedback**: `Patches/PlayButtonStatePatch.cs` hooks `EFT.UI.MenuScreen.Show(Profile, MatchmakerPlayersController, ESessionMode)` and `MenuScreen.OnMatchingTypeUpdate` via `[HarmonyPostfix]`, then calls native `_playButton.SetDisabledTooltip(...)` and sets `Interactable = false`: the native implementation dims the button to alpha 0.3, disables clicks, and shows the tooltip on hover. When not blocked it leaves the button untouched so native logic (e.g. group-match disabling) decides.
+- Text comes from `OneShotText.Get(...)`, selected by `LocalizationManager.Instance.Culture` via `LocaleSelector.Resolve`.
 
 ## Reset