Files
blitzkit/src/CLI/Functions/Unpacker.cs
T

106 lines
2.8 KiB
C#
Raw Normal View History

2025-01-25 22:44:50 -06:00
using CLI.Utils;
2025-01-25 22:17:41 -06:00
using CUE4Parse.FileProvider.Objects;
using CUE4Parse.UE4.Pak;
2025-01-23 21:43:54 -06:00
namespace CLI.Functions
{
2025-01-25 21:42:25 -06:00
class Unpacker
2025-01-23 21:43:54 -06:00
{
2025-01-25 23:27:39 -06:00
private const string contentGroup = "p14y73c7_p5e_b10gg3RS_big_play";
private const string vfs = "../../temp/vfs/";
2025-01-25 22:44:50 -06:00
// this may be different from the one provided in args so check this and not args[1]
// we don't wanna delete my local installation of the game when debugging haha!
public static string tempDepotsDir = "../../temp/depot/";
2025-01-25 22:17:41 -06:00
2025-01-25 21:42:25 -06:00
public static void Unpack(string[] args)
2025-01-23 21:43:54 -06:00
{
2025-01-25 21:42:25 -06:00
if (args.Length < 2)
{
2025-01-25 22:17:41 -06:00
throw new ArgumentException("Missing required initial paks directory");
2025-01-25 21:42:25 -06:00
}
2025-01-25 13:49:28 -06:00
2025-01-25 22:44:50 -06:00
AgnosticZlibHelper.Initialize();
2025-01-25 22:17:41 -06:00
2025-01-25 23:27:39 -06:00
UnpackDepot(args[1]);
UnpackDLC();
}
private static void UnpackDLC()
{
string defaultDlcPath = Path.Combine(vfs, "Blitz/Config/DefaultDlc.ini");
IniParser iniParser = new(defaultDlcPath);
string? contentBuildId = iniParser.GetString("DefaultContentBuildId");
if (string.IsNullOrEmpty(contentBuildId))
{
throw new Exception("Failed to read content build id from DefaultDlc.ini");
}
Console.WriteLine($"Exploring DLC {contentBuildId} within group {contentGroup}");
}
private static void UnpackDepot(string workingDirectory)
{
2025-01-25 21:42:25 -06:00
string paksDirectory = Path.Combine(workingDirectory, "Blitz/Content/Paks");
2025-01-25 22:17:41 -06:00
string[] containers = Directory.GetFiles(paksDirectory, "*.pak");
2025-01-25 21:42:25 -06:00
2025-01-25 22:17:41 -06:00
foreach (string container in containers)
2025-01-25 21:42:25 -06:00
{
2025-01-25 22:17:41 -06:00
Exergy(container);
2025-01-25 21:42:25 -06:00
}
2025-01-25 22:44:50 -06:00
if (Directory.Exists(tempDepotsDir))
{
Console.WriteLine("Deleting temp depots directory...");
Directory.Delete(tempDepotsDir, true);
}
2025-01-25 22:17:41 -06:00
}
2025-01-25 21:42:25 -06:00
2025-01-25 23:27:39 -06:00
private static void Exergy(string container)
2025-01-25 22:17:41 -06:00
{
Console.WriteLine($"Filtering {container}");
2025-01-25 21:42:25 -06:00
2025-01-25 22:17:41 -06:00
PakFileReader reader = new(container);
2025-01-25 13:49:28 -06:00
2025-01-25 22:17:41 -06:00
reader.Mount();
2025-01-23 21:43:54 -06:00
2025-01-25 22:17:41 -06:00
foreach (var file in reader.Files)
{
GameFile gameFile = file.Value;
bool exergizable = ShouldExergize(gameFile.Path);
if (!exergizable)
{
continue;
}
2025-01-25 23:27:39 -06:00
string writePath = Path.Combine(vfs, gameFile.Path);
2025-01-25 22:17:41 -06:00
if (File.Exists(writePath))
{
Console.WriteLine($"{gameFile.Path} already exists; skipping...");
continue;
}
Console.WriteLine($"{gameFile.Path} writing from vfs...");
string? directory = Path.GetDirectoryName(writePath);
if (directory != null && !Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
File.WriteAllBytes(writePath, gameFile.Read());
}
}
2025-01-25 23:27:39 -06:00
private static string[] ExergizableFiles = ["Blitz/Config/DefaultDlc.ini"];
2025-01-25 22:17:41 -06:00
2025-01-25 23:27:39 -06:00
private static bool ShouldExergize(string path)
2025-01-25 22:17:41 -06:00
{
return ExergizableFiles.Contains(path);
2025-01-23 21:43:54 -06:00
}
}
}