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
5 changes: 5 additions & 0 deletions Game.Assets/Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public static List<AssetMapping> GetOptionalAssets() {
}
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
string p = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Application Support", "Steam");
if (Directory.Exists(p))
steamPath = p;
}

if (string.IsNullOrEmpty(steamPath))
return null;
Expand Down
6 changes: 1 addition & 5 deletions Game.UI/GameUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ public bool SetShowProgressText(bool show) {
private bool FindPlatformDirectory(out ReadOnlySpan<char> platformDir) {
platformDir = string.Empty;

#if WIN32
string? dir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
#else
string? dir = Directory.GetCurrentDirectory();
#endif
string? dir = AppContext.BaseDirectory;
if (string.IsNullOrEmpty(dir))
return false;

Expand Down
5 changes: 5 additions & 0 deletions HTML.CEF/CefSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public bool Init(ReadOnlySpan<char> pBaseDir, IHtmlResourceHandler resourceHandl
if (OperatingSystem.IsWindows() && !LowIntegrityLabel.Apply(rootCachePath))
resourceHandler.Message($"Chromium: failed to set a low integrity label on {rootCachePath}, cookies and storage will not persist.\n");

if (OperatingSystem.IsMacOS() && !Directory.Exists(Path.Combine(chromiumDir, "Chromium Embedded Framework.framework"))) {
resourceHandler.Message($"Chromium failed to load: Chromium Embedded Framework.framework is missing from {chromiumDir}\n");
return false;
}

try {
if (OperatingSystem.IsWindows())
CefRuntime.Load(chromiumDir);
Expand Down
5 changes: 5 additions & 0 deletions Source.Common/Platform.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Source.Common;

using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;

namespace Source;
Expand Down Expand Up @@ -56,6 +57,10 @@ public static unsafe void DebugString(ReadOnlySpan<char> buf) {
}

public static void Initialize() {
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
ThreadUtils.SetMainThread();
}
}
2 changes: 1 addition & 1 deletion Source.Engine/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void InitFilesystem(ReadOnlySpan<char> fullModPath) {
FileSystem FileSystem = providers.GetRequiredService<FileSystem>();

initInfo.FileSystem = engineAPI.GetRequiredService<IFileSystem>();
initInfo.DirectoryName = new(fullModPath);
initInfo.DirectoryName = fullModPath.IsEmpty ? "" : Path.GetFullPath(new string(fullModPath), AppContext.BaseDirectory);
if (initInfo.DirectoryName == null)
initInfo.DirectoryName = Host.GetCurrentGame();

Expand Down
3 changes: 2 additions & 1 deletion Source.Engine/Source.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<PackageReference Include="FreeImage-dotnet-core" ExcludeAssets="native" />
<None Include="$(NuGetPackageRoot)freeimage-dotnet-core\4.3.6\runtimes\win7-x64\native\FreeImage.dll" Link="FreeImage.dll" CopyToOutputDirectory="PreserveNewest" Visible="false" Condition="$([MSBuild]::IsOSPlatform('Windows')) And Exists('$(NuGetPackageRoot)freeimage-dotnet-core\4.3.6\runtimes\win7-x64\native\FreeImage.dll')" />
<None Include="$(NuGetPackageRoot)freeimage-dotnet-core\4.3.6\runtimes\ubuntu.16.04-x64\native\FreeImage.so" Link="FreeImage.so" CopyToOutputDirectory="PreserveNewest" Visible="false" Condition="$([MSBuild]::IsOSPlatform('Linux')) And Exists('$(NuGetPackageRoot)freeimage-dotnet-core\4.3.6\runtimes\ubuntu.16.04-x64\native\FreeImage.so')" />
<None Include="$(NuGetPackageRoot)freeimage-dotnet-core\4.3.6\runtimes\osx.10.10-x64\native\FreeImage.dylib" Link="FreeImage.dylib" CopyToOutputDirectory="PreserveNewest" Visible="false" Condition="$([MSBuild]::IsOSPlatform('OSX')) And Exists('$(NuGetPackageRoot)freeimage-dotnet-core\4.3.6\runtimes\osx.10.10-x64\native\FreeImage.dylib')" />
<None Include="$(NuGetPackageRoot)freeimage-dotnet-core\4.3.6\runtimes\osx.10.10-x64\native\FreeImage.dylib" Link="FreeImage.dylib" CopyToOutputDirectory="PreserveNewest" Visible="false" Condition="$([MSBuild]::IsOSPlatform('OSX')) And '$(PlatformTarget)' != 'arm64' And Exists('$(NuGetPackageRoot)freeimage-dotnet-core\4.3.6\runtimes\osx.10.10-x64\native\FreeImage.dylib')" />
<None Include="/opt/homebrew/opt/freeimage/lib/libfreeimage.dylib" Link="FreeImage.dylib" CopyToOutputDirectory="PreserveNewest" Visible="false" Condition="$([MSBuild]::IsOSPlatform('OSX')) And '$(PlatformTarget)' == 'arm64' And Exists('/opt/homebrew/opt/freeimage/lib/libfreeimage.dylib')" />
</ItemGroup>
<ItemGroup>
<Folder Include="GarrysMod\" />
Expand Down
4 changes: 2 additions & 2 deletions Source.Filesystem/BaseFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void AddMapPackFile(ReadOnlySpan<char> path, ReadOnlySpan<char> pathID,
}

private void AddVPKFile(ReadOnlySpan<char> path, ReadOnlySpan<char> pathID, SearchPathAdd addType, PathGroupName groupName) {
string newPath = Path.IsPathFullyQualified(path) ? new(path) : Path.GetFullPath(new(path));
string newPath = Path.IsPathFullyQualified(path) ? new(path) : Path.GetFullPath(new(path), AppContext.BaseDirectory);

if (!SearchPaths.OpenOrCreateCollection(pathID, out SearchPathCollection collection)) {
for (int i = 0, c = collection.Count; i < c; i++) {
Expand Down Expand Up @@ -136,7 +136,7 @@ private void AddSearchPathDiskInternal(ReadOnlySpan<char> path, ReadOnlySpan<cha
case ".vpk": AddVPKFile(path, pathID, addType, groupName); return;
}

string newPath = Path.IsPathFullyQualified(path) ? new(path) : Path.GetFullPath(new(path));
string newPath = Path.IsPathFullyQualified(path) ? new(path) : Path.GetFullPath(new(path), AppContext.BaseDirectory);
AddSeparatorAndFixPath(ref newPath);

if (!SearchPaths.OpenOrCreateCollection(pathID, out SearchPathCollection collection)) {
Expand Down
24 changes: 24 additions & 0 deletions Source.Launcher/Source.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@
<Copy SourceFiles="@(CefRedistLinuxX64)" DestinationFiles="@(CefRedistLinuxX64->'$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>

<!-- macOS caps OpenGL at 4.1, so GL 4.6 runs on Mesa (Zink over KosmicKrisp). libEGL is repointed at the bundled libgallium so that Zink's @rpath lookup finds the bundled Vulkan loader. -->
<PropertyGroup Condition="'$(IsOSX)'=='true'">
<MesaPrefix Condition="'$(MesaPrefix)'==''">/opt/homebrew/opt/mesa</MesaPrefix>
<VulkanLoaderPrefix Condition="'$(VulkanLoaderPrefix)'==''">/opt/homebrew/opt/vulkan-loader</VulkanLoaderPrefix>
<MesaBundleDir>$(OutputPath)mesa/lib/</MesaBundleDir>
</PropertyGroup>

<Target Name="SNWarnMissingMesa" AfterTargets="Build" Condition="'$(SNClientBuild)'=='true' And '$(IsOSX)'=='true' And (!Exists('$(MesaPrefix)/lib/libEGL.1.dylib') Or !Exists('$(VulkanLoaderPrefix)/lib/libvulkan.1.dylib'))">
<Warning Text="Mesa or the Vulkan loader was not found, so the client cannot render on macOS. Run 'brew install mesa vulkan-loader' and rebuild." />
</Target>

<ItemGroup Condition="'$(IsOSX)'=='true'">
<MesaBundleFile Include="$(MesaPrefix)/lib/libEGL.1.dylib" />
<MesaBundleFile Include="$(MesaPrefix)/lib/libgallium-*.dylib" />
<MesaBundleFile Include="$(MesaPrefix)/lib/libvulkan_kosmickrisp.dylib" />
<MesaBundleFile Include="$(VulkanLoaderPrefix)/lib/libvulkan.1.dylib" />
</ItemGroup>

<Target Name="SNBundleMesa" AfterTargets="Build" Condition="'$(SNClientBuild)'=='true' And '$(IsOSX)'=='true' And Exists('$(MesaPrefix)/lib/libEGL.1.dylib') And Exists('$(VulkanLoaderPrefix)/lib/libvulkan.1.dylib')" Inputs="@(MesaBundleFile)" Outputs="$(MesaBundleDir)libEGL.1.dylib">
<Copy SourceFiles="@(MesaBundleFile)" DestinationFolder="$(MesaBundleDir)" />
<Exec WorkingDirectory="$(MesaBundleDir)" Command="old=`otool -L libEGL.1.dylib | awk '/libgallium/{print $1}'` &amp;&amp; install_name_tool -change &quot;$old&quot; &quot;@loader_path/`basename $old`&quot; libEGL.1.dylib 2&gt;/dev/null &amp;&amp; codesign -f -s - libEGL.1.dylib" />
<WriteLinesToFile File="$(MesaBundleDir)kosmickrisp_icd.json" Lines="{ &quot;file_format_version&quot;: &quot;1.0.1&quot;, &quot;ICD&quot;: { &quot;library_path&quot;: &quot;./libvulkan_kosmickrisp.dylib&quot;, &quot;api_version&quot;: &quot;1.4.0&quot; } }" Overwrite="true" />
</Target>

<!-- Copy LuaJIT (Game.Lua imports "lua51", which .NET resolves to liblua51.so on Linux) -->
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\Dependencies\LuaJIT\win64\lua51.dll" Link="lua51.dll" CopyToOutputDirectory="PreserveNewest" Visible="false" Condition="'$(IsWindows)'=='true'" />
Expand Down
2 changes: 1 addition & 1 deletion Source.MaterialSystem/Surface/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ internal void InitFontSettings() {

for (KeyValues? kv = fallbackFonts.GetFirstSubKey(); kv != null; kv = kv.GetNextKey()) {
string? key = kv.Name == "NULL" ? null : kv.Name;
string? value = kv.GetString() == "NULL" ? null : new(kv.GetString());
string? value = kv.GetString().SequenceEqual("NULL") ? null : new(kv.GetString());
FallbackFonts[ffidx++] = new(key, value);
}

Expand Down
25 changes: 22 additions & 3 deletions Source.SDLInputSystem/SDL3_InputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,30 @@ public void SetConsoleTextMode(bool consoleTextMode) {
public unsafe void GetCursorPosition(out int x, out int y) {
float fx, fy;
SDL3.SDL_GetMouseState(&fx, &fy);
x = (int)fx;
y = (int)fy;
GetCursorScale(out float sx, out float sy);
x = (int)(fx * sx);
y = (int)(fy * sy);
}

public unsafe void SetCursorPosition(int x, int y) => SDL3.SDL_WarpMouseInWindow((SDL_Window*)Window!.GetHandle(), x, y);
public unsafe void SetCursorPosition(int x, int y) {
GetCursorScale(out float sx, out float sy);
SDL3.SDL_WarpMouseInWindow((SDL_Window*)Window!.GetHandle(), x / sx, y / sy);
}

void GetCursorScale(out float sx, out float sy) {
sx = sy = 1.0f;
#if OSX
if (launcherMgr == null)
return;
int renderWidth = 0, renderHeight = 0;
launcherMgr.RenderedSize(false, ref renderWidth, ref renderHeight);
launcherMgr.DisplayedSize(out int displayWidth, out int displayHeight);
if (renderWidth > 0 && renderHeight > 0 && displayWidth > 0 && displayHeight > 0) {
sx = (float)renderWidth / displayWidth;
sy = (float)renderHeight / displayHeight;
}
#endif
}

public ButtonCode VirtualKeyToButtonCode(int virtualKey) {
return virtualKeyToButtonCode[virtualKey];
Expand Down
28 changes: 28 additions & 0 deletions Source.SDLManager/SDL3_LauncherManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ public bool CreateGameWindow(string title, bool windowed, bool borderless, int w
SDL_WindowFlags flags = default;
GraphicsDriver driver = GraphicsDriver.OpenGL46; // todo, dont hardcode
switch(driver.GetDriver()){
#if OSX
case GraphicsDriver.OpenGL: flags |= SDL_WindowFlags.SDL_WINDOW_METAL; break;
#else
case GraphicsDriver.OpenGL: flags |= SDL_WindowFlags.SDL_WINDOW_OPENGL; break;
#endif
case GraphicsDriver.Metal: flags |= SDL_WindowFlags.SDL_WINDOW_METAL; break;
case GraphicsDriver.Vulkan: flags |= SDL_WindowFlags.SDL_WINDOW_VULKAN; break;
default: throw new Exception("Need graphics driver support");
Expand Down Expand Up @@ -226,6 +230,10 @@ public void RenderedSize(bool set, ref int width, ref int height) {
if (set) {
renderedWidth = width;
renderedHeight = height;
#if OSX
window.RenderWidth = width;
window.RenderHeight = height;
#endif
}
else {
width = renderedWidth;
Expand Down Expand Up @@ -355,17 +363,37 @@ public bool PrepareContext(GraphicsDriver driver) {
window = window == null ? this.window : window;
if (0 != (deviceInfo.Driver & GraphicsDriver.OpenGL)) {
nint handle = (nint)((SDL3_Window)window).HardwareHandle;
#if OSX
int modeWidth = deviceInfo.DisplayMode.Width, modeHeight = deviceInfo.DisplayMode.Height;
return SDL3_MesaEGL_Context.Create((SDL_Window*)handle, 4, 6, () => {
if (renderedWidth > 0 && renderedHeight > 0)
return (renderedWidth, renderedHeight);
if (modeWidth > 0 && modeHeight > 0)
return (modeWidth, modeHeight);
DisplayedSize(out int w, out int h);
return (w, h);
});
#else
nint ctx = (nint)SDL3.SDL_GL_CreateContext((SDL_Window*)handle);
if (ctx == 0) {
Warning($"Could not create GL context: {SDL3.SDL_GetError()}\n");
return null;
}
SDL3.SDL_GL_SetSwapInterval(0);
gfx = new SDL3_OpenGL46_Context(handle, ctx);
return gfx;
#endif
}

Warning("Cannot support this graphics API\n");
return null;
}

#if OSX
public delegate* unmanaged[Cdecl]<byte*, void*> GL_LoadExtensionsPtr() => &SDL3_MesaEGL_Context.GetProcAddress;
#else
public delegate* unmanaged[Cdecl]<byte*, void*> GL_LoadExtensionsPtr() => &GL_ProcAddress;
#endif

ICursor[] DefaultCursors;

Expand Down
Loading
Loading