Fix issue with TorchMod being added to the server config. (also removes TorchMod from any extant config to avoid Problems)

This commit is contained in:
Brant Martin
2018-07-20 10:05:08 -04:00
parent 94c25a70b3
commit 9a0e7809cd
2 changed files with 11 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ using Sandbox.Game.Gui;
using Torch.API; using Torch.API;
using Torch.API.Managers; using Torch.API.Managers;
using Torch.Managers; using Torch.Managers;
using Torch.Mod;
using Torch.Server.ViewModels; using Torch.Server.ViewModels;
using VRage; using VRage;
using VRage.FileSystem; using VRage.FileSystem;
@@ -90,6 +91,8 @@ namespace Torch.Server.Managers
if (DedicatedConfig.SelectedWorld?.Checkpoint != null) if (DedicatedConfig.SelectedWorld?.Checkpoint != null)
{ {
DedicatedConfig.Mods.Clear(); DedicatedConfig.Mods.Clear();
//remove the Torch mod to avoid running multiple copies of it
DedicatedConfig.SelectedWorld.Checkpoint.Mods.RemoveAll(m => m.PublishedFileId == TorchModCore.MOD_ID);
foreach (var m in DedicatedConfig.SelectedWorld.Checkpoint.Mods) foreach (var m in DedicatedConfig.SelectedWorld.Checkpoint.Mods)
DedicatedConfig.Mods.Add(m.PublishedFileId); DedicatedConfig.Mods.Add(m.PublishedFileId);
} }
@@ -102,6 +105,8 @@ namespace Torch.Server.Managers
if (DedicatedConfig.SelectedWorld?.Checkpoint != null) if (DedicatedConfig.SelectedWorld?.Checkpoint != null)
{ {
DedicatedConfig.Mods.Clear(); DedicatedConfig.Mods.Clear();
//remove the Torch mod to avoid running multiple copies of it
DedicatedConfig.SelectedWorld.Checkpoint.Mods.RemoveAll(m => m.PublishedFileId == TorchModCore.MOD_ID);
foreach (var m in DedicatedConfig.SelectedWorld.Checkpoint.Mods) foreach (var m in DedicatedConfig.SelectedWorld.Checkpoint.Mods)
DedicatedConfig.Mods.Add(m.PublishedFileId); DedicatedConfig.Mods.Add(m.PublishedFileId);
} }

View File

@@ -1,9 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLog;
using Sandbox.Game.World; using Sandbox.Game.World;
using Torch.Managers.PatchManager; using Torch.Managers.PatchManager;
using Torch.Mod; using Torch.Mod;
@@ -22,8 +24,10 @@ namespace Torch.Patches
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
private static void SuffixGetWorld(ref MyObjectBuilder_World __result) private static void SuffixGetWorld(ref MyObjectBuilder_World __result)
{ {
if (!__result.Checkpoint.Mods.Any(m => m.PublishedFileId == TorchModCore.MOD_ID)) //copy this list so mods added here don't propagate up to the real session
__result.Checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(TorchModCore.MOD_ID)); __result.Checkpoint.Mods = __result.Checkpoint.Mods.ToList();
__result.Checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(TorchModCore.MOD_ID));
} }
} }
} }