From 3f5d0c9a8ea3d233729f0a9a09569bc3dae12ffb Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Sun, 14 Jul 2024 20:58:41 +0200 Subject: [PATCH] Wait for host to be ready before counting down (mod compat) --- Fika.Core/Coop/GameMode/CoopGame.cs | 23 +++++++++++++++++++ Fika.Core/Networking/FikaClient.cs | 1 + .../Packets/Backend/InformationPacket.cs | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 17034230..c3b57251 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -663,6 +663,27 @@ internal void DespawnBot(CoopHandler coopHandler, Player bot) /// public override IEnumerator vmethod_1() { + if (!isServer) + { + FikaClient fikaClient = Singleton.Instance; + do + { + yield return new WaitForEndOfFrame(); + } while (!fikaClient.HostReady); + } + else + { + FikaServer fikaServer = Singleton.Instance; + InformationPacket packet = new(false) + { + NumberOfPlayers = fikaServer.NetServer.ConnectedPeersCount, + ReadyPlayers = fikaServer.ReadyClients, + HostReady = true + }; + + fikaServer.SendDataToAll(new(), ref packet, LiteNetLib.DeliveryMethod.ReliableUnordered); + } + CoopPlayer coopPlayer = (CoopPlayer)PlayerOwner.Player; coopPlayer.PacketSender.Init(); @@ -1477,6 +1498,8 @@ private void OnMineExplode(MineDirectional directional) /// public override void vmethod_5() { + + GameTimer.Start(null, null); gparam_0.Player.HealthController.DiedEvent += HealthController_DiedEvent; gparam_0.vmethod_0(); diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index 80cf4605..e15f39c4 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -44,6 +44,7 @@ public class FikaClient : MonoBehaviour, INetEventListener public int Ping = 0; public int ConnectedClients = 0; public int ReadyClients = 0; + public bool HostReady = false; public NetManager NetClient { get diff --git a/Fika.Core/Networking/Packets/Backend/InformationPacket.cs b/Fika.Core/Networking/Packets/Backend/InformationPacket.cs index 3868c8a7..d2ebd63d 100644 --- a/Fika.Core/Networking/Packets/Backend/InformationPacket.cs +++ b/Fika.Core/Networking/Packets/Backend/InformationPacket.cs @@ -9,13 +9,14 @@ public struct InformationPacket(bool isRequest) : INetSerializable public bool IsRequest = isRequest; public int NumberOfPlayers = 0; public int ReadyPlayers = 0; - + public bool HostReady = false; public void Deserialize(NetDataReader reader) { IsRequest = reader.GetBool(); NumberOfPlayers = reader.GetInt(); ReadyPlayers = reader.GetInt(); + HostReady = reader.GetBool(); } public void Serialize(NetDataWriter writer) @@ -23,6 +24,7 @@ public void Serialize(NetDataWriter writer) writer.Put(IsRequest); writer.Put(NumberOfPlayers); writer.Put(ReadyPlayers); + writer.Put(HostReady); } } }