2026-02-02 19:04:54 -06:00
|
|
|
using System.Runtime.InteropServices;
|
2026-05-24 12:42:08 -05:00
|
|
|
using CUE4Parse_Conversion.Textures;
|
2026-02-02 19:04:54 -06:00
|
|
|
using CUE4Parse.Compression;
|
2026-02-02 18:07:20 -06:00
|
|
|
using CUE4Parse.FileProvider;
|
2026-02-02 17:08:37 -06:00
|
|
|
using CUE4Parse.MappingsProvider;
|
2026-05-24 12:42:08 -05:00
|
|
|
using CUE4Parse.UE4.Assets.Exports.Texture;
|
2026-05-23 13:18:09 -05:00
|
|
|
using CUE4Parse.UE4.Exceptions;
|
2026-05-24 12:42:08 -05:00
|
|
|
using CUE4Parse.UE4.Objects.Engine;
|
|
|
|
|
using CUE4Parse.UE4.Objects.UObject;
|
2026-02-02 17:08:37 -06:00
|
|
|
using CUE4Parse.UE4.Versions;
|
2026-05-23 13:18:09 -05:00
|
|
|
using CUE4Parse.Utils;
|
2026-05-24 12:42:08 -05:00
|
|
|
using SkiaSharp;
|
2026-05-27 20:54:48 -05:00
|
|
|
using CUE4Parse.UE4.Readers;
|
|
|
|
|
using CUE4Parse.UE4.AssetRegistry;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using CUE4Parse.UE4.Assets.Exports;
|
2026-02-02 17:08:37 -06:00
|
|
|
|
2026-02-02 17:28:24 -06:00
|
|
|
namespace BlitzKit.Game.Models;
|
2026-02-02 17:08:37 -06:00
|
|
|
|
2026-05-27 20:54:48 -05:00
|
|
|
public partial class BlitzFileProvider : DefaultFileProvider
|
2026-02-02 17:08:37 -06:00
|
|
|
{
|
2026-05-27 20:54:48 -05:00
|
|
|
[GeneratedRegex(@"\(GameplayTags=\(\(TagName=""(.+)""\)\)\)")]
|
|
|
|
|
private static partial Regex GameplayTagsRegex();
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<string, string> discovered = [];
|
|
|
|
|
|
|
|
|
|
public BlitzFileProvider(string directory, string map, string temp)
|
2026-02-02 17:08:37 -06:00
|
|
|
: base(
|
|
|
|
|
directory: directory,
|
|
|
|
|
searchOption: SearchOption.AllDirectories,
|
|
|
|
|
versions: new(EGame.GAME_UE5_5),
|
|
|
|
|
pathComparer: StringComparer.OrdinalIgnoreCase
|
|
|
|
|
)
|
|
|
|
|
{
|
2026-06-10 13:43:09 -05:00
|
|
|
Console.WriteLine("BlitzFileProvider constructor called");
|
|
|
|
|
|
2026-05-22 13:51:30 -05:00
|
|
|
MappingsContainer = new FileUsmapTypeMappingsProvider(map);
|
2026-02-02 19:04:54 -06:00
|
|
|
|
2026-06-10 13:43:09 -05:00
|
|
|
Console.WriteLine("MappingsContainer initialized");
|
|
|
|
|
|
2026-02-02 19:04:54 -06:00
|
|
|
Initialize();
|
2026-06-10 13:43:09 -05:00
|
|
|
|
|
|
|
|
Console.WriteLine("Initialize called");
|
|
|
|
|
|
2026-02-02 19:04:54 -06:00
|
|
|
Mount();
|
2026-05-27 20:54:48 -05:00
|
|
|
|
2026-06-10 13:43:09 -05:00
|
|
|
Console.WriteLine("Mount called");
|
|
|
|
|
|
2026-05-27 20:54:48 -05:00
|
|
|
string oodlePath = $"{temp}/oodle.so";
|
2026-06-10 13:50:13 -05:00
|
|
|
// OodleHelper.DownloadOodleDll(ref oodlePath!);
|
|
|
|
|
// Console.WriteLine("DownloadOodleDll called");
|
2026-06-10 13:43:09 -05:00
|
|
|
|
2026-06-10 13:50:13 -05:00
|
|
|
OodleHelper.Initialize("../../stupid/oodle.so");
|
2026-05-27 20:54:48 -05:00
|
|
|
|
2026-06-10 13:43:09 -05:00
|
|
|
Console.WriteLine("Initialize called");
|
|
|
|
|
|
2026-05-27 20:54:48 -05:00
|
|
|
if (TryGetGameFile("Blitz/AssetRegistry.bin", out var file))
|
|
|
|
|
{
|
|
|
|
|
var bytes = file.Read();
|
|
|
|
|
var archive = new FByteArchive(file.Path, bytes, Versions);
|
|
|
|
|
var state = new FAssetRegistryState(archive);
|
|
|
|
|
|
|
|
|
|
foreach (var asset in state.PreallocatedAssetDataBuffers)
|
|
|
|
|
{
|
|
|
|
|
if (asset.TagsAndValues.TryGetValue("DiscoveryTags", out var tags))
|
|
|
|
|
{
|
|
|
|
|
var match = GameplayTagsRegex().Match(tags);
|
|
|
|
|
|
|
|
|
|
if (!match.Success)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tag = match.Groups[1].Value;
|
|
|
|
|
discovered[tag] = asset.ObjectPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public T Discovered<T>(string path) where T : UObject
|
|
|
|
|
{
|
|
|
|
|
return LoadPackageObject<T>(discovered[path]);
|
2026-02-02 17:08:37 -06:00
|
|
|
}
|
2026-05-24 12:42:08 -05:00
|
|
|
|
|
|
|
|
public UPrimaryDataAsset PDA(string path)
|
|
|
|
|
{
|
|
|
|
|
var name = Path.GetFileNameWithoutExtension(path);
|
|
|
|
|
var combined = $"{path}.{name}";
|
|
|
|
|
return LoadPackageObject<UPrimaryDataAsset>(combined);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] Image(FSoftObjectPath path)
|
|
|
|
|
{
|
|
|
|
|
var uTexture = path.Load<UTexture2D>();
|
|
|
|
|
return Image(uTexture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly SKEncodedImageFormat imageFormat = SKEncodedImageFormat.Webp;
|
|
|
|
|
private readonly int imageQuality = 80;
|
|
|
|
|
|
|
|
|
|
public byte[] Image(UTexture2D uTexture)
|
|
|
|
|
{
|
|
|
|
|
var cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
|
|
|
|
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(cTexture);
|
|
|
|
|
|
|
|
|
|
var bitmap = cTexture.ToSkBitmap();
|
|
|
|
|
var data = bitmap.Encode(imageFormat, imageQuality);
|
|
|
|
|
|
|
|
|
|
return data.ToArray();
|
|
|
|
|
}
|
2026-02-02 17:08:37 -06:00
|
|
|
}
|