diff --git a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaScriptLoader.cs b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaScriptLoader.cs index 8b87662b9..dd49dd7b8 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaScriptLoader.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaScriptLoader.cs @@ -4,6 +4,7 @@ using System.Text; using System.IO; using MoonSharp.Interpreter; using MoonSharp.Interpreter.Loaders; +using System.Linq; namespace Barotrauma { @@ -11,18 +12,11 @@ namespace Barotrauma public class LuaScriptLoader : ScriptLoaderBase { - public LuaSetup lua; - - public LuaScriptLoader(LuaSetup l) - { - lua = l; - } - public override object LoadFile(string file, Table globalContext) { - if (!LuaFile.IsPathAllowedLuaException(file, false)) return null; - + if (!LuaFile.IsPathAllowedLuaException(file, false)) return null; + return File.ReadAllText(file); } @@ -32,7 +26,6 @@ namespace Barotrauma return File.Exists(file); } - - } + } } } \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs index 65de6a2e4..c8c509782 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs @@ -126,6 +126,13 @@ namespace Barotrauma public DynValue DoFile(string file, Table globalContext = null, string codeStringFriendly = null) { + if (!LuaFile.IsPathAllowedLuaException(file, false)) return null; + if (!LuaFile.Exists(file)) + { + HandleLuaException(new Exception($"dofile: File {file} not found.")); + return null; + } + try { return lua.DoFile(file, globalContext, codeStringFriendly); @@ -157,6 +164,13 @@ namespace Barotrauma public DynValue LoadFile(string file, Table globalContext = null, string codeStringFriendly = null) { + if (!LuaFile.IsPathAllowedLuaException(file, false)) return null; + if (!LuaFile.Exists(file)) + { + HandleLuaException(new Exception($"loadfile: File {file} not found.")); + return null; + } + try { return lua.LoadFile(file, globalContext, codeStringFriendly); @@ -223,7 +237,7 @@ namespace Barotrauma PrintMessage("Lua! Version " + AssemblyInfo.GitRevision); - luaScriptLoader = new LuaScriptLoader(this); + luaScriptLoader = new LuaScriptLoader(); luaScriptLoader.ModulePaths = new string[] { }; LuaCustomConverters.RegisterAll();