BlockStartPatch.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using EFT;
  2. using EFT.UI;
  3. using HarmonyLib;
  4. namespace OneShot.Patches
  5. {
  6. /// <summary>
  7. /// 拦截“开始战局/重连”:本次会话已进过场景时,静默跳过整段界面切换流程。
  8. /// Blocks starting a raid / reconnecting: silently skips the whole screen-switch flow
  9. /// once a scene has been entered this session.
  10. /// 提示 UI 由另一条 lane 负责,此处不弹窗。
  11. /// The notification UI is handled by another lane; no popup is shown here.
  12. /// </summary>
  13. [HarmonyPatch(typeof(MainMenuShowOperation), nameof(MainMenuShowOperation.ShowScreen))]
  14. internal static class BlockStartPatch
  15. {
  16. /// <summary>
  17. /// 目标方法存在性检查;缺失时安全降级为不挂钩,保持游戏原行为。
  18. /// Verifies the target method exists; degrades safely to no-op if it is missing.
  19. /// </summary>
  20. [HarmonyPrepare]
  21. private static bool Prepare()
  22. {
  23. return AccessTools.Method(
  24. typeof(MainMenuShowOperation),
  25. nameof(MainMenuShowOperation.ShowScreen),
  26. new[] { typeof(EMenuType), typeof(bool) }) != null;
  27. }
  28. /// <summary>
  29. /// 仅拦截 Play(开始战局)与 Reconnect(重连);绝不拦截 Hideout(藏身处)等其他界面。
  30. /// Only blocks Play (start raid) and Reconnect; never blocks Hideout or any other screen.
  31. /// </summary>
  32. [HarmonyPrefix]
  33. [HarmonyWrapSafe]
  34. private static bool Prefix(EMenuType screen)
  35. {
  36. // 白名单:只处理开始战局与重连,其余界面一律放行。
  37. // Allow-list: only handle starting a raid and reconnecting; pass everything else through.
  38. if (screen != EMenuType.Play && screen != EMenuType.Reconnect)
  39. {
  40. return true;
  41. }
  42. if (PluginConfig.Enabled == null || !PluginConfig.Enabled.Value)
  43. {
  44. return true;
  45. }
  46. if (OneShotPlugin.Gate == null || !OneShotPlugin.Gate.ShouldBlockStart(true))
  47. {
  48. return true;
  49. }
  50. Log.Info("已进过场景,本次会话禁止再开始战局 | A scene was already entered; starting another raid is blocked for this session.");
  51. return false;
  52. }
  53. }
  54. }