Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
name: build and test
name: build

on:
pull_request:
branches: [ master ]
paths:
- '**.cs'
- '**.csproj'
branches: [master]
push:
branches:
- master
branches: [master]
workflow_dispatch:

jobs:
build-and-test:

name: build-and-test-${{matrix.os}}
runs-on: windows-latest
build:
name: build-${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
- name: Checkout
uses: actions/checkout@v4
with:
submodules: false

- name: Init CUE4Parse submodule
shell: bash
run: git submodule update --init external/CUE4Parse

- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Restore
run: dotnet restore UnrealReZen/UnrealReZen.csproj

- name: Restore dependencies
run: dotnet restore

- name: Build solution
run: dotnet build --no-restore --configuration Release

- name: Run tests
run: dotnet test --no-build --verbosity normal --configuration Release
- name: Build
run: dotnet build UnrealReZen/UnrealReZen.csproj --no-restore --configuration Release
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,6 @@ FodyWeavers.xsd
/UnrealReZen/Properties/launchSettings.json
/UnrealReZen/Properties/PublishProfiles/FolderProfile.pubxml
/UnrealReZen/Properties/PublishProfiles/FolderProfile.pubxml.user

# Claude Code
.claude/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "external/CUE4Parse"]
path = external/CUE4Parse
url = https://github.com/FabianFG/CUE4Parse.git
70 changes: 29 additions & 41 deletions UnrealReZen/Core/Compression/Compressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace UnrealReZen.Core.Compression
{
public class CompressionUtils
public static class CompressionUtils
{

public static readonly Dictionary<string, Func<byte[], byte[]>> CompressionMethods = new(StringComparer.OrdinalIgnoreCase)
{
{ "None", CompressNone },
Expand All @@ -15,64 +14,53 @@ public class CompressionUtils
{ "Lz4", CompressLZ4 }
};

public static byte[]? Compress(string method, byte[] inputData)
{
if (CompressionMethods.TryGetValue(method, out var compressionFunction))
{
return compressionFunction(inputData);
}
return null;
}

public static Func<byte[], byte[]>? GetCompressionFunction(string method)
{
if (CompressionMethods.TryGetValue(method, out var compressionFunction))
{
return compressionFunction;
}
return null;
}
=> CompressionMethods.TryGetValue(method, out var fn) ? fn : null;

private static byte[] CompressNone(byte[] inData)
{
return inData;
}
private static readonly Lazy<Zlibng> _zlib = new(() =>
new Zlibng(Path.Combine(Constants.ToolDirectory, CUE4Parse.Compression.ZlibHelper.DllName)),
isThreadSafe: true);

private static readonly Lazy<Oodle> _oodle = new(() =>
new Oodle(Path.Combine(Constants.ToolDirectory, CUE4Parse.Compression.OodleHelper.OodleFileName)),
isThreadSafe: true);

private static byte[] CompressNone(byte[] inData) => inData;

private static byte[] CompressZlib(byte[] inData)
{
using var _zlib = new Zlibng(Path.Combine(Constants.ToolDirectory, CUE4Parse.Compression.ZlibHelper.DLL_NAME));
var compressedBufferSize = (int)_zlib.CompressBound(inData.Length);
var compressedBuffer = new byte[compressedBufferSize];
var compressionResult = _zlib.Compress(compressedBuffer, inData, out int compressedSize);
if (compressionResult.CompareTo(ZlibngCompressionResult.Ok) != 0)
var zlib = _zlib.Value;
var bufferSize = (int)zlib.CompressBound(inData.Length);
var buffer = new byte[bufferSize];
var result = zlib.Compress(buffer, inData, out int compressedSize);
if (result != ZlibngCompressionResult.Ok)
{
throw new Exception($"Zlib compression failed with error code {compressionResult}");
throw new InvalidOperationException($"Zlib compression failed with error code {result}");
}
return compressedBuffer.AsSpan(0, compressedSize).ToArray();

Array.Resize(ref buffer, compressedSize);
return buffer;
}

private static byte[] CompressOodle(byte[] inData)
{
const OodleCompressor compressor = OodleCompressor.Kraken;
using var _oodle = new Oodle(Path.Combine(Constants.ToolDirectory, CUE4Parse.Compression.OodleHelper.OODLE_DLL_NAME));
var compressedBufferSize = (int)_oodle.GetCompressedBufferSizeNeeded(compressor, inData.Length);
var compressedBuffer = new byte[compressedBufferSize];
var compressedSize = (int)_oodle.Compress(compressor, OodleCompressionLevel.Max, inData, compressedBuffer);
return [.. compressedBuffer.Take(compressedSize)];
var oodle = _oodle.Value;
var bufferSize = (int)oodle.GetCompressedBufferSizeNeeded(compressor, inData.Length);
var buffer = new byte[bufferSize];
var compressedSize = (int)oodle.Compress(compressor, OodleCompressionLevel.Max, inData, buffer);
Array.Resize(ref buffer, compressedSize);
return buffer;
}

private static byte[] CompressLZ4(byte[] inData)
{
using (var inputStream = new MemoryStream(inData))
using (var outputStream = new MemoryStream())
using var inputStream = new MemoryStream(inData);
using var outputStream = new MemoryStream(inData.Length);
using (var lz4Stream = LZ4Stream.Encode(outputStream))
{
inputStream.CopyTo(lz4Stream);
lz4Stream.Flush();
return outputStream.ToArray();
}

return outputStream.ToArray();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
namespace UnrealReZen.Core
namespace UnrealReZen.Core
{
public static class Constants
{
public static string[] CompressionTypes = ["none", "zlib", "oodle", "lz4"];
public static readonly string[] CompressionTypes = ["none", "zlib", "oodle", "lz4"];
public static readonly string DefaultAES = "0x" + new string('0', 64);

public static string ToolDirectory = "";
public static string DefaultAES = "0x" + new string('0', 64);
public static string MountPoint = "../../../";

public const string MagicUtoc = "-==--==--==--==-";
public const string DepFileName = "dependencies";
public const string UnrealSignature = "\xC1\x83\x2A\x9E";
public const uint NoneEntry = 0xFFFFFFFF;
public const int UE5_DepFile_Sig = 1232028526;
public const int CompSize = 0x10000;
Expand Down
6 changes: 0 additions & 6 deletions UnrealReZen/Core/FIoDependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,4 @@ public void Write(MemoryStream br)
}
}

public static class ManifestData
{
public const int UE5_DepFile_Sig = 1232028526;

}

}
Loading
Loading