principle.md 3.8 KB

原理与钩子设计

本文记录判定点与拦截钩子的设计。当前仓库为骨架,钩子尚未实现;实现时以本文为准。

总体思路

限制是会话级的:只需在内存里记录“本次 SPT 运行是否已进入过场景”,并在“开始战局”的入口查询该标记。数据流如下:

进入战局/藏身处  →  置位标记 (SessionGate.MarkEnteredScene)
试图开始战局    →  查询 (SessionGate.ShouldBlockStart)  →  阻止或放行

OneShot.Core.SessionGate 为纯逻辑状态机,不依赖游戏程序集,因此可在公共 CI 上直接单测。

判定点:进入

计划钩子点:EFT.GameWorld.OnGameStarted。

  • 当 GameWorld 启动完成,即视为“已进入一次战局”。
  • 藏身处同样经由 GameWorld 流程,故一并覆盖。
  • 置位动作幂等:重复进入只保持标记为真。

拦截点:开始战局

计划钩子点:EFT.MainMenuShowOperation / EFT.UI.MenuScreen。

  • 在主菜单开始战局的入口(MainMenuShowOperation)拦截: 当 ShouldBlockStart(PluginConfig.Enabled.Value) 为真时阻止流程继续。
  • 视图层(EFT.UI.MenuScreen)可用于展示“已被限制”提示;文案取自 OneShotText.Get(...),按系统区域选择中/英文。

具体钩子的目标签名需随 EFT 版本逆向确认;本骨架不实现钩子,只固定 Patches/ 目录与纯逻辑接口。

复位

  • 手动:配置中的“重置已进局标记”触发 SessionGate.Reset()。
  • 自动:SPT 进程结束,内存标记随之消失,无需持久化。

界面说明

  • 配置界面由 BepInEx ConfigurationManager 提供(SPT 默认 F12)。
  • ResetRequested 为一次性操作项:勾选后由 PluginConfig 复位为 false 并触发事件,避免界面停留在“已勾选”。

===============================================================

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.

Approach

The restriction is session-scoped: keep an in-memory flag for "has a scene been entered this SPT run" and consult it at the raid-start entry. Data flow:

enter raid/hideout  →  set flag (SessionGate.MarkEnteredScene)
try to start raid   →  query (SessionGate.ShouldBlockStart)  →  block or allow

OneShot.Core.SessionGate is a pure-logic state machine with no game-assembly dependency, so it can be unit-tested on public CI.

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.

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.

Reset

  • Manual: the "Reset Entered Flag" config fires SessionGate.Reset().
  • Automatic: the in-memory flag disappears when the SPT process ends; no persistence.

UI notes

  • The config UI is provided by BepInEx ConfigurationManager (F12 by default in SPT).
  • ResetRequested is a one-shot action item: on check, PluginConfig resets it to false and raises the event so the UI does not stay on.