Implement cross-platform improvements from master

Contains fixes rebased from d2afe06 ... 9f4dcb6
This commit is contained in:
Bepis committed 2020-11-05 23:18:52 +11:00
1 parent 265f484447
commit 1c32115fa2
34 files changed
+1117 -257

No files matched your search

+24
View File
@@ -6,6 +6,7 @@ using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Mono.Cecil;
using MonoMod.Utils;
namespace BepInEx
{
@@ -270,5 +271,28 @@ namespace BepInEx
return builder.ToString();
}
public static Platform CurrentPlatform { get; private set; } = CheckPlatform();
// Adapted from https://github.com/MonoMod/MonoMod.Common/blob/master/Utils/PlatformHelper.cs#L13
private static Platform CheckPlatform()
{
var pPlatform = typeof(Environment).GetProperty("Platform", BindingFlags.NonPublic | BindingFlags.Static);
string platId = pPlatform != null ? pPlatform.GetValue(null, new object[0]).ToString() : Environment.OSVersion.Platform.ToString();
platId = platId.ToLowerInvariant();
var cur = Platform.Unknown;
if (platId.Contains("win"))
cur = Platform.Windows;
else if (platId.Contains("mac") || platId.Contains("osx"))
cur = Platform.MacOS;
else if (platId.Contains("lin") || platId.Contains("unix"))
cur = Platform.Linux;
if (IntPtr.Size == 8)
cur |= Platform.Bits64;
return cur;
}
}
}