diff --git a/BanjoBotAssets/AssetExportService.cs b/BanjoBotAssets/AssetExportService.cs index f9f0735..510d776 100644 --- a/BanjoBotAssets/AssetExportService.cs +++ b/BanjoBotAssets/AssetExportService.cs @@ -26,6 +26,7 @@ using Microsoft.Extensions.Options; using System.Collections.Concurrent; using System.Diagnostics; +using System.Text.RegularExpressions; namespace BanjoBotAssets { @@ -198,7 +199,7 @@ private async Task LoadMappingsAsync(CancellationToken cancellationToken) { logger.LogInformation(Resources.Status_LoadingMappings); - if (provider.InternalGameName.Equals("FortniteGame", StringComparison.OrdinalIgnoreCase)) + if (provider.ProjectName.Equals("FortniteGame", StringComparison.OrdinalIgnoreCase)) { provider.MappingsContainer = typeMappingsProviderFactory.Create(); } @@ -351,6 +352,9 @@ private void OfferFileListToExporters() private void LoadLocalization(CancellationToken cancellationToken) { + //intended to be used to validate encryption keys, but now also prepares localisation dictionary (???) + provider.PostMount(); + logger.LogInformation(Resources.Status_LoadingLocalization, languageProvider.Language.ToString()); provider.LoadLocalization(languageProvider.Language, cancellationToken); } diff --git a/BanjoBotAssets/CachingFileProvider.cs b/BanjoBotAssets/CachingFileProvider.cs index 52f8672..381c145 100644 --- a/BanjoBotAssets/CachingFileProvider.cs +++ b/BanjoBotAssets/CachingFileProvider.cs @@ -98,13 +98,13 @@ private void WriteToAssetLog(string line) } } - public override Task LoadPackageAsync(GameFile file) + public override IPackage LoadPackage(GameFile file) { Interlocked.Increment(ref cacheRequests); - return cache.Cache.GetOrAddAsync( + return cache.Cache.GetOrAdd( file.Path, - async _ => + _ => { Interlocked.Increment(ref cacheMisses); @@ -112,12 +112,12 @@ public override Task LoadPackageAsync(GameFile file) logger.LogDebug(Resources.Status_CacheMiss, file.Path, file.Size); WriteToAssetLog(file.Path); - return await base.LoadPackageAsync(file); + return base.LoadPackage(file); }, new MemoryCacheEntryOptions { Size = file.Size }); } - public override Task TryLoadPackageAsync(GameFile file) + public override Task LoadPackageAsync(GameFile file) { Interlocked.Increment(ref cacheRequests); @@ -131,7 +131,7 @@ public override Task LoadPackageAsync(GameFile file) logger.LogDebug(Resources.Status_CacheMiss, file.Path, file.Size); WriteToAssetLog(file.Path); - return await base.TryLoadPackageAsync(file); + return await base.LoadPackageAsync(file); }, new MemoryCacheEntryOptions { Size = file.Size }); } diff --git a/BanjoBotAssets/Config/ServiceCollectionExtensions.AppConfig.cs b/BanjoBotAssets/Config/ServiceCollectionExtensions.AppConfig.cs index c0d49a4..9198af7 100644 --- a/BanjoBotAssets/Config/ServiceCollectionExtensions.AppConfig.cs +++ b/BanjoBotAssets/Config/ServiceCollectionExtensions.AppConfig.cs @@ -152,7 +152,7 @@ public static IServiceCollection AddGameFileProvider(this IServiceCollection ser directory: gameDirectory, searchOption: SearchOption.TopDirectoryOnly, isCaseInsensitive: true, - versions: new VersionContainer(EGame.GAME_UE5_4), + versions: new VersionContainer(EGame.GAME_UE5_6), assetLogPath: perfOptions.Value.AssetLogPath); provider.Initialize(); diff --git a/BanjoBotAssets/Exporters/BaseExporter.cs b/BanjoBotAssets/Exporters/BaseExporter.cs index c109ebd..7967949 100644 --- a/BanjoBotAssets/Exporters/BaseExporter.cs +++ b/BanjoBotAssets/Exporters/BaseExporter.cs @@ -56,7 +56,7 @@ public void CountAssetLoaded() var file = provider[path]; CountAssetLoaded(); - return await provider.LoadObjectAsync(file.PathWithoutExtension); + return await provider.SafeLoadPackageObjectAsync(file.PathWithoutExtension); } public abstract Task ExportAssetsAsync(IProgress progress, IAssetOutput output, CancellationToken cancellationToken); diff --git a/BanjoBotAssets/Exporters/DifficultyExporter.cs b/BanjoBotAssets/Exporters/DifficultyExporter.cs index ae1f550..2481154 100644 --- a/BanjoBotAssets/Exporters/DifficultyExporter.cs +++ b/BanjoBotAssets/Exporters/DifficultyExporter.cs @@ -32,7 +32,7 @@ public override async Task ExportAssetsAsync(IProgress progress, var file = provider[growthBoundsPath]; Interlocked.Increment(ref assetsLoaded); - var dataTable = await provider.LoadObjectAsync(file.PathWithoutExtension); + var dataTable = await provider.SafeLoadPackageObjectAsync(file.PathWithoutExtension); if (dataTable == null) { diff --git a/BanjoBotAssets/Exporters/ExpeditionCriteriaExporter.cs b/BanjoBotAssets/Exporters/ExpeditionCriteriaExporter.cs index b9059ca..306796d 100644 --- a/BanjoBotAssets/Exporters/ExpeditionCriteriaExporter.cs +++ b/BanjoBotAssets/Exporters/ExpeditionCriteriaExporter.cs @@ -17,7 +17,7 @@ public override async Task ExportAssetsAsync(IProgress progress, var file = provider[criteriaPath]; Interlocked.Increment(ref assetsLoaded); - var dataTable = await provider.LoadObjectAsync(file.PathWithoutExtension); + var dataTable = await provider.SafeLoadPackageObjectAsync(file.PathWithoutExtension); if (dataTable == null) { diff --git a/BanjoBotAssets/Exporters/Groups/GroupExporter.cs b/BanjoBotAssets/Exporters/Groups/GroupExporter.cs index 6b60060..390287d 100644 --- a/BanjoBotAssets/Exporters/Groups/GroupExporter.cs +++ b/BanjoBotAssets/Exporters/Groups/GroupExporter.cs @@ -128,7 +128,7 @@ await Parallel.ForEachAsync(assetsToProcess, opts, async (grouping, _) => Report(progress, file.PathWithoutExtension); - var asset = await provider.LoadObjectAsync(file.PathWithoutExtension); + var asset = await provider.SafeLoadPackageObjectAsync(file.PathWithoutExtension); if (asset == null) { diff --git a/BanjoBotAssets/Exporters/Groups/HeroExporter.cs b/BanjoBotAssets/Exporters/Groups/HeroExporter.cs index 56ec7b8..a0bace6 100644 --- a/BanjoBotAssets/Exporters/Groups/HeroExporter.cs +++ b/BanjoBotAssets/Exporters/Groups/HeroExporter.cs @@ -165,8 +165,8 @@ public override async Task ExportAssetsAsync(IProgress progress, { if (itemToQuestPath != null && questRewardsPath != null) { - var itemToQuestTask = provider.LoadObjectAsync(provider.Files[itemToQuestPath].PathWithoutExtension); - var questRewardsTask = provider.LoadObjectAsync(provider.Files[questRewardsPath].PathWithoutExtension); + var itemToQuestTask = provider.SafeLoadPackageObjectAsync(provider.Files[itemToQuestPath].PathWithoutExtension); + var questRewardsTask = provider.SafeLoadPackageObjectAsync(provider.Files[questRewardsPath].PathWithoutExtension); var itemToQuestTable = await itemToQuestTask; var questRewardsTable = await questRewardsTask; @@ -179,6 +179,9 @@ public override async Task ExportAssetsAsync(IProgress progress, private void InitHeroToTeamPerkMapping(UDataTable itemToQuestTable, UDataTable questRewardsTable) { + if (questRewardsTable is null) + return; + var questToTeamPerk = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (var entry in questRewardsTable.RowMap.Values) diff --git a/BanjoBotAssets/Exporters/Groups/SchematicExporter.cs b/BanjoBotAssets/Exporters/Groups/SchematicExporter.cs index bd1781c..a8feaae 100644 --- a/BanjoBotAssets/Exporters/Groups/SchematicExporter.cs +++ b/BanjoBotAssets/Exporters/Groups/SchematicExporter.cs @@ -195,7 +195,7 @@ public override async Task ExportAssetsAsync(IProgress progress, } var widOrTidFile = provider[widOrTidPath]; Interlocked.Increment(ref assetsLoaded); - return await provider.LoadObjectAsync(widOrTidFile.PathWithoutExtension); + return await provider.SafeLoadPackageObjectAsync(widOrTidFile.PathWithoutExtension); } protected override async Task ExtractCommonFieldsAsync(UObject asset, IGrouping grouping) @@ -347,7 +347,7 @@ private static (string category, string subType) CategoryAndSubTypeFromTags(FGam return await cachedAmmoTypesFromPaths.GetOrAdd(ammoDataPath.AssetPathName.Text, static async (path, provider) => { - var asset = await provider.LoadObjectAsync(path); + var asset = await provider.SafeLoadPackageObjectAsync(path); if (asset.ItemName?.Text is string str) { var i = str.IndexOf(':'); diff --git a/BanjoBotAssets/Exporters/ItemRatingExporter.cs b/BanjoBotAssets/Exporters/ItemRatingExporter.cs index 4ad2feb..db7a16c 100644 --- a/BanjoBotAssets/Exporters/ItemRatingExporter.cs +++ b/BanjoBotAssets/Exporters/ItemRatingExporter.cs @@ -47,7 +47,7 @@ private async Task ExportDefaultItemRatingsAsync(IAssetOutput output) var file = provider[baseItemRatingPath]; Interlocked.Increment(ref assetsLoaded); - var curveTable = await provider.LoadObjectAsync(file.PathWithoutExtension); + var curveTable = await provider.SafeLoadPackageObjectAsync(file.PathWithoutExtension); if (curveTable == null) { @@ -71,7 +71,7 @@ private async Task ExportSurvivorItemRatingsAsync(IAssetOutput output) var file = provider[survivorItemRatingPath]; Interlocked.Increment(ref assetsLoaded); - var curveTable = await provider.LoadObjectAsync(file.PathWithoutExtension); + var curveTable = await provider.SafeLoadPackageObjectAsync(file.PathWithoutExtension); if (curveTable == null) { diff --git a/BanjoBotAssets/Exporters/QuestMapExporter.cs b/BanjoBotAssets/Exporters/QuestMapExporter.cs index 0f6150f..d22ba4c 100644 --- a/BanjoBotAssets/Exporters/QuestMapExporter.cs +++ b/BanjoBotAssets/Exporters/QuestMapExporter.cs @@ -29,7 +29,7 @@ public override async Task ExportAssetsAsync(IProgress progress, var file = provider[assetPaths[0]]; Interlocked.Increment(ref assetsLoaded); - var mapData = await provider.LoadObjectAsync(file.PathWithoutExtension); + var mapData = await provider.SafeLoadPackageObjectAsync(file.PathWithoutExtension); cancellationToken.ThrowIfCancellationRequested(); diff --git a/BanjoBotAssets/Exporters/UObjects/AbilityExporter.cs b/BanjoBotAssets/Exporters/UObjects/AbilityExporter.cs index 17057af..70afb24 100644 --- a/BanjoBotAssets/Exporters/UObjects/AbilityExporter.cs +++ b/BanjoBotAssets/Exporters/UObjects/AbilityExporter.cs @@ -18,6 +18,7 @@ using BanjoBotAssets.UExports; using CUE4Parse.FN.Structs.GA; using CUE4Parse.UE4.Objects.Engine; +using CUE4Parse.Utilities; using System.Data; namespace BanjoBotAssets.Exporters.UObjects diff --git a/BanjoBotAssets/Exporters/UObjects/UObjectExporter.cs b/BanjoBotAssets/Exporters/UObjects/UObjectExporter.cs index cdcd3b7..550fc09 100644 --- a/BanjoBotAssets/Exporters/UObjects/UObjectExporter.cs +++ b/BanjoBotAssets/Exporters/UObjects/UObjectExporter.cs @@ -17,6 +17,7 @@ */ using CUE4Parse.FN.Enums.FortniteGame; using System.Collections.Concurrent; +using CUE4Parse.Utilities; namespace BanjoBotAssets.Exporters.UObjects { @@ -85,7 +86,16 @@ await Parallel.ForEachAsync(assetsToProcess, opts, async (path, _) => TAsset? uobject; if (IgnoreLoadFailures) { - var pkg = await provider.TryLoadPackageAsync(file); + IPackage? pkg = null; + + try + { + pkg = await provider.LoadPackageAsync(file); + } + catch + { + return; + } cancellationToken.ThrowIfCancellationRequested(); diff --git a/BanjoBotAssets/Exporters/VenturesSeasonExporter.cs b/BanjoBotAssets/Exporters/VenturesSeasonExporter.cs index c639677..b688b32 100644 --- a/BanjoBotAssets/Exporters/VenturesSeasonExporter.cs +++ b/BanjoBotAssets/Exporters/VenturesSeasonExporter.cs @@ -47,9 +47,9 @@ public override async Task ExportAssetsAsync(IProgress progress, return; } - var levelRewardsTask = provider.LoadObjectAsync(provider[levelRewardsPath].PathWithoutExtension); - var pastLevelRewardsTask = provider.LoadObjectAsync(provider[pastLevelRewardsPath].PathWithoutExtension); - var defaultGameDataTask = provider.LoadObjectAsync(provider[defaultGameDataPath].PathWithoutExtension); + var levelRewardsTask = provider.SafeLoadPackageObjectAsync(provider[levelRewardsPath].PathWithoutExtension); + var pastLevelRewardsTask = provider.SafeLoadPackageObjectAsync(provider[pastLevelRewardsPath].PathWithoutExtension); + var defaultGameDataTask = provider.SafeLoadPackageObjectAsync(provider[defaultGameDataPath].PathWithoutExtension); ExportLevelRewards(await levelRewardsTask, output, cancellationToken); ExportPastLevelRewards(await pastLevelRewardsTask, output, cancellationToken); diff --git a/BanjoBotAssets/PostExporters/ImageFilesPostExporter.cs b/BanjoBotAssets/PostExporters/ImageFilesPostExporter.cs index 34277f8..f0f36b3 100644 --- a/BanjoBotAssets/PostExporters/ImageFilesPostExporter.cs +++ b/BanjoBotAssets/PostExporters/ImageFilesPostExporter.cs @@ -18,6 +18,7 @@ using BanjoBotAssets.Config; using CUE4Parse.UE4.Assets.Exports.Texture; using CUE4Parse_Conversion.Textures; +using CUE4Parse_Conversion.Textures.BC; using Microsoft.Extensions.Options; namespace BanjoBotAssets.PostExporters @@ -44,6 +45,8 @@ public async Task ProcessExportsAsync(ExportedAssets exportedAssets, IList(imagePath); - using var bitmap = asset.Decode(); + var asset = await provider.SafeLoadPackageObjectAsync(imagePath); + var bitmap = asset?.Decode(); if (bitmap == null) { logger.LogError(Resources.Error_CannotDecodeTexture, imagePath); continue; } - await using var stream = new FileStream(exportedPath, FileMode.Create, FileAccess.Write); - if (!bitmap.Encode(stream, SkiaSharp.SKEncodedImageFormat.Png, 100)) + var bytes = bitmap.Encode(ETextureFormat.Png, out var ext); + if (ext != "png") { logger.LogError(Resources.Error_CannotEncodeTexture, imagePath); } + await using var stream = new FileStream(exportedPath, FileMode.Create, FileAccess.Write); + stream.Write(bytes, 0, bytes.Length); filesWritten++; } } diff --git a/external/CUE4Parse b/external/CUE4Parse index 0566f26..8bbcb3c 160000 --- a/external/CUE4Parse +++ b/external/CUE4Parse @@ -1 +1 @@ -Subproject commit 0566f26df1a8fab6e7980fc8dc498487953d9378 +Subproject commit 8bbcb3c1c8fcd0372f168d7c6c91cfa0d5fa21d1 diff --git a/external/CUE4Parse-FortniteTypes b/external/CUE4Parse-FortniteTypes index 424118b..93c7f33 160000 --- a/external/CUE4Parse-FortniteTypes +++ b/external/CUE4Parse-FortniteTypes @@ -1 +1 @@ -Subproject commit 424118b4072aaccf64dbb3f6e801860c5945b3a1 +Subproject commit 93c7f33ccb215b07e2dcd331cd9f0bf7ca4ecfde