- Added alpha legacy mod support.
- StorageService: Fixed ContentPackages' directories not properly resolving. - TODO: Rewrite StorageService LocalData functions to use ContentPath for resolution.
This commit is contained in:
@@ -41,7 +41,8 @@ public interface IResourceInfo : IPlatformInfo
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// [Optional]
|
/// [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 <see cref="ContentPackage"/>. Lower number is higher priority, see <see cref="System.Linq.Enumerable.OrderBy{TSource,TKey}(IEnumerable{TSource}, Func{TSource,TKey})"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int LoadPriority { get; }
|
int LoadPriority { get; }
|
||||||
|
|
||||||
|
|||||||
+135
-31
@@ -225,40 +225,144 @@ public sealed class ModConfigService : IModConfigService
|
|||||||
|
|
||||||
private async Task<Result<IModConfigInfo>> CreateFromLegacyAsync(ContentPackage src)
|
private async Task<Result<IModConfigInfo>> CreateFromLegacyAsync(ContentPackage src)
|
||||||
{
|
{
|
||||||
List<ILuaScriptResourceInfo> luaScripts = new List<ILuaScriptResourceInfo>();
|
|
||||||
|
|
||||||
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<ContentPath> contentPaths = new List<ContentPath>();
|
|
||||||
|
|
||||||
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<Identifier>.Empty,
|
|
||||||
RequiredPackages = ImmutableArray<Identifier>.Empty,
|
|
||||||
FilePaths = contentPaths.ToImmutableArray()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ModConfigInfo()
|
return new ModConfigInfo()
|
||||||
{
|
{
|
||||||
Package = src,
|
Package = src,
|
||||||
Assemblies = ImmutableArray<IAssemblyResourceInfo>.Empty,
|
Assemblies = GetAssembliesLegacy(src),
|
||||||
Configs = ImmutableArray<IConfigResourceInfo>.Empty,
|
Configs = GetConfigsLegacy(src),
|
||||||
LuaScripts = luaScripts.ToImmutableArray()
|
LuaScripts = GetLuaScriptsLegacy(src)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ImmutableArray<IAssemblyResourceInfo> 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<IAssemblyResourceInfo>();
|
||||||
|
|
||||||
|
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<Identifier>.Empty,
|
||||||
|
RequiredPackages = ImmutableArray<Identifier>.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<ContentPath>.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<Identifier>.Empty,
|
||||||
|
RequiredPackages = ImmutableArray<Identifier>.Empty,
|
||||||
|
IsScript = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.ToImmutable();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImmutableArray<IConfigResourceInfo> GetConfigsLegacy(ContentPackage src)
|
||||||
|
{
|
||||||
|
return ImmutableArray<IConfigResourceInfo>.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImmutableArray<ILuaScriptResourceInfo> GetLuaScriptsLegacy(ContentPackage src)
|
||||||
|
{
|
||||||
|
var builder = ImmutableArray.CreateBuilder<ILuaScriptResourceInfo>();
|
||||||
|
|
||||||
|
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<Identifier>.Empty,
|
||||||
|
RequiredPackages = ImmutableArray<Identifier>.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<Identifier>.Empty,
|
||||||
|
RequiredPackages = ImmutableArray<Identifier>.Empty,
|
||||||
|
IsAutorun = false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.ToImmutable();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using Barotrauma.LuaCs.Data;
|
|||||||
using Barotrauma.Networking;
|
using Barotrauma.Networking;
|
||||||
using FluentResults;
|
using FluentResults;
|
||||||
using FluentResults.LuaCs;
|
using FluentResults.LuaCs;
|
||||||
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.Toolkit.Diagnostics;
|
using Microsoft.Toolkit.Diagnostics;
|
||||||
using Error = FluentResults.Error;
|
using Error = FluentResults.Error;
|
||||||
using Path = System.IO.Path;
|
using Path = System.IO.Path;
|
||||||
@@ -266,9 +267,10 @@ public class StorageService : IStorageService
|
|||||||
Guard.IsNotNull(package, nameof(package));
|
Guard.IsNotNull(package, nameof(package));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var cp = ContentPath.FromRaw(package, package.Dir);
|
||||||
var fullPath = localSubfolder.IsNullOrWhiteSpace()
|
var fullPath = localSubfolder.IsNullOrWhiteSpace()
|
||||||
? Path.GetFullPath(package.Dir)
|
? Path.GetFullPath(cp.FullPath)
|
||||||
: Path.GetFullPath(package.Dir, localSubfolder);
|
: Path.GetFullPath(localSubfolder, cp.FullPath);
|
||||||
return System.IO.Directory.GetFiles(fullPath, regexFilter,
|
return System.IO.Directory.GetFiles(fullPath, regexFilter,
|
||||||
searchRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
|
searchRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
|
|||||||
Reference in New Issue
Block a user