From 934538d3cd221a5e0005d664a6b44094deeb95b5 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 16 Feb 2021 20:49:10 +0000 Subject: [PATCH] fix broken QM eye vortex warp --- QSB/QuantumSync/Patches/QuantumPatches.cs | 81 ++++++++++++++++ .../Patches/ServerQuantumPatches.cs | 95 +------------------ 2 files changed, 85 insertions(+), 91 deletions(-) diff --git a/QSB/QuantumSync/Patches/QuantumPatches.cs b/QSB/QuantumSync/Patches/QuantumPatches.cs index 995063da..8f9e25f7 100644 --- a/QSB/QuantumSync/Patches/QuantumPatches.cs +++ b/QSB/QuantumSync/Patches/QuantumPatches.cs @@ -7,6 +7,7 @@ using QSB.WorldSync; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using UnityEngine; namespace QSB.QuantumSync.Patches @@ -26,6 +27,7 @@ namespace QSB.QuantumSync.Patches QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(QuantumPatches), nameof(Shrine_ChangeQuantumState)); QSBCore.Helper.HarmonyHelper.AddPrefix("OnEntry", typeof(QuantumPatches), nameof(Shrine_OnEntry)); QSBCore.Helper.HarmonyHelper.AddPrefix("OnExit", typeof(QuantumPatches), nameof(Shrine_OnExit)); + QSBCore.Helper.HarmonyHelper.AddPrefix("CheckPlayerFogProximity", typeof(ServerQuantumPatches), nameof(Moon_CheckPlayerFogProximity)); } public override void DoUnpatches() @@ -39,6 +41,7 @@ namespace QSB.QuantumSync.Patches QSBCore.Helper.HarmonyHelper.Unpatch("ChangeQuantumState"); QSBCore.Helper.HarmonyHelper.Unpatch("OnEntry"); QSBCore.Helper.HarmonyHelper.Unpatch("OnExit"); + QSBCore.Helper.HarmonyHelper.Unpatch("CheckPlayerFogProximity"); } public static bool Socketed_ChangeQuantumState(SocketedQuantumObject __instance) @@ -204,5 +207,83 @@ namespace QSB.QuantumSync.Patches } return false; } + + public static bool Moon_CheckPlayerFogProximity( + QuantumMoon __instance, + int ____stateIndex, + float ____eyeStateFogOffset, + ref bool ____isPlayerInside, + float ____fogRadius, + float ____fogThickness, + float ____fogRolloffDistance, + string ____revealFactID, + OWRigidbody ____moonBody, + bool ____hasSunCollapsed, + Transform ____vortexReturnPivot, + OWAudioSource ____vortexAudio, + ref int ____collapseToIndex, + VisibilityTracker ____visibilityTracker, + QuantumFogEffectBubbleController ____playerFogBubble, + QuantumFogEffectBubbleController ____shipLandingCamFogBubble) + { + var playerDistance = Vector3.Distance(__instance.transform.position, Locator.GetPlayerCamera().transform.position); + var fogOffset = (____stateIndex != 5) ? 0f : ____eyeStateFogOffset; + var distanceFromFog = playerDistance - (____fogRadius + fogOffset); + var fogAlpha = 0f; + if (!____isPlayerInside) + { + fogAlpha = Mathf.InverseLerp(____fogThickness + ____fogRolloffDistance, ____fogThickness, distanceFromFog); + if (distanceFromFog < 0f) + { + if ((bool)__instance.GetType().GetMethod("IsLockedByProbeSnapshot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null) || QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, true)) + { + ____isPlayerInside = true; + __instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { ____stateIndex }); + Locator.GetShipLogManager().RevealFact(____revealFactID, true, true); + QSBEventManager.FireEvent("PlayerEnterQuantumMoon"); + } + else + { + __instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true }); + } + } + } + else if (____isPlayerInside) + { + fogAlpha = Mathf.InverseLerp(-____fogThickness - ____fogRolloffDistance, -____fogThickness, distanceFromFog); + if (distanceFromFog >= 0f) + { + if (____stateIndex != 5) + { + ____isPlayerInside = false; + if (!(bool)__instance.GetType().GetMethod("IsLockedByProbeSnapshot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null) && !QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, true)) + { + __instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true }); + } + __instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { -1 }); + QSBEventManager.FireEvent("PlayerExitQuantumMoon"); + } + else + { + var vector = Locator.GetPlayerTransform().position - __instance.transform.position; + Locator.GetPlayerBody().SetVelocity(____moonBody.GetPointVelocity(Locator.GetPlayerTransform().position) - (vector.normalized * 5f)); + var d = 80f; + Locator.GetPlayerBody().SetPosition(__instance.transform.position + (____vortexReturnPivot.up * d)); + if (!Physics.autoSyncTransforms) + { + Physics.SyncTransforms(); + } + var component = Locator.GetPlayerCamera().GetComponent(); + component.SetDegreesY(component.GetMinDegreesY()); + ____vortexAudio.SetLocalVolume(0f); + ____collapseToIndex = 1; + __instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true }); + } + } + } + ____playerFogBubble.SetFogAlpha(fogAlpha); + ____shipLandingCamFogBubble.SetFogAlpha(fogAlpha); + return false; + } } } diff --git a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs b/QSB/QuantumSync/Patches/ServerQuantumPatches.cs index 2301537b..ad8a37cc 100644 --- a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs +++ b/QSB/QuantumSync/Patches/ServerQuantumPatches.cs @@ -12,17 +12,11 @@ namespace QSB.QuantumSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnServerClientConnect; - public override void DoPatches() - { - QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ServerQuantumPatches), nameof(Moon_ChangeQuantumState)); - QSBCore.Helper.HarmonyHelper.AddPrefix("CheckPlayerFogProximity", typeof(ServerQuantumPatches), nameof(Moon_CheckPlayerFogProximity)); - } + public override void DoPatches() + => QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ServerQuantumPatches), nameof(Moon_ChangeQuantumState)); - public override void DoUnpatches() - { - QSBCore.Helper.HarmonyHelper.Unpatch("ChangeQuantumState"); - QSBCore.Helper.HarmonyHelper.Unpatch("CheckPlayerFogProximity"); - } + public override void DoUnpatches() + => QSBCore.Helper.HarmonyHelper.Unpatch("ChangeQuantumState"); public static bool Moon_ChangeQuantumState( QuantumMoon __instance, @@ -164,86 +158,5 @@ namespace QSB.QuantumSync.Patches __result = false; return false; } - - - - public static bool Moon_CheckPlayerFogProximity( - QuantumMoon __instance, - int ____stateIndex, - float ____eyeStateFogOffset, - ref bool ____isPlayerInside, - float ____fogRadius, - float ____fogThickness, - float ____fogRolloffDistance, - string ____revealFactID, - OWRigidbody ____moonBody, - bool ____hasSunCollapsed, - Transform ____vortexReturnPivot, - OWAudioSource ____vortexAudio, - ref int ____collapseToIndex, - VisibilityTracker ____visibilityTracker, - QuantumFogEffectBubbleController ____playerFogBubble, - QuantumFogEffectBubbleController ____shipLandingCamFogBubble) - { - var playerDistance = Vector3.Distance(__instance.transform.position, Locator.GetPlayerCamera().transform.position); - var fogOffset = (____stateIndex != 5) ? 0f : ____eyeStateFogOffset; - var distanceFromFog = playerDistance - (____fogRadius + fogOffset); - var fogAlpha = 0f; - if (!____isPlayerInside) - { - fogAlpha = Mathf.InverseLerp(____fogThickness + ____fogRolloffDistance, ____fogThickness, distanceFromFog); - if (distanceFromFog < 0f) - { - if ((bool)__instance.GetType().GetMethod("IsLockedByProbeSnapshot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null) || QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, true)) - { - ____isPlayerInside = true; - __instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { ____stateIndex }); - Locator.GetShipLogManager().RevealFact(____revealFactID, true, true); - QSBEventManager.FireEvent("PlayerEnterQuantumMoon"); - } - else - { - __instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true }); - } - } - } - else if (____isPlayerInside) - { - fogAlpha = Mathf.InverseLerp(-____fogThickness - ____fogRolloffDistance, -____fogThickness, distanceFromFog); - if (distanceFromFog >= 0f) - { - if (____stateIndex != 5) - { - ____isPlayerInside = false; - if (!(bool)__instance.GetType().GetMethod("IsLockedByProbeSnapshot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null) && !QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, true)) - { - __instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true }); - } - __instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { -1 }); - QSBEventManager.FireEvent("PlayerExitQuantumMoon"); - } - else - { - var vector = Locator.GetPlayerTransform().position - __instance.transform.position; - Locator.GetPlayerBody().SetVelocity(____moonBody.GetPointVelocity(Locator.GetPlayerTransform().position) - (vector.normalized * 5f)); - var d = (!____hasSunCollapsed) ? (____fogRadius - 1f) : 80f; - Locator.GetPlayerBody().SetPosition(__instance.transform.position + (____vortexReturnPivot.up * d)); - if (!Physics.autoSyncTransforms) - { - Physics.SyncTransforms(); - } - var component = Locator.GetPlayerCamera().GetComponent(); - component.SetDegreesY(component.GetMinDegreesY()); - ____vortexAudio.SetLocalVolume(0f); - ____collapseToIndex = 1; - // TODO : Handle players exiting eye state when other players are still on eye state, etc... - __instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true }); - } - } - } - ____playerFogBubble.SetFogAlpha(fogAlpha); - ____shipLandingCamFogBubble.SetFogAlpha(fogAlpha); - return false; - } } } \ No newline at end of file