From 47293bfb8d999acac78231619b88a834998b7224 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 16 Apr 2022 10:08:59 +0100 Subject: [PATCH 01/17] sync signalscope and probe launcher --- .../Messages/PlayerInformationMessage.cs | 10 ++-- QSB/Player/PlayerInfo.cs | 8 ++- QSB/Player/PlayerInfoParts/Tools.cs | 6 ++- QSB/ShipSync/ShipManager.cs | 20 +++++++ .../Messages/EquipProbeLauncherMessage.cs | 53 +++++++++++-------- .../Messages/PlayerEquipLauncherMessage.cs | 21 ++++++++ .../Messages/PlayerLaunchProbeMessage.cs | 2 +- .../Messages/PlayerRetrieveProbeMessage.cs | 2 +- .../WorldObjects/QSBProbeLauncher.cs | 2 +- QSB/Tools/ProbeTool/QSBProbe.cs | 4 +- .../TransformSync/PlayerProbeSync.cs | 10 ++-- QSB/Tools/QSBTool.cs | 13 ++++- .../Messages/PlayerSignalscopeMessage.cs | 6 +++ 13 files changed, 115 insertions(+), 42 deletions(-) create mode 100644 QSB/Tools/ProbeLauncherTool/Messages/PlayerEquipLauncherMessage.cs diff --git a/QSB/Player/Messages/PlayerInformationMessage.cs b/QSB/Player/Messages/PlayerInformationMessage.cs index 8da4d2f7..b54ab35f 100644 --- a/QSB/Player/Messages/PlayerInformationMessage.cs +++ b/QSB/Player/Messages/PlayerInformationMessage.cs @@ -12,7 +12,7 @@ public class PlayerInformationMessage : QSBMessage private bool IsReady; private bool FlashlightActive; private bool SuitedUp; - private bool ProbeLauncherEquipped; + private bool LocalProbeLauncherEquipped; private bool SignalscopeEquipped; private bool TranslatorEquipped; private bool ProbeActive; @@ -25,7 +25,7 @@ public class PlayerInformationMessage : QSBMessage IsReady = player.IsReady; FlashlightActive = player.FlashlightActive; SuitedUp = player.SuitedUp; - ProbeLauncherEquipped = player.ProbeLauncherEquipped; + LocalProbeLauncherEquipped = player.LocalProbeLauncherEquipped; SignalscopeEquipped = player.SignalscopeEquipped; TranslatorEquipped = player.TranslatorEquipped; ProbeActive = player.ProbeActive; @@ -39,7 +39,7 @@ public class PlayerInformationMessage : QSBMessage writer.Write(IsReady); writer.Write(FlashlightActive); writer.Write(SuitedUp); - writer.Write(ProbeLauncherEquipped); + writer.Write(LocalProbeLauncherEquipped); writer.Write(SignalscopeEquipped); writer.Write(TranslatorEquipped); writer.Write(ProbeActive); @@ -53,7 +53,7 @@ public class PlayerInformationMessage : QSBMessage IsReady = reader.Read(); FlashlightActive = reader.Read(); SuitedUp = reader.Read(); - ProbeLauncherEquipped = reader.Read(); + LocalProbeLauncherEquipped = reader.Read(); SignalscopeEquipped = reader.Read(); TranslatorEquipped = reader.Read(); ProbeActive = reader.Read(); @@ -70,7 +70,7 @@ public class PlayerInformationMessage : QSBMessage player.IsReady = IsReady; player.FlashlightActive = FlashlightActive; player.SuitedUp = SuitedUp; - player.ProbeLauncherEquipped = ProbeLauncherEquipped; + player.LocalProbeLauncherEquipped = LocalProbeLauncherEquipped; player.SignalscopeEquipped = SignalscopeEquipped; player.TranslatorEquipped = TranslatorEquipped; player.ProbeActive = ProbeActive; diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index 3e5ea5fb..e411957f 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -6,6 +6,7 @@ using QSB.Messaging; using QSB.Player.Messages; using QSB.Player.TransformSync; using QSB.QuantumSync.WorldObjects; +using QSB.ShipSync; using QSB.Tools; using QSB.Utility; using System.Linq; @@ -32,6 +33,7 @@ public partial class PlayerInfo public QSBPlayerAudioController AudioController { get; set; } public bool IsLocalPlayer => TransformSync.isLocalPlayer; public ThrusterLightTracker ThrusterLightTracker; + public bool FlyingShip => ShipManager.Instance.CurrentFlyer == PlayerId; public PlayerInfo(PlayerTransformSync transformSync) { @@ -63,17 +65,19 @@ public partial class PlayerInfo HeldItem = default; FlashlightActive = default; SuitedUp = default; - ProbeLauncherEquipped = default; + LocalProbeLauncherEquipped = default; SignalscopeEquipped = default; TranslatorEquipped = default; ProbeActive = default; + + ProbeLauncherEquipped = default; } public void UpdateObjectsFromStates() { FlashLight.UpdateState(FlashlightActive); Translator.ChangeEquipState(TranslatorEquipped); - ProbeLauncher.ChangeEquipState(ProbeLauncherEquipped); + ProbeLauncherTool.ChangeEquipState(LocalProbeLauncherEquipped); Signalscope.ChangeEquipState(SignalscopeEquipped); AnimationSync.SetSuitState(SuitedUp); } diff --git a/QSB/Player/PlayerInfoParts/Tools.cs b/QSB/Player/PlayerInfoParts/Tools.cs index d74a2b75..bc01d36f 100644 --- a/QSB/Player/PlayerInfoParts/Tools.cs +++ b/QSB/Player/PlayerInfoParts/Tools.cs @@ -5,6 +5,7 @@ using QSB.RoastingSync; using QSB.Tools; using QSB.Tools.FlashlightTool; using QSB.Tools.ProbeLauncherTool; +using QSB.Tools.ProbeLauncherTool.WorldObjects; using QSB.Tools.ProbeTool; using QSB.Utility; using UnityEngine; @@ -18,7 +19,7 @@ public partial class PlayerInfo public QSBFlashlight FlashLight => CameraBody == null ? null : CameraBody.GetComponentInChildren(); public QSBTool Signalscope => GetToolByType(ToolType.Signalscope); public QSBTool Translator => GetToolByType(ToolType.Translator); - public QSBProbeLauncherTool ProbeLauncher => (QSBProbeLauncherTool)GetToolByType(ToolType.ProbeLauncher); + public QSBProbeLauncherTool ProbeLauncherTool => (QSBProbeLauncherTool)GetToolByType(ToolType.ProbeLauncher); private Transform _handPivot; public Transform HandPivot { @@ -80,9 +81,10 @@ public partial class PlayerInfo public IQSBItem HeldItem { get; set; } public bool FlashlightActive { get; set; } public bool SuitedUp { get; set; } - public bool ProbeLauncherEquipped { get; set; } + public bool LocalProbeLauncherEquipped { get; set; } public bool SignalscopeEquipped { get; set; } public bool TranslatorEquipped { get; set; } public bool ProbeActive { get; set; } public GameObject RoastingStick { get; set; } + public QSBProbeLauncher ProbeLauncherEquipped { get; set; } } diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index a101de8f..89f78d8e 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -24,6 +24,7 @@ internal class ShipManager : WorldObjectManager public ShipTractorBeamSwitch ShipTractorBeam; public ShipCockpitController CockpitController; public ShipElectricalComponent ShipElectricalComponent; + public ShipCockpitUI ShipCockpitUI; private GameObject _shipCustomAttach; public uint CurrentFlyer { @@ -66,6 +67,7 @@ internal class ShipManager : WorldObjectManager ShipTractorBeam = QSBWorldSync.GetUnityObjects().First(); CockpitController = QSBWorldSync.GetUnityObjects().First(); ShipElectricalComponent = QSBWorldSync.GetUnityObjects().First(); + ShipCockpitUI = QSBWorldSync.GetUnityObjects().First(); var sphereShape = HatchController.GetComponent(); sphereShape.radius = 2.5f; @@ -141,4 +143,22 @@ internal class ShipManager : WorldObjectManager } } } + + public void UpdateSignalscope(bool equipped) + { + ShipCockpitUI._displaySignalscopeScreen = equipped; + ShipCockpitUI._sigScopeScreenLight.SetOn(equipped); + ShipCockpitUI._shipAudioController.PlaySigScopeSlide(); + } + + public void UpdateProbeLauncher(bool equipped) + { + ShipCockpitUI._displayProbeLauncherScreen = equipped; + ShipCockpitUI._shipAudioController.PlayProbeScreenMotor(); + + if (!equipped) + { + ShipCockpitUI._probeLauncherScreenLight.SetOn(false); + } + } } \ No newline at end of file diff --git a/QSB/Tools/ProbeLauncherTool/Messages/EquipProbeLauncherMessage.cs b/QSB/Tools/ProbeLauncherTool/Messages/EquipProbeLauncherMessage.cs index 3b24d6a5..4db000cb 100644 --- a/QSB/Tools/ProbeLauncherTool/Messages/EquipProbeLauncherMessage.cs +++ b/QSB/Tools/ProbeLauncherTool/Messages/EquipProbeLauncherMessage.cs @@ -1,12 +1,14 @@ -using OWML.Common; -using QSB.Messaging; +using QSB.Messaging; using QSB.Player; using QSB.Player.TransformSync; +using QSB.ShipSync; +using QSB.Tools.ProbeLauncherTool.WorldObjects; using QSB.Utility; +using QSB.WorldSync; namespace QSB.Tools.ProbeLauncherTool.Messages; -public class EquipProbeLauncherMessage : QSBMessage +public class EquipProbeLauncherMessage : QSBWorldObjectMessage { static EquipProbeLauncherMessage() { @@ -14,37 +16,42 @@ public class EquipProbeLauncherMessage : QSBMessage GlobalMessenger.AddListener(OWEvents.ProbeLauncherUnequipped, launcher => Handle(launcher, false)); } - private static bool _nonPlayerLauncherEquipped; - private static void Handle(ProbeLauncher launcher, bool equipped) { - if (PlayerTransformSync.LocalInstance) + if (PlayerTransformSync.LocalInstance == null) { - if (launcher != QSBPlayerManager.LocalPlayer.LocalProbeLauncher) - { - _nonPlayerLauncherEquipped = equipped; - return; - } - - if (_nonPlayerLauncherEquipped) - { - DebugLog.ToConsole($"Warning - Trying to equip/unequip player launcher whilst non player launcher is still equipped?", MessageType.Warning); - return; - } - - new EquipProbeLauncherMessage(equipped).Send(); + return; } + + var local = launcher == QSBPlayerManager.LocalPlayer.LocalProbeLauncher; + + if (local) + { + new PlayerEquipLauncherMessage(equipped).Send(); + return; + } + + var worldObject = launcher.GetWorldObject(); + worldObject.SendMessage(new EquipProbeLauncherMessage(equipped)); } private EquipProbeLauncherMessage(bool equipped) : base(equipped) { } public override void OnReceiveRemote() { + DebugLog.DebugWrite($"{From} equip {WorldObject}"); + var player = QSBPlayerManager.GetPlayer(From); - player.ProbeLauncherEquipped = Data; - player.ProbeLauncher?.ChangeEquipState(Data); + player.ProbeLauncherEquipped = WorldObject; + + if (player.FlyingShip && WorldObject.AttachedObject == ShipManager.Instance.CockpitController.GetShipProbeLauncher()) + { + ShipManager.Instance.UpdateProbeLauncher(Data); + } } - public override void OnReceiveLocal() => - QSBPlayerManager.LocalPlayer.ProbeLauncherEquipped = Data; + public override void OnReceiveLocal() + { + QSBPlayerManager.LocalPlayer.ProbeLauncherEquipped = WorldObject; + } } \ No newline at end of file diff --git a/QSB/Tools/ProbeLauncherTool/Messages/PlayerEquipLauncherMessage.cs b/QSB/Tools/ProbeLauncherTool/Messages/PlayerEquipLauncherMessage.cs new file mode 100644 index 00000000..74ddf8c8 --- /dev/null +++ b/QSB/Tools/ProbeLauncherTool/Messages/PlayerEquipLauncherMessage.cs @@ -0,0 +1,21 @@ +using QSB.Messaging; +using QSB.Player; + +namespace QSB.Tools.ProbeLauncherTool.Messages; + +internal class PlayerEquipLauncherMessage : QSBMessage +{ + public PlayerEquipLauncherMessage(bool equipped) : base(equipped) { } + + public override void OnReceiveRemote() + { + var player = QSBPlayerManager.GetPlayer(From); + player.LocalProbeLauncherEquipped = Data; + player.ProbeLauncherTool?.ChangeEquipState(Data); + } + + public override void OnReceiveLocal() + { + QSBPlayerManager.LocalPlayer.LocalProbeLauncherEquipped = Data; + } +} diff --git a/QSB/Tools/ProbeLauncherTool/Messages/PlayerLaunchProbeMessage.cs b/QSB/Tools/ProbeLauncherTool/Messages/PlayerLaunchProbeMessage.cs index ebae6a9a..95bddbe8 100644 --- a/QSB/Tools/ProbeLauncherTool/Messages/PlayerLaunchProbeMessage.cs +++ b/QSB/Tools/ProbeLauncherTool/Messages/PlayerLaunchProbeMessage.cs @@ -11,6 +11,6 @@ internal class PlayerLaunchProbeMessage : QSBMessage public override void OnReceiveRemote() { var player = QSBPlayerManager.GetPlayer(From); - player.ProbeLauncher.LaunchProbe(); + player.ProbeLauncherTool.LaunchProbe(); } } \ No newline at end of file diff --git a/QSB/Tools/ProbeLauncherTool/Messages/PlayerRetrieveProbeMessage.cs b/QSB/Tools/ProbeLauncherTool/Messages/PlayerRetrieveProbeMessage.cs index 1e5c3cc0..4fd48ef4 100644 --- a/QSB/Tools/ProbeLauncherTool/Messages/PlayerRetrieveProbeMessage.cs +++ b/QSB/Tools/ProbeLauncherTool/Messages/PlayerRetrieveProbeMessage.cs @@ -13,6 +13,6 @@ internal class PlayerRetrieveProbeMessage : QSBMessage public override void OnReceiveRemote() { var player = QSBPlayerManager.GetPlayer(From); - player.ProbeLauncher.RetrieveProbe(Data); + player.ProbeLauncherTool.RetrieveProbe(Data); } } \ No newline at end of file diff --git a/QSB/Tools/ProbeLauncherTool/WorldObjects/QSBProbeLauncher.cs b/QSB/Tools/ProbeLauncherTool/WorldObjects/QSBProbeLauncher.cs index 84a03286..80742aca 100644 --- a/QSB/Tools/ProbeLauncherTool/WorldObjects/QSBProbeLauncher.cs +++ b/QSB/Tools/ProbeLauncherTool/WorldObjects/QSBProbeLauncher.cs @@ -6,7 +6,7 @@ using System.Threading; namespace QSB.Tools.ProbeLauncherTool.WorldObjects; -internal class QSBProbeLauncher : WorldObject +public class QSBProbeLauncher : WorldObject { public override async UniTask Init(CancellationToken ct) => AttachedObject.OnLaunchProbe += OnLaunchProbe; diff --git a/QSB/Tools/ProbeTool/QSBProbe.cs b/QSB/Tools/ProbeTool/QSBProbe.cs index 0500a3e7..d0427f32 100644 --- a/QSB/Tools/ProbeTool/QSBProbe.cs +++ b/QSB/Tools/ProbeTool/QSBProbe.cs @@ -86,8 +86,8 @@ public class QSBProbe : MonoBehaviour, ILightSource gameObject.SetActive(true); _lightSourceVol.SetVolumeActivation(true); - transform.position = _owner.ProbeLauncher.transform.position; - transform.rotation = _owner.ProbeLauncher.transform.rotation; + transform.position = _owner.ProbeLauncherTool.transform.position; + transform.rotation = _owner.ProbeLauncherTool.transform.rotation; if (OnLaunchProbe == null) { diff --git a/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs b/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs index 495846af..e0d95b59 100644 --- a/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs +++ b/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs @@ -1,7 +1,9 @@ using OWML.Common; using QSB.Syncs.Sectored.Transforms; using QSB.Tools.ProbeLauncherTool; +using QSB.Tools.ProbeLauncherTool.WorldObjects; using QSB.Utility; +using QSB.WorldSync; using UnityEngine; namespace QSB.Tools.ProbeTool.TransformSync; @@ -58,9 +60,11 @@ public class PlayerProbeSync : SectoredTransformSync DebugLog.ToConsole($"Warning - Could not find OWRigidbody of local probe.", MessageType.Warning); } - var probeLauncher = Player.LocalProbeLauncher; - // TODO : make this sync to the *active* probe launcher's _launcherTransform - var launcherTransform = probeLauncher._launcherTransform; + var probeLauncher = Player.ProbeLauncherEquipped; + var launcherTransform = probeLauncher == null + ? Player.LocalProbeLauncher._launcherTransform + : probeLauncher.AttachedObject._launcherTransform; + probeBody.SetPosition(launcherTransform.position); probeBody.SetRotation(launcherTransform.rotation); diff --git a/QSB/Tools/QSBTool.cs b/QSB/Tools/QSBTool.cs index 23a0593b..49fdee06 100644 --- a/QSB/Tools/QSBTool.cs +++ b/QSB/Tools/QSBTool.cs @@ -46,7 +46,13 @@ public class QSBTool : PlayerTool _ditheringAnimator.SetVisible(false); } - public virtual void OnEnable() => ToolGameObject?.SetActive(true); + public virtual void OnEnable() + { + if (!Player.FlyingShip) + { + ToolGameObject?.SetActive(true); + } + } public virtual void OnDisable() { @@ -77,7 +83,10 @@ public class QSBTool : PlayerTool _ditheringAnimator.SetVisible(true, .2f); } - Player.AudioController.PlayEquipTool(); + if (!Player.FlyingShip) + { + Player.AudioController.PlayEquipTool(); + } } public override void UnequipTool() diff --git a/QSB/Tools/SignalscopeTool/Messages/PlayerSignalscopeMessage.cs b/QSB/Tools/SignalscopeTool/Messages/PlayerSignalscopeMessage.cs index b4128660..0a732e53 100644 --- a/QSB/Tools/SignalscopeTool/Messages/PlayerSignalscopeMessage.cs +++ b/QSB/Tools/SignalscopeTool/Messages/PlayerSignalscopeMessage.cs @@ -1,6 +1,7 @@ using QSB.Messaging; using QSB.Player; using QSB.Player.TransformSync; +using QSB.ShipSync; namespace QSB.Tools.SignalscopeTool.Messages; @@ -27,6 +28,11 @@ public class PlayerSignalscopeMessage : QSBMessage var player = QSBPlayerManager.GetPlayer(From); player.SignalscopeEquipped = Data; player.Signalscope?.ChangeEquipState(Data); + + if (player.FlyingShip) + { + ShipManager.Instance.UpdateSignalscope(Data); + } } public override void OnReceiveLocal() => From 17f769a60a7e3795a43a08c69144b51a6995c69c Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 16 Apr 2022 10:32:25 +0100 Subject: [PATCH 02/17] Update EquipProbeLauncherMessage.cs --- .../ProbeLauncherTool/Messages/EquipProbeLauncherMessage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QSB/Tools/ProbeLauncherTool/Messages/EquipProbeLauncherMessage.cs b/QSB/Tools/ProbeLauncherTool/Messages/EquipProbeLauncherMessage.cs index 4db000cb..c2ef4196 100644 --- a/QSB/Tools/ProbeLauncherTool/Messages/EquipProbeLauncherMessage.cs +++ b/QSB/Tools/ProbeLauncherTool/Messages/EquipProbeLauncherMessage.cs @@ -42,7 +42,7 @@ public class EquipProbeLauncherMessage : QSBWorldObjectMessage Date: Sat, 16 Apr 2022 21:31:01 +0100 Subject: [PATCH 03/17] sync ship lights --- QSB/ShipSync/Messages/LandingCameraMessage.cs | 19 +++++ QSB/ShipSync/Messages/ShipLightMessage.cs | 20 +++++ QSB/ShipSync/Patches/ShipPatches.cs | 76 +++++++++++++++++++ QSB/ShipSync/ShipManager.cs | 50 +++++++++++- QSB/ShipSync/WorldObjects/QSBShipLight.cs | 37 +++++++++ QSB/WorldSync/QSBWorldSync.cs | 3 + 6 files changed, 202 insertions(+), 3 deletions(-) create mode 100644 QSB/ShipSync/Messages/LandingCameraMessage.cs create mode 100644 QSB/ShipSync/Messages/ShipLightMessage.cs create mode 100644 QSB/ShipSync/WorldObjects/QSBShipLight.cs diff --git a/QSB/ShipSync/Messages/LandingCameraMessage.cs b/QSB/ShipSync/Messages/LandingCameraMessage.cs new file mode 100644 index 00000000..c42a6c32 --- /dev/null +++ b/QSB/ShipSync/Messages/LandingCameraMessage.cs @@ -0,0 +1,19 @@ +using QSB.Messaging; +using QSB.Utility; + +namespace QSB.ShipSync.Messages; + +internal class LandingCameraMessage : QSBMessage +{ + public LandingCameraMessage(bool on) : base(on) { } + + public override void OnReceiveRemote() + { + if (From != ShipManager.Instance.CurrentFlyer) + { + DebugLog.ToConsole($"Warning - Received LandingCameraMessage from someone who isn't flying the ship!", OWML.Common.MessageType.Warning); + } + + ShipManager.Instance.UpdateLandingCamera(Data); + } +} diff --git a/QSB/ShipSync/Messages/ShipLightMessage.cs b/QSB/ShipSync/Messages/ShipLightMessage.cs new file mode 100644 index 00000000..6ee6c9ef --- /dev/null +++ b/QSB/ShipSync/Messages/ShipLightMessage.cs @@ -0,0 +1,20 @@ +using QSB.Messaging; +using QSB.ShipSync.WorldObjects; +using QSB.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QSB.ShipSync.Messages; + +internal class ShipLightMessage : QSBWorldObjectMessage +{ + public ShipLightMessage(bool on) : base(on) { } + + public override void OnReceiveRemote() + { + WorldObject.SetOn(Data); + } +} diff --git a/QSB/ShipSync/Patches/ShipPatches.cs b/QSB/ShipSync/Patches/ShipPatches.cs index 372f86d8..458c1895 100644 --- a/QSB/ShipSync/Patches/ShipPatches.cs +++ b/QSB/ShipSync/Patches/ShipPatches.cs @@ -1,6 +1,7 @@ using HarmonyLib; using QSB.Messaging; using QSB.Patches; +using QSB.Player; using QSB.ShipSync.Messages; using QSB.ShipSync.Messages.Component; using QSB.ShipSync.Messages.Hull; @@ -8,6 +9,7 @@ using QSB.ShipSync.TransformSync; using QSB.ShipSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; +using System; using UnityEngine; namespace QSB.ShipSync.Patches; @@ -252,4 +254,78 @@ internal class ShipPatches : QSBPatch return false; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipCockpitController), nameof(ShipCockpitController.EnterLandingView))] + public static bool EnterLandingView() + { + new LandingCameraMessage(true).Send(); + return true; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipCockpitController), nameof(ShipCockpitController.ExitLandingView))] + public static bool ExitLandingView() + { + new LandingCameraMessage(false).Send(); + return true; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipLight), nameof(ShipLight.SetOn))] + public static bool SetOn(ShipLight __instance, bool on) + { + if (!QSBWorldSync.WorldObjectExistsFor(__instance)) + { + return true; + } + + if (QSBPlayerManager.LocalPlayerId != ShipManager.Instance.CurrentFlyer) + { + return false; + } + + var worldObject = __instance.GetWorldObject(); + + if (__instance.IsOn() != on) + { + worldObject.SendMessage(new ShipLightMessage(on)); + + worldObject.SetOn(on); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipCockpitUI), nameof(ShipCockpitUI.UpdateSignalscopeCanvas))] + public static bool UpdateSignalscopeCanvas(ShipCockpitUI __instance) + { + var flag = false; + if (Locator.GetToolModeSwapper().GetToolMode() != ToolMode.SignalScope) + { + if (__instance._signalscopeUI.IsActivated()) + { + __instance._signalscopeUI.Deactivate(); + } + } + else if (ShipManager.Instance.CurrentFlyer != uint.MaxValue) + { + flag = true; + if (!__instance._signalscopeUI.IsActivated()) + { + if (__instance._reticuleController == null) + { + Debug.LogError("ReticuleController cannot be null!"); + } + + __instance._signalscopeUI.Activate(__instance._signalscopeTool, __instance._reticuleController); + } + } + + __instance._scopeScreenMaterial.SetColor(__instance._propID_EmissionColor, __instance._scopeScreenColor * (flag ? 1f : 0f)); + __instance._sigScopeScreenLight.SetOn(flag); + + return false; + } } \ No newline at end of file diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index 89f78d8e..7db40e79 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -100,6 +100,21 @@ internal class ShipManager : WorldObjectManager _shipCustomAttach = new GameObject(nameof(ShipCustomAttach)); _shipCustomAttach.transform.SetParent(shipBody.transform, false); _shipCustomAttach.AddComponent(); + + QSBWorldSync.Init(new List() + { + CockpitController._headlight, + CockpitController._landingLight, + ShipCockpitUI._altimeterLight, + ShipCockpitUI._landingCamScreenLight, + ShipCockpitUI._minimapLight, + ShipCockpitUI._minimapNorthPoleLight, + ShipCockpitUI._minimapProbeLight, + ShipCockpitUI._minimapShipLight, + ShipCockpitUI._minimapSouthPoleLight, + ShipCockpitUI._probeLauncherScreenLight, + ShipCockpitUI._sigScopeScreenLight + }); } public override void UnbuildWorldObjects() => Destroy(_shipCustomAttach); @@ -147,7 +162,6 @@ internal class ShipManager : WorldObjectManager public void UpdateSignalscope(bool equipped) { ShipCockpitUI._displaySignalscopeScreen = equipped; - ShipCockpitUI._sigScopeScreenLight.SetOn(equipped); ShipCockpitUI._shipAudioController.PlaySigScopeSlide(); } @@ -155,10 +169,40 @@ internal class ShipManager : WorldObjectManager { ShipCockpitUI._displayProbeLauncherScreen = equipped; ShipCockpitUI._shipAudioController.PlayProbeScreenMotor(); + } - if (!equipped) + public void UpdateLandingCamera(bool on) + { + if (on) { - ShipCockpitUI._probeLauncherScreenLight.SetOn(false); + EnterLandingView(); + return; } + + ExitLandingView(); + } + + private void EnterLandingView() + { + if (CockpitController._landingCam.mode == LandingCamera.Mode.Double) + { + CockpitController._landingCam.enabled = true; + } + + if (CockpitController._landingCamComponent.isDamaged) + { + CockpitController._shipAudioController.PlayLandingCamOn(AudioType.ShipCockpitLandingCamStatic_LP); + CockpitController._shipAudioController.PlayLandingCamStatic(0.25f); + return; + } + + CockpitController._shipAudioController.PlayLandingCamOn(AudioType.ShipCockpitLandingCamAmbient_LP); + CockpitController._shipAudioController.PlayLandingCamAmbient(0.25f); + } + + private void ExitLandingView() + { + CockpitController._landingCam.enabled = false; + CockpitController._shipAudioController.PlayLandingCamOff(); } } \ No newline at end of file diff --git a/QSB/ShipSync/WorldObjects/QSBShipLight.cs b/QSB/ShipSync/WorldObjects/QSBShipLight.cs new file mode 100644 index 00000000..43f6c3c1 --- /dev/null +++ b/QSB/ShipSync/WorldObjects/QSBShipLight.cs @@ -0,0 +1,37 @@ +using QSB.Messaging; +using QSB.Player; +using QSB.ShipSync.Messages; +using QSB.Utility; +using QSB.WorldSync; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace QSB.ShipSync.WorldObjects; + +internal class QSBShipLight : WorldObject +{ + public override void SendInitialState(uint to) + { + // todo : add this + } + + public void SetOn(bool on) + { + AttachedObject._on = on; + AttachedObject._startIntensity = AttachedObject._light.intensity; + AttachedObject._targetIntensity = (AttachedObject._on && !AttachedObject._damaged && AttachedObject._powered) + ? (AttachedObject._baseIntensity * AttachedObject._intensityScale) + : 0f; + AttachedObject._fadeStartTime = Time.time; + if (AttachedObject._lightSourceVol != null) + { + AttachedObject._lightSourceVol.SetVolumeActivation(AttachedObject._on); + } + + AttachedObject.enabled = true; + } +} diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 69fe28f5..54c4af91 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -245,6 +245,9 @@ public static class QSBWorldSync return (TWorldObject)worldObject; } + public static bool WorldObjectExistsFor(this MonoBehaviour unityObject) + => unityObject != null && UnityObjectsToWorldObjects.ContainsKey(unityObject); + /// /// not deterministic across platforms /// From 06f5a99f37f25e204a51a64938ebcce915289749 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 16 Apr 2022 21:37:15 +0100 Subject: [PATCH 04/17] fix signalscope --- QSB/Tools/QSBTool.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/QSB/Tools/QSBTool.cs b/QSB/Tools/QSBTool.cs index 49fdee06..908252ac 100644 --- a/QSB/Tools/QSBTool.cs +++ b/QSB/Tools/QSBTool.cs @@ -77,16 +77,17 @@ public class QSBTool : PlayerTool { base.EquipTool(); - if (_ditheringAnimator != null) - { - ToolGameObject?.SetActive(true); - _ditheringAnimator.SetVisible(true, .2f); - } - if (!Player.FlyingShip) { + ToolGameObject?.SetActive(true); Player.AudioController.PlayEquipTool(); } + + if (_ditheringAnimator != null) + { + + _ditheringAnimator.SetVisible(true, .2f); + } } public override void UnequipTool() From 942535c16281b0165032ddef3c37b0d4d7f4f658 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 14 May 2022 12:18:48 +0100 Subject: [PATCH 05/17] sync detaching --- QSB/DeathSync/Patches/DeathPatches.cs | 31 ------------- QSB/Player/Messages/PlayerJoinMessage.cs | 3 ++ QSB/QSBNetworkManager.cs | 8 ++++ QSB/ShipSync/Messages/ModuleDetachMessage.cs | 17 +++++++ .../Patches/ShipDetachableModulePatches.cs | 23 ++++++++++ QSB/ShipSync/ShipManager.cs | 3 ++ .../TransformSync/ShipLegTransformSync.cs | 45 +++++++++++++++++++ .../TransformSync/ShipModuleTransformSync.cs | 45 +++++++++++++++++++ .../WorldObjects/QSBShipDetachableLeg.cs | 21 +++++++++ .../WorldObjects/QSBShipDetachableModule.cs | 21 +++++++++ QSB/Utility/LinkedWorldObject/Extensions.cs | 2 + QSB/manifest.json | 2 +- 12 files changed, 189 insertions(+), 32 deletions(-) create mode 100644 QSB/ShipSync/Messages/ModuleDetachMessage.cs create mode 100644 QSB/ShipSync/Patches/ShipDetachableModulePatches.cs create mode 100644 QSB/ShipSync/TransformSync/ShipLegTransformSync.cs create mode 100644 QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs create mode 100644 QSB/ShipSync/WorldObjects/QSBShipDetachableLeg.cs create mode 100644 QSB/ShipSync/WorldObjects/QSBShipDetachableModule.cs diff --git a/QSB/DeathSync/Patches/DeathPatches.cs b/QSB/DeathSync/Patches/DeathPatches.cs index 349d5fcb..df3bf8ad 100644 --- a/QSB/DeathSync/Patches/DeathPatches.cs +++ b/QSB/DeathSync/Patches/DeathPatches.cs @@ -15,30 +15,6 @@ public class DeathPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - // TODO : Remove with future functionality. - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipEjectionSystem), nameof(ShipEjectionSystem.OnPressInteract))] - public static bool DisableEjection() - => false; - - // TODO : Remove with future functionality. - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipDetachableLeg), nameof(ShipDetachableLeg.Detach))] - public static bool ShipDetachableLeg_Detach(out OWRigidbody __result) - { - __result = null; - return false; - } - - // TODO : Remove with future functionality. - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipDetachableModule), nameof(ShipDetachableModule.Detach))] - public static bool ShipDetachableModule_Detach(out OWRigidbody __result) - { - __result = null; - return false; - } - [HarmonyPrefix] [HarmonyPatch(typeof(PlayerResources), nameof(PlayerResources.OnImpact))] public static bool PlayerResources_OnImpact(PlayerResources __instance, ImpactData impact) => @@ -260,13 +236,6 @@ public class DeathPatches : QSBPatch } } - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipDamageController), nameof(ShipDamageController.Explode))] - public static bool ShipDamageController_Explode() - // prevent ship from exploding - // todo remove this when sync ship explosions - => false; - [HarmonyPrefix] [HarmonyPatch(typeof(DestructionVolume), nameof(DestructionVolume.VanishShip))] public static bool DestructionVolume_VanishShip(DestructionVolume __instance) diff --git a/QSB/Player/Messages/PlayerJoinMessage.cs b/QSB/Player/Messages/PlayerJoinMessage.cs index 363ff291..b24fea96 100644 --- a/QSB/Player/Messages/PlayerJoinMessage.cs +++ b/QSB/Player/Messages/PlayerJoinMessage.cs @@ -28,6 +28,8 @@ public class PlayerJoinMessage : QSBMessage var allEnabledMods = QSBCore.Helper.Interaction.GetMods(); FirstIncompatibleMod = ""; + +#if RELEASE foreach (var mod in allEnabledMods) { if (QSBCore.IncompatibleMods.Contains(mod.ModHelper.Manifest.UniqueName)) @@ -35,6 +37,7 @@ public class PlayerJoinMessage : QSBMessage FirstIncompatibleMod = mod.ModHelper.Manifest.UniqueName; } } +#endif AddonHashes = QSBCore.Addons.Keys .Select(x => x.GetStableHashCode()) diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 04b33b53..e2fdea95 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -49,6 +49,8 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart public GameObject DoorPrefab { get; private set; } public GameObject ElevatorPrefab { get; private set; } public GameObject AirlockPrefab { get; private set; } + public GameObject ShipModulePrefab { get; private set; } + public GameObject ShipLegPrefab { get; private set; } private string PlayerName { get; set; } private GameObject _probePrefab; @@ -130,6 +132,12 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart AirlockPrefab = MakeNewNetworkObject(11, "NetworkGhostAirlock", typeof(AirlockVariableSyncer)); spawnPrefabs.Add(AirlockPrefab); + ShipModulePrefab = MakeNewNetworkObject(12, "NetworkShipModule", typeof(ShipModuleTransformSync)); + spawnPrefabs.Add(ShipModulePrefab); + + ShipLegPrefab = MakeNewNetworkObject(13, "NetworkShipLeg", typeof(ShipLegTransformSync)); + spawnPrefabs.Add(ShipLegPrefab); + ConfigureNetworkManager(); } diff --git a/QSB/ShipSync/Messages/ModuleDetachMessage.cs b/QSB/ShipSync/Messages/ModuleDetachMessage.cs new file mode 100644 index 00000000..89791b46 --- /dev/null +++ b/QSB/ShipSync/Messages/ModuleDetachMessage.cs @@ -0,0 +1,17 @@ +using QSB.Messaging; +using QSB.ShipSync.WorldObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QSB.ShipSync.Messages; + +internal class ModuleDetachMessage : QSBWorldObjectMessage +{ + public override void OnReceiveRemote() + { + WorldObject.AttachedObject.Detach(); + } +} diff --git a/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs b/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs new file mode 100644 index 00000000..a82af62b --- /dev/null +++ b/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs @@ -0,0 +1,23 @@ +using HarmonyLib; +using QSB.Messaging; +using QSB.Patches; +using QSB.ShipSync.Messages; +using QSB.ShipSync.WorldObjects; +using QSB.Utility; +using QSB.WorldSync; +using UnityEngine; + +namespace QSB.ShipSync.Patches; + +[HarmonyPatch(typeof(ShipDetachableModule))] +internal class ShipDetachableModulePatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPostfix] + [HarmonyPatch(nameof(ShipDetachableModule.Detach))] + public static void Detach(ShipDetachableModule __instance) + { + __instance.GetWorldObject().SendMessage(new ModuleDetachMessage()); + } +} diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index ccb4190a..91375a08 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -128,6 +128,9 @@ internal class ShipManager : WorldObjectManager ShipCockpitUI._probeLauncherScreenLight, ShipCockpitUI._sigScopeScreenLight }); + + QSBWorldSync.Init(); + QSBWorldSync.Init(); } public override void UnbuildWorldObjects() => Destroy(_shipCustomAttach); diff --git a/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs b/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs new file mode 100644 index 00000000..3556bc0c --- /dev/null +++ b/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs @@ -0,0 +1,45 @@ +using QSB.ShipSync.WorldObjects; +using QSB.Syncs.Sectored.Rigidbodies; +using QSB.Utility.LinkedWorldObject; +using QSB.WorldSync; + +namespace QSB.ShipSync.TransformSync; + +internal class ShipLegTransformSync : SectoredRigidbodySync, ILinkedNetworkBehaviour +{ + /// + /// normally prints error when attached object is null. + /// this overrides it so that doesn't happen, since the module can be destroyed. + /// + protected override bool CheckValid() + => AttachedTransform + && base.CheckValid(); + + protected override bool CheckReady() + => _qsbModule != null + && _qsbModule.AttachedObject.isDetached + && base.CheckReady(); + + protected override bool UseInterpolation => true; + protected override float DistanceChangeThreshold => 1f; + + private QSBShipDetachableLeg _qsbModule; + public void SetWorldObject(IWorldObject worldObject) => _qsbModule = (QSBShipDetachableLeg)worldObject; + + protected override OWRigidbody InitAttachedRigidbody() + { + var owRigidbody = _qsbModule.AttachedObject.GetComponent(); + SectorDetector.Init(owRigidbody.transform.Find("DetectorVolume").GetComponent()); + return owRigidbody; + } + + protected override void ApplyToAttached() + { + if (!_qsbModule.AttachedObject.isDetached) + { + return; + } + + base.ApplyToAttached(); + } +} diff --git a/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs b/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs new file mode 100644 index 00000000..71814185 --- /dev/null +++ b/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs @@ -0,0 +1,45 @@ +using QSB.ShipSync.WorldObjects; +using QSB.Syncs.Sectored.Rigidbodies; +using QSB.Utility.LinkedWorldObject; +using QSB.WorldSync; + +namespace QSB.ShipSync.TransformSync; + +internal class ShipModuleTransformSync : SectoredRigidbodySync, ILinkedNetworkBehaviour +{ + /// + /// normally prints error when attached object is null. + /// this overrides it so that doesn't happen, since the module can be destroyed. + /// + protected override bool CheckValid() + => AttachedTransform + && base.CheckValid(); + + protected override bool CheckReady() + => _qsbModule != null + && _qsbModule.AttachedObject.isDetached + && base.CheckReady(); + + protected override bool UseInterpolation => true; + protected override float DistanceChangeThreshold => 1f; + + private QSBShipDetachableModule _qsbModule; + public void SetWorldObject(IWorldObject worldObject) => _qsbModule = (QSBShipDetachableModule)worldObject; + + protected override OWRigidbody InitAttachedRigidbody() + { + var owRigidbody = _qsbModule.AttachedObject.GetComponent(); + SectorDetector.Init(owRigidbody.transform.Find("DetectorVolume").GetComponent()); + return owRigidbody; + } + + protected override void ApplyToAttached() + { + if (!_qsbModule.AttachedObject.isDetached) + { + return; + } + + base.ApplyToAttached(); + } +} diff --git a/QSB/ShipSync/WorldObjects/QSBShipDetachableLeg.cs b/QSB/ShipSync/WorldObjects/QSBShipDetachableLeg.cs new file mode 100644 index 00000000..cd49af02 --- /dev/null +++ b/QSB/ShipSync/WorldObjects/QSBShipDetachableLeg.cs @@ -0,0 +1,21 @@ +using QSB.ShipSync.TransformSync; +using QSB.Utility.LinkedWorldObject; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace QSB.ShipSync.WorldObjects; + +internal class QSBShipDetachableLeg : LinkedWorldObject +{ + protected override GameObject NetworkObjectPrefab => QSBNetworkManager.singleton.ShipLegPrefab; + protected override bool SpawnWithServerAuthority => true; + + public override void SendInitialState(uint to) + { + + } +} diff --git a/QSB/ShipSync/WorldObjects/QSBShipDetachableModule.cs b/QSB/ShipSync/WorldObjects/QSBShipDetachableModule.cs new file mode 100644 index 00000000..c314f4ed --- /dev/null +++ b/QSB/ShipSync/WorldObjects/QSBShipDetachableModule.cs @@ -0,0 +1,21 @@ +using QSB.ShipSync.TransformSync; +using QSB.Utility.LinkedWorldObject; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace QSB.ShipSync.WorldObjects; + +internal class QSBShipDetachableModule : LinkedWorldObject +{ + protected override GameObject NetworkObjectPrefab => QSBNetworkManager.singleton.ShipModulePrefab; + protected override bool SpawnWithServerAuthority => true; + + public override void SendInitialState(uint to) + { + + } +} diff --git a/QSB/Utility/LinkedWorldObject/Extensions.cs b/QSB/Utility/LinkedWorldObject/Extensions.cs index 97b0b69d..bbf76e93 100644 --- a/QSB/Utility/LinkedWorldObject/Extensions.cs +++ b/QSB/Utility/LinkedWorldObject/Extensions.cs @@ -22,6 +22,8 @@ public static class Extensions /// public static void SpawnLinked(this ILinkedWorldObject worldObject, GameObject prefab, bool spawnWithServerAuthority) { + DebugLog.DebugWrite($"SpawnLinked {prefab.name}"); + var go = Object.Instantiate(prefab); var networkBehaviour = go.GetComponent(); diff --git a/QSB/manifest.json b/QSB/manifest.json index 5d9444e9..b9991496 100644 --- a/QSB/manifest.json +++ b/QSB/manifest.json @@ -9,6 +9,6 @@ "uniqueName": "Raicuparta.QuantumSpaceBuddies", "version": "0.19.0", "owmlVersion": "2.3.3", - "dependencies": [ "_nebula.MenuFramework" ], + "dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ], "pathsToPreserve": [ "debugsettings.json", "storage.json" ] } From d6cbd55dc1ff3a3edef746c805d836eea0ec4359 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 14 May 2022 13:15:06 +0100 Subject: [PATCH 06/17] dont do the respawn stuff when ship is destroyed --- QSB/RespawnSync/RespawnHUDMarker.cs | 9 ++++++--- QSB/RespawnSync/RespawnManager.cs | 17 ----------------- QSB/RespawnSync/ShipRecoveryPoint.cs | 5 +++-- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/QSB/RespawnSync/RespawnHUDMarker.cs b/QSB/RespawnSync/RespawnHUDMarker.cs index 87a25412..b52329cb 100644 --- a/QSB/RespawnSync/RespawnHUDMarker.cs +++ b/QSB/RespawnSync/RespawnHUDMarker.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using QSB.ShipSync; +using UnityEngine; namespace QSB.RespawnSync; @@ -26,10 +27,12 @@ public class RespawnHUDMarker : HUDDistanceMarker if (_canvasMarker != null) { var isVisible = _canvasMarker.IsVisible(); + var shouldBeVisible = RespawnManager.Instance.RespawnNeeded + && !ShipManager.Instance.ShipCockpitUI._shipDamageCtrlr.IsDestroyed(); - if (RespawnManager.Instance.RespawnNeeded != isVisible) + if (shouldBeVisible != isVisible) { - _isVisible = RespawnManager.Instance.RespawnNeeded; + _isVisible = shouldBeVisible; _canvasMarker.SetVisibility(_isVisible); } } diff --git a/QSB/RespawnSync/RespawnManager.cs b/QSB/RespawnSync/RespawnManager.cs index 334965f7..ab2aa021 100644 --- a/QSB/RespawnSync/RespawnManager.cs +++ b/QSB/RespawnSync/RespawnManager.cs @@ -35,7 +35,6 @@ internal class RespawnManager : MonoBehaviour, IAddComponentOnStart QSBPlayerManager.OnRemovePlayer += player => { _playersPendingRespawn.Remove(player); - UpdateRespawnNotification(); }; } @@ -148,7 +147,6 @@ internal class RespawnManager : MonoBehaviour, IAddComponentOnStart player.IsDead = true; _playersPendingRespawn.Add(player); - UpdateRespawnNotification(); var deadPlayersCount = QSBPlayerManager.PlayerList.Count(x => x.IsDead); @@ -172,7 +170,6 @@ internal class RespawnManager : MonoBehaviour, IAddComponentOnStart player.IsDead = false; _playersPendingRespawn.Remove(player); - UpdateRespawnNotification(); player.SetVisible(true, 1); } @@ -182,18 +179,4 @@ internal class RespawnManager : MonoBehaviour, IAddComponentOnStart var playerToRespawn = _playersPendingRespawn.First(); new PlayerRespawnMessage(playerToRespawn.PlayerId).Send(); } - - private void UpdateRespawnNotification() - { - NotificationManager.SharedInstance.UnpinNotification(_previousNotification); - - if (_playersPendingRespawn.Count == 0) - { - return; - } - - var data = new NotificationData(NotificationTarget.Player, $"[{_playersPendingRespawn.Count}] PLAYER(S) AWAITING RESPAWN"); - NotificationManager.SharedInstance.PostNotification(data, true); - _previousNotification = data; - } } \ No newline at end of file diff --git a/QSB/RespawnSync/ShipRecoveryPoint.cs b/QSB/RespawnSync/ShipRecoveryPoint.cs index 0a54d193..6c2f8c62 100644 --- a/QSB/RespawnSync/ShipRecoveryPoint.cs +++ b/QSB/RespawnSync/ShipRecoveryPoint.cs @@ -1,4 +1,5 @@ using QSB.Messaging; +using QSB.ShipSync; using QSB.Utility; using UnityEngine; @@ -56,7 +57,7 @@ internal class ShipRecoveryPoint : MonoBehaviour _playerResources = Locator.GetPlayerTransform().GetComponent(); } - if (RespawnManager.Instance.RespawnNeeded) + if (RespawnManager.Instance.RespawnNeeded && !ShipManager.Instance.ShipCockpitUI._shipDamageCtrlr.IsDestroyed()) { _interactVolume.EnableSingleInteraction(true, _respawnIndex); _interactVolume.SetKeyCommandVisible(true, _respawnIndex); @@ -124,7 +125,7 @@ internal class ShipRecoveryPoint : MonoBehaviour } else if (inputCommand == _interactVolume.GetInteractionAt(_respawnIndex).inputCommand) { - if (!RespawnManager.Instance.RespawnNeeded) + if (!RespawnManager.Instance.RespawnNeeded || ShipManager.Instance.ShipCockpitUI._shipDamageCtrlr.IsDestroyed()) { return; } From 582166cb82d7ad50ca69975d9fa8dde89f1eaf2c Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 14 May 2022 14:04:49 +0100 Subject: [PATCH 07/17] reactor countdown sync --- .../Messages/ReactorCountdownMessage.cs | 17 +++++++++++++++++ QSB/ShipSync/Patches/ShipPatches.cs | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 QSB/ShipSync/Messages/ReactorCountdownMessage.cs diff --git a/QSB/ShipSync/Messages/ReactorCountdownMessage.cs b/QSB/ShipSync/Messages/ReactorCountdownMessage.cs new file mode 100644 index 00000000..7d88a5bc --- /dev/null +++ b/QSB/ShipSync/Messages/ReactorCountdownMessage.cs @@ -0,0 +1,17 @@ +using QSB.Messaging; +using QSB.WorldSync; + +namespace QSB.ShipSync.Messages; + +internal class ReactorCountdownMessage : QSBMessage +{ + public ReactorCountdownMessage(float countdown) : base(countdown) { } + + public override void OnReceiveRemote() + { + var reactor = QSBWorldSync.GetUnityObject(); + reactor._criticalCountdown = Data; + reactor._criticalTimer = Data; + reactor.enabled = true; + } +} diff --git a/QSB/ShipSync/Patches/ShipPatches.cs b/QSB/ShipSync/Patches/ShipPatches.cs index 458c1895..d3afb4cf 100644 --- a/QSB/ShipSync/Patches/ShipPatches.cs +++ b/QSB/ShipSync/Patches/ShipPatches.cs @@ -328,4 +328,21 @@ internal class ShipPatches : QSBPatch return false; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipReactorComponent), nameof(ShipReactorComponent.OnComponentDamaged))] + public static bool ByeByeReactor(ShipReactorComponent __instance) + { + if (!QSBCore.IsHost) + { + return false; + } + + __instance._criticalCountdown = UnityEngine.Random.Range(__instance._minCountdown, __instance._maxCountdown); + __instance._criticalTimer = __instance._criticalCountdown; + __instance.enabled = true; + new ReactorCountdownMessage(__instance._criticalCountdown).Send(); + + return false; + } } \ No newline at end of file From e0940ae0114ada406c75dfbf9d49b3582a3d6cc8 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 14 May 2022 14:33:49 +0100 Subject: [PATCH 08/17] destroy ship in the sun --- QSB/DeathSync/Patches/DeathPatches.cs | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/QSB/DeathSync/Patches/DeathPatches.cs b/QSB/DeathSync/Patches/DeathPatches.cs index df3bf8ad..f0f6b8fe 100644 --- a/QSB/DeathSync/Patches/DeathPatches.cs +++ b/QSB/DeathSync/Patches/DeathPatches.cs @@ -238,26 +238,27 @@ public class DeathPatches : QSBPatch [HarmonyPrefix] [HarmonyPatch(typeof(DestructionVolume), nameof(DestructionVolume.VanishShip))] - public static bool DestructionVolume_VanishShip(DestructionVolume __instance) + public static bool DestructionVolume_VanishShip(DestructionVolume __instance, OWRigidbody shipBody, RelativeLocationData entryLocation) { - if (RespawnOnDeath.Instance == null) + var cockpitIntact = !shipBody.GetComponent().IsCockpitDetached(); + if (PlayerState.IsInsideShip() || PlayerState.UsingShipComputer() || (cockpitIntact && PlayerState.AtFlightConsole())) { - return true; - } + var autopilot = shipBody.GetComponent(); + if (autopilot != null && autopilot.IsFlyingToDestination()) + { + var astroObject = __instance.GetComponentInParent(); + if (astroObject != null && astroObject.GetAstroObjectType() == AstroObject.Type.Star) + { + PlayerData.SetPersistentCondition("AUTOPILOT_INTO_SUN", true); + MonoBehaviour.print("AUTOPILOT_INTO_SUN"); + } + } - // apparently this is to fix a weird bug when flying into the sun. idk this is 2-year-old code. - if (!ShipTransformSync.LocalInstance.hasAuthority) - { - return false; - } - - if (PlayerState.IsInsideShip() || PlayerState.UsingShipComputer() || PlayerState.AtFlightConsole()) - { Locator.GetDeathManager().KillPlayer(__instance._deathType); } - // don't actually delete the ship to allow respawns or something - - return true; + __instance.Vanish(shipBody, entryLocation); + GlobalMessenger.FireEvent("ShipDestroyed"); + return false; } } From 1ee72ef9731b909dc51d819fddadbe8353916b6b Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 17 May 2022 22:28:49 +0100 Subject: [PATCH 09/17] buh --- QSB/Animation/Player/AnimationSync.cs | 2 +- ...ackAccelerationSync.cs => ThrusterSync.cs} | 4 +- QSB/Player/PlayerInfoParts/Animation.cs | 2 +- QSB/ShipSync/Patches/FlameWashPatches.cs | 34 +++++++++++++ QSB/ShipSync/ShipManager.cs | 2 + QSB/ShipSync/ShipThrusterManager.cs | 48 +++++++++++++++++++ .../TransformSync/ShipTransformSync.cs | 11 +++++ 7 files changed, 98 insertions(+), 5 deletions(-) rename QSB/Animation/Player/Thrusters/{JetpackAccelerationSync.cs => ThrusterSync.cs} (72%) create mode 100644 QSB/ShipSync/Patches/FlameWashPatches.cs create mode 100644 QSB/ShipSync/ShipThrusterManager.cs diff --git a/QSB/Animation/Player/AnimationSync.cs b/QSB/Animation/Player/AnimationSync.cs index e039dac0..2b23e838 100644 --- a/QSB/Animation/Player/AnimationSync.cs +++ b/QSB/Animation/Player/AnimationSync.cs @@ -95,7 +95,7 @@ public class AnimationSync : PlayerSyncObject private void InitAccelerationSync() { - Player.JetpackAcceleration = GetComponent(); + Player.JetpackAcceleration = GetComponent(); var thrusterModel = hasAuthority ? Locator.GetPlayerBody().GetComponent() : null; Player.JetpackAcceleration.Init(thrusterModel); } diff --git a/QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs b/QSB/Animation/Player/Thrusters/ThrusterSync.cs similarity index 72% rename from QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs rename to QSB/Animation/Player/Thrusters/ThrusterSync.cs index 89b53a8f..28f552de 100644 --- a/QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs +++ b/QSB/Animation/Player/Thrusters/ThrusterSync.cs @@ -3,10 +3,9 @@ using QSB.Utility.VariableSync; namespace QSB.Animation.Player.Thrusters; -public class JetpackAccelerationSync : NetworkBehaviour +public class ThrusterSync : NetworkBehaviour { public Vector3VariableSyncer AccelerationVariableSyncer; - public BoolVariableSyncer ThrustingVariableSyncer; private ThrusterModel _thrusterModel; @@ -25,7 +24,6 @@ public class JetpackAccelerationSync : NetworkBehaviour if (_thrusterModel != null) { AccelerationVariableSyncer.Value = _thrusterModel.GetLocalAcceleration(); - ThrustingVariableSyncer.Value = _thrusterModel.IsTranslationalThrusterFiring(); } } } \ No newline at end of file diff --git a/QSB/Player/PlayerInfoParts/Animation.cs b/QSB/Player/PlayerInfoParts/Animation.cs index 9779aede..440617a0 100644 --- a/QSB/Player/PlayerInfoParts/Animation.cs +++ b/QSB/Player/PlayerInfoParts/Animation.cs @@ -8,7 +8,7 @@ public partial class PlayerInfo { public bool Visible => IsLocalPlayer || _ditheringAnimator == null || _ditheringAnimator.FullyVisible; public AnimationSync AnimationSync { get; } - public JetpackAccelerationSync JetpackAcceleration { get; set; } + public ThrusterSync JetpackAcceleration { get; set; } internal QSBDitheringAnimator _ditheringAnimator; public DreamWorldSpawnAnimator DreamWorldSpawnAnimator { get; set; } } diff --git a/QSB/ShipSync/Patches/FlameWashPatches.cs b/QSB/ShipSync/Patches/FlameWashPatches.cs new file mode 100644 index 00000000..261d3a5c --- /dev/null +++ b/QSB/ShipSync/Patches/FlameWashPatches.cs @@ -0,0 +1,34 @@ +using HarmonyLib; +using QSB.Patches; +using QSB.Player; +using UnityEngine; + +namespace QSB.ShipSync.Patches; + +internal class FlameWashPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ThrusterFlameController), nameof(ThrusterFlameController.GetThrustFraction))] + public static bool FlameThrustFraction(ThrusterFlameController __instance, ref float __result) + { + if (!__instance._thrusterModel.IsThrusterBankEnabled(OWUtilities.GetShipThrusterBank(__instance._thruster))) + { + __result = 0f; + return false; + } + + if (QSBPlayerManager.LocalPlayer.FlyingShip) + { + __result = Vector3.Dot(__instance._thrusterModel.GetLocalAcceleration(), __instance._thrusterFilter); + } + else + { + __instance.OnStartTranslationalThrust(); + __result = Vector3.Dot(ShipManager.Instance.ShipThrusterSync.AccelerationVariableSyncer.Value, __instance._thrusterFilter); + } + + return false; + } +} \ No newline at end of file diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index 91375a08..e01d6066 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -1,6 +1,7 @@ using Cysharp.Threading.Tasks; using Mirror; using OWML.Common; +using QSB.Animation.Player.Thrusters; using QSB.Messaging; using QSB.Player; using QSB.ShipSync.Messages; @@ -27,6 +28,7 @@ internal class ShipManager : WorldObjectManager public ShipCockpitController CockpitController; public ShipElectricalComponent ShipElectricalComponent; public ShipCockpitUI ShipCockpitUI; + public ThrusterSync ShipThrusterSync; private GameObject _shipCustomAttach; public uint CurrentFlyer { diff --git a/QSB/ShipSync/ShipThrusterManager.cs b/QSB/ShipSync/ShipThrusterManager.cs new file mode 100644 index 00000000..da113401 --- /dev/null +++ b/QSB/ShipSync/ShipThrusterManager.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace QSB.ShipSync; + +public static class ShipThrusterManager +{ + public static List ShipFlameControllers = new(); + public static ThrusterWashController ShipWashController = new(); + + public static void CreateShipVFX() + { + var shipBody = Locator.GetShipBody(); + var Module_Cabin = shipBody.transform.Find("Module_Cabin"); + var Effects_Cabin = Module_Cabin.Find("Effects_Cabin"); + var ThrusterWash = Effects_Cabin.Find("ThrusterWash"); + + ShipWashController = ThrusterWash.GetComponent(); + + var Module_Supplies = shipBody.transform.Find("Module_Supplies"); + var Effects_Supplies = Module_Supplies.Find("Effects_Supplies"); + var SuppliesThrusters = Effects_Supplies.Find("Thrusters"); + foreach (Transform thruster in SuppliesThrusters) + { + if (thruster.name == "Particles") + { + continue; + } + + var flame = thruster.GetChild(0); + ShipFlameControllers.Add(flame.GetComponent()); + } + + var Module_Engine = shipBody.transform.Find("Module_Engine"); + var Effects_Engine = Module_Engine.Find("Effects_Engine"); + var EngineThrusters = Effects_Engine.Find("Thrusters"); + foreach (Transform thruster in EngineThrusters) + { + if (thruster.name == "Particles") + { + continue; + } + + var flame = thruster.GetChild(0); + ShipFlameControllers.Add(flame.GetComponent()); + } + } +} diff --git a/QSB/ShipSync/TransformSync/ShipTransformSync.cs b/QSB/ShipSync/TransformSync/ShipTransformSync.cs index a881846b..80bcb39f 100644 --- a/QSB/ShipSync/TransformSync/ShipTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipTransformSync.cs @@ -1,3 +1,4 @@ +using QSB.Animation.Player.Thrusters; using QSB.Syncs.Sectored.Rigidbodies; using QSB.Utility; using UnityEngine; @@ -27,6 +28,16 @@ public class ShipTransformSync : SectoredRigidbodySync return Locator.GetShipBody(); } + protected override void Init() + { + base.Init(); + + ShipManager.Instance.ShipThrusterSync = gameObject.GetAddComponent(); + ShipManager.Instance.ShipThrusterSync.Init(Locator.GetShipBody().GetComponent()); + + ShipThrusterManager.CreateShipVFX(); + } + /// Dont do base... this is a replacement! protected override void ApplyToAttached() { From adf1945b75e5adee2d6ba2b910693634aed4c332 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Thu, 19 May 2022 14:34:49 +0100 Subject: [PATCH 10/17] sync flames --- QSB/Animation/Player/AnimationSync.cs | 4 +- ...sterSync.cs => JetpackAccelerationSync.cs} | 2 +- .../RotatingElementsVariableSyncer.cs | 2 +- QSB/Player/PlayerInfoParts/Animation.cs | 2 +- QSB/QSBNetworkManager.cs | 5 ++ ...lameWashPatches.cs => ShipFlamePatches.cs} | 18 ++++--- QSB/ShipSync/ShipManager.cs | 1 - QSB/ShipSync/ShipThrusterVariableSyncer.cs | 48 +++++++++++++++++++ .../TransformSync/ShipTransformSync.cs | 6 ++- QSB/Syncs/QSBNetworkTransform.cs | 2 +- QSB/Syncs/QSBNetworkTransformChild.cs | 2 +- .../Rigidbodies/SectoredRigidbodySync.cs | 2 +- QSB/Syncs/SyncBase.cs | 2 +- .../Rigidbodies/UnsectoredRigidbodySync.cs | 2 +- QSB/Utility/QSBNetworkBehaviour.cs | 2 +- .../VariableSync/BaseVariableSyncer.cs | 2 +- 16 files changed, 81 insertions(+), 21 deletions(-) rename QSB/Animation/Player/Thrusters/{ThrusterSync.cs => JetpackAccelerationSync.cs} (89%) rename QSB/ShipSync/Patches/{FlameWashPatches.cs => ShipFlamePatches.cs} (51%) create mode 100644 QSB/ShipSync/ShipThrusterVariableSyncer.cs diff --git a/QSB/Animation/Player/AnimationSync.cs b/QSB/Animation/Player/AnimationSync.cs index 2b23e838..2b0069f4 100644 --- a/QSB/Animation/Player/AnimationSync.cs +++ b/QSB/Animation/Player/AnimationSync.cs @@ -95,14 +95,14 @@ public class AnimationSync : PlayerSyncObject private void InitAccelerationSync() { - Player.JetpackAcceleration = GetComponent(); + Player.JetpackAcceleration = GetComponent(); var thrusterModel = hasAuthority ? Locator.GetPlayerBody().GetComponent() : null; Player.JetpackAcceleration.Init(thrusterModel); } private void InitCrouchSync() { - _crouchSync = GetComponent(); + _crouchSync = this.GetRequiredComponent(); _crouchSync.Init(_playerController, VisibleAnimator); } diff --git a/QSB/Animation/Player/Thrusters/ThrusterSync.cs b/QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs similarity index 89% rename from QSB/Animation/Player/Thrusters/ThrusterSync.cs rename to QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs index 28f552de..4ce65696 100644 --- a/QSB/Animation/Player/Thrusters/ThrusterSync.cs +++ b/QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs @@ -3,7 +3,7 @@ using QSB.Utility.VariableSync; namespace QSB.Animation.Player.Thrusters; -public class ThrusterSync : NetworkBehaviour +public class JetpackAccelerationSync : NetworkBehaviour { public Vector3VariableSyncer AccelerationVariableSyncer; diff --git a/QSB/EchoesOfTheEye/RotatingElementsVariableSyncer.cs b/QSB/EchoesOfTheEye/RotatingElementsVariableSyncer.cs index c510a730..5f54daed 100644 --- a/QSB/EchoesOfTheEye/RotatingElementsVariableSyncer.cs +++ b/QSB/EchoesOfTheEye/RotatingElementsVariableSyncer.cs @@ -33,7 +33,7 @@ internal abstract class RotatingElementsVariableSyncer : BaseVaria protected abstract Transform[] RotatingElements { get; } - protected override bool HasChanged() + public override bool HasChanged() { var rotatingElements = RotatingElements; Value ??= new Quaternion[rotatingElements.Length]; diff --git a/QSB/Player/PlayerInfoParts/Animation.cs b/QSB/Player/PlayerInfoParts/Animation.cs index 440617a0..9779aede 100644 --- a/QSB/Player/PlayerInfoParts/Animation.cs +++ b/QSB/Player/PlayerInfoParts/Animation.cs @@ -8,7 +8,7 @@ public partial class PlayerInfo { public bool Visible => IsLocalPlayer || _ditheringAnimator == null || _ditheringAnimator.FullyVisible; public AnimationSync AnimationSync { get; } - public ThrusterSync JetpackAcceleration { get; set; } + public JetpackAccelerationSync JetpackAcceleration { get; set; } internal QSBDitheringAnimator _ditheringAnimator; public DreamWorldSpawnAnimator DreamWorldSpawnAnimator { get; set; } } diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index e2fdea95..6f74e92d 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -20,11 +20,13 @@ using QSB.Patches; using QSB.Player; using QSB.Player.Messages; using QSB.Player.TransformSync; +using QSB.ShipSync; using QSB.ShipSync.TransformSync; using QSB.Syncs.Occasional; using QSB.TimeSync; using QSB.Tools.ProbeTool.TransformSync; using QSB.Utility; +using QSB.Utility.VariableSync; using QSB.WorldSync; using System; using System.Linq; @@ -103,6 +105,9 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart playerPrefab.GetRequiredComponent().SetValue("m_AssetId", 1.ToGuid().ToString("N")); ShipPrefab = MakeNewNetworkObject(2, "NetworkShip", typeof(ShipTransformSync)); + var shipVector3Sync = ShipPrefab.AddComponent(); + var shipThrustSync = ShipPrefab.AddComponent(); + shipThrustSync.AccelerationSyncer = shipVector3Sync; spawnPrefabs.Add(ShipPrefab); _probePrefab = MakeNewNetworkObject(3, "NetworkProbe", typeof(PlayerProbeSync)); diff --git a/QSB/ShipSync/Patches/FlameWashPatches.cs b/QSB/ShipSync/Patches/ShipFlamePatches.cs similarity index 51% rename from QSB/ShipSync/Patches/FlameWashPatches.cs rename to QSB/ShipSync/Patches/ShipFlamePatches.cs index 261d3a5c..78d4cb61 100644 --- a/QSB/ShipSync/Patches/FlameWashPatches.cs +++ b/QSB/ShipSync/Patches/ShipFlamePatches.cs @@ -1,18 +1,25 @@ using HarmonyLib; using QSB.Patches; using QSB.Player; +using QSB.ShipSync.TransformSync; using UnityEngine; namespace QSB.ShipSync.Patches; -internal class FlameWashPatches : QSBPatch +[HarmonyPatch(typeof(ThrusterFlameController))] +internal class ShipFlamePatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; [HarmonyPrefix] - [HarmonyPatch(typeof(ThrusterFlameController), nameof(ThrusterFlameController.GetThrustFraction))] - public static bool FlameThrustFraction(ThrusterFlameController __instance, ref float __result) + [HarmonyPatch(nameof(ThrusterFlameController.GetThrustFraction))] + public static bool GetThrustFraction(ThrusterFlameController __instance, ref float __result) { + if (!ShipThrusterManager.ShipFlameControllers.Contains(__instance)) + { + return true; + } + if (!__instance._thrusterModel.IsThrusterBankEnabled(OWUtilities.GetShipThrusterBank(__instance._thruster))) { __result = 0f; @@ -25,10 +32,9 @@ internal class FlameWashPatches : QSBPatch } else { - __instance.OnStartTranslationalThrust(); - __result = Vector3.Dot(ShipManager.Instance.ShipThrusterSync.AccelerationVariableSyncer.Value, __instance._thrusterFilter); + __result = Vector3.Dot(ShipTransformSync.LocalInstance.ThrusterVariableSyncer.AccelerationSyncer.Value, __instance._thrusterFilter); } return false; } -} \ No newline at end of file +} diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index e01d6066..aa88ca0f 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -28,7 +28,6 @@ internal class ShipManager : WorldObjectManager public ShipCockpitController CockpitController; public ShipElectricalComponent ShipElectricalComponent; public ShipCockpitUI ShipCockpitUI; - public ThrusterSync ShipThrusterSync; private GameObject _shipCustomAttach; public uint CurrentFlyer { diff --git a/QSB/ShipSync/ShipThrusterVariableSyncer.cs b/QSB/ShipSync/ShipThrusterVariableSyncer.cs new file mode 100644 index 00000000..3ea3944d --- /dev/null +++ b/QSB/ShipSync/ShipThrusterVariableSyncer.cs @@ -0,0 +1,48 @@ +using Mirror; +using QSB.Player; +using QSB.Utility.VariableSync; +using UnityEngine; + +namespace QSB.ShipSync; + +public class ShipThrusterVariableSyncer : NetworkBehaviour +{ + public Vector3VariableSyncer AccelerationSyncer; + + private ShipThrusterModel _thrusterModel; + + public void Init() + { + _thrusterModel = Locator.GetShipBody().GetComponent(); + } + + public void Update() + { + if (QSBPlayerManager.LocalPlayer.FlyingShip) + { + GetFromShip(); + return; + } + + if (AccelerationSyncer.HasChanged()) + { + if (AccelerationSyncer.Value == Vector3.zero) + { + foreach (var item in ShipThrusterManager.ShipFlameControllers) + { + item.OnStopTranslationalThrust(); + } + } + else + { + foreach (var item in ShipThrusterManager.ShipFlameControllers) + { + item.OnStartTranslationalThrust(); + } + } + } + } + + private void GetFromShip() => AccelerationSyncer.Value = _thrusterModel.GetLocalAcceleration(); +} + \ No newline at end of file diff --git a/QSB/ShipSync/TransformSync/ShipTransformSync.cs b/QSB/ShipSync/TransformSync/ShipTransformSync.cs index 80bcb39f..502606a2 100644 --- a/QSB/ShipSync/TransformSync/ShipTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipTransformSync.cs @@ -9,6 +9,8 @@ public class ShipTransformSync : SectoredRigidbodySync { public static ShipTransformSync LocalInstance { get; private set; } + public ShipThrusterVariableSyncer ThrusterVariableSyncer { get; private set; } + private float _lastSetPositionTime; private const float ForcePositionAfterTime = 1; @@ -32,8 +34,8 @@ public class ShipTransformSync : SectoredRigidbodySync { base.Init(); - ShipManager.Instance.ShipThrusterSync = gameObject.GetAddComponent(); - ShipManager.Instance.ShipThrusterSync.Init(Locator.GetShipBody().GetComponent()); + ThrusterVariableSyncer = this.GetRequiredComponent(); + ThrusterVariableSyncer.Init(); ShipThrusterManager.CreateShipVFX(); } diff --git a/QSB/Syncs/QSBNetworkTransform.cs b/QSB/Syncs/QSBNetworkTransform.cs index 655ebe5e..584898e4 100644 --- a/QSB/Syncs/QSBNetworkTransform.cs +++ b/QSB/Syncs/QSBNetworkTransform.cs @@ -14,7 +14,7 @@ public class QSBNetworkTransform : QSBNetworkBehaviour private Vector3 _prevPosition; private Quaternion _prevRotation; - protected override bool HasChanged() => + public override bool HasChanged() => Vector3.Distance(transform.position, _prevPosition) > PositionChangeThreshold || Quaternion.Angle(transform.rotation, _prevRotation) > RotationChangeThreshold; diff --git a/QSB/Syncs/QSBNetworkTransformChild.cs b/QSB/Syncs/QSBNetworkTransformChild.cs index b96fc084..ff064d0d 100644 --- a/QSB/Syncs/QSBNetworkTransformChild.cs +++ b/QSB/Syncs/QSBNetworkTransformChild.cs @@ -16,7 +16,7 @@ public class QSBNetworkTransformChild : QSBNetworkBehaviour private Vector3 _prevPosition; private Quaternion _prevRotation; - protected override bool HasChanged() => + public override bool HasChanged() => Vector3.Distance(Target.localPosition, _prevPosition) > PositionChangeThreshold || Quaternion.Angle(Target.localRotation, _prevRotation) > RotationChangeThreshold; diff --git a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs index e41f85c7..7fb1e458 100644 --- a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs +++ b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs @@ -36,7 +36,7 @@ public abstract class SectoredRigidbodySync : BaseSectoredSync ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null; } - protected override bool HasChanged() => + public override bool HasChanged() => base.HasChanged() || Vector3.Distance(Velocity, _prevVelocity) > VelocityChangeThreshold || Vector3.Distance(AngularVelocity, _prevAngularVelocity) > AngularVelocityChangeThreshold; diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 1ab3a6a1..6f8ab9ae 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -198,7 +198,7 @@ public abstract class SyncBase : QSBNetworkTransform /// /// call the base method FIRST /// - protected override bool HasChanged() + public override bool HasChanged() { GetFromAttached(); if (UseInterpolation) diff --git a/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs b/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs index 99b5cc91..56573829 100644 --- a/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs +++ b/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs @@ -36,7 +36,7 @@ public abstract class UnsectoredRigidbodySync : BaseUnsectoredSync ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null; } - protected override bool HasChanged() => + public override bool HasChanged() => base.HasChanged() || Vector3.Distance(Velocity, _prevVelocity) > VelocityChangeThreshold || Vector3.Distance(AngularVelocity, _prevAngularVelocity) > AngularVelocityChangeThreshold; diff --git a/QSB/Utility/QSBNetworkBehaviour.cs b/QSB/Utility/QSBNetworkBehaviour.cs index 534fda1c..54659cb4 100644 --- a/QSB/Utility/QSBNetworkBehaviour.cs +++ b/QSB/Utility/QSBNetworkBehaviour.cs @@ -23,7 +23,7 @@ public abstract class QSBNetworkBehaviour : NetworkBehaviour /// /// checked before serializing /// - protected abstract bool HasChanged(); + public abstract bool HasChanged(); protected abstract void Serialize(NetworkWriter writer); diff --git a/QSB/Utility/VariableSync/BaseVariableSyncer.cs b/QSB/Utility/VariableSync/BaseVariableSyncer.cs index 27291a1b..40c00c39 100644 --- a/QSB/Utility/VariableSync/BaseVariableSyncer.cs +++ b/QSB/Utility/VariableSync/BaseVariableSyncer.cs @@ -12,7 +12,7 @@ public abstract class BaseVariableSyncer : QSBNetworkBehaviour [NonSerialized] public T Value; - protected override bool HasChanged() => !EqualityComparer.Default.Equals(PrevValue, Value); + public override bool HasChanged() => !EqualityComparer.Default.Equals(PrevValue, Value); protected override void UpdatePrevData() => PrevValue = Value; protected override void Serialize(NetworkWriter writer) => writer.Write(Value); protected override void Deserialize(NetworkReader reader) => Value = reader.Read(); From 8f797a22ab1982b680a24a6c710bcf3c806304bd Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Thu, 19 May 2022 15:13:22 +0100 Subject: [PATCH 11/17] sync ship wash --- QSB/ShipSync/Patches/ShipFlamePatches.cs | 40 ------ QSB/ShipSync/Patches/ShipFlameWashPatches.cs | 126 +++++++++++++++++++ QSB/ShipSync/ShipThrusterVariableSyncer.cs | 4 + 3 files changed, 130 insertions(+), 40 deletions(-) delete mode 100644 QSB/ShipSync/Patches/ShipFlamePatches.cs create mode 100644 QSB/ShipSync/Patches/ShipFlameWashPatches.cs diff --git a/QSB/ShipSync/Patches/ShipFlamePatches.cs b/QSB/ShipSync/Patches/ShipFlamePatches.cs deleted file mode 100644 index 78d4cb61..00000000 --- a/QSB/ShipSync/Patches/ShipFlamePatches.cs +++ /dev/null @@ -1,40 +0,0 @@ -using HarmonyLib; -using QSB.Patches; -using QSB.Player; -using QSB.ShipSync.TransformSync; -using UnityEngine; - -namespace QSB.ShipSync.Patches; - -[HarmonyPatch(typeof(ThrusterFlameController))] -internal class ShipFlamePatches : QSBPatch -{ - public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - - [HarmonyPrefix] - [HarmonyPatch(nameof(ThrusterFlameController.GetThrustFraction))] - public static bool GetThrustFraction(ThrusterFlameController __instance, ref float __result) - { - if (!ShipThrusterManager.ShipFlameControllers.Contains(__instance)) - { - return true; - } - - if (!__instance._thrusterModel.IsThrusterBankEnabled(OWUtilities.GetShipThrusterBank(__instance._thruster))) - { - __result = 0f; - return false; - } - - if (QSBPlayerManager.LocalPlayer.FlyingShip) - { - __result = Vector3.Dot(__instance._thrusterModel.GetLocalAcceleration(), __instance._thrusterFilter); - } - else - { - __result = Vector3.Dot(ShipTransformSync.LocalInstance.ThrusterVariableSyncer.AccelerationSyncer.Value, __instance._thrusterFilter); - } - - return false; - } -} diff --git a/QSB/ShipSync/Patches/ShipFlameWashPatches.cs b/QSB/ShipSync/Patches/ShipFlameWashPatches.cs new file mode 100644 index 00000000..ddf2eac8 --- /dev/null +++ b/QSB/ShipSync/Patches/ShipFlameWashPatches.cs @@ -0,0 +1,126 @@ +using HarmonyLib; +using QSB.Patches; +using QSB.Player; +using QSB.ShipSync.TransformSync; +using UnityEngine; + +namespace QSB.ShipSync.Patches; + +internal class ShipFlameWashPatches : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ThrusterFlameController), nameof(ThrusterFlameController.GetThrustFraction))] + public static bool GetThrustFraction(ThrusterFlameController __instance, ref float __result) + { + if (!ShipThrusterManager.ShipFlameControllers.Contains(__instance)) + { + return true; + } + + if (!__instance._thrusterModel.IsThrusterBankEnabled(OWUtilities.GetShipThrusterBank(__instance._thruster))) + { + __result = 0f; + return false; + } + + if (QSBPlayerManager.LocalPlayer.FlyingShip) + { + __result = Vector3.Dot(__instance._thrusterModel.GetLocalAcceleration(), __instance._thrusterFilter); + } + else + { + __result = Vector3.Dot(ShipTransformSync.LocalInstance.ThrusterVariableSyncer.AccelerationSyncer.Value, __instance._thrusterFilter); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ThrusterWashController), nameof(ThrusterWashController.Update))] + public static bool Update(ThrusterWashController __instance) + { + if (ShipThrusterManager.ShipWashController != __instance) + { + return true; + } + + var hitInfo = default(RaycastHit); + var aboveGround = false; + var localAcceleration = QSBPlayerManager.LocalPlayer.FlyingShip + ? __instance._thrusterModel.GetLocalAcceleration() + : ShipTransformSync.LocalInstance.ThrusterVariableSyncer.AccelerationSyncer.Value; + var emissionScale = __instance._emissionThrusterScale.Evaluate(localAcceleration.y); + if (emissionScale > 0f) + { + aboveGround = Physics.Raycast(__instance.transform.position, __instance.transform.forward, out hitInfo, __instance._raycastDistance, OWLayerMask.physicalMask); + } + + emissionScale = aboveGround ? (emissionScale * __instance._emissionDistanceScale.Evaluate(hitInfo.distance)) : 0f; + if (emissionScale > 0f) + { + var position = hitInfo.point + (hitInfo.normal * 0.25f); + var rotation = Quaternion.LookRotation(hitInfo.normal); + if (!__instance._defaultParticleSystem.isPlaying) + { + __instance._defaultParticleSystem.Play(); + } + + __instance._defaultEmissionModule.rateOverTimeMultiplier = __instance._baseDefaultEmissionRate * emissionScale; + __instance._defaultParticleSystem.transform.SetPositionAndRotation(position, rotation); + if (__instance._defaultMainModule.customSimulationSpace != hitInfo.transform) + { + __instance._defaultMainModule.customSimulationSpace = hitInfo.transform; + __instance._defaultParticleSystem.Clear(); + } + + var hitSurfaceType = Locator.GetSurfaceManager().GetHitSurfaceType(hitInfo); + var particleSystem = __instance._particleSystemBySurfaceType[(int)hitSurfaceType]; + if (particleSystem != __instance._activeSurfaceParticleSystem) + { + if (__instance._activeSurfaceParticleSystem != null) + { + __instance._activeSurfaceParticleSystem.Stop(false, ParticleSystemStopBehavior.StopEmitting); + } + + if (particleSystem != null) + { + particleSystem.Play(); + } + + __instance._activeSurfaceParticleSystem = particleSystem; + } + + if (__instance._activeSurfaceParticleSystem != null) + { + var es = __instance._activeSurfaceParticleSystem.emission; + es.rateOverTimeMultiplier = __instance._baseSurfaceEmissionRate[(int)hitSurfaceType] * emissionScale; + __instance._activeSurfaceParticleSystem.transform.position = hitInfo.point + (hitInfo.normal * 0.25f); + __instance._activeSurfaceParticleSystem.transform.rotation = Quaternion.LookRotation(hitInfo.normal); + var main = __instance._activeSurfaceParticleSystem.main; + if (main.customSimulationSpace != hitInfo.transform) + { + main.customSimulationSpace = hitInfo.transform; + __instance._activeSurfaceParticleSystem.Clear(); + return false; + } + } + } + else + { + if (__instance._defaultParticleSystem.isPlaying) + { + __instance._defaultParticleSystem.Stop(false, ParticleSystemStopBehavior.StopEmitting); + } + + if (__instance._activeSurfaceParticleSystem != null) + { + __instance._activeSurfaceParticleSystem.Stop(false, ParticleSystemStopBehavior.StopEmitting); + __instance._activeSurfaceParticleSystem = null; + } + } + + return false; + } +} diff --git a/QSB/ShipSync/ShipThrusterVariableSyncer.cs b/QSB/ShipSync/ShipThrusterVariableSyncer.cs index 3ea3944d..a068d8d0 100644 --- a/QSB/ShipSync/ShipThrusterVariableSyncer.cs +++ b/QSB/ShipSync/ShipThrusterVariableSyncer.cs @@ -32,6 +32,8 @@ public class ShipThrusterVariableSyncer : NetworkBehaviour { item.OnStopTranslationalThrust(); } + + ShipThrusterManager.ShipWashController.OnStopTranslationalThrust(); } else { @@ -39,6 +41,8 @@ public class ShipThrusterVariableSyncer : NetworkBehaviour { item.OnStartTranslationalThrust(); } + + ShipThrusterManager.ShipWashController.OnStartTranslationalThrust(); } } } From db69f220eb118fef41cadb412c2e8e2241891a10 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 19 May 2022 15:31:05 -0700 Subject: [PATCH 12/17] make sure detachable isnt recursive --- QSB/Player/Messages/PlayerJoinMessage.cs | 2 - QSB/ShipSync/Messages/LegDetachMessage.cs | 11 +++++ QSB/ShipSync/Messages/ModuleDetachMessage.cs | 12 ++---- .../Patches/ShipDetachableModulePatches.cs | 41 +++++++++++++++++-- .../TransformSync/ShipLegTransformSync.cs | 16 ++------ .../TransformSync/ShipModuleTransformSync.cs | 16 ++------ 6 files changed, 58 insertions(+), 40 deletions(-) create mode 100644 QSB/ShipSync/Messages/LegDetachMessage.cs diff --git a/QSB/Player/Messages/PlayerJoinMessage.cs b/QSB/Player/Messages/PlayerJoinMessage.cs index b24fea96..692ae704 100644 --- a/QSB/Player/Messages/PlayerJoinMessage.cs +++ b/QSB/Player/Messages/PlayerJoinMessage.cs @@ -29,7 +29,6 @@ public class PlayerJoinMessage : QSBMessage FirstIncompatibleMod = ""; -#if RELEASE foreach (var mod in allEnabledMods) { if (QSBCore.IncompatibleMods.Contains(mod.ModHelper.Manifest.UniqueName)) @@ -37,7 +36,6 @@ public class PlayerJoinMessage : QSBMessage FirstIncompatibleMod = mod.ModHelper.Manifest.UniqueName; } } -#endif AddonHashes = QSBCore.Addons.Keys .Select(x => x.GetStableHashCode()) diff --git a/QSB/ShipSync/Messages/LegDetachMessage.cs b/QSB/ShipSync/Messages/LegDetachMessage.cs new file mode 100644 index 00000000..cc3a9608 --- /dev/null +++ b/QSB/ShipSync/Messages/LegDetachMessage.cs @@ -0,0 +1,11 @@ +using QSB.Messaging; +using QSB.Patches; +using QSB.ShipSync.WorldObjects; + +namespace QSB.ShipSync.Messages; + +internal class LegDetachMessage : QSBWorldObjectMessage +{ + public override void OnReceiveRemote() => + QSBPatch.RemoteCall(WorldObject.AttachedObject.Detach); +} diff --git a/QSB/ShipSync/Messages/ModuleDetachMessage.cs b/QSB/ShipSync/Messages/ModuleDetachMessage.cs index 89791b46..e47c242c 100644 --- a/QSB/ShipSync/Messages/ModuleDetachMessage.cs +++ b/QSB/ShipSync/Messages/ModuleDetachMessage.cs @@ -1,17 +1,11 @@ using QSB.Messaging; +using QSB.Patches; using QSB.ShipSync.WorldObjects; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace QSB.ShipSync.Messages; internal class ModuleDetachMessage : QSBWorldObjectMessage { - public override void OnReceiveRemote() - { - WorldObject.AttachedObject.Detach(); - } + public override void OnReceiveRemote() => + QSBPatch.RemoteCall(WorldObject.AttachedObject.Detach); } diff --git a/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs b/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs index a82af62b..da1a6231 100644 --- a/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs +++ b/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs @@ -3,9 +3,7 @@ using QSB.Messaging; using QSB.Patches; using QSB.ShipSync.Messages; using QSB.ShipSync.WorldObjects; -using QSB.Utility; using QSB.WorldSync; -using UnityEngine; namespace QSB.ShipSync.Patches; @@ -14,10 +12,47 @@ internal class ShipDetachableModulePatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - [HarmonyPostfix] + [HarmonyPrefix] [HarmonyPatch(nameof(ShipDetachableModule.Detach))] public static void Detach(ShipDetachableModule __instance) { + if (Remote) + { + return; + } + + if (__instance.isDetached) + { + return; + } + + if (!QSBWorldSync.AllObjectsReady) + { + return; + } + __instance.GetWorldObject().SendMessage(new ModuleDetachMessage()); } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipDetachableLeg.Detach))] + public static void Detach(ShipDetachableLeg __instance) + { + if (Remote) + { + return; + } + + if (__instance.isDetached) + { + return; + } + + if (!QSBWorldSync.AllObjectsReady) + { + return; + } + + __instance.GetWorldObject().SendMessage(new LegDetachMessage()); + } } diff --git a/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs b/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs index 3556bc0c..ef50d78f 100644 --- a/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs @@ -13,12 +13,12 @@ internal class ShipLegTransformSync : SectoredRigidbodySync, ILinkedNetworkBehav /// protected override bool CheckValid() => AttachedTransform - && base.CheckValid(); + && base.CheckValid(); protected override bool CheckReady() => _qsbModule != null - && _qsbModule.AttachedObject.isDetached - && base.CheckReady(); + && _qsbModule.AttachedObject.isDetached + && base.CheckReady(); protected override bool UseInterpolation => true; protected override float DistanceChangeThreshold => 1f; @@ -32,14 +32,4 @@ internal class ShipLegTransformSync : SectoredRigidbodySync, ILinkedNetworkBehav SectorDetector.Init(owRigidbody.transform.Find("DetectorVolume").GetComponent()); return owRigidbody; } - - protected override void ApplyToAttached() - { - if (!_qsbModule.AttachedObject.isDetached) - { - return; - } - - base.ApplyToAttached(); - } } diff --git a/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs b/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs index 71814185..6678ba4d 100644 --- a/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs @@ -13,12 +13,12 @@ internal class ShipModuleTransformSync : SectoredRigidbodySync, ILinkedNetworkBe /// protected override bool CheckValid() => AttachedTransform - && base.CheckValid(); + && base.CheckValid(); protected override bool CheckReady() => _qsbModule != null - && _qsbModule.AttachedObject.isDetached - && base.CheckReady(); + && _qsbModule.AttachedObject.isDetached + && base.CheckReady(); protected override bool UseInterpolation => true; protected override float DistanceChangeThreshold => 1f; @@ -32,14 +32,4 @@ internal class ShipModuleTransformSync : SectoredRigidbodySync, ILinkedNetworkBe SectorDetector.Init(owRigidbody.transform.Find("DetectorVolume").GetComponent()); return owRigidbody; } - - protected override void ApplyToAttached() - { - if (!_qsbModule.AttachedObject.isDetached) - { - return; - } - - base.ApplyToAttached(); - } } From bb285fda70424a1b3b6ca7718d7a5f24b90331a7 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 19 May 2022 15:35:09 -0700 Subject: [PATCH 13/17] ship can be destroyed --- QSB/ShipSync/TransformSync/ShipTransformSync.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/QSB/ShipSync/TransformSync/ShipTransformSync.cs b/QSB/ShipSync/TransformSync/ShipTransformSync.cs index 502606a2..8abe29dd 100644 --- a/QSB/ShipSync/TransformSync/ShipTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipTransformSync.cs @@ -1,4 +1,3 @@ -using QSB.Animation.Player.Thrusters; using QSB.Syncs.Sectored.Rigidbodies; using QSB.Utility; using UnityEngine; @@ -14,6 +13,14 @@ public class ShipTransformSync : SectoredRigidbodySync private float _lastSetPositionTime; private const float ForcePositionAfterTime = 1; + /// + /// normally prints error when attached object is null. + /// this overrides it so that doesn't happen, since the ship can be destroyed. + /// + protected override bool CheckValid() + => AttachedTransform + && base.CheckValid(); + protected override bool CheckReady() => base.CheckReady() && Locator.GetShipBody(); @@ -85,4 +92,4 @@ public class ShipTransformSync : SectoredRigidbodySync } protected override bool UseInterpolation => false; -} \ No newline at end of file +} From 39b1727723cc63b967adb3f6203300fc2765f8f6 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 19 May 2022 15:39:19 -0700 Subject: [PATCH 14/17] ship modules: remove tiny DistanceChangeThreshold --- QSB/ShipSync/TransformSync/ShipLegTransformSync.cs | 1 - QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs b/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs index ef50d78f..36222680 100644 --- a/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs @@ -21,7 +21,6 @@ internal class ShipLegTransformSync : SectoredRigidbodySync, ILinkedNetworkBehav && base.CheckReady(); protected override bool UseInterpolation => true; - protected override float DistanceChangeThreshold => 1f; private QSBShipDetachableLeg _qsbModule; public void SetWorldObject(IWorldObject worldObject) => _qsbModule = (QSBShipDetachableLeg)worldObject; diff --git a/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs b/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs index 6678ba4d..d49ed51f 100644 --- a/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipModuleTransformSync.cs @@ -21,7 +21,6 @@ internal class ShipModuleTransformSync : SectoredRigidbodySync, ILinkedNetworkBe && base.CheckReady(); protected override bool UseInterpolation => true; - protected override float DistanceChangeThreshold => 1f; private QSBShipDetachableModule _qsbModule; public void SetWorldObject(IWorldObject worldObject) => _qsbModule = (QSBShipDetachableModule)worldObject; From 423a554f7a0c2db1adfd3206153a84c97b650646 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 19 May 2022 16:23:32 -0700 Subject: [PATCH 15/17] ship lights: make it so i dont want to die when i read it --- QSB/ShipSync/Messages/ShipLightMessage.cs | 13 ++------ QSB/ShipSync/Patches/ShipPatches.cs | 37 +++++++++-------------- QSB/ShipSync/WorldObjects/QSBShipLight.cs | 30 ++---------------- QSB/WorldSync/QSBWorldSync.cs | 4 +-- 4 files changed, 22 insertions(+), 62 deletions(-) diff --git a/QSB/ShipSync/Messages/ShipLightMessage.cs b/QSB/ShipSync/Messages/ShipLightMessage.cs index 6ee6c9ef..4e52bafb 100644 --- a/QSB/ShipSync/Messages/ShipLightMessage.cs +++ b/QSB/ShipSync/Messages/ShipLightMessage.cs @@ -1,11 +1,6 @@ using QSB.Messaging; +using QSB.Patches; using QSB.ShipSync.WorldObjects; -using QSB.Utility; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace QSB.ShipSync.Messages; @@ -13,8 +8,6 @@ internal class ShipLightMessage : QSBWorldObjectMessage { public ShipLightMessage(bool on) : base(on) { } - public override void OnReceiveRemote() - { - WorldObject.SetOn(Data); - } + public override void OnReceiveRemote() => + QSBPatch.RemoteCall(() => WorldObject.AttachedObject.SetOn(Data)); } diff --git a/QSB/ShipSync/Patches/ShipPatches.cs b/QSB/ShipSync/Patches/ShipPatches.cs index d3afb4cf..82c1a90a 100644 --- a/QSB/ShipSync/Patches/ShipPatches.cs +++ b/QSB/ShipSync/Patches/ShipPatches.cs @@ -1,7 +1,6 @@ using HarmonyLib; using QSB.Messaging; using QSB.Patches; -using QSB.Player; using QSB.ShipSync.Messages; using QSB.ShipSync.Messages.Component; using QSB.ShipSync.Messages.Hull; @@ -9,7 +8,6 @@ using QSB.ShipSync.TransformSync; using QSB.ShipSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; -using System; using UnityEngine; namespace QSB.ShipSync.Patches; @@ -257,44 +255,39 @@ internal class ShipPatches : QSBPatch [HarmonyPrefix] [HarmonyPatch(typeof(ShipCockpitController), nameof(ShipCockpitController.EnterLandingView))] - public static bool EnterLandingView() - { + public static void EnterLandingView() => new LandingCameraMessage(true).Send(); - return true; - } [HarmonyPrefix] [HarmonyPatch(typeof(ShipCockpitController), nameof(ShipCockpitController.ExitLandingView))] - public static bool ExitLandingView() - { + public static void ExitLandingView() => new LandingCameraMessage(false).Send(); - return true; - } [HarmonyPrefix] [HarmonyPatch(typeof(ShipLight), nameof(ShipLight.SetOn))] - public static bool SetOn(ShipLight __instance, bool on) + public static void SetOn(ShipLight __instance, bool on) { - if (!QSBWorldSync.WorldObjectExistsFor(__instance)) + if (Remote) { - return true; + return; } - if (QSBPlayerManager.LocalPlayerId != ShipManager.Instance.CurrentFlyer) + if (__instance._on == on) { - return false; + return; } - var worldObject = __instance.GetWorldObject(); - - if (__instance.IsOn() != on) + if (!QSBWorldSync.AllObjectsReady) { - worldObject.SendMessage(new ShipLightMessage(on)); - - worldObject.SetOn(on); + return; } - return false; + if (!__instance.HasWorldObject()) + { + return; + } + + __instance.GetWorldObject().SendMessage(new ShipLightMessage(on)); } [HarmonyPrefix] diff --git a/QSB/ShipSync/WorldObjects/QSBShipLight.cs b/QSB/ShipSync/WorldObjects/QSBShipLight.cs index 43f6c3c1..2d545b3d 100644 --- a/QSB/ShipSync/WorldObjects/QSBShipLight.cs +++ b/QSB/ShipSync/WorldObjects/QSBShipLight.cs @@ -1,37 +1,11 @@ using QSB.Messaging; -using QSB.Player; using QSB.ShipSync.Messages; -using QSB.Utility; using QSB.WorldSync; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UnityEngine; namespace QSB.ShipSync.WorldObjects; internal class QSBShipLight : WorldObject { - public override void SendInitialState(uint to) - { - // todo : add this - } - - public void SetOn(bool on) - { - AttachedObject._on = on; - AttachedObject._startIntensity = AttachedObject._light.intensity; - AttachedObject._targetIntensity = (AttachedObject._on && !AttachedObject._damaged && AttachedObject._powered) - ? (AttachedObject._baseIntensity * AttachedObject._intensityScale) - : 0f; - AttachedObject._fadeStartTime = Time.time; - if (AttachedObject._lightSourceVol != null) - { - AttachedObject._lightSourceVol.SetVolumeActivation(AttachedObject._on); - } - - AttachedObject.enabled = true; - } + public override void SendInitialState(uint to) => + this.SendMessage(new ShipLightMessage(AttachedObject._on) { To = to }); } diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index ce14b618..5451b8a0 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -269,8 +269,8 @@ public static class QSBWorldSync return (TWorldObject)worldObject; } - public static bool WorldObjectExistsFor(this MonoBehaviour unityObject) - => unityObject != null && UnityObjectsToWorldObjects.ContainsKey(unityObject); + public static bool HasWorldObject(this MonoBehaviour unityObject) + => unityObject && UnityObjectsToWorldObjects.ContainsKey(unityObject); /// /// not deterministic across platforms. From 256a0e350b510ba4e3a37c556a7c23ade60c81a9 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 26 May 2022 21:27:55 -0700 Subject: [PATCH 16/17] TryGetWorldObject --- QSB/ShipSync/Patches/ShipPatches.cs | 4 ++-- QSB/WorldSync/QSBWorldSync.cs | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/QSB/ShipSync/Patches/ShipPatches.cs b/QSB/ShipSync/Patches/ShipPatches.cs index 82c1a90a..e062e3c0 100644 --- a/QSB/ShipSync/Patches/ShipPatches.cs +++ b/QSB/ShipSync/Patches/ShipPatches.cs @@ -282,12 +282,12 @@ internal class ShipPatches : QSBPatch return; } - if (!__instance.HasWorldObject()) + if (!__instance.TryGetWorldObject(out QSBShipLight qsbShipLight)) { return; } - __instance.GetWorldObject().SendMessage(new ShipLightMessage(on)); + qsbShipLight.SendMessage(new ShipLightMessage(on)); } [HarmonyPrefix] diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 5451b8a0..9c50dcb6 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -269,8 +269,25 @@ public static class QSBWorldSync return (TWorldObject)worldObject; } - public static bool HasWorldObject(this MonoBehaviour unityObject) - => unityObject && UnityObjectsToWorldObjects.ContainsKey(unityObject); + public static bool TryGetWorldObject(this MonoBehaviour unityObject, out TWorldObject worldObject) + where TWorldObject : IWorldObject + { + if (!unityObject) + { + DebugLog.ToConsole($"Error - Trying to run GetWorldFromUnity with a null unity object! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:NULL, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); + worldObject = default; + return false; + } + + if (!UnityObjectsToWorldObjects.TryGetValue(unityObject, out var iWorldObject)) + { + worldObject = default; + return false; + } + + worldObject = (TWorldObject)iWorldObject; + return true; + } /// /// not deterministic across platforms. From f0696684afdee8e684cafdefa1eedca2792c7dca Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 29 May 2022 11:58:23 -0700 Subject: [PATCH 17/17] HasChanged -> CheckChanged, then make variable (like IsValid) --- QSB/EchoesOfTheEye/RotatingElementsVariableSyncer.cs | 2 +- QSB/ShipSync/ShipThrusterVariableSyncer.cs | 2 +- QSB/Syncs/QSBNetworkTransform.cs | 2 +- QSB/Syncs/QSBNetworkTransformChild.cs | 2 +- QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs | 4 ++-- QSB/Syncs/SyncBase.cs | 4 ++-- .../Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs | 4 ++-- QSB/Utility/QSBNetworkBehaviour.cs | 7 +++++-- QSB/Utility/VariableSync/BaseVariableSyncer.cs | 2 +- 9 files changed, 16 insertions(+), 13 deletions(-) diff --git a/QSB/EchoesOfTheEye/RotatingElementsVariableSyncer.cs b/QSB/EchoesOfTheEye/RotatingElementsVariableSyncer.cs index 5f54daed..ac4941fd 100644 --- a/QSB/EchoesOfTheEye/RotatingElementsVariableSyncer.cs +++ b/QSB/EchoesOfTheEye/RotatingElementsVariableSyncer.cs @@ -33,7 +33,7 @@ internal abstract class RotatingElementsVariableSyncer : BaseVaria protected abstract Transform[] RotatingElements { get; } - public override bool HasChanged() + protected override bool CheckChanged() { var rotatingElements = RotatingElements; Value ??= new Quaternion[rotatingElements.Length]; diff --git a/QSB/ShipSync/ShipThrusterVariableSyncer.cs b/QSB/ShipSync/ShipThrusterVariableSyncer.cs index a068d8d0..585c8ddd 100644 --- a/QSB/ShipSync/ShipThrusterVariableSyncer.cs +++ b/QSB/ShipSync/ShipThrusterVariableSyncer.cs @@ -24,7 +24,7 @@ public class ShipThrusterVariableSyncer : NetworkBehaviour return; } - if (AccelerationSyncer.HasChanged()) + if (AccelerationSyncer.HasChanged) { if (AccelerationSyncer.Value == Vector3.zero) { diff --git a/QSB/Syncs/QSBNetworkTransform.cs b/QSB/Syncs/QSBNetworkTransform.cs index 584898e4..ddf72bbf 100644 --- a/QSB/Syncs/QSBNetworkTransform.cs +++ b/QSB/Syncs/QSBNetworkTransform.cs @@ -14,7 +14,7 @@ public class QSBNetworkTransform : QSBNetworkBehaviour private Vector3 _prevPosition; private Quaternion _prevRotation; - public override bool HasChanged() => + protected override bool CheckChanged() => Vector3.Distance(transform.position, _prevPosition) > PositionChangeThreshold || Quaternion.Angle(transform.rotation, _prevRotation) > RotationChangeThreshold; diff --git a/QSB/Syncs/QSBNetworkTransformChild.cs b/QSB/Syncs/QSBNetworkTransformChild.cs index ff064d0d..fd829934 100644 --- a/QSB/Syncs/QSBNetworkTransformChild.cs +++ b/QSB/Syncs/QSBNetworkTransformChild.cs @@ -16,7 +16,7 @@ public class QSBNetworkTransformChild : QSBNetworkBehaviour private Vector3 _prevPosition; private Quaternion _prevRotation; - public override bool HasChanged() => + protected override bool CheckChanged() => Vector3.Distance(Target.localPosition, _prevPosition) > PositionChangeThreshold || Quaternion.Angle(Target.localRotation, _prevRotation) > RotationChangeThreshold; diff --git a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs index 7fb1e458..bfd7ff1f 100644 --- a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs +++ b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs @@ -36,8 +36,8 @@ public abstract class SectoredRigidbodySync : BaseSectoredSync ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null; } - public override bool HasChanged() => - base.HasChanged() || + protected override bool CheckChanged() => + base.CheckChanged() || Vector3.Distance(Velocity, _prevVelocity) > VelocityChangeThreshold || Vector3.Distance(AngularVelocity, _prevAngularVelocity) > AngularVelocityChangeThreshold; diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 6f8ab9ae..be35998e 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -198,7 +198,7 @@ public abstract class SyncBase : QSBNetworkTransform /// /// call the base method FIRST /// - public override bool HasChanged() + protected override bool CheckChanged() { GetFromAttached(); if (UseInterpolation) @@ -207,7 +207,7 @@ public abstract class SyncBase : QSBNetworkTransform SmoothRotation = transform.rotation; } - return base.HasChanged(); + return base.CheckChanged(); } /// diff --git a/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs b/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs index 56573829..ece3d92b 100644 --- a/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs +++ b/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs @@ -36,8 +36,8 @@ public abstract class UnsectoredRigidbodySync : BaseUnsectoredSync ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null; } - public override bool HasChanged() => - base.HasChanged() || + protected override bool CheckChanged() => + base.CheckChanged() || Vector3.Distance(Velocity, _prevVelocity) > VelocityChangeThreshold || Vector3.Distance(AngularVelocity, _prevAngularVelocity) > AngularVelocityChangeThreshold; diff --git a/QSB/Utility/QSBNetworkBehaviour.cs b/QSB/Utility/QSBNetworkBehaviour.cs index 54659cb4..28a118a1 100644 --- a/QSB/Utility/QSBNetworkBehaviour.cs +++ b/QSB/Utility/QSBNetworkBehaviour.cs @@ -20,10 +20,12 @@ public abstract class QSBNetworkBehaviour : NetworkBehaviour public override void OnStopClient() => RequestInitialStatesMessage.SendInitialState -= SendInitialState; + public bool HasChanged { get; private set; } + /// /// checked before serializing /// - public abstract bool HasChanged(); + protected abstract bool CheckChanged(); protected abstract void Serialize(NetworkWriter writer); @@ -54,7 +56,8 @@ public abstract class QSBNetworkBehaviour : NetworkBehaviour { _lastSendTime = NetworkTime.localTime; - if (!HasChanged()) + HasChanged = CheckChanged(); + if (!HasChanged) { return; } diff --git a/QSB/Utility/VariableSync/BaseVariableSyncer.cs b/QSB/Utility/VariableSync/BaseVariableSyncer.cs index 40c00c39..e25cddf1 100644 --- a/QSB/Utility/VariableSync/BaseVariableSyncer.cs +++ b/QSB/Utility/VariableSync/BaseVariableSyncer.cs @@ -12,7 +12,7 @@ public abstract class BaseVariableSyncer : QSBNetworkBehaviour [NonSerialized] public T Value; - public override bool HasChanged() => !EqualityComparer.Default.Equals(PrevValue, Value); + protected override bool CheckChanged() => !EqualityComparer.Default.Equals(PrevValue, Value); protected override void UpdatePrevData() => PrevValue = Value; protected override void Serialize(NetworkWriter writer) => writer.Write(Value); protected override void Deserialize(NetworkReader reader) => Value = reader.Read();