Files
blitzkit/packages/game/src/classes/GameInterface.cs
T

88 lines
2.2 KiB
C#
Raw Normal View History

2026-02-01 21:05:38 -06:00
using System.Runtime.InteropServices;
using CUE4Parse.Compression;
2026-01-27 08:59:34 -06:00
using Microsoft.JavaScript.NodeApi;
namespace game.src.classes;
[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-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:24:20 -06:00
Directory.CreateDirectory("../../temp");
Console.WriteLine($"../..temp/oodle.{libraryExtension}");
var bool1 = OodleHelper.DownloadOodleDll($"../..temp/oodle.{libraryExtension}");
Console.WriteLine(bool1);
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
}