From 137a953b288ed6cfe10ec6ff45b21a2ee2cc7fad Mon Sep 17 00:00:00 2001 From: Nekromateion <43814053+Nekromateion@users.noreply.github.com> Date: Wed, 7 Aug 2024 10:54:48 +0200 Subject: [PATCH] Warning for unhandled exceptions for faulty CPUs (#861) --- Dotnet/Program.cs | 10 ++++++++++ Dotnet/WinApi.cs | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/Dotnet/Program.cs b/Dotnet/Program.cs index b80aeca1..5c1ca866 100644 --- a/Dotnet/Program.cs +++ b/Dotnet/Program.cs @@ -7,6 +7,7 @@ using NLog; using NLog.Targets; using System; +using System.Diagnostics; using System.IO; using System.Threading; using System.Windows.Forms; @@ -133,6 +134,15 @@ namespace VRCX #endregion catch (Exception e) { + var cpuError = WinApi.GetCpuErrorMessage(); + if (cpuError != null) + { + var messageBoxResult = MessageBox.Show(cpuError.Value.Item1, "Potentially Faulty CPU Detected", MessageBoxButtons.YesNo, MessageBoxIcon.Error); + if (messageBoxResult == DialogResult.Yes) + { + Process.Start(cpuError.Value.Item2); + } + } logger.Fatal(e, "Unhandled Exception, program dying"); MessageBox.Show(e.ToString(), "PLEASE REPORT IN https://vrcx.app/discord", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); diff --git a/Dotnet/WinApi.cs b/Dotnet/WinApi.cs index 3790d82a..930e2f69 100644 --- a/Dotnet/WinApi.cs +++ b/Dotnet/WinApi.cs @@ -4,13 +4,22 @@ // This work is licensed under the terms of the MIT license. // For a copy, see . +using Microsoft.Win32; using System; +using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; namespace VRCX { public static class WinApi { + private static List<(List, string, string)> CpuErrorMessages = new List<(List, string, string)>() + { + (["Intel", "Core", "-13"], "VRCX has detected that you're using a 13th or 14th generation Intel CPU.\nThese CPUs are known to have issues which can lead to crashes.\nThis crash was unlikely caused by VRCX itself, therefore limited support can be offered.\nWould you like to open a link with more information?", "https://www.youtube.com/watch?v=b6vQlvefGxk"), + (["Intel", "Core", "-14"], "VRCX has detected that you're using a 13th or 14th generation Intel CPU.\nThese CPUs are known to have issues which can lead to crashes.\nThis crash was unlikely caused by VRCX itself, therefore limited support can be offered.\nWould you like to open a link with more information?", "https://www.youtube.com/watch?v=b6vQlvefGxk"), + }; + [DllImport("kernel32.dll", SetLastError = false)] public static extern void RtlCopyMemory(IntPtr destination, IntPtr source, uint length); @@ -76,5 +85,25 @@ namespace VRCX return exited; } + + internal static string GetCpuName() + { + return Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0\")?.GetValue("ProcessorNameString").ToString() ?? null; + } + + internal static (string, string)? GetCpuErrorMessage() + { + string cpuName = GetCpuName(); + if (cpuName == null) + return null; + + foreach (var errorInfo in CpuErrorMessages) + { + if (errorInfo.Item1.All(cpuName.Contains)) + return (errorInfo.Item2, errorInfo.Item3); + } + + return null; + } } }