public static bool QuantumMoon_CheckPlayerFogProximity(QuantumMoon __instance) { var playerDistance = Vector3.Distance(__instance.transform.position, Locator.GetPlayerCamera().transform.position); var fogOffset = (__instance._stateIndex != 5) ? 0f : __instance._eyeStateFogOffset; var distanceFromFog = playerDistance - (__instance._fogRadius + fogOffset); var fogAlpha = 0f; if (!__instance._isPlayerInside) { fogAlpha = Mathf.InverseLerp(__instance._fogThickness + __instance._fogRolloffDistance, __instance._fogThickness, distanceFromFog); if (distanceFromFog < 0f) { if (__instance.IsLockedByProbeSnapshot() || QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)__instance._visibilityTracker, true).Item1) { __instance._isPlayerInside = true; __instance.SetSurfaceState(__instance._stateIndex); Locator.GetShipLogManager().RevealFact(__instance._revealFactID); GlobalMessenger.FireEvent(OWEvents.PlayerEnterQuantumMoon); } else { __instance.Collapse(true); } } } else if (__instance._isPlayerInside) { fogAlpha = Mathf.InverseLerp(-__instance._fogThickness - __instance._fogRolloffDistance, -__instance._fogThickness, distanceFromFog); if (distanceFromFog >= 0f) { if (__instance._stateIndex != 5) { __instance._isPlayerInside = false; if (!__instance.IsLockedByProbeSnapshot() && !QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)__instance._visibilityTracker, true).Item1) { __instance.Collapse(true); } __instance.SetSurfaceState(-1); GlobalMessenger.FireEvent(OWEvents.PlayerExitQuantumMoon); } else { var vector = Locator.GetPlayerTransform().position - __instance.transform.position; Locator.GetPlayerBody().SetVelocity(__instance._moonBody.GetPointVelocity(Locator.GetPlayerTransform().position) - (vector.normalized * 5f)); var d = 80f; Locator.GetPlayerBody().SetPosition(__instance.transform.position + (__instance._vortexReturnPivot.up * d)); if (!Physics.autoSyncTransforms) { Physics.SyncTransforms(); } var component = Locator.GetPlayerCamera().GetComponent <PlayerCameraController>(); component.SetDegreesY(component.GetMinDegreesY()); __instance._vortexAudio.SetLocalVolume(0f); __instance._collapseToIndex = 1; __instance.Collapse(true); } } } __instance._playerFogBubble.SetFogAlpha(fogAlpha); __instance._shipLandingCamFogBubble.SetFogAlpha(fogAlpha); return(false); }
// ShapeVisibilityTracker patches public static bool ShapeIsVisibleUsingCameraFrustum(ShapeVisibilityTracker __instance, ref bool __result) { __result = QuantumManager.IsVisibleUsingCameraFrustum(__instance, false); return(false); }
public static bool ChangeQuantumState(QuantumMoon __instance, bool skipInstantVisibilityCheck, out bool __result) { var foundNewPosition = false; var playersInQuantumMoon = QSBPlayerManager.PlayerList.Where(x => x.IsInMoon); var isVisibleOutput = QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)__instance._visibilityTracker, skipInstantVisibilityCheck); var shrineLit = QuantumManager.Shrine != null && QuantumManager.Shrine.IsPlayerInDarkness(); var playersInQuantumShrine = QSBPlayerManager.PlayerList.Where(x => x.IsInShrine); var playersWhoCanSeeQuantumMoon = isVisibleOutput.Item2; var playersNotInQuantumShrine = QSBPlayerManager.PlayerList.Where(x => !x.IsInShrine); // If any of the players in the moon are not in the shrine if (playersInQuantumMoon.Any(x => !x.IsInShrine)) { __result = false; return(false); } // If any of the players outside the shrine can see the moon if (playersNotInQuantumShrine.Any(playersWhoCanSeeQuantumMoon.Contains)) { __result = false; return(false); } // If there are players in the shrine and the shrine is not lit if (playersInQuantumShrine.Count() != 0 && !shrineLit) { __result = false; return(false); } var anyPlayerInQM = playersInQuantumMoon.Any(); if (anyPlayerInQM && __instance._hasSunCollapsed) { __result = false; return(false); } if (Time.time - __instance._playerWarpTime < 1f) { __result = false; return(false); } if (__instance._stateIndex == 5 && anyPlayerInQM && !__instance.IsPlayerEntangled()) { __result = false; return(false); } for (var i = 0; i < 10; i++) { FindStateAndOrbit(__instance, out var stateIndex, out var orbitIndex); GetTargetPosition(__instance, stateIndex, orbitIndex, out var orbitRadius, out var bodyToOrbit, out var targetPosition, out var onUnitSphere); if (!Physics.CheckSphere(targetPosition, __instance._sphereCheckRadius, OWLayerMask.physicalMask) || __instance._collapseToIndex != -1) { __instance._visibilityTracker.transform.position = targetPosition; if (!Physics.autoSyncTransforms) { Physics.SyncTransforms(); } if (skipInstantVisibilityCheck || anyPlayerInQM || !__instance.CheckVisibilityInstantly()) { MoveMoon(__instance, targetPosition, bodyToOrbit, stateIndex, onUnitSphere, ref foundNewPosition); break; } __instance._visibilityTracker.transform.localPosition = Vector3.zero; } else { Debug.LogError("Quantum moon orbit position occupied! Aborting collapse."); } } if (foundNewPosition) { DealWithNewPosition(__instance); __result = true; return(false); } __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 = 80f; Locator.GetPlayerBody().SetPosition(__instance.transform.position + (____vortexReturnPivot.up * d)); if (!Physics.autoSyncTransforms) { Physics.SyncTransforms(); } var component = Locator.GetPlayerCamera().GetComponent <PlayerCameraController>(); 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); }
public static bool Moon_ChangeQuantumState( QuantumMoon __instance, ref bool __result, bool skipInstantVisibilityCheck, bool ____isPlayerInside, bool ____hasSunCollapsed, float ____playerWarpTime, ref int ____stateIndex, ref int ____collapseToIndex, QuantumOrbit[] ____orbits, float ____sphereCheckRadius, VisibilityTracker ____visibilityTracker, OWRigidbody ____moonBody, ConstantForceDetector ____constantForceDetector, ref bool ____useInitialMotion, ref int ____lastStateIndex, ref int[] ____stateSkipCounts, AudioSignal ____quantumSignal, ReferenceFrameVolume ____referenceFrameVolume, GameObject[] ____deactivateAtEye ) { if (QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, skipInstantVisibilityCheck) && !QuantumManager.Instance.Shrine.IsPlayerInDarkness()) { if (!skipInstantVisibilityCheck) { var method = new StackTrace().GetFrame(3).GetMethod(); DebugLog.ToConsole($"Warning - Tried to change moon state while still observed. Called by {method.DeclaringType}.{method.Name}", MessageType.Warning); } __result = false; return(false); } var flag = false; if (____isPlayerInside && ____hasSunCollapsed) { __result = false; return(false); } if (Time.time - ____playerWarpTime < 1f) { __result = false; return(false); } if (____stateIndex == 5 && ____isPlayerInside && !__instance.IsPlayerEntangled()) { __result = false; return(false); } for (var i = 0; i < 10; i++) { var stateIndex = (____collapseToIndex == -1) ? (int)__instance.GetType().GetMethod("GetRandomStateIndex", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null) : ____collapseToIndex; var orbitIndex = -1; for (var j = 0; j < ____orbits.Length; j++) { if (____orbits[j].GetStateIndex() == stateIndex) { orbitIndex = j; break; } } if (orbitIndex == -1) { DebugLog.ToConsole($"Error - QM failed to find orbit for state {stateIndex}", MessageType.Error); } var orbitRadius = (orbitIndex == -1) ? 10000f : ____orbits[orbitIndex].GetOrbitRadius(); var owRigidbody = (orbitIndex == -1) ? Locator.GetAstroObject(AstroObject.Name.Sun).GetOWRigidbody() : ____orbits[orbitIndex].GetAttachedOWRigidbody(); var onUnitSphere = UnityEngine.Random.onUnitSphere; if (stateIndex == 5) { onUnitSphere.y = 0f; onUnitSphere.Normalize(); } var position = (onUnitSphere * orbitRadius) + owRigidbody.GetWorldCenterOfMass(); if (!Physics.CheckSphere(position, ____sphereCheckRadius, OWLayerMask.physicalMask) || ____collapseToIndex != -1) { ____visibilityTracker.transform.position = position; if (!Physics.autoSyncTransforms) { Physics.SyncTransforms(); } if (__instance.IsPlayerEntangled() || !QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, skipInstantVisibilityCheck)) { ____moonBody.transform.position = position; if (!Physics.autoSyncTransforms) { Physics.SyncTransforms(); } ____visibilityTracker.transform.localPosition = Vector3.zero; ____constantForceDetector.AddConstantVolume(owRigidbody.GetAttachedGravityVolume(), true, true); var velocity = owRigidbody.GetVelocity(); if (____useInitialMotion) { var initialMotion = owRigidbody.GetComponent <InitialMotion>(); velocity = (initialMotion == null) ? Vector3.zero : initialMotion.GetInitVelocity(); ____useInitialMotion = false; } var orbitAngle = UnityEngine.Random.Range(0, 360); ____moonBody.SetVelocity(OWPhysics.CalculateOrbitVelocity(owRigidbody, ____moonBody, orbitAngle) + velocity); ____lastStateIndex = ____stateIndex; ____stateIndex = stateIndex; ____collapseToIndex = -1; flag = true; for (var k = 0; k < ____stateSkipCounts.Length; k++) { ____stateSkipCounts[k] = (k != ____stateIndex) ? (____stateSkipCounts[k] + 1) : 0; } QSBEventManager.FireEvent(EventNames.QSBMoonStateChange, stateIndex, onUnitSphere, orbitAngle); break; } ____visibilityTracker.transform.localPosition = Vector3.zero; } else { DebugLog.ToConsole("Warning - Quantum moon orbit position occupied! Aborting collapse.", MessageType.Warning); } } if (flag) { if (____isPlayerInside) { __instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { ____stateIndex }); } else { __instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { -1 }); ____quantumSignal.SetSignalActivation(____stateIndex != 5, 2f); } ____referenceFrameVolume.gameObject.SetActive(____stateIndex != 5); ____moonBody.SetIsTargetable(____stateIndex != 5); for (var l = 0; l < ____deactivateAtEye.Length; l++) { ____deactivateAtEye[l].SetActive(____stateIndex != 5); } GlobalMessenger <OWRigidbody> .FireEvent("QuantumMoonChangeState", ____moonBody); __result = true; return(false); } __result = false; return(false); }