Skip to content
Open
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
4 changes: 3 additions & 1 deletion UET/Redpoint.Logging.Mac/Redpoint.Logging.Mac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<MacNativeVersion>*</MacNativeVersion>
<MacNativeVersion Condition="$([MSBuild]::IsOSPlatform('OSX'))">$(PackageVersion)</MacNativeVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<ProjectReference Include="..\Lib\Redpoint.ThirdParty.Microsoft.Extensions.Logging.Console\Redpoint.ThirdParty.Microsoft.Extensions.Logging.Console.csproj" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Redpoint.Logging.Mac.Native" Version="$(PackageVersion)" />
<PackageReference Include="Redpoint.Logging.Mac.Native" Version="$(MacNativeVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<ItemGroup>
<PackageReference Include="Vecc.YamlDotNet.Analyzers.StaticGenerator" Version="13.0.2" />
<PackageReference Include="YamlDotNet" Version="13.1.0" />
<PackageReference Include="YamlDotNet" Version="15.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 20 additions & 0 deletions UET/Redpoint.Uet.Patching.Runtime/ConsoleUetPatchLogging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Redpoint.Uet.Patching.Runtime
{
internal class ConsoleUetPatchLogging : IUetPatchLogging
{
public void LogInfo(string message)
{
Console.WriteLine($"Redpoint.Uet.Patching.Runtime [info ] {message}");
}

public void LogWarning(string message)
{
Console.WriteLine($"Redpoint.Uet.Patching.Runtime [warn ] {message}");
}

public void LogError(string message)
{
Console.WriteLine($"Redpoint.Uet.Patching.Runtime [error] {message}");
}
}
}
11 changes: 11 additions & 0 deletions UET/Redpoint.Uet.Patching.Runtime/IUetPatchLogging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Redpoint.Uet.Patching.Runtime
{
internal interface IUetPatchLogging
{
void LogInfo(string message);

void LogWarning(string message);

void LogError(string message);
}
}
17 changes: 17 additions & 0 deletions UET/Redpoint.Uet.Patching.Runtime/NullUetPatchLogging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Redpoint.Uet.Patching.Runtime
{
internal class NullUetPatchLogging : IUetPatchLogging
{
public void LogInfo(string message)
{
}

public void LogWarning(string message)
{
}

public void LogError(string message)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Redpoint.Uet.Patching.Runtime.Patches
{
using HarmonyLib;
using System.Reflection;
using System.Runtime.Loader;

internal class UeDeployAndroidExternalFilesDirUetPatch : IUetPatch
{
private static IUetPatchLogging? _logging;

public bool ShouldApplyPatch()
{
return Assembly.GetEntryAssembly()?.GetName()?.Name == "UnrealBuildTool";
}

public void ApplyPatch(IUetPatchLogging logging, Harmony harmony)
{
// Get the UnrealBuildTool.dll assembly.
var loadedUbtAssembly = AssemblyLoadContext.Default.Assemblies.First(x => x.GetName().Name == "UnrealBuildTool");

// Find the UseExternalFilesDir method.
var method = loadedUbtAssembly.GetType("UnrealBuildTool.UEDeployAndroid")?.GetDeclaredMethods()
.Where(x => x.Name == "UseExternalFilesDir")
.FirstOrDefault();
if (method == null)
{
throw new InvalidOperationException("Unable to find UnrealBuildTool.UEDeployAndroid.UseExternalFilesDir method!");
}

// Store the logger so we can emit logs when overriding the disallow parameter.
_logging = logging;

// Apply the prefix patch to always set 'bDisallowExternalFilesDir' to false.
var prefix = GetType().GetMethod(nameof(OverrideDisallowExternalFilesDir), AccessTools.all);
harmony.Patch(method, prefix: new HarmonyMethod(prefix));
}

public static void OverrideDisallowExternalFilesDir(ref bool bDisallowExternalFilesDir)
{
_logging?.LogInfo("Intercepting 'UseExternalFilesDir' method and setting 'bDisallowExternalFilesDir' to false.");
bDisallowExternalFilesDir = false;
}
}
}
12 changes: 12 additions & 0 deletions UET/Redpoint.Uet.Patching.Runtime/Patches/UetPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Redpoint.Uet.Patching.Runtime.Patches
{
using HarmonyLib;
using Redpoint.Uet.Patching.Runtime;

internal interface IUetPatch
{
bool ShouldApplyPatch();

void ApplyPatch(IUetPatchLogging logging, Harmony harmony);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="KubernetesClient" Version="14.0.2" />
<PackageReference Include="Lib.Harmony" Version="2.3.3" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions UET/Redpoint.Uet.Patching.Runtime/StartupHook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Reflection;
using System.Runtime.Loader;

internal class StartupHook
{
public static void Initialize()
{
// Set our assembly resolver for Mono.Cecil and other things.
var ourDirectoryPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName!;
AssemblyLoadContext.Default.Resolving += (AssemblyLoadContext context, AssemblyName name) =>
{
var targetAssembly = Path.Combine(ourDirectoryPath, name.Name + ".dll");
if (File.Exists(targetAssembly))
{
return Assembly.LoadFrom(targetAssembly);
}
return null;
};

// Then call our real code.
Redpoint.Uet.Patching.Runtime.UetStartupHook.Initialize();
}
}
49 changes: 49 additions & 0 deletions UET/Redpoint.Uet.Patching.Runtime/UetStartupHook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace Redpoint.Uet.Patching.Runtime
{
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;
using Redpoint.Uet.Patching.Runtime.Patches;
using System;
using System.Reflection;
using System.Runtime.Loader;

public static class UetStartupHook
{
public static void Initialize()
{
// Prevent MSBuild from re-using nodes, since we're injected into all .NET processes (including MSBuild).
Environment.SetEnvironmentVariable("MSBUILDDISABLENODEREUSE", "1");

// Our list of patches.
var patches = new IUetPatch[]
{
new UeDeployAndroidExternalFilesDirUetPatch(),
};

// Determine if we have any patches to apply. If we have none, we're done.
if (!patches.Any(x => x.ShouldApplyPatch()))
{
return;
}

// Create our logging instance.
IUetPatchLogging logging = Environment.GetEnvironmentVariable("UET_RUNTIME_PATCHING_ENABLE_LOGGING") == "1"
? new ConsoleUetPatchLogging()
: new NullUetPatchLogging();

// Create our Harmony instance.
var harmony = new Harmony("games.redpoint.uet");

// Go through our patches and apply the ones that are relevant.
foreach (var patch in patches)
{
if (patch.ShouldApplyPatch())
{
patch.ApplyPatch(logging, harmony);
}
}
}
}
}
2 changes: 2 additions & 0 deletions UET/Redpoint.Uet.Uat/DefaultUATExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ await File.ReadAllTextAsync(scriptModuleFullName, cancellationToken).ConfigureAw
while (true);
}

// Extract the hooks and set DOTNET_STARTUP_HOOKS.

// Determine the process specification to use based on whether we're running on macOS/Linux or Windows.
ProcessSpecification processSpecification;
if (OperatingSystem.IsWindows())
Expand Down
7 changes: 7 additions & 0 deletions UET/Redpoint.Uet.Uat/Redpoint.Uet.Uat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
<ProjectReference Include="..\Redpoint.ProcessExecution\Redpoint.ProcessExecution.csproj" />
<ProjectReference Include="..\Redpoint.Uet.Core\Redpoint.Uet.Core.csproj" />
<ProjectReference Include="..\Redpoint.Windows.HandleManagement\Redpoint.Windows.HandleManagement.csproj" />
<ProjectReference Include="..\Redpoint.Uet.Patching.Runtime\Redpoint.Uet.Patching.Runtime.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\Redpoint.Uet.Patching.Runtime\bin\$(Configuration)\$(TargetFramework)\*.dll">
<Link>Embedded\%(Filename)%(Extension)</Link>
</EmbeddedResource>
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions UET/UET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Redpoint.Uba", "Redpoint.Ub
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Redpoint.Uba", "Redpoint.Uba\Redpoint.Uba.csproj", "{2AAD5971-F06A-4B7A-9E11-538BEC82F247}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Redpoint.Uet.Patching.Runtime", "Redpoint.Uet.Patching.Runtime\Redpoint.Uet.Patching.Runtime.csproj", "{2B61E65D-9CCD-4671-B713-BD3CD4694014}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -857,6 +859,10 @@ Global
{2AAD5971-F06A-4B7A-9E11-538BEC82F247}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AAD5971-F06A-4B7A-9E11-538BEC82F247}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AAD5971-F06A-4B7A-9E11-538BEC82F247}.Release|Any CPU.Build.0 = Release|Any CPU
{2B61E65D-9CCD-4671-B713-BD3CD4694014}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B61E65D-9CCD-4671-B713-BD3CD4694014}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B61E65D-9CCD-4671-B713-BD3CD4694014}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B61E65D-9CCD-4671-B713-BD3CD4694014}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -967,6 +973,7 @@ Global
{7CDD0F44-C516-47E9-99E5-3885AD24636F} = {A10A6C63-109E-4825-AA79-81B0AE279A76}
{D19B5289-C0A3-4025-834D-FA8AB1C19A32} = {1AE4AFCD-0F49-4CEA-8439-F1AAA2CDD183}
{2AAD5971-F06A-4B7A-9E11-538BEC82F247} = {586E33AB-CC82-4ADF-92F3-3B287A5AEEAC}
{2B61E65D-9CCD-4671-B713-BD3CD4694014} = {1AE4AFCD-0F49-4CEA-8439-F1AAA2CDD183}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8598A278-509A-48A6-A7B3-3E3B0D1011F1}
Expand Down
Loading