From 8599f3c3846674397c3830fd0429c0406b208ae0 Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Sun, 17 Mar 2024 16:05:22 -0400 Subject: [PATCH 01/15] Add check for compatibility mode on game startup --- osu.Desktop/OsuGameDesktop.cs | 3 + .../Security/CompatibilityModeChecker.cs | 57 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 osu.Desktop/Security/CompatibilityModeChecker.cs diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 2b232db274b1..8a394f79838e 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -145,6 +145,9 @@ protected override void LoadComplete() LoadComponentAsync(new ElevatedPrivilegesChecker(), Add); + if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows) + LoadComponentAsync(new CompatibilityModeChecker(), Add); + osuSchemeLinkIPCChannel = new OsuSchemeLinkIPCChannel(Host, this); archiveImportIPCChannel = new ArchiveImportIPCChannel(Host, this); } diff --git a/osu.Desktop/Security/CompatibilityModeChecker.cs b/osu.Desktop/Security/CompatibilityModeChecker.cs new file mode 100644 index 000000000000..870f6539385d --- /dev/null +++ b/osu.Desktop/Security/CompatibilityModeChecker.cs @@ -0,0 +1,57 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. + +using System; +using System.Linq; +using Microsoft.Win32; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; +using osu.Game.Overlays; +using osu.Game.Overlays.Notifications; + +namespace osu.Desktop.Security +{ + /// + /// Checks if the game is running with windows compatibility optimizations which could cause issues. Displays a warning notification if so. + /// + public partial class CompatibilityModeChecker : Drawable + { + [Resolved] + private INotificationOverlay notifications { get; set; } = null!; + + [BackgroundDependencyLoader] + private void load() + { + if (checkCompatibilityMode()) + notifications.Post(new CompatibilityModeNotification()); + } + + private bool checkCompatibilityMode() + { + if (!OperatingSystem.IsWindows()) + return false; + + using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"); + + return layers != null && layers.GetValueNames().Any(name => name.EndsWith("osu!.exe", StringComparison.OrdinalIgnoreCase)); + } + + private partial class CompatibilityModeNotification : SimpleNotification + { + public override bool IsImportant => true; + + public CompatibilityModeNotification() + { + Text = "osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode."; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + Icon = FontAwesome.Solid.ShieldAlt; + IconContent.Colour = colours.YellowDark; + } + } + } +} From 6b7a7900564371de9786bf0085a99fd3fd8e37bf Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Sun, 17 Mar 2024 16:14:39 -0400 Subject: [PATCH 02/15] Fix peppy copyright disclaimer --- osu.Desktop/Security/CompatibilityModeChecker.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Desktop/Security/CompatibilityModeChecker.cs b/osu.Desktop/Security/CompatibilityModeChecker.cs index 870f6539385d..f08b897061de 100644 --- a/osu.Desktop/Security/CompatibilityModeChecker.cs +++ b/osu.Desktop/Security/CompatibilityModeChecker.cs @@ -1,4 +1,5 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. using System; using System.Linq; From 1f362a582a7c2afa58b1a6d20fc5442352054067 Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Sun, 17 Mar 2024 16:46:13 -0400 Subject: [PATCH 03/15] Remove comments about compatibility mode from `Program.cs` since this PR will be resolving it --- osu.Desktop/Program.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index 73670adc495d..deba13f127ef 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -52,10 +52,6 @@ public static void Main(string[] args) // See https://www.mongodb.com/docs/realm/sdk/dotnet/compatibility/ if (windowsVersion.Major < 6 || (windowsVersion.Major == 6 && windowsVersion.Minor <= 2)) { - // If users running in compatibility mode becomes more of a common thing, we may want to provide better guidance or even consider - // disabling it ourselves. - // We could also better detect compatibility mode if required: - // https://stackoverflow.com/questions/10744651/how-i-can-detect-if-my-application-is-running-under-compatibility-mode#comment58183249_10744730 SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, "Your operating system is too old to run osu!", "This version of osu! requires at least Windows 8.1 to run.\n" From 87dcaa80fa4eef3d11ca79a00525a33678586a93 Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Sun, 17 Mar 2024 19:11:22 -0400 Subject: [PATCH 04/15] Inherit from component instead of drawable --- osu.Desktop/Security/CompatibilityModeChecker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Desktop/Security/CompatibilityModeChecker.cs b/osu.Desktop/Security/CompatibilityModeChecker.cs index f08b897061de..e64015b4217f 100644 --- a/osu.Desktop/Security/CompatibilityModeChecker.cs +++ b/osu.Desktop/Security/CompatibilityModeChecker.cs @@ -16,7 +16,7 @@ namespace osu.Desktop.Security /// /// Checks if the game is running with windows compatibility optimizations which could cause issues. Displays a warning notification if so. /// - public partial class CompatibilityModeChecker : Drawable + public partial class CompatibilityModeChecker : Component { [Resolved] private INotificationOverlay notifications { get; set; } = null!; From be2f3f1bc0fe5de3fd5a6f01a83ed9954d7b8a69 Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 18 Mar 2024 09:28:27 -0400 Subject: [PATCH 05/15] Move to osu.Desktop/Windows --- osu.Desktop/{Security => Windows}/CompatibilityModeChecker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename osu.Desktop/{Security => Windows}/CompatibilityModeChecker.cs (98%) diff --git a/osu.Desktop/Security/CompatibilityModeChecker.cs b/osu.Desktop/Windows/CompatibilityModeChecker.cs similarity index 98% rename from osu.Desktop/Security/CompatibilityModeChecker.cs rename to osu.Desktop/Windows/CompatibilityModeChecker.cs index e64015b4217f..685345af3092 100644 --- a/osu.Desktop/Security/CompatibilityModeChecker.cs +++ b/osu.Desktop/Windows/CompatibilityModeChecker.cs @@ -11,7 +11,7 @@ using osu.Game.Overlays; using osu.Game.Overlays.Notifications; -namespace osu.Desktop.Security +namespace osu.Desktop.Windows { /// /// Checks if the game is running with windows compatibility optimizations which could cause issues. Displays a warning notification if so. From d9ee7b4aa178b51b25b3021fda23f371af2b1cec Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:55:28 -0400 Subject: [PATCH 06/15] Move operating system check to outside --- osu.Desktop/OsuGameDesktop.cs | 2 +- osu.Desktop/Windows/CompatibilityModeChecker.cs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 8a394f79838e..f92e0c659a5a 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -145,7 +145,7 @@ protected override void LoadComplete() LoadComponentAsync(new ElevatedPrivilegesChecker(), Add); - if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows) + if (OperatingSystem.IsWindows()) LoadComponentAsync(new CompatibilityModeChecker(), Add); osuSchemeLinkIPCChannel = new OsuSchemeLinkIPCChannel(Host, this); diff --git a/osu.Desktop/Windows/CompatibilityModeChecker.cs b/osu.Desktop/Windows/CompatibilityModeChecker.cs index 685345af3092..2bb3ed5060f7 100644 --- a/osu.Desktop/Windows/CompatibilityModeChecker.cs +++ b/osu.Desktop/Windows/CompatibilityModeChecker.cs @@ -3,6 +3,7 @@ using System; using System.Linq; +using System.Runtime.Versioning; using Microsoft.Win32; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -16,6 +17,7 @@ namespace osu.Desktop.Windows /// /// Checks if the game is running with windows compatibility optimizations which could cause issues. Displays a warning notification if so. /// + [SupportedOSPlatform("windows")] public partial class CompatibilityModeChecker : Component { [Resolved] @@ -30,9 +32,6 @@ private void load() private bool checkCompatibilityMode() { - if (!OperatingSystem.IsWindows()) - return false; - using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"); return layers != null && layers.GetValueNames().Any(name => name.EndsWith("osu!.exe", StringComparison.OrdinalIgnoreCase)); From a59e63a378e2708b81f5e4ab14ab96c49118baab Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:31:26 -0400 Subject: [PATCH 07/15] Show a different messagebox if compatibility mode is detected during windows version check --- osu.Desktop/Program.cs | 23 +++++++++++++++---- .../Windows/CompatibilityModeChecker.cs | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index deba13f127ef..87c48cfd04f2 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -52,11 +52,24 @@ public static void Main(string[] args) // See https://www.mongodb.com/docs/realm/sdk/dotnet/compatibility/ if (windowsVersion.Major < 6 || (windowsVersion.Major == 6 && windowsVersion.Minor <= 2)) { - SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, - "Your operating system is too old to run osu!", - "This version of osu! requires at least Windows 8.1 to run.\n" - + "Please upgrade your operating system or consider using an older version of osu!.\n\n" - + "If you are running a newer version of windows, please check you don't have \"Compatibility mode\" turned on for osu!", IntPtr.Zero); + bool isInCompatibilityMode = new CompatibilityModeChecker() + .checkCompatibilityMode(); + + if (isInCompatibilityMode) + { + SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, + "osu! is running in compatibility mode", + "osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode.", IntPtr.Zero); + } + else + { + SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, + "Your operating system is too old to run osu!", + "This version of osu! requires at least Windows 8.1 to run.\n" + + "Please upgrade your operating system or consider using an older version of osu!.\n\n" + + "If you are running a newer version of windows, please check you don't have \"Compatibility mode\" turned on for osu!", IntPtr.Zero); + } + return; } diff --git a/osu.Desktop/Windows/CompatibilityModeChecker.cs b/osu.Desktop/Windows/CompatibilityModeChecker.cs index 2bb3ed5060f7..00c33e4c77f2 100644 --- a/osu.Desktop/Windows/CompatibilityModeChecker.cs +++ b/osu.Desktop/Windows/CompatibilityModeChecker.cs @@ -30,7 +30,7 @@ private void load() notifications.Post(new CompatibilityModeNotification()); } - private bool checkCompatibilityMode() + public bool checkCompatibilityMode() { using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"); From 4865310199ee4c034389c7edb663680b20d0dffa Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:55:35 -0400 Subject: [PATCH 08/15] Check if compatibility mode is checked for the runtime executable instead of checking if it is flipped on for any executable titled "osu!.exe" --- osu.Desktop/Windows/CompatibilityModeChecker.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Desktop/Windows/CompatibilityModeChecker.cs b/osu.Desktop/Windows/CompatibilityModeChecker.cs index 00c33e4c77f2..9bcb8a0340e9 100644 --- a/osu.Desktop/Windows/CompatibilityModeChecker.cs +++ b/osu.Desktop/Windows/CompatibilityModeChecker.cs @@ -3,6 +3,7 @@ using System; using System.Linq; +using System.Reflection; using System.Runtime.Versioning; using Microsoft.Win32; using osu.Framework.Allocation; @@ -34,7 +35,9 @@ public bool checkCompatibilityMode() { using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"); - return layers != null && layers.GetValueNames().Any(name => name.EndsWith("osu!.exe", StringComparison.OrdinalIgnoreCase)); + var exePath = Assembly.GetExecutingAssembly().Location; + + return layers != null && layers.GetValueNames().Any(name => name.Equals(exePath, StringComparison.OrdinalIgnoreCase)); } private partial class CompatibilityModeNotification : SimpleNotification From 0a66f438c486e9fc4385a3a34b8c83c334bfe382 Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 18 Mar 2024 13:25:42 -0400 Subject: [PATCH 09/15] Code quality - Make checkCompatibilityMode static - Fixing naming for CheckCompatibilityMode - Use explicit type for exePath --- osu.Desktop/Program.cs | 3 +-- osu.Desktop/Windows/CompatibilityModeChecker.cs | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index 87c48cfd04f2..37de1f9e530a 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -52,8 +52,7 @@ public static void Main(string[] args) // See https://www.mongodb.com/docs/realm/sdk/dotnet/compatibility/ if (windowsVersion.Major < 6 || (windowsVersion.Major == 6 && windowsVersion.Minor <= 2)) { - bool isInCompatibilityMode = new CompatibilityModeChecker() - .checkCompatibilityMode(); + bool isInCompatibilityMode = CompatibilityModeChecker.CheckCompatibilityMode(); if (isInCompatibilityMode) { diff --git a/osu.Desktop/Windows/CompatibilityModeChecker.cs b/osu.Desktop/Windows/CompatibilityModeChecker.cs index 9bcb8a0340e9..31f32441d7f6 100644 --- a/osu.Desktop/Windows/CompatibilityModeChecker.cs +++ b/osu.Desktop/Windows/CompatibilityModeChecker.cs @@ -27,15 +27,15 @@ public partial class CompatibilityModeChecker : Component [BackgroundDependencyLoader] private void load() { - if (checkCompatibilityMode()) + if (CheckCompatibilityMode()) notifications.Post(new CompatibilityModeNotification()); } - public bool checkCompatibilityMode() + public static bool CheckCompatibilityMode() { using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"); - var exePath = Assembly.GetExecutingAssembly().Location; + string exePath = Assembly.GetExecutingAssembly().Location; return layers != null && layers.GetValueNames().Any(name => name.Equals(exePath, StringComparison.OrdinalIgnoreCase)); } From e7d7bdc1a56201518b4c3387d197b060d86fbbc3 Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:12:14 -0400 Subject: [PATCH 10/15] Final touches - Add docstrings to the functions - Add a new function to log the compatibility flags - Add patch for locating the actual exe --- osu.Desktop/Program.cs | 2 ++ .../Windows/CompatibilityModeChecker.cs | 25 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index 37de1f9e530a..8bd056592a5f 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -69,6 +69,8 @@ public static void Main(string[] args) + "If you are running a newer version of windows, please check you don't have \"Compatibility mode\" turned on for osu!", IntPtr.Zero); } + CompatibilityModeChecker.LogCompatibilityFlags(); + return; } diff --git a/osu.Desktop/Windows/CompatibilityModeChecker.cs b/osu.Desktop/Windows/CompatibilityModeChecker.cs index 31f32441d7f6..f5614ec6ac2b 100644 --- a/osu.Desktop/Windows/CompatibilityModeChecker.cs +++ b/osu.Desktop/Windows/CompatibilityModeChecker.cs @@ -3,12 +3,12 @@ using System; using System.Linq; -using System.Reflection; using System.Runtime.Versioning; using Microsoft.Win32; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; +using osu.Framework.Logging; using osu.Game.Graphics; using osu.Game.Overlays; using osu.Game.Overlays.Notifications; @@ -27,17 +27,32 @@ public partial class CompatibilityModeChecker : Component [BackgroundDependencyLoader] private void load() { - if (CheckCompatibilityMode()) - notifications.Post(new CompatibilityModeNotification()); + if (!CheckCompatibilityMode()) return; + + notifications.Post(new CompatibilityModeNotification()); + LogCompatibilityFlags(); } + /// + /// Check if the game is running with windows compatibility optimizations + /// + /// public static bool CheckCompatibilityMode() { using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"); - string exePath = Assembly.GetExecutingAssembly().Location; + return layers != null && layers.GetValueNames().Any(name => name.Equals(Environment.ProcessPath, StringComparison.OrdinalIgnoreCase)); + } + + /// + /// Log the compatibility flags for the current process if they exist + /// + public static void LogCompatibilityFlags() + { + using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"); - return layers != null && layers.GetValueNames().Any(name => name.Equals(exePath, StringComparison.OrdinalIgnoreCase)); + if (layers?.GetValue(Environment.ProcessPath) is string flags) + Logger.Log($"Compatibility flags for {Environment.ProcessPath}: {flags}", LoggingTarget.Information); } private partial class CompatibilityModeNotification : SimpleNotification From 5d1f3b1776d5e7427b4482da964fec67b4fe81c9 Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:24:26 -0400 Subject: [PATCH 11/15] Move flags log within if statement clause In my previous commit I figured that I should put it outside of the if statement so that it logs the compatibility mode flags regardless (in case the other messagebox is shown for some reason and compatibility mode is enabled). But I figured that it's highly likely this would never happen, so might as well just keep it in the if statement. --- osu.Desktop/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index 8bd056592a5f..f8bd0a44430c 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -59,6 +59,8 @@ public static void Main(string[] args) SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, "osu! is running in compatibility mode", "osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode.", IntPtr.Zero); + + CompatibilityModeChecker.LogCompatibilityFlags(); } else { @@ -69,8 +71,6 @@ public static void Main(string[] args) + "If you are running a newer version of windows, please check you don't have \"Compatibility mode\" turned on for osu!", IntPtr.Zero); } - CompatibilityModeChecker.LogCompatibilityFlags(); - return; } From f25e50a7d4fdfdb48b55194acc11b484032b07a9 Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:26:35 -0400 Subject: [PATCH 12/15] Make the notification text for the compatibility mode checker translatable Will probably make a small PR in the future to do the same for the admin mode checker --- .../Windows/CompatibilityModeChecker.cs | 3 ++- .../WindowsCompatibilityModeCheckerStrings.cs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Localisation/WindowsCompatibilityModeCheckerStrings.cs diff --git a/osu.Desktop/Windows/CompatibilityModeChecker.cs b/osu.Desktop/Windows/CompatibilityModeChecker.cs index f5614ec6ac2b..5b3a984ae541 100644 --- a/osu.Desktop/Windows/CompatibilityModeChecker.cs +++ b/osu.Desktop/Windows/CompatibilityModeChecker.cs @@ -10,6 +10,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Logging; using osu.Game.Graphics; +using osu.Game.Localisation; using osu.Game.Overlays; using osu.Game.Overlays.Notifications; @@ -61,7 +62,7 @@ private partial class CompatibilityModeNotification : SimpleNotification public CompatibilityModeNotification() { - Text = "osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode."; + Text = WindowsCompatibilityModeCheckerStrings.NotificationText; } [BackgroundDependencyLoader] diff --git a/osu.Game/Localisation/WindowsCompatibilityModeCheckerStrings.cs b/osu.Game/Localisation/WindowsCompatibilityModeCheckerStrings.cs new file mode 100644 index 000000000000..726a7163695e --- /dev/null +++ b/osu.Game/Localisation/WindowsCompatibilityModeCheckerStrings.cs @@ -0,0 +1,19 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Localisation; + +namespace osu.Game.Localisation +{ + public static class WindowsCompatibilityModeCheckerStrings + { + private const string prefix = @"osu.Game.Resources.Localisation.WindowsCompatibilityModeChecker"; + + /// + /// "osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode." + /// + public static LocalisableString NotificationText => new TranslatableString(getKey(@"notification_text"), @"osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode."); + + private static string getKey(string key) => $@"{prefix}:{key}"; + } +} From c8e03fe64784103e775fe3b0a4bb2bfdce1d41bf Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:40:10 -0400 Subject: [PATCH 13/15] Don't log to void --- osu.Desktop/Windows/CompatibilityModeChecker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Desktop/Windows/CompatibilityModeChecker.cs b/osu.Desktop/Windows/CompatibilityModeChecker.cs index 5b3a984ae541..0cd82bda54e7 100644 --- a/osu.Desktop/Windows/CompatibilityModeChecker.cs +++ b/osu.Desktop/Windows/CompatibilityModeChecker.cs @@ -53,7 +53,7 @@ public static void LogCompatibilityFlags() using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"); if (layers?.GetValue(Environment.ProcessPath) is string flags) - Logger.Log($"Compatibility flags for {Environment.ProcessPath}: {flags}", LoggingTarget.Information); + Logger.Log($"Compatibility flags for {Environment.ProcessPath}: {flags}"); } private partial class CompatibilityModeNotification : SimpleNotification From 10c0459d131fe5e58c05f3b74d498f831bc2ea3f Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:44:54 -0400 Subject: [PATCH 14/15] Forgot to add the return description to the function --- osu.Desktop/Windows/CompatibilityModeChecker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Desktop/Windows/CompatibilityModeChecker.cs b/osu.Desktop/Windows/CompatibilityModeChecker.cs index 0cd82bda54e7..c32cfa78ea6e 100644 --- a/osu.Desktop/Windows/CompatibilityModeChecker.cs +++ b/osu.Desktop/Windows/CompatibilityModeChecker.cs @@ -37,7 +37,7 @@ private void load() /// /// Check if the game is running with windows compatibility optimizations /// - /// + /// Whether compatibility mode flags are detected or not public static bool CheckCompatibilityMode() { using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"); From 90f46cc0ba907c2d22ce094d595c3da0d4205e18 Mon Sep 17 00:00:00 2001 From: smallketchup82 <69545310+smallketchup82@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:51:55 -0400 Subject: [PATCH 15/15] Fix compatibility flags debug info not being written to logfiles due to uninitialized logger This makes a new function, `GetCompatibilityFlags` and includes that within the messagebox. This would probably be a better approach for diagnosing something like this in general (instead of having to flip through a user's debug logs, you simply view a screenshot of the messagebox) --- osu.Desktop/Program.cs | 5 ++--- osu.Desktop/Windows/CompatibilityModeChecker.cs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index f8bd0a44430c..5d6243cd50bd 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -58,9 +58,8 @@ public static void Main(string[] args) { SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, "osu! is running in compatibility mode", - "osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode.", IntPtr.Zero); - - CompatibilityModeChecker.LogCompatibilityFlags(); + "osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode.\n\n" + + "Debug information: " + CompatibilityModeChecker.GetCompatibilityFlags(), IntPtr.Zero); } else { diff --git a/osu.Desktop/Windows/CompatibilityModeChecker.cs b/osu.Desktop/Windows/CompatibilityModeChecker.cs index c32cfa78ea6e..9ce9470257bb 100644 --- a/osu.Desktop/Windows/CompatibilityModeChecker.cs +++ b/osu.Desktop/Windows/CompatibilityModeChecker.cs @@ -49,11 +49,19 @@ public static bool CheckCompatibilityMode() /// Log the compatibility flags for the current process if they exist /// public static void LogCompatibilityFlags() + { + Logger.Log($"Compatibility flags for {Environment.ProcessPath}: {GetCompatibilityFlags()}"); + } + + /// + /// Get the compatibility flags for the current process if they exist + /// + /// The compatibility flags + public static string GetCompatibilityFlags() { using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"); - if (layers?.GetValue(Environment.ProcessPath) is string flags) - Logger.Log($"Compatibility flags for {Environment.ProcessPath}: {flags}"); + return layers?.GetValue(Environment.ProcessPath) as string ?? string.Empty; } private partial class CompatibilityModeNotification : SimpleNotification