From d948e25b144667e91bd6a2be162977f7a9890d58 Mon Sep 17 00:00:00 2001 From: Tlya <94857119+Tllya@users.noreply.github.com> Date: Wed, 18 Jan 2023 12:10:00 +0500 Subject: [PATCH 01/28] Update ru.json --- QSB/Translations/ru.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/QSB/Translations/ru.json b/QSB/Translations/ru.json index 51e5832ef..ea2971381 100644 --- a/QSB/Translations/ru.json +++ b/QSB/Translations/ru.json @@ -18,30 +18,30 @@ "Yes": "ДА", "No": "НЕТ", "StopHostingAreYouSure": "Вы уверены, что хотите прекратить хостинг?\nЭто отключит всех игроков от игры и отправит их в главное меню.", - "CopyProductUserIDToClipboard": "Начинаю хостинг.\nИгроки будут использовать ваш ID игрока :\n{0}\nЖелаете скопировать его в буфер обмена?", + "CopyProductUserIDToClipboard": "Начинаю хостинг.\nИгроки будут использовать ваш ID продукта :\n{0}\nЖелаете скопировать его в буфер обмена?", "Connecting": "ПОДКЛЮЧЕНИЕ...", "OK": "ЛАДНО", "ServerRefusedConnection": "Сервер отказал в подключении.\n{0}", "ClientDisconnectWithError": "Клиент отключён с ошибкой!\n{0}", "QSBVersionMismatch": "Версия QSB различается. (Клиент:{0}, Сервер:{1})", "OWVersionMismatch": "Версия Outer Wilds различается. (Клиент:{0}, Сервер:{1})", - "DLCMismatch": "Состояние DLC отличается. (Клиент:{0}, Сервер:{1})", + "DLCMismatch": "Состояние присутствия DLC отличается. (Клиент:{0}, Сервер:{1})", "GameProgressLimit": "Игра продолжалась слишком долго.", - "AddonMismatch": "Аддоны различаются. (Клиент:{0} аддонов, Сервер:{1} Аддонов)", - "IncompatibleMod": "Используется несовместимый/неразрешенный мод. Первый из них - {0}", + "AddonMismatch": "Аддоны различаются. (Клиент:{0} аддонов, Сервер:{1} аддонов)", + "IncompatibleMod": "Используется несовместимый(ые)/неразрешенный(ые) мод(ы). Первый из них - {0}", "PlayerJoinedTheGame": "{0} подключился!", "PlayerWasKicked": "{0} был отключён.", "KickedFromServer": "Отключён от сервера. Причина : {0}", "RespawnPlayer": "Возродить игрока", - "TimeSyncTooFarBehind": "{0}\nБыстрая перемотка, что-бы соответствовать времени сервера...", - "TimeSyncWaitingForStartOfServer": "Ожидаю запуск сервера...", - "TimeSyncTooFarAhead": "{0}\nПауза, что-бы соответствовать времени сервера...", - "TimeSyncWaitForAllToReady": "Ожидаю начало цикла...", - "TimeSyncWaitForAllToDie": "Ожидаю конец цикла...", - "GalaxyMapEveryoneNotPresent": "Ещё не время. Все должны быть здесь, что-бы начать.", + "TimeSyncTooFarBehind": "{0}\nБыстрая перемотка, чтобы соответствовать времени сервера...", + "TimeSyncWaitingForStartOfServer": "Ожидание запуска сервера...", + "TimeSyncTooFarAhead": "{0}\nПауза, чтобы соответствовать времени сервера...", + "TimeSyncWaitForAllToReady": "Ожидание начала цикла...", + "TimeSyncWaitForAllToDie": "Ожидание конца цикла...", + "GalaxyMapEveryoneNotPresent": "Ещё не время. Все должны быть здесь, чтобы начать.", "YouAreDead": "Вы погибли.", - "WaitingForRespawn": "Ожидаю, пока кто-нибудь возрадит вас...", - "WaitingForAllToDie": "Ждём пока {0} игрок(а)(ов) умрут...", + "WaitingForRespawn": "Ожидание, пока кто-нибудь возрадит вас...", + "WaitingForAllToDie": "Ожидание смерти {0} игрока(ов)...", "AttachToShip": "Зацепиться на корабль", "DetachFromShip": "Отцепиться от корабля", "DeathMessages": { From 34c8369e9119b2939c83b9843a8936e880025533 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 21 Jan 2023 10:48:54 +0000 Subject: [PATCH 02/28] add IsInShip to PlayerInfo --- QSB/Player/PlayerInfo.cs | 1 + QSB/ShipSync/ShipManager.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index c6a0fe420..7cb23a5c4 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -31,6 +31,7 @@ public partial class PlayerInfo public bool IsInMoon { get; set; } public bool IsInShrine { get; set; } public bool IsInEyeShuttle { get; set; } + public bool IsInShip { get; set; } public IQSBQuantumObject EntangledObject { get; set; } public QSBPlayerAudioController AudioController { get; set; } public bool IsLocalPlayer => TransformSync.isLocalPlayer; // if TransformSync is ever null, i give permission for nebula to make fun of me about it for the rest of time - johncorby diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index 405059c4c..9af8f4645 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -165,12 +165,14 @@ public override void UnbuildWorldObjects() public void AddPlayerToShip(PlayerInfo player) { + player.IsInShip = true; _playersInShip.Add(player); UpdateElectricalComponent(); } public void RemovePlayerFromShip(PlayerInfo player) { + player.IsInShip = false; _playersInShip.Remove(player); UpdateElectricalComponent(); } From 33a4bb042adf5a394df142725dd315ed3a6afdb3 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 21 Jan 2023 10:49:38 +0000 Subject: [PATCH 03/28] remove unused method --- QSB/ShipSync/ShipManager.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index 9af8f4645..8b9b36696 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -177,9 +177,6 @@ public void RemovePlayerFromShip(PlayerInfo player) UpdateElectricalComponent(); } - public bool IsPlayerInShip(PlayerInfo player) - => _playersInShip.Contains(player); - private void UpdateElectricalComponent() { var electricalSystem = ShipElectricalComponent._electricalSystem; From 52608963138b6c056b772b9ab41ccb9b84d10aed Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 21 Jan 2023 11:09:24 +0000 Subject: [PATCH 04/28] sync player camera fov fixes #578 --- .../Messages/PlayerInformationMessage.cs | 8 ++++++++ QSB/Player/Messages/UpdateFOVMessage.cs | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 QSB/Player/Messages/UpdateFOVMessage.cs diff --git a/QSB/Player/Messages/PlayerInformationMessage.cs b/QSB/Player/Messages/PlayerInformationMessage.cs index b54ab35f5..423135168 100644 --- a/QSB/Player/Messages/PlayerInformationMessage.cs +++ b/QSB/Player/Messages/PlayerInformationMessage.cs @@ -17,6 +17,7 @@ public class PlayerInformationMessage : QSBMessage private bool TranslatorEquipped; private bool ProbeActive; private ClientState ClientState; + private float FieldOfView; public PlayerInformationMessage() { @@ -30,6 +31,7 @@ public PlayerInformationMessage() TranslatorEquipped = player.TranslatorEquipped; ProbeActive = player.ProbeActive; ClientState = player.State; + FieldOfView = PlayerData.GetGraphicSettings().fieldOfView; } public override void Serialize(NetworkWriter writer) @@ -44,6 +46,7 @@ public override void Serialize(NetworkWriter writer) writer.Write(TranslatorEquipped); writer.Write(ProbeActive); writer.Write(ClientState); + writer.Write(FieldOfView); } public override void Deserialize(NetworkReader reader) @@ -58,6 +61,7 @@ public override void Deserialize(NetworkReader reader) TranslatorEquipped = reader.Read(); ProbeActive = reader.Read(); ClientState = reader.Read(); + FieldOfView = reader.ReadFloat(); } public override void OnReceiveRemote() @@ -79,6 +83,10 @@ public override void OnReceiveRemote() player.UpdateObjectsFromStates(); } + Delay.RunWhen( + () => player.Camera != null, + () => player.Camera.fieldOfView = FieldOfView); + player.State = ClientState; } else diff --git a/QSB/Player/Messages/UpdateFOVMessage.cs b/QSB/Player/Messages/UpdateFOVMessage.cs new file mode 100644 index 000000000..f92a37e61 --- /dev/null +++ b/QSB/Player/Messages/UpdateFOVMessage.cs @@ -0,0 +1,20 @@ +using QSB.Messaging; +using QSB.Utility; + +namespace QSB.Player.Messages; + +internal class UpdateFOVMessage : QSBMessage +{ + static UpdateFOVMessage() + => GlobalMessenger.AddListener( + "GraphicSettingsUpdated", + (GraphicSettings settings) => new UpdateFOVMessage(settings.fieldOfView).Send()); + + private UpdateFOVMessage(float fov) : base(fov) { } + + public override void OnReceiveRemote() + { + var player = QSBPlayerManager.GetPlayer(From); + player.Camera.fieldOfView = Data; + } +} From 9e1b7b5b9ff6b065e96ad915b54be37097843e2d Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 21 Jan 2023 12:08:57 +0000 Subject: [PATCH 05/28] remove some BUG comments they're covered by a IsHost check --- .../Ghosts/Patches/GhostPartyPathDirectorPatches.cs | 2 -- QSB/EchoesOfTheEye/Ghosts/Patches/GhostZone2DirectorPatches.cs | 1 - 2 files changed, 3 deletions(-) diff --git a/QSB/EchoesOfTheEye/Ghosts/Patches/GhostPartyPathDirectorPatches.cs b/QSB/EchoesOfTheEye/Ghosts/Patches/GhostPartyPathDirectorPatches.cs index 68491445b..648ad3a44 100644 --- a/QSB/EchoesOfTheEye/Ghosts/Patches/GhostPartyPathDirectorPatches.cs +++ b/QSB/EchoesOfTheEye/Ghosts/Patches/GhostPartyPathDirectorPatches.cs @@ -60,7 +60,6 @@ public static bool Update(GhostPartyPathDirector __instance) var ghostBrain = __instance._dispatchedGhosts[i].GetWorldObject(); if (ghostBrain.GetCurrentActionName() == GhostAction.Name.PartyPath) { - // BUG: breaks on client cuz cast var partyPathAction = (QSBPartyPathAction)ghostBrain.GetCurrentAction(); if (partyPathAction.hasReachedEndOfPath) { @@ -105,7 +104,6 @@ public static bool Update(GhostPartyPathDirector __instance) var num = Random.Range(0, __instance._ghostSpawns.Length); ghostBrain2.AttachedObject.transform.position = __instance._ghostSpawns[num].spawnTransform.position; ghostBrain2.AttachedObject.transform.eulerAngles = Vector3.up * __instance._ghostSpawns[num].spawnTransform.eulerAngles.y; - // BUG: breaks on client cuz cast ((QSBPartyPathAction)ghostBrain2.GetCurrentAction()).StartFollowPath(); __instance._ghostSpawns[num].spawnDoor.Open(); __instance._ghostSpawns[num].spawnDoorTimer = Time.timeSinceLevelLoad + 4f; diff --git a/QSB/EchoesOfTheEye/Ghosts/Patches/GhostZone2DirectorPatches.cs b/QSB/EchoesOfTheEye/Ghosts/Patches/GhostZone2DirectorPatches.cs index 0533be1b7..e4979a085 100644 --- a/QSB/EchoesOfTheEye/Ghosts/Patches/GhostZone2DirectorPatches.cs +++ b/QSB/EchoesOfTheEye/Ghosts/Patches/GhostZone2DirectorPatches.cs @@ -200,7 +200,6 @@ public static bool OnLightsExtinguished(GhostZone2Director __instance) DebugLog.DebugWrite($"- fade light down"); QSBGhostZone2Director.ElevatorsStatus[j].elevatorPair.elevator.topLight.FadeTo(0f, 0.2f); DebugLog.DebugWrite($"- get action"); - // BUG: breaks on client cuz cast QSBGhostZone2Director.ElevatorsStatus[j].elevatorAction = (QSBElevatorWalkAction)__instance._elevators[j].ghost.GetWorldObject().GetAction(GhostAction.Name.ElevatorWalk); DebugLog.DebugWrite($"- CallToUseElevator on action"); QSBGhostZone2Director.ElevatorsStatus[j].elevatorAction.CallToUseElevator(); From 7b69b649cb4db27b34dbb47f682de5b397a6d162 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 21 Jan 2023 12:50:37 +0000 Subject: [PATCH 06/28] split patches into own files --- .../ClientEyeProxyQuantumMoonPatches.cs | 15 + .../Client/ClientQuantumMoonPatches.cs | 20 + .../Patches/ClientQuantumPatches.cs | 25 - .../Common/MultiStateQuantumObjectPatches.cs | 68 +++ .../Patches/Common/QuantumMoonPatches.cs | 79 +++ .../Patches/Common/QuantumObjectPatches.cs | 48 ++ .../Patches/Common/QuantumShrinePatches.cs | 71 +++ .../Common/QuantumShuffleObjectPatches.cs | 57 ++ .../Common/QuantumSkeletonTowerPatches.cs | 59 +++ .../QuantumSocketCollapseTriggerPatches.cs | 14 + .../Patches/Common/QuantumStatePatches.cs | 50 ++ .../Common/SocketedQuantumObjectPatches.cs | 162 ++++++ ...ibilityRendererVisibilityTrackerPatches.cs | 24 + .../Visibility/VisibilityShapePatches.cs | 21 + ...VisibilityShapeVisibilityTrackerPatches.cs | 26 + .../VisibilityVisibilityObjectPatches.cs | 76 +++ QSB/QuantumSync/Patches/QuantumPatches.cs | 494 ------------------ .../Patches/QuantumVisibilityPatches.cs | 121 ----- .../ServerEyeProxyQuantumMoonPatches.cs | 50 ++ .../ServerQuantumMoonPatches.cs} | 52 +- 20 files changed, 844 insertions(+), 688 deletions(-) create mode 100644 QSB/QuantumSync/Patches/Client/ClientEyeProxyQuantumMoonPatches.cs create mode 100644 QSB/QuantumSync/Patches/Client/ClientQuantumMoonPatches.cs delete mode 100644 QSB/QuantumSync/Patches/ClientQuantumPatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/MultiStateQuantumObjectPatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/QuantumObjectPatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/QuantumShrinePatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/QuantumShuffleObjectPatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/QuantumSkeletonTowerPatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/QuantumSocketCollapseTriggerPatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/QuantumStatePatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/SocketedQuantumObjectPatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/Visibility/VisibilityRendererVisibilityTrackerPatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/Visibility/VisibilityShapePatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/Visibility/VisibilityShapeVisibilityTrackerPatches.cs create mode 100644 QSB/QuantumSync/Patches/Common/Visibility/VisibilityVisibilityObjectPatches.cs delete mode 100644 QSB/QuantumSync/Patches/QuantumPatches.cs delete mode 100644 QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs create mode 100644 QSB/QuantumSync/Patches/Server/ServerEyeProxyQuantumMoonPatches.cs rename QSB/QuantumSync/Patches/{ServerQuantumPatches.cs => Server/ServerQuantumMoonPatches.cs} (81%) diff --git a/QSB/QuantumSync/Patches/Client/ClientEyeProxyQuantumMoonPatches.cs b/QSB/QuantumSync/Patches/Client/ClientEyeProxyQuantumMoonPatches.cs new file mode 100644 index 000000000..7e35d09ce --- /dev/null +++ b/QSB/QuantumSync/Patches/Client/ClientEyeProxyQuantumMoonPatches.cs @@ -0,0 +1,15 @@ +using HarmonyLib; +using QSB.Patches; + +namespace QSB.QuantumSync.Patches.Client; + +[HarmonyPatch(typeof(EyeProxyQuantumMoon))] +internal class ClientEyeProxyQuantumMoonPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnNonServerClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(EyeProxyQuantumMoon.ChangeQuantumState))] + public static bool ChangeQuantumState() + => false; +} diff --git a/QSB/QuantumSync/Patches/Client/ClientQuantumMoonPatches.cs b/QSB/QuantumSync/Patches/Client/ClientQuantumMoonPatches.cs new file mode 100644 index 000000000..61fdecd8e --- /dev/null +++ b/QSB/QuantumSync/Patches/Client/ClientQuantumMoonPatches.cs @@ -0,0 +1,20 @@ +using HarmonyLib; +using QSB.Patches; + +namespace QSB.QuantumSync.Patches.Client; + +[HarmonyPatch(typeof(QuantumMoon))] +internal class ClientQuantumMoonPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnNonServerClientConnect; + + [HarmonyPostfix] + [HarmonyPatch(nameof(QuantumMoon.Start))] + public static void Start(QuantumMoon __instance) + => __instance.SetSurfaceState(-1); + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumMoon.ChangeQuantumState))] + public static bool ChangeQuantumState() + => false; +} diff --git a/QSB/QuantumSync/Patches/ClientQuantumPatches.cs b/QSB/QuantumSync/Patches/ClientQuantumPatches.cs deleted file mode 100644 index d102ae854..000000000 --- a/QSB/QuantumSync/Patches/ClientQuantumPatches.cs +++ /dev/null @@ -1,25 +0,0 @@ -using HarmonyLib; -using QSB.Patches; - -namespace QSB.QuantumSync.Patches; - -[HarmonyPatch] -public class ClientQuantumPatches : QSBPatch -{ - public override QSBPatchTypes Type => QSBPatchTypes.OnNonServerClientConnect; - - [HarmonyPostfix] - [HarmonyPatch(typeof(QuantumMoon), nameof(QuantumMoon.Start))] - public static void QuantumMoon_Start(QuantumMoon __instance) - => __instance.SetSurfaceState(-1); - - [HarmonyPrefix] - [HarmonyPatch(typeof(QuantumMoon), nameof(QuantumMoon.ChangeQuantumState))] - public static bool QuantumMoon_ChangeQuantumState() - => false; - - [HarmonyPrefix] - [HarmonyPatch(typeof(EyeProxyQuantumMoon), nameof(EyeProxyQuantumMoon.ChangeQuantumState))] - public static bool EyeProxyQuantumMoon_ChangeQuantumState() - => false; -} \ No newline at end of file diff --git a/QSB/QuantumSync/Patches/Common/MultiStateQuantumObjectPatches.cs b/QSB/QuantumSync/Patches/Common/MultiStateQuantumObjectPatches.cs new file mode 100644 index 000000000..689c627d2 --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/MultiStateQuantumObjectPatches.cs @@ -0,0 +1,68 @@ +using HarmonyLib; +using QSB.Patches; +using QSB.Player; +using QSB.QuantumSync.WorldObjects; +using QSB.WorldSync; + +namespace QSB.QuantumSync.Patches.Common; + +[HarmonyPatch(typeof(MultiStateQuantumObject))] +public class MultiStateQuantumObjectPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(MultiStateQuantumObject.Start))] + public static bool Start(MultiStateQuantumObject __instance) + { + if (!QSBWorldSync.AllObjectsReady) + { + return true; + } + + var qsbObj = __instance.GetWorldObject(); + if (qsbObj.ControllingPlayer == 0) + { + return true; + } + + foreach (var state in qsbObj.QuantumStates) + { + if (!state.IsMeantToBeEnabled) + { + state.SetVisible(false); + } + } + + if (__instance._sector == null) + { + __instance.CheckEnabled(); + } + + if (__instance._collapseOnStart) + { + __instance.Collapse(true); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(MultiStateQuantumObject.ChangeQuantumState))] + public static bool ChangeQuantumState(MultiStateQuantumObject __instance) + { + if (!QSBWorldSync.AllObjectsReady) + { + return true; + } + + var qsbObj = __instance.GetWorldObject(); + if (qsbObj.ControllingPlayer == 0 && qsbObj.CurrentState == -1) + { + return true; + } + + var isInControl = qsbObj.ControllingPlayer == QSBPlayerManager.LocalPlayerId; + return isInControl; + } +} diff --git a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs new file mode 100644 index 000000000..7ed46a83e --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs @@ -0,0 +1,79 @@ +using HarmonyLib; +using QSB.Messaging; +using QSB.Patches; +using UnityEngine; + +namespace QSB.QuantumSync.Patches.Common; + +[HarmonyPatch(typeof(QuantumMoon))] +internal class QuantumMoonPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumMoon.CheckPlayerFogProximity))] + public static bool 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).FoundPlayers) + { + __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).FoundPlayers) + { + __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(); + component.SetDegreesY(component.GetMinDegreesY()); + __instance._vortexAudio.SetLocalVolume(0f); + __instance._collapseToIndex = 1; + __instance.Collapse(true); + } + } + } + + __instance._playerFogBubble.SetFogAlpha(fogAlpha); + __instance._shipLandingCamFogBubble.SetFogAlpha(fogAlpha); + return false; + } +} diff --git a/QSB/QuantumSync/Patches/Common/QuantumObjectPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumObjectPatches.cs new file mode 100644 index 000000000..37c57dcff --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/QuantumObjectPatches.cs @@ -0,0 +1,48 @@ +using HarmonyLib; +using QSB.Messaging; +using QSB.Patches; +using QSB.QuantumSync.Messages; +using QSB.QuantumSync.WorldObjects; +using QSB.WorldSync; +using System.Linq; + +namespace QSB.QuantumSync.Patches.Common; + +[HarmonyPatch(typeof(QuantumObject))] +public class QuantumObjectPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumObject.IsLockedByPlayerContact))] + public static bool IsLockedByPlayerContact(out bool __result, QuantumObject __instance) + { + var playersEntangled = QuantumManager.GetEntangledPlayers(__instance); + __result = playersEntangled.Count() != 0 && __instance.IsIlluminated(); + return false; + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(QuantumObject.SetIsQuantum))] + public static void SetIsQuantum(QuantumObject __instance) + { + if (QSBWorldSync.AllObjectsReady) + { + __instance.GetWorldObject().SendMessage(new SetIsQuantumMessage(__instance.IsQuantum())); + } + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumObject.OnProbeSnapshot))] + public static bool OnProbeSnapshot() + { + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumObject.OnProbeSnapshotRemoved))] + public static bool OnProbeSnapshotRemoved() + { + return false; + } +} diff --git a/QSB/QuantumSync/Patches/Common/QuantumShrinePatches.cs b/QSB/QuantumSync/Patches/Common/QuantumShrinePatches.cs new file mode 100644 index 000000000..be81dc957 --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/QuantumShrinePatches.cs @@ -0,0 +1,71 @@ +using HarmonyLib; +using QSB.Patches; +using QSB.Player; +using QSB.QuantumSync.WorldObjects; +using QSB.WorldSync; +using System.Linq; + +namespace QSB.QuantumSync.Patches.Common; + +[HarmonyPatch(typeof(QuantumShrine))] +public class QuantumShrinePatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumShrine.IsPlayerInDarkness))] + public static bool IsPlayerInDarkness(QuantumShrine __instance, out bool __result) + { + foreach (var lamp in __instance._lamps) + { + if (lamp.intensity > 0f) + { + __result = false; + return false; + } + } + + var playersInMoon = QSBPlayerManager.PlayerList.Where(x => x.IsInMoon).ToList(); + + if (playersInMoon.Any(player => !player.IsInShrine)) + { + __result = false; + return false; + } + + if (playersInMoon.Any(player => player.FlashLight != null && player.FlashLight.FlashlightOn)) + { + __result = false; + return false; + } + + if (playersInMoon.Count == 0) + { + __result = false; + return false; + } + + if (QSBPlayerManager.LocalPlayer != null + && QSBPlayerManager.LocalPlayer.IsInShrine + && PlayerState.IsFlashlightOn()) + { + __result = false; + return false; + } + + // BUG : make this *really* check for all players - check other probes and other jetpacks! + __result = __instance._gate.GetOpenFraction() == 0f + && !__instance._isProbeInside + && Locator.GetThrusterLightTracker().GetLightRange() <= 0f; + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumShrine.ChangeQuantumState))] + public static bool ChangeQuantumState(QuantumShrine __instance) + { + var shrineWorldObject = __instance.GetWorldObject(); + var isInControl = shrineWorldObject.ControllingPlayer == QSBPlayerManager.LocalPlayerId; + return isInControl; + } +} diff --git a/QSB/QuantumSync/Patches/Common/QuantumShuffleObjectPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumShuffleObjectPatches.cs new file mode 100644 index 000000000..54546d07c --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/QuantumShuffleObjectPatches.cs @@ -0,0 +1,57 @@ +using HarmonyLib; +using QSB.Messaging; +using QSB.Patches; +using QSB.Player; +using QSB.QuantumSync.Messages; +using QSB.QuantumSync.WorldObjects; +using QSB.WorldSync; +using System.Linq; +using UnityEngine; + +namespace QSB.QuantumSync.Patches.Common; + +[HarmonyPatch(typeof(QuantumShuffleObject))] +internal class QuantumShuffleObjectPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumShuffleObject.ChangeQuantumState))] + public static bool ChangeQuantumState( + QuantumShuffleObject __instance, + ref bool __result) + { + QSBQuantumShuffleObject shuffleWorldObject = default; + if (QSBWorldSync.AllObjectsReady) + { + shuffleWorldObject = __instance.GetWorldObject(); + if (shuffleWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId) + { + return false; + } + } + + __instance._indexList.Clear(); + __instance._indexList = Enumerable.Range(0, __instance._localPositions.Length).ToList(); + for (var i = 0; i < __instance._indexList.Count; ++i) + { + var random = Random.Range(i, __instance._indexList.Count); + var temp = __instance._indexList[i]; + __instance._indexList[i] = __instance._indexList[random]; + __instance._indexList[random] = temp; + } + + for (var j = 0; j < __instance._shuffledObjects.Length; j++) + { + __instance._shuffledObjects[j].localPosition = __instance._localPositions[__instance._indexList[j]]; + } + + if (QSBWorldSync.AllObjectsReady) + { + shuffleWorldObject.SendMessage(new QuantumShuffleMessage(__instance._indexList.ToArray())); + __result = true; + } + + return false; + } +} diff --git a/QSB/QuantumSync/Patches/Common/QuantumSkeletonTowerPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumSkeletonTowerPatches.cs new file mode 100644 index 000000000..4c8d33010 --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/QuantumSkeletonTowerPatches.cs @@ -0,0 +1,59 @@ +using HarmonyLib; +using QSB.Messaging; +using QSB.Patches; +using QSB.Player; +using QSB.QuantumSync.Messages; +using QSB.QuantumSync.WorldObjects; +using QSB.WorldSync; + +namespace QSB.QuantumSync.Patches.Common; + +[HarmonyPatch(typeof(QuantumSkeletonTower))] +internal class QuantumSkeletonTowerPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumSkeletonTower.ChangeQuantumState))] + public static bool ChangeQuantumState(QuantumSkeletonTower __instance, ref bool __result) + { + if (!QSBWorldSync.AllObjectsReady) + { + return true; + } + + var qsbQuantumSkeletonTower = __instance.GetWorldObject(); + if (qsbQuantumSkeletonTower.ControllingPlayer != QSBPlayerManager.LocalPlayerId) + { + return false; + } + + if (__instance._waitForPlayerToLookAtTower) + { + __result = false; + return false; + } + + if (__instance._index < __instance._towerSkeletons.Length) + { + for (var i = 0; i < __instance._pointingSkeletons.Length; i++) + { + if (__instance._pointingSkeletons[i].gameObject.activeInHierarchy && + (!__instance._pointingSkeletons[i].IsVisible() || !__instance._pointingSkeletons[i].IsIlluminated())) + { + __instance._pointingSkeletons[i].gameObject.SetActive(false); + + __instance._towerSkeletons[__instance._index].SetActive(true); + __instance._index++; + __instance._waitForPlayerToLookAtTower = true; + qsbQuantumSkeletonTower.SendMessage(new MoveSkeletonMessage(i)); + __result = true; + return false; + } + } + } + + __result = false; + return false; + } +} diff --git a/QSB/QuantumSync/Patches/Common/QuantumSocketCollapseTriggerPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumSocketCollapseTriggerPatches.cs new file mode 100644 index 000000000..2745cb698 --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/QuantumSocketCollapseTriggerPatches.cs @@ -0,0 +1,14 @@ +using HarmonyLib; +using QSB.Patches; + +namespace QSB.QuantumSync.Patches.Common; + +[HarmonyPatch(typeof(QuantumSocketCollapseTrigger))] +internal class QuantumSocketCollapseTriggerPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumSocketCollapseTrigger.OnTriggerEnter))] + public static bool OnTriggerEnter() => false; +} diff --git a/QSB/QuantumSync/Patches/Common/QuantumStatePatches.cs b/QSB/QuantumSync/Patches/Common/QuantumStatePatches.cs new file mode 100644 index 000000000..99e5c82a6 --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/QuantumStatePatches.cs @@ -0,0 +1,50 @@ +using HarmonyLib; +using OWML.Common; +using QSB.Messaging; +using QSB.Patches; +using QSB.Player; +using QSB.QuantumSync.Messages; +using QSB.QuantumSync.WorldObjects; +using QSB.Utility; +using QSB.WorldSync; +using System.Linq; + +namespace QSB.QuantumSync.Patches.Common; + +[HarmonyPatch(typeof(QuantumState))] +public class QuantumStatePatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPostfix] + [HarmonyPatch(nameof(QuantumState.SetVisible))] + public static void SetVisible(QuantumState __instance, bool visible) + { + if (!QSBWorldSync.AllObjectsReady) + { + return; + } + + if (!visible) + { + return; + } + + var allMultiStates = QSBWorldSync.GetWorldObjects(); + var stateObject = __instance.GetWorldObject(); + var owner = allMultiStates.FirstOrDefault(x => x.QuantumStates.Contains(stateObject)); + if (owner == default) + { + DebugLog.ToConsole($"Error - Could not find QSBMultiStateQuantumObject for state {__instance.name}", MessageType.Error); + return; + } + + if (owner.ControllingPlayer != QSBPlayerManager.LocalPlayerId) + { + return; + } + + var stateIndex = owner.QuantumStates.IndexOf(stateObject); + owner.SendMessage(new MultiStateChangeMessage(stateIndex)); + } +} diff --git a/QSB/QuantumSync/Patches/Common/SocketedQuantumObjectPatches.cs b/QSB/QuantumSync/Patches/Common/SocketedQuantumObjectPatches.cs new file mode 100644 index 000000000..687d9afc0 --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/SocketedQuantumObjectPatches.cs @@ -0,0 +1,162 @@ +using HarmonyLib; +using OWML.Common; +using QSB.Messaging; +using QSB.Patches; +using QSB.Player; +using QSB.QuantumSync.Messages; +using QSB.QuantumSync.WorldObjects; +using QSB.Utility; +using QSB.WorldSync; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace QSB.QuantumSync.Patches.Common; + +[HarmonyPatch(typeof(SocketedQuantumObject))] +public class SocketedQuantumObjectPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(SocketedQuantumObject.ChangeQuantumState))] + public static bool ChangeQuantumState( + SocketedQuantumObject __instance, + ref bool __result, + bool skipInstantVisibilityCheck) + { + if (QSBWorldSync.AllObjectsReady) + { + var socketedWorldObject = __instance.GetWorldObject(); + if (socketedWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId) + { + return false; + } + } + + foreach (var socket in __instance._childSockets) + { + if (socket.IsOccupied()) + { + __result = false; + return false; + } + } + + if (__instance._socketList.Count <= 1) + { + DebugLog.ToConsole($"Error - Not enough quantum sockets in list for {__instance.name}!", MessageType.Error); + __result = false; + return false; + } + + var list = new List(); + foreach (var socket in __instance._socketList) + { + if (!socket.IsOccupied() && socket.IsActive()) + { + list.Add(socket); + } + } + + if (list.Count == 0) + { + __result = false; + return false; + } + + if (__instance._recentlyObscuredSocket != null) + { + __instance.MoveToSocket(__instance._recentlyObscuredSocket); + __instance._recentlyObscuredSocket = null; + __result = true; + return false; + } + + var occupiedSocket = __instance._occupiedSocket; + for (var i = 0; i < 20; i++) + { + var index = Random.Range(0, list.Count); + __instance.MoveToSocket(list[index]); + if (skipInstantVisibilityCheck) + { + __result = true; + return false; + } + + bool socketNotSuitable; + var isSocketIlluminated = __instance.CheckIllumination(); + + var playersEntangled = QuantumManager.GetEntangledPlayers(__instance); + if (playersEntangled.Count() != 0) + { + // socket not suitable if illuminated + socketNotSuitable = isSocketIlluminated; + } + else + { + var checkVisInstant = __instance.CheckVisibilityInstantly(); + if (isSocketIlluminated) + { + // socket not suitable if object is visible + socketNotSuitable = checkVisInstant; + } + else + { + // socket not suitable if player is inside object + socketNotSuitable = playersEntangled.Any(x => __instance.CheckPointInside(x.CameraBody.transform.position)); + } + } + + if (!socketNotSuitable) + { + __result = true; + return false; + } + + list.RemoveAt(index); + if (list.Count == 0) + { + break; + } + } + + __instance.MoveToSocket(occupiedSocket); + __result = false; + return false; + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(SocketedQuantumObject.MoveToSocket))] + public static void MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket) + { + if (!QSBWorldSync.AllObjectsReady) + { + return; + } + + if (socket == null) + { + DebugLog.ToConsole($"Error - Trying to move {__instance.name} to a null socket!", MessageType.Error); + return; + } + + var objectWorldObject = __instance.GetWorldObject(); + var socketWorldObject = socket.GetWorldObject(); + + if (objectWorldObject == null) + { + DebugLog.ToConsole($"Worldobject is null for {__instance.name}!"); + return; + } + + if (objectWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId) + { + return; + } + + objectWorldObject.SendMessage(new SocketStateChangeMessage( + socketWorldObject.ObjectId, + __instance.transform.localRotation)); + } +} diff --git a/QSB/QuantumSync/Patches/Common/Visibility/VisibilityRendererVisibilityTrackerPatches.cs b/QSB/QuantumSync/Patches/Common/Visibility/VisibilityRendererVisibilityTrackerPatches.cs new file mode 100644 index 000000000..334f8879d --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/Visibility/VisibilityRendererVisibilityTrackerPatches.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using QSB.Patches; +using QSB.Player; +using System.Linq; +using UnityEngine; + +namespace QSB.QuantumSync.Patches.Common.Visibility; + +[HarmonyPatch(typeof(RendererVisibilityTracker))] +internal class VisibilityRendererVisibilityTrackerPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(RendererVisibilityTracker), nameof(RendererVisibilityTracker.IsVisibleUsingCameraFrustum))] + public static bool RendererVisibilityTracker_IsVisibleUsingCameraFrustum(RendererVisibilityTracker __instance, out bool __result) + { + __result = QSBPlayerManager.GetPlayersWithCameras() + .Any(x => GeometryUtility.TestPlanesAABB(x.Camera.GetFrustumPlanes(), __instance._renderer.bounds)) + && (!__instance._checkFrustumOcclusion || QSBPlayerManager.GetPlayersWithCameras() + .Any(x => !__instance.IsOccludedFromPosition(x.Camera.transform.position))); + return false; + } +} diff --git a/QSB/QuantumSync/Patches/Common/Visibility/VisibilityShapePatches.cs b/QSB/QuantumSync/Patches/Common/Visibility/VisibilityShapePatches.cs new file mode 100644 index 000000000..64015bf01 --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/Visibility/VisibilityShapePatches.cs @@ -0,0 +1,21 @@ +using HarmonyLib; +using QSB.Patches; +using QSB.Utility; + +namespace QSB.QuantumSync.Patches.Common.Visibility; + +[HarmonyPatch(typeof(Shape))] +internal class VisibilityShapePatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPostfix] + [HarmonyPatch(nameof(Shape.OnEnable))] + public static void OnEnable(Shape __instance) + => __instance.RaiseEvent(nameof(__instance.OnShapeActivated), __instance); + + [HarmonyPostfix] + [HarmonyPatch(nameof(Shape.OnDisable))] + public static void OnDisable(Shape __instance) + => __instance.RaiseEvent(nameof(__instance.OnShapeDeactivated), __instance); +} diff --git a/QSB/QuantumSync/Patches/Common/Visibility/VisibilityShapeVisibilityTrackerPatches.cs b/QSB/QuantumSync/Patches/Common/Visibility/VisibilityShapeVisibilityTrackerPatches.cs new file mode 100644 index 000000000..9e101fb3f --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/Visibility/VisibilityShapeVisibilityTrackerPatches.cs @@ -0,0 +1,26 @@ +using HarmonyLib; +using QSB.Patches; + +namespace QSB.QuantumSync.Patches.Common.Visibility; + +[HarmonyPatch(typeof(ShapeVisibilityTracker))] +internal class VisibilityShapeVisibilityTrackerPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(ShapeVisibilityTracker.IsVisibleUsingCameraFrustum))] + public static bool IsVisibleUsingCameraFrustum(ShapeVisibilityTracker __instance, out bool __result) + { + __result = QuantumManager.IsVisibleUsingCameraFrustum(__instance, false).FoundPlayers; + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ShapeVisibilityTracker.IsVisible))] + public static bool IsVisible(ShapeVisibilityTracker __instance, out bool __result) + { + __result = QuantumManager.IsVisible(__instance, false); + return false; + } +} diff --git a/QSB/QuantumSync/Patches/Common/Visibility/VisibilityVisibilityObjectPatches.cs b/QSB/QuantumSync/Patches/Common/Visibility/VisibilityVisibilityObjectPatches.cs new file mode 100644 index 000000000..b69230641 --- /dev/null +++ b/QSB/QuantumSync/Patches/Common/Visibility/VisibilityVisibilityObjectPatches.cs @@ -0,0 +1,76 @@ +using HarmonyLib; +using QSB.Patches; +using QSB.Player; +using System.Linq; + +namespace QSB.QuantumSync.Patches.Common.Visibility; + +[HarmonyPatch(typeof(VisibilityObject))] +internal class VisibilityObjectPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(VisibilityObject.CheckIllumination))] + public static bool CheckIllumination(VisibilityObject __instance, out bool __result) + { + if (!__instance._checkIllumination) + { + __result = true; + return false; + } + + var point = __instance.transform.TransformPoint(__instance._localIlluminationOffset); + var (localFlashlight, playerFlashlights) = QSBPlayerManager.GetPlayerFlashlights(); + + if (localFlashlight.CheckIlluminationAtPoint(point, __instance._illuminationRadius)) + { + __result = true; + return false; + } + + if (playerFlashlights.Any(x => x.CheckIlluminationAtPoint(point, __instance._illuminationRadius))) + { + __result = true; + return false; + } + + var (localProbe, playerProbes) = QSBPlayerManager.GetPlayerProbes(); + + if (localProbe != null + && localProbe.IsLaunched() + && localProbe.CheckIlluminationAtPoint(point, __instance._illuminationRadius)) + { + __result = true; + return false; + } + + if (playerProbes.Any(x => x.IsLaunched() && x.CheckIlluminationAtPoint(point, __instance._illuminationRadius))) + { + __result = true; + return false; + } + + if (QSBPlayerManager.GetThrusterLightTrackers() + .Any(x => x.CheckIlluminationAtPoint(point, __instance._illuminationRadius))) + { + __result = true; + return false; + } + + if (__instance._lightSources != null) + { + foreach (var light in __instance._lightSources) + { + if (light.intensity > 0f && light.range > 0f) + { + __result = true; + return false; + } + } + } + + __result = false; + return false; + } +} diff --git a/QSB/QuantumSync/Patches/QuantumPatches.cs b/QSB/QuantumSync/Patches/QuantumPatches.cs deleted file mode 100644 index a37e418ba..000000000 --- a/QSB/QuantumSync/Patches/QuantumPatches.cs +++ /dev/null @@ -1,494 +0,0 @@ -using HarmonyLib; -using OWML.Common; -using QSB.Messaging; -using QSB.Patches; -using QSB.Player; -using QSB.QuantumSync.Messages; -using QSB.QuantumSync.WorldObjects; -using QSB.Utility; -using QSB.WorldSync; -using System.Collections.Generic; -using System.Linq; -using UnityEngine; - -namespace QSB.QuantumSync.Patches; - -[HarmonyPatch] -public class QuantumPatches : QSBPatch -{ - public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - - [HarmonyPrefix] - [HarmonyPatch(typeof(QuantumSocketCollapseTrigger), nameof(QuantumSocketCollapseTrigger.OnTriggerEnter))] - public static bool QuantumSocketCollapseTrigger_OnTriggerEnter() => false; - - [HarmonyPrefix] - [HarmonyPatch(typeof(QuantumObject), nameof(QuantumObject.IsLockedByPlayerContact))] - public static bool QuantumObject_IsLockedByPlayerContact(out bool __result, QuantumObject __instance) - { - var playersEntangled = QuantumManager.GetEntangledPlayers(__instance); - __result = playersEntangled.Count() != 0 && __instance.IsIlluminated(); - return false; - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(QuantumObject), nameof(QuantumObject.SetIsQuantum))] - public static void QuantumObject_SetIsQuantum(QuantumObject __instance) - { - if (QSBWorldSync.AllObjectsReady) - { - __instance.GetWorldObject().SendMessage(new SetIsQuantumMessage(__instance.IsQuantum())); - } - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(SocketedQuantumObject), nameof(SocketedQuantumObject.ChangeQuantumState))] - public static bool SocketedQuantumObject_ChangeQuantumState( - SocketedQuantumObject __instance, - ref bool __result, - bool skipInstantVisibilityCheck) - { - if (QSBWorldSync.AllObjectsReady) - { - var socketedWorldObject = __instance.GetWorldObject(); - if (socketedWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId) - { - return false; - } - } - - foreach (var socket in __instance._childSockets) - { - if (socket.IsOccupied()) - { - __result = false; - return false; - } - } - - if (__instance._socketList.Count <= 1) - { - DebugLog.ToConsole($"Error - Not enough quantum sockets in list for {__instance.name}!", MessageType.Error); - __result = false; - return false; - } - - var list = new List(); - foreach (var socket in __instance._socketList) - { - if (!socket.IsOccupied() && socket.IsActive()) - { - list.Add(socket); - } - } - - if (list.Count == 0) - { - __result = false; - return false; - } - - if (__instance._recentlyObscuredSocket != null) - { - __instance.MoveToSocket(__instance._recentlyObscuredSocket); - __instance._recentlyObscuredSocket = null; - __result = true; - return false; - } - - var occupiedSocket = __instance._occupiedSocket; - for (var i = 0; i < 20; i++) - { - var index = Random.Range(0, list.Count); - __instance.MoveToSocket(list[index]); - if (skipInstantVisibilityCheck) - { - __result = true; - return false; - } - - bool socketNotSuitable; - var isSocketIlluminated = __instance.CheckIllumination(); - - var playersEntangled = QuantumManager.GetEntangledPlayers(__instance); - if (playersEntangled.Count() != 0) - { - // socket not suitable if illuminated - socketNotSuitable = isSocketIlluminated; - } - else - { - var checkVisInstant = __instance.CheckVisibilityInstantly(); - if (isSocketIlluminated) - { - // socket not suitable if object is visible - socketNotSuitable = checkVisInstant; - } - else - { - // socket not suitable if player is inside object - socketNotSuitable = playersEntangled.Any(x => __instance.CheckPointInside(x.CameraBody.transform.position)); - } - } - - if (!socketNotSuitable) - { - __result = true; - return false; - } - - list.RemoveAt(index); - if (list.Count == 0) - { - break; - } - } - - __instance.MoveToSocket(occupiedSocket); - __result = false; - return false; - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(SocketedQuantumObject), nameof(SocketedQuantumObject.MoveToSocket))] - public static void SocketedQuantumObject_MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket) - { - if (!QSBWorldSync.AllObjectsReady) - { - return; - } - - if (socket == null) - { - DebugLog.ToConsole($"Error - Trying to move {__instance.name} to a null socket!", MessageType.Error); - return; - } - - var objectWorldObject = __instance.GetWorldObject(); - var socketWorldObject = socket.GetWorldObject(); - - if (objectWorldObject == null) - { - DebugLog.ToConsole($"Worldobject is null for {__instance.name}!"); - return; - } - - if (objectWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId) - { - return; - } - - objectWorldObject.SendMessage(new SocketStateChangeMessage( - socketWorldObject.ObjectId, - __instance.transform.localRotation)); - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(QuantumShuffleObject), nameof(QuantumShuffleObject.ChangeQuantumState))] - public static bool QuantumShuffleObject_ChangeQuantumState( - QuantumShuffleObject __instance, - ref bool __result) - { - QSBQuantumShuffleObject shuffleWorldObject = default; - if (QSBWorldSync.AllObjectsReady) - { - shuffleWorldObject = __instance.GetWorldObject(); - if (shuffleWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId) - { - return false; - } - } - - __instance._indexList.Clear(); - __instance._indexList = Enumerable.Range(0, __instance._localPositions.Length).ToList(); - for (var i = 0; i < __instance._indexList.Count; ++i) - { - var random = Random.Range(i, __instance._indexList.Count); - var temp = __instance._indexList[i]; - __instance._indexList[i] = __instance._indexList[random]; - __instance._indexList[random] = temp; - } - - for (var j = 0; j < __instance._shuffledObjects.Length; j++) - { - __instance._shuffledObjects[j].localPosition = __instance._localPositions[__instance._indexList[j]]; - } - - if (QSBWorldSync.AllObjectsReady) - { - shuffleWorldObject.SendMessage(new QuantumShuffleMessage(__instance._indexList.ToArray())); - __result = true; - } - - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(MultiStateQuantumObject), nameof(MultiStateQuantumObject.Start))] - public static bool MultiStateQuantumObject_Start(MultiStateQuantumObject __instance) - { - if (!QSBWorldSync.AllObjectsReady) - { - return true; - } - - var qsbObj = __instance.GetWorldObject(); - if (qsbObj.ControllingPlayer == 0) - { - return true; - } - - foreach (var state in qsbObj.QuantumStates) - { - if (!state.IsMeantToBeEnabled) - { - state.SetVisible(false); - } - } - - if (__instance._sector == null) - { - __instance.CheckEnabled(); - } - - if (__instance._collapseOnStart) - { - __instance.Collapse(true); - } - - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(MultiStateQuantumObject), nameof(MultiStateQuantumObject.ChangeQuantumState))] - public static bool MultiStateQuantumObject_ChangeQuantumState(MultiStateQuantumObject __instance) - { - if (!QSBWorldSync.AllObjectsReady) - { - return true; - } - - var qsbObj = __instance.GetWorldObject(); - if (qsbObj.ControllingPlayer == 0 && qsbObj.CurrentState == -1) - { - return true; - } - - var isInControl = qsbObj.ControllingPlayer == QSBPlayerManager.LocalPlayerId; - return isInControl; - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(QuantumState), nameof(QuantumState.SetVisible))] - public static void QuantumState_SetVisible(QuantumState __instance, bool visible) - { - if (!QSBWorldSync.AllObjectsReady) - { - return; - } - - if (!visible) - { - return; - } - - var allMultiStates = QSBWorldSync.GetWorldObjects(); - var stateObject = __instance.GetWorldObject(); - var owner = allMultiStates.FirstOrDefault(x => x.QuantumStates.Contains(stateObject)); - if (owner == default) - { - DebugLog.ToConsole($"Error - Could not find QSBMultiStateQuantumObject for state {__instance.name}", MessageType.Error); - return; - } - - if (owner.ControllingPlayer != QSBPlayerManager.LocalPlayerId) - { - return; - } - - var stateIndex = owner.QuantumStates.IndexOf(stateObject); - owner.SendMessage(new MultiStateChangeMessage(stateIndex)); - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(QuantumShrine), nameof(QuantumShrine.IsPlayerInDarkness))] - public static bool QuantumShrine_IsPlayerInDarkness(QuantumShrine __instance, out bool __result) - { - foreach (var lamp in __instance._lamps) - { - if (lamp.intensity > 0f) - { - __result = false; - return false; - } - } - - var playersInMoon = QSBPlayerManager.PlayerList.Where(x => x.IsInMoon).ToList(); - - if (playersInMoon.Any(player => !player.IsInShrine)) - { - __result = false; - return false; - } - - if (playersInMoon.Any(player => player.FlashLight != null && player.FlashLight.FlashlightOn)) - { - __result = false; - return false; - } - - if (playersInMoon.Count == 0) - { - __result = false; - return false; - } - - if (QSBPlayerManager.LocalPlayer != null - && QSBPlayerManager.LocalPlayer.IsInShrine - && PlayerState.IsFlashlightOn()) - { - __result = false; - return false; - } - - // BUG : make this *really* check for all players - check other probes and other jetpacks! - __result = __instance._gate.GetOpenFraction() == 0f - && !__instance._isProbeInside - && Locator.GetThrusterLightTracker().GetLightRange() <= 0f; - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(QuantumShrine), nameof(QuantumShrine.ChangeQuantumState))] - public static bool QuantumShrine_ChangeQuantumState(QuantumShrine __instance) - { - var shrineWorldObject = __instance.GetWorldObject(); - var isInControl = shrineWorldObject.ControllingPlayer == QSBPlayerManager.LocalPlayerId; - return isInControl; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(QuantumMoon), nameof(QuantumMoon.CheckPlayerFogProximity))] - 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).FoundPlayers) - { - __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).FoundPlayers) - { - __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(); - component.SetDegreesY(component.GetMinDegreesY()); - __instance._vortexAudio.SetLocalVolume(0f); - __instance._collapseToIndex = 1; - __instance.Collapse(true); - } - } - } - - __instance._playerFogBubble.SetFogAlpha(fogAlpha); - __instance._shipLandingCamFogBubble.SetFogAlpha(fogAlpha); - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(QuantumSkeletonTower), nameof(QuantumSkeletonTower.ChangeQuantumState))] - public static bool QuantumSkeletonTower_ChangeQuantumState(QuantumSkeletonTower __instance, ref bool __result) - { - if (!QSBWorldSync.AllObjectsReady) - { - return true; - } - - var qsbQuantumSkeletonTower = __instance.GetWorldObject(); - if (qsbQuantumSkeletonTower.ControllingPlayer != QSBPlayerManager.LocalPlayerId) - { - return false; - } - - if (__instance._waitForPlayerToLookAtTower) - { - __result = false; - return false; - } - - if (__instance._index < __instance._towerSkeletons.Length) - { - for (var i = 0; i < __instance._pointingSkeletons.Length; i++) - { - if (__instance._pointingSkeletons[i].gameObject.activeInHierarchy && - (!__instance._pointingSkeletons[i].IsVisible() || !__instance._pointingSkeletons[i].IsIlluminated())) - { - __instance._pointingSkeletons[i].gameObject.SetActive(false); - - __instance._towerSkeletons[__instance._index].SetActive(true); - __instance._index++; - __instance._waitForPlayerToLookAtTower = true; - qsbQuantumSkeletonTower.SendMessage(new MoveSkeletonMessage(i)); - __result = true; - return false; - } - } - } - - __result = false; - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(QuantumObject), nameof(QuantumObject.OnProbeSnapshot))] - public static bool OnProbeSnapshot() - { - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(QuantumObject), nameof(QuantumObject.OnProbeSnapshotRemoved))] - public static bool OnProbeSnapshotRemoved() - { - return false; - } -} \ No newline at end of file diff --git a/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs b/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs deleted file mode 100644 index dddf9136f..000000000 --- a/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs +++ /dev/null @@ -1,121 +0,0 @@ -using HarmonyLib; -using QSB.Patches; -using QSB.Player; -using QSB.Utility; -using System.Linq; -using UnityEngine; - -namespace QSB.QuantumSync.Patches; - -[HarmonyPatch] -public class QuantumVisibilityPatches : QSBPatch -{ - public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - - [HarmonyPostfix] - [HarmonyPatch(typeof(Shape), nameof(Shape.OnEnable))] - public static void Shape_OnEnable(Shape __instance) - => __instance.RaiseEvent(nameof(__instance.OnShapeActivated), __instance); - - [HarmonyPostfix] - [HarmonyPatch(typeof(Shape), nameof(Shape.OnDisable))] - public static void Shape_OnDisable(Shape __instance) - => __instance.RaiseEvent(nameof(__instance.OnShapeDeactivated), __instance); - - // ShapeVisibilityTracker patches - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShapeVisibilityTracker), nameof(ShapeVisibilityTracker.IsVisibleUsingCameraFrustum))] - public static bool ShapeVisibilityTracker_IsVisibleUsingCameraFrustum(ShapeVisibilityTracker __instance, out bool __result) - { - __result = QuantumManager.IsVisibleUsingCameraFrustum(__instance, false).FoundPlayers; - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShapeVisibilityTracker), nameof(ShapeVisibilityTracker.IsVisible))] - public static bool ShapeVisibilityTracker_IsVisible(ShapeVisibilityTracker __instance, out bool __result) - { - __result = QuantumManager.IsVisible(__instance, false); - return false; - } - - // RendererVisibilityTracker patches - probably not needed as i don't think RendererVisibilityTracker is ever used? - - [HarmonyPrefix] - [HarmonyPatch(typeof(RendererVisibilityTracker), nameof(RendererVisibilityTracker.IsVisibleUsingCameraFrustum))] - public static bool RendererVisibilityTracker_IsVisibleUsingCameraFrustum(RendererVisibilityTracker __instance, out bool __result) - { - __result = QSBPlayerManager.GetPlayersWithCameras() - .Any(x => GeometryUtility.TestPlanesAABB(x.Camera.GetFrustumPlanes(), __instance._renderer.bounds)) - && (!__instance._checkFrustumOcclusion || QSBPlayerManager.GetPlayersWithCameras() - .Any(x => !__instance.IsOccludedFromPosition(x.Camera.transform.position))); - return false; - } - - // VisibilityObject - - [HarmonyPrefix] - [HarmonyPatch(typeof(VisibilityObject), nameof(VisibilityObject.CheckIllumination))] - public static bool VisibilityObject_CheckIllumination(VisibilityObject __instance, out bool __result) - { - if (!__instance._checkIllumination) - { - __result = true; - return false; - } - - var point = __instance.transform.TransformPoint(__instance._localIlluminationOffset); - var (localFlashlight, playerFlashlights) = QSBPlayerManager.GetPlayerFlashlights(); - - if (localFlashlight.CheckIlluminationAtPoint(point, __instance._illuminationRadius)) - { - __result = true; - return false; - } - - if (playerFlashlights.Any(x => x.CheckIlluminationAtPoint(point, __instance._illuminationRadius))) - { - __result = true; - return false; - } - - var (localProbe, playerProbes) = QSBPlayerManager.GetPlayerProbes(); - - if (localProbe != null - && localProbe.IsLaunched() - && localProbe.CheckIlluminationAtPoint(point, __instance._illuminationRadius)) - { - __result = true; - return false; - } - - if (playerProbes.Any(x => x.IsLaunched() && x.CheckIlluminationAtPoint(point, __instance._illuminationRadius))) - { - __result = true; - return false; - } - - if (QSBPlayerManager.GetThrusterLightTrackers() - .Any(x => x.CheckIlluminationAtPoint(point, __instance._illuminationRadius))) - { - __result = true; - return false; - } - - if (__instance._lightSources != null) - { - foreach (var light in __instance._lightSources) - { - if (light.intensity > 0f && light.range > 0f) - { - __result = true; - return false; - } - } - } - - __result = false; - return false; - } -} \ No newline at end of file diff --git a/QSB/QuantumSync/Patches/Server/ServerEyeProxyQuantumMoonPatches.cs b/QSB/QuantumSync/Patches/Server/ServerEyeProxyQuantumMoonPatches.cs new file mode 100644 index 000000000..903ed62bf --- /dev/null +++ b/QSB/QuantumSync/Patches/Server/ServerEyeProxyQuantumMoonPatches.cs @@ -0,0 +1,50 @@ +using HarmonyLib; +using QSB.Messaging; +using QSB.Patches; +using QSB.QuantumSync.Messages; +using QSB.QuantumSync.WorldObjects; +using QSB.WorldSync; +using UnityEngine; + +namespace QSB.QuantumSync.Patches.Server; + +[HarmonyPatch(typeof(EyeProxyQuantumMoon))] +public class ServerEyeProxyQuantumMoonPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnServerClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(EyeProxyQuantumMoon), nameof(EyeProxyQuantumMoon.ChangeQuantumState))] + public static bool EyeProxyQuantumMoon_ChangeQuantumState(EyeProxyQuantumMoon __instance, ref bool __result, bool skipInstantVisibilityCheck) + { + if (!QSBWorldSync.AllObjectsReady) + { + return true; + } + + var qsbEyeProxyQuantumMoon = __instance.GetWorldObject(); + if (TimeLoop.GetSecondsRemaining() > 0f && Random.value > 0.3f) + { + __instance._moonStateRoot.SetActive(false); + qsbEyeProxyQuantumMoon.SendMessage(new EyeProxyMoonStateChangeMessage(false, -1f)); + __result = true; + return false; + } + + __instance._moonStateRoot.SetActive(true); + for (var i = 0; i < 20; i++) + { + var angle = Random.Range(0f, 360f); + __instance.transform.localEulerAngles = new Vector3(0f, angle, 0f); + if (skipInstantVisibilityCheck || !__instance.CheckVisibilityInstantly()) + { + qsbEyeProxyQuantumMoon.SendMessage(new EyeProxyMoonStateChangeMessage(true, angle)); + __result = true; + return false; + } + } + + __result = true; + return false; + } +} diff --git a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs b/QSB/QuantumSync/Patches/Server/ServerQuantumMoonPatches.cs similarity index 81% rename from QSB/QuantumSync/Patches/ServerQuantumPatches.cs rename to QSB/QuantumSync/Patches/Server/ServerQuantumMoonPatches.cs index 4baa74b73..3c55e3fa3 100644 --- a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs +++ b/QSB/QuantumSync/Patches/Server/ServerQuantumMoonPatches.cs @@ -3,60 +3,16 @@ using QSB.Patches; using QSB.Player; using QSB.QuantumSync.Messages; -using QSB.QuantumSync.WorldObjects; -using QSB.WorldSync; using System.Linq; using UnityEngine; -namespace QSB.QuantumSync.Patches; +namespace QSB.QuantumSync.Patches.Server; -[HarmonyPatch] -public class ServerQuantumPatches : QSBPatch +[HarmonyPatch(typeof(QuantumMoon))] +public class ServerQuantumMoonPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnServerClientConnect; - [HarmonyPrefix] - [HarmonyPatch(typeof(EyeProxyQuantumMoon), nameof(EyeProxyQuantumMoon.ChangeQuantumState))] - public static bool EyeProxyQuantumMoon_ChangeQuantumState(EyeProxyQuantumMoon __instance, ref bool __result, bool skipInstantVisibilityCheck) - { - if (!QSBWorldSync.AllObjectsReady) - { - return true; - } - - var qsbEyeProxyQuantumMoon = __instance.GetWorldObject(); - if (TimeLoop.GetSecondsRemaining() > 0f && Random.value > 0.3f) - { - __instance._moonStateRoot.SetActive(false); - qsbEyeProxyQuantumMoon.SendMessage(new EyeProxyMoonStateChangeMessage(false, -1f)); - __result = true; - return false; - } - - __instance._moonStateRoot.SetActive(true); - for (var i = 0; i < 20; i++) - { - var angle = Random.Range(0f, 360f); - __instance.transform.localEulerAngles = new Vector3(0f, angle, 0f); - if (skipInstantVisibilityCheck || !__instance.CheckVisibilityInstantly()) - { - qsbEyeProxyQuantumMoon.SendMessage(new EyeProxyMoonStateChangeMessage(true, angle)); - __result = true; - return false; - } - } - - __result = true; - return false; - } - - /* - * This patch used to be different, but that one completely broke Solanum's NomaiTextLines. - * I have no idea why, and I fixed it by just writing this patch again. - * The patches did the same thing. - * ¯\_(ツ)_/¯ - */ - [HarmonyPrefix] [HarmonyPatch(typeof(QuantumMoon), nameof(QuantumMoon.ChangeQuantumState))] public static bool ChangeQuantumState(QuantumMoon __instance, bool skipInstantVisibilityCheck, out bool __result) @@ -253,4 +209,4 @@ private static void DealWithNewPosition(QuantumMoon __instance) GlobalMessenger.FireEvent("QuantumMoonChangeState", __instance._moonBody); } -} \ No newline at end of file +} From 3aa1a2cdc362b809b5822b140539149973926d62 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 22 Jan 2023 00:58:43 +0000 Subject: [PATCH 07/28] test QM stuff --- .../Patches/Common/QuantumMoonPatches.cs | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs index 7ed46a83e..976bf091e 100644 --- a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs +++ b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs @@ -1,6 +1,10 @@ using HarmonyLib; using QSB.Messaging; using QSB.Patches; +using QSB.Player; +using QSB.ShipSync; +using QSB.Utility; +using System.Linq; using UnityEngine; namespace QSB.QuantumSync.Patches.Common; @@ -15,16 +19,30 @@ internal class QuantumMoonPatches : QSBPatch public static bool CheckPlayerFogProximity(QuantumMoon __instance) { var playerDistance = Vector3.Distance(__instance.transform.position, Locator.GetPlayerCamera().transform.position); - var fogOffset = (__instance._stateIndex != 5) ? 0f : __instance._eyeStateFogOffset; + var fogOffset = (__instance._stateIndex == 5) ? __instance._eyeStateFogOffset : 0f; 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 (distanceFromFog < 0f) // inside fog { - if (__instance.IsLockedByProbeSnapshot() || QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)__instance._visibilityTracker, true).FoundPlayers) + var playersWhoCanSeeMoon = QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)__instance._visibilityTracker, true).PlayersWhoCanSee; + var shipInFog = GetShipInFog(__instance); + + DebugLog.DebugWrite($"Inside Fog - shipInFog:{shipInFog} playersWhoCanSeeMoon.Count:{playersWhoCanSeeMoon.Count}, lockedByProbeSnapshot:{__instance.IsLockedByProbeSnapshot()}"); + + if (playersWhoCanSeeMoon.Any(x => !(shipInFog && x.IsInShip) && !GetTransformInFog(__instance, x.CameraBody.transform)) || __instance.IsLockedByProbeSnapshot()) { + /* Either : + * - The moon is locked with a snapshot + * OR + * - If the ship is in the fog : + * - there are people outside the ship who can see the moon, and who are not in the fog + * - If the ship is not in the fog + * - There are people who can see the moon, who are not in the fog + */ __instance._isPlayerInside = true; __instance.SetSurfaceState(__instance._stateIndex); Locator.GetShipLogManager().RevealFact(__instance._revealFactID); @@ -76,4 +94,22 @@ public static bool CheckPlayerFogProximity(QuantumMoon __instance) __instance._shipLandingCamFogBubble.SetFogAlpha(fogAlpha); return false; } + + private static bool GetShipInFog(QuantumMoon moon) + { + if (ShipManager.Instance.IsShipWrecked) + { + return false; + } + + return GetTransformInFog(moon, Locator.GetShipTransform()); + } + + private static bool GetTransformInFog(QuantumMoon moon, Transform transform) + { + var distance = Vector3.Distance(moon.transform.position, transform.position); + var fogOffset = (moon._stateIndex == 5) ? moon._eyeStateFogOffset : 0f; + var distanceFromFog = distance - (moon._fogRadius + fogOffset); + return distanceFromFog < 0f; + } } From f515d054c709a0004f6acc22e9c8c5503b198634 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 21 Jan 2023 17:08:07 -0800 Subject: [PATCH 08/28] sync transforms after moving player --- .../RaftSync/TransformSync/RaftTransformSync.cs | 5 +++++ QSB/ShipSync/TransformSync/ShipTransformSync.cs | 5 +++++ QSB/Syncs/Occasional/OccasionalTransformSync.cs | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/QSB/EchoesOfTheEye/RaftSync/TransformSync/RaftTransformSync.cs b/QSB/EchoesOfTheEye/RaftSync/TransformSync/RaftTransformSync.cs index 51494895b..f7a3d9ed1 100644 --- a/QSB/EchoesOfTheEye/RaftSync/TransformSync/RaftTransformSync.cs +++ b/QSB/EchoesOfTheEye/RaftSync/TransformSync/RaftTransformSync.cs @@ -102,6 +102,11 @@ protected override void ApplyToAttached() playerBody.SetPosition(AttachedTransform.FromRelPos(relPos)); playerBody.SetRotation(AttachedTransform.FromRelRot(relRot)); + + if (!Physics.autoSyncTransforms) + { + Physics.SyncTransforms(); + } } } else diff --git a/QSB/ShipSync/TransformSync/ShipTransformSync.cs b/QSB/ShipSync/TransformSync/ShipTransformSync.cs index 0fd5bc5a7..5bd46328f 100644 --- a/QSB/ShipSync/TransformSync/ShipTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipTransformSync.cs @@ -74,6 +74,11 @@ protected override void ApplyToAttached() playerBody.SetPosition(AttachedTransform.FromRelPos(relPos)); playerBody.SetRotation(AttachedTransform.FromRelRot(relRot)); + + if (!Physics.autoSyncTransforms) + { + Physics.SyncTransforms(); + } } } else diff --git a/QSB/Syncs/Occasional/OccasionalTransformSync.cs b/QSB/Syncs/Occasional/OccasionalTransformSync.cs index 32659d9c7..d96ab318e 100644 --- a/QSB/Syncs/Occasional/OccasionalTransformSync.cs +++ b/QSB/Syncs/Occasional/OccasionalTransformSync.cs @@ -75,6 +75,11 @@ protected override void ApplyToAttached() AttachedRigidbody.SetAngularVelocity(ReferenceRigidbody.FromRelAngVel(AngularVelocity)); Move(); + + if (!Physics.autoSyncTransforms) + { + Physics.SyncTransforms(); + } } private readonly List _toMove = new(); @@ -125,4 +130,4 @@ private void Move() _toMove.Clear(); } -} \ No newline at end of file +} From b7949ed917b58e88498401293aba7fd0b5057972 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 22 Jan 2023 01:14:48 +0000 Subject: [PATCH 09/28] fix ship fog --- QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs index 976bf091e..79d3e6cd5 100644 --- a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs +++ b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs @@ -102,7 +102,10 @@ private static bool GetShipInFog(QuantumMoon moon) return false; } - return GetTransformInFog(moon, Locator.GetShipTransform()); + var distance = Vector3.Distance(moon.transform.position, Locator.GetShipTransform().position); + var fogOffset = (moon._stateIndex == 5) ? moon._eyeStateFogOffset : 0f; + var distanceFromFog = distance - (moon._fogRadius + fogOffset); + return distanceFromFog < 10f; } private static bool GetTransformInFog(QuantumMoon moon, Transform transform) From 24e44a6d0108c522aa3c60e55994f8c4fb92f360 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 21 Jan 2023 20:30:02 -0800 Subject: [PATCH 10/28] put gameobject name in teleport planets patch --- QSB/TeleportingPlanetsPatch.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/TeleportingPlanetsPatch.cs b/QSB/TeleportingPlanetsPatch.cs index 94c9e581f..d222911cb 100644 --- a/QSB/TeleportingPlanetsPatch.cs +++ b/QSB/TeleportingPlanetsPatch.cs @@ -21,7 +21,7 @@ private static void SetPosition(OWRigidbody __instance, Vector3 worldPosition) { if (__instance.TryGetComponent(out var astroObject) && astroObject._name != AstroObject.Name.ProbeCannon) { - DebugLog.ToAll($"AHHHHHHHHH!!!!!!!!!\n{Environment.StackTrace}", MessageType.Error); + DebugLog.ToAll($"AHHHHHHHHH!!!!!!!!!\n{__instance.name}\n{Environment.StackTrace}", MessageType.Error); } } } From fd46b3864a3a35f4115b690b66ca96e117b348d4 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 22 Jan 2023 19:49:46 +0000 Subject: [PATCH 11/28] fix nres in debuggui --- QSB/Utility/DebugGUI.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/QSB/Utility/DebugGUI.cs b/QSB/Utility/DebugGUI.cs index 995236e51..aa034073f 100644 --- a/QSB/Utility/DebugGUI.cs +++ b/QSB/Utility/DebugGUI.cs @@ -136,8 +136,17 @@ private static void DrawGui() } WriteLine(1, $"Selected WorldObject : {(DebugActions.WorldObjectSelection == null ? "All" : DebugActions.WorldObjectSelection.Name)}"); - WriteLine(1, $"Invincible : {Locator.GetDeathManager()._invincible}"); - WriteLine(1, $"Tool Mode : {Locator.GetToolModeSwapper().GetToolMode()}"); + + if (Locator.GetDeathManager() != null) + { + WriteLine(1, $"Invincible : {Locator.GetDeathManager()._invincible}"); + } + + if (Locator.GetToolModeSwapper() != null) + { + WriteLine(1, $"Tool Mode : {Locator.GetToolModeSwapper().GetToolMode()}"); + } + WriteLine(1, $"Input Mode Stack :"); foreach (var item in OWInput.GetInputModeStack()) { @@ -158,7 +167,7 @@ private static void DrawGui() WriteLine(2, $"Dead : {player.IsDead}"); WriteLine(2, $"Ready : {player.IsReady}"); WriteLine(2, $"Suited Up : {player.SuitedUp}"); - WriteLine(2, $"In Suited Up State : {player.AnimationSync.InSuitedUpState}"); + WriteLine(2, $"In Suited Up State : {player.AnimationSync?.InSuitedUpState}"); WriteLine(2, $"InDreamWorld : {player.InDreamWorld}"); if (player.IsReady && QSBWorldSync.AllObjectsReady) From 6f44dc7bc15994a09efed45344072e1a331ae685 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 22 Jan 2023 19:49:55 +0000 Subject: [PATCH 12/28] fix class name --- .../Common/Visibility/VisibilityVisibilityObjectPatches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/QuantumSync/Patches/Common/Visibility/VisibilityVisibilityObjectPatches.cs b/QSB/QuantumSync/Patches/Common/Visibility/VisibilityVisibilityObjectPatches.cs index b69230641..69aa8d24f 100644 --- a/QSB/QuantumSync/Patches/Common/Visibility/VisibilityVisibilityObjectPatches.cs +++ b/QSB/QuantumSync/Patches/Common/Visibility/VisibilityVisibilityObjectPatches.cs @@ -6,7 +6,7 @@ namespace QSB.QuantumSync.Patches.Common.Visibility; [HarmonyPatch(typeof(VisibilityObject))] -internal class VisibilityObjectPatches : QSBPatch +internal class VisibilityVisibilityObjectPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; From 67ba18fa84858799effcf6e59bf0179e8f2f0b03 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 22 Jan 2023 19:50:51 +0000 Subject: [PATCH 13/28] fix moon not collapsing when in fog --- QSB/QuantumSync/Patches/Server/ServerQuantumMoonPatches.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/QSB/QuantumSync/Patches/Server/ServerQuantumMoonPatches.cs b/QSB/QuantumSync/Patches/Server/ServerQuantumMoonPatches.cs index 3c55e3fa3..158263fe8 100644 --- a/QSB/QuantumSync/Patches/Server/ServerQuantumMoonPatches.cs +++ b/QSB/QuantumSync/Patches/Server/ServerQuantumMoonPatches.cs @@ -3,6 +3,7 @@ using QSB.Patches; using QSB.Player; using QSB.QuantumSync.Messages; +using QSB.QuantumSync.Patches.Common; using System.Linq; using UnityEngine; @@ -33,7 +34,7 @@ public static bool ChangeQuantumState(QuantumMoon __instance, bool skipInstantVi } // If any of the players outside the shrine can see the moon - if (playersNotInQuantumShrine.Any(playersWhoCanSeeQuantumMoon.Contains)) + if (playersNotInQuantumShrine.Any(x => playersWhoCanSeeQuantumMoon.Contains(x) && !QuantumMoonPatches.GetTransformInFog(Locator.GetQuantumMoon(), x.CameraBody.transform))) { __result = false; return false; From 58e97e44a1858431594940097d0ae777670cefd2 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 22 Jan 2023 19:51:03 +0000 Subject: [PATCH 14/28] whoops --- QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs index 79d3e6cd5..d5f33768c 100644 --- a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs +++ b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs @@ -95,7 +95,7 @@ public static bool CheckPlayerFogProximity(QuantumMoon __instance) return false; } - private static bool GetShipInFog(QuantumMoon moon) + public static bool GetShipInFog(QuantumMoon moon) { if (ShipManager.Instance.IsShipWrecked) { @@ -108,7 +108,7 @@ private static bool GetShipInFog(QuantumMoon moon) return distanceFromFog < 10f; } - private static bool GetTransformInFog(QuantumMoon moon, Transform transform) + public static bool GetTransformInFog(QuantumMoon moon, Transform transform) { var distance = Vector3.Distance(moon.transform.position, transform.position); var fogOffset = (moon._stateIndex == 5) ? moon._eyeStateFogOffset : 0f; From 9169283ac49bb787136815513de4c456966da36b Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 22 Jan 2023 22:44:59 +0000 Subject: [PATCH 15/28] add cloak to enterleave --- QSB/Messaging/OWEvents.cs | 2 ++ QSB/Player/EnterLeaveType.cs | 2 ++ QSB/Player/Messages/EnterLeaveMessage.cs | 8 ++++++++ QSB/Player/PlayerInfo.cs | 1 + 4 files changed, 13 insertions(+) diff --git a/QSB/Messaging/OWEvents.cs b/QSB/Messaging/OWEvents.cs index 865b0b120..2fdd654da 100644 --- a/QSB/Messaging/OWEvents.cs +++ b/QSB/Messaging/OWEvents.cs @@ -37,4 +37,6 @@ public static class OWEvents public const string StartShipIgnition = nameof(StartShipIgnition); public const string CompleteShipIgnition = nameof(CompleteShipIgnition); public const string CancelShipIgnition = nameof(CancelShipIgnition); + public const string EnterCloak = nameof(EnterCloak); + public const string ExitCloak = nameof(ExitCloak); } \ No newline at end of file diff --git a/QSB/Player/EnterLeaveType.cs b/QSB/Player/EnterLeaveType.cs index 4b94ba118..3acf5e50a 100644 --- a/QSB/Player/EnterLeaveType.cs +++ b/QSB/Player/EnterLeaveType.cs @@ -8,4 +8,6 @@ public enum EnterLeaveType ExitPlatform, EnterShip, ExitShip, + EnterCloak, + ExitCloak } \ No newline at end of file diff --git a/QSB/Player/Messages/EnterLeaveMessage.cs b/QSB/Player/Messages/EnterLeaveMessage.cs index 62b1ea6a5..8fa22dd31 100644 --- a/QSB/Player/Messages/EnterLeaveMessage.cs +++ b/QSB/Player/Messages/EnterLeaveMessage.cs @@ -20,6 +20,8 @@ static EnterLeaveMessage() GlobalMessenger.AddListener(OWEvents.PlayerExitQuantumMoon, () => Handler(EnterLeaveType.ExitMoon)); GlobalMessenger.AddListener(OWEvents.EnterShip, () => Handler(EnterLeaveType.EnterShip)); GlobalMessenger.AddListener(OWEvents.ExitShip, () => Handler(EnterLeaveType.ExitShip)); + GlobalMessenger.AddListener(OWEvents.EnterCloak, () => Handler(EnterLeaveType.EnterCloak)); + GlobalMessenger.AddListener(OWEvents.ExitCloak, () => Handler(EnterLeaveType.ExitCloak)); } private static void Handler(EnterLeaveType type, int objectId = -1) @@ -62,6 +64,12 @@ public override void OnReceiveRemote() case EnterLeaveType.ExitMoon: player.IsInMoon = false; break; + case EnterLeaveType.EnterCloak: + player.IsInCloak = true; + break; + case EnterLeaveType.ExitCloak: + player.IsInCloak = false; + break; case EnterLeaveType.EnterPlatform: CustomNomaiRemoteCameraPlatform.CustomPlatformList[ObjectId] .OnRemotePlayerEnter(From); diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index 7cb23a5c4..b0a16927f 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -32,6 +32,7 @@ public partial class PlayerInfo public bool IsInShrine { get; set; } public bool IsInEyeShuttle { get; set; } public bool IsInShip { get; set; } + public bool IsInCloak { get; set; } public IQSBQuantumObject EntangledObject { get; set; } public QSBPlayerAudioController AudioController { get; set; } public bool IsLocalPlayer => TransformSync.isLocalPlayer; // if TransformSync is ever null, i give permission for nebula to make fun of me about it for the rest of time - johncorby From ae6131c64a9272e2f828167773a06c9dfc610f30 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Mon, 23 Jan 2023 13:06:04 +0000 Subject: [PATCH 16/28] Update PlayerInformationMessage.cs --- QSB/Player/Messages/PlayerInformationMessage.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/QSB/Player/Messages/PlayerInformationMessage.cs b/QSB/Player/Messages/PlayerInformationMessage.cs index 423135168..61775a969 100644 --- a/QSB/Player/Messages/PlayerInformationMessage.cs +++ b/QSB/Player/Messages/PlayerInformationMessage.cs @@ -18,6 +18,7 @@ public class PlayerInformationMessage : QSBMessage private bool ProbeActive; private ClientState ClientState; private float FieldOfView; + private bool IsInShip; public PlayerInformationMessage() { @@ -32,6 +33,7 @@ public PlayerInformationMessage() ProbeActive = player.ProbeActive; ClientState = player.State; FieldOfView = PlayerData.GetGraphicSettings().fieldOfView; + IsInShip = player.IsInShip; } public override void Serialize(NetworkWriter writer) @@ -47,6 +49,7 @@ public override void Serialize(NetworkWriter writer) writer.Write(ProbeActive); writer.Write(ClientState); writer.Write(FieldOfView); + writer.Write(IsInShip); } public override void Deserialize(NetworkReader reader) @@ -62,6 +65,7 @@ public override void Deserialize(NetworkReader reader) ProbeActive = reader.Read(); ClientState = reader.Read(); FieldOfView = reader.ReadFloat(); + IsInShip = reader.ReadBool(); } public override void OnReceiveRemote() @@ -78,6 +82,7 @@ public override void OnReceiveRemote() player.SignalscopeEquipped = SignalscopeEquipped; player.TranslatorEquipped = TranslatorEquipped; player.ProbeActive = ProbeActive; + player.IsInShip = IsInShip; if (QSBPlayerManager.LocalPlayer.IsReady && player.IsReady) { player.UpdateObjectsFromStates(); From 5b10a570d7734478c57d5e7f45f0a1ca51404084 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Mon, 23 Jan 2023 20:13:31 +0000 Subject: [PATCH 17/28] probe enter/leave QM messages --- QSB/Messaging/OWEvents.cs | 2 + .../Messages/ProbeEnterLeaveMessage.cs | 46 +++++++++++++++++++ QSB/Tools/ProbeTool/ProbeEnterLeaveType.cs | 9 ++++ QSB/Tools/ProbeTool/QSBSurveyorProbe.cs | 3 ++ 4 files changed, 60 insertions(+) create mode 100644 QSB/Tools/ProbeTool/Messages/ProbeEnterLeaveMessage.cs create mode 100644 QSB/Tools/ProbeTool/ProbeEnterLeaveType.cs diff --git a/QSB/Messaging/OWEvents.cs b/QSB/Messaging/OWEvents.cs index 2fdd654da..fa8f0f538 100644 --- a/QSB/Messaging/OWEvents.cs +++ b/QSB/Messaging/OWEvents.cs @@ -37,6 +37,8 @@ public static class OWEvents public const string StartShipIgnition = nameof(StartShipIgnition); public const string CompleteShipIgnition = nameof(CompleteShipIgnition); public const string CancelShipIgnition = nameof(CancelShipIgnition); + public const string ProbeEnterQuantumMoon = nameof(ProbeEnterQuantumMoon); + public const string ProbeExitQuantumMoon = nameof(ProbeExitQuantumMoon); public const string EnterCloak = nameof(EnterCloak); public const string ExitCloak = nameof(ExitCloak); } \ No newline at end of file diff --git a/QSB/Tools/ProbeTool/Messages/ProbeEnterLeaveMessage.cs b/QSB/Tools/ProbeTool/Messages/ProbeEnterLeaveMessage.cs new file mode 100644 index 000000000..1f5d698e3 --- /dev/null +++ b/QSB/Tools/ProbeTool/Messages/ProbeEnterLeaveMessage.cs @@ -0,0 +1,46 @@ +using QSB.Messaging; +using QSB.Player.Messages; +using QSB.Player.TransformSync; +using QSB.Player; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using QSB.Utility; + +namespace QSB.Tools.ProbeTool.Messages; + +internal class ProbeEnterLeaveMessage : QSBMessage +{ + static ProbeEnterLeaveMessage() + { + GlobalMessenger.AddListener(OWEvents.ProbeEnterQuantumMoon, () => Handler(ProbeEnterLeaveType.EnterQuantumMoon)); + GlobalMessenger.AddListener(OWEvents.ProbeExitQuantumMoon, () => Handler(ProbeEnterLeaveType.ExitQuantumMoon)); + // TODO : add cloak messages + } + + private static void Handler(ProbeEnterLeaveType type) + { + new ProbeEnterLeaveMessage(type).Send(); + } + + public ProbeEnterLeaveMessage(ProbeEnterLeaveType type) : base(type) { } + + public override void OnReceiveRemote() + { + var player = QSBPlayerManager.GetPlayer(From); + switch (Data) + { + case ProbeEnterLeaveType.EnterQuantumMoon: + DebugLog.DebugWrite($"{player} probe enter QM"); + player.Probe.InsideQuantumMoon = true; + break; + case ProbeEnterLeaveType.ExitQuantumMoon: + DebugLog.DebugWrite($"{player} probe exit QM"); + player.Probe.InsideQuantumMoon = false; + break; + } + } +} diff --git a/QSB/Tools/ProbeTool/ProbeEnterLeaveType.cs b/QSB/Tools/ProbeTool/ProbeEnterLeaveType.cs new file mode 100644 index 000000000..817223b09 --- /dev/null +++ b/QSB/Tools/ProbeTool/ProbeEnterLeaveType.cs @@ -0,0 +1,9 @@ +namespace QSB.Tools.ProbeTool; + +public enum ProbeEnterLeaveType +{ + EnterQuantumMoon, + ExitQuantumMoon, + EnterCloak, + ExitCloak +} diff --git a/QSB/Tools/ProbeTool/QSBSurveyorProbe.cs b/QSB/Tools/ProbeTool/QSBSurveyorProbe.cs index 1869b7fa2..d779aa6ac 100644 --- a/QSB/Tools/ProbeTool/QSBSurveyorProbe.cs +++ b/QSB/Tools/ProbeTool/QSBSurveyorProbe.cs @@ -21,6 +21,9 @@ public class QSBSurveyorProbe : MonoBehaviour, ILightSource public event SurveyorProbeEvent OnTakeSnapshot; public event RetrieveEvent OnStartRetrieveProbe; + public bool InsideQuantumMoon; + public bool InsideCloak; + private GameObject _detectorObj; private RulesetDetector _rulesetDetector; private SingularityWarpEffect _warpEffect; From e49dd307f5b0619f61649e9935009de0770e5b2b Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Mon, 23 Jan 2023 20:13:55 +0000 Subject: [PATCH 18/28] fix interference --- QSB/Tools/ProbeTool/QSBProbeCamera.cs | 19 ++++++++----------- QSB/Tools/ProbeTool/QSBSurveyorProbe.cs | 2 ++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/QSB/Tools/ProbeTool/QSBProbeCamera.cs b/QSB/Tools/ProbeTool/QSBProbeCamera.cs index 8efaa1661..f723f963e 100644 --- a/QSB/Tools/ProbeTool/QSBProbeCamera.cs +++ b/QSB/Tools/ProbeTool/QSBProbeCamera.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using QSB.Player; +using UnityEngine; namespace QSB.Tools.ProbeTool; @@ -15,8 +16,8 @@ public class QSBProbeCamera : MonoBehaviour private Quaternion _origLocalRotation; private Quaternion _origParentLocalRotation; private Vector2 _cameraRotation = Vector2.zero; - private QuantumMoon _quantumMoon; private SandLevelController _sandLevelController; + private PlayerInfo owner; public event ProbeCamera.RotateCameraEvent OnRotateCamera; @@ -33,11 +34,8 @@ private void OnDestroy() private void Start() { - var astroObject = Locator.GetAstroObject(AstroObject.Name.QuantumMoon); - if (astroObject != null) - { - _quantumMoon = astroObject.GetComponent(); - } + var probe = GetComponentInParent(); + owner = probe.GetOwner(); } public static OWCamera GetLastSnapshotCamera() => @@ -53,10 +51,9 @@ public void SetSandLevelController(SandLevelController sandLevelController) => _sandLevelController = sandLevelController; public bool HasInterference() => - _id != ProbeCamera.ID.PreLaunch - //&& ((this._quantumMoon != null && this._quantumMoon.IsPlayerInside() != this._quantumMoon.IsProbeInside()) - || (_sandLevelController != null && _sandLevelController.IsPointBuried(transform.position)); - //|| (Locator.GetCloakFieldController() != null && Locator.GetCloakFieldController().isPlayerInsideCloak != Locator.GetCloakFieldController().isProbeInsideCloak)); + (_id != ProbeCamera.ID.PreLaunch && owner.IsInMoon != owner.Probe.InsideQuantumMoon) + || (_sandLevelController != null && _sandLevelController.IsPointBuried(transform.position)) + || (Locator.GetCloakFieldController() != null && owner.IsInCloak != owner.Probe.InsideCloak); public RenderTexture TakeSnapshot() { diff --git a/QSB/Tools/ProbeTool/QSBSurveyorProbe.cs b/QSB/Tools/ProbeTool/QSBSurveyorProbe.cs index d779aa6ac..b469fcb0d 100644 --- a/QSB/Tools/ProbeTool/QSBSurveyorProbe.cs +++ b/QSB/Tools/ProbeTool/QSBSurveyorProbe.cs @@ -116,6 +116,8 @@ public void SetOwner(PlayerInfo player) _owner = player; } + public PlayerInfo GetOwner() => _owner; + private void OnWarpComplete() => Deactivate(); public bool IsRetrieving() From e069416b89efa343ec721b71a8db7e4d3ea203e5 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Mon, 23 Jan 2023 20:14:05 +0000 Subject: [PATCH 19/28] patch IsLockedByProbeSnapshot --- QSB/QuantumSync/Patches/Common/QuantumObjectPatches.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/QSB/QuantumSync/Patches/Common/QuantumObjectPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumObjectPatches.cs index 37c57dcff..97e612050 100644 --- a/QSB/QuantumSync/Patches/Common/QuantumObjectPatches.cs +++ b/QSB/QuantumSync/Patches/Common/QuantumObjectPatches.cs @@ -45,4 +45,12 @@ public static bool OnProbeSnapshotRemoved() { return false; } + + [HarmonyPrefix] + [HarmonyPatch(nameof(QuantumObject.IsLockedByProbeSnapshot))] + public static bool IsLockedByProbeSnapshot(QuantumObject __instance, ref bool __result) + { + __result = __instance._visibleInProbeSnapshot; + return false; + } } From 4cdedc781cb289505ae6c5de6f7acec8fdd3b6cc Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 30 Jan 2023 10:24:39 -0800 Subject: [PATCH 20/28] remove GameDir from template --- DevEnv.template.targets | 1 - 1 file changed, 1 deletion(-) diff --git a/DevEnv.template.targets b/DevEnv.template.targets index 40290644a..65a271378 100644 --- a/DevEnv.template.targets +++ b/DevEnv.template.targets @@ -1,7 +1,6 @@ - C:\Program Files\Epic Games\OuterWilds $(AppData)\OuterWildsModManager\OWML $(SolutionDir)\qsb-unityproject\Assets From b7cdbf13cd4d8605c83149c65023fbc033788a0d Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Thu, 2 Feb 2023 11:29:30 +0000 Subject: [PATCH 21/28] Update SyncBase.cs --- QSB/Syncs/SyncBase.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 1ab3a6a1d..64e31720b 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -342,6 +342,9 @@ private void OnGUI() return; } - DebugGUI.DrawLabel(AttachedTransform, ToString()); + if (DebugActions.WorldObjectSelection == null) + { + DebugGUI.DrawLabel(AttachedTransform, ToString()); + } } } \ No newline at end of file From d69e5d2d7a53f358cce4bf5da61e9f656b6269a2 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Thu, 2 Feb 2023 11:29:39 +0000 Subject: [PATCH 22/28] bump version --- QSB/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/manifest.json b/QSB/manifest.json index 3a368e484..23ecb4978 100644 --- a/QSB/manifest.json +++ b/QSB/manifest.json @@ -7,7 +7,7 @@ "body": "- Disable *all* other mods. (Can heavily affect performance)\n- Make sure you are not running any other network-intensive applications." }, "uniqueName": "Raicuparta.QuantumSpaceBuddies", - "version": "0.24.4", + "version": "0.25.0", "owmlVersion": "2.9.0", "dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ], "pathsToPreserve": [ "debugsettings.json" ], From f9dc544405e52ec2f377528ab412d4ed789905d5 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Thu, 2 Feb 2023 19:19:38 +0000 Subject: [PATCH 23/28] update label --- QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs index a9c1e1084..674ca1488 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs @@ -330,6 +330,8 @@ public override string ReturnLabel() label += $"{tracker.name}:\r\n IsVisible:{tracker.IsVisible()}\r\n VisibleUsingCamera:{tracker.IsVisibleUsingCameraFrustum()}\r\n"; } + label += $"VisibleInProbeSnapshot:{AttachedObject._visibleInProbeSnapshot}\r\n"; + return label; } } \ No newline at end of file From 69844210346eab9b586b83a22bf6a6c3bb70333f Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 7 Feb 2023 22:37:11 +0000 Subject: [PATCH 24/28] fix probe cameras not rotating properly --- QSB/Tools/ProbeTool/QSBProbeCamera.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/QSB/Tools/ProbeTool/QSBProbeCamera.cs b/QSB/Tools/ProbeTool/QSBProbeCamera.cs index f723f963e..c390c9b2c 100644 --- a/QSB/Tools/ProbeTool/QSBProbeCamera.cs +++ b/QSB/Tools/ProbeTool/QSBProbeCamera.cs @@ -11,7 +11,6 @@ public class QSBProbeCamera : MonoBehaviour private OWCamera _camera; private RenderTexture _snapshotTexture; - private NoiseImageEffect _noiseEffect; private static OWCamera _lastSnapshotCamera; private Quaternion _origLocalRotation; private Quaternion _origParentLocalRotation; @@ -23,10 +22,10 @@ public class QSBProbeCamera : MonoBehaviour private void Awake() { + _origLocalRotation = transform.localRotation; + _origParentLocalRotation = transform.parent.localRotation; _camera = this.GetRequiredComponent(); _camera.enabled = false; - _noiseEffect = GetComponent(); - //this._snapshotTexture = ProbeCamera.GetSharedSnapshotTexture(); } private void OnDestroy() @@ -58,11 +57,6 @@ public bool HasInterference() => public RenderTexture TakeSnapshot() { _lastSnapshotCamera = _camera; - if (_noiseEffect != null) - { - _noiseEffect.enabled = HasInterference(); - } - _camera.targetTexture = _snapshotTexture; _camera.Render(); return _snapshotTexture; From 1168da8c69b258af51fc4093ee99e0637ad99773 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 8 Feb 2023 10:57:41 +0000 Subject: [PATCH 25/28] add comment --- QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs index d5f33768c..400ab77d2 100644 --- a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs +++ b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs @@ -105,7 +105,7 @@ public static bool GetShipInFog(QuantumMoon moon) var distance = Vector3.Distance(moon.transform.position, Locator.GetShipTransform().position); var fogOffset = (moon._stateIndex == 5) ? moon._eyeStateFogOffset : 0f; var distanceFromFog = distance - (moon._fogRadius + fogOffset); - return distanceFromFog < 10f; + return distanceFromFog < 10f; // to account for ship size } public static bool GetTransformInFog(QuantumMoon moon, Transform transform) From 4800123ddb47b593bfa30e91030c094ec302ed32 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 8 Feb 2023 11:37:17 +0000 Subject: [PATCH 26/28] make HostControls public and in interface --- QSB/QuantumSync/WorldObjects/IQSBQuantumObject.cs | 1 + QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs | 2 +- QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs | 2 +- QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/QSB/QuantumSync/WorldObjects/IQSBQuantumObject.cs b/QSB/QuantumSync/WorldObjects/IQSBQuantumObject.cs index ebf3a9899..931f8e1f8 100644 --- a/QSB/QuantumSync/WorldObjects/IQSBQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/IQSBQuantumObject.cs @@ -6,6 +6,7 @@ namespace QSB.QuantumSync.WorldObjects; public interface IQSBQuantumObject : IWorldObject { + bool HostControls { get; } uint ControllingPlayer { get; set; } bool IsEnabled { get; } diff --git a/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs b/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs index 9b36d0d3d..5ded51022 100644 --- a/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs +++ b/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs @@ -2,7 +2,7 @@ internal class QSBEyeProxyQuantumMoon : QSBQuantumObject { - protected override bool HostControls => true; + public override bool HostControls => true; public override void SendInitialState(uint to) { diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs index 1cc1a3cc8..68ea48987 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs @@ -7,7 +7,7 @@ namespace QSB.QuantumSync.WorldObjects; internal class QSBQuantumMoon : QSBQuantumObject { - protected override bool HostControls => true; + public override bool HostControls => true; public override void SendInitialState(uint to) { diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs index 674ca1488..601a74732 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs @@ -25,7 +25,7 @@ internal abstract class QSBQuantumObject : WorldObject, IQSBQuantumObject /// whether the controlling player is always the host
/// also means this object is considered always enabled /// - protected virtual bool HostControls => false; + public virtual bool HostControls => false; public uint ControllingPlayer { get; set; } public bool IsEnabled { get; private set; } From 4ce0c844a1de1c4b4043899e47b8a2d854855931 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 8 Feb 2023 12:10:17 +0000 Subject: [PATCH 27/28] fix QM inside not loading for clients --- QSB/QuantumSync/QuantumManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QSB/QuantumSync/QuantumManager.cs b/QSB/QuantumSync/QuantumManager.cs index ae1429d2e..237bc3eb2 100644 --- a/QSB/QuantumSync/QuantumManager.cs +++ b/QSB/QuantumSync/QuantumManager.cs @@ -130,7 +130,7 @@ public static void OnTakeProbeSnapshot(PlayerInfo player, ProbeCamera.ID cameraI { foreach (var quantumObject in QSBWorldSync.GetWorldObjects()) { - if (quantumObject.ControllingPlayer == QSBPlayerManager.LocalPlayerId) + if (quantumObject.ControllingPlayer == QSBPlayerManager.LocalPlayerId || quantumObject.HostControls) { quantumObject.OnTakeProbeSnapshot(player, cameraId); } @@ -141,7 +141,7 @@ public static void OnRemoveProbeSnapshot(PlayerInfo player) { foreach (var quantumObject in QSBWorldSync.GetWorldObjects()) { - if (quantumObject.ControllingPlayer == QSBPlayerManager.LocalPlayerId) + if (quantumObject.ControllingPlayer == QSBPlayerManager.LocalPlayerId || quantumObject.HostControls) { quantumObject.OnRemoveProbeSnapshot(player); } From b4741c6f1bcd3edf0c5f513e82058352f72c971d Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 8 Feb 2023 12:16:12 +0000 Subject: [PATCH 28/28] allow enter moon if someone else is inside it --- QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs index 400ab77d2..b0831c9e1 100644 --- a/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs +++ b/QSB/QuantumSync/Patches/Common/QuantumMoonPatches.cs @@ -30,14 +30,16 @@ public static bool CheckPlayerFogProximity(QuantumMoon __instance) { var playersWhoCanSeeMoon = QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)__instance._visibilityTracker, true).PlayersWhoCanSee; var shipInFog = GetShipInFog(__instance); + var anyoneInMoon = QSBPlayerManager.PlayerList.Any(x => x.IsInMoon && !x.IsLocalPlayer); - DebugLog.DebugWrite($"Inside Fog - shipInFog:{shipInFog} playersWhoCanSeeMoon.Count:{playersWhoCanSeeMoon.Count}, lockedByProbeSnapshot:{__instance.IsLockedByProbeSnapshot()}"); - - if (playersWhoCanSeeMoon.Any(x => !(shipInFog && x.IsInShip) && !GetTransformInFog(__instance, x.CameraBody.transform)) || __instance.IsLockedByProbeSnapshot()) + // this probably breaks in really obscure cases, but it should be good enough... + if (playersWhoCanSeeMoon.Any(x => !(shipInFog && x.IsInShip) && !GetTransformInFog(__instance, x.CameraBody.transform)) || __instance.IsLockedByProbeSnapshot() || anyoneInMoon) { /* Either : * - The moon is locked with a snapshot * OR + * - Someone else is in the moon + * OR * - If the ship is in the fog : * - there are people outside the ship who can see the moon, and who are not in the fog * - If the ship is not in the fog