Pārlūkot izejas kodu

【新增】实现会话限制判定与开局拦截钩子

为编译 HideoutController 与 MainMenuShowOperation 的补丁,插件工程补充 Comfort.Unity 与 Sirenix.Serialization 程序集引用。
PJ568 1 mēnesi atpakaļ
vecāks
revīzija
1a6a0c2908

+ 10 - 0
src/OneShot.Plugin/OneShot.Plugin.csproj

@@ -34,6 +34,16 @@
       <HintPath>$(SPT_MANAGED)/Assembly-CSharp.dll</HintPath>
       <HintPath>$(SPT_MANAGED)/Assembly-CSharp.dll</HintPath>
       <Private>false</Private>
       <Private>false</Private>
     </Reference>
     </Reference>
+    <!-- HideoutController / MainMenuShowOperation 的基类所依赖的程序集 -->
+    <!-- Assemblies required by the base types of HideoutController / MainMenuShowOperation -->
+    <Reference Include="Comfort.Unity">
+      <HintPath>$(SPT_MANAGED)/Comfort.Unity.dll</HintPath>
+      <Private>false</Private>
+    </Reference>
+    <Reference Include="Sirenix.Serialization">
+      <HintPath>$(SPT_MANAGED)/Sirenix.Serialization.dll</HintPath>
+      <Private>false</Private>
+    </Reference>
     <Reference Include="UnityEngine">
     <Reference Include="UnityEngine">
       <HintPath>$(SPT_MANAGED)/UnityEngine.dll</HintPath>
       <HintPath>$(SPT_MANAGED)/UnityEngine.dll</HintPath>
       <Private>false</Private>
       <Private>false</Private>

+ 59 - 0
src/OneShot.Plugin/Patches/BlockStartPatch.cs

@@ -0,0 +1,59 @@
+using EFT;
+using EFT.UI;
+using HarmonyLib;
+
+namespace OneShot
+{
+    /// <summary>
+    /// 拦截“开始战局/重连”:本次会话已进过场景时,静默跳过整段界面切换流程。
+    /// Blocks starting a raid / reconnecting: silently skips the whole screen-switch flow
+    /// once a scene has been entered this session.
+    /// 提示 UI 由另一条 lane 负责,此处不弹窗。
+    /// The notification UI is handled by another lane; no popup is shown here.
+    /// </summary>
+    [HarmonyPatch(typeof(MainMenuShowOperation), nameof(MainMenuShowOperation.ShowScreen))]
+    internal static class BlockStartPatch
+    {
+        /// <summary>
+        /// 目标方法存在性检查;缺失时安全降级为不挂钩,保持游戏原行为。
+        /// Verifies the target method exists; degrades safely to no-op if it is missing.
+        /// </summary>
+        [HarmonyPrepare]
+        private static bool Prepare()
+        {
+            return AccessTools.Method(
+                typeof(MainMenuShowOperation),
+                nameof(MainMenuShowOperation.ShowScreen),
+                new[] { typeof(EMenuType), typeof(bool) }) != null;
+        }
+
+        /// <summary>
+        /// 仅拦截 Play(开始战局)与 Reconnect(重连);绝不拦截 Hideout(藏身处)等其他界面。
+        /// Only blocks Play (start raid) and Reconnect; never blocks Hideout or any other screen.
+        /// </summary>
+        [HarmonyPrefix]
+        [HarmonyWrapSafe]
+        private static bool Prefix(EMenuType screen)
+        {
+            // 白名单:只处理开始战局与重连,其余界面一律放行。
+            // Allow-list: only handle starting a raid and reconnecting; pass everything else through.
+            if (screen != EMenuType.Play && screen != EMenuType.Reconnect)
+            {
+                return true;
+            }
+
+            if (PluginConfig.Enabled == null || !PluginConfig.Enabled.Value)
+            {
+                return true;
+            }
+
+            if (OneShotPlugin.Gate == null || !OneShotPlugin.Gate.ShouldBlockStart(true))
+            {
+                return true;
+            }
+
+            Log.Info("已进过场景,本次会话禁止再开始战局 | A scene was already entered; starting another raid is blocked for this session.");
+            return false;
+        }
+    }
+}

+ 36 - 0
src/OneShot.Plugin/Patches/EnterHideoutPatch.cs

@@ -0,0 +1,36 @@
+using EFT.Hideout;
+using HarmonyLib;
+
+namespace OneShot
+{
+    /// <summary>
+    /// 判定“进入藏身处”:藏身处不会触发 <c>GameWorld.OnGameStarted</c>,故单独挂钩。
+    /// Detects entering the hideout: the hideout does not fire <c>GameWorld.OnGameStarted</c>, so it is hooked separately.
+    /// 注意目标为 <c>EFT.Hideout.HideoutController</c>,切勿与 <c>EFT.TarkovApplication.HideoutController</c> 混淆。
+    /// Note the target is <c>EFT.Hideout.HideoutController</c>; do not confuse it with the nested <c>EFT.TarkovApplication.HideoutController</c>.
+    /// </summary>
+    [HarmonyPatch(typeof(HideoutController), nameof(HideoutController.HideoutAwake))]
+    internal static class EnterHideoutPatch
+    {
+        /// <summary>
+        /// 目标方法存在性检查;缺失时安全降级为不挂钩,保持游戏原行为。
+        /// Verifies the target method exists; degrades safely to no-op if it is missing.
+        /// </summary>
+        [HarmonyPrepare]
+        private static bool Prepare()
+        {
+            return AccessTools.Method(typeof(HideoutController), nameof(HideoutController.HideoutAwake)) != null;
+        }
+
+        /// <summary>
+        /// 藏身处场景加载完成后标记本会话已进入过场景。
+        /// Marks this session as having entered a scene once the hideout scene finishes loading.
+        /// </summary>
+        [HarmonyPostfix]
+        [HarmonyWrapSafe]
+        private static void Postfix()
+        {
+            OneShotPlugin.Gate?.MarkEnteredScene();
+        }
+    }
+}

+ 34 - 0
src/OneShot.Plugin/Patches/EnterRaidPatch.cs

@@ -0,0 +1,34 @@
+using EFT;
+using HarmonyLib;
+
+namespace OneShot
+{
+    /// <summary>
+    /// 判定“进入战斗战局”:仅在离线/在线战局加载完成时触发一次。
+    /// Detects entering a combat raid: fires once when the offline/online raid finishes loading.
+    /// </summary>
+    [HarmonyPatch(typeof(GameWorld), nameof(GameWorld.OnGameStarted))]
+    internal static class EnterRaidPatch
+    {
+        /// <summary>
+        /// 目标方法存在性检查;缺失时安全降级为不挂钩,保持游戏原行为。
+        /// Verifies the target method exists; degrades safely to no-op if it is missing.
+        /// </summary>
+        [HarmonyPrepare]
+        private static bool Prepare()
+        {
+            return AccessTools.Method(typeof(GameWorld), nameof(GameWorld.OnGameStarted)) != null;
+        }
+
+        /// <summary>
+        /// 战局开始后标记本会话已进入过场景。
+        /// Marks this session as having entered a scene once the raid starts.
+        /// </summary>
+        [HarmonyPostfix]
+        [HarmonyWrapSafe]
+        private static void Postfix()
+        {
+            OneShotPlugin.Gate?.MarkEnteredScene();
+        }
+    }
+}