From fd131845f005507e6687fb88e0a44b29726bce44 Mon Sep 17 00:00:00 2001 From: Garrett <52760019+Casimir255@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:00:10 -0500 Subject: [PATCH] Some more fixes --- Components/ServerSwitcherComponentOLD.cs | 69 +++++++++++++++++++++--- Properties/AssemblyInfo.cs | 4 +- Seamless.cs | 2 - 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/Components/ServerSwitcherComponentOLD.cs b/Components/ServerSwitcherComponentOLD.cs index 5cbfe46..ae5e7ad 100644 --- a/Components/ServerSwitcherComponentOLD.cs +++ b/Components/ServerSwitcherComponentOLD.cs @@ -31,6 +31,10 @@ using System.Threading; using System.Diagnostics; using System.Runtime.Remoting.Metadata.W3cXsd2001; using VRage.Scripting; +using EmptyKeys.UserInterface.Generated.StoreBlockView_Bindings; +using VRage.Game.Components; +using System.CodeDom; +using VRage.Collections; namespace SeamlessClient.Components { @@ -45,10 +49,10 @@ 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; + private static FieldInfo SessionComponents; private static PropertyInfo MySessionLayer; public static MyGameServerItem TargetServer { get; private set; } @@ -79,7 +83,7 @@ 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"); + SessionComponents = PatchUtils.GetField(typeof(MySession), "m_loadOrder"); VirtualClients = PatchUtils.GetField(typeof(MySession), "VirtualClients"); @@ -110,7 +114,7 @@ namespace SeamlessClient.Components TargetWorld = _TargetWorld; - LoadTime.Start(); + LoadTime.Restart(); MySandboxGame.Static.Invoke(delegate { //Set camera controller to fixed spectator @@ -173,7 +177,6 @@ namespace SeamlessClient.Components MyModAPIHelper.Initialize(); MySession.Static.LoadDataComponents(); - InitDataComponents.Invoke(MySession.Static, null); //MySession.Static.LoadObjectBuildersComponents(TargetWorld.Checkpoint.SessionComponents); @@ -190,7 +193,7 @@ namespace SeamlessClient.Components UpdateWorldGenerator(); - + UpdateSessionComponents(TargetWorld.Checkpoint.SessionComponents); StartEntitySync(); @@ -294,6 +297,8 @@ namespace SeamlessClient.Components MySession.Static.CustomSkybox = TargetWorld.Checkpoint.CustomSkybox; MyAPIUtilities.Static.Variables = TargetWorld.Checkpoint.ScriptManagerData.variables.Dictionary; + + try { @@ -403,6 +408,7 @@ namespace SeamlessClient.Components //typeof(MyGuiScreenTerminal).GetMethod("CreateTabs") MySession.Static.LoadDataComponents(); + //Session.Static.LoadObjectBuildersComponents(TargetWorld.Checkpoint.SessionComponents); //MyGuiSandbox.LoadData(false); //MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.HUDScreen)); MyRenderProxy.RebuildCullingStructure(); @@ -469,7 +475,7 @@ namespace SeamlessClient.Components MySessionComponentIngameHelp component = MySession.Static.GetComponent(); component?.TryCancelObjective(); - //Clear all old players and clients. + Sync.Clients.Clear(); Sync.Players.ClearPlayers(); @@ -482,8 +488,17 @@ namespace SeamlessClient.Components MySession.Static.Gpss.RemovePlayerGpss(MySession.Static.LocalPlayerId); MyHud.GpsMarkers.Clear(); MyMultiplayer.Static.ReplicationLayer.Disconnect(); + UnloadSessionComponents(); + + MyMultiplayer.Static.ReplicationLayer.Dispose(); + + + MyMultiplayer.Static.Dispose(); + + //Clear all old players and clients. + MyMultiplayer.Static = null; //Close any respawn screens that are open @@ -504,7 +519,49 @@ namespace SeamlessClient.Components } } + private void UnloadSessionComponents() + { + List sessions = (List)SessionComponents.GetValue(MySession.Static); + foreach(var session in sessions) + { + if(session.ModContext == null) + continue; + + if (session.Initialized == false) + continue; + + + MethodInfo unload = PatchUtils.GetMethod(typeof(MySessionComponentBase), "UnloadData"); + unload.Invoke(session, null); + FieldInfo inited = PatchUtils.GetField(typeof(MySessionComponentBase), "m_initialized"); + inited.SetValue(session, false); + + + MyLog.Default.WriteLine($"{session.GetType()}"); + } + } + + static List ValidInitTypes = new List() { typeof(MyProceduralWorldGenerator), typeof(MySessionComponentSafeZones) }; + + private static void UpdateSessionComponents(List objectBuilderData) + { + + FieldInfo sessionComps = PatchUtils.GetField(typeof(MySession), "m_sessionComponents"); + CachingDictionary dict = (CachingDictionary)sessionComps.GetValue(MySession.Static); + + foreach (var entity in objectBuilderData) + { + + Type t = MySessionComponentMapping.TryGetMappedSessionComponentType(entity.GetType()); + if(dict.TryGetValue(t, out var component) & ValidInitTypes.Contains(component.GetType())) + { + component.Init(entity); + } + } + + + } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c03939d..21db6a3 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.7")] //Set these both to the same -[assembly: AssemblyFileVersion("2.0.0.7")] +[assembly: AssemblyVersion("2.0.0.8")] //Set these both to the same +[assembly: AssemblyFileVersion("2.0.0.8")] diff --git a/Seamless.cs b/Seamless.cs index 2e5a7e3..55d9ba3 100644 --- a/Seamless.cs +++ b/Seamless.cs @@ -47,8 +47,6 @@ namespace SeamlessClient TryShow($"Running Seamless Client Plugin v[{SeamlessVersion}]"); SeamlessPatcher = new Harmony("SeamlessClientPatcher"); GetComponents(); - - PatchComponents(SeamlessPatcher); }