From c29fdcca609cce6a4cc4c262882b6aa6ba666d3b Mon Sep 17 00:00:00 2001 From: js6pak Date: Thu, 13 Jan 2022 17:05:58 +0100 Subject: [PATCH] Fix process bitness detection --- BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs b/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs index f0a9f87..7d1e62b 100644 --- a/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs +++ b/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs @@ -204,8 +204,7 @@ public unsafe class IL2CPPDetourMethodPatcher : MethodPatcher var paramStartIndex = 0; var managedReturnType = AccessTools.GetReturnedType(Original); - var hasReturnBuffer = managedReturnType.IsSubclassOf(typeof(ValueType)) && - PlatformHelper.Is(Platform.Bits64); + var hasReturnBuffer = managedReturnType.IsSubclassOf(typeof(ValueType)) && Environment.Is64BitProcess; if (hasReturnBuffer) // C compilers seem to return values larger than 64 bits by allocating a return buffer on caller's side and passing it as the first parameter // TODO: Handle ARM @@ -322,7 +321,7 @@ public unsafe class IL2CPPDetourMethodPatcher : MethodPatcher if (directType == typeof(string) || directType.IsSubclassOf(typeof(Il2CppObjectBase))) return typeof(IntPtr*); } - else if (managedType.IsSubclassOf(typeof(ValueType)) && !PlatformHelper.Is(Platform.Bits64)) + else if (managedType.IsSubclassOf(typeof(ValueType)) && !Environment.Is64BitProcess) { // Struct that's passed on the stack => handle as general struct uint align = 0; @@ -369,7 +368,7 @@ public unsafe class IL2CPPDetourMethodPatcher : MethodPatcher il.Emit(OpCodes.Conv_I); // On x64, struct is always a pointer but it is a non-pointer on x86 // We don't handle byref structs on x86 yet but we're yet to encounter those - il.Emit(PlatformHelper.Is(Platform.Bits64) ? OpCodes.Ldarg : OpCodes.Ldarga_S, argIndex); + il.Emit(Environment.Is64BitProcess ? OpCodes.Ldarg : OpCodes.Ldarga_S, argIndex); il.Emit(OpCodes.Call, AccessTools.Method(typeof(UnhollowerBaseLib.IL2CPP), nameof(UnhollowerBaseLib.IL2CPP.il2cpp_value_box)));