quantum-space-buddies/QSB/WakeUpSync.cs

66 lines
2.2 KiB
C#
Raw Normal View History

using OWML.ModHelper.Events;
2020-02-15 20:48:02 +01:00
using QSB.Messaging;
using System;
using UnityEngine.Networking;
2020-02-15 20:48:02 +01:00
namespace QSB
{
public class WakeUpSync : MessageHandler
{
public static bool IsServer;
2020-02-15 20:48:02 +01:00
protected override MessageType Type => MessageType.WakeUp;
private void Start()
{
DebugLog.Screen("Start WakeUpSync");
GlobalMessenger.AddListener("WakeUp", OnWakeUp);
}
2020-02-15 20:48:02 +01:00
private void OnWakeUp()
{
DebugLog.Screen("Sending wakeup to all my friends");
2020-02-15 20:48:02 +01:00
if (IsServer)
{
var message = new WakeUpMessage();
2020-02-15 20:48:02 +01:00
NetworkServer.SendToAll((short)MessageType.WakeUp, message);
}
}
2020-02-15 20:48:02 +01:00
protected override void OnClientReceiveMessage(NetworkMessage netMsg)
{
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 20:48:02 +01:00
// Enable all inputs immediately.
OWInput.ChangeInputMode(InputMode.Character);
typeof(OWInput).SetValue("_inputFadeFraction", 0f);
GlobalMessenger.FireEvent("TakeFirstFlashbackSnapshot");
}
2020-02-15 20:48:02 +01:00
protected override void OnServerReceiveMessage(NetworkMessage netMsg)
{
throw new NotImplementedException();
}
2020-02-15 20:48:02 +01:00
}
}