From 8e6bbcbf6509cf21507afb72443de26c04fecc46 Mon Sep 17 00:00:00 2001
From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com>
Date: Thu, 17 Jun 2021 00:14:42 -0500
Subject: [PATCH] Fix for asteroid settings not being resynced on server switch
---
SeamlessClientPlugin.csproj | 1 +
SeamlessTransfer/ModLoader.cs | 19 +++++++++++++++++++
SeamlessTransfer/SwitchServers.cs | 19 +++++++++++++++++++
Utilities/Patches.cs | 6 ++++++
4 files changed, 45 insertions(+)
create mode 100644 SeamlessTransfer/ModLoader.cs
diff --git a/SeamlessClientPlugin.csproj b/SeamlessClientPlugin.csproj
index 0f70936..943e1bf 100644
--- a/SeamlessClientPlugin.csproj
+++ b/SeamlessClientPlugin.csproj
@@ -162,6 +162,7 @@
+
diff --git a/SeamlessTransfer/ModLoader.cs b/SeamlessTransfer/ModLoader.cs
new file mode 100644
index 0000000..2c495b1
--- /dev/null
+++ b/SeamlessTransfer/ModLoader.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SeamlessClientPlugin.SeamlessTransfer
+{
+ public class ModLoader
+ {
+ /* Mod loader should download and load missing mods for target server, and unload ones that arent needed
+ *
+ *
+ *
+ *
+ */
+
+ }
+}
diff --git a/SeamlessTransfer/SwitchServers.cs b/SeamlessTransfer/SwitchServers.cs
index e7e40ca..b975cef 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.Game.World.Generator;
using Sandbox.ModAPI;
using SeamlessClientPlugin.Utilities;
using System;
@@ -111,6 +112,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer
LoadOnlinePlayers();
SetWorldSettings();
RemoveOldEntities();
+ UpdateWorldGenerator();
+
+
StartEntitySync();
MyModAPIHelper.Initialize();
@@ -322,6 +326,21 @@ namespace SeamlessClientPlugin.SeamlessTransfer
+ private void UpdateWorldGenerator()
+ {
+ //This will re-init the MyProceduralWorldGenerator. (Not doing this will result in asteroids not rendering in properly)
+
+ //This shoud never be null
+ var Generator = MySession.Static.GetComponent();
+
+ //Force component to unload
+ Patches.UnloadProceduralWorldGenerator.Invoke(Generator, null);
+
+ //Force component to reload, re-syncing settings and seeds to the destination server
+ Generator.LoadData();
+
+
+ }
private void UnloadCurrentServer()
{
diff --git a/Utilities/Patches.cs b/Utilities/Patches.cs
index c837e00..3abb77b 100644
--- a/Utilities/Patches.cs
+++ b/Utilities/Patches.cs
@@ -3,6 +3,7 @@ using Sandbox.Engine.Multiplayer;
using Sandbox.Engine.Networking;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.World;
+using Sandbox.Game.World.Generator;
using Sandbox.Graphics.GUI;
using System;
using System.Collections.Generic;
@@ -66,6 +67,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer
+ /* WorldGenerator */
+ public static MethodInfo UnloadProceduralWorldGenerator;
+
public static void GetPatches()
@@ -101,6 +105,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
LoadMembersFromWorld = GetMethod(typeof(MySession), "LoadMembersFromWorld", BindingFlags.NonPublic | BindingFlags.Instance);
LoadMultiplayer = GetMethod(typeof(MySession), "LoadMultiplayer", BindingFlags.Static | BindingFlags.NonPublic);
SendPlayerData = GetMethod(ClientType, "SendPlayerData", BindingFlags.Instance | BindingFlags.NonPublic);
+ UnloadProceduralWorldGenerator = GetMethod(typeof(MyProceduralWorldGenerator), "UnloadData", BindingFlags.Instance | BindingFlags.NonPublic);
+
MethodInfo ConnectToServer = GetMethod(typeof(MyGameService), "ConnectToServer", BindingFlags.Static | BindingFlags.Public);