From 6125c5d1433f66bb7e1439f803aa4c77bc2ae8f1 Mon Sep 17 00:00:00 2001 From: Kinsi Date: Wed, 24 Feb 2021 02:52:33 +0100 Subject: [PATCH] Fix Camera being stuck in Void when you fail in MP --- HarmonyPatches/HookMultiplayer.cs | 13 +++++++++++++ Middlewares/ModmapExtensions.cs | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/HarmonyPatches/HookMultiplayer.cs b/HarmonyPatches/HookMultiplayer.cs index 2a75215..4f8ee52 100644 --- a/HarmonyPatches/HookMultiplayer.cs +++ b/HarmonyPatches/HookMultiplayer.cs @@ -1,5 +1,6 @@ using HarmonyLib; using Camera2.Managers; +using Camera2.Utils; namespace Camera2.HarmonyPatches { [HarmonyPatch(typeof(MultiplayerSessionManager), "UpdateConnectionState")] @@ -13,4 +14,16 @@ static void Postfix(MultiplayerSessionManager __instance) { ScenesManager.ActiveSceneChanged(); } } + + // When you die in MP the Origin of the normal camera ends up becoming inactive, thus modmap-parented + // cameras become inactive too and you get a black screen. + [HarmonyPatch(typeof(MultiplayerLocalActivePlayerGameplayManager), nameof(MultiplayerLocalActivePlayerGameplayManager.PerformPlayerFail))] + class HookMultiplayerFail { + static void Postfix() { +#if DEBUG + Plugin.Log.Info("MultiplayerLocalActivePlayerGameplayManager.PerformPlayerFail()"); +#endif + SceneUtil.OnSceneMaybeUnloadPre(); + } + } } diff --git a/Middlewares/ModmapExtensions.cs b/Middlewares/ModmapExtensions.cs index 71e5970..c7b1da0 100644 --- a/Middlewares/ModmapExtensions.cs +++ b/Middlewares/ModmapExtensions.cs @@ -2,6 +2,7 @@ using Camera2.Utils; using Camera2.Interfaces; using Camera2.Managers; +using Camera2.HarmonyPatches; namespace Camera2.Configuration { class Settings_ModmapExtensions : CameraSubSettings { @@ -21,7 +22,8 @@ class ModmapExtensions : CamMiddleware, IMHandler { (settings.ModmapExtensions.moveWithMap || settings.type == Configuration.CameraType.FirstPerson) && !SceneUtil.isInMenu && cam.settings.type != Configuration.CameraType.Attached && - SceneUtil.songWorldTransform != null + SceneUtil.songWorldTransform != null && + SceneUtil.songWorldTransform.gameObject.activeInHierarchy ) { // If we are not yet attached, and we dont have a parent thats active yet, try to get one! if(attachedTo != SceneUtil.songWorldTransform) { @@ -32,6 +34,9 @@ class ModmapExtensions : CamMiddleware, IMHandler { cam.SetParent(SceneUtil.songWorldTransform); } } else if(attachedTo != null) { +#if DEBUG + Plugin.Log.Info($"Disabling Modmap parenting for camera {cam.name}"); +#endif attachedTo = null; cam.SetParent(null); } @@ -47,6 +52,9 @@ public static void ForceDetachTracks() { if(cam.settings.type == Configuration.CameraType.Attached) continue; +#if DEBUG + Plugin.Log.Info($"Detaching Modmap parenting for camera {cam.name}"); +#endif cam.SetParent(null); } }