Skip to content

Commit e21677f

Browse files
authored
Merge pull request #352 from js6pak/bitness
Fix process bitness detection
2 parents ce04a24 + c29fdcc commit e21677f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ private DynamicMethodDefinition GenerateNativeToManagedTrampoline(MethodInfo tar
204204
var paramStartIndex = 0;
205205

206206
var managedReturnType = AccessTools.GetReturnedType(Original);
207-
var hasReturnBuffer = managedReturnType.IsSubclassOf(typeof(ValueType)) &&
208-
PlatformHelper.Is(Platform.Bits64);
207+
var hasReturnBuffer = managedReturnType.IsSubclassOf(typeof(ValueType)) && Environment.Is64BitProcess;
209208
if (hasReturnBuffer)
210209
// 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
211210
// TODO: Handle ARM
@@ -322,7 +321,7 @@ private static Type ConvertManagedTypeToIL2CPPType(Type managedType)
322321
if (directType == typeof(string) || directType.IsSubclassOf(typeof(Il2CppObjectBase)))
323322
return typeof(IntPtr*);
324323
}
325-
else if (managedType.IsSubclassOf(typeof(ValueType)) && !PlatformHelper.Is(Platform.Bits64))
324+
else if (managedType.IsSubclassOf(typeof(ValueType)) && !Environment.Is64BitProcess)
326325
{
327326
// Struct that's passed on the stack => handle as general struct
328327
uint align = 0;
@@ -369,7 +368,7 @@ private static void EmitConvertArgumentToManaged(ILGenerator il,
369368
il.Emit(OpCodes.Conv_I);
370369
// On x64, struct is always a pointer but it is a non-pointer on x86
371370
// We don't handle byref structs on x86 yet but we're yet to encounter those
372-
il.Emit(PlatformHelper.Is(Platform.Bits64) ? OpCodes.Ldarg : OpCodes.Ldarga_S, argIndex);
371+
il.Emit(Environment.Is64BitProcess ? OpCodes.Ldarg : OpCodes.Ldarga_S, argIndex);
373372
il.Emit(OpCodes.Call,
374373
AccessTools.Method(typeof(UnhollowerBaseLib.IL2CPP),
375374
nameof(UnhollowerBaseLib.IL2CPP.il2cpp_value_box)));

0 commit comments

Comments
 (0)