diff --git a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsSetup.cs b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsSetup.cs new file mode 100644 index 000000000..d9a85ee69 --- /dev/null +++ b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsSetup.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace Barotrauma +{ + partial class LuaCsSetup + { + public void CheckInitialize() + { + List csharpMods = new List(); + foreach (ContentPackage cp in ContentPackageManager.EnabledPackages.All) + { + if (Directory.Exists(cp.Dir + "/CSharp")) + { + csharpMods.Add(cp); + } + } + + if (csharpMods.Count == 0 || ShouldRunCs || GameMain.Client == null) + { + Initialize(); + return; + } + + if (GameMain.Client.IsServerOwner) + { + new GUIMessageBox("", "You have CSharp mods enabled but don't have the Cs For Barotrauma package enabled, those mods might not work."); + return; + } + + StringBuilder sb = new StringBuilder(); + + foreach (ContentPackage cp in csharpMods) + { + if (cp.UgcId.TryUnwrap(out ContentPackageId id)) + { + sb.AppendLine($"- {cp.Name} ({id})"); + } + else + { + sb.AppendLine($"- {cp.Name} (Not On Workshop)"); + } + } + + GUIMessageBox msg = new GUIMessageBox( + "Confirm", + $"This server has the following CSharp mods installed: \n{sb}\nDo you wish to run them? Cs mods are not sandboxed so make sure you trust these mods.", + new LocalizedString[2] { "Run", "Don't Run" }); + + msg.Buttons[0].OnClicked = (GUIButton button, object obj) => + { + Initialize(true); + msg.Close(); + return true; + }; + + msg.Buttons[1].OnClicked = (GUIButton button, object obj) => + { + Initialize(); + msg.Close(); + return true; + }; + } + } +} diff --git a/Barotrauma/BarotraumaClient/ClientSource/Screens/ModDownloadScreen.cs b/Barotrauma/BarotraumaClient/ClientSource/Screens/ModDownloadScreen.cs index 536ebbd7d..81c40bd0d 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Screens/ModDownloadScreen.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Screens/ModDownloadScreen.cs @@ -116,7 +116,7 @@ namespace Barotrauma ContentPackageManager.EnabledPackages.SetRegular(regularPackages); } GameMain.NetLobbyScreen.Select(); - GameMain.LuaCs.Initialize(); + GameMain.LuaCs.CheckInitialize(); return; } diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs index 00d6df848..0cfb28954 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Collections.Generic; using MoonSharp.Interpreter; using MoonSharp.Interpreter.Interop; using System.Runtime.CompilerServices; @@ -65,6 +64,14 @@ namespace Barotrauma public CsScriptLoader CsScriptLoader { get; private set; } public LuaCsSetupConfig Config { get; private set; } + private bool ShouldRunCs + { + get + { + return GetPackage(CsForBarotraumaId, false, true) != null || Config.ForceCsScripting; + } + } + public LuaCsSetup() { Hook = new LuaCsHook(this); @@ -260,13 +267,13 @@ namespace Barotrauma } } - public void Initialize() + public void Initialize(bool forceEnableCs = false) { Stop(); LuaCsLogger.LogMessage("Lua! Version " + AssemblyInfo.GitRevision); - bool csActive = GetPackage(CsForBarotraumaId, false, true) != null || Config.ForceCsScripting; + bool csActive = ShouldRunCs || forceEnableCs; LuaScriptLoader = new LuaScriptLoader(); LuaScriptLoader.ModulePaths = new string[] { };