Remove all uses of the Cs Package now that we don't need it anymore
LuaCs Settings no longer uses LuaCsConfig Cs Package is no longer is used for enabling CSharp Scripting (except for dedicated server, to not make those people confused) Added popups for when you have CSharp mods enabled but don't have CSharp enabled when going to singleplayer/multiplayer
This commit is contained in:
@@ -179,7 +179,7 @@ namespace Barotrauma.Tutorials
|
||||
|
||||
public void Start()
|
||||
{
|
||||
GameMain.LuaCs.Initialize();
|
||||
GameMain.LuaCs.CheckInitialize();
|
||||
|
||||
GameMain.Instance.ShowLoading(Loading());
|
||||
ObjectiveManager.ResetObjectives();
|
||||
|
||||
@@ -19,12 +19,12 @@ namespace Barotrauma
|
||||
|
||||
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Force Enable CSharp")
|
||||
{
|
||||
Selected = GameMain.LuaCs.Config.ForceCsScripting,
|
||||
ToolTip = "This forces CSharp Scripting to be always enabled regardless if you have the package or not.",
|
||||
Selected = GameMain.LuaCs.Config.EnableCsScripting,
|
||||
ToolTip = "This enables CSharp Scripting for mods to use, WARNING: CSharp is NOT sandboxed, be careful with what mods you download.",
|
||||
OnSelected = (GUITickBox tick) =>
|
||||
{
|
||||
GameMain.LuaCs.Config.ForceCsScripting = tick.Selected;
|
||||
GameMain.LuaCs.UpdateConfig();
|
||||
GameMain.LuaCs.Config.EnableCsScripting = tick.Selected;
|
||||
GameMain.LuaCs.WriteSettings();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace Barotrauma
|
||||
OnSelected = (GUITickBox tick) =>
|
||||
{
|
||||
GameMain.LuaCs.Config.TreatForcedModsAsNormal = tick.Selected;
|
||||
GameMain.LuaCs.UpdateConfig();
|
||||
GameMain.LuaCs.WriteSettings();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace Barotrauma
|
||||
OnSelected = (GUITickBox tick) =>
|
||||
{
|
||||
GameMain.LuaCs.Config.PreferToUseWorkshopLuaSetup = tick.Selected;
|
||||
GameMain.LuaCs.UpdateConfig();
|
||||
GameMain.LuaCs.WriteSettings();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace Barotrauma
|
||||
OnSelected = (GUITickBox tick) =>
|
||||
{
|
||||
GameMain.LuaCs.Config.DisableErrorGUIOverlay = tick.Selected;
|
||||
GameMain.LuaCs.UpdateConfig();
|
||||
GameMain.LuaCs.WriteSettings();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ namespace Barotrauma
|
||||
OnSelected = (GUITickBox tick) =>
|
||||
{
|
||||
GameMain.LuaCs.Config.HideUserNames = tick.Selected;
|
||||
GameMain.LuaCs.UpdateConfig();
|
||||
GameMain.LuaCs.WriteSettings();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,19 +25,12 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
if (csharpMods.Count == 0 || ShouldRunCs || GameMain.Client == null)
|
||||
if (csharpMods.Count == 0 || ShouldRunCs)
|
||||
{
|
||||
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.");
|
||||
Initialize();
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
foreach (ContentPackage cp in csharpMods)
|
||||
@@ -52,6 +45,13 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
if (GameMain.Client == null || GameMain.Client.IsServerOwner)
|
||||
{
|
||||
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}");
|
||||
Initialize();
|
||||
return;
|
||||
}
|
||||
|
||||
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.",
|
||||
|
||||
@@ -1235,7 +1235,7 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
GameMain.LuaCs.Initialize();
|
||||
GameMain.LuaCs.CheckInitialize();
|
||||
|
||||
selectedSub = new SubmarineInfo(Path.Combine(SaveUtil.TempPath, selectedSub.Name + ".sub"));
|
||||
|
||||
@@ -1252,7 +1252,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(saveFile)) return;
|
||||
|
||||
GameMain.LuaCs.Initialize();
|
||||
GameMain.LuaCs.CheckInitialize();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1345,7 +1345,7 @@ namespace Barotrauma
|
||||
{
|
||||
Select(enableAutoSave: true);
|
||||
|
||||
GameMain.LuaCs.Initialize();
|
||||
GameMain.LuaCs.CheckInitialize();
|
||||
}
|
||||
|
||||
public void Select(bool enableAutoSave = true)
|
||||
|
||||
@@ -10,17 +10,22 @@ using System.Diagnostics;
|
||||
using MoonSharp.VsCodeDebugger;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.Networking;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class LuaCsSetupConfig
|
||||
{
|
||||
public bool FirstTimeCsWarning = true;
|
||||
public bool ForceCsScripting = false;
|
||||
public bool EnableCsScripting = false;
|
||||
public bool TreatForcedModsAsNormal = true;
|
||||
public bool PreferToUseWorkshopLuaSetup = false;
|
||||
public bool DisableErrorGUIOverlay = false;
|
||||
public bool HideUserNames = true;
|
||||
public bool HideUserNames
|
||||
{
|
||||
get { return LuaCsLogger.HideUserNames; }
|
||||
set { LuaCsLogger.HideUserNames = value; }
|
||||
}
|
||||
|
||||
public LuaCsSetupConfig() { }
|
||||
}
|
||||
@@ -96,7 +101,11 @@ namespace Barotrauma
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetPackage(CsForBarotraumaId, false, true) != null || Config.ForceCsScripting;
|
||||
#if SERVER
|
||||
if (GetPackage(CsForBarotraumaId, false, false) != null && GameMain.Server.ServerPeer is LidgrenServerPeer) { return true; }
|
||||
#endif
|
||||
|
||||
return Config.EnableCsScripting;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,19 +120,7 @@ namespace Barotrauma
|
||||
Networking = new LuaCsNetworking();
|
||||
DebugServer = new MoonSharpVsCodeDebugServer();
|
||||
|
||||
if (File.Exists(configFileName))
|
||||
{
|
||||
using (var file = File.Open(configFileName, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
Config = LuaCsConfig.Load<LuaCsSetupConfig>(file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Config = new LuaCsSetupConfig();
|
||||
}
|
||||
|
||||
UpdateConfigVars();
|
||||
ReadSettings();
|
||||
}
|
||||
|
||||
[Obsolete("Use AssemblyManager::GetTypesByName()")]
|
||||
@@ -164,20 +161,41 @@ namespace Barotrauma
|
||||
|
||||
public void DetachDebugger() => DebugServer.Detach(Lua);
|
||||
|
||||
public void UpdateConfigVars()
|
||||
public void ReadSettings()
|
||||
{
|
||||
LuaCsLogger.HideUserNames = Config.HideUserNames;
|
||||
Config = new LuaCsSetupConfig();
|
||||
|
||||
if (File.Exists(configFileName))
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var file = File.Open(configFileName, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
XDocument document = XDocument.Load(file);
|
||||
Config.EnableCsScripting = bool.Parse(document.Root.Element("ForceCsScripting").Value);
|
||||
Config.TreatForcedModsAsNormal = bool.Parse(document.Root.Element("TreatForcedModsAsNormal").Value);
|
||||
Config.PreferToUseWorkshopLuaSetup = bool.Parse(document.Root.Element("PreferToUseWorkshopLuaSetup").Value);
|
||||
Config.DisableErrorGUIOverlay = bool.Parse(document.Root.Element("DisableErrorGUIOverlay").Value);
|
||||
Config.HideUserNames = bool.Parse(document.Root.Element("HideUserNames").Value);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LuaCsLogger.HandleException(e, LuaCsMessageOrigin.LuaCs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateConfig()
|
||||
public void WriteSettings()
|
||||
{
|
||||
FileStream file;
|
||||
if (!File.Exists(configFileName)) { file = File.Create(configFileName); }
|
||||
else { file = File.Open(configFileName, FileMode.Truncate, FileAccess.Write); }
|
||||
LuaCsConfig.Save(file, Config);
|
||||
file.Close();
|
||||
|
||||
UpdateConfigVars();
|
||||
XDocument document = new XDocument();
|
||||
document.Add(new XElement("LuaCsSetupConfig"));
|
||||
document.Root.Add(new XElement("ForceCsScripting", Config.EnableCsScripting));
|
||||
document.Root.Add(new XElement("TreatForcedModsAsNormal", Config.TreatForcedModsAsNormal));
|
||||
document.Root.Add(new XElement("PreferToUseWorkshopLuaSetup", Config.PreferToUseWorkshopLuaSetup));
|
||||
document.Root.Add(new XElement("DisableErrorGUIOverlay", Config.DisableErrorGUIOverlay));
|
||||
document.Root.Add(new XElement("HideUserNames", Config.HideUserNames));
|
||||
document.Save(configFileName);
|
||||
}
|
||||
|
||||
public static ContentPackage GetPackage(ContentPackageId id, bool fallbackToAll = true, bool useBackup = false)
|
||||
@@ -393,9 +411,6 @@ namespace Barotrauma
|
||||
UserData.RegisterType<LuaUserData>();
|
||||
UserData.RegisterType<LuaCsPerformanceCounter>();
|
||||
UserData.RegisterType<IUserDataDescriptor>();
|
||||
UserData.RegisterType<CsPackageManager>();
|
||||
UserData.RegisterType<AssemblyManager>();
|
||||
UserData.RegisterType<IAssemblyPlugin>();
|
||||
|
||||
UserData.RegisterExtensionType(typeof(MathUtils));
|
||||
UserData.RegisterExtensionType(typeof(XMLExtensions));
|
||||
@@ -438,13 +453,9 @@ namespace Barotrauma
|
||||
{
|
||||
LuaCsLogger.LogMessage("Cs! Version " + AssemblyInfo.GitRevision);
|
||||
|
||||
if (Config.FirstTimeCsWarning)
|
||||
{
|
||||
Config.FirstTimeCsWarning = false;
|
||||
UpdateConfig();
|
||||
|
||||
DebugConsole.AddWarning("Cs package active! Cs mods are NOT sandboxed, use it at your own risk!");
|
||||
}
|
||||
UserData.RegisterType<CsPackageManager>();
|
||||
UserData.RegisterType<AssemblyManager>();
|
||||
UserData.RegisterType<IAssemblyPlugin>();
|
||||
|
||||
Lua.Globals["PluginPackageManager"] = PluginPackageManager;
|
||||
Lua.Globals["AssemblyManager"] = AssemblyManager;
|
||||
|
||||
Reference in New Issue
Block a user