mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
feat: custom provider
This commit is contained in:
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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user