Added settings that allow you to force turn on CSharp, treat forced mods as normal and allow for the workshop lua setup to be the preferred one
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
static class LuaCsSettingsMenu
|
||||
{
|
||||
private static GUIFrame frame;
|
||||
|
||||
public static void Open(RectTransform rectTransform)
|
||||
{
|
||||
Close();
|
||||
|
||||
frame = new GUIFrame(new RectTransform(new Vector2(0.4f, 0.6f), rectTransform, Anchor.Center));
|
||||
|
||||
GUIListBox list = new GUIListBox(new RectTransform(new Vector2(0.95f, 0.95f), frame.RectTransform, Anchor.Center), false);
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1f, 0.1f), list.Content.RectTransform), "LuaCs Settings", textAlignment: Alignment.Center);
|
||||
|
||||
|
||||
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.",
|
||||
OnSelected = (GUITickBox tick) =>
|
||||
{
|
||||
GameMain.LuaCs.Config.ForceCsScripting = tick.Selected;
|
||||
GameMain.LuaCs.UpdateConfig();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Treat Forced Mods As Normal")
|
||||
{
|
||||
Selected = GameMain.LuaCs.Config.TreatForcedModsAsNormal,
|
||||
ToolTip = "This makes mods that were setup to run even when disabled to only run when enabled.",
|
||||
OnSelected = (GUITickBox tick) =>
|
||||
{
|
||||
GameMain.LuaCs.Config.TreatForcedModsAsNormal = tick.Selected;
|
||||
GameMain.LuaCs.UpdateConfig();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Prefer To Use Workshop Lua Setup")
|
||||
{
|
||||
Selected = GameMain.LuaCs.Config.PreferToUseWorkshopLuaSetup,
|
||||
ToolTip = "This makes Lua look first for the Lua/LuaSetup.lua located in the Workshop package instead of the one located locally.",
|
||||
OnSelected = (GUITickBox tick) =>
|
||||
{
|
||||
GameMain.LuaCs.Config.PreferToUseWorkshopLuaSetup = tick.Selected;
|
||||
GameMain.LuaCs.UpdateConfig();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
new GUIButton(new RectTransform(new Vector2(1f, 0.1f), list.Content.RectTransform), $"Remove Client-Side LuaCs", style: "GUIButtonSmall")
|
||||
{
|
||||
ToolTip = "Remove Client-Side LuaCs.",
|
||||
OnClicked = (tb, userdata) =>
|
||||
{
|
||||
LuaCsInstaller.Uninstall();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
new GUIButton(new RectTransform(new Vector2(0.8f, 0.01f), frame.RectTransform, Anchor.BottomCenter)
|
||||
{
|
||||
RelativeOffset = new Vector2(0f, 0.05f)
|
||||
}, "Close")
|
||||
{
|
||||
OnClicked = (GUIButton button, object obj) =>
|
||||
{
|
||||
Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void Close()
|
||||
{
|
||||
frame?.Parent.RemoveChild(frame);
|
||||
frame = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,24 +420,20 @@ namespace Barotrauma
|
||||
}
|
||||
};
|
||||
#endif
|
||||
string additional = LuaCsSetup.GetPackage(LuaCsSetup.CsForBarotraumaId, false, true) == null ? "" : "Cs";
|
||||
|
||||
new GUIButton(new RectTransform(new Point(300, 30), Frame.RectTransform, Anchor.TopLeft) { AbsoluteOffset = new Point(20, 50) },
|
||||
$"Remove Client-Side Lua{additional}", style: "MainMenuGUIButton", color: GUIStyle.Red)
|
||||
new GUIButton(new RectTransform(new Point(300, 30), Frame.RectTransform, Anchor.TopLeft) { AbsoluteOffset = new Point(40, 50) },
|
||||
$"Open LuaCs Settings", style: "MainMenuGUIButton", color: GUIStyle.Red)
|
||||
{
|
||||
IgnoreLayoutGroups = true,
|
||||
UserData = Tab.Empty,
|
||||
ToolTip = "Remove Client-Side LuaCs.",
|
||||
OnClicked = (tb, userdata) =>
|
||||
{
|
||||
LuaCsInstaller.Uninstall();
|
||||
LuaCsSettingsMenu.Open(Frame.RectTransform);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
string version = File.Exists(LuaCsSetup.VersionFile) ? File.ReadAllText(LuaCsSetup.VersionFile) : "Github";
|
||||
|
||||
new GUITextBlock(new RectTransform(new Point(300, 30), Frame.RectTransform, Anchor.TopLeft) { AbsoluteOffset = new Point(10, 10) }, $"Using Lua{additional}ForBarotrauma revision {AssemblyInfo.GitRevision} version {version}", Color.Red)
|
||||
new GUITextBlock(new RectTransform(new Point(300, 30), Frame.RectTransform, Anchor.TopLeft) { AbsoluteOffset = new Point(10, 10) }, $"Using LuaCsForBarotrauma revision {AssemblyInfo.GitRevision} version {version}", Color.Red)
|
||||
{
|
||||
IgnoreLayoutGroups = false
|
||||
};
|
||||
|
||||
@@ -89,35 +89,28 @@ local function ProcessPackages(packages, fn)
|
||||
end
|
||||
end
|
||||
|
||||
ProcessPackages(
|
||||
ContentPackageManager.EnabledPackages.All,
|
||||
function(pkg, pkgPath)
|
||||
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
||||
local autorunPath = pkgPath .. LUA_MOD_AUTORUN_PATH
|
||||
if File.DirectoryExists(autorunPath) then
|
||||
QueueAutorun.Add(autorunPath, pkgPath, pkg)
|
||||
end
|
||||
ProcessPackages(ContentPackageManager.EnabledPackages.All, function(pkg, pkgPath)
|
||||
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
||||
local autorunPath = pkgPath .. LUA_MOD_AUTORUN_PATH
|
||||
if File.DirectoryExists(autorunPath) then
|
||||
QueueAutorun.Add(autorunPath, pkgPath, pkg)
|
||||
end
|
||||
)
|
||||
end)
|
||||
|
||||
-- we don't want to execute workshop ForcedAutorun if we have a local Package
|
||||
local executedLocalPackages = {}
|
||||
|
||||
ProcessPackages(
|
||||
ContentPackageManager.EnabledPackages.All,
|
||||
function(pkg, pkgPath)
|
||||
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
||||
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
|
||||
if File.DirectoryExists(forcedAutorunPath) then
|
||||
QueueForcedAutorun.Add(forcedAutorunPath, pkgPath, pkg)
|
||||
executedLocalPackages[pkg.Name] = true
|
||||
end
|
||||
ProcessPackages(ContentPackageManager.EnabledPackages.All, function(pkg, pkgPath)
|
||||
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
||||
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
|
||||
if File.DirectoryExists(forcedAutorunPath) then
|
||||
QueueForcedAutorun.Add(forcedAutorunPath, pkgPath, pkg)
|
||||
executedLocalPackages[pkg.Name] = true
|
||||
end
|
||||
)
|
||||
end)
|
||||
|
||||
ProcessPackages(
|
||||
ContentPackageManager.LocalPackages,
|
||||
function(pkg, pkgPath)
|
||||
if not LuaCsConfig.TreatForcedModsAsNormal then
|
||||
ProcessPackages(ContentPackageManager.LocalPackages, function(pkg, pkgPath)
|
||||
if not executedLocalPackages[pkg.Name] then
|
||||
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
||||
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
|
||||
@@ -126,12 +119,9 @@ ProcessPackages(
|
||||
executedLocalPackages[pkg.Name] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end)
|
||||
|
||||
ProcessPackages(
|
||||
ContentPackageManager.AllPackages,
|
||||
function(pkg, pkgPath)
|
||||
ProcessPackages(ContentPackageManager.AllPackages, function(pkg, pkgPath)
|
||||
if not executedLocalPackages[pkg.Name] then
|
||||
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
||||
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
|
||||
@@ -139,8 +129,8 @@ ProcessPackages(
|
||||
QueueForcedAutorun.Add(forcedAutorunPath, pkgPath, pkg)
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
setmodulepaths(package.path)
|
||||
setmodulepaths = nil
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Barotrauma
|
||||
LuaCsLogger.LogMessage($"Added {cp.Name} {cp.ModVersion} to Cs compilation. (Standard)");
|
||||
return true;
|
||||
}
|
||||
else if (rtValue == RunType.Forced)
|
||||
else if (rtValue == RunType.Forced && (isEnabled || !GameMain.LuaCs.Config.TreatForcedModsAsNormal))
|
||||
{
|
||||
LuaCsLogger.LogMessage($"Added {cp.Name} {cp.ModVersion} to Cs compilation. (Forced)");
|
||||
return true;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Barotrauma.Networking;
|
||||
using System.Collections.Generic;
|
||||
using MoonSharp.Interpreter;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MoonSharp.Interpreter.Interop;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Linq;
|
||||
@@ -17,6 +16,9 @@ namespace Barotrauma
|
||||
class LuaCsSetupConfig
|
||||
{
|
||||
public bool FirstTimeCsWarning = true;
|
||||
public bool ForceCsScripting = false;
|
||||
public bool TreatForcedModsAsNormal = false;
|
||||
public bool PreferToUseWorkshopLuaSetup = false;
|
||||
|
||||
public LuaCsSetupConfig() { }
|
||||
}
|
||||
@@ -70,6 +72,19 @@ namespace Barotrauma
|
||||
|
||||
Game = new LuaGame();
|
||||
Networking = new LuaCsNetworking();
|
||||
|
||||
if (File.Exists(configFileName))
|
||||
{
|
||||
using (var file = File.Open(configFileName, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
Config = LuaCsConfig.Load<LuaCsSetupConfig>(file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Config = new LuaCsSetupConfig();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void UpdateConfig()
|
||||
@@ -236,7 +251,6 @@ namespace Barotrauma
|
||||
LuaScriptLoader = null;
|
||||
Lua = null;
|
||||
CsScript = null;
|
||||
Config = null;
|
||||
|
||||
if (CsScriptLoader != null)
|
||||
{
|
||||
@@ -252,17 +266,7 @@ namespace Barotrauma
|
||||
|
||||
LuaCsLogger.LogMessage("Lua! Version " + AssemblyInfo.GitRevision);
|
||||
|
||||
if (File.Exists(configFileName))
|
||||
{
|
||||
using (var file = File.Open(configFileName, FileMode.Open, FileAccess.Read))
|
||||
Config = LuaCsConfig.Load<LuaCsSetupConfig>(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
Config = new LuaCsSetupConfig();
|
||||
}
|
||||
|
||||
bool csActive = GetPackage(CsForBarotraumaId, false, true) != null;
|
||||
bool csActive = GetPackage(CsForBarotraumaId, false, true) != null || Config.ForceCsScripting;
|
||||
|
||||
LuaScriptLoader = new LuaScriptLoader();
|
||||
LuaScriptLoader.ModulePaths = new string[] { };
|
||||
@@ -287,11 +291,11 @@ namespace Barotrauma
|
||||
ModStore.Initialize();
|
||||
|
||||
UserData.RegisterType<LuaCsConfig>();
|
||||
UserData.RegisterType<LuaCsSetupConfig>();
|
||||
UserData.RegisterType<LuaCsAction>();
|
||||
UserData.RegisterType<LuaCsFile>();
|
||||
UserData.RegisterType<LuaCsCompatPatchFunc>();
|
||||
UserData.RegisterType<LuaCsPatchFunc>();
|
||||
UserData.RegisterType<LuaCsConfig>();
|
||||
UserData.RegisterType<CsScriptRunner>();
|
||||
UserData.RegisterType<LuaGame>();
|
||||
UserData.RegisterType<LuaCsTimer>();
|
||||
@@ -323,6 +327,7 @@ namespace Barotrauma
|
||||
Lua.Globals["Networking"] = Networking;
|
||||
Lua.Globals["Steam"] = Steam;
|
||||
Lua.Globals["PerformanceCounter"] = PerformanceCounter;
|
||||
Lua.Globals["LuaCsConfig"] = Config;
|
||||
|
||||
Lua.Globals["ExecutionNumber"] = executionNumber;
|
||||
Lua.Globals["CSActive"] = csActive;
|
||||
@@ -376,39 +381,36 @@ namespace Barotrauma
|
||||
|
||||
ContentPackage luaPackage = GetPackage(LuaForBarotraumaId);
|
||||
|
||||
if (File.Exists(LuaSetupFile))
|
||||
void runLocal()
|
||||
{
|
||||
LuaCsLogger.LogMessage("Using LuaSetup.lua from the Barotrauma Lua/ folder.");
|
||||
|
||||
try
|
||||
{
|
||||
DynValue function = Lua.LoadFile(LuaSetupFile);
|
||||
CallLuaFunction(function, Path.GetDirectoryName(Path.GetFullPath(LuaSetupFile)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LuaCsLogger.HandleException(e, LuaCsMessageOrigin.LuaMod);
|
||||
}
|
||||
string luaPath = LuaSetupFile;
|
||||
CallLuaFunction(Lua.LoadFile(luaPath), Path.GetDirectoryName(Path.GetFullPath(luaPath)));
|
||||
}
|
||||
else if (luaPackage != null)
|
||||
|
||||
void runWorkshop()
|
||||
{
|
||||
LuaCsLogger.LogMessage("Using LuaSetup.lua from the content package.");
|
||||
string luaPath = Path.Combine(Path.GetDirectoryName(luaPackage.Path), "Binary/Lua/LuaSetup.lua");
|
||||
CallLuaFunction(Lua.LoadFile(luaPath), Path.GetDirectoryName(Path.GetFullPath(luaPath)));
|
||||
}
|
||||
|
||||
string path = Path.GetDirectoryName(luaPackage.Path);
|
||||
void runNone()
|
||||
{
|
||||
LuaCsLogger.LogError("LuaSetup.lua not found! Lua/LuaSetup.lua, no Lua scripts will be executed or work.", LuaCsMessageOrigin.LuaMod);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string luaPath = Path.Combine(path, "Binary/Lua/LuaSetup.lua");
|
||||
CallLuaFunction(Lua.LoadFile(luaPath), Path.GetDirectoryName(Path.GetFullPath(luaPath)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LuaCsLogger.HandleException(e, LuaCsMessageOrigin.LuaMod);
|
||||
}
|
||||
if (Config.PreferToUseWorkshopLuaSetup)
|
||||
{
|
||||
if (luaPackage != null) { runWorkshop(); }
|
||||
else if (File.Exists(LuaSetupFile)) { runLocal(); }
|
||||
else { runNone(); }
|
||||
}
|
||||
else
|
||||
{
|
||||
LuaCsLogger.LogError("LuaSetup.lua not found! Lua/LuaSetup.lua, no Lua scripts will be executed or work.", LuaCsMessageOrigin.LuaMod);
|
||||
if (File.Exists(LuaSetupFile)) { runLocal(); }
|
||||
else if (luaPackage != null) { runWorkshop(); }
|
||||
else { runNone(); }
|
||||
}
|
||||
|
||||
executionNumber++;
|
||||
|
||||
Reference in New Issue
Block a user