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)
|
public void PromptCSharpMods(Action<bool> onSelection, bool joiningServer)
|
||||||
{
|
{
|
||||||
ImmutableArray<ContentPackage> contentPackages = PackageManagementService.GetLoadedAssemblyPackages()
|
ImmutableArray<ContentPackage> contentPackages = PackageManagementService.GetLoadedUnrestrictedPackages()
|
||||||
.Where(p => p.Name != PackageName)
|
.Where(p => p.Name != PackageName)
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ namespace Barotrauma
|
|||||||
Stretch = true
|
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);
|
font: GUIStyle.SubHeadingFont, wrap: true, textAlignment: Alignment.Center);
|
||||||
|
|
||||||
GUIListBox packageListBox = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.4f), msgBoxLayout.RectTransform))
|
GUIListBox packageListBox = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.4f), msgBoxLayout.RectTransform))
|
||||||
@@ -84,8 +84,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
string bodyText =
|
string bodyText =
|
||||||
joiningServer ?
|
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 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 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)
|
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 record LuaScriptsResourceInfo : BaseResourceInfo, ILuaScriptResourceInfo
|
||||||
{
|
{
|
||||||
public bool IsAutorun { get; init; }
|
public bool IsAutorun { get; init; }
|
||||||
|
public bool RunUnrestricted { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ public interface ILuaScriptResourceInfo : IBaseResourceInfo
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[XmlAttribute("IsAutorun")]
|
[XmlAttribute("IsAutorun")]
|
||||||
public bool IsAutorun { get; }
|
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
|
public interface IAssemblyResourceInfo : IBaseResourceInfo
|
||||||
|
|||||||
+2
-1
@@ -174,7 +174,8 @@ public sealed partial class ModConfigFileParserService :
|
|||||||
RequiredPackages = src.Required,
|
RequiredPackages = src.Required,
|
||||||
IncompatiblePackages = src.Incompatible,
|
IncompatiblePackages = src.Incompatible,
|
||||||
// Type Specific
|
// 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,
|
IncompatiblePackages = ImmutableArray<Identifier>.Empty,
|
||||||
RequiredPackages = ImmutableArray<Identifier>.Empty,
|
RequiredPackages = ImmutableArray<Identifier>.Empty,
|
||||||
IsAutorun = true,
|
IsAutorun = true,
|
||||||
|
RunUnrestricted = false
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Add(new LuaScriptsResourceInfo()
|
builder.Add(new LuaScriptsResourceInfo()
|
||||||
@@ -418,6 +419,7 @@ public sealed class ModConfigService : IModConfigService
|
|||||||
IncompatiblePackages = ImmutableArray<Identifier>.Empty,
|
IncompatiblePackages = ImmutableArray<Identifier>.Empty,
|
||||||
RequiredPackages = ImmutableArray<Identifier>.Empty,
|
RequiredPackages = ImmutableArray<Identifier>.Empty,
|
||||||
IsAutorun = false,
|
IsAutorun = false,
|
||||||
|
RunUnrestricted = false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -345,6 +345,8 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
|
|
||||||
//lua scripts
|
//lua scripts
|
||||||
var luaScripts = SelectCompatible(loadingOrderedPackages
|
var luaScripts = SelectCompatible(loadingOrderedPackages
|
||||||
|
.Where(pkg => executeCsAssemblies
|
||||||
|
|| !pkg.Value.LuaScripts.Any(scr => scr.RunUnrestricted))
|
||||||
.SelectMany(pkg => pkg.Value.LuaScripts)
|
.SelectMany(pkg => pkg.Value.LuaScripts)
|
||||||
.ToImmutableArray(), toLoadPackagesIndents, loadOrderByPackage);
|
.ToImmutableArray(), toLoadPackagesIndents, loadOrderByPackage);
|
||||||
|
|
||||||
@@ -513,14 +515,14 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
return !_runningPackages.IsEmpty;
|
return !_runningPackages.IsEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImmutableArray<ContentPackage> GetLoadedAssemblyPackages()
|
public ImmutableArray<ContentPackage> GetLoadedUnrestrictedPackages()
|
||||||
{
|
{
|
||||||
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
IService.CheckDisposed(this);
|
IService.CheckDisposed(this);
|
||||||
if (_loadedPackages.IsEmpty)
|
if (_loadedPackages.IsEmpty)
|
||||||
return ImmutableArray<ContentPackage>.Empty;
|
return ImmutableArray<ContentPackage>.Empty;
|
||||||
return [.._loadedPackages.Values
|
return [.._loadedPackages.Values
|
||||||
.Where(cfg => !cfg.Assemblies.IsDefaultOrEmpty)
|
.Where(cfg => !cfg.Assemblies.IsDefaultOrEmpty || cfg.LuaScripts.Any(scr => scr.RunUnrestricted))
|
||||||
.Select(cfg => cfg.Package)];
|
.Select(cfg => cfg.Package)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ public interface IPackageManagementService : IReusableService
|
|||||||
public FluentResults.Result UnloadPackages(ImmutableArray<ContentPackage> packages);
|
public FluentResults.Result UnloadPackages(ImmutableArray<ContentPackage> packages);
|
||||||
public FluentResults.Result UnloadAllPackages();
|
public FluentResults.Result UnloadAllPackages();
|
||||||
public ImmutableArray<ContentPackage> GetAllLoadedPackages();
|
public ImmutableArray<ContentPackage> GetAllLoadedPackages();
|
||||||
public ImmutableArray<ContentPackage> GetLoadedAssemblyPackages();
|
public ImmutableArray<ContentPackage> GetLoadedUnrestrictedPackages();
|
||||||
public bool IsPackageRunning(ContentPackage package);
|
public bool IsPackageRunning(ContentPackage package);
|
||||||
public bool IsAnyPackageLoaded();
|
public bool IsAnyPackageLoaded();
|
||||||
public bool IsAnyPackageRunning();
|
public bool IsAnyPackageRunning();
|
||||||
|
|||||||
Reference in New Issue
Block a user