From 8cf3da12fa3cdab5054c300fe1598281ff5e2076 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Sat, 23 May 2026 14:30:52 -0500 Subject: [PATCH] well its working now at least i guess --- packages/game/JSExport/GameInterface.cs | 84 ++++++++++++------------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/packages/game/JSExport/GameInterface.cs b/packages/game/JSExport/GameInterface.cs index 74a524317..e5c51bf73 100644 --- a/packages/game/JSExport/GameInterface.cs +++ b/packages/game/JSExport/GameInterface.cs @@ -10,7 +10,6 @@ using CUE4Parse.UE4.Objects.Engine; using CUE4Parse.UE4.Objects.UObject; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.JavaScript.NodeApi; -using SharpGLTF.Schema2; using SkiaSharp; namespace BlitzKit.Game.JSExport; @@ -80,13 +79,13 @@ public partial class GameInterface [GeneratedRegex(@"T_UI_Flag_(\w+)_S")] private static partial Regex FlagNameRegex(); - private readonly string flagsPrefix = "Blitz/Content/UI/Textures/Flag/TankCard/"; - - public byte[]? Flag(string nation) + public byte[] Flag(string nation) { - foreach (var path in files) + var flagsBase = "Blitz/Content/UI/Textures/Flag/TankCard/"; + + foreach (var path in provider.Files.Keys) { - if (!path.StartsWith(flagsPrefix)) + if (!path.StartsWith(flagsBase)) { continue; } @@ -101,23 +100,34 @@ public partial class GameInterface { if (provider.TryLoadPackageObject($"{path}.{fileName}", out var uTexture)) { - return Image(uTexture); + CTexture? cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile); + + if (cTexture is null) + { + Console.WriteLine($"No flag found for {nation}"); + return []; + } + + SKBitmap bitmap = cTexture.ToSkBitmap(); + SKData data = bitmap.Encode(SKEncodedImageFormat.Webp, 80); + + return data.ToArray(); } Console.WriteLine($"No flag found for {nation}"); - return null; + return []; } } Console.WriteLine($"No flag found for {nation}"); - return null; + return []; } private static readonly string equipmentPDAPrefix = "Blitz/Content/TanksStuff/Equipment/PDA_Equipment"; private static readonly string equipmentPDASuffix = ".uasset"; - public byte[]? EquipmentIcon(string[] names) + public byte[] EquipmentIcon(string[] names) { List candidates = []; @@ -144,46 +154,30 @@ public partial class GameInterface if (candidate is null) { Console.WriteLine($"No equipment pda found for {string.Join(", ", names)}"); - return null; + return []; } - var pda = PDA(candidate); - var icon = pda.Get("Icon"); + var path = $"{candidate}.{Path.GetFileNameWithoutExtension(candidate)}"; - return Image(icon); - } - - private UPrimaryDataAsset PDA(string path) - { - var name = Path.GetFileNameWithoutExtension(path); - var fullPath = $"{path}.{name}"; - var pda = provider.LoadPackageObject(fullPath); - - return pda; - } - - private readonly SKEncodedImageFormat imageFormat = SKEncodedImageFormat.Webp; - private readonly int imageQuality = 80; - - private byte[]? Image(UTexture2D uTexture) - { - var cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile); - - if (cTexture is null) + if (provider.TryLoadPackageObject(path, out var pda)) { - Console.WriteLine($"Could not extract icon for {uTexture}"); - return null; + var icon = pda.Get("Icon"); + var uTexture = icon.Load(); + var cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile); + + if (cTexture is null) + { + Console.WriteLine($"Could not extract icon for {path}"); + return []; + } + + var bitmap = cTexture.ToSkBitmap(); + var data = bitmap.Encode(SKEncodedImageFormat.Webp, 80); + + return data.ToArray(); } - var bitmap = cTexture.ToSkBitmap(); - var data = bitmap.Encode(imageFormat, imageQuality); - - return data.ToArray(); - } - - private byte[]? Image(FSoftObjectPath image) - { - var uTexture = image.Load(); - return Image(uTexture); + Console.WriteLine($"Could not load {path} as pda"); + return []; } }