Started mod unloading/loading

This commit is contained in:
Bob Da Ross
2021-09-18 23:56:52 -05:00
parent 5d281c9fb2
commit 1f888260f2
3 changed files with 110 additions and 4 deletions

View File

@@ -1,12 +1,17 @@
using System;
using Sandbox.Definitions;
using Sandbox.Engine.Networking;
using Sandbox.Game.World;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using VRage.Game;
namespace SeamlessClientPlugin.SeamlessTransfer
{
public class ModLoader
public static class ModLoader
{
/* Mod loader should download and load missing mods for target server, and unload ones that arent needed
*
@@ -22,5 +27,80 @@ namespace SeamlessClientPlugin.SeamlessTransfer
*
*/
//Mods that are currently loaded in this instance.
private static List<MyObjectBuilder_Checkpoint.ModItem> CurrentLoadedMods = new List<MyObjectBuilder_Checkpoint.ModItem>();
//Mods that we are switching to.
private static List<MyObjectBuilder_Checkpoint.ModItem> TargetServerMods = new List<MyObjectBuilder_Checkpoint.ModItem>();
private static bool FinishedDownloadingMods = false;
private static bool DownloadSuccess = false;
private static DateTime DownloadTimeout;
public static void DownloadNewMods(List<MyObjectBuilder_Checkpoint.ModItem> Target)
{
CurrentLoadedMods = MySession.Static.Mods;
TargetServerMods = Target;
DownloadTimeout = DateTime.Now + TimeSpan.FromMinutes(5);
SeamlessClient.TryShow("Downloading New Mods");
MyWorkshop.DownloadModsAsync(Target, ModDownloadingFinished);
}
private static void ModDownloadingFinished(bool Success)
{
if (Success)
{
SeamlessClient.TryShow("Mod Downloading Finished!");
FinishedDownloadingMods = true;
DownloadSuccess = true;
//May need to wait seamless loading if mods have yet to finish downloading
}
else
{
DownloadSuccess = false;
FinishedDownloadingMods = true;
}
}
public static void ReadyModSwitch()
{
while (!FinishedDownloadingMods)
{
//Break out of loop
if (DownloadTimeout < DateTime.Now)
break;
Thread.Sleep(20);
}
FinishedDownloadingMods = false;
//Skip mod switch
if (!DownloadSuccess)
return;
MySession.Static.ScriptManager.LoadData();
MyDefinitionManager.Static.LoadData(TargetServerMods);
MyLocalCache.PreloadLocalInventoryConfig();
SeamlessClient.TryShow("Finished transfering!");
}
}
}

View File

@@ -40,6 +40,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
SeamlessClient.TryShow("Beginning Redirect to server: " + Transfer.TargetServerID);
SwitchServers Switcher = new SwitchServers(E, Request.DeserializeWorldData());
Switcher.BeginSwitch();
}

View File

@@ -1,4 +1,5 @@
using Sandbox;
using Sandbox.Definitions;
using Sandbox.Engine.Multiplayer;
using Sandbox.Engine.Networking;
using Sandbox.Game;
@@ -27,6 +28,7 @@ using VRage.Steam;
using VRage.Utils;
using VRageMath;
using VRageRender;
using VRageRender.Messages;
namespace SeamlessClientPlugin.SeamlessTransfer
{
@@ -42,6 +44,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
{
this.TargetServer = TargetServer;
this.TargetWorld = TargetWorld;
ModLoader.DownloadNewMods(TargetWorld.Checkpoint.Mods);
}
@@ -115,11 +119,31 @@ namespace SeamlessClientPlugin.SeamlessTransfer
MyHud.Chat.RegisterChat(MyMultiplayer.Static);
MyMultiplayer.Static.OnSessionReady();
LoadConnectedClients();
LoadOnlinePlayers();
SetWorldSettings();
ModLoader.ReadyModSwitch();
MySector.InitEnvironmentSettings(TargetWorld.Sector.Environment);
MyModAPIHelper.Initialize();
string text = ((!string.IsNullOrEmpty(TargetWorld.Checkpoint.CustomSkybox)) ? TargetWorld.Checkpoint.CustomSkybox : MySector.EnvironmentDefinition.EnvironmentTexture);
MyRenderProxy.PreloadTextures(new string[1] { text }, TextureType.CubeMap);
MySession.Static.LoadDataComponents();
MySession.Static.LoadObjectBuildersComponents(TargetWorld.Checkpoint.SessionComponents);
MethodInfo A = typeof(MySession).GetMethod("LoadGameDefinition", BindingFlags.Instance | BindingFlags.NonPublic);
A.Invoke(MySession.Static, new object[] { TargetWorld.Checkpoint });
MyMultiplayer.Static.OnSessionReady();
RemoveOldEntities();
UpdateWorldGenerator();
@@ -127,7 +151,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer
MyModAPIHelper.Initialize();
// Allow the game to start proccessing incoming messages in the buffer
MyMultiplayer.Static.StartProcessingClientMessages();