diff --git a/.vscode/settings.json b/.vscode/settings.json index 11364d580..9f1f75861 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -127,6 +127,7 @@ "noout", "normalmap", "oneof", + "Oodle", "oopsies", "Oopsy", "opentest", diff --git a/src/CLI/Functions/Unpacker.cs b/src/CLI/Functions/Unpacker.cs index d4fb18d89..10e9dfba5 100644 --- a/src/CLI/Functions/Unpacker.cs +++ b/src/CLI/Functions/Unpacker.cs @@ -25,7 +25,7 @@ namespace CLI.Functions throw new ArgumentException("Missing required initial paks directory"); } - AgnosticZlibHelper.Initialize(); + AgnosticHelpers.Initialize(); UnpackDepot(args[1]); await UnpackDLC(); @@ -64,6 +64,9 @@ namespace CLI.Functions PakFileReader reader = new(archive); Exergize(reader); + + memoryStream.Dispose(); + httpStream.Dispose(); } } diff --git a/src/CLI/Utils/AgnosticHelpers.cs b/src/CLI/Utils/AgnosticHelpers.cs new file mode 100644 index 000000000..afb07f8f4 --- /dev/null +++ b/src/CLI/Utils/AgnosticHelpers.cs @@ -0,0 +1,101 @@ +using System.IO.Compression; +using System.Runtime.InteropServices; +using CUE4Parse.Compression; + +namespace CLI.Utils +{ + public static class AgnosticHelpers + { + public const string BINARY_DIR = "../../temp/"; + public const string ZLIB_BINARY_URL_PREFIX = + "https://github.com/NotOfficer/Zlib-ng.NET/releases/download/1.0.0"; + public const string OODLE_BINARY_URL_PREFIX = + "https://github.com/WorkingRobot/OodleUE/releases/download/2024-11-01-726"; + + public static void Initialize() + { + InitializeZlib(); + InitializeOodle(); + } + + public static async Task InitializeOodle() + { + string url; + string extension; + string entry; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + url = $"{OODLE_BINARY_URL_PREFIX}/msvc.zip"; + entry = "bin/Release/oodle-data-shared.dll"; + extension = "dll"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + url = $"{ZLIB_BINARY_URL_PREFIX}/gcc.zip"; + entry = "lib/Release/liboodle-data-shared.so"; + extension = "so"; + } + else + { + throw new PlatformNotSupportedException(); + } + + HttpClient client = new(); + using var response = await client.GetAsync(url).ConfigureAwait(false); + + response.EnsureSuccessStatusCode(); + + await using var responseStream = await response + .Content.ReadAsStreamAsync() + .ConfigureAwait(false); + using var zip = new ZipArchive(responseStream, ZipArchiveMode.Read); + var zipEntry = zip.GetEntry(entry); + + ArgumentNullException.ThrowIfNull(zipEntry, "oodle entry in zip not found"); + + string path = Path.Combine(BINARY_DIR, $"oodle.{extension}"); + await using var entryStream = zipEntry.Open(); + await using var fs = File.Create(path); + await entryStream.CopyToAsync(fs).ConfigureAwait(false); + + OodleHelper.Initialize(path); + } + + public static void InitializeZlib() + { + string url; + string extension; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + url = $"{ZLIB_BINARY_URL_PREFIX}/zlib-ng2.dll"; + extension = "dll"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + url = $"{ZLIB_BINARY_URL_PREFIX}/libz-ng.so"; + extension = "so"; + } + else + { + throw new PlatformNotSupportedException(); + } + + string fileName = $"zlib.{extension}"; + string filePath = Path.Combine(BINARY_DIR, fileName); + + if (File.Exists(filePath)) + { + Console.WriteLine($"Zlib found at {filePath}; using that..."); + } + else + { + Console.WriteLine($"Zlib not found; downloading to {filePath} from {url}..."); + ZlibHelper.DownloadDll(filePath, url); + } + + ZlibHelper.Initialize(filePath); + } + } +} diff --git a/src/CLI/Utils/AgnosticZlibHelper.cs b/src/CLI/Utils/AgnosticZlibHelper.cs deleted file mode 100644 index 64a21ef35..000000000 --- a/src/CLI/Utils/AgnosticZlibHelper.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Runtime.InteropServices; -using CUE4Parse.Compression; - -namespace CLI.Utils -{ - public static class AgnosticZlibHelper - { - public const string ZLIB_BINARY_DIR = "../../temp/"; - public const string ZLIB_BINARY_URL_PREFIX = - "https://github.com/NotOfficer/Zlib-ng.NET/releases/download/1.0.0"; - - public static void Initialize() - { - string binariesUrl; - string fileExtension; - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - binariesUrl = $"{ZLIB_BINARY_URL_PREFIX}/zlib-ng2.dll"; - fileExtension = "dll"; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - binariesUrl = $"{ZLIB_BINARY_URL_PREFIX}/libz-ng.so"; - fileExtension = "so"; - } - else - { - throw new PlatformNotSupportedException(); - } - - string fileName = $"zlib.{fileExtension}"; - string filePath = Path.Combine(ZLIB_BINARY_DIR, fileName); - - if (File.Exists(filePath)) - { - Console.WriteLine($"Zlib found at {filePath}; using that..."); - } - else - { - Console.WriteLine($"Zlib not found; downloading to {filePath} from {binariesUrl}..."); - ZlibHelper.DownloadDll(filePath, binariesUrl); - } - - ZlibHelper.Initialize(filePath); - } - } -}