### Examples Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Examples of initializing DefaultFileProvider. ```csharp // Basic setup for UE4.27 var provider = new DefaultFileProvider( @"C:\Games\GameTitle", SearchOption.TopDirectoryOnly, new VersionContainer(EGame.GAME_UE4_27)); provider.Initialize(); // Case-insensitive paths var provider = new DefaultFileProvider( gameDir, SearchOption.AllDirectories, new VersionContainer(EGame.GAME_UE5_0), StringComparer.OrdinalIgnoreCase); // Multiple search directories var extraDirs = new[] { new DirectoryInfo(@"C:\Games\DLC1"), new DirectoryInfo(@"C:\Games\DLC2") }; var provider = new DefaultFileProvider( new DirectoryInfo(@"C:\Games\MainGame"), extraDirs, SearchOption.AllDirectories, new VersionContainer(EGame.GAME_FORTNITE), StringComparer.Ordinal); provider.Initialize(); ``` -------------------------------- ### Globals Configuration Examples Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Examples of modifying global settings. ```csharp // Suppress VFS mount logging Globals.LogVfsMounts = false; // Enable strict error handling Globals.FatalObjectSerializationErrors = true; ``` -------------------------------- ### TypeMappings Loading Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Example of loading TypeMappings. ```csharp var mappings = provider.MappingsContainer?.GetMappings(provider.Game); if (mappings != null) { // Properties can be parsed without version headers } ``` -------------------------------- ### UE4 Game Setup Configuration Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Provides an example of configuring `DefaultFileProvider` for a UE4 game, specifying the game version, platform, and search options, and enabling script data reading and lazy package serialization. ```csharp var versions = new VersionContainer( game: EGame.GAME_UE4_27, platform: ETexturePlatform.DesktopMobile, ver: default, customVersions: null); var provider = new DefaultFileProvider( gameDirectory: @"C:\Games\MyGame", searchOption: SearchOption.TopDirectoryOnly, versions: versions, pathComparer: StringComparer.Ordinal); provider.ReadScriptData = true; provider.UseLazyPackageSerialization = true; provider.Initialize(); ``` -------------------------------- ### Example Usage of Localization Methods Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/file-providers.md Example of loading localization and getting a translated string. ```csharp provider.LoadLocalization(ELanguage.English); var dialogText = provider.GetLocalizedString("Dialogue", "NPC_Welcome", "Hello"); ``` -------------------------------- ### FPackageFileVersion Example (UE5.1) Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Example of setting an explicit UE5.1 version. ```csharp // Set UE5.1 version var version5 = new FPackageFileVersion { FileVersionUE4 = 0, FileVersionUE5 = 1 }; ``` -------------------------------- ### Get/Set Version Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Example of setting game and version properties. ```csharp var versions = new VersionContainer(EGame.GAME_UE4_27); versions.Game = EGame.GAME_UE5_0; // Updates options automatically versions.Ver = new FPackageFileVersion { FileVersionUE4 = 522 }; ``` -------------------------------- ### FPackageFileVersion Example (UE4.27) Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Example of setting an explicit UE4.27 version. ```csharp // Set explicit UE4.27 version (522) var version = new FPackageFileVersion { FileVersionUE4 = 522, FileVersionUE5 = 0 }; ``` -------------------------------- ### Property Access Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/packages-objects.md An example demonstrating how to access texture properties like dimensions and format using the Get and GetOrDefault methods. ```csharp var texture = uobject as UTexture2D; if (texture != null) { var width = texture.Get("ImportedSize").X; // FIntPoint property var format = texture.GetOrDefault("Format", EPixelFormat.PF_Unknown); } ``` -------------------------------- ### Example Usage of DefaultFileProvider and Initialize Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/file-providers.md Example of creating and initializing a DefaultFileProvider. ```csharp var provider = new DefaultFileProvider( @"C:\\Games\\UnrealGame", SearchOption.TopDirectoryOnly, new VersionContainer(EGame.GAME_UE4_27)); provider.Initialize(); // Scans and registers all files ``` -------------------------------- ### Version Querying Examples Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Helper extensions for version checks. ```csharp // Get version for a specific game var version = EGame.GAME_UE4_27.GetVersion(); // Get default supported version var uassetVersion = EGame.GAME_UE4_27.GetUassetVersion(); // Parse version from enum var versionInfo = VersionUtils.ParseVersion(EGame.GAME_UE5_1); ``` -------------------------------- ### Option Access Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Example of accessing and setting version-specific options. ```csharp if (versions["StaticMesh.UseNewCookedFormat"]) { // Use UE4.23+ mesh deserialization } versions["CustomOption"] = true; // Set custom option ``` -------------------------------- ### FCustomVersionContainer Usage Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Example demonstrating how to retrieve custom version information. ```csharp var customVersions = package.Summary.CustomVersions; if (customVersions.TryGetVersion(FPhysicsObjectVersion.GUID, out var physicsVer)) { Console.WriteLine($"Physics version: {physicsVer}"); } ``` -------------------------------- ### Runtime Installation Source: https://github.com/fabianfg/cue4parse/blob/master/CUE4Parse-Natives/CMakeLists.txt Installs the built target to Debug and Release runtime directories. ```cmake install(TARGETS CUE4Parse-Natives CONFIGURATIONS Debug RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/bin/Debug/") install(TARGETS CUE4Parse-Natives CONFIGURATIONS Release RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/bin/Release/") ``` -------------------------------- ### Texture Platform Examples Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Illustrates creating VersionContainer instances for various texture platforms. ```csharp // Desktop/PC new VersionContainer(EGame.GAME_UE4_27, ETexturePlatform.Desktop); // Mobile (Android, iOS) new VersionContainer(EGame.GAME_UE4_27, ETexturePlatform.Mobile); // Platform-specific Android new VersionContainer(EGame.GAME_UE4_27, ETexturePlatform.Android); // Console (PlayStation, Xbox) new VersionContainer(EGame.GAME_UE5_0, ETexturePlatform.Console); ``` -------------------------------- ### ObjectVersion Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Example of checking the rendering object version. ```csharp if (FRenderingObjectVersion.Get(Ar) >= FRenderingObjectVersion.Type.RemovedMaterialShaderQualityOverrides) { // Use new rendering feature } ``` -------------------------------- ### Export Access Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/packages-objects.md Example of using IPackage.GetExportOrNull and IPackage.GetExport. ```csharp // Using TryLoad pattern var texture = package.GetExportOrNull("MainTexture"); // Using index access var export = package.GetExport(0); ``` -------------------------------- ### Usage Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Examples of how to modify global settings. ```csharp // Suppress verbose logging Globals.LogVfsMounts = false; // Enable strict error handling Globals.FatalObjectSerializationErrors = true; // Suppress import resolution warnings Globals.WarnMissingImportPackage = false; ``` -------------------------------- ### FGuid Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/readers.md Example of reading and printing an FGuid. ```csharp var guid = reader.Read(); Console.WriteLine(guid); // Output: 12345678-90ABCDEF-... ``` -------------------------------- ### FName Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/readers.md Example of reading and checking an FName. ```csharp var name = reader.ReadFName(); if (!name.IsNone) { Console.WriteLine(name); // "ActorName_2" } ``` -------------------------------- ### Clone the Repository Source: https://github.com/fabianfg/cue4parse/wiki/Installing-CUE4Parse This command clones the CUE4Parse repository from GitHub, including submodules, for manual installation. ```shell git clone https://github.com/FabianFG/CUE4Parse.git --recursive ``` -------------------------------- ### ETexturePlatform Usage Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Example demonstrating how to use ETexturePlatform for texture decoding. ```csharp var versions = new VersionContainer(EGame.GAME_UE4_27, ETexturePlatform.Android); var texture = provider.LoadPackageObject("MyTexture.uasset"); var decoded = texture.Decode(ETexturePlatform.Mobile); // Mobile format ``` -------------------------------- ### Example Usage of FixPath Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/file-providers.md Example of normalizing a file path. ```csharp var normalized = provider.FixPath("Content\\Maps\\MyMap.umap"); // Returns: "Content/Maps/MyMap.umap" ``` -------------------------------- ### Version Comparison Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Examples of comparing EGame enum values for conditional logic. ```csharp if (game >= EGame.GAME_UE4_25) { // Apply UE4.25+ logic } if (game < EGame.GAME_UE5_0) { // UE4-only code } if (game >= EGame.GAME_UE5_0) { // UE5+ specific handling } // Game-specific branching if (game == EGame.GAME_DeadIsland2) { // Dead Island 2 specific workarounds } ``` -------------------------------- ### EUnrealEngineObjectUE4Version Usage Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Example showing how to check for specific feature availability using EUnrealEngineObjectUE4Version. ```csharp if (Ar.Ver >= EUnrealEngineObjectUE4Version.ADD_COOKED_TO_TEXTURE2D) { // Texture cooked data is present var bCooked = Ar.ReadBoolean(); } ``` -------------------------------- ### Oodle Configuration Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/compression-encryption.md Shows how to set the OODLE_PATH environment variable if the Oodle library is not in a default location. ```csharp // Oodle library path (if custom) Environment.SetEnvironmentVariable("OODLE_PATH", @"C:\path\to\oodle.dll"); ``` -------------------------------- ### TArray Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/types.md Example of reading a TArray of FName. ```csharp var array = Ar.ReadArray(() => new FName(Ar)); ``` -------------------------------- ### Install via NuGet Package Source: https://github.com/fabianfg/cue4parse/wiki/Installing-CUE4Parse This command adds the CUE4Parse NuGet package to your .NET project. ```shell dotnet add package CUE4Parse ``` -------------------------------- ### TMap Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/types.md Example of reading a TMap with key-value pairs. ```csharp var count = Ar.Read(); var map = new Dictionary(count); for (int i = 0; i < count; i++) { var key = Ar.Read(); var value = Ar.Read(); map[key] = value; } ``` -------------------------------- ### Option Override Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Demonstrates how to set specific deserialization options for different Unreal Engine versions. ```csharp var options = new Dictionary { { "StaticMesh.UseNewCookedFormat", true }, { "VirtualTextures", false }, // Force disable despite UE4.23+ { "MyCustomOption", true } }; var versions = new VersionContainer( EGame.GAME_UE4_27, ETexturePlatform.DesktopMobile, default, null, options); ``` -------------------------------- ### MSVC Debug PDB Installation Source: https://github.com/fabianfg/cue4parse/blob/master/CUE4Parse-Natives/CMakeLists.txt Installs the PDB file for MSVC builds in the Debug directory. ```cmake if (MSVC) install(FILES $ DESTINATION "${PROJECT_SOURCE_DIR}/bin/Debug/" OPTIONAL) endif() ``` -------------------------------- ### DefaultFileProvider Example 2 Source: https://github.com/fabianfg/cue4parse/wiki/File-Providers Instantiates a DefaultFileProvider specifying multiple directories, including those in %localappdata%. ```csharp var provider = new DefaultFileProvider( directory: new DirectoryInfo("D:\\Games\\PC\\XXXXXXX\\XXXXXXX\\Content\\Paks"), extraDirectories: new DirectoryInfo[] { new(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\XXXXXXX\\Saved\\Paks"), new(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\XXXXXXX\\Saved\\DisabledPaks") }, searchOption: SearchOption.TopDirectoryOnly, isCaseInsensitive: true, versions: new VersionContainer(EGame.GAME_UE4_LATEST)); ``` -------------------------------- ### ParserException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Demonstrates catching a ParserException during package loading. ```csharp public class ParserException : Exception { public ParserException(string message); public ParserException(FArchive Ar, string message); public ParserException(string message, Exception? innerException); } ``` ```csharp try { var package = provider.LoadPackage("Content/MyAsset.uasset"); } catch (ParserException ex) { Console.WriteLine($"Parse error: {ex.Message}"); } ``` -------------------------------- ### KeyNotFoundException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Compares avoiding KeyNotFoundException with the preferred TryGetGameFile method. ```csharp // Avoid: try { var obj = package.GetExport("NonExistent"); } catch (KeyNotFoundException) { } // Prefer: if (package.TryLoadPackageObject("NonExistent.uasset", out var obj)) { // Use obj } ``` -------------------------------- ### Zlib/Deflate Decompression Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/compression-encryption.md Example of decompressing data that is assumed to be zlib-compressed. ```csharp var compressedData = gameFile.Read(); // Decompressed automatically if zlib-compressed var decompressed = ZlibDecompress(compressedData); ``` -------------------------------- ### Type Safety Examples Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/types.md Examples demonstrating type-safe property access, generic package object loading, and type-checked export iteration. ```csharp // Safe property access var width = texture.GetOrDefault("ImportedSize"); // Generic package object loading var mesh = provider.LoadPackageObject("Content/Meshes/Mesh.uasset"); // Type-checked export iteration foreach (var export in package.GetExports().OfType()) { var decoded = export.Decode(ETexturePlatform.Mobile); } ``` -------------------------------- ### ApkFileProvider Example Source: https://github.com/fabianfg/cue4parse/wiki/File-Providers Instantiates an ApkFileProvider for parsing APK files and retrieving archives within them. ```csharp var provider = new ApkFileProvider( file: "D:\\Games\\Android\\XXXXXXX.apk", isCaseInsensitive: true, versions: new VersionContainer(EGame.GAME_UE4_LATEST)); ``` -------------------------------- ### FPropertyTag Example Access Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/types.md Example of accessing property values from an FPropertyTag. ```csharp foreach (var prop in uobject.Properties) { var value = prop.Tag?.GetValue(typeof(int)); } ``` -------------------------------- ### UnknownPropertyException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Definition and recovery strategy for UnknownPropertyException. ```csharp public class UnknownPropertyException : ParserException { public UnknownPropertyException(string propertyType, uint arrayDim); } ``` ```csharp // Check Globals.FatalObjectSerializationErrors Globals.FatalObjectSerializationErrors = false; // Skip unknown properties ``` -------------------------------- ### DirectoryNotFoundException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Demonstrates catching DirectoryNotFoundException when the game directory does not exist. ```csharp try { var provider = new DefaultFileProvider(@"C:\Invalid\Path", SearchOption.TopDirectoryOnly); provider.Initialize(); } catch (DirectoryNotFoundException) { Console.WriteLine("Game directory not found"); } ``` -------------------------------- ### Structured Logging Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Demonstrates how to use structured logging with `Log.Error` to capture detailed context when parsing a package fails. ```csharp try { var package = provider.LoadPackage("Asset.uasset"); } catch (ParserException ex) { Log.Error(ex, "Failed to parse package: {Package}, Game: {Game}, Error: {Error}", "Asset.uasset", provider.Versions.Game, ex.Message); } catch (Exception ex) { Log.Fatal(ex, "Unexpected error"); } ``` -------------------------------- ### Manual Compression (Advanced) Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Example of creating a reader for a file and reading compressed data, with automatic decompression handled by the GameFile implementation. ```csharp var compressedReader = file.CreateReader(); // Decompression is handled automatically by GameFile implementation var data = compressedReader.ReadBytes(1024); ``` -------------------------------- ### FileNotFoundException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Demonstrates catching FileNotFoundException when a file is not found in the file provider. ```csharp try { var file = provider["NonExistent/File.uasset"]; } catch (FileNotFoundException) { Console.WriteLine("File not in file provider"); } ``` -------------------------------- ### Iterative Decompression Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/compression-encryption.md Demonstrates how to iteratively decompress large compressed assets block by block. ```csharp var reader = gameFile.CreateReader(); while (reader.Position < reader.Length) { var compressedSize = reader.Read(); var uncompressedSize = reader.Read(); var block = reader.ReadBytes((int)compressedSize); var decompressed = DecompressBlock(block, (int)uncompressedSize); ProcessBlock(decompressed); } ``` -------------------------------- ### DefaultFileProvider Example 1 Source: https://github.com/fabianfg/cue4parse/wiki/File-Providers Instantiates a DefaultFileProvider for accessing archives within a local directory. ```csharp var provider = new DefaultFileProvider( directory: "D:\\Games\\PC\\XXXXXXX\\XXXXXXX\\Content\\Paks", searchOption: SearchOption.TopDirectoryOnly, isCaseInsensitive: true, versions: new VersionContainer(EGame.GAME_UE4_LATEST)); ``` -------------------------------- ### Automatic Decompression Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/compression-encryption.md Demonstrates how CUE4Parse automatically detects and decompresses data. ```csharp var gameFile = provider["Content/Data/Compressed.uasset"]; // CompressionMethod is detected automatically if (gameFile.CompressionMethod != CompressionMethod.None) { var reader = gameFile.CreateReader(); // Auto-decompresses var data = reader.ReadBytes(256); } ``` -------------------------------- ### Custom Game with Overrides Configuration Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md An example of configuring `DefaultFileProvider` for a custom game, allowing for custom version settings and specific feature overrides for build formats and game-specific features. ```csharp var customVersions = new FCustomVersionContainer(); customVersions.SetVersion(FPhysicsObjectVersion.GUID, 42); var options = new Dictionary { { "StaticMesh.UseNewCookedFormat", false }, // Force old format { "CustomFeature", true } // Game-specific }; var versions = new VersionContainer( game: EGame.GAME_UE4_LATEST, platform: ETexturePlatform.Desktop, ver: new FPackageFileVersion { FileVersionUE4 = 500 }, customVersions: customVersions, optionOverrides: options); var provider = new DefaultFileProvider(gameDir, SearchOption.AllDirectories, versions); provider.Initialize(); ``` -------------------------------- ### Troubleshooting Decompressor Not Available Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/compression-encryption.md Example of checking for Oodle library availability before use. ```csharp // Check if Oodle available before use try { var decompressed = OodleDecompress(data); } catch (DllNotFoundException) { Log.Warning("Oodle library not available, skipping"); } ``` -------------------------------- ### Configure Version Options Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/INDEX.md Example of configuring version options, including overriding specific settings, for a VersionContainer. ```csharp var options = new Dictionary { { "StaticMesh.UseNewCookedFormat", true } }; var versions = new VersionContainer(EGame.GAME_UE4_27, optionOverrides: options); ``` -------------------------------- ### TextureDecodingException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Shows how to catch exceptions during texture decoding operations. ```csharp try { var bitmap = texture.Decode(ETexturePlatform.Mobile); } catch (Exception ex) { Console.WriteLine($"Decode failed: {ex.Message}"); } ``` -------------------------------- ### Basic Usage Example Source: https://github.com/fabianfg/cue4parse/blob/master/README.md Demonstrates how to initialize the file provider, load objects, serialize them to JSON, and handle different object types like textures, sounds, and meshes. ```csharp var provider = new DefaultFileProvider(ARCHIVE_DIRECTORY_HERE, SearchOption.TopDirectoryOnly, true, new VersionContainer(EGame.GAME_UE4_27)); provider.Initialize(); // will scan the archive directory for supported file extensions var allObjects = provider.LoadAllObjects(PACKAGE_PATH_HERE); // {GAME}/Content/Folder1/Folder2/PackageName.uasset var fullJson = JsonConvert.SerializeObject(allExports, Formatting.Indented); var obj = provider.LoadObject(OBJECT_PATH_HERE); // {GAME}/Content/Folder1/Folder2/PackageName.ObjectName var objJson = JsonConvert.SerializeObject(objectExport, Formatting.Indented); switch (obj) { case UTexture2D texture: { var bitmap = texture.Decode(ETexturePlatform.DesktopMobile); ... } case USoundWave: { objectExport.Decode(true, out var audioFormat, out var data); ... } case UStaticMesh: case USkeletalMesh: case UAnimSequence: { var toSave = new Exporter(objectExport, EXPORT_OPTIONS_HERE); var success = toSave.TryWriteToDir(SAVE_DIRECTORY_INFO_HERE, out var label, out var savedFilePath); ... } default: { ... } } ``` -------------------------------- ### ArgumentNullException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Demonstrates catching ArgumentNullException for invalid parameters. ```csharp try { provider.LoadPackageObject(null); // Null path } catch (ArgumentNullException ex) { Console.WriteLine($"Invalid parameter: {ex.ParamName}"); } ``` -------------------------------- ### CustomConfigIni Representation Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/file-providers.md Example of accessing section-based INI configuration data. ```csharp public class CustomConfigIni : Dictionary> ``` ```csharp var renderer = provider.DefaultEngine["Rendering"]; if (renderer.TryGetValue("r.DefaultFeature.LightUnits", out var lightUnit)) { Console.WriteLine($"Default light unit: {lightUnit}"); } ``` -------------------------------- ### Custom Type Registration Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Demonstrates registering custom UObject implementations with the library, including an example of a custom asset class and its registration. ```csharp [SkipObjectRegistration] public class MyCustomAsset : UObject { public override void Deserialize(FAssetArchive Ar, long validPos) { base.Deserialize(Ar, validPos); // Custom deserialization } } // In initialization ObjectTypeRegistry.Register(typeof(MyCustomAsset)); ``` -------------------------------- ### Troubleshooting Decompression Failed Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/compression-encryption.md Example of handling decompression failures with a try-catch block. ```csharp try { var data = gameFile.Read(); } catch (Exception ex) { Log.Error($"Decompression failed: {ex.Message}"); // Try with different method or skip file } ``` -------------------------------- ### Ace Combat 7 Encryption Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/compression-encryption.md Shows how CUE4Parse handles Ace Combat 7's AES-128 XOR-based encryption automatically. ```csharp if (package.Game == EGame.GAME_AceCombat7) { // Decryption handled automatically during package loading var package = provider.LoadPackage("Content/Models/Fighter.uasset"); } ``` -------------------------------- ### Custom UObject Construction Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/packages-objects.md Example of creating a custom UObject subclass to handle game-specific formats, including registration with the ObjectTypeRegistry. ```csharp [SkipObjectRegistration] public class MyCustomObject : UObject { public string CustomField { get; private set; } public override void Deserialize(FAssetArchive Ar, long validPos) { base.Deserialize(Ar, validPos); if (Ar.ReadBoolean()) { CustomField = Ar.ReadString(); } } } // Register during initialization ObjectTypeRegistry.Register(typeof(MyCustomObject)); ``` -------------------------------- ### Troubleshooting Compressed Size Mismatch Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/compression-encryption.md Example of validating block boundaries to prevent size mismatches. ```csharp var startPos = reader.Position; var compressedSize = reader.Read(); var uncompressedSize = reader.Read(); // Validate if (reader.Position + compressedSize > reader.Length) { Log.Error("Block extends beyond file"); return null; } ``` -------------------------------- ### Custom Reader Implementation Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/INDEX.md An example of implementing a custom deserialization method for FAssetArchive, including version-specific logic. ```csharp public override void Deserialize(FAssetArchive Ar, long validPos) { base.Deserialize(Ar, validPos); if (Ar.Game >= EGame.GAME_UE4_25) { var feature = Ar.Read(); } } ``` -------------------------------- ### FByteArchive Usage Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/readers.md Create from byte arrays obtained from GameFile.Read() or other sources. ```csharp var fileData = gameFile.Read(); var reader = new FByteArchive("MyFile", fileData); reader.SeekAbsolute(0x100); var value = reader.Read(); ``` -------------------------------- ### StreamedFileProvider Example Source: https://github.com/fabianfg/cue4parse/wiki/File-Providers Instantiates a StreamedFileProvider for accessing archives from remote directories or manifest files, requiring manual VFS registration. ```csharp var provider = new StreamedFileProvider( liveGame: "XXXXXXX", // can be useful in some cases isCaseInsensitive: true, versions: new VersionContainer(EGame.GAME_UE4_LATEST)); foreach (var archive in manifestInfo.Archives) { provider.RegisterVfs( file: archive.GetFullName(), stream: new[] { archive.GetStream() }); } ``` -------------------------------- ### CustomVfsFileProvider Example Source: https://github.com/fabianfg/cue4parse/wiki/File-Providers A custom VFS file provider that inherits from AbstractVfsFileProvider and registers archives from a specified directory. ```csharp public class CustomVfsFileProvider : AbstractVfsFileProvider { public override void Initialize() { foreach (var file in Directory.GetFiles(@"D:\\Games\\PC\\XXXXXXX\\XXXXXXX\\Content\\Paks")) { RegisterVfs(file); } } // Implement custom functionality here } ``` -------------------------------- ### Graceful Degradation Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md An example of loading assets gracefully, attempting a primary load and falling back to a safer method if the primary fails. ```csharp public List LoadAssetsGracefully(IFileProvider provider, string[] paths) { var results = new List(); foreach (var path in paths) { if (provider.TryLoadPackageObject(path, out var obj)) { results.Add(obj); } else if (provider.SafeLoadPackageObject(path) is UObject fallback) { results.Add(fallback); Log.Debug($"Loaded fallback for {path}"); } else { Log.Warning($"Failed to load {path}, skipping"); } } return results; } ``` -------------------------------- ### IFileProvider Configuration Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Shows how to configure a DefaultFileProvider before and after initialization, including setting game versions and parsing options. ```csharp var provider = new DefaultFileProvider(gameDir, SearchOption.TopDirectoryOnly); // Configure before initialize provider.Versions.Game = EGame.GAME_UE4_27; provider.ReadScriptData = true; provider.ReadShaderMaps = true; provider.ReadNaniteData = true; provider.SkipReferencedTextures = false; provider.UseLazyPackageSerialization = true; provider.Initialize(); // Or configure mapping container before loading packages if (provider.MappingsContainer != null) { var mappings = provider.MappingsContainer.GetMappings(provider.Versions.Game); // Use mappings for unversioned property deserialization } ``` -------------------------------- ### Custom Encryption Detection Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/compression-encryption.md A function signature for detecting if a file is encrypted, with a placeholder for other games. ```csharp public bool IsFileEncrypted(GameFile file, EGame game) { return game switch { EGame.GAME_AceCombat7 => true, // Add other encrypted games _ => file.IsEncrypted // Check GameFile property }; } ``` -------------------------------- ### Access Object Properties Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/INDEX.md Demonstrates how to access properties of a UObject using the Get and GetOrDefault methods. ```csharp var width = uobject.Get("Width"); var name = uobject.GetOrDefault("DisplayName", FName.None); ``` -------------------------------- ### Loading Virtual Path Mappings Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Shows how to initialize a file provider and load virtual path mappings from configuration files (INI/redirects), and how to access these mappings to resolve old paths to new ones. ```csharp var provider = new DefaultFileProvider(...); provider.Initialize(); // Load virtual path mappings from INI/redirects int mappingsLoaded = provider.LoadVirtualPaths(); // Access mapped paths if (provider.VirtualPaths.TryGetValue("/OldPath", out var newPath)) { Console.WriteLine($"Redirects to: {newPath}"); } ``` -------------------------------- ### Loading Localization Data Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Demonstrates how to initialize a file provider and load localization data for different languages and culture codes, as well as how to change the current culture at runtime and access localized strings. ```csharp var provider = new DefaultFileProvider(...); provider.Initialize(); // Load specific language int loadedCount = provider.LoadLocalization(ELanguage.French); Console.WriteLine($"Loaded {loadedCount} French strings"); // Or load by culture code loadedCount = provider.LoadLocalization("de-DE"); // Switch language at runtime provider.TryChangeCulture("ja-JP"); // Access localized strings var greeting = provider.GetLocalizedString("Greeting", "Welcome", "Hello"); ``` -------------------------------- ### Manual PAK/Container Mounting Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Illustrates how to manually register a PAK file with the file provider if it's not automatically discovered, before initializing the provider. ```csharp var provider = new DefaultFileProvider(...); var pakFile = new FileInfo("Plugin.pak"); // Mount manually if not auto-discovered provider.RegisterVfs(pakFile); provider.Initialize(); ``` -------------------------------- ### Environment Variables for Logging and Compression Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Demonstrates how to set environment variables to configure CUE4Parse's logging level and specify paths for custom compression libraries like OODLE. ```csharp // Log level (via Serilog) Environment.SetEnvironmentVariable("SERILOG_LEVEL", "Debug"); // Compression library paths (if custom builds needed) Environment.SetEnvironmentVariable("OODLE_PATH", @"C:\custom\oodle.dll"); ``` -------------------------------- ### VersionContainer Constructor Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Constructor for VersionContainer. ```csharp public class VersionContainer : ICloneable { public VersionContainer( EGame game = EGame.GAME_UE4_LATEST, ETexturePlatform platform = ETexturePlatform.DesktopMobile, FPackageFileVersion ver = default, FCustomVersionContainer? customVersions = null, IDictionary? optionOverrides = null, IDictionary>? mapStructTypesOverrides = null); } ``` -------------------------------- ### Simple Asset Loading Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/INDEX.md Demonstrates how to load a package object (e.g., a texture) using the DefaultFileProvider. ```csharp var provider = new DefaultFileProvider(gameDir, SearchOption.TopDirectoryOnly, new VersionContainer(EGame.GAME_UE4_27)); provider.Initialize(); var texture = provider.LoadPackageObject("Content/Textures/Texture.uasset"); ``` -------------------------------- ### Main CMake Configuration Source: https://github.com/fabianfg/cue4parse/blob/master/CUE4Parse-Natives/CMakeLists.txt Sets the minimum CMake version, project name, C++ standard, and conditionally enables ACL and Oodle support based on directory existence. ```cmake cmake_minimum_required(VERSION 3.10) project(CUE4Parse-Natives CXX) set(CMAKE_CXX_STANDARD 11) if (EXISTS "${PROJECT_SOURCE_DIR}/ACL/external/acl/includes") set(WITH_ACL 1) endif() if (EXISTS "${PROJECT_SOURCE_DIR}/Oodle/external/oodle2/core") set(WITH_Oodle 1) endif() ``` -------------------------------- ### DefaultFileProvider Constructor Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Modern constructors with explicit StringComparer. ```csharp public class DefaultFileProvider : AbstractVfsFileProvider { // Modern constructors with explicit StringComparer public DefaultFileProvider( string directory, SearchOption searchOption, VersionContainer? versions = null, StringComparer? pathComparer = null); public DefaultFileProvider( DirectoryInfo directory, SearchOption searchOption, VersionContainer? versions = null, StringComparer? pathComparer = null); public DefaultFileProvider( DirectoryInfo directory, DirectoryInfo[] extraDirectories, SearchOption searchOption, VersionContainer? versions = null, StringComparer? pathComparer = null); } ``` -------------------------------- ### NullReferenceException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Compares avoiding NullReferenceException with the preferred GetExportOrNull method. ```csharp // Avoid: var texture = package.GetExport("MyMesh"); // Wrong type! // Prefer: var texture = package.GetExportOrNull("MyTexture"); if (texture != null) { // Use texture } ``` -------------------------------- ### OperationCanceledException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Demonstrates catching OperationCanceledException for async operations with cancellation tokens. ```csharp var cts = new CancellationTokenSource(); cts.CancelAfter(TimeSpan.FromSeconds(5)); try { var result = await provider.LoadPackageObjectAsync(path); } catch (OperationCanceledException) { Console.WriteLine("Operation timed out"); } ``` -------------------------------- ### InvalidOperationException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Demonstrates catching InvalidOperationException when attempting to write to a read-only archive. ```csharp var reader = new FByteArchive(data); try { reader.Write(new byte[10], 0, 10); // Read-only } catch (InvalidOperationException) { Console.WriteLine("Cannot write to read-only archive"); } ``` -------------------------------- ### UE5 Game with Mobile Assets Configuration Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Shows how to configure `DefaultFileProvider` for a UE5 game targeting mobile, including specific option overrides for virtual textures and sound wave streaming. ```csharp var versions = new VersionContainer( game: EGame.GAME_UE5_2, platform: ETexturePlatform.Android, optionOverrides: new Dictionary { { "VirtualTextures", true }, { "SoundWave.UseAudioStreaming", true } }); var provider = new DefaultFileProvider( new DirectoryInfo(@"C:\Games\MobileGame"), new[] { new DirectoryInfo(@"C:\Games\MobileGame\Plugins") }, SearchOption.AllDirectories, versions, StringComparer.OrdinalIgnoreCase); provider.Initialize(); ``` -------------------------------- ### Game-Specific EGame Enum Values Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Examples of game-specific enum values and their offsets. ```csharp public enum EGame : uint { GAME_UE4_25 = ..., GAME_UE4_25_Plus = GAME_UE4_25 + 1, GAME_Fortnite = GAME_UE4_25 + 2, GAME_PlayerUnknownsBattlegrounds = GAME_UE4_16 + 1, GAME_Borderlands3 = GAME_UE4_20 + 1, GAME_StarWarsJediFallenOrder = GAME_UE4_21 + 1, GAME_DaysGone = GAME_UE4_11 + 2, GAME_DeadIsland2 = GAME_UE4_25 + 3, GAME_Stray = GAME_UE4_27 + ..., // ... 100+ game variants } ``` -------------------------------- ### DefaultFileProvider Initialize Method Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/file-providers.md Method to scan the directory and register all game files. ```csharp public override void Initialize(); ``` -------------------------------- ### Safe Loading Pattern (Recommended) Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md A recommended pattern for safely loading assets, handling common exceptions like FileNotFoundException and ParserException. ```csharp public bool TryLoadAsset(IFileProvider provider, string path, out T? asset) where T : UObject { try { asset = provider.SafeLoadPackageObject(path); return asset != null; } catch (FileNotFoundException) { Log.Warning($"Asset file not found: {path}"); asset = null; return false; } catch (ParserException ex) { Log.Warning($"Parse error loading {path}: {ex.Message}"); asset = null; return false; } catch (Exception ex) { Log.Error(ex, $"Unexpected error loading {path}"); asset = null; return false; } } ``` -------------------------------- ### PropertyValueException Example Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Illustrates catching InvalidCastException when a property value cannot be converted to the requested type. ```csharp try { var stringValue = uobject.Get("IntProperty"); } catch (InvalidCastException) { Console.WriteLine("Property is not string type"); } ``` -------------------------------- ### Load a Game Directory Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/INDEX.md Loads a game directory using DefaultFileProvider and initializes it. ```csharp var versions = new VersionContainer(EGame.GAME_UE4_27); var provider = new DefaultFileProvider(@"C:\Games\MyGame", SearchOption.TopDirectoryOnly, versions); provider.Initialize(); ``` -------------------------------- ### Lazy Serialization Configuration Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Explains and demonstrates the `UseLazyPackageSerialization` setting for `DefaultFileProvider`, contrasting the default lazy behavior with eager deserialization. ```csharp // Default: lazy (exports deserialized on access) var provider = new DefaultFileProvider(gameDir, SearchOption.TopDirectoryOnly); provider.UseLazyPackageSerialization = true; // Default provider.Initialize(); // Eager: all exports deserialized immediately provider.UseLazyPackageSerialization = false; ``` -------------------------------- ### Custom Reader Implementation Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/readers.md Provides an example of extending FArchive to create a custom reader for specialized formats. ```csharp public class MyCustomArchive : FArchive { private byte[] _data; private int _position; public MyCustomArchive(byte[] data) => _data = data; public override string Name => "MyCustom"; public override int Read(byte[] buffer, int offset, int count) { int toCopy = Math.Min(count, _data.Length - _position); Array.Copy(_data, _position, buffer, offset, toCopy); _position += toCopy; return toCopy; } public override void Seek(long offset, SeekOrigin origin) { _position = origin switch { SeekOrigin.Begin => (int)offset, SeekOrigin.Current => _position + (int)offset, SeekOrigin.End => _data.Length + (int)offset, _ => throw new ArgumentException() }; } public override long Length => _data.Length; } ``` -------------------------------- ### Batch Processing with Error Tolerance Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md An example of processing multiple assets in a batch, tolerating errors for individual assets. ```csharp var successCount = 0; var errorCount = 0; foreach (var path in assetPaths) { try { var asset = provider.LoadPackageObject(path); ProcessAsset(asset); successCount++; } catch (FileNotFoundException) { errorCount++; Log.Debug($"Skipping missing file: {path}"); } catch (ParserException ex) { errorCount++; Log.Debug($"Skipping parse error ({path}): {ex.Message}"); } } Log.Information($"Processed {successCount} assets, {errorCount} errors"); ``` -------------------------------- ### Load a Package Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/INDEX.md Loads a package from the provider and retrieves its exports. ```csharp if (provider.TryLoadPackage("Content/Maps/Level.umap", out var package)) { var exports = package.GetExports(); } ``` -------------------------------- ### Read Binary Data Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/INDEX.md Shows how to create a binary reader and read primitive types and arrays from a file. ```csharp var reader = provider.CreateReader("Content/Data.bin"); var value = reader.Read(); var array = reader.ReadArray(100); ``` -------------------------------- ### Serilog Logging Configuration in Code Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Shows how to configure Serilog for logging within CUE4Parse by setting up a logger with specific minimum levels and output destinations (console, file). ```csharp using Serilog; Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Console() .WriteTo.File("logs/cue4parse-.txt", rollingInterval: RollingInterval.Day) .CreateLogger(); // Now CUE4Parse operations are logged var provider = new DefaultFileProvider(...); provider.Initialize(); // Logs VFS mount operations ``` -------------------------------- ### Streamed File Provider for Large Games Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Introduces `StreamedFileProvider` as an alternative for very large games, which streams data on demand instead of loading entire files. ```csharp // Streams data on demand instead of loading entire files var provider = new StreamedFileProvider(gameDir, versions); provider.Initialize(); ``` -------------------------------- ### Retry with Fallback Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/errors.md Demonstrates a strategy for retrying asset loading with a fallback mechanism and exponential backoff. ```csharp public async Task LoadPackageWithRetry( IFileProvider provider, string path, int maxRetries = 3) { for (int i = 0; i < maxRetries; i++) { try { return await provider.LoadPackageAsync(path); } catch (IOException) when (i < maxRetries - 1) { Log.Warning($"Retry {i + 1}/{maxRetries} loading {path}"); await Task.Delay(100 * (i + 1)); } catch (ParserException ex) { Log.Error($"Cannot parse {path}: {ex.Message}"); return null; } } return null; } ``` -------------------------------- ### FPackageFileSummary Structure Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/packages-objects.md Represents the header of a package file, containing metadata such as signature, version information, counts and offsets for various tables, and a GUID. ```csharp public struct FPackageFileSummary { public uint Signature { get; } public int FileVersionUE4 { get; } public int FileVersionUE5 { get; } public int FileVersionLicensee { get; } public FCustomVersionContainer CustomVersions { get; } public EPackageFlags PackageFlags { get; } public int NameCount { get; } public long NameOffset { get; } public int ImportCount { get; } public long ImportOffset { get; } public int ExportCount { get; } public long ExportOffset { get; } public FGuid Guid { get; } public int[] Generations { get; } // ...and many more fields } ``` -------------------------------- ### Oodle Module Configuration Source: https://github.com/fabianfg/cue4parse/blob/master/CUE4Parse-Natives/CMakeLists.txt Configures the build to include Oodle if WITH_Oodle is set, adding compile definitions and subdirectories. ```cmake # Oodle if (WITH_Oodle) add_compile_definitions(OODLE_BUILDING_DLL) add_compile_definitions(WITH_Oodle) add_subdirectory("${PROJECT_SOURCE_DIR}/Oodle/") endif() ``` -------------------------------- ### Disabling Specific Logs Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/configuration.md Provides examples of how to disable specific logging categories within CUE4Parse, such as VFS mount operations and warnings for missing import packages. ```csharp Globals.LogVfsMounts = false; Globals.WarnMissingImportPackage = false; ``` -------------------------------- ### Clone Method Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Creates an independent copy for parallel version handling. ```csharp public object Clone(); ``` -------------------------------- ### Oodle Linking and Export Options Source: https://github.com/fabianfg/cue4parse/blob/master/CUE4Parse-Natives/CMakeLists.txt Links the Oodle library and configures platform-specific whole archive options to ensure all Oodle symbols are exported. ```cmake # Oodle if (WITH_Oodle) target_link_libraries("${PROJECT_NAME}" PRIVATE oodle2) # Ensure all Oodle symbols are exported with the shared library if(WIN32) target_link_options("${PROJECT_NAME}" PRIVATE "/WHOLEARCHIVE:oodle2") elseif(APPLE) target_link_options("${PROJECT_NAME}" PRIVATE "-Wl,-force_load,$") else() # Linux and other platforms target_link_options("${PROJECT_NAME}" PRIVATE "-Wl,--whole-archive" "$" "-Wl,--no-whole-archive") endif() endif() ``` -------------------------------- ### TryLoadPackages Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/file-providers.md Loads all available versions of a package (for different platforms or configurations). ```csharp public bool TryLoadPackages(string path, out List packages); ``` -------------------------------- ### ACL Module Configuration Source: https://github.com/fabianfg/cue4parse/blob/master/CUE4Parse-Natives/CMakeLists.txt Configures the build to include ACL if WITH_ACL is set, adding compile definitions and include directories. ```cmake # ACL if (WITH_ACL) add_compile_definitions(WITH_ACL) include_directories("${PROJECT_SOURCE_DIR}/ACL/external/acl/includes") include_directories("${PROJECT_SOURCE_DIR}/ACL/external/acl/external/rtm/includes") set(SOURCES ${SOURCES} ${PROJECT_SOURCE_DIR}/ACL/ACL.cpp) endif() ``` -------------------------------- ### FCustomVersionContainer Class Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Stores game and engine-specific custom version markers. ```csharp public class FCustomVersionContainer { public Dictionary Versions { get; } public bool TryGetVersion(FGuid guid, out int version); public int GetVersion(FGuid guid); } ``` -------------------------------- ### FPackageFileVersion Struct Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Represents explicit package file versions for UE3, UE4, and UE5. ```csharp public struct FPackageFileVersion { public int FileVersionUE3 { get; set; } public int FileVersionUE4 { get; set; } public int FileVersionUE5 { get; set; } public int FileVersionLicensee { get; set; } } ``` -------------------------------- ### IFileProvider Interface Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/types.md Interface for game file access and asset loading. ```csharp public interface IFileProvider : IDisposable { VersionContainer Versions { get; } FileProviderDictionary Files { get; } bool TryGetGameFile(string path, out GameFile file); IPackage LoadPackage(string path); T LoadPackageObject(string path) where T : UObject; } ``` -------------------------------- ### File Access Methods Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/file-providers.md Locate a game file by path. The indexer variant throws KeyNotFoundException if the file is not found. ```csharp public GameFile this[string path] { get; } public bool TryGetGameFile(string path, [MaybeNullWhen(false)] out GameFile file); ``` ```csharp if (provider.TryGetGameFile("Content/Maps/MyMap.umap", out var mapFile)) { var data = mapFile.Read(); } ``` -------------------------------- ### LoadPackage / LoadPackageAsync / TryLoadPackage Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/file-providers.md Methods for loading a complete package file and returning its structure. Supports lazy or eager serialization of exports. ```csharp public IPackage LoadPackage(string path); public IPackage LoadPackage(GameFile file); public Task LoadPackageAsync(string path); public Task LoadPackageAsync(GameFile file); public bool TryLoadPackage(string path, [MaybeNullWhen(false)] out IPackage package); public bool TryLoadPackage(GameFile file, [MaybeNullWhen(false)] out IPackage package); public bool TryLoadPackages(string path, out List packages); ``` ```csharp var provider = new DefaultFileProvider(gameDirectory, SearchOption.TopDirectoryOnly, new VersionContainer(EGame.GAME_UE4_27)); provider.Initialize(); if (provider.TryLoadPackage("Content/MyAsset.uasset", out var package)) { var firstExport = package.GetExport(0); Console.WriteLine($"Export type: {firstExport?.ExportType}"); } ``` -------------------------------- ### Globals Configuration Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/versions.md Static global settings affecting library behavior. ```csharp public static class Globals { public static bool LogVfsMounts = true; public static bool FatalObjectSerializationErrors = false; public static bool WarnMissingImportPackage = true; } ``` -------------------------------- ### Package Class Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/packages-objects.md Concrete implementation of IPackage for standard UE4/5 packages. ```csharp public sealed class Package : AbstractUePackage { public Package( FArchive uasset, FArchive? uexp, FArchive? ubulk = null, FArchive? uptnl = null, IFileProvider? provider = null, bool useLazySerialization = true); public Package( string name, byte[] uasset, byte[]? uexp, byte[]? ubulk = null, byte[]? uptnl = null, IFileProvider? provider = null, bool useLazySerialization = true); } ``` -------------------------------- ### Asset Loading Methods Source: https://github.com/fabianfg/cue4parse/blob/master/_autodocs/api-reference/file-providers.md Load complete asset file data into memory. Returns all file parts (uasset, uexp, ubulk, uptnl) combined. ```csharp public byte[] SaveAsset(string path); public byte[] SaveAsset(GameFile file); public Task SaveAssetAsync(string path); public Task SaveAssetAsync(GameFile file); public bool TrySaveAsset(string path, [MaybeNullWhen(false)] out byte[] data); public bool TrySaveAsset(GameFile file, [MaybeNullWhen(false)] out byte[] data); ``` ```csharp if (provider.TrySaveAsset("Content/Textures/Diffuse.uasset", out var assetData)) { File.WriteAllBytes("export.uasset", assetData); } ```