diff --git a/UnrealReZen/Core/FIoPack.cs b/UnrealReZen/Core/FIoPack.cs index 4e7c68a..a318d75 100644 --- a/UnrealReZen/Core/FIoPack.cs +++ b/UnrealReZen/Core/FIoPack.cs @@ -1,5 +1,7 @@ using CUE4Parse.Encryption.Aes; using CUE4Parse.UE4.IO.Objects; +using CUE4Parse.UE4.Objects.Core.Misc; +using CUE4Parse.UE4.Versions; using System.Globalization; using System.IO.MemoryMappedFiles; using System.Text; @@ -10,8 +12,10 @@ namespace UnrealReZen.Core { public static class Packer { - public static int PackToCasToc(string dir, Dependency m, string outFilename, string compression, FAesKey aes, string mountPoint, FIoDependencyFormat depver) + public static int PackToCasToc(string dir, Dependency m, string outFilename, string compression, FAesKey aes, string mountPoint, EGame gameVer) { + FIoDependencyFormat depver = gameVer >= EGame.GAME_UE5_0 ? FIoDependencyFormat.UE5 : FIoDependencyFormat.UE4; + var fdata = new List(); AssetMetadata newEntry; Constants.MountPoint = mountPoint; @@ -50,7 +54,7 @@ public static int PackToCasToc(string dir, Dependency m, string outFilename, str File.WriteAllBytes(Path.ChangeExtension(outFilename, ".ucas"), encrypted); } - var utocBytes = fdata.ConstructUtocFile(compression, aes); + var utocBytes = fdata.ConstructUtocFile(compression, aes, gameVer); File.WriteAllBytes(outFilename, utocBytes); File.WriteAllBytes(Path.ChangeExtension(outFilename, ".pak"), PakHolder.Packed_P); return fdata.Count; @@ -217,7 +221,7 @@ public static byte[] DeparseDirectoryIndex(List files) return wrapper.ToBytes(); } - public static byte[] ConstructUtocFile(this List files, string compression, FAesKey AESKey) + public static byte[] ConstructUtocFile(this List files, string compression, FAesKey AESKey, EGame gameVer) { var udata = new UToc(new UTocHeader(), [], "", []); @@ -241,7 +245,8 @@ public static byte[] ConstructUtocFile(this List files, string co for (var i = 0; i < files.Count; i++) { compressedBlocksCount += files[i].CompressionBlocks.Count; - if (files[i].ChunkID.Type == 10) + if ((gameVer < EGame.GAME_UE5_0 && files[i].ChunkID.Type == (byte)EIoChunkType.ContainerHeader) || + gameVer >= EGame.GAME_UE5_0 && files[i].ChunkID.Type == (byte)EIoChunkType5.ContainerHeader) { containerIndex = i; } diff --git a/UnrealReZen/Program.cs b/UnrealReZen/Program.cs index 1ae64e6..331eb18 100644 --- a/UnrealReZen/Program.cs +++ b/UnrealReZen/Program.cs @@ -139,7 +139,9 @@ static void RunOptionsAndReturnExitCode(Options opts) Dependency m = new() { Deps = new DependenciesData { ChunkIDToDependencies = [] }, Files = [] }; List FilesToRepack = new(Directory.GetFiles(opts.ContentPath, "*", SearchOption.AllDirectories)); var newContainerID = opts.ContainerId ?? CryptographyHelpers.RandomUlong(); - m.Files.Add(new ManifestFile { ChunkID = new FIoChunkID(newContainerID, 0, 0, (byte)EIoChunkType.ContainerHeader), Filepath = Constants.DepFileName }); + + byte type = (EGame)engineVersion >= EGame.GAME_UE5_0 ? (byte)EIoChunkType5.ContainerHeader : (byte)EIoChunkType.ContainerHeader; + m.Files.Add(new ManifestFile { ChunkID = new FIoChunkID(newContainerID, 0, 0, type), Filepath = Constants.DepFileName }); m.Deps.ThisPackageID = newContainerID; if (FilesToRepack.Count == 0) { @@ -173,7 +175,7 @@ static void RunOptionsAndReturnExitCode(Options opts) } } Log.Information("Packing files..."); - Packer.PackToCasToc(opts.ContentPath, m, opts.OutputPath, opts.CompressionFormat, aesKey, opts.MountPoint, (EGame)engineVersion > EGame.GAME_UE4_LATEST ? FIoDependencyFormat.UE5 : FIoDependencyFormat.UE4); + Packer.PackToCasToc(opts.ContentPath, m, opts.OutputPath, opts.CompressionFormat, aesKey, opts.MountPoint, (EGame)engineVersion); Console.WriteLine($"Done! {FilesToRepack.Count} file(s) packed"); }