Skip to content

Commit

Permalink
Fix Camera being stuck in Void when you fail in MP
Browse files Browse the repository at this point in the history
  • Loading branch information
kinsi55 committed Feb 24, 2021
1 parent c0ead5c commit 6125c5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions HarmonyPatches/HookMultiplayer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HarmonyLib;
using Camera2.Managers;
using Camera2.Utils;

namespace Camera2.HarmonyPatches {
[HarmonyPatch(typeof(MultiplayerSessionManager), "UpdateConnectionState")]
Expand All @@ -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();
}
}
}
10 changes: 9 additions & 1 deletion Middlewares/ModmapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Camera2.Utils;
using Camera2.Interfaces;
using Camera2.Managers;
using Camera2.HarmonyPatches;

namespace Camera2.Configuration {
class Settings_ModmapExtensions : CameraSubSettings {
Expand All @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 6125c5d

Please sign in to comment.