Skip to content

Commit

Permalink
Fix C# 10 CS8983 regression
Browse files Browse the repository at this point in the history
  • Loading branch information
ghorsington committed Feb 24, 2022
1 parent 4cc7ab0 commit b7a05a6
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions BepInEx.Preloader.Core/PlatformUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace BepInEx.Preloader.Core;

internal static class PlatformUtils
{
public static readonly bool ProcessIs64Bit = IntPtr.Size >= 8;
public static Version WindowsVersion { get; set; }

This comment has been minimized.

Copy link
@Jakklittley

Jakklittley Feb 25, 2022

help


public static string LinuxArchitecture { get; set; }
public static string LinuxKernelVersion { get; set; }

[DllImport("libc.so.6", EntryPoint = "uname", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi)]
private static extern IntPtr uname_linux(ref utsname_linux utsname);
Expand All @@ -23,13 +29,6 @@ internal static class PlatformUtils
private static bool Is(this Platform current, Platform expected) => (current & expected) == expected;


public static readonly bool ProcessIs64Bit = IntPtr.Size >= 8;
public static Version WindowsVersion { get; set; }

public static string LinuxArchitecture { get; set; }
public static string LinuxKernelVersion { get; set; }


/// <summary>
/// Recreation of MonoMod's PlatformHelper.DeterminePlatform method, but with libc calls instead of creating processes.
/// </summary>
Expand Down Expand Up @@ -65,7 +64,9 @@ public static void SetPlatform()
var windowsVersionInfo = new WindowsOSVersionInfoExW();
RtlGetVersion(ref windowsVersionInfo);

WindowsVersion = new Version((int)windowsVersionInfo.dwMajorVersion, (int)windowsVersionInfo.dwMinorVersion, 0, (int)windowsVersionInfo.dwBuildNumber);
WindowsVersion = new Version((int) windowsVersionInfo.dwMajorVersion,
(int) windowsVersionInfo.dwMinorVersion, 0,
(int) windowsVersionInfo.dwBuildNumber);
}

// Is64BitOperatingSystem has been added in .NET Framework 4.0
Expand All @@ -75,7 +76,7 @@ public static void SetPlatform()
current |= (bool) m_get_Is64BitOperatingSystem.Invoke(null, new object[0]) ? Platform.Bits64 : 0;
else
current |= IntPtr.Size >= 8 ? Platform.Bits64 : 0;

if ((current.Is(Platform.MacOS) || current.Is(Platform.Linux)) && Type.GetType("Mono.Runtime") != null)
{
string arch;
Expand Down Expand Up @@ -115,19 +116,35 @@ public static void SetPlatform()
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct WindowsOSVersionInfoExW
{
private static uint size = (uint)Marshal.SizeOf(typeof(WindowsOSVersionInfoExW));
public uint dwOSVersionInfoSize = size;
public uint dwOSVersionInfoSize;
public uint dwMajorVersion;
public uint dwMinorVersion;
public uint dwBuildNumber;
public uint dwPlatformId;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;

public ushort wServicePackMajor;
public ushort wServicePackMinor;
public ushort wSuiteMask;
public byte wProductType;
public byte wReserved;

public WindowsOSVersionInfoExW()
{
dwOSVersionInfoSize = (uint) Marshal.SizeOf(typeof(WindowsOSVersionInfoExW));
dwMajorVersion = 0;
dwMinorVersion = 0;
dwBuildNumber = 0;
dwPlatformId = 0;
szCSDVersion = null;
wServicePackMajor = 0;
wServicePackMinor = 0;
wSuiteMask = 0;
wProductType = 0;
wReserved = 0;
}
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
Expand Down

0 comments on commit b7a05a6

Please sign in to comment.