2026-02-01 21:05:38 -06:00
|
|
|
using System.Runtime.InteropServices;
|
2026-02-02 17:28:24 -06:00
|
|
|
using BlitzKit.Game.Models;
|
2026-02-02 17:37:36 -06:00
|
|
|
using CUE4Parse.Compression;
|
2026-01-27 08:59:34 -06:00
|
|
|
using Microsoft.JavaScript.NodeApi;
|
|
|
|
|
|
2026-02-02 17:28:24 -06:00
|
|
|
namespace BlitzKit.Game.JSExport;
|
2026-01-27 08:59:34 -06:00
|
|
|
|
|
|
|
|
[JSExport]
|
2026-02-02 17:08:37 -06:00
|
|
|
public class GameInterface
|
2026-01-27 08:59:34 -06:00
|
|
|
{
|
2026-02-02 17:08:37 -06:00
|
|
|
private readonly BlitzFileProvider provider;
|
2026-01-27 08:59:34 -06:00
|
|
|
|
2026-02-01 19:34:36 -06:00
|
|
|
public string[] files;
|
|
|
|
|
public string[] tanksDirectoryNations;
|
2026-01-27 08:59:34 -06:00
|
|
|
|
2026-02-02 17:08:37 -06:00
|
|
|
public GameInterface(string directory)
|
2026-02-01 19:34:36 -06:00
|
|
|
{
|
2026-02-02 17:08:37 -06:00
|
|
|
provider = new(directory);
|
2026-02-01 21:05:38 -06:00
|
|
|
|
2026-02-01 19:34:36 -06:00
|
|
|
provider.Initialize();
|
|
|
|
|
provider.Mount();
|
|
|
|
|
|
2026-02-02 18:07:20 -06:00
|
|
|
Console.WriteLine("Mounted VFS:");
|
|
|
|
|
Console.WriteLine(provider.MountedVfs.Count);
|
|
|
|
|
foreach (var vfs in provider.MountedVfs)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(vfs.Path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Unloaded VFS:");
|
|
|
|
|
Console.WriteLine(provider.UnloadedVfs.Count);
|
|
|
|
|
foreach (var vfs in provider.UnloadedVfs)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(vfs.Path);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-01 21:05:38 -06:00
|
|
|
string libraryExtension;
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
{
|
|
|
|
|
libraryExtension = "dll";
|
|
|
|
|
}
|
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
{
|
|
|
|
|
libraryExtension = "so";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Unsupported OS");
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-02 17:37:36 -06:00
|
|
|
OodleHelper.DownloadOodleDll($"../../temp/oodle.{libraryExtension}");
|
|
|
|
|
OodleHelper.Initialize($"../../temp/oodle.{libraryExtension}");
|
2026-02-01 21:05:38 -06:00
|
|
|
|
2026-02-01 19:34:36 -06:00
|
|
|
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(),
|
|
|
|
|
];
|
2026-02-02 17:24:20 -06:00
|
|
|
|
|
|
|
|
var pda = provider.LoadPackageObject(
|
|
|
|
|
"Blitz/Content/Tanks/USA/A97_M41_Bulldog/PDA_A97_M41_Bulldog.PDA_A97_M41_Bulldog"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(pda);
|
2026-02-01 19:34:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] Files => files;
|
|
|
|
|
public string[] TanksDirectoryNations => tanksDirectoryNations;
|
|
|
|
|
|
|
|
|
|
public byte[] TankBigIcon(string tankId, string pdaName)
|
|
|
|
|
{
|
2026-02-01 21:05:38 -06:00
|
|
|
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");
|
2026-02-01 19:34:36 -06:00
|
|
|
}
|
2026-01-27 08:59:34 -06:00
|
|
|
}
|