quantum-space-buddies/QSB/WakeUpSync.cs

60 lines
2.1 KiB
C#
Raw Normal View History

using OWML.ModHelper.Events;
2020-02-15 19:48:02 +00:00
using QSB.Messaging;
2020-02-21 22:36:07 +00:00
using UnityEngine;
2020-02-15 19:48:02 +00:00
namespace QSB
{
2020-02-21 22:36:07 +00:00
public class WakeUpSync : MonoBehaviour
2020-02-15 19:48:02 +00:00
{
public static bool IsServer;
2020-02-21 22:36:07 +00:00
private MessageHandler<WakeUpMessage> _wakeUpHandler;
2020-02-15 19:48:02 +00:00
private void Start()
{
DebugLog.Screen("Start WakeUpSync");
GlobalMessenger.AddListener("WakeUp", OnWakeUp);
2020-02-21 22:36:07 +00:00
_wakeUpHandler = new MessageHandler<WakeUpMessage>();
_wakeUpHandler.OnClientReceiveMessage += OnClientReceiveMessage;
}
2020-02-15 19:48:02 +00:00
private void OnWakeUp()
{
DebugLog.Screen("Sending wakeup to all my friends");
2020-02-15 19:48:02 +00:00
if (IsServer)
{
2020-02-21 22:36:07 +00:00
_wakeUpHandler.SendToAll(new WakeUpMessage());
}
}
2020-02-21 22:36:07 +00:00
private void OnClientReceiveMessage(WakeUpMessage message)
2020-02-15 19:48:02 +00:00
{
if (IsServer)
{
return;
}
// I copied all of this from my AutoResume mod, since that already wakes up the player instantly.
// There must be a simpler way to do this though, I just couldn't find it.
// Skip wake up animation.
var cameraEffectController = FindObjectOfType<PlayerCameraEffectController>();
cameraEffectController.OpenEyes(0, true);
cameraEffectController.SetValue("_wakeLength", 0f);
cameraEffectController.SetValue("_waitForWakeInput", false);
// Skip wake up prompt.
LateInitializerManager.pauseOnInitialization = false;
Locator.GetPauseCommandListener().RemovePauseCommandLock();
Locator.GetPromptManager().RemoveScreenPrompt(cameraEffectController.GetValue<ScreenPrompt>("_wakePrompt"));
OWTime.Unpause(OWTime.PauseType.Sleeping);
cameraEffectController.Invoke("WakeUp");
2020-02-15 19:48:02 +00:00
// Enable all inputs immediately.
OWInput.ChangeInputMode(InputMode.Character);
typeof(OWInput).SetValue("_inputFadeFraction", 0f);
GlobalMessenger.FireEvent("TakeFirstFlashbackSnapshot");
}
}
}