style: declare types, add extra logging, cleanup

This commit is contained in:
2026-06-18 16:47:16 -03:00
parent 188ce7bdee
commit 902b8f6676
+17 -22
View File
@@ -2,6 +2,7 @@ using CUE4Parse.Compression;
using CUE4Parse.Encryption.Aes; using CUE4Parse.Encryption.Aes;
using CUE4Parse.FileProvider; using CUE4Parse.FileProvider;
using CUE4Parse.MappingsProvider.Usmap; using CUE4Parse.MappingsProvider.Usmap;
using CUE4Parse.UE4.Assets;
using CUE4Parse.UE4.Assets.Exports.Engine; using CUE4Parse.UE4.Assets.Exports.Engine;
using CUE4Parse.UE4.Assets.Exports.Texture; using CUE4Parse.UE4.Assets.Exports.Texture;
using CUE4Parse.UE4.Assets.Objects; using CUE4Parse.UE4.Assets.Objects;
@@ -64,10 +65,10 @@ class Dumper
/* /*
* game path * game path
*/ */
var gamePath = Utils.GetGamePath(); string? gamePath = Utils.GetGamePath();
if (gamePath == null) return false; if (gamePath == null) return false;
var pakDir = Path.Combine(gamePath, "DeadByDaylight", "Content", "Paks"); string pakDir = Path.Combine(gamePath, "DeadByDaylight", "Content", "Paks");
if (!Directory.Exists(pakDir)) if (!Directory.Exists(pakDir))
{ {
Console.WriteLine("PAK dir does not exist. (Invalid install?)"); Console.WriteLine("PAK dir does not exist. (Invalid install?)");
@@ -77,7 +78,7 @@ class Dumper
/* /*
* file provider * file provider
*/ */
var version = new VersionContainer(EGame.GAME_DeadByDaylight, ETexturePlatform.DesktopMobile); VersionContainer? version = new VersionContainer(EGame.GAME_DeadByDaylight, ETexturePlatform.DesktopMobile);
_provider = new DefaultFileProvider(pakDir, SearchOption.TopDirectoryOnly, version) _provider = new DefaultFileProvider(pakDir, SearchOption.TopDirectoryOnly, version)
{ {
MappingsContainer = new FileUsmapTypeMappingsProvider(mappingPath) MappingsContainer = new FileUsmapTypeMappingsProvider(mappingPath)
@@ -88,12 +89,6 @@ class Dumper
_provider.Mount(); _provider.Mount();
_provider.PostMount(); _provider.PostMount();
if (!_provider.TryGetArchive("pakchunk3-WinGDK.utoc", out _iconPak)) // icons
{
Console.WriteLine("Failed to load pakchunk3-WinGDK.utoc");
return false;
}
if (!_provider.TryGetArchive("pakchunk4-WinGDK.utoc", out _dataPak)) // data if (!_provider.TryGetArchive("pakchunk4-WinGDK.utoc", out _dataPak)) // data
{ {
Console.WriteLine("Failed to load pakchunk4-WinGDK.utoc"); Console.WriteLine("Failed to load pakchunk4-WinGDK.utoc");
@@ -119,13 +114,13 @@ class Dumper
foreach (string path in charDbPaths) foreach (string path in charDbPaths)
{ {
var cleanPath = path.Contains('.') ? path[..path.LastIndexOf('.')] : path; string cleanPath = path.Contains('.') ? path[..path.LastIndexOf('.')] : path;
if (_provider.TryLoadPackageObject<UDataTable>(cleanPath, out var dataTable)) if (_provider.TryLoadPackageObject<UDataTable>(cleanPath, out UDataTable? dataTable))
{ {
foreach (var row in dataTable.RowMap) foreach (KeyValuePair<FName, FStructFallback> row in dataTable.RowMap)
{ {
var props = row.Value.Properties; List<FPropertyTag> props = row.Value.Properties;
/* /*
* props * props
@@ -174,10 +169,10 @@ class Dumper
*/ */
private bool TryGetProp<T>(IEnumerable<FPropertyTag> properties, string propName, out T value) private bool TryGetProp<T>(IEnumerable<FPropertyTag> properties, string propName, out T value)
{ {
var prop = properties.FirstOrDefault(p => p.Name.Text == propName); FPropertyTag? prop = properties.FirstOrDefault(p => p.Name.Text == propName);
if (prop?.Tag != null) if (prop?.Tag != null)
{ {
var val = prop.Tag.GetValue<T>(); T? val = prop.Tag.GetValue<T>();
if (val != null) if (val != null)
{ {
value = val; value = val;
@@ -190,7 +185,7 @@ class Dumper
} }
private bool TryGetStringProp<T>(IEnumerable<FPropertyTag> properties, string propName, out string value) private bool TryGetStringProp<T>(IEnumerable<FPropertyTag> properties, string propName, out string value)
{ {
if (TryGetProp<T>(properties, propName, out var rawValue) && rawValue != null) if (TryGetProp<T>(properties, propName, out T? rawValue) && rawValue != null)
{ {
string? strVal = rawValue.ToString(); string? strVal = rawValue.ToString();
@@ -227,28 +222,28 @@ class Dumper
if (_provider == null) return; if (_provider == null) return;
if (_provider.TryLoadPackage(cleanPath, out var package)) if (_provider.TryLoadPackage(cleanPath, out IPackage? package))
{ {
var texture = package.GetExports().OfType<UTexture2D>().FirstOrDefault(); UTexture2D? texture = package.GetExports().OfType<UTexture2D>().FirstOrDefault();
if (texture != null) if (texture != null)
{ {
var bitmap = texture.Decode(ETexturePlatform.DesktopMobile); CTexture? bitmap = texture.Decode(ETexturePlatform.DesktopMobile);
if (bitmap != null) if (bitmap != null)
{ {
var bytes = bitmap.Encode(ETextureFormat.Png, false, out _); byte[] bytes = bitmap.Encode(ETextureFormat.Png, false, out _);
string? parentFolder = Path.GetDirectoryName(fullPath); string? parentFolder = Path.GetDirectoryName(fullPath);
if (!string.IsNullOrEmpty(parentFolder)) if (!string.IsNullOrEmpty(parentFolder))
Directory.CreateDirectory(parentFolder); Directory.CreateDirectory(parentFolder);
File.WriteAllBytes(fullPath, bytes); File.WriteAllBytes(fullPath, bytes);
Console.WriteLine($"Exported icon: {fileName}"); _log.Verbose("Exported icon: {0}", fileName);
} }
} }
else else
Console.WriteLine($"Failed to find a UTexture2D export in package: {cleanPath}"); throw new FileNotFoundException("Failed to find texture");
} }
} }
} }