diff --git a/SeamlessClient.cs b/SeamlessClient.cs index 1e616cd..6a5b996 100644 --- a/SeamlessClient.cs +++ b/SeamlessClient.cs @@ -18,6 +18,7 @@ using System.Text; using System.Threading.Tasks; using System.Timers; using System.Windows.Forms; +using VRage.Game.ModAPI; using VRage.Input; using VRage.Plugins; using VRage.Utils; @@ -124,51 +125,31 @@ namespace SeamlessClientPlugin { Patches.GetPatches(); TryShow("Running Seamless Client Plugin v[" + Version + "]"); - PingTimer.Elapsed += PingTimer_Elapsed; - PingTimer.Start(); + // PingTimer.Elapsed += PingTimer_Elapsed; + // PingTimer.Start(); + + + + } + public void Update() { if (MyAPIGateway.Multiplayer == null) return; + if (!Initilized) { TryShow("Initilizing Communications!"); RunInitilizations(); } - - - - //OnNewPlayerRequest - //throw new NotImplementedException(); } - - - private void PingTimer_Elapsed(object sender, ElapsedEventArgs e) - { - // Terrible way to make sure server knows we are running seamless client - try - { - - - ClientMessage PingServer = new ClientMessage(ClientMessageType.FirstJoin); - MyAPIGateway.Multiplayer?.SendMessageToServer(SeamlessClientNetID, Utilities.Utility.Serialize(PingServer)); - } - catch (Exception ex) - { - //TryShow(ex.ToString()); - } - } - - - - public static void RunInitilizations() { MyAPIGateway.Multiplayer.RegisterSecureMessageHandler(SeamlessClientNetID, MessageHandler); @@ -189,12 +170,17 @@ namespace SeamlessClientPlugin try { ClientMessage Recieved = Utilities.Utility.Deserialize(obj2); - if (Recieved.MessageType == ClientMessageType.TransferServer) + + if(Recieved.MessageType == ClientMessageType.FirstJoin) { + //Server sent a first join message! Send a reply back so the server knows what version we are on + ClientMessage PingServer = new ClientMessage(ClientMessageType.FirstJoin); + MyAPIGateway.Multiplayer?.SendMessageToServer(SeamlessClientNetID, Utilities.Utility.Serialize(PingServer)); + } + else if (Recieved.MessageType == ClientMessageType.TransferServer) + { + //Server sent a transfer message! Begin transfer via seamless Transfer TransferMessage = Recieved.GetTransferData(); - - - ServerPing.StartServerPing(TransferMessage); } } @@ -213,6 +199,8 @@ namespace SeamlessClientPlugin MyLog.Default?.WriteLineAndConsole($"SeamlessClient: {message}"); } + + public void Dispose() { DisposeInitilizations(); diff --git a/SeamlessTransfer/PingServer.cs b/SeamlessTransfer/PingServer.cs index 5ec2162..218e9ea 100644 --- a/SeamlessTransfer/PingServer.cs +++ b/SeamlessTransfer/PingServer.cs @@ -42,11 +42,6 @@ namespace SeamlessClientPlugin.SeamlessTransfer SwitchServers Switcher = new SwitchServers(E, Request.DeserializeWorldData()); Switcher.BeginSwitch(); - - // MyGameService.OnPingServerResponded += PingResponded; - //MyGameService.OnPingServerFailedToRespond += FailedToRespond; - - //MyGameService.PingServer(Transfer.IPAdress); } } } diff --git a/SeamlessTransfer/SwitchServers.cs b/SeamlessTransfer/SwitchServers.cs index d616365..00e1a4e 100644 --- a/SeamlessTransfer/SwitchServers.cs +++ b/SeamlessTransfer/SwitchServers.cs @@ -123,9 +123,10 @@ namespace SeamlessClientPlugin.SeamlessTransfer RemoveOldEntities(); UpdateWorldGenerator(); - StartEntitySync(); + + MyModAPIHelper.Initialize(); // Allow the game to start proccessing incoming messages in the buffer MyMultiplayer.Static.StartProcessingClientMessages(); diff --git a/Utilities/Patches.cs b/Utilities/Patches.cs index f575607..23a4eb1 100644 --- a/Utilities/Patches.cs +++ b/Utilities/Patches.cs @@ -9,6 +9,8 @@ using Sandbox.Game.World; using Sandbox.Game.World.Generator; using Sandbox.Graphics; using Sandbox.Graphics.GUI; +using Sandbox.ModAPI; +using SeamlessClientPlugin.ClientMessages; using System; using System.Collections.Generic; using System.IO; @@ -115,23 +117,31 @@ namespace SeamlessClientPlugin.SeamlessTransfer - MethodInfo ConnectToServer = GetMethod(typeof(MyGameService), "ConnectToServer", BindingFlags.Static | BindingFlags.Public); + //MethodInfo ConnectToServer = GetMethod(typeof(MyGameService), "ConnectToServer", BindingFlags.Static | BindingFlags.Public); MethodInfo LoadingScreenDraw = GetMethod(typeof(MyGuiScreenLoading), "DrawInternal", BindingFlags.Instance | BindingFlags.NonPublic); + + Patcher.Patch(LoadingScreenDraw, prefix: new HarmonyMethod(GetPatchMethod(nameof(DrawInternal)))); Patcher.Patch(OnJoin, postfix: new HarmonyMethod(GetPatchMethod(nameof(OnUserJoined)))); Patcher.Patch(LoadingAction, prefix: new HarmonyMethod(GetPatchMethod(nameof(LoadMultiplayerSession)))); - //Patcher.Patch(ConnectToServer, prefix: new HarmonyMethod(GetPatchMethod(nameof(OnConnectToServer)))); } + + + private static MethodInfo GetPatchMethod(string v) { return typeof(Patches).GetMethod(v, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); } + + + + #region LoadingScreen /* Loading Screen Stuff */ @@ -142,6 +152,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer private static bool LoadMultiplayerSession(MyObjectBuilder_World world, MyMultiplayerBase multiplayerSession) { + if (SeamlessClient.IsSwitching) + return true; + MyLog.Default.WriteLine("LoadSession() - Start"); if (!MyWorkshop.CheckLocalModsAllowed(world.Checkpoint.Mods, allowLocalMods: false)) @@ -150,6 +163,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer MyLog.Default.WriteLine("LoadSession() - End"); return false; } + + MyWorkshop.DownloadModsAsync(world.Checkpoint.Mods, delegate (bool success) { if (success) @@ -302,6 +317,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer } } + + + private static bool OnConnectToServer(MyGameServerItem server, Action onDone) { if (SeamlessClient.IsSwitching) @@ -315,6 +333,10 @@ namespace SeamlessClientPlugin.SeamlessTransfer + + + /* Patch Utils */ + private static MethodInfo GetMethod(Type type, string MethodName, BindingFlags Flags) { try