Files
sbox-public/engine/Launcher/Shared/LauncherEnvironment.cs
Sam Pavlovic e995ba452d Linux ARM64 (#4469)
* Simple DLLImportResolver for the 3 platforms, on linux/mac it tries to load DLLs from managed/ directory even with PATH being set, and backport the steamworks behaviour from Facepunch.Steamwokrs

* Fix DLLImportResolver, also let's try to keep just a single set of binaries for managed without platform variants

* Temporary Podman Bootstrap

* PLT relocation suffix is only valid for x86 GCC; ARM64 linker handles PLT automatically

* HAVE_NEON if $ARCH_ARM64 instead of $APPLEALL

* Linux ARM64 steamapi

* This unalignedptr behaviour used on mac arm64 is same for linux arm64

* Maybe use system SDL3 for vpc and native arch since we aim to regenerate this

* sdl3 and jre on podman

* Linux ARM64 GetSystemIncludePaths fix

* Add support for Linux ARM64 file system paths

* libEtcLib for linux arm64

* holy shit we dont want embree on linux at all

* remaining linux arm64 dependencies except for sdl3

* mkdir vpc output folder

* add <concepts> header for clang compatibility in commonmacros

* Steam Audio ARM64

* VPC build points to the correct linux variant

* SDL3 ARM64

* steamnetworkingsockets and steamapi arm64

* Launch on linuxarm64 properly

* steam audio arm64

* Was using wrong ARM64 Steam Audio

* libdxcompiler on client, game boots

* podman takes 16GB instead of throttling it

* skiasharp native arm64

* dont fucking use system sdl since our build machine doesnt have it, get both from our prebuilt

* Fix solutiongenerator_xcode not allowing compiler flags

* Delete Podman-Bootstrap.sh, eventually add what it does into github ci

* Fix $File_NoPCH doing nothing on xcode, VPC deals with VPC_FILE_FLAGS_NO_PCH properly on mac

* ogg_vorbis_impl.c tagged as NoPCH

* use system curl on a mac, the one we ship doesnt contain all symbols we need

* not using libsteamnetworkingsockets separately
2026-05-22 03:58:01 +02:00

101 lines
2.7 KiB
C#

using System;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Sandbox;
public static class LauncherEnvironment
{
/// <summary>
/// The folder containing sbox.exe
/// </summary>
public static string GamePath { get; set; }
/// <summary>
/// The folder containing Sandbox.Engine.dll
/// </summary>
public static string ManagedDllPath { get; set; }
public static string PlatformName
{
get
{
var platform = OperatingSystem.IsWindows() ? "win"
: OperatingSystem.IsLinux() ? "linuxsteamrt"
: OperatingSystem.IsMacOS() ? "osx"
: throw new Exception( "Unsupported platform" );
var architecture = RuntimeInformation.OSArchitecture == Architecture.Arm64 ? "arm64" : "64";
return $"{platform}{architecture}";
}
}
public static void Init()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
GamePath = AppContext.BaseDirectory;
// this exe is in the bin folder
if ( GamePath.EndsWith( System.IO.Path.Combine( "bin", PlatformName ) ) )
{
// go up two folders
GamePath = System.IO.Path.GetDirectoryName( GamePath );
GamePath = System.IO.Path.GetDirectoryName( GamePath );
}
// this exe is in the game folder
ManagedDllPath = $"{GamePath}/bin/managed/";
var nativeDllPath = $"{GamePath}/bin/{PlatformName}/";
// make the game dir our current dir
Environment.CurrentDirectory = GamePath;
//
// Allows unit tests and csproj to find the engine path.
//
if ( System.Environment.GetEnvironmentVariable( "FACEPUNCH_ENGINE", EnvironmentVariableTarget.User ) != GamePath )
{
System.Environment.SetEnvironmentVariable( "FACEPUNCH_ENGINE", GamePath, EnvironmentVariableTarget.User );
}
UpdateNativeDllPath( nativeDllPath );
}
private static void UpdateNativeDllPath( string nativeDllPath )
{
// WARNING: this calls into Sandbox.Engine.dll - so we need to put it in
// this method, which is executed AFTER CurrentDomain_AssemblyResolve is set
// so that managed can find the correct dll
NetCore.NativeDllPath = nativeDllPath;
//
// Put our native dll path first so that when looking up native dlls we'll
// always use the ones from our folder first
//
if ( OperatingSystem.IsWindows() )
{
var path = System.Environment.GetEnvironmentVariable( "PATH" );
path = $"{nativeDllPath};{path}";
System.Environment.SetEnvironmentVariable( "PATH", path );
}
}
private static Assembly CurrentDomain_AssemblyResolve( object sender, ResolveEventArgs args )
{
var trim = args.Name.Split( ',' )[0];
var name = $"{ManagedDllPath}/{trim}.dll";
// dlls with resources inside appear as a different name
name = name.Replace( ".resources.dll", ".dll" );
if ( System.IO.File.Exists( name ) )
{
return Assembly.LoadFrom( name );
}
return null;
}
}