@@ -8,6 +8,12 @@ namespace BepInEx.Preloader.Core;
88
99internal static class PlatformUtils
1010{
11+ public static readonly bool ProcessIs64Bit = IntPtr . Size >= 8 ;
12+ public static Version WindowsVersion { get ; set ; }
13+
14+ public static string LinuxArchitecture { get ; set ; }
15+ public static string LinuxKernelVersion { get ; set ; }
16+
1117 [ DllImport ( "libc.so.6" , EntryPoint = "uname" , CallingConvention = CallingConvention . Cdecl ,
1218 CharSet = CharSet . Ansi ) ]
1319 private static extern IntPtr uname_linux ( ref utsname_linux utsname ) ;
@@ -23,13 +29,6 @@ internal static class PlatformUtils
2329 private static bool Is ( this Platform current , Platform expected ) => ( current & expected ) == expected ;
2430
2531
26- public static readonly bool ProcessIs64Bit = IntPtr . Size >= 8 ;
27- public static Version WindowsVersion { get ; set ; }
28-
29- public static string LinuxArchitecture { get ; set ; }
30- public static string LinuxKernelVersion { get ; set ; }
31-
32-
3332 /// <summary>
3433 /// Recreation of MonoMod's PlatformHelper.DeterminePlatform method, but with libc calls instead of creating processes.
3534 /// </summary>
@@ -65,7 +64,9 @@ public static void SetPlatform()
6564 var windowsVersionInfo = new WindowsOSVersionInfoExW ( ) ;
6665 RtlGetVersion ( ref windowsVersionInfo ) ;
6766
68- WindowsVersion = new Version ( ( int ) windowsVersionInfo . dwMajorVersion , ( int ) windowsVersionInfo . dwMinorVersion , 0 , ( int ) windowsVersionInfo . dwBuildNumber ) ;
67+ WindowsVersion = new Version ( ( int ) windowsVersionInfo . dwMajorVersion ,
68+ ( int ) windowsVersionInfo . dwMinorVersion , 0 ,
69+ ( int ) windowsVersionInfo . dwBuildNumber ) ;
6970 }
7071
7172 // Is64BitOperatingSystem has been added in .NET Framework 4.0
@@ -75,7 +76,7 @@ public static void SetPlatform()
7576 current |= ( bool ) m_get_Is64BitOperatingSystem . Invoke ( null , new object [ 0 ] ) ? Platform . Bits64 : 0 ;
7677 else
7778 current |= IntPtr . Size >= 8 ? Platform . Bits64 : 0 ;
78-
79+
7980 if ( ( current . Is ( Platform . MacOS ) || current . Is ( Platform . Linux ) ) && Type . GetType ( "Mono.Runtime" ) != null )
8081 {
8182 string arch ;
@@ -115,19 +116,35 @@ public static void SetPlatform()
115116 [ StructLayout ( LayoutKind . Sequential , Pack = 1 , CharSet = CharSet . Unicode ) ]
116117 public struct WindowsOSVersionInfoExW
117118 {
118- private static uint size = ( uint ) Marshal . SizeOf ( typeof ( WindowsOSVersionInfoExW ) ) ;
119- public uint dwOSVersionInfoSize = size ;
119+ public uint dwOSVersionInfoSize ;
120120 public uint dwMajorVersion ;
121121 public uint dwMinorVersion ;
122122 public uint dwBuildNumber ;
123123 public uint dwPlatformId ;
124+
124125 [ MarshalAs ( UnmanagedType . ByValTStr , SizeConst = 128 ) ]
125126 public string szCSDVersion ;
127+
126128 public ushort wServicePackMajor ;
127129 public ushort wServicePackMinor ;
128130 public ushort wSuiteMask ;
129131 public byte wProductType ;
130132 public byte wReserved ;
133+
134+ public WindowsOSVersionInfoExW ( )
135+ {
136+ dwOSVersionInfoSize = ( uint ) Marshal . SizeOf ( typeof ( WindowsOSVersionInfoExW ) ) ;
137+ dwMajorVersion = 0 ;
138+ dwMinorVersion = 0 ;
139+ dwBuildNumber = 0 ;
140+ dwPlatformId = 0 ;
141+ szCSDVersion = null ;
142+ wServicePackMajor = 0 ;
143+ wServicePackMinor = 0 ;
144+ wSuiteMask = 0 ;
145+ wProductType = 0 ;
146+ wReserved = 0 ;
147+ }
131148 }
132149
133150 [ StructLayout ( LayoutKind . Sequential , Pack = 1 ) ]
0 commit comments