diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Data/IBaseInfoDefinitions.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Data/IBaseInfoDefinitions.cs
index 66dcdb626..4f5cb032b 100644
--- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Data/IBaseInfoDefinitions.cs
+++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Data/IBaseInfoDefinitions.cs
@@ -41,7 +41,8 @@ public interface IResourceInfo : IPlatformInfo
{
///
/// [Optional]
- /// Allows you to specify the loading order for all assets of the same type (ie. styles, assemblies, etc.).
+ /// Specifies the loading order for all assets of the same type (ie. styles, assemblies, etc.) from
+ /// the same . Lower number is higher priority, see
///
int LoadPriority { get; }
diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Processing/ModConfigService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Processing/ModConfigService.cs
index 279a4f31c..2ad82d06c 100644
--- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Processing/ModConfigService.cs
+++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Processing/ModConfigService.cs
@@ -225,40 +225,144 @@ public sealed class ModConfigService : IModConfigService
private async Task> CreateFromLegacyAsync(ContentPackage src)
{
- List luaScripts = new List();
-
- if (_storageService.DirectoryExists(Path.Combine(src.Path, "Lua", "Autorun")) is { IsSuccess: true, Value: true })
- {
- var result = _storageService.FindFilesInPackage(src, "Lua/Autorun", "*.lua", true);
- if (result.IsSuccess)
- {
- List contentPaths = new List();
-
- foreach (var path in result.Value)
- {
- contentPaths.Add(ContentPath.FromRaw(src, $"%ModDir%/{Path.GetFullPath(path, src.Dir)}"));
- }
-
- luaScripts.Add(new LuaScriptsResourceInfo()
- {
- IsAutorun = true,
- SupportedPlatforms = Platform.Any,
- SupportedTargets = Target.Any,
- InternalName = "legacy",
- OwnerPackage = src,
- IncompatiblePackages = ImmutableArray.Empty,
- RequiredPackages = ImmutableArray.Empty,
- FilePaths = contentPaths.ToImmutableArray()
- });
- }
- }
-
return new ModConfigInfo()
{
Package = src,
- Assemblies = ImmutableArray.Empty,
- Configs = ImmutableArray.Empty,
- LuaScripts = luaScripts.ToImmutableArray()
+ Assemblies = GetAssembliesLegacy(src),
+ Configs = GetConfigsLegacy(src),
+ LuaScripts = GetLuaScriptsLegacy(src)
};
+
+ ImmutableArray GetAssembliesLegacy(ContentPackage src)
+ {
+ var binSearchInd = new (string SubFolder, Target Targets, Platform Platforms)[]
+ {
+ ("bin/Client/Windows", Target.Client, Platform.Windows),
+ ("bin/Client/Linux", Target.Client, Platform.Linux),
+ ("bin/Client/OSX", Target.Client, Platform.OSX),
+ ("bin/Server/Windows", Target.Server, Platform.Windows),
+ ("bin/Server/Linux", Target.Server, Platform.Linux),
+ ("bin/Server/OSX", Target.Server, Platform.OSX)
+ };
+
+ var builder = ImmutableArray.CreateBuilder();
+
+ foreach (var searchPathways in binSearchInd)
+ {
+ if (_storageService.FindFilesInPackage(src, searchPathways.SubFolder, "*.dll",
+ true) is { IsSuccess: true, Value.IsDefaultOrEmpty: false } result)
+ {
+ builder.Add(new AssemblyResourceInfo()
+ {
+ OwnerPackage = src,
+ InternalName = searchPathways.SubFolder,
+ SupportedPlatforms = searchPathways.Platforms,
+ SupportedTargets = searchPathways.Targets,
+ LoadPriority = 0,
+ FilePaths = result.Value.Select(fp => ContentPath.FromRaw(src, $"%ModDir%/{Path.GetRelativePath(src.Dir, fp)}".CleanUpPathCrossPlatform()))
+ .ToImmutableArray(),
+ FriendlyName = $"{src.Name}.{searchPathways.SubFolder.Replace('/','.')}",
+ IncompatiblePackages = ImmutableArray.Empty,
+ RequiredPackages = ImmutableArray.Empty,
+ IsScript = false
+ });
+ }
+ }
+
+ var sharedResult = _storageService.FindFilesInPackage(src,
+ Path.Combine(src.Dir, "CSharp/Shared"),
+ "*.cs", true);
+ var sharedFiles = sharedResult.IsSuccess && !sharedResult.Value.IsDefaultOrEmpty
+ ? sharedResult.Value.Select(fp =>
+ ContentPath.FromRaw(src, $"%ModDir%/{Path.GetRelativePath(src.Dir, fp)}".CleanUpPathCrossPlatform()))
+ .ToImmutableArray()
+ : ImmutableArray.Empty;
+
+ var srcSearchInd = new (string SubFolder, Target Targets, Platform Platforms)[]
+ {
+ ("CSharp/Client", Target.Client, Platform.Any),
+ ("CSharp/Server", Target.Server, Platform.Any)
+ };
+
+ foreach (var searchPathways in srcSearchInd)
+ {
+ if (_storageService.FindFilesInPackage(src, searchPathways.SubFolder, "*.cs",
+ true) is { IsSuccess: true, Value.IsDefaultOrEmpty: false } result)
+ {
+ builder.Add(new AssemblyResourceInfo()
+ {
+ OwnerPackage = src,
+ InternalName = searchPathways.SubFolder,
+ SupportedPlatforms = searchPathways.Platforms,
+ SupportedTargets = searchPathways.Targets,
+ LoadPriority = 0,
+ FilePaths = result.Value
+ .Select(fp => ContentPath.FromRaw(src,
+ $"%ModDir%/{Path.GetRelativePath(src.Dir, fp)}".CleanUpPathCrossPlatform()))
+ .Concat(sharedFiles).ToImmutableArray(),
+ FriendlyName = IAssemblyLoaderService.InternalsAwareAssemblyName,
+ IncompatiblePackages = ImmutableArray.Empty,
+ RequiredPackages = ImmutableArray.Empty,
+ IsScript = true
+ });
+ }
+ }
+
+ return builder.ToImmutable();
+ }
+
+ ImmutableArray GetConfigsLegacy(ContentPackage src)
+ {
+ return ImmutableArray.Empty;
+ }
+
+ ImmutableArray GetLuaScriptsLegacy(ContentPackage src)
+ {
+ var builder = ImmutableArray.CreateBuilder();
+
+ if (_storageService.FindFilesInPackage(src, "Lua", "*.lua", true)
+ is { IsSuccess: true, Value.IsDefaultOrEmpty: false } result)
+ {
+ var autorun = result.Value
+ .Where(fp => fp.CleanUpPathCrossPlatform().Contains("Lua/Autorun/"))
+ .ToImmutableArray();
+ var autorunFP = autorun.Select(fp => ContentPath.FromRaw(src,
+ $"%ModDir%/{Path.GetRelativePath(src.Dir, fp)}".CleanUpPathCrossPlatform()))
+ .ToImmutableArray();
+ var reg = result.Value.Except(autorun)
+ .Select(fp => ContentPath.FromRaw(src,
+ $"%ModDir%/{Path.GetRelativePath(src.Dir, fp)}".CleanUpPathCrossPlatform()))
+ .ToImmutableArray();
+
+ builder.Add(new LuaScriptsResourceInfo()
+ {
+ OwnerPackage = src,
+ InternalName = "LegacyAutorun",
+ SupportedPlatforms = Platform.Any,
+ SupportedTargets = Target.Any,
+ LoadPriority = 1, // autorun should be last to ensure that dependent code in other files are loaded first
+ FilePaths = autorunFP,
+ IncompatiblePackages = ImmutableArray.Empty,
+ RequiredPackages = ImmutableArray.Empty,
+ IsAutorun = true,
+ });
+
+ builder.Add(new LuaScriptsResourceInfo()
+ {
+ OwnerPackage = src,
+ InternalName = "Legacy",
+ SupportedPlatforms = Platform.Any,
+ SupportedTargets = Target.Any,
+ LoadPriority = 0, // should be included first to ensure that dependent code in these files are available
+ FilePaths = reg,
+ IncompatiblePackages = ImmutableArray.Empty,
+ RequiredPackages = ImmutableArray.Empty,
+ IsAutorun = false,
+ });
+ }
+
+ return builder.ToImmutable();
+ }
+
}
}
diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/StorageService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/StorageService.cs
index c78decde0..5abfdc0a2 100644
--- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/StorageService.cs
+++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/StorageService.cs
@@ -12,6 +12,7 @@ using Barotrauma.LuaCs.Data;
using Barotrauma.Networking;
using FluentResults;
using FluentResults.LuaCs;
+using Microsoft.CodeAnalysis;
using Microsoft.Toolkit.Diagnostics;
using Error = FluentResults.Error;
using Path = System.IO.Path;
@@ -266,9 +267,10 @@ public class StorageService : IStorageService
Guard.IsNotNull(package, nameof(package));
try
{
+ var cp = ContentPath.FromRaw(package, package.Dir);
var fullPath = localSubfolder.IsNullOrWhiteSpace()
- ? Path.GetFullPath(package.Dir)
- : Path.GetFullPath(package.Dir, localSubfolder);
+ ? Path.GetFullPath(cp.FullPath)
+ : Path.GetFullPath(localSubfolder, cp.FullPath);
return System.IO.Directory.GetFiles(fullPath, regexFilter,
searchRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
.ToImmutableArray();