Added "RunUnrestricted" mode for lua scripts that need to run outside of sandbox.
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Barotrauma
|
||||
{
|
||||
public void PromptCSharpMods(Action<bool> onSelection, bool joiningServer)
|
||||
{
|
||||
ImmutableArray<ContentPackage> contentPackages = PackageManagementService.GetLoadedAssemblyPackages()
|
||||
ImmutableArray<ContentPackage> contentPackages = PackageManagementService.GetLoadedUnrestrictedPackages()
|
||||
.Where(p => p.Name != PackageName)
|
||||
.ToImmutableArray();
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Barotrauma
|
||||
Stretch = true
|
||||
};
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), msgBoxLayout.RectTransform), "The following mods contain CSharp code",
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), msgBoxLayout.RectTransform), "The following mods contain CSharp code OR Unsandboxed Lua Code",
|
||||
font: GUIStyle.SubHeadingFont, wrap: true, textAlignment: Alignment.Center);
|
||||
|
||||
GUIListBox packageListBox = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.4f), msgBoxLayout.RectTransform))
|
||||
@@ -84,8 +84,8 @@ namespace Barotrauma
|
||||
|
||||
string bodyText =
|
||||
joiningServer ?
|
||||
"You are joining a server that includes mods with C# code. These mods are not sandboxed and may access your computer without restrictions. If you trust these mods, select 'Enable C# for this session'. Otherwise, select 'Cancel' to run only Lua mods."
|
||||
: "You have enabled mods that include C# code. These mods are not sandboxed and may access your computer without restrictions. If you trust these mods, select 'Enable C# for this session'. Otherwise, select 'Cancel' to run only Lua mods.";
|
||||
"You are joining a server that includes mods with C# code OR unrestricted Lua code. These mods are not sandboxed and may access your computer without restrictions. If you trust these mods, select 'Enable C# for this session'. Otherwise, select 'Cancel' to run only Lua mods."
|
||||
: "You have enabled mods that include C# code. These mods are not sandboxed and may access your computer without restrictions. If you trust these mods, select 'Enable C# for this session'. Otherwise, select 'Cancel' to run only Sandboxed Lua mods.";
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0f), msgBoxLayout.RectTransform), bodyText, wrap: true)
|
||||
{
|
||||
|
||||
@@ -56,6 +56,7 @@ public record ConfigResourceInfo : BaseResourceInfo, IConfigResourceInfo {}
|
||||
public record LuaScriptsResourceInfo : BaseResourceInfo, ILuaScriptResourceInfo
|
||||
{
|
||||
public bool IsAutorun { get; init; }
|
||||
public bool RunUnrestricted { get; init; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -21,6 +21,12 @@ public interface ILuaScriptResourceInfo : IBaseResourceInfo
|
||||
/// </summary>
|
||||
[XmlAttribute("IsAutorun")]
|
||||
public bool IsAutorun { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that this lua resources needs to run outside sandbox/requires unrestricted access.
|
||||
/// </summary>
|
||||
[XmlAttribute("RunUnrestricted")]
|
||||
public bool RunUnrestricted { get; }
|
||||
}
|
||||
|
||||
public interface IAssemblyResourceInfo : IBaseResourceInfo
|
||||
|
||||
@@ -174,7 +174,8 @@ public sealed partial class ModConfigFileParserService :
|
||||
RequiredPackages = src.Required,
|
||||
IncompatiblePackages = src.Incompatible,
|
||||
// Type Specific
|
||||
IsAutorun = src.Element.GetAttributeBool("IsAutorun", false)
|
||||
IsAutorun = src.Element.GetAttributeBool("IsAutorun", false),
|
||||
RunUnrestricted = src.Element.GetAttributeBool("RunUnrestricted", false)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -405,6 +405,7 @@ public sealed class ModConfigService : IModConfigService
|
||||
IncompatiblePackages = ImmutableArray<Identifier>.Empty,
|
||||
RequiredPackages = ImmutableArray<Identifier>.Empty,
|
||||
IsAutorun = true,
|
||||
RunUnrestricted = false
|
||||
});
|
||||
|
||||
builder.Add(new LuaScriptsResourceInfo()
|
||||
@@ -418,6 +419,7 @@ public sealed class ModConfigService : IModConfigService
|
||||
IncompatiblePackages = ImmutableArray<Identifier>.Empty,
|
||||
RequiredPackages = ImmutableArray<Identifier>.Empty,
|
||||
IsAutorun = false,
|
||||
RunUnrestricted = false
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -345,6 +345,8 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
|
||||
//lua scripts
|
||||
var luaScripts = SelectCompatible(loadingOrderedPackages
|
||||
.Where(pkg => executeCsAssemblies
|
||||
|| !pkg.Value.LuaScripts.Any(scr => scr.RunUnrestricted))
|
||||
.SelectMany(pkg => pkg.Value.LuaScripts)
|
||||
.ToImmutableArray(), toLoadPackagesIndents, loadOrderByPackage);
|
||||
|
||||
@@ -513,14 +515,14 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
return !_runningPackages.IsEmpty;
|
||||
}
|
||||
|
||||
public ImmutableArray<ContentPackage> GetLoadedAssemblyPackages()
|
||||
public ImmutableArray<ContentPackage> GetLoadedUnrestrictedPackages()
|
||||
{
|
||||
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
IService.CheckDisposed(this);
|
||||
if (_loadedPackages.IsEmpty)
|
||||
return ImmutableArray<ContentPackage>.Empty;
|
||||
return [.._loadedPackages.Values
|
||||
.Where(cfg => !cfg.Assemblies.IsDefaultOrEmpty)
|
||||
.Where(cfg => !cfg.Assemblies.IsDefaultOrEmpty || cfg.LuaScripts.Any(scr => scr.RunUnrestricted))
|
||||
.Select(cfg => cfg.Package)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface IPackageManagementService : IReusableService
|
||||
public FluentResults.Result UnloadPackages(ImmutableArray<ContentPackage> packages);
|
||||
public FluentResults.Result UnloadAllPackages();
|
||||
public ImmutableArray<ContentPackage> GetAllLoadedPackages();
|
||||
public ImmutableArray<ContentPackage> GetLoadedAssemblyPackages();
|
||||
public ImmutableArray<ContentPackage> GetLoadedUnrestrictedPackages();
|
||||
public bool IsPackageRunning(ContentPackage package);
|
||||
public bool IsAnyPackageLoaded();
|
||||
public bool IsAnyPackageRunning();
|
||||
|
||||
Reference in New Issue
Block a user