diff --git a/packages/game/JSExport/GameInterface.cs b/packages/game/JSExport/GameInterface.cs index e7240b73e..3d958b8b8 100644 --- a/packages/game/JSExport/GameInterface.cs +++ b/packages/game/JSExport/GameInterface.cs @@ -4,6 +4,7 @@ using CUE4Parse.UE4.Assets.Exports.Texture; using CUE4Parse.UE4.Objects.Engine; using CUE4Parse.UE4.Objects.UObject; using Microsoft.JavaScript.NodeApi; +using SkiaSharp; namespace BlitzKit.Game.JSExport; @@ -44,20 +45,20 @@ public class GameInterface if (provider.TryLoadPackageObject(path, out var pda)) { - try + FSoftObjectPath objectPath = pda.Get("BigIcon"); + UTexture2D uTexture = objectPath.Load(); + CTexture? cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile); + + if (cTexture is null) { - return pda.Get("BigIcon") - .Load() - .Decode(ETexturePlatform.DesktopMobile)! - .ToSkBitmap() - .Encode(SkiaSharp.SKEncodedImageFormat.Webp, 80) - .ToArray(); - } - catch (Exception e) - { - Console.WriteLine(e); - throw; + continue; } + + SKBitmap bitmap = cTexture.ToSkBitmap(); + SKData data = bitmap.Encode(SKEncodedImageFormat.Webp, 80); + byte[] bytes = data.ToArray(); + + return bytes; } else { @@ -65,6 +66,6 @@ public class GameInterface } } - throw new FileNotFoundException($"Tank {tankId}/{pdaName} not found in any nation"); + return []; } } diff --git a/packages/game/game.slnx b/packages/game/game.slnx new file mode 100644 index 000000000..66702466a --- /dev/null +++ b/packages/game/game.slnx @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/website-ue/src/pages/api/tanks/[id].webp.ts b/packages/website-ue/src/pages/api/tanks/[id].webp.ts index 21cea66e8..ba0cfbeaa 100644 --- a/packages/website-ue/src/pages/api/tanks/[id].webp.ts +++ b/packages/website-ue/src/pages/api/tanks/[id].webp.ts @@ -7,5 +7,8 @@ export { getStaticPaths } from "./[id].pb"; export async function GET({ params }: APIContext) { const tank = await api.tank(params.id); const image = game.tankBigIcon(params.id, tank.tank!.visual_data); + + if (image.length === 0) return new Response(null, { status: 404 }); + return new Response(new Uint8Array(image)); }