feat: custom provider

This commit is contained in:
TrèsAbhi committed 2026-02-02 17:08:37 -06:00
1 parent 0b7f717057
commit 6c1c088d44
2 files changed
+53 -29

No files matched your search

@@ -0,0 +1,79 @@
using System.Runtime.InteropServices;
using CUE4Parse.Compression;
using Microsoft.JavaScript.NodeApi;
namespace game.src.classes;
[JSExport]
public class GameInterface
{
private readonly BlitzFileProvider provider;
public string[] files;
public string[] tanksDirectoryNations;
public GameInterface(string directory)
{
provider = new(directory);
provider.Initialize();
provider.Mount();
string libraryExtension;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
libraryExtension = "dll";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
libraryExtension = "so";
}
else
{
throw new Exception("Unsupported OS");
}
OodleHelper.DownloadOodleDll($"temp/oodle.{libraryExtension}");
OodleHelper.Initialize($"temp/oodle.{libraryExtension}");
files = [.. provider.Files.Keys];
var tanksBase = "Blitz/Content/Tanks/";
tanksDirectoryNations =
[
.. files
.Where(path => path.StartsWith(tanksBase))
.Select(path => path[tanksBase.Length..])
.Select(path => path.Split('/')[0])
.Where(nation => !nation.EndsWith(".uasset") && nation != "TankStub")
.Distinct(),
];
}
public string[] Files => files;
public string[] TanksDirectoryNations => tanksDirectoryNations;
public byte[] TankBigIcon(string tankId, string pdaName)
{
foreach (var nation in tanksDirectoryNations)
{
var path = $"Blitz/Content/Tanks/{nation}/{tankId}/{pdaName}.{pdaName}";
Console.WriteLine(path);
if (provider.TryLoadPackageObject(path, out var pda))
{
Console.WriteLine(pda);
Console.WriteLine(pda.GetType());
return [];
}
else
{
continue;
}
}
throw new FileNotFoundException($"Tank {tankId}/{pdaName} not found in any nation");
}
}