From 53fd4b1258ad7cee7498c78da4fe30985654019f Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Wed, 1 Sep 2021 13:47:30 -0300 Subject: [PATCH] made modules partially work and replace/removed useless functions --- .../ServerSource/Lua/LuaSetup.cs | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs index ac8af40d7..4c24557b8 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs @@ -61,6 +61,7 @@ namespace Barotrauma try { return lua.DoFile(file); + } catch (Exception e) { @@ -71,6 +72,21 @@ namespace Barotrauma } + public DynValue LoadFile(string file) + { + try + { + return lua.LoadFile(file); + + } + catch (Exception e) + { + HandleLuaException(e); + } + + return null; + } + public static DynValue CreateUserDataSafe(object o) { if(o == null) @@ -86,6 +102,7 @@ namespace Barotrauma PrintMessage("Lua!"); LuaScriptLoader luaScriptLoader = new LuaScriptLoader(this); + luaScriptLoader.ModulePaths = new string[] { }; LuaCustomConverters.RegisterAll(); @@ -163,6 +180,9 @@ namespace Barotrauma game = new LuaGame(this); lua.Globals["dofile"] = (Func)DoFile; + lua.Globals["loadfile"] = (Func)LoadFile; + lua.Globals["loadfilesafe"] = null; + lua.Globals["Player"] = new LuaPlayer(); lua.Globals["Game"] = game; lua.Globals["Hook"] = hook; @@ -196,23 +216,19 @@ namespace Barotrauma lua.Globals["InvSlotType"] = UserData.CreateStatic(); lua.Globals["Gap"] = UserData.CreateStatic(); + List modulePaths = new List(); + foreach (string d in Directory.GetDirectories("Mods")) { + modulePaths.Add(d + "/Lua/?.lua"); + if (Directory.Exists(d + "/Lua/Autorun")) { luaScriptLoader.RunFolder(d + "/Lua/Autorun"); } - - if (Directory.Exists(d + "/LuaRaw")) - { - foreach (string d2 in Directory.GetDirectories(d + "/LuaRaw")) - { - luaScriptLoader.RunFolder(d2 + "/Autorun"); - } - } } - + luaScriptLoader.ModulePaths = modulePaths.ToArray(); }