Skip to content

Commit cbae410

Browse files
committed
IL2CPPDetourMethodPatcher: Revert to original argument handling in x64
Because on x64 the calling convention forces all structs to be passed as pointers, there is no need to handle it differently
1 parent 82538d8 commit cbae410

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
using System.Reflection;
55
using System.Reflection.Emit;
66
using System.Runtime.InteropServices;
7+
using System.Text;
78
using BepInEx.Logging;
89
using HarmonyLib;
910
using HarmonyLib.Public.Patching;
11+
using Mono.Cecil.Cil;
1012
using MonoMod.Cil;
1113
using MonoMod.RuntimeDetour;
1214
using MonoMod.Utils;
1315
using UnhollowerBaseLib;
1416
using UnhollowerBaseLib.Runtime;
1517
using UnhollowerBaseLib.Runtime.VersionSpecific.MethodInfo;
18+
using OpCode = System.Reflection.Emit.OpCode;
19+
using OpCodes = System.Reflection.Emit.OpCodes;
1620
using ValueType = Il2CppSystem.ValueType;
1721
using Void = Il2CppSystem.Void;
1822

@@ -289,9 +293,9 @@ private static Type ConvertManagedTypeToIL2CPPType(Type managedType)
289293
if (directType == typeof(string) || directType.IsSubclassOf(typeof(Il2CppObjectBase)))
290294
return typeof(IntPtr*);
291295
}
292-
else if (managedType.IsSubclassOf(typeof(ValueType))
293-
) // Struct that's passed on the stack => handle as general struct
296+
else if (managedType.IsSubclassOf(typeof(ValueType)) && !PlatformHelper.Is(Platform.Bits64))
294297
{
298+
// Struct that's passed on the stack => handle as general struct
295299
uint align = 0;
296300
var fixedSize =
297301
UnhollowerBaseLib.IL2CPP.il2cpp_class_value_size(Il2CppTypeToClassPointer(managedType), ref align);
@@ -329,10 +333,10 @@ private static void EmitConvertArgumentToManaged(ILGenerator il,
329333
{
330334
variable = null;
331335

332-
// Box struct into object first before conversion
333-
// This will likely incur struct copying down the line, but it shouldn't be a massive loss
334-
if (managedParamType.IsSubclassOf(typeof(ValueType)))
336+
if (managedParamType.IsSubclassOf(typeof(ValueType)) && !PlatformHelper.Is(Platform.Bits64))
335337
{
338+
// Box struct into object first before conversion
339+
// This will likely incur struct copying down the line, but it shouldn't be a massive loss
336340
il.Emit(OpCodes.Ldc_I8, Il2CppTypeToClassPointer(managedParamType).ToInt64());
337341
il.Emit(OpCodes.Conv_I);
338342
il.Emit(OpCodes.Ldarga_S, argIndex);

0 commit comments

Comments
 (0)