Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/LuaCs/LuaCsSetup.cs
1 using System.Collections.Generic;
2 using System.IO;
3 using System.Text;
4 
5 namespace Barotrauma
6 {
7  partial class LuaCsSetup
8  {
9  public void AddToGUIUpdateList()
10  {
12  {
14  }
15  }
16 
17  public void CheckInitialize()
18  {
19  List<ContentPackage> csharpMods = new List<ContentPackage>();
20  foreach (ContentPackage cp in ContentPackageManager.EnabledPackages.All)
21  {
22  if (Directory.Exists(cp.Dir + "/CSharp") || Directory.Exists(cp.Dir + "/bin"))
23  {
24  csharpMods.Add(cp);
25  }
26  }
27 
28  if (csharpMods.Count == 0 || ShouldRunCs)
29  {
30  Initialize();
31  return;
32  }
33 
34  StringBuilder sb = new StringBuilder();
35 
36  foreach (ContentPackage cp in csharpMods)
37  {
38  if (cp.UgcId.TryUnwrap(out ContentPackageId id))
39  {
40  sb.AppendLine($"- {cp.Name} ({id})");
41  }
42  else
43  {
44  sb.AppendLine($"- {cp.Name} (Not On Workshop)");
45  }
46  }
47 
49  {
50  new GUIMessageBox("", $"You have CSharp mods enabled but don't have the CSharp Scripting enabled, those mods might not work, go to the Main Menu, click on LuaCs Settings and check Enable CSharp Scripting.\n\n{sb}");
51  Initialize();
52  return;
53  }
54 
55  GUIMessageBox msg = new GUIMessageBox(
56  "Confirm",
57  $"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.",
58  new LocalizedString[2] { "Run", "Don't Run" });
59 
60  msg.Buttons[0].OnClicked = (GUIButton button, object obj) =>
61  {
62  Initialize(true);
63  msg.Close();
64  return true;
65  };
66 
67  msg.Buttons[1].OnClicked = (GUIButton button, object obj) =>
68  {
69  Initialize();
70  msg.Close();
71  return true;
72  };
73  }
74  }
75 }
readonly Option< ContentPackageId > UgcId
List< GUIButton > Buttons
static GameClient Client
Definition: GameMain.cs:188
static LuaCsSetup LuaCs
Definition: GameMain.cs:26