Skip to content

Commit

Permalink
IL2CPPDetourMethodPatcher: Revert to original argument handling in x64
Browse files Browse the repository at this point in the history
Because on x64 the calling convention forces all structs to be passed as pointers, there is no need to handle it differently
  • Loading branch information
ghorsington committed Jan 1, 2022
1 parent 82538d8 commit cbae410
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Text;
using BepInEx.Logging;
using HarmonyLib;
using HarmonyLib.Public.Patching;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using MonoMod.Utils;
using UnhollowerBaseLib;
using UnhollowerBaseLib.Runtime;
using UnhollowerBaseLib.Runtime.VersionSpecific.MethodInfo;
using OpCode = System.Reflection.Emit.OpCode;
using OpCodes = System.Reflection.Emit.OpCodes;
using ValueType = Il2CppSystem.ValueType;
using Void = Il2CppSystem.Void;

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

// Box struct into object first before conversion
// This will likely incur struct copying down the line, but it shouldn't be a massive loss
if (managedParamType.IsSubclassOf(typeof(ValueType)))
if (managedParamType.IsSubclassOf(typeof(ValueType)) && !PlatformHelper.Is(Platform.Bits64))
{
// Box struct into object first before conversion
// This will likely incur struct copying down the line, but it shouldn't be a massive loss
il.Emit(OpCodes.Ldc_I8, Il2CppTypeToClassPointer(managedParamType).ToInt64());
il.Emit(OpCodes.Conv_I);
il.Emit(OpCodes.Ldarga_S, argIndex);
Expand Down

0 comments on commit cbae410

Please sign in to comment.