Use WorkshopId instead and minor cleanup
This commit is contained in:
@@ -3278,7 +3278,7 @@ namespace Barotrauma
|
||||
const string CMD_CL_CS = "cl_cs";
|
||||
commands.Add(new Command(CMD_CL_CS, $"{CMD_CL_CS}: runs a string on the client", (string[] args) =>
|
||||
{
|
||||
if (LuaCsSetup.GetPackage("CsForBarotrauma", false, true) == null) { return; }
|
||||
if (LuaCsSetup.GetPackage(LuaCsSetup.CsForBarotraumaId, false, true) == null) { return; }
|
||||
|
||||
if (GameMain.Client != null && !GameMain.Client.HasPermission(ClientPermissions.ConsoleCommands))
|
||||
{
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (!File.Exists(LuaCsSetup.VersionFile)) { return; }
|
||||
|
||||
ContentPackage luaPackage = LuaCsSetup.GetPackage("Lua For Barotrauma");
|
||||
ContentPackage luaPackage = LuaCsSetup.GetPackage(LuaCsSetup.LuaForBarotraumaId);
|
||||
string luaCsPath = Path.GetDirectoryName(luaPackage.Path);
|
||||
|
||||
if (luaPackage == null) { return; }
|
||||
@@ -69,7 +69,7 @@ namespace Barotrauma
|
||||
|
||||
if (clientVersion == workshopVersion) { return; }
|
||||
|
||||
string additional = LuaCsSetup.GetPackage("CsForBarotrauma", false, true) == null ? "" : "Cs";
|
||||
string additional = LuaCsSetup.GetPackage(LuaCsSetup.CsForBarotraumaId, false, true) == null ? "" : "Cs";
|
||||
|
||||
var msg = new GUIMessageBox($"Lua{additional} Update", $"Your Lua{additional} client version is different from the version found in the Lua{additional}ForBarotrauma workshop files. Do you want to update?\n\n Client Version: {clientVersion}\n Workshop Version: {workshopVersion}",
|
||||
new LocalizedString[2] { TextManager.Get("Yes"), TextManager.Get("Cancel") });
|
||||
|
||||
@@ -400,7 +400,7 @@ namespace Barotrauma
|
||||
}
|
||||
};
|
||||
#endif
|
||||
string additional = LuaCsSetup.GetPackage("CsForBarotrauma", false, true) == null ? "" : "Cs";
|
||||
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)
|
||||
|
||||
@@ -1264,7 +1264,7 @@ namespace Barotrauma
|
||||
}));
|
||||
commands.Add(new Command("cs", "cs: Runs a string", (string[] args) =>
|
||||
{
|
||||
if (LuaCsSetup.GetPackage("CsForBarotrauma", false, true) == null) { return; }
|
||||
if (LuaCsSetup.GetPackage(LuaCsSetup.CsForBarotraumaId, false, true) == null) { return; }
|
||||
|
||||
GameMain.LuaCs.CsScript.Run(string.Join(" ", args));
|
||||
GameMain.LuaCs.RecreateCsScript();
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
{
|
||||
public static void Install()
|
||||
{
|
||||
ContentPackage luaPackage = LuaCsSetup.GetPackage("Lua For Barotrauma");
|
||||
ContentPackage luaPackage = LuaCsSetup.GetPackage(LuaCsSetup.LuaForBarotraumaId);
|
||||
|
||||
if (luaPackage == null)
|
||||
{
|
||||
|
||||
@@ -38,6 +38,20 @@ require("DefaultHook")
|
||||
Descriptors = LuaSetup.LuaUserData.Descriptors
|
||||
LuaUserData = LuaSetup.LuaUserData
|
||||
|
||||
if CSActive then
|
||||
LuaUserData.RegisterType = function (typeName)
|
||||
local descriptor = Descriptors[typeName]
|
||||
|
||||
print(typeName)
|
||||
|
||||
if descriptor == nil then
|
||||
error("Type '" .. typeName .. "' can't be registered", 2)
|
||||
else
|
||||
return descriptor
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
LuaSetup = nil
|
||||
|
||||
require("ModLoader")
|
||||
@@ -516,7 +516,7 @@ namespace Barotrauma
|
||||
{
|
||||
"Barotrauma.Lua",
|
||||
"Barotrauma.Cs",
|
||||
"ContentPackageManager",
|
||||
"Barotrauma.ContentPackageManager",
|
||||
};
|
||||
|
||||
private static void ValidatePatchTarget(MethodBase method)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
@@ -18,12 +18,12 @@ using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch;
|
||||
[assembly: InternalsVisibleTo(Barotrauma.CsScriptBase.CsOneTimeScriptAssembly, AllInternalsVisible = true)]
|
||||
namespace Barotrauma
|
||||
{
|
||||
class LuaCsSetupConfig
|
||||
class LuaCsSetupConfig
|
||||
{
|
||||
public bool FirstTimeCsWarning = true;
|
||||
public bool FirstTimeCsWarning = true;
|
||||
|
||||
public LuaCsSetupConfig() { }
|
||||
}
|
||||
public LuaCsSetupConfig() { }
|
||||
}
|
||||
|
||||
internal delegate void LuaCsMessageLogger(string prefix, object o);
|
||||
|
||||
@@ -37,120 +37,123 @@ namespace Barotrauma
|
||||
CSharpMod,
|
||||
}
|
||||
|
||||
partial class LuaCsSetup
|
||||
{
|
||||
public const string LuaSetupFile = "Lua/LuaSetup.lua";
|
||||
public const string VersionFile = "luacsversion.txt";
|
||||
partial class LuaCsSetup
|
||||
{
|
||||
public const string LuaSetupFile = "Lua/LuaSetup.lua";
|
||||
public const string VersionFile = "luacsversion.txt";
|
||||
public static ContentPackageId LuaForBarotraumaId = new SteamWorkshopId(2559634234);
|
||||
public static ContentPackageId CsForBarotraumaId = new SteamWorkshopId(2795927223);
|
||||
|
||||
private const string configFileName = "LuaCsSetupConfig.xml";
|
||||
|
||||
private const string configFileName = "LuaCsSetupConfig.xml";
|
||||
|
||||
#if SERVER
|
||||
public const bool IsServer = true;
|
||||
public const bool IsClient = false;
|
||||
public const bool IsServer = true;
|
||||
public const bool IsClient = false;
|
||||
#else
|
||||
public const bool IsServer = false;
|
||||
public const bool IsClient = true;
|
||||
public const bool IsServer = false;
|
||||
public const bool IsClient = true;
|
||||
#endif
|
||||
|
||||
private static int executionNumber = 0;
|
||||
private static int executionNumber = 0;
|
||||
|
||||
private Script lua;
|
||||
public Script Lua
|
||||
private Script lua;
|
||||
public Script Lua
|
||||
{
|
||||
get { return lua; }
|
||||
}
|
||||
|
||||
public CsScriptRunner CsScript { get; private set; }
|
||||
public CsScriptRunner CsScript { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// due to there's a race on the process and the unloaded AssemblyLoadContexts,
|
||||
/// should recreate runner after the script runs
|
||||
/// </summary>
|
||||
public void RecreateCsScript()
|
||||
/// <summary>
|
||||
/// due to there's a race on the process and the unloaded AssemblyLoadContexts,
|
||||
/// should recreate runner after the script runs
|
||||
/// </summary>
|
||||
public void RecreateCsScript()
|
||||
{
|
||||
CsScript = new CsScriptRunner(CsScript.setup);
|
||||
lua.Globals["CsScript"] = CsScript;
|
||||
}
|
||||
CsScript = new CsScriptRunner(CsScript.setup);
|
||||
lua.Globals["CsScript"] = CsScript;
|
||||
}
|
||||
|
||||
public LuaScriptLoader LuaScriptLoader { get; private set; }
|
||||
public LuaScriptLoader LuaScriptLoader { get; private set; }
|
||||
|
||||
public LuaGame Game { get; private set; }
|
||||
public LuaCsHook Hook { get; private set; }
|
||||
public LuaCsTimer Timer { get; private set; }
|
||||
public LuaCsNetworking Networking { get; private set; }
|
||||
public LuaCsSteam Steam { get; private set; }
|
||||
public LuaCsPerformanceCounter PerformanceCounter { get; private set; }
|
||||
public LuaGame Game { get; private set; }
|
||||
public LuaCsHook Hook { get; private set; }
|
||||
public LuaCsTimer Timer { get; private set; }
|
||||
public LuaCsNetworking Networking { get; private set; }
|
||||
public LuaCsSteam Steam { get; private set; }
|
||||
public LuaCsPerformanceCounter PerformanceCounter { get; private set; }
|
||||
|
||||
public LuaCsModStore ModStore { get; private set; }
|
||||
private LuaRequire require { get; set; }
|
||||
public LuaCsModStore ModStore { get; private set; }
|
||||
private LuaRequire require { get; set; }
|
||||
|
||||
public CsScriptLoader CsScriptLoader { get; private set; }
|
||||
public LuaCsSetupConfig Config { get; private set; }
|
||||
public CsScriptLoader CsScriptLoader { get; private set; }
|
||||
public LuaCsSetupConfig Config { get; private set; }
|
||||
|
||||
public LuaCsSetup()
|
||||
{
|
||||
public LuaCsSetup()
|
||||
{
|
||||
MessageLogger = DefaultMessageLogger;
|
||||
ExceptionHandler = DefaultExceptionHandler;
|
||||
ExceptionHandler = DefaultExceptionHandler;
|
||||
|
||||
Hook = new LuaCsHook(this);
|
||||
ModStore = new LuaCsModStore();
|
||||
ModStore = new LuaCsModStore();
|
||||
|
||||
Game = new LuaGame();
|
||||
Networking = new LuaCsNetworking();
|
||||
}
|
||||
Game = new LuaGame();
|
||||
Networking = new LuaCsNetworking();
|
||||
}
|
||||
|
||||
public void UpdateConfig()
|
||||
public void UpdateConfig()
|
||||
{
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
public static ContentPackage GetPackage(Identifier name, bool fallbackToAll = true, bool useBackup = false)
|
||||
{
|
||||
foreach (ContentPackage package in ContentPackageManager.EnabledPackages.All)
|
||||
{
|
||||
if (package.NameMatches(name))
|
||||
{
|
||||
return package;
|
||||
}
|
||||
}
|
||||
|
||||
if (fallbackToAll)
|
||||
{
|
||||
foreach (ContentPackage package in ContentPackageManager.LocalPackages)
|
||||
{
|
||||
if (package.NameMatches(name))
|
||||
{
|
||||
return package;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ContentPackage package in ContentPackageManager.AllPackages)
|
||||
{
|
||||
if (package.NameMatches(name))
|
||||
{
|
||||
return package;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useBackup && ContentPackageManager.EnabledPackages.BackupPackages.Regular != null)
|
||||
public static ContentPackage GetPackage(ContentPackageId id, bool fallbackToAll = true, bool useBackup = false)
|
||||
{
|
||||
foreach (ContentPackage package in ContentPackageManager.EnabledPackages.All)
|
||||
{
|
||||
foreach (ContentPackage package in ContentPackageManager.EnabledPackages.BackupPackages.Regular.Value)
|
||||
{
|
||||
if (package.NameMatches(name))
|
||||
{
|
||||
return package;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (package.UgcId.ValueEquals(id))
|
||||
{
|
||||
return package;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
if (fallbackToAll)
|
||||
{
|
||||
foreach (ContentPackage package in ContentPackageManager.LocalPackages)
|
||||
{
|
||||
if (package.UgcId.ValueEquals(id))
|
||||
{
|
||||
return package;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ContentPackage package in ContentPackageManager.AllPackages)
|
||||
{
|
||||
if (package.UgcId.ValueEquals(id))
|
||||
{
|
||||
return package;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useBackup && ContentPackageManager.EnabledPackages.BackupPackages.Regular != null)
|
||||
{
|
||||
foreach (ContentPackage package in ContentPackageManager.EnabledPackages.BackupPackages.Regular.Value)
|
||||
{
|
||||
if (package.UgcId.ValueEquals(id))
|
||||
{
|
||||
return package;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void DefaultExceptionHandler(Exception ex, LuaCsMessageOrigin origin)
|
||||
{
|
||||
@@ -288,271 +291,271 @@ namespace Barotrauma
|
||||
// TODO: deprecate this (in an effort to get rid of as much global state as possible)
|
||||
public static void PrintCsMessage(object message) => GameMain.LuaCs.PrintMessage(message);
|
||||
|
||||
private DynValue DoFile(string file, Table globalContext = null, string codeStringFriendly = null)
|
||||
{
|
||||
if (!LuaCsFile.CanReadFromPath(file))
|
||||
{
|
||||
throw new ScriptRuntimeException($"dofile: File access to {file} not allowed.");
|
||||
}
|
||||
|
||||
if (!LuaCsFile.Exists(file))
|
||||
{
|
||||
throw new ScriptRuntimeException($"dofile: File {file} not found.");
|
||||
}
|
||||
|
||||
return lua.DoFile(file, globalContext, codeStringFriendly);
|
||||
}
|
||||
|
||||
private DynValue LoadFile(string file, Table globalContext = null, string codeStringFriendly = null)
|
||||
{
|
||||
if (!LuaCsFile.CanReadFromPath(file))
|
||||
private DynValue DoFile(string file, Table globalContext = null, string codeStringFriendly = null)
|
||||
{
|
||||
if (!LuaCsFile.CanReadFromPath(file))
|
||||
{
|
||||
throw new ScriptRuntimeException($"loadfile: File access to {file} not allowed.");
|
||||
}
|
||||
throw new ScriptRuntimeException($"dofile: File access to {file} not allowed.");
|
||||
}
|
||||
|
||||
if (!LuaCsFile.Exists(file))
|
||||
{
|
||||
throw new ScriptRuntimeException($"loadfile: File {file} not found.");
|
||||
}
|
||||
if (!LuaCsFile.Exists(file))
|
||||
{
|
||||
throw new ScriptRuntimeException($"dofile: File {file} not found.");
|
||||
}
|
||||
|
||||
return lua.LoadFile(file, globalContext, codeStringFriendly);
|
||||
}
|
||||
return lua.DoFile(file, globalContext, codeStringFriendly);
|
||||
}
|
||||
|
||||
public DynValue CallLuaFunction(object function, params object[] args)
|
||||
{
|
||||
private DynValue LoadFile(string file, Table globalContext = null, string codeStringFriendly = null)
|
||||
{
|
||||
if (!LuaCsFile.CanReadFromPath(file))
|
||||
{
|
||||
throw new ScriptRuntimeException($"loadfile: File access to {file} not allowed.");
|
||||
}
|
||||
|
||||
if (!LuaCsFile.Exists(file))
|
||||
{
|
||||
throw new ScriptRuntimeException($"loadfile: File {file} not found.");
|
||||
}
|
||||
|
||||
return lua.LoadFile(file, globalContext, codeStringFriendly);
|
||||
}
|
||||
|
||||
public DynValue CallLuaFunction(object function, params object[] args)
|
||||
{
|
||||
// XXX: `lua` might be null if `LuaCsSetup.Stop()` is called while
|
||||
// a patched function is still running.
|
||||
if (lua == null) return null;
|
||||
|
||||
lock (lua)
|
||||
{
|
||||
try
|
||||
{
|
||||
return lua.Call(function, args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandleException(e, LuaCsMessageOrigin.LuaMod);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
lock (lua)
|
||||
{
|
||||
try
|
||||
{
|
||||
return lua.Call(function, args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandleException(e, LuaCsMessageOrigin.LuaMod);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetModulePaths(string[] str)
|
||||
{
|
||||
LuaScriptLoader.ModulePaths = str;
|
||||
}
|
||||
private void SetModulePaths(string[] str)
|
||||
{
|
||||
LuaScriptLoader.ModulePaths = str;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Hook?.Update();
|
||||
Timer?.Update();
|
||||
Steam?.Update();
|
||||
}
|
||||
public void Update()
|
||||
{
|
||||
Hook?.Update();
|
||||
Timer?.Update();
|
||||
Steam?.Update();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
foreach (var type in AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == CsScriptBase.CsScriptAssembly).SelectMany(assembly => assembly.GetTypes()))
|
||||
{
|
||||
UserData.UnregisterType(type, true);
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
foreach (var type in AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == CsScriptBase.CsScriptAssembly).SelectMany(assembly => assembly.GetTypes()))
|
||||
{
|
||||
UserData.UnregisterType(type, true);
|
||||
}
|
||||
|
||||
foreach (var mod in ACsMod.LoadedMods.ToArray())
|
||||
{
|
||||
mod.Dispose();
|
||||
}
|
||||
|
||||
ACsMod.LoadedMods.Clear();
|
||||
foreach (var mod in ACsMod.LoadedMods.ToArray())
|
||||
{
|
||||
mod.Dispose();
|
||||
}
|
||||
|
||||
ACsMod.LoadedMods.Clear();
|
||||
|
||||
if (Thread.CurrentThread == GameMain.MainThread)
|
||||
{
|
||||
Hook?.Call("stop");
|
||||
}
|
||||
if (Thread.CurrentThread == GameMain.MainThread)
|
||||
{
|
||||
Hook?.Call("stop");
|
||||
}
|
||||
|
||||
Game?.Stop();
|
||||
Game?.Stop();
|
||||
|
||||
Hook.Clear();
|
||||
ModStore.Clear();
|
||||
Game = new LuaGame();
|
||||
Networking = new LuaCsNetworking();
|
||||
Timer = new LuaCsTimer();
|
||||
Steam = new LuaCsSteam();
|
||||
PerformanceCounter = new LuaCsPerformanceCounter();
|
||||
LuaScriptLoader = null;
|
||||
lua = null;
|
||||
CsScript = null;
|
||||
Config = null;
|
||||
Hook.Clear();
|
||||
ModStore.Clear();
|
||||
Game = new LuaGame();
|
||||
Networking = new LuaCsNetworking();
|
||||
Timer = new LuaCsTimer();
|
||||
Steam = new LuaCsSteam();
|
||||
PerformanceCounter = new LuaCsPerformanceCounter();
|
||||
LuaScriptLoader = null;
|
||||
lua = null;
|
||||
CsScript = null;
|
||||
Config = null;
|
||||
|
||||
if (CsScriptLoader != null)
|
||||
{
|
||||
CsScriptLoader.Clear();
|
||||
CsScriptLoader.Unload();
|
||||
CsScriptLoader = null;
|
||||
}
|
||||
}
|
||||
{
|
||||
CsScriptLoader.Clear();
|
||||
CsScriptLoader.Unload();
|
||||
CsScriptLoader = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Stop();
|
||||
public void Initialize()
|
||||
{
|
||||
Stop();
|
||||
|
||||
PrintMessage("Lua! Version " + AssemblyInfo.GitRevision);
|
||||
PrintMessage("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();
|
||||
}
|
||||
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("CsForBarotrauma", false, true) != null;
|
||||
bool csActive = GetPackage(CsForBarotraumaId, false, true) != null;
|
||||
|
||||
LuaScriptLoader = new LuaScriptLoader();
|
||||
LuaScriptLoader.ModulePaths = new string[] { };
|
||||
LuaScriptLoader = new LuaScriptLoader();
|
||||
LuaScriptLoader.ModulePaths = new string[] { };
|
||||
|
||||
RegisterLuaConverters();
|
||||
|
||||
lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.Debug);
|
||||
lua.Options.DebugPrint = PrintMessage;
|
||||
lua.Options.ScriptLoader = LuaScriptLoader;
|
||||
lua.Options.CheckThreadAccess = false;
|
||||
CsScript = new CsScriptRunner(this);
|
||||
lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.Debug);
|
||||
lua.Options.DebugPrint = PrintMessage;
|
||||
lua.Options.ScriptLoader = LuaScriptLoader;
|
||||
lua.Options.CheckThreadAccess = false;
|
||||
CsScript = new CsScriptRunner(this);
|
||||
|
||||
require = new LuaRequire(lua);
|
||||
require = new LuaRequire(lua);
|
||||
|
||||
Game = new LuaGame();
|
||||
Networking = new LuaCsNetworking();
|
||||
Timer = new LuaCsTimer();
|
||||
Steam = new LuaCsSteam();
|
||||
PerformanceCounter = new LuaCsPerformanceCounter();
|
||||
Hook.Initialize();
|
||||
ModStore.Initialize();
|
||||
Game = new LuaGame();
|
||||
Networking = new LuaCsNetworking();
|
||||
Timer = new LuaCsTimer();
|
||||
Steam = new LuaCsSteam();
|
||||
PerformanceCounter = new LuaCsPerformanceCounter();
|
||||
Hook.Initialize();
|
||||
ModStore.Initialize();
|
||||
|
||||
UserData.RegisterType<LuaCsConfig>();
|
||||
UserData.RegisterType<LuaCsAction>();
|
||||
UserData.RegisterType<LuaCsFile>();
|
||||
UserData.RegisterType<LuaCsCompatPatchFunc>();
|
||||
UserData.RegisterType<LuaCsPatchFunc>();
|
||||
UserData.RegisterType<LuaCsConfig>();
|
||||
UserData.RegisterType<CsScriptRunner>();
|
||||
UserData.RegisterType<LuaGame>();
|
||||
UserData.RegisterType<LuaCsTimer>();
|
||||
UserData.RegisterType<LuaCsFile>();
|
||||
UserData.RegisterType<LuaCsNetworking>();
|
||||
UserData.RegisterType<LuaCsSteam>();
|
||||
UserData.RegisterType<LuaUserData>();
|
||||
UserData.RegisterType<LuaCsPerformanceCounter>();
|
||||
UserData.RegisterType<IUserDataDescriptor>();
|
||||
UserData.RegisterType<LuaCsConfig>();
|
||||
UserData.RegisterType<LuaCsAction>();
|
||||
UserData.RegisterType<LuaCsFile>();
|
||||
UserData.RegisterType<LuaCsCompatPatchFunc>();
|
||||
UserData.RegisterType<LuaCsPatchFunc>();
|
||||
UserData.RegisterType<LuaCsConfig>();
|
||||
UserData.RegisterType<CsScriptRunner>();
|
||||
UserData.RegisterType<LuaGame>();
|
||||
UserData.RegisterType<LuaCsTimer>();
|
||||
UserData.RegisterType<LuaCsFile>();
|
||||
UserData.RegisterType<LuaCsNetworking>();
|
||||
UserData.RegisterType<LuaCsSteam>();
|
||||
UserData.RegisterType<LuaUserData>();
|
||||
UserData.RegisterType<LuaCsPerformanceCounter>();
|
||||
UserData.RegisterType<IUserDataDescriptor>();
|
||||
|
||||
lua.Globals["printerror"] = (Action<object>)PrintLuaError;
|
||||
lua.Globals["printerror"] = (Action<object>)PrintLuaError;
|
||||
|
||||
lua.Globals["setmodulepaths"] = (Action<string[]>)SetModulePaths;
|
||||
lua.Globals["setmodulepaths"] = (Action<string[]>)SetModulePaths;
|
||||
|
||||
lua.Globals["dofile"] = (Func<string, Table, string, DynValue>)DoFile;
|
||||
lua.Globals["loadfile"] = (Func<string, Table, string, DynValue>)LoadFile;
|
||||
lua.Globals["require"] = (Func<string, Table, DynValue>)require.Require;
|
||||
lua.Globals["dofile"] = (Func<string, Table, string, DynValue>)DoFile;
|
||||
lua.Globals["loadfile"] = (Func<string, Table, string, DynValue>)LoadFile;
|
||||
lua.Globals["require"] = (Func<string, Table, DynValue>)require.Require;
|
||||
|
||||
lua.Globals["dostring"] = (Func<string, Table, string, DynValue>)lua.DoString;
|
||||
lua.Globals["load"] = (Func<string, Table, string, DynValue>)lua.LoadString;
|
||||
lua.Globals["dostring"] = (Func<string, Table, string, DynValue>)lua.DoString;
|
||||
lua.Globals["load"] = (Func<string, Table, string, DynValue>)lua.LoadString;
|
||||
|
||||
lua.Globals["CsScript"] = CsScript;
|
||||
lua.Globals["LuaUserData"] = UserData.CreateStatic<LuaUserData>();
|
||||
lua.Globals["Game"] = Game;
|
||||
lua.Globals["Hook"] = Hook;
|
||||
lua.Globals["ModStore"] = ModStore;
|
||||
lua.Globals["Timer"] = Timer;
|
||||
lua.Globals["File"] = UserData.CreateStatic<LuaCsFile>();
|
||||
lua.Globals["Networking"] = Networking;
|
||||
lua.Globals["Steam"] = Steam;
|
||||
lua.Globals["PerformanceCounter"] = PerformanceCounter;
|
||||
lua.Globals["CsScript"] = CsScript;
|
||||
lua.Globals["LuaUserData"] = UserData.CreateStatic<LuaUserData>();
|
||||
lua.Globals["Game"] = Game;
|
||||
lua.Globals["Hook"] = Hook;
|
||||
lua.Globals["ModStore"] = ModStore;
|
||||
lua.Globals["Timer"] = Timer;
|
||||
lua.Globals["File"] = UserData.CreateStatic<LuaCsFile>();
|
||||
lua.Globals["Networking"] = Networking;
|
||||
lua.Globals["Steam"] = Steam;
|
||||
lua.Globals["PerformanceCounter"] = PerformanceCounter;
|
||||
|
||||
lua.Globals["ExecutionNumber"] = executionNumber;
|
||||
lua.Globals["CSActive"] = csActive;
|
||||
lua.Globals["ExecutionNumber"] = executionNumber;
|
||||
lua.Globals["CSActive"] = csActive;
|
||||
|
||||
lua.Globals["SERVER"] = IsServer;
|
||||
lua.Globals["CLIENT"] = IsClient;
|
||||
lua.Globals["SERVER"] = IsServer;
|
||||
lua.Globals["CLIENT"] = IsClient;
|
||||
|
||||
if (csActive)
|
||||
{
|
||||
PrintMessage("Cs! Version " + AssemblyInfo.GitRevision);
|
||||
if (csActive)
|
||||
{
|
||||
PrintMessage("Cs! Version " + AssemblyInfo.GitRevision);
|
||||
|
||||
if (Config.FirstTimeCsWarning)
|
||||
{
|
||||
Config.FirstTimeCsWarning = false;
|
||||
UpdateConfig();
|
||||
if (Config.FirstTimeCsWarning)
|
||||
{
|
||||
Config.FirstTimeCsWarning = false;
|
||||
UpdateConfig();
|
||||
|
||||
DebugConsole.AddWarning("Cs package active! Cs mods are NOT sandboxed, use it at your own risk!");
|
||||
}
|
||||
DebugConsole.AddWarning("Cs package active! Cs mods are NOT sandboxed, use it at your own risk!");
|
||||
}
|
||||
|
||||
CsScriptLoader = new CsScriptLoader();
|
||||
CsScriptLoader.SearchFolders();
|
||||
if (CsScriptLoader.HasSources)
|
||||
{
|
||||
try
|
||||
{
|
||||
var modTypes = CsScriptLoader.Compile();
|
||||
modTypes.ForEach(t =>
|
||||
{
|
||||
try
|
||||
{
|
||||
t.GetConstructor(new Type[] { })?.Invoke(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
CsScriptLoader = new CsScriptLoader();
|
||||
CsScriptLoader.SearchFolders();
|
||||
if (CsScriptLoader.HasSources)
|
||||
{
|
||||
try
|
||||
{
|
||||
var modTypes = CsScriptLoader.Compile();
|
||||
modTypes.ForEach(t =>
|
||||
{
|
||||
try
|
||||
{
|
||||
HandleException(ex, LuaCsMessageOrigin.CSharpMod);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HandleException(ex, LuaCsMessageOrigin.CSharpMod);
|
||||
}
|
||||
}
|
||||
t.GetConstructor(new Type[] { })?.Invoke(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HandleException(ex, LuaCsMessageOrigin.CSharpMod);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HandleException(ex, LuaCsMessageOrigin.CSharpMod);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ContentPackage luaPackage = GetPackage("Lua For Barotrauma");
|
||||
ContentPackage luaPackage = GetPackage(LuaForBarotraumaId);
|
||||
|
||||
if (File.Exists(LuaSetupFile))
|
||||
{
|
||||
PrintMessage("Using LuaSetup.lua from the Barotrauma Lua/ folder.");
|
||||
if (File.Exists(LuaSetupFile))
|
||||
{
|
||||
PrintMessage("Using LuaSetup.lua from the Barotrauma Lua/ folder.");
|
||||
|
||||
try
|
||||
{
|
||||
DynValue function = lua.LoadFile(LuaSetupFile);
|
||||
CallLuaFunction(function, Path.GetDirectoryName(Path.GetFullPath(LuaSetupFile)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandleException(e, LuaCsMessageOrigin.LuaMod);
|
||||
}
|
||||
}
|
||||
else if (luaPackage != null)
|
||||
{
|
||||
PrintMessage("Using LuaSetup.lua from the content package.");
|
||||
try
|
||||
{
|
||||
DynValue function = lua.LoadFile(LuaSetupFile);
|
||||
CallLuaFunction(function, Path.GetDirectoryName(Path.GetFullPath(LuaSetupFile)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandleException(e, LuaCsMessageOrigin.LuaMod);
|
||||
}
|
||||
}
|
||||
else if (luaPackage != null)
|
||||
{
|
||||
PrintMessage("Using LuaSetup.lua from the content package.");
|
||||
|
||||
string path = Path.GetDirectoryName(luaPackage.Path);
|
||||
string path = Path.GetDirectoryName(luaPackage.Path);
|
||||
|
||||
try
|
||||
{
|
||||
string luaPath = Path.Combine(path, "Binary/Lua/LuaSetup.lua");
|
||||
CallLuaFunction(lua.LoadFile(luaPath), Path.GetDirectoryName(Path.GetFullPath(luaPath)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandleException(e, LuaCsMessageOrigin.LuaMod);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintLuaError("LuaSetup.lua not found! Lua/LuaSetup.lua, no Lua scripts will be executed or work.");
|
||||
}
|
||||
try
|
||||
{
|
||||
string luaPath = Path.Combine(path, "Binary/Lua/LuaSetup.lua");
|
||||
CallLuaFunction(lua.LoadFile(luaPath), Path.GetDirectoryName(Path.GetFullPath(luaPath)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandleException(e, LuaCsMessageOrigin.LuaMod);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintLuaError("LuaSetup.lua not found! Lua/LuaSetup.lua, no Lua scripts will be executed or work.");
|
||||
}
|
||||
|
||||
executionNumber++;
|
||||
}
|
||||
executionNumber++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,15 +55,14 @@ namespace Barotrauma
|
||||
|
||||
bool pathStartsWith(string prefix) => path.StartsWith(prefix, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (pathStartsWith(getFullPath(ContentPackage.LocalModsDir + "Lua For Barotrauma")))
|
||||
return false;
|
||||
foreach (var package in ContentPackageManager.AllPackages)
|
||||
{
|
||||
if (package.UgcId.ValueEquals(LuaCsSetup.LuaForBarotraumaId) && pathStartsWith(getFullPath(package.Path)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (pathStartsWith(getFullPath(ContentPackage.WorkshopModsDir + "Lua For Barotrauma")))
|
||||
return false;
|
||||
#if CLIENT
|
||||
if (pathStartsWith(getFullPath(ModReceiver.DownloadFolder + "Lua For Barotrauma")))
|
||||
return false;
|
||||
#endif
|
||||
if (pathStartsWith(getFullPath(SaveUtil.SaveFolder)))
|
||||
return true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user