From e9cac15a3ae452d491c94ed6d1166e4bd7e17f64 Mon Sep 17 00:00:00 2001 From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com> Date: Mon, 10 May 2021 18:08:30 -0500 Subject: [PATCH] Fixed spectator issue --- SeamlessClient.cs | 2 +- SeamlessTransfer/SwitchServers.cs | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/SeamlessClient.cs b/SeamlessClient.cs index f2048b5..55e4f3e 100644 --- a/SeamlessClient.cs +++ b/SeamlessClient.cs @@ -182,7 +182,7 @@ namespace SeamlessClientPlugin public static void DisposeInitilizations() { PingTimer.Stop(); - MyAPIGateway.Multiplayer.UnregisterSecureMessageHandler(SeamlessClientNetID, MessageHandler); + MyAPIGateway.Multiplayer?.UnregisterSecureMessageHandler(SeamlessClientNetID, MessageHandler); Initilized = false; } diff --git a/SeamlessTransfer/SwitchServers.cs b/SeamlessTransfer/SwitchServers.cs index ec11521..a4baa59 100644 --- a/SeamlessTransfer/SwitchServers.cs +++ b/SeamlessTransfer/SwitchServers.cs @@ -7,6 +7,7 @@ using Sandbox.Game.Gui; using Sandbox.Game.GUI; using Sandbox.Game.Multiplayer; using Sandbox.Game.World; +using Sandbox.ModAPI; using SeamlessClientPlugin.Utilities; using System; using System.Collections.Concurrent; @@ -98,7 +99,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer RemoveOldEntities(); StartEntitySync(); - + MyModAPIHelper.Initialize(); // Allow the game to start proccessing incoming messages in the buffer MyMultiplayer.Static.StartProcessingClientMessages(); } @@ -107,12 +108,19 @@ namespace SeamlessClientPlugin.SeamlessTransfer private void LoadOnlinePlayers() { //Get This players ID + MyPlayer.PlayerId? savingPlayerId = new MyPlayer.PlayerId(Sync.MyId); if (!savingPlayerId.HasValue) { SeamlessClient.TryShow("SavingPlayerID is null! Creating Default!"); savingPlayerId = new MyPlayer.PlayerId(Sync.MyId); } + SeamlessClient.TryShow("Saving PlayerID: " + savingPlayerId.ToString()); + + Sync.Players.LoadConnectedPlayers(TargetWorld.Checkpoint, savingPlayerId); + Sync.Players.LoadControlledEntities(TargetWorld.Checkpoint.ControlledEntities, TargetWorld.Checkpoint.ControlledObject, savingPlayerId); + /* + SeamlessClient.TryShow("Saving PlayerID: " + savingPlayerId.ToString()); @@ -145,6 +153,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer } } + */ + } private void SetWorldSettings() @@ -169,8 +179,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer MySession.Static.WorldBoundaries = TargetWorld.Checkpoint.WorldBoundaries; MySession.Static.InGameTime = MyObjectBuilder_Checkpoint.DEFAULT_DATE; MySession.Static.ElapsedGameTime = new TimeSpan(TargetWorld.Checkpoint.ElapsedGameTime); - - + MySession.Static.Settings.EnableSpectator = false; + MySession.Static.Password = TargetWorld.Checkpoint.Password; MySession.Static.PreviousEnvironmentHostility = TargetWorld.Checkpoint.PreviousEnvironmentHostility; @@ -248,16 +258,23 @@ namespace SeamlessClientPlugin.SeamlessTransfer private void LoadConnectedClients() { + + + Patches.LoadMembersFromWorld.Invoke(MySession.Static, new object[] { TargetWorld, MyMultiplayer.Static }); + + //Re-Initilize Virtual clients object VirtualClientsValue = Patches.VirtualClients.GetValue(MySession.Static); Patches.InitVirtualClients.Invoke(VirtualClientsValue, null); + /* SeamlessClient.TryShow("Loading exsisting Members From World!"); foreach (var Client in TargetWorld.Checkpoint.Clients) { SeamlessClient.TryShow("Adding New Client: " + Client.Name); Sync.Clients.AddClient(Client.SteamId, Client.Name); - } + }*/ + } private void StartEntitySync()