diff --git a/HKMP/Api/Client/IClientManager.cs b/HKMP/Api/Client/IClientManager.cs index 53ed9f15..18805b51 100644 --- a/HKMP/Api/Client/IClientManager.cs +++ b/HKMP/Api/Client/IClientManager.cs @@ -90,4 +90,14 @@ public interface IClientManager { /// Event that is called when another player leaves the local scene. /// event Action PlayerLeaveSceneEvent; + + /// + /// Event that is called when HKMP modifies the game's time scale. + /// + delegate void SetTimeScale(float timeScale); + + /// + /// Event that is called when HKMP modifies the game's time scale. + /// + event SetTimeScale OnSetTimeScale; } diff --git a/HKMP/Game/Client/ClientManager.cs b/HKMP/Game/Client/ClientManager.cs index 6ac6a69c..f5bdc98d 100644 --- a/HKMP/Game/Client/ClientManager.cs +++ b/HKMP/Game/Client/ClientManager.cs @@ -74,6 +74,11 @@ internal class ClientManager : IClientManager { /// private readonly EntityManager _entityManager; + /// + /// The pause manager instance. + /// + private readonly PauseManager _pauseManager; + /// /// The client addon manager instance. /// @@ -128,6 +133,9 @@ public string Username { /// public event Action PlayerLeaveSceneEvent; + /// + public event IClientManager.SetTimeScale OnSetTimeScale; + /// public Team Team => _playerManager.LocalPlayerTeam; @@ -180,7 +188,9 @@ ModSettings modSettings _entityManager = new EntityManager(netClient); - new PauseManager(netClient).RegisterHooks(); + _pauseManager = new PauseManager(netClient, timeScale => OnSetTimeScale?.Invoke(timeScale)); + _pauseManager.RegisterHooks(); + new FsmPatcher().RegisterHooks(); _commandManager = new ClientCommandManager(); @@ -327,7 +337,7 @@ private void InternalDisconnect() { // Check whether the game is in the pause menu and reset timescale to 0 in that case if (UIManager.instance.uiState.Equals(UIState.PAUSED)) { - PauseManager.SetTimeScale(0); + _pauseManager.SetTimeScale(0); } try { @@ -485,7 +495,7 @@ private void OnClientConnect(LoginResponse loginResponse) { // Since we are probably in the pause menu when we connect, set the timescale so the game // is running while paused - PauseManager.SetTimeScale(1.0f); + _pauseManager.SetTimeScale(1.0f); UiManager.InternalChatBox.AddMessage("You are connected to the server"); } diff --git a/HKMP/Game/Client/PauseManager.cs b/HKMP/Game/Client/PauseManager.cs index 89fda0fe..cab60a9b 100644 --- a/HKMP/Game/Client/PauseManager.cs +++ b/HKMP/Game/Client/PauseManager.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Reflection; using GlobalEnums; +using Hkmp.Api.Client; using Hkmp.Networking.Client; using Modding; using UnityEngine; @@ -15,9 +16,15 @@ internal class PauseManager { /// The net client instance. /// private readonly NetClient _netClient; + + /// + /// Hook for time scale changes. + /// + private readonly IClientManager.SetTimeScale _onSetTimeScale; - public PauseManager(NetClient netClient) { + public PauseManager(NetClient netClient, IClientManager.SetTimeScale onSetTimeScale) { _netClient = netClient; + _onSetTimeScale = onSetTimeScale; } /// @@ -194,7 +201,9 @@ private static void ImmediateUnpauseIfPaused() { /// Sets the time scale similarly to the method GameManager#SetTimeScale. /// /// The new time scale. - public static void SetTimeScale(float timeScale) { - TimeController.GenericTimeScale = timeScale > 0.00999999977648258 ? timeScale : 0.0f; + public void SetTimeScale(float timeScale) { + timeScale = timeScale > 0.00999999977648258 ? timeScale : 0.0f; + TimeController.GenericTimeScale = timeScale; + _onSetTimeScale(timeScale); } }