| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- // 具体 Harmony 钩子见 Patches/ 目录(另行实现)
- using BepInEx;
- using BepInEx.Configuration;
- using HarmonyLib;
- using OneShot.Core;
- namespace OneShot
- {
- /// <summary>
- /// 插件入口:初始化配置、日志与会话闸门。
- /// 进入过一次战局(含藏身处)后,本次 SPT 会话内禁止再开始战局。
- /// Plugin entry point: initializes config, logging and the session gate.
- /// Once a raid (or the hideout) has been entered, starting another raid is blocked for this SPT session.
- /// </summary>
- [BepInPlugin("com.pj568.oneshot", "OneShot", "0.1.0")]
- public class OneShotPlugin : BaseUnityPlugin
- {
- private const string HarmonyId = "com.pj568.oneshot";
- /// <summary>
- /// 会话级闸门,记录本次运行是否已进入过场景。
- /// The session-level gate recording whether a scene has been entered this run.
- /// </summary>
- public static SessionGate Gate { get; private set; } = new SessionGate();
- private Harmony _harmony;
- private void Awake()
- {
- Log.Init(Logger);
- PluginConfig.Init(Config);
- PluginConfig.ResetTriggered += OnResetTriggered;
- ApplyHarmonyPatches();
- Log.Info("OneShot 已加载 | loaded");
- }
- private void OnDestroy()
- {
- PluginConfig.ResetTriggered -= OnResetTriggered;
- if (_harmony == null)
- {
- return;
- }
- try
- {
- _harmony.UnpatchSelf();
- }
- catch (System.Exception e)
- {
- Log.Error("卸载 Harmony 补丁失败 | Failed to unpatch Harmony patches: " + e);
- }
- }
- /// <summary>
- /// 响应配置中的一次性重置请求,清除“已进过局”标记。
- /// Handles the one-shot reset request from config by clearing the "entered" flag.
- /// </summary>
- private void OnResetTriggered()
- {
- Gate?.Reset();
- }
- private void ApplyHarmonyPatches()
- {
- try
- {
- _harmony = new Harmony(HarmonyId);
- _harmony.PatchAll(typeof(OneShotPlugin).Assembly);
- }
- catch (System.Exception e)
- {
- Log.Error("应用 Harmony 补丁失败 | Failed to apply Harmony patches: " + e);
- }
- }
- }
- }
|