Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions UnrealReZen/Core/FIoPack.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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>();
AssetMetadata newEntry;
Constants.MountPoint = mountPoint;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -217,7 +221,7 @@ public static byte[] DeparseDirectoryIndex(List<AssetMetadata> files)
return wrapper.ToBytes();
}

public static byte[] ConstructUtocFile(this List<AssetMetadata> files, string compression, FAesKey AESKey)
public static byte[] ConstructUtocFile(this List<AssetMetadata> files, string compression, FAesKey AESKey, EGame gameVer)
{
var udata = new UToc(new UTocHeader(), [], "", []);

Expand All @@ -241,7 +245,8 @@ public static byte[] ConstructUtocFile(this List<AssetMetadata> 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;
}
Expand Down
6 changes: 4 additions & 2 deletions UnrealReZen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ static void RunOptionsAndReturnExitCode(Options opts)
Dependency m = new() { Deps = new DependenciesData { ChunkIDToDependencies = [] }, Files = [] };
List<string> 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)
{
Expand Down Expand Up @@ -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");

}
Expand Down
Loading