FabianFG / CUE4Parse

Apache License 2.0
255 stars 109 forks source link

New Wiki Page - Linux #100

Open Sembiance opened 1 year ago

Sembiance commented 1 year ago

I got CUE4Parse working under Linux and thought these instructions might be useful to add to the Wiki:


Linux

These steps walk you through creating a dotnet project on Linux that can use CUE4Parse.

dotnet-sdk

Install the dotnet-sdk from Microsoft. This differs depending on your Linux distro. With Gentoo Linux: emerge dotnet-sdk-bin Once running dotnet --version returns something like 7.0.200 you should be all set.

Unreal Engine

CUE4Parse uses Oodle externally to decompress data from PAK files. The Unreal Engine provides this file. Some Linux distros may have an easy way to install this, but here is how to build it from source:

git clone git@github.com:EpicGames/UnrealEngine.git -b ue5-main
cd UnrealEngine
./Setup.sh
./GenerateProjectFiles.sh
make UnrealPak

detex

CUE4Parse uses detex to convert textures. Here is how to build it from source:

git clone https://github.com/hglm/detex
cd detex

# Modify Makefile.conf and change:
LIBRARY_CONFIGURATION = SHARED

# Modify detex.h the declaration for detexDecompressTextureLinear so it's loadable externally from CUE4Parse
# Replace the prefix DETEX_API with DETEX_HELPER_SHARED_EXPORT
DETEX_HELPER_SHARED_EXPORT bool detexDecompressTextureLinear(const detexTexture *texture, uint8_t *pixel_buffer,
    uint32_t pixel_format);

# Now build it:
make

CUE4Parse

Clone the CUE4Parse repo:

git clone https://github.com/FabianFG/CUE4Parse.git --recursive

Your Program

Create a new dotnet console program:

mkdir YourProgram
cd YourProgram
dotnet new console

# CUE4Parse uses SkiaSharp for Texture Bitmaps:
dotnet add package SkiaSharp.NativeAssets.Linux

Add a reference to CUE4Parse to YourProgram.csproj:

<ItemGroup>
    <ProjectReference Include="../CUE4Parse/CUE4Parse-Conversion/CUE4Parse-Conversion.csproj" />
    <ProjectReference Include="../CUE4Parse/CUE4Parse/CUE4Parse.csproj" />
</ItemGroup>

Build and run. You should see output: Hello, World!

dotnet build
dotnet run

Copy the Oodle and detex libs to a place that dotnet can find them:

cp /path/to/UnrealEngine/Engine/Source/Programs/Shared/EpicGames.Oodle/Sdk/2.9.3/linux/lib/liboo2corelinux64.so.9 ./bin/Debug/net7.0/oo2core_9_win64.dll
cp /path/to/detex/libdetex.so.0.1.2 ./bin/Debug/net7.0/Detex.dll

Update Program.cs with your program code, using CUE4Parse as you see fit.

Example code that extracts all assets from Pak files: https://gist.github.com/Sembiance/d4d65671a87c586286093d3c64beb29d

dotnet build
dotnet run --aesKey=0x0DEADBEEF0CAFEBABE0 --pakDir=/path/to/Game/UE_game/Content/Paks/ --outDir=/path/to/out/
yretenai commented 7 months ago

If https://github.com/FabianFG/CUE4Parse/pull/120 gets merged, the copy step needs to become:

cp /path/to/UnrealEngine/Engine/Source/Programs/Shared/EpicGames.Oodle/Sdk/2.9.3/linux/lib/liboo2corelinux64.so.9 ./bin/Debug/net7.0/
cp /path/to/detex/libdetex.so.0.1.2 ./bin/Debug/net7.0/libdetex.so

For tegra_swizzle you first have to install rust somehow, on gentoo: emerge dev-lang/rust, then

git clone https://github.com/ScanMountGoat/tegra_swizzle
cd tegra_swizzle
cargo build -r

to copy the library:

cp path/to/tegra_swizzle/target/release/libtegra_swizzle.so ./bin/Debug/net7.0/libtegra_swizzle_x64.so

note: these steps also work for mac, and 32-bit and arm variants for all 3 platforms. on mac any file that has the extension .so has to be .dylib, and on windows it's .dll.