From 173ca011fdc4e0725ae00303746466220579d7e4 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Thu, 28 Dec 2023 05:26:40 +0100 Subject: [PATCH] ACZ fixes (#1573) * Fix packaging * Fix ACZ root path being wrong if using relative JSON path The JSON path is relative to the original working directory of the file. However the server switches working directory during initialization of DreamResourceManager, which invalidates the old path. This old path was still passed to ACZ, so using a relative JSON path would make ACZ unable to find rsc files. The path is now turned absolute before the working directory switch occurs. * Add Full Hybrid ACZ provider. This permits rsc resources to be combined with the Content.Client.zip Hybrid ACZ. Also update RT * Update OpenDreamPackaging/DreamPackaging.cs --------- Co-authored-by: wixoa --- OpenDreamPackaging/DreamPackaging.cs | 17 ++++++--- OpenDreamRuntime/DreamAczProvider.cs | 43 +++++++++++++++++++++++ OpenDreamRuntime/DreamMagicAczProvider.cs | 26 -------------- OpenDreamRuntime/DreamManager.cs | 8 ++--- OpenDreamRuntime/EntryPoint.cs | 4 --- RobustToolbox | 2 +- 6 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 OpenDreamRuntime/DreamAczProvider.cs delete mode 100644 OpenDreamRuntime/DreamMagicAczProvider.cs diff --git a/OpenDreamPackaging/DreamPackaging.cs b/OpenDreamPackaging/DreamPackaging.cs index 13004e1e97..e171bb0208 100644 --- a/OpenDreamPackaging/DreamPackaging.cs +++ b/OpenDreamPackaging/DreamPackaging.cs @@ -1,5 +1,6 @@ using Robust.Packaging; using Robust.Packaging.AssetProcessing; +using Robust.Packaging.AssetProcessing.Passes; namespace OpenDreamPackaging; @@ -19,13 +20,21 @@ public static async Task WriteResources( var inputPass = graph.Input; - await RobustClientPackaging.WriteClientResources( - contentDir, + await RobustSharedPackaging.WriteContentAssemblies( inputPass, - cancel); + contentDir, + "Content.Client", + new[] { "OpenDreamClient", "OpenDreamShared" }, + cancel: cancel); await RobustClientPackaging.WriteClientResources(contentDir, inputPass, cancel); + WriteRscResources(dreamRootDir, resources, inputPass); + + inputPass.InjectFinished(); + } + + public static void WriteRscResources(string dreamRootDir, string[] resources, AssetPassPipe inputPass) { for (var i = 0; i < resources.Length; i++) { var resource = resources[i].Replace('\\', Path.DirectorySeparatorChar); // The game client only knows a resource ID, so that's what we name the files. @@ -35,7 +44,5 @@ await RobustClientPackaging.WriteClientResources( inputPass.InjectFileFromDisk(path, diskPath); } - - inputPass.InjectFinished(); } } diff --git a/OpenDreamRuntime/DreamAczProvider.cs b/OpenDreamRuntime/DreamAczProvider.cs new file mode 100644 index 0000000000..c85182a556 --- /dev/null +++ b/OpenDreamRuntime/DreamAczProvider.cs @@ -0,0 +1,43 @@ +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using OpenDreamPackaging; +using Robust.Packaging; +using Robust.Packaging.AssetProcessing; +using Robust.Server.ServerStatus; + +namespace OpenDreamRuntime; + +public sealed class DreamAczProvider : IMagicAczProvider, IFullHybridAczProvider { + private readonly IDependencyCollection _dependencies; + private readonly string _rootPath; + private readonly string[] _resources; + + public DreamAczProvider(IDependencyCollection dependencies, string rootPath, string[] resources) { + _dependencies = dependencies; + _rootPath = rootPath; + _resources = resources; + } + + public async Task Package(AssetPass pass, IPackageLogger logger, CancellationToken cancel) { + var contentDir = DefaultMagicAczProvider.FindContentRootPath(_dependencies); + + await DreamPackaging.WriteResources(contentDir, _rootPath, _resources, pass, logger, cancel); + } + + public Task Package(AssetPass hybridPackageInput, AssetPass output, IPackageLogger logger, CancellationToken cancel) { + var clientAssetGraph = new RobustClientAssetGraph(); + var resourceInput = clientAssetGraph.Input; + output.AddDependency(clientAssetGraph.Output); + output.AddDependency(hybridPackageInput); + + AssetGraph.CalculateGraph( + clientAssetGraph.AllPasses.Concat(new[] { hybridPackageInput, output }).ToArray(), + logger); + + DreamPackaging.WriteRscResources(_rootPath, _resources, resourceInput); + resourceInput.InjectFinished(); + + return Task.CompletedTask; + } +} diff --git a/OpenDreamRuntime/DreamMagicAczProvider.cs b/OpenDreamRuntime/DreamMagicAczProvider.cs deleted file mode 100644 index 965f6aa8b6..0000000000 --- a/OpenDreamRuntime/DreamMagicAczProvider.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; -using OpenDreamPackaging; -using Robust.Packaging; -using Robust.Packaging.AssetProcessing; -using Robust.Server.ServerStatus; - -namespace OpenDreamRuntime; - -public sealed class DreamMagicAczProvider : IMagicAczProvider { - private readonly IDependencyCollection _dependencies; - private readonly string _rootPath; - private readonly string[] _resources; - - public DreamMagicAczProvider(IDependencyCollection dependencies, string rootPath, string[] resources) { - _dependencies = dependencies; - _rootPath = rootPath; - _resources = resources; - } - - public async Task Package(AssetPass pass, IPackageLogger logger, CancellationToken cancel) { - var contentDir = DefaultMagicAczProvider.FindContentRootPath(_dependencies); - - await DreamPackaging.WriteResources(contentDir, _rootPath, _resources, pass, logger, cancel); - } -} diff --git a/OpenDreamRuntime/DreamManager.cs b/OpenDreamRuntime/DreamManager.cs index 5befb8d19f..7453ae3c70 100644 --- a/OpenDreamRuntime/DreamManager.cs +++ b/OpenDreamRuntime/DreamManager.cs @@ -116,7 +116,7 @@ public bool LoadJson(string? jsonPath) { } _compiledJson = json; - var rootPath = Path.GetDirectoryName(jsonPath)!; + var rootPath = Path.GetFullPath(Path.GetDirectoryName(jsonPath)!); var resources = _compiledJson.Resources ?? Array.Empty(); _dreamResourceManager.Initialize(rootPath, resources); if(!string.IsNullOrEmpty(_compiledJson.Interface) && !_dreamResourceManager.DoesFileExist(_compiledJson.Interface)) @@ -146,9 +146,9 @@ public bool LoadJson(string? jsonPath) { _dreamMapManager.LoadMaps(_compiledJson.Maps); - _statusHost.SetMagicAczProvider(new DreamMagicAczProvider( - _dependencyCollection, rootPath, resources - )); + var aczProvider = new DreamAczProvider(_dependencyCollection, rootPath, resources); + _statusHost.SetMagicAczProvider(aczProvider); + _statusHost.SetFullHybridAczProvider(aczProvider); return true; } diff --git a/OpenDreamRuntime/EntryPoint.cs b/OpenDreamRuntime/EntryPoint.cs index 6f962e645e..6a54f0db18 100644 --- a/OpenDreamRuntime/EntryPoint.cs +++ b/OpenDreamRuntime/EntryPoint.cs @@ -25,10 +25,6 @@ public sealed class EntryPoint : GameServer { private DreamCommandSystem? _commandSystem; public override void Init() { - IoCManager.Resolve().SetMagicAczProvider(new DefaultMagicAczProvider( - new DefaultMagicAczInfo("Content.Client", new[] {"OpenDreamClient", "OpenDreamShared"}), - IoCManager.Resolve())); - IComponentFactory componentFactory = IoCManager.Resolve(); componentFactory.DoAutoRegistrations(); diff --git a/RobustToolbox b/RobustToolbox index eb092e90ef..a891cacae5 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit eb092e90efc7ac4ae562bc46f9b760745a29e289 +Subproject commit a891cacae53d704f1d0afa85bd3bc10820c38881