From a4c99e8402b508a56b9f18717ee11021e13dcad5 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Thu, 13 Aug 2020 22:06:34 +0100 Subject: [PATCH 1/4] do stuff --- QSB/PlayerInfo.cs | 2 +- QSB/QSB.cs | 15 --------------- QSB/QSB.csproj | 5 +++++ QSB/QSBNetworkManager.cs | 1 + QSB/TimeSync/WakeUpPatches.cs | 25 +++++++++++++++++++++++++ QSB/TimeSync/WakeUpSync.cs | 12 ++++++++++++ QSB/Utility/QSBExtensions.cs | 10 ++++++++++ 7 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 QSB/TimeSync/WakeUpPatches.cs 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..09d02ecc 100644 --- a/QSB/QSB.cs +++ b/QSB/QSB.cs @@ -14,7 +14,6 @@ namespace QSB public static IModHelper Helper; public static string DefaultServerIP; public static bool DebugMode; - public static bool WokenUp; private void Awake() { @@ -32,20 +31,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..4306b13c 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -97,6 +97,10 @@ $(GameDir)\OuterWilds_Data\Managed\UnityEngine.Networking.dll + + False + D:\EpicGames\OuterWilds\OuterWilds_Data\Managed\UnityEngine.PhysicsModule.dll + False $(GameDir)\OuterWilds_Data\Managed\UnityEngine.TextRenderingModule.dll @@ -129,6 +133,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..88f5b012 --- /dev/null +++ b/QSB/TimeSync/WakeUpPatches.cs @@ -0,0 +1,25 @@ +using QSB.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace QSB.TimeSync +{ + public static class WakeUpPatches + { + public static void AddPatches() + { + QSB.Helper.HarmonyHelper.AddPrefix("OnStartOfTimeLoop", typeof(WakeUpPatches), nameof(WakeUpPatches.OnStartOfTimeLoopPrefix)); + } + + public static bool OnStartOfTimeLoopPrefix(ref PlayerCameraEffectController __instance) + { + if (__instance.gameObject.CompareTag("MainCamera") && LoadManager.GetCurrentScene() != OWScene.EyeOfTheUniverse) + { + __instance.Call("WakeUp"); + } + return false; + } + } +} diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index cb57175a..3b947f79 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -132,6 +132,7 @@ namespace QSB.TimeSync } _timeScale = MaxFastForwardSpeed; _state = State.FastForwarding; + SpinnerUI.Show(); } private void StartPausing() @@ -142,6 +143,7 @@ namespace QSB.TimeSync } _timeScale = 0f; _state = State.Pausing; + SpinnerUI.Show(); } private void ResetTimeScale() @@ -153,6 +155,9 @@ namespace QSB.TimeSync { EnableInput(); } + Physics.SyncTransforms(); + SpinnerUI.Hide(); + GlobalMessenger.FireEvent(EventNames.QSBPlayerStatesRequest); } private void DisableInput() @@ -213,6 +218,13 @@ namespace QSB.TimeSync Time.timeScale = _timeScale; } + if (LoadManager.GetCurrentScene() == OWScene.SolarSystem) + { + Locator.GetPlayerTransform().position = Locator.GetPlayerBody().GetComponent().GetInitialSpawnPoint().transform.position; + Locator.GetPlayerTransform().rotation = Locator.GetPlayerBody().GetComponent().GetInitialSpawnPoint().transform.rotation; + Physics.SyncTransforms(); + } + var isDoneFastForwarding = _state == State.FastForwarding && Time.timeSinceLevelLoad >= _serverTime; var isDonePausing = _state == State.Pausing && Time.timeSinceLevelLoad < _serverTime; diff --git a/QSB/Utility/QSBExtensions.cs b/QSB/Utility/QSBExtensions.cs index aacd8049..d50d38e4 100644 --- a/QSB/Utility/QSBExtensions.cs +++ b/QSB/Utility/QSBExtensions.cs @@ -26,5 +26,15 @@ namespace QSB.Utility } return name; } + + public static object Call(this object obj, string methodName, params object[] args) + { + var method = obj.GetType().GetMethod(methodName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + if (method != null) + { + return method.Invoke(obj, args); + } + return null; + } } } From 7c68ff02c3d373b0f9bc1dd9fa25910f36b810f8 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Thu, 13 Aug 2020 22:10:25 +0100 Subject: [PATCH 2/4] fixes --- QSB/TimeSync/WakeUpSync.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index 3b947f79..c66fda44 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -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; @@ -155,6 +156,7 @@ namespace QSB.TimeSync { EnableInput(); } + _isFirstFastForward = false; Physics.SyncTransforms(); SpinnerUI.Hide(); GlobalMessenger.FireEvent(EventNames.QSBPlayerStatesRequest); @@ -212,19 +214,19 @@ namespace QSB.TimeSync { var diff = _serverTime - Time.timeSinceLevelLoad; Time.timeScale = Mathf.Lerp(MinFastForwardSpeed, MaxFastForwardSpeed, Mathf.Abs(diff) / MaxFastForwardDiff); + + if (LoadManager.GetCurrentScene() == OWScene.SolarSystem && _isFirstFastForward) + { + Locator.GetPlayerTransform().position = Locator.GetPlayerBody().GetComponent().GetInitialSpawnPoint().transform.position; + Locator.GetPlayerTransform().rotation = Locator.GetPlayerBody().GetComponent().GetInitialSpawnPoint().transform.rotation; + Physics.SyncTransforms(); + } } else { Time.timeScale = _timeScale; } - if (LoadManager.GetCurrentScene() == OWScene.SolarSystem) - { - Locator.GetPlayerTransform().position = Locator.GetPlayerBody().GetComponent().GetInitialSpawnPoint().transform.position; - Locator.GetPlayerTransform().rotation = Locator.GetPlayerBody().GetComponent().GetInitialSpawnPoint().transform.rotation; - Physics.SyncTransforms(); - } - var isDoneFastForwarding = _state == State.FastForwarding && Time.timeSinceLevelLoad >= _serverTime; var isDonePausing = _state == State.Pausing && Time.timeSinceLevelLoad < _serverTime; From d822b23f74eb005265914428eeadbcc491887227 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Thu, 13 Aug 2020 22:17:18 +0100 Subject: [PATCH 3/4] fix --- QSB/QSB.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 4306b13c..66c9f979 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -99,7 +99,7 @@ False - D:\EpicGames\OuterWilds\OuterWilds_Data\Managed\UnityEngine.PhysicsModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.PhysicsModule.dll False From 871cb1d43747668b9fa2d823f25aef35f208afd7 Mon Sep 17 00:00:00 2001 From: Aleksander Waage Date: Fri, 14 Aug 2020 05:04:31 +0200 Subject: [PATCH 4/4] cleanup + showing clock when fast forwarding --- QSB/QSB.cs | 1 - QSB/QSB.csproj | 2 +- QSB/TimeSync/WakeUpPatches.cs | 10 +++------ QSB/TimeSync/WakeUpSync.cs | 12 ++++++----- QSB/Tools/ToolExtensions.cs | 17 +++++++++++++++ QSB/Utility/QSBExtensions.cs | 40 ----------------------------------- 6 files changed, 28 insertions(+), 54 deletions(-) create mode 100644 QSB/Tools/ToolExtensions.cs delete mode 100644 QSB/Utility/QSBExtensions.cs diff --git a/QSB/QSB.cs b/QSB/QSB.cs index 09d02ecc..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; diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 66c9f979..84230304 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -180,7 +180,7 @@ - + diff --git a/QSB/TimeSync/WakeUpPatches.cs b/QSB/TimeSync/WakeUpPatches.cs index 88f5b012..0bca8f7c 100644 --- a/QSB/TimeSync/WakeUpPatches.cs +++ b/QSB/TimeSync/WakeUpPatches.cs @@ -1,8 +1,4 @@ -using QSB.Utility; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using OWML.ModHelper.Events; namespace QSB.TimeSync { @@ -10,14 +6,14 @@ namespace QSB.TimeSync { public static void AddPatches() { - QSB.Helper.HarmonyHelper.AddPrefix("OnStartOfTimeLoop", typeof(WakeUpPatches), nameof(WakeUpPatches.OnStartOfTimeLoopPrefix)); + 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.Call("WakeUp"); + __instance.Invoke("WakeUp"); } return false; } diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index c66fda44..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; @@ -133,7 +133,7 @@ namespace QSB.TimeSync } _timeScale = MaxFastForwardSpeed; _state = State.FastForwarding; - SpinnerUI.Show(); + FindObjectOfType().Invoke("OnStartFastForward"); } private void StartPausing() @@ -159,6 +159,7 @@ namespace QSB.TimeSync _isFirstFastForward = false; Physics.SyncTransforms(); SpinnerUI.Hide(); + FindObjectOfType().Invoke("OnEndFastForward"); GlobalMessenger.FireEvent(EventNames.QSBPlayerStatesRequest); } @@ -217,8 +218,9 @@ namespace QSB.TimeSync if (LoadManager.GetCurrentScene() == OWScene.SolarSystem && _isFirstFastForward) { - Locator.GetPlayerTransform().position = Locator.GetPlayerBody().GetComponent().GetInitialSpawnPoint().transform.position; - Locator.GetPlayerTransform().rotation = Locator.GetPlayerBody().GetComponent().GetInitialSpawnPoint().transform.rotation; + var spawnPoint = Locator.GetPlayerBody().GetComponent().GetInitialSpawnPoint().transform; + Locator.GetPlayerTransform().position = spawnPoint.position; + Locator.GetPlayerTransform().rotation = spawnPoint.rotation; Physics.SyncTransforms(); } } 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 d50d38e4..00000000 --- a/QSB/Utility/QSBExtensions.cs +++ /dev/null @@ -1,40 +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; - } - - public static object Call(this object obj, string methodName, params object[] args) - { - var method = obj.GetType().GetMethod(methodName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); - if (method != null) - { - return method.Invoke(obj, args); - } - return null; - } - } -}