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
|
#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(40, 50) },
|
||||||
|
$"Open LuaCs Settings", style: "MainMenuGUIButton", color: GUIStyle.Red)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
IgnoreLayoutGroups = true,
|
IgnoreLayoutGroups = true,
|
||||||
UserData = Tab.Empty,
|
|
||||||
ToolTip = "Remove Client-Side LuaCs.",
|
|
||||||
OnClicked = (tb, userdata) =>
|
OnClicked = (tb, userdata) =>
|
||||||
{
|
{
|
||||||
LuaCsInstaller.Uninstall();
|
LuaCsSettingsMenu.Open(Frame.RectTransform);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
string version = File.Exists(LuaCsSetup.VersionFile) ? File.ReadAllText(LuaCsSetup.VersionFile) : "Github";
|
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
|
IgnoreLayoutGroups = false
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -89,35 +89,28 @@ local function ProcessPackages(packages, fn)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ProcessPackages(
|
ProcessPackages(ContentPackageManager.EnabledPackages.All, function(pkg, pkgPath)
|
||||||
ContentPackageManager.EnabledPackages.All,
|
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
||||||
function(pkg, pkgPath)
|
local autorunPath = pkgPath .. LUA_MOD_AUTORUN_PATH
|
||||||
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
if File.DirectoryExists(autorunPath) then
|
||||||
local autorunPath = pkgPath .. LUA_MOD_AUTORUN_PATH
|
QueueAutorun.Add(autorunPath, pkgPath, pkg)
|
||||||
if File.DirectoryExists(autorunPath) then
|
|
||||||
QueueAutorun.Add(autorunPath, pkgPath, pkg)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
)
|
end)
|
||||||
|
|
||||||
-- we don't want to execute workshop ForcedAutorun if we have a local Package
|
-- we don't want to execute workshop ForcedAutorun if we have a local Package
|
||||||
local executedLocalPackages = {}
|
local executedLocalPackages = {}
|
||||||
|
|
||||||
ProcessPackages(
|
ProcessPackages(ContentPackageManager.EnabledPackages.All, function(pkg, pkgPath)
|
||||||
ContentPackageManager.EnabledPackages.All,
|
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
||||||
function(pkg, pkgPath)
|
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
|
||||||
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
if File.DirectoryExists(forcedAutorunPath) then
|
||||||
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
|
QueueForcedAutorun.Add(forcedAutorunPath, pkgPath, pkg)
|
||||||
if File.DirectoryExists(forcedAutorunPath) then
|
executedLocalPackages[pkg.Name] = true
|
||||||
QueueForcedAutorun.Add(forcedAutorunPath, pkgPath, pkg)
|
|
||||||
executedLocalPackages[pkg.Name] = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
)
|
end)
|
||||||
|
|
||||||
ProcessPackages(
|
if not LuaCsConfig.TreatForcedModsAsNormal then
|
||||||
ContentPackageManager.LocalPackages,
|
ProcessPackages(ContentPackageManager.LocalPackages, function(pkg, pkgPath)
|
||||||
function(pkg, pkgPath)
|
|
||||||
if not executedLocalPackages[pkg.Name] then
|
if not executedLocalPackages[pkg.Name] then
|
||||||
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
||||||
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
|
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
|
||||||
@@ -126,12 +119,9 @@ ProcessPackages(
|
|||||||
executedLocalPackages[pkg.Name] = true
|
executedLocalPackages[pkg.Name] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
)
|
|
||||||
|
|
||||||
ProcessPackages(
|
ProcessPackages(ContentPackageManager.AllPackages, function(pkg, pkgPath)
|
||||||
ContentPackageManager.AllPackages,
|
|
||||||
function(pkg, pkgPath)
|
|
||||||
if not executedLocalPackages[pkg.Name] then
|
if not executedLocalPackages[pkg.Name] then
|
||||||
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
|
||||||
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
|
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
|
||||||
@@ -139,8 +129,8 @@ ProcessPackages(
|
|||||||
QueueForcedAutorun.Add(forcedAutorunPath, pkgPath, pkg)
|
QueueForcedAutorun.Add(forcedAutorunPath, pkgPath, pkg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
)
|
end
|
||||||
|
|
||||||
setmodulepaths(package.path)
|
setmodulepaths(package.path)
|
||||||
setmodulepaths = nil
|
setmodulepaths = nil
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace Barotrauma
|
|||||||
LuaCsLogger.LogMessage($"Added {cp.Name} {cp.ModVersion} to Cs compilation. (Standard)");
|
LuaCsLogger.LogMessage($"Added {cp.Name} {cp.ModVersion} to Cs compilation. (Standard)");
|
||||||
return true;
|
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)");
|
LuaCsLogger.LogMessage($"Added {cp.Name} {cp.ModVersion} to Cs compilation. (Forced)");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Barotrauma.Networking;
|
using System.Collections.Generic;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using MoonSharp.Interpreter.Interop;
|
using MoonSharp.Interpreter.Interop;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -17,6 +16,9 @@ namespace Barotrauma
|
|||||||
class LuaCsSetupConfig
|
class LuaCsSetupConfig
|
||||||
{
|
{
|
||||||
public bool FirstTimeCsWarning = true;
|
public bool FirstTimeCsWarning = true;
|
||||||
|
public bool ForceCsScripting = false;
|
||||||
|
public bool TreatForcedModsAsNormal = false;
|
||||||
|
public bool PreferToUseWorkshopLuaSetup = false;
|
||||||
|
|
||||||
public LuaCsSetupConfig() { }
|
public LuaCsSetupConfig() { }
|
||||||
}
|
}
|
||||||
@@ -70,6 +72,19 @@ namespace Barotrauma
|
|||||||
|
|
||||||
Game = new LuaGame();
|
Game = new LuaGame();
|
||||||
Networking = new LuaCsNetworking();
|
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()
|
public void UpdateConfig()
|
||||||
@@ -236,7 +251,6 @@ namespace Barotrauma
|
|||||||
LuaScriptLoader = null;
|
LuaScriptLoader = null;
|
||||||
Lua = null;
|
Lua = null;
|
||||||
CsScript = null;
|
CsScript = null;
|
||||||
Config = null;
|
|
||||||
|
|
||||||
if (CsScriptLoader != null)
|
if (CsScriptLoader != null)
|
||||||
{
|
{
|
||||||
@@ -252,17 +266,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
LuaCsLogger.LogMessage("Lua! Version " + AssemblyInfo.GitRevision);
|
LuaCsLogger.LogMessage("Lua! Version " + AssemblyInfo.GitRevision);
|
||||||
|
|
||||||
if (File.Exists(configFileName))
|
bool csActive = GetPackage(CsForBarotraumaId, false, true) != null || Config.ForceCsScripting;
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
LuaScriptLoader = new LuaScriptLoader();
|
LuaScriptLoader = new LuaScriptLoader();
|
||||||
LuaScriptLoader.ModulePaths = new string[] { };
|
LuaScriptLoader.ModulePaths = new string[] { };
|
||||||
@@ -287,11 +291,11 @@ namespace Barotrauma
|
|||||||
ModStore.Initialize();
|
ModStore.Initialize();
|
||||||
|
|
||||||
UserData.RegisterType<LuaCsConfig>();
|
UserData.RegisterType<LuaCsConfig>();
|
||||||
|
UserData.RegisterType<LuaCsSetupConfig>();
|
||||||
UserData.RegisterType<LuaCsAction>();
|
UserData.RegisterType<LuaCsAction>();
|
||||||
UserData.RegisterType<LuaCsFile>();
|
UserData.RegisterType<LuaCsFile>();
|
||||||
UserData.RegisterType<LuaCsCompatPatchFunc>();
|
UserData.RegisterType<LuaCsCompatPatchFunc>();
|
||||||
UserData.RegisterType<LuaCsPatchFunc>();
|
UserData.RegisterType<LuaCsPatchFunc>();
|
||||||
UserData.RegisterType<LuaCsConfig>();
|
|
||||||
UserData.RegisterType<CsScriptRunner>();
|
UserData.RegisterType<CsScriptRunner>();
|
||||||
UserData.RegisterType<LuaGame>();
|
UserData.RegisterType<LuaGame>();
|
||||||
UserData.RegisterType<LuaCsTimer>();
|
UserData.RegisterType<LuaCsTimer>();
|
||||||
@@ -323,6 +327,7 @@ namespace Barotrauma
|
|||||||
Lua.Globals["Networking"] = Networking;
|
Lua.Globals["Networking"] = Networking;
|
||||||
Lua.Globals["Steam"] = Steam;
|
Lua.Globals["Steam"] = Steam;
|
||||||
Lua.Globals["PerformanceCounter"] = PerformanceCounter;
|
Lua.Globals["PerformanceCounter"] = PerformanceCounter;
|
||||||
|
Lua.Globals["LuaCsConfig"] = Config;
|
||||||
|
|
||||||
Lua.Globals["ExecutionNumber"] = executionNumber;
|
Lua.Globals["ExecutionNumber"] = executionNumber;
|
||||||
Lua.Globals["CSActive"] = csActive;
|
Lua.Globals["CSActive"] = csActive;
|
||||||
@@ -376,39 +381,36 @@ namespace Barotrauma
|
|||||||
|
|
||||||
ContentPackage luaPackage = GetPackage(LuaForBarotraumaId);
|
ContentPackage luaPackage = GetPackage(LuaForBarotraumaId);
|
||||||
|
|
||||||
if (File.Exists(LuaSetupFile))
|
void runLocal()
|
||||||
{
|
{
|
||||||
LuaCsLogger.LogMessage("Using LuaSetup.lua from the Barotrauma Lua/ folder.");
|
LuaCsLogger.LogMessage("Using LuaSetup.lua from the Barotrauma Lua/ folder.");
|
||||||
|
string luaPath = LuaSetupFile;
|
||||||
try
|
CallLuaFunction(Lua.LoadFile(luaPath), Path.GetDirectoryName(Path.GetFullPath(luaPath)));
|
||||||
{
|
|
||||||
DynValue function = Lua.LoadFile(LuaSetupFile);
|
|
||||||
CallLuaFunction(function, Path.GetDirectoryName(Path.GetFullPath(LuaSetupFile)));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LuaCsLogger.HandleException(e, LuaCsMessageOrigin.LuaMod);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (luaPackage != null)
|
|
||||||
|
void runWorkshop()
|
||||||
{
|
{
|
||||||
LuaCsLogger.LogMessage("Using LuaSetup.lua from the content package.");
|
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
|
if (Config.PreferToUseWorkshopLuaSetup)
|
||||||
{
|
{
|
||||||
string luaPath = Path.Combine(path, "Binary/Lua/LuaSetup.lua");
|
if (luaPackage != null) { runWorkshop(); }
|
||||||
CallLuaFunction(Lua.LoadFile(luaPath), Path.GetDirectoryName(Path.GetFullPath(luaPath)));
|
else if (File.Exists(LuaSetupFile)) { runLocal(); }
|
||||||
}
|
else { runNone(); }
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LuaCsLogger.HandleException(e, LuaCsMessageOrigin.LuaMod);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
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++;
|
executionNumber++;
|
||||||
|
|||||||
Reference in New Issue
Block a user