From 7f9c6ecb2d4e0955587b4ad19c7a2b5dd2c23b61 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Tue, 18 Feb 2025 21:10:51 -0600 Subject: [PATCH 1/3] Publish AOT --- .github/workflows/build.yml | 6 +++--- Borderless1942.csproj | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bb1a128..1162eb5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,12 +28,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Setup dotnet 6.0 + - name: Setup dotnet 9.0 uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.x + dotnet-version: 9.0.x - name: Build - run: dotnet publish -c Release --output ${{env.BUILD_ARTIFACT_PATH}} -r win-x64 -p:PublishSingleFile=true --self-contained true + run: dotnet publish -c Release --output ${{env.BUILD_ARTIFACT_PATH}} -r win-x64 - name: Publish artifacts uses: actions/upload-artifact@v2 with: diff --git a/Borderless1942.csproj b/Borderless1942.csproj index 3d15b94..a6c616d 100644 --- a/Borderless1942.csproj +++ b/Borderless1942.csproj @@ -2,14 +2,12 @@ Exe - net6.0 + net9.0 enable enable true - true - embedded - true - win-x64 + win-x64 + true From dd0f1c1c1b80f7e934f89b9b5695ede9372cc192 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Tue, 18 Feb 2025 23:51:40 -0600 Subject: [PATCH 2/3] Make application DPI aware, auto-patch video settings --- Borderless1942.csproj | 3 +- NativeMethods.txt | 4 ++- Program.cs | 76 ++++++++++++++++++++++++++++++++++++++--- Properties/app.manifest | 16 +++++++++ Win32Extensions.cs | 13 ++++++- 5 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 Properties/app.manifest diff --git a/Borderless1942.csproj b/Borderless1942.csproj index a6c616d..7ba25a7 100644 --- a/Borderless1942.csproj +++ b/Borderless1942.csproj @@ -1,4 +1,4 @@ - + Exe @@ -8,6 +8,7 @@ true win-x64 true + Properties\app.manifest diff --git a/NativeMethods.txt b/NativeMethods.txt index 33f2469..05e771a 100644 --- a/NativeMethods.txt +++ b/NativeMethods.txt @@ -1,6 +1,8 @@ -MonitorFromWindow +MonitorFromPoint +MonitorFromWindow GetMonitorInfo SetWindowPos +SetProcessDPIAwareness SendMessage GetWindowInfo SetWindowLong diff --git a/Program.cs b/Program.cs index 4b77a87..59c57ff 100644 --- a/Program.cs +++ b/Program.cs @@ -1,15 +1,81 @@ using Borderless1942; using System.Diagnostics; +var monitorBounds = Win32Extensions.GetPrimaryMonitor().GetBounds(); +var defaultWidth = monitorBounds.Width; +var defaultHeight = monitorBounds.Height; +var width = defaultWidth; +var height = defaultHeight; +var skipConfigEdits = false; + +for (int i = 0; i < args.Length; i++) +{ + if (args[i].Equals("-width", StringComparison.OrdinalIgnoreCase) && i + 1 < args.Length) + { + if (int.TryParse(args[i + 1], out int parsedWidth)) + { + width = parsedWidth; + } + } + else if (args[i].Equals("-height", StringComparison.OrdinalIgnoreCase) && i + 1 < args.Length) + { + if (int.TryParse(args[i + 1], out int parsedHeight)) + { + height = parsedHeight; + } + } + else if (args[i].Equals("-noedit", StringComparison.OrdinalIgnoreCase)) + { + skipConfigEdits = true; + } +} + +if (!skipConfigEdits) +{ + // Update Video.con files if they exist + var modsPath = Path.Combine(Environment.CurrentDirectory, "Mods", "bf1942", "Settings"); + if (Directory.Exists(modsPath)) + { + // Update resolution in profile Video.con files + var videoConFiles = Directory.GetFiles(Path.Combine(modsPath, "Profiles"), "Video.con", SearchOption.AllDirectories); + foreach (var videoConFile in videoConFiles) + { + var lines = File.ReadAllLines(videoConFile); + for (int i = 0; i < lines.Length; i++) + { + if (lines[i].StartsWith("game.setGameDisplayMode")) + { + lines[i] = $"game.setGameDisplayMode {width} {height} 32 60"; + } + } + File.WriteAllLines(videoConFile, lines); + Console.WriteLine($"[Borderless1942]: [{DateTime.Now:yyyy-MM-dd - hh:mm:ss tt}] [Updated resolution in {videoConFile} to {width}x{height}]"); + } + + // Update fullscreen setting in VideoDefault.con + var videoDefaultPath = Path.Combine(modsPath, "VideoDefault.con"); + if (File.Exists(videoDefaultPath)) + { + var lines = File.ReadAllLines(videoDefaultPath); + for (int i = 0; i < lines.Length; i++) + { + if (lines[i].StartsWith("renderer.setFullScreen")) + { + lines[i] = "renderer.setFullScreen 0"; + } + } + File.WriteAllLines(videoDefaultPath, lines); + Console.WriteLine($"[Borderless1942]: [{DateTime.Now:yyyy-MM-dd - hh:mm:ss tt}] [Updated fullscreen setting in VideoDefault.con]"); + } + } +} + // Start Process var processStartInfo = new ProcessStartInfo { FileName = @"BF1942.exe" }; -foreach (var arg in args) -{ - processStartInfo.ArgumentList.Add(arg); -} + var process = Process.Start(processStartInfo)!; var keepAlive = true; Console.WriteLine($"[Borderless1942]: [{DateTime.Now:yyyy-MM-dd - hh:mm:ss tt}] [BF1942 Process Has Started] [{process.Id}]"); @@ -49,7 +115,7 @@ } keepAlive = false; Console.WriteLine($"[Borderless1942]: [{DateTime.Now:yyyy-MM-dd - hh:mm:ss tt}] [BF1942 Process Has Exited]"); - } + } } static void UpdateWindowPosition(Window window) diff --git a/Properties/app.manifest b/Properties/app.manifest new file mode 100644 index 0000000..a660e53 --- /dev/null +++ b/Properties/app.manifest @@ -0,0 +1,16 @@ + + + + + + + + + + + + + true + + + diff --git a/Win32Extensions.cs b/Win32Extensions.cs index d6b1bd8..80ca8b5 100644 --- a/Win32Extensions.cs +++ b/Win32Extensions.cs @@ -10,7 +10,18 @@ namespace Borderless1942; public static class Win32Extensions { - public static async ValueTask WaitForMainWindowAsync(this Process process) + public static Monitor GetPrimaryMonitor() + { + nint handle = PInvoke.MonitorFromPoint(new POINT + { + x = 0, + y = 0 + }, 0); + + return new(handle); + } + + public static async ValueTask WaitForMainWindowAsync(this Process process) { while (process.MainWindowHandle == IntPtr.Zero) { From 51ef9b94f1ff0f1aa95eeb2ac7eeef531078c9c8 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Wed, 19 Feb 2025 00:05:17 -0600 Subject: [PATCH 3/3] Fix additional arguments not being passed --- Program.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 59c57ff..da270fa 100644 --- a/Program.cs +++ b/Program.cs @@ -8,6 +8,8 @@ var height = defaultHeight; var skipConfigEdits = false; +List additionalArgs = new(); + for (int i = 0; i < args.Length; i++) { if (args[i].Equals("-width", StringComparison.OrdinalIgnoreCase) && i + 1 < args.Length) @@ -28,6 +30,8 @@ { skipConfigEdits = true; } + else + additionalArgs.Add(args[i]); } if (!skipConfigEdits) @@ -73,9 +77,12 @@ // Start Process var processStartInfo = new ProcessStartInfo { - FileName = @"BF1942.exe" + FileName = @"BF1942.exe", }; +foreach (var arg in additionalArgs) + processStartInfo.ArgumentList.Add(arg); + var process = Process.Start(processStartInfo)!; var keepAlive = true; Console.WriteLine($"[Borderless1942]: [{DateTime.Now:yyyy-MM-dd - hh:mm:ss tt}] [BF1942 Process Has Started] [{process.Id}]");