2026-02-02 19:04:54 -06:00
|
|
|
using System.Runtime.InteropServices;
|
2026-06-10 20:12:18 -05:00
|
|
|
using System.Text.RegularExpressions;
|
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-06-10 20:12:18 -05:00
|
|
|
using CUE4Parse.UE4.AssetRegistry;
|
|
|
|
|
using CUE4Parse.UE4.Assets.Exports;
|
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-06-10 20:12:18 -05:00
|
|
|
using CUE4Parse.UE4.Readers;
|
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-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-06-12 20:59:43 -05:00
|
|
|
public enum ImagePostProcess
|
|
|
|
|
{
|
|
|
|
|
None,
|
|
|
|
|
RMAO,
|
|
|
|
|
}
|
|
|
|
|
|
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-05-22 13:51:30 -05:00
|
|
|
MappingsContainer = new FileUsmapTypeMappingsProvider(map);
|
2026-02-02 19:04:54 -06:00
|
|
|
|
|
|
|
|
Initialize();
|
|
|
|
|
Mount();
|
2026-05-27 20:54:48 -05:00
|
|
|
|
2026-06-10 20:12:18 -05:00
|
|
|
// string oodlePath = $"{temp}/oodle.so";
|
2026-06-10 13:50:13 -05:00
|
|
|
// OodleHelper.DownloadOodleDll(ref oodlePath!);
|
|
|
|
|
OodleHelper.Initialize("../../stupid/oodle.so");
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-10 20:12:18 -05:00
|
|
|
public T Discovered<T>(string path)
|
|
|
|
|
where T : UObject
|
2026-05-27 20:54:48 -05:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2026-06-12 20:59:43 -05:00
|
|
|
public byte[] Image(UTexture2D uTexture, ImagePostProcess postProcess = ImagePostProcess.None)
|
2026-05-24 12:42:08 -05:00
|
|
|
{
|
|
|
|
|
var cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
|
|
|
|
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(cTexture);
|
|
|
|
|
|
|
|
|
|
var bitmap = cTexture.ToSkBitmap();
|
2026-06-12 20:59:43 -05:00
|
|
|
|
|
|
|
|
return Image(bitmap, postProcess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private byte[] Image(SKBitmap bitmap, ImagePostProcess postProcess)
|
|
|
|
|
{
|
|
|
|
|
if (postProcess != ImagePostProcess.None)
|
|
|
|
|
{
|
|
|
|
|
for (int y = 0; y < bitmap.Height; y++)
|
|
|
|
|
{
|
|
|
|
|
for (int x = 0; x < bitmap.Width; x++)
|
|
|
|
|
{
|
|
|
|
|
var color = bitmap.GetPixel(x, y);
|
|
|
|
|
|
|
|
|
|
switch (postProcess)
|
|
|
|
|
{
|
|
|
|
|
case ImagePostProcess.RMAO:
|
|
|
|
|
bitmap.SetPixel(x, y, new SKColor(color.Blue, color.Red, color.Green, color.Alpha));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 12:42:08 -05:00
|
|
|
var data = bitmap.Encode(imageFormat, imageQuality);
|
|
|
|
|
|
|
|
|
|
return data.ToArray();
|
|
|
|
|
}
|
2026-02-02 17:08:37 -06:00
|
|
|
}
|