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()
|
public void Start()
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.Initialize();
|
GameMain.LuaCs.CheckInitialize();
|
||||||
|
|
||||||
GameMain.Instance.ShowLoading(Loading());
|
GameMain.Instance.ShowLoading(Loading());
|
||||||
ObjectiveManager.ResetObjectives();
|
ObjectiveManager.ResetObjectives();
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Force Enable CSharp")
|
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Force Enable CSharp")
|
||||||
{
|
{
|
||||||
Selected = GameMain.LuaCs.Config.ForceCsScripting,
|
Selected = GameMain.LuaCs.Config.EnableCsScripting,
|
||||||
ToolTip = "This forces CSharp Scripting to be always enabled regardless if you have the package or not.",
|
ToolTip = "This enables CSharp Scripting for mods to use, WARNING: CSharp is NOT sandboxed, be careful with what mods you download.",
|
||||||
OnSelected = (GUITickBox tick) =>
|
OnSelected = (GUITickBox tick) =>
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.Config.ForceCsScripting = tick.Selected;
|
GameMain.LuaCs.Config.EnableCsScripting = tick.Selected;
|
||||||
GameMain.LuaCs.UpdateConfig();
|
GameMain.LuaCs.WriteSettings();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ namespace Barotrauma
|
|||||||
OnSelected = (GUITickBox tick) =>
|
OnSelected = (GUITickBox tick) =>
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.Config.TreatForcedModsAsNormal = tick.Selected;
|
GameMain.LuaCs.Config.TreatForcedModsAsNormal = tick.Selected;
|
||||||
GameMain.LuaCs.UpdateConfig();
|
GameMain.LuaCs.WriteSettings();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ namespace Barotrauma
|
|||||||
OnSelected = (GUITickBox tick) =>
|
OnSelected = (GUITickBox tick) =>
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.Config.PreferToUseWorkshopLuaSetup = tick.Selected;
|
GameMain.LuaCs.Config.PreferToUseWorkshopLuaSetup = tick.Selected;
|
||||||
GameMain.LuaCs.UpdateConfig();
|
GameMain.LuaCs.WriteSettings();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ namespace Barotrauma
|
|||||||
OnSelected = (GUITickBox tick) =>
|
OnSelected = (GUITickBox tick) =>
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.Config.DisableErrorGUIOverlay = tick.Selected;
|
GameMain.LuaCs.Config.DisableErrorGUIOverlay = tick.Selected;
|
||||||
GameMain.LuaCs.UpdateConfig();
|
GameMain.LuaCs.WriteSettings();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ namespace Barotrauma
|
|||||||
OnSelected = (GUITickBox tick) =>
|
OnSelected = (GUITickBox tick) =>
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.Config.HideUserNames = tick.Selected;
|
GameMain.LuaCs.Config.HideUserNames = tick.Selected;
|
||||||
GameMain.LuaCs.UpdateConfig();
|
GameMain.LuaCs.WriteSettings();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,19 +25,12 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (csharpMods.Count == 0 || ShouldRunCs || GameMain.Client == null)
|
if (csharpMods.Count == 0 || ShouldRunCs)
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
return;
|
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();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
foreach (ContentPackage cp in csharpMods)
|
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(
|
GUIMessageBox msg = new GUIMessageBox(
|
||||||
"Confirm",
|
"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.",
|
$"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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameMain.LuaCs.Initialize();
|
GameMain.LuaCs.CheckInitialize();
|
||||||
|
|
||||||
selectedSub = new SubmarineInfo(Path.Combine(SaveUtil.TempPath, selectedSub.Name + ".sub"));
|
selectedSub = new SubmarineInfo(Path.Combine(SaveUtil.TempPath, selectedSub.Name + ".sub"));
|
||||||
|
|
||||||
@@ -1252,7 +1252,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(saveFile)) return;
|
if (string.IsNullOrWhiteSpace(saveFile)) return;
|
||||||
|
|
||||||
GameMain.LuaCs.Initialize();
|
GameMain.LuaCs.CheckInitialize();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1345,7 +1345,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
Select(enableAutoSave: true);
|
Select(enableAutoSave: true);
|
||||||
|
|
||||||
GameMain.LuaCs.Initialize();
|
GameMain.LuaCs.CheckInitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Select(bool enableAutoSave = true)
|
public void Select(bool enableAutoSave = true)
|
||||||
|
|||||||
@@ -10,17 +10,22 @@ using System.Diagnostics;
|
|||||||
using MoonSharp.VsCodeDebugger;
|
using MoonSharp.VsCodeDebugger;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Barotrauma.Networking;
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
class LuaCsSetupConfig
|
class LuaCsSetupConfig
|
||||||
{
|
{
|
||||||
public bool FirstTimeCsWarning = true;
|
public bool EnableCsScripting = false;
|
||||||
public bool ForceCsScripting = false;
|
|
||||||
public bool TreatForcedModsAsNormal = true;
|
public bool TreatForcedModsAsNormal = true;
|
||||||
public bool PreferToUseWorkshopLuaSetup = false;
|
public bool PreferToUseWorkshopLuaSetup = false;
|
||||||
public bool DisableErrorGUIOverlay = false;
|
public bool DisableErrorGUIOverlay = false;
|
||||||
public bool HideUserNames = true;
|
public bool HideUserNames
|
||||||
|
{
|
||||||
|
get { return LuaCsLogger.HideUserNames; }
|
||||||
|
set { LuaCsLogger.HideUserNames = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public LuaCsSetupConfig() { }
|
public LuaCsSetupConfig() { }
|
||||||
}
|
}
|
||||||
@@ -96,7 +101,11 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
get
|
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();
|
Networking = new LuaCsNetworking();
|
||||||
DebugServer = new MoonSharpVsCodeDebugServer();
|
DebugServer = new MoonSharpVsCodeDebugServer();
|
||||||
|
|
||||||
if (File.Exists(configFileName))
|
ReadSettings();
|
||||||
{
|
|
||||||
using (var file = File.Open(configFileName, FileMode.Open, FileAccess.Read))
|
|
||||||
{
|
|
||||||
Config = LuaCsConfig.Load<LuaCsSetupConfig>(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Config = new LuaCsSetupConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateConfigVars();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("Use AssemblyManager::GetTypesByName()")]
|
[Obsolete("Use AssemblyManager::GetTypesByName()")]
|
||||||
@@ -164,20 +161,41 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void DetachDebugger() => DebugServer.Detach(Lua);
|
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;
|
XDocument document = new XDocument();
|
||||||
if (!File.Exists(configFileName)) { file = File.Create(configFileName); }
|
document.Add(new XElement("LuaCsSetupConfig"));
|
||||||
else { file = File.Open(configFileName, FileMode.Truncate, FileAccess.Write); }
|
document.Root.Add(new XElement("ForceCsScripting", Config.EnableCsScripting));
|
||||||
LuaCsConfig.Save(file, Config);
|
document.Root.Add(new XElement("TreatForcedModsAsNormal", Config.TreatForcedModsAsNormal));
|
||||||
file.Close();
|
document.Root.Add(new XElement("PreferToUseWorkshopLuaSetup", Config.PreferToUseWorkshopLuaSetup));
|
||||||
|
document.Root.Add(new XElement("DisableErrorGUIOverlay", Config.DisableErrorGUIOverlay));
|
||||||
UpdateConfigVars();
|
document.Root.Add(new XElement("HideUserNames", Config.HideUserNames));
|
||||||
|
document.Save(configFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContentPackage GetPackage(ContentPackageId id, bool fallbackToAll = true, bool useBackup = false)
|
public static ContentPackage GetPackage(ContentPackageId id, bool fallbackToAll = true, bool useBackup = false)
|
||||||
@@ -393,9 +411,6 @@ namespace Barotrauma
|
|||||||
UserData.RegisterType<LuaUserData>();
|
UserData.RegisterType<LuaUserData>();
|
||||||
UserData.RegisterType<LuaCsPerformanceCounter>();
|
UserData.RegisterType<LuaCsPerformanceCounter>();
|
||||||
UserData.RegisterType<IUserDataDescriptor>();
|
UserData.RegisterType<IUserDataDescriptor>();
|
||||||
UserData.RegisterType<CsPackageManager>();
|
|
||||||
UserData.RegisterType<AssemblyManager>();
|
|
||||||
UserData.RegisterType<IAssemblyPlugin>();
|
|
||||||
|
|
||||||
UserData.RegisterExtensionType(typeof(MathUtils));
|
UserData.RegisterExtensionType(typeof(MathUtils));
|
||||||
UserData.RegisterExtensionType(typeof(XMLExtensions));
|
UserData.RegisterExtensionType(typeof(XMLExtensions));
|
||||||
@@ -438,13 +453,9 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
LuaCsLogger.LogMessage("Cs! Version " + AssemblyInfo.GitRevision);
|
LuaCsLogger.LogMessage("Cs! Version " + AssemblyInfo.GitRevision);
|
||||||
|
|
||||||
if (Config.FirstTimeCsWarning)
|
UserData.RegisterType<CsPackageManager>();
|
||||||
{
|
UserData.RegisterType<AssemblyManager>();
|
||||||
Config.FirstTimeCsWarning = false;
|
UserData.RegisterType<IAssemblyPlugin>();
|
||||||
UpdateConfig();
|
|
||||||
|
|
||||||
DebugConsole.AddWarning("Cs package active! Cs mods are NOT sandboxed, use it at your own risk!");
|
|
||||||
}
|
|
||||||
|
|
||||||
Lua.Globals["PluginPackageManager"] = PluginPackageManager;
|
Lua.Globals["PluginPackageManager"] = PluginPackageManager;
|
||||||
Lua.Globals["AssemblyManager"] = AssemblyManager;
|
Lua.Globals["AssemblyManager"] = AssemblyManager;
|
||||||
|
|||||||
Reference in New Issue
Block a user