diff --git a/QSB/PlayerInfo.cs b/QSB/PlayerInfo.cs index 60818bcc..d864e382 100644 --- a/QSB/PlayerInfo.cs +++ b/QSB/PlayerInfo.cs @@ -41,7 +41,7 @@ namespace QSB public void UpdateStateObjects() { - if (!QSB.WokenUp) + if (OWInput.GetInputMode() == InputMode.None) { return; } diff --git a/QSB/QSB.cs b/QSB/QSB.cs index e42428ae..ba41172e 100644 --- a/QSB/QSB.cs +++ b/QSB/QSB.cs @@ -1,7 +1,6 @@ using OWML.Common; using OWML.ModHelper; using QSB.ElevatorSync; -using QSB.Events; using QSB.GeyserSync; using QSB.Utility; using UnityEngine; @@ -14,7 +13,6 @@ namespace QSB public static IModHelper Helper; public static string DefaultServerIP; public static bool DebugMode; - public static bool WokenUp; private void Awake() { @@ -32,20 +30,6 @@ namespace QSB gameObject.AddComponent(); gameObject.AddComponent(); gameObject.AddComponent(); - - GlobalMessenger.AddListener(EventNames.RestartTimeLoop, OnLoopStart); - GlobalMessenger.AddListener(EventNames.WakeUp, OnWakeUp); - } - - private void OnWakeUp() - { - WokenUp = true; - GlobalMessenger.FireEvent(EventNames.QSBPlayerStatesRequest); - } - - private void OnLoopStart() - { - WokenUp = false; } public override void Configure(IModConfig config) diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 92a2a422..84230304 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -97,6 +97,10 @@ $(GameDir)\OuterWilds_Data\Managed\UnityEngine.Networking.dll + + False + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.PhysicsModule.dll + False $(GameDir)\OuterWilds_Data\Managed\UnityEngine.TextRenderingModule.dll @@ -129,6 +133,7 @@ + @@ -175,7 +180,7 @@ - + diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index c636a507..a5d29565 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -127,6 +127,7 @@ namespace QSB { gameObject.AddComponent(); GeyserManager.Instance.EmptyUpdate(); + WakeUpPatches.AddPatches(); } _canEditName = false; diff --git a/QSB/TimeSync/WakeUpPatches.cs b/QSB/TimeSync/WakeUpPatches.cs new file mode 100644 index 00000000..0bca8f7c --- /dev/null +++ b/QSB/TimeSync/WakeUpPatches.cs @@ -0,0 +1,21 @@ +using OWML.ModHelper.Events; + +namespace QSB.TimeSync +{ + public static class WakeUpPatches + { + public static void AddPatches() + { + QSB.Helper.HarmonyHelper.AddPrefix("OnStartOfTimeLoop", typeof(WakeUpPatches), nameof(OnStartOfTimeLoopPrefix)); + } + + public static bool OnStartOfTimeLoopPrefix(ref PlayerCameraEffectController __instance) + { + if (__instance.gameObject.CompareTag("MainCamera") && LoadManager.GetCurrentScene() != OWScene.EyeOfTheUniverse) + { + __instance.Invoke("WakeUp"); + } + return false; + } + } +} diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index cb57175a..fb0c2ff0 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -1,5 +1,5 @@ -using QSB.Events; -using QSB.Messaging; +using OWML.ModHelper.Events; +using QSB.Events; using UnityEngine; using UnityEngine.Networking; @@ -21,6 +21,7 @@ namespace QSB.TimeSync private float _serverTime; private float _timeScale; private bool _isInputEnabled = true; + private bool _isFirstFastForward = true; private int _localLoopCount; private int _serverLoopCount; @@ -132,6 +133,7 @@ namespace QSB.TimeSync } _timeScale = MaxFastForwardSpeed; _state = State.FastForwarding; + FindObjectOfType().Invoke("OnStartFastForward"); } private void StartPausing() @@ -142,6 +144,7 @@ namespace QSB.TimeSync } _timeScale = 0f; _state = State.Pausing; + SpinnerUI.Show(); } private void ResetTimeScale() @@ -153,6 +156,11 @@ namespace QSB.TimeSync { EnableInput(); } + _isFirstFastForward = false; + Physics.SyncTransforms(); + SpinnerUI.Hide(); + FindObjectOfType().Invoke("OnEndFastForward"); + GlobalMessenger.FireEvent(EventNames.QSBPlayerStatesRequest); } private void DisableInput() @@ -207,6 +215,14 @@ namespace QSB.TimeSync { var diff = _serverTime - Time.timeSinceLevelLoad; Time.timeScale = Mathf.Lerp(MinFastForwardSpeed, MaxFastForwardSpeed, Mathf.Abs(diff) / MaxFastForwardDiff); + + if (LoadManager.GetCurrentScene() == OWScene.SolarSystem && _isFirstFastForward) + { + var spawnPoint = Locator.GetPlayerBody().GetComponent().GetInitialSpawnPoint().transform; + Locator.GetPlayerTransform().position = spawnPoint.position; + Locator.GetPlayerTransform().rotation = spawnPoint.rotation; + Physics.SyncTransforms(); + } } else { diff --git a/QSB/Tools/ToolExtensions.cs b/QSB/Tools/ToolExtensions.cs new file mode 100644 index 00000000..67a871ad --- /dev/null +++ b/QSB/Tools/ToolExtensions.cs @@ -0,0 +1,17 @@ +namespace QSB.Tools +{ + public static class ToolExtensions + { + public static void ChangeEquipState(this PlayerTool tool, bool equipState) + { + if (equipState) + { + tool.EquipTool(); + } + else + { + tool.UnequipTool(); + } + } + } +} diff --git a/QSB/Utility/QSBExtensions.cs b/QSB/Utility/QSBExtensions.cs deleted file mode 100644 index aacd8049..00000000 --- a/QSB/Utility/QSBExtensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -using UnityEngine; - -namespace QSB.Utility -{ - public static class QSBExtensions - { - public static void ChangeEquipState(this PlayerTool tool, bool equipState) - { - if (equipState) - { - tool.EquipTool(); - } - else - { - tool.UnequipTool(); - } - } - - public static string GetHierarchy(this GameObject go) - { - var name = go.name; - while (go.transform.parent != null) - { - go = go.transform.parent.gameObject; - name = go.name + "/" + name; - } - return name; - } - } -}