From b070cad92a1d5a66fe05429ae4c66178d7eb32ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:35:02 -0600 Subject: [PATCH] SynchronousOodleHelper --- packages/game/JSExport/GameInterface.cs | 9 +-- ...hronousFileProvider.cs => FileProvider.cs} | 0 packages/game/Synchronous/OodleHelper.cs | 71 +++++++++++++++++++ 3 files changed, 74 insertions(+), 6 deletions(-) rename packages/game/Synchronous/{SynchronousFileProvider.cs => FileProvider.cs} (100%) create mode 100644 packages/game/Synchronous/OodleHelper.cs diff --git a/packages/game/JSExport/GameInterface.cs b/packages/game/JSExport/GameInterface.cs index 101417bd9..2342e16a2 100644 --- a/packages/game/JSExport/GameInterface.cs +++ b/packages/game/JSExport/GameInterface.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; using BlitzKit.Game.Models; -using CUE4Parse.Compression; +using BlitzKit.Game.Synchronous; using Microsoft.JavaScript.NodeApi; namespace BlitzKit.Game.JSExport; @@ -34,11 +34,8 @@ public class GameInterface throw new Exception("Unsupported OS"); } - Directory.CreateDirectory("../../temp"); - Console.WriteLine($"../..temp/oodle.{libraryExtension}"); - var bool1 = OodleHelper.DownloadOodleDll($"../..temp/oodle.{libraryExtension}"); - Console.WriteLine(bool1); - OodleHelper.Initialize($"../..temp/oodle.{libraryExtension}"); + SynchronousOodleHelper.DownloadOodleDll($"../..temp/oodle.{libraryExtension}"); + SynchronousOodleHelper.Initialize($"../..temp/oodle.{libraryExtension}"); files = [.. provider.Files.Keys]; diff --git a/packages/game/Synchronous/SynchronousFileProvider.cs b/packages/game/Synchronous/FileProvider.cs similarity index 100% rename from packages/game/Synchronous/SynchronousFileProvider.cs rename to packages/game/Synchronous/FileProvider.cs diff --git a/packages/game/Synchronous/OodleHelper.cs b/packages/game/Synchronous/OodleHelper.cs new file mode 100644 index 000000000..f85307fcf --- /dev/null +++ b/packages/game/Synchronous/OodleHelper.cs @@ -0,0 +1,71 @@ +using System.IO.Compression; +using System.Net; +using System.Net.Http.Headers; +using CUE4Parse.Compression; + +namespace BlitzKit.Game.Synchronous; + +public static class SynchronousOodleHelper +{ + public static bool DownloadOodleDll(string? path = null) + { + path ??= OodleHelper.OODLE_DLL_NAME_OLD; + + if (File.Exists(path)) + return false; + + using var client = new HttpClient( + new SocketsHttpHandler + { + UseProxy = false, + UseCookies = false, + AutomaticDecompression = DecompressionMethods.All, + } + ); + + client.DefaultRequestHeaders.UserAgent.Add( + new ProductInfoHeaderValue( + nameof(CUE4Parse), + typeof(OodleHelper).Assembly.GetName().Version?.ToString() ?? "1.0.0" + ) + ); + client.Timeout = TimeSpan.FromSeconds(30); + + return DownloadOodleDllFromOodleUE(client, path); + } + + public static bool DownloadOodleDllFromOodleUE(HttpClient client, string path) + { + const string url = + "https://github.com/WorkingRobot/OodleUE/releases/download/2025-07-31-1001/clang-cl.zip"; // 2.9.14 + const string entryName = "bin/Release/oodle-data-shared.dll"; + + try + { + using var response = client.GetAsync(url).GetAwaiter().GetResult(); + response.EnsureSuccessStatusCode(); + + using var responseStream = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult(); + using var zip = new ZipArchive(responseStream, ZipArchiveMode.Read); + var entry = zip.GetEntry(entryName); + ArgumentNullException.ThrowIfNull(entry, "oodle entry in zip not found"); + + using var entryStream = entry.Open(); + using var fs = File.Create(path); + entryStream.CopyTo(fs); + + return true; + } + catch (Exception e) + { + Console.WriteLine($"Uncaught exception while downloading oodle dll from OodleUE: {e}"); + } + + return false; + } + + public static void Initialize(string? path = null) + { + OodleHelper.Initialize(path); + } +}