diff --git a/build/Build.cs b/build/Build.cs index ce740c4e..f5f3e5cd 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -7,6 +7,7 @@ using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using ICSharpCode.SharpZipLib.Zip; +using ICSharpCode.SharpZipLib.Zip.Compression; using LibHacBuild.CodeGen.Stage1; using Nuke.Common; using Nuke.Common.CI.AppVeyor; @@ -514,6 +515,21 @@ namespace LibHacBuild } } + public static byte[] DeflateBytes(byte[] data) + { + var s = new Deflater(9, true); + s.SetInput(data); + s.Finish(); + byte[] buffer = new byte[data.Length]; + s.Deflate(buffer); + + Debug.Assert(s.IsFinished); + + byte[] compressed = new byte[s.TotalOut]; + Array.Copy(buffer, compressed, compressed.Length); + return compressed; + } + public static void PushArtifact(string path) { if (!File.Exists(path)) diff --git a/build/CodeGen/Stage1/ResultCodegen.cs b/build/CodeGen/Stage1/ResultCodegen.cs index 936f42c7..2971a0b9 100644 --- a/build/CodeGen/Stage1/ResultCodegen.cs +++ b/build/CodeGen/Stage1/ResultCodegen.cs @@ -36,7 +36,8 @@ namespace LibHacBuild.CodeGen.Stage1 } byte[] archive = BuildArchive(modules); - string archiveStr = PrintArchive(archive); + byte[] compressedArchive = Build.DeflateBytes(archive); + string archiveStr = PrintArchive(compressedArchive); WriteOutput("LibHac/ResultNameResolver.Generated.cs", archiveStr); } diff --git a/src/LibHac/ResultNameResolver.cs b/src/LibHac/ResultNameResolver.cs index 2aee430e..545a9622 100644 --- a/src/LibHac/ResultNameResolver.cs +++ b/src/LibHac/ResultNameResolver.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Compression; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using LibHac.Common; @@ -19,10 +20,18 @@ namespace LibHac private static Dictionary GetResultNames() { - var archiveReader = new ResultArchiveReader(ArchiveData); + var archiveReader = new ResultArchiveReader(DecompressArchive()); return archiveReader.GetDictionary(); } + private static byte[] DecompressArchive() + { + var deflateStream = new DeflateStream(new MemoryStream(ArchiveData.ToArray()), CompressionMode.Decompress); + var archiveDataStream = new MemoryStream(); + deflateStream.CopyTo(archiveDataStream); + return archiveDataStream.ToArray(); + } + // To save a bunch of space in the assembly, Results with their names are packed into // an archive and unpacked at runtime. private readonly ref struct ResultArchiveReader