Mod switching
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
using Sandbox.Definitions;
|
||||
using Sandbox.Engine.Networking;
|
||||
using Sandbox.Game.World;
|
||||
using Sandbox.ModAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using VRage.Game;
|
||||
using VRage.Game.GUI;
|
||||
|
||||
namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
{
|
||||
@@ -31,27 +34,55 @@ 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>();
|
||||
|
||||
|
||||
|
||||
//Mods that we need to Load
|
||||
private static List<MyObjectBuilder_Checkpoint.ModItem> TargetLoadMods = new List<MyObjectBuilder_Checkpoint.ModItem>();
|
||||
|
||||
//Mods that we need to UnLoad
|
||||
private static List<MyObjectBuilder_Checkpoint.ModItem> TargetUnLoadMods = new List<MyObjectBuilder_Checkpoint.ModItem>();
|
||||
|
||||
|
||||
private static bool FinishedDownloadingMods = false;
|
||||
private static bool DownloadSuccess = false;
|
||||
|
||||
private static DateTime DownloadTimeout;
|
||||
|
||||
private static MethodInfo PrepareBaseSession = typeof(MySession).GetMethod("PreloadModels", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
private static FieldInfo ScriptManager = typeof(MySession).GetField("ScriptManager", BindingFlags.Instance | BindingFlags.Public);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void DownloadNewMods(List<MyObjectBuilder_Checkpoint.ModItem> Target)
|
||||
{
|
||||
CurrentLoadedMods = MySession.Static.Mods;
|
||||
TargetServerMods = Target;
|
||||
|
||||
|
||||
|
||||
//Loop through our current mods
|
||||
foreach(var mod in CurrentLoadedMods)
|
||||
{
|
||||
if (!Target.Contains(mod))
|
||||
TargetUnLoadMods.Add(mod);
|
||||
}
|
||||
|
||||
|
||||
//Loop through our TargetMods
|
||||
foreach(var mod in Target)
|
||||
{
|
||||
if (!CurrentLoadedMods.Contains(mod))
|
||||
TargetLoadMods.Add(mod);
|
||||
}
|
||||
|
||||
|
||||
DownloadTimeout = DateTime.Now + TimeSpan.FromMinutes(5);
|
||||
SeamlessClient.TryShow("Downloading New Mods");
|
||||
MyWorkshop.DownloadModsAsync(Target, ModDownloadingFinished);
|
||||
MyWorkshop.DownloadModsAsync(TargetLoadMods, ModDownloadingFinished);
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +102,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadyModSwitch()
|
||||
|
||||
public static void ReadyModSwitch(MyObjectBuilder_Checkpoint checkpoint, MyObjectBuilder_Sector sector)
|
||||
{
|
||||
|
||||
while (!FinishedDownloadingMods)
|
||||
@@ -91,16 +123,50 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
if (!DownloadSuccess)
|
||||
return;
|
||||
|
||||
/*
|
||||
MySession.Static.ScriptManager.LoadData();
|
||||
|
||||
|
||||
//Create new script manager?
|
||||
ScriptManager.SetValue(MySession.Static, new MyScriptManager());
|
||||
|
||||
|
||||
MyGuiTextures.Static.Unload();
|
||||
MySession.Static.ScriptManager.Init(checkpoint.ScriptManagerData);
|
||||
MyDefinitionManager.Static.LoadData(TargetServerMods);
|
||||
PrepareBaseSession.Invoke(null, new object[] { sector });
|
||||
|
||||
|
||||
MyLocalCache.PreloadLocalInventoryConfig();
|
||||
SeamlessClient.TryShow("Finished transfering!");
|
||||
*/
|
||||
|
||||
|
||||
//SeamlessClient.TryShow("Finished transfering!");
|
||||
|
||||
|
||||
// PrepareBaseSession.Invoke(MySession.Static, new object[] { TargetServerMods, null });
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void UnloadOldScripts()
|
||||
{
|
||||
// MySandboxGame.Log.WriteLine(string.Format("Script loaded: {0}", value.FullName));
|
||||
int amount = 0;
|
||||
foreach (var mod in TargetUnLoadMods)
|
||||
{
|
||||
var val = MySession.Static.ScriptManager.Scripts.FirstOrDefault(x => x.Value.FullName.Contains(mod.PublishedFileId.ToString()));
|
||||
MySession.Static.ScriptManager.Scripts.Remove(val.Key);
|
||||
|
||||
amount++;
|
||||
}
|
||||
|
||||
SeamlessClient.TryShow($"Removed {amount} old scripts!");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user