diff --git a/MiraAPI/ModCompatibility.cs b/MiraAPI/ModCompatibility.cs index 4163037..23744ab 100644 --- a/MiraAPI/ModCompatibility.cs +++ b/MiraAPI/ModCompatibility.cs @@ -1,4 +1,6 @@ -using BepInEx.Unity.IL2CPP; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using BepInEx.Unity.IL2CPP; namespace MiraAPI; @@ -13,7 +15,14 @@ public static class ModCompatibility public const string SubmergedId = "Submerged"; /// - /// Gets a value indicating whether the Submerged mod is loaded. + /// Checks if the Submerged mod is loaded. /// - public static bool SubmergedLoaded => IL2CPPChainloader.Instance.Plugins.TryGetValue(SubmergedId, out _); + /// Submerged mod assembly if loaded, null otherwise. + /// True if the Submerged mod is loaded, false otherwise. + public static bool SubmergedLoaded([NotNullWhen(true)] out Assembly? submergedAssembly) + { + var result = IL2CPPChainloader.Instance.Plugins.TryGetValue(SubmergedId, out var plugin); + submergedAssembly = result ? plugin?.Instance.GetType().Assembly : null; + return result; + } } diff --git a/MiraAPI/Patches/Events/SpawnInMinigamePatch.cs b/MiraAPI/Patches/Events/SpawnInMinigamePatch.cs new file mode 100644 index 0000000..b726999 --- /dev/null +++ b/MiraAPI/Patches/Events/SpawnInMinigamePatch.cs @@ -0,0 +1,15 @@ +using HarmonyLib; +using MiraAPI.Events; +using MiraAPI.Events.Vanilla.Gameplay; + +namespace MiraAPI.Patches.Events; + +[HarmonyPatch(typeof(SpawnInMinigame), nameof(SpawnInMinigame.Close))] +internal static class SpawnInMinigamePatch +{ + public static void Postfix() + { + var @event = new RoundStartEvent(false); + MiraEventManager.InvokeEvent(@event); + } +} diff --git a/MiraAPI/Patches/Events/SubmergedSpawnGamePatch.cs b/MiraAPI/Patches/Events/SubmergedSpawnGamePatch.cs new file mode 100644 index 0000000..d20c426 --- /dev/null +++ b/MiraAPI/Patches/Events/SubmergedSpawnGamePatch.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Reflection; +using HarmonyLib; +using MiraAPI.Events; +using MiraAPI.Events.Vanilla.Gameplay; + +namespace MiraAPI.Patches.Events; + +[HarmonyPatch] +internal static class SubmergedSpawnGamePatch +{ + public static IEnumerable TargetMethods() + { + if (ModCompatibility.SubmergedLoaded(out var subAss) && + subAss.GetType("Submerged.SpawnIn.SubmarineSelectSpawn") is { } selectSpawn) + { + yield return AccessTools.Method(selectSpawn, "OnDestroy"); + } + } + + public static void Postfix() + { + var @event = new RoundStartEvent(false); + MiraEventManager.InvokeEvent(@event); + } +} diff --git a/MiraAPI/Patches/Roles/EjectionPatches.cs b/MiraAPI/Patches/Roles/EjectionPatches.cs index ec1d123..74f0d26 100644 --- a/MiraAPI/Patches/Roles/EjectionPatches.cs +++ b/MiraAPI/Patches/Roles/EjectionPatches.cs @@ -12,7 +12,7 @@ namespace MiraAPI.Patches.Roles; /// Patches for custom ejection messages. /// [HarmonyPatch(typeof(ExileController))] -public static class EjectionPatches +internal static class EjectionPatches { [HarmonyPostfix] [HarmonyPatch(nameof(ExileController.Begin))] @@ -35,19 +35,9 @@ public static class EjectionPatches __instance.completeString = role.GetCustomEjectionMessage(__instance.initData.networkedPlayer); } - [HarmonyPatch] - internal static class WrapUpPatch + [HarmonyPatch(typeof(ExileController), nameof(ExileController.WrapUp))] + public static class WrapUpPatch { - public static IEnumerable TargetMethods() - { - yield return AccessTools.Method(typeof(ExileController), nameof(ExileController.WrapUp)); - yield return AccessTools.Method(typeof(AirshipExileController), nameof(AirshipExileController.WrapUpAndSpawn)); - if (ModCompatibility.SubmergedLoaded && AccessTools.TypeByName("Submerged.ExileCutscene.SubmergedExileController") is { } type) - { - yield return AccessTools.Method(type, "WrapUpAndSpawn"); - } - } - public static void Postfix() { var @event = new RoundStartEvent(false);