From 21ac7c47331a13720341d0f6bdaf4a714d976c8e Mon Sep 17 00:00:00 2001 From: Garrett <52760019+Casimir255@users.noreply.github.com> Date: Wed, 17 Jul 2024 20:30:12 -0500 Subject: [PATCH] Minor fixes. Fixed game not pausing in offline mode, and possible fix for specific mods using script data --- Components/ServerSwitcherComponentOLD.cs | 20 ++++++++++++++++++++ Properties/AssemblyInfo.cs | 4 ++-- Seamless.cs | 9 +++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Components/ServerSwitcherComponentOLD.cs b/Components/ServerSwitcherComponentOLD.cs index 5c6ee6d..5cbfe46 100644 --- a/Components/ServerSwitcherComponentOLD.cs +++ b/Components/ServerSwitcherComponentOLD.cs @@ -27,6 +27,10 @@ using Sandbox.Game; using VRage.Game.ModAPI; using VRage.Utils; using SeamlessClient.ServerSwitching; +using System.Threading; +using System.Diagnostics; +using System.Runtime.Remoting.Metadata.W3cXsd2001; +using VRage.Scripting; namespace SeamlessClient.Components { @@ -41,6 +45,7 @@ namespace SeamlessClient.Components private static MethodInfo GpsRegisterChat; private static MethodInfo LoadMembersFromWorld; private static MethodInfo InitVirtualClients; + private static MethodInfo InitDataComponents; private static FieldInfo AdminSettings; private static FieldInfo RemoteAdminSettings; private static FieldInfo VirtualClients; @@ -52,6 +57,8 @@ namespace SeamlessClient.Components public static ServerSwitcherComponentOLD Instance { get; private set; } private string OldArmorSkin { get; set; } = string.Empty; + private static Stopwatch LoadTime = new Stopwatch(); + public ServerSwitcherComponentOLD() { Instance = this; } @@ -72,7 +79,9 @@ namespace SeamlessClient.Components RemoteAdminSettings = PatchUtils.GetField(typeof(MySession), "m_remoteAdminSettings"); LoadMembersFromWorld = PatchUtils.GetMethod(typeof(MySession), "LoadMembersFromWorld"); InitVirtualClients = PatchUtils.GetMethod(PatchUtils.VirtualClientsType, "Init"); + InitDataComponents = PatchUtils.GetMethod(typeof(MySession), "InitDataComponents"); VirtualClients = PatchUtils.GetField(typeof(MySession), "VirtualClients"); + patcher.Patch(onJoin, postfix: new HarmonyMethod(Get(typeof(ServerSwitcherComponentOLD), nameof(OnUserJoined)))); base.Patch(patcher); @@ -87,6 +96,9 @@ namespace SeamlessClient.Components //Invoke the switch event ForceClientConnection(); isSeamlessSwitching = false; + LoadTime.Stop(); + + MyAPIGateway.Utilities?.ShowMessage("Seamless", $"Loading Time: {LoadTime.Elapsed.ToString(@"s\.fff")}s"); } } @@ -97,6 +109,8 @@ namespace SeamlessClient.Components TargetServer = _TargetServer; TargetWorld = _TargetWorld; + + LoadTime.Start(); MySandboxGame.Static.Invoke(delegate { //Set camera controller to fixed spectator @@ -159,6 +173,8 @@ namespace SeamlessClient.Components MyModAPIHelper.Initialize(); MySession.Static.LoadDataComponents(); + InitDataComponents.Invoke(MySession.Static, null); + //MySession.Static.LoadObjectBuildersComponents(TargetWorld.Checkpoint.SessionComponents); MyModAPIHelper.Initialize(); @@ -188,6 +204,10 @@ namespace SeamlessClient.Components //Recreate all controls... Will fix weird gui/paint/crap MyGuiScreenHudSpace.Static?.RecreateControls(true); //MySession.Static.LocalHumanPlayer.BuildArmorSkin = OldArmorSkin; + + //Pop any queued pause popup messages. Dirty way + for(int i = 0; i < 10; i++) + MySandboxGame.PausePop(); } private static void LoadOnlinePlayers() diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 8dd9d50..c03939d 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -33,5 +33,5 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.6")] //Set these both to the same -[assembly: AssemblyFileVersion("2.0.0.6")] +[assembly: AssemblyVersion("2.0.0.7")] //Set these both to the same +[assembly: AssemblyFileVersion("2.0.0.7")] diff --git a/Seamless.cs b/Seamless.cs index ebf8184..2e5a7e3 100644 --- a/Seamless.cs +++ b/Seamless.cs @@ -162,8 +162,10 @@ namespace SeamlessClient public void Update() { allComps.ForEach(x => x.Update()); + - if (MyAPIGateway.Multiplayer == null) + //All this crap needs to be cleaned + if (MyAPIGateway.Multiplayer == null || MyAPIGateway.Multiplayer.MyId == MyAPIGateway.Multiplayer.ServerId) { isSeamlessServer = false; return; @@ -176,11 +178,6 @@ namespace SeamlessClient Initialized = true; } - - IMyGameServer server = MyServiceManager.Instance.GetService(); - MySandboxGame.PausePop(); - - }