From df33064275108ccdf6b0ed1f797ff5dbd3a25108 Mon Sep 17 00:00:00 2001 From: Kasuromi <29818914+Kasuromi@users.noreply.github.com> Date: Sat, 14 Jan 2023 13:03:10 +0200 Subject: [PATCH] Use method signature for delegate type --- Il2CppInterop.Runtime/DelegateSupport.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Il2CppInterop.Runtime/DelegateSupport.cs b/Il2CppInterop.Runtime/DelegateSupport.cs index 864138bd..124f8d96 100644 --- a/Il2CppInterop.Runtime/DelegateSupport.cs +++ b/Il2CppInterop.Runtime/DelegateSupport.cs @@ -31,15 +31,15 @@ internal static Type GetOrCreateDelegateType(MethodSignature signature, MethodIn { return ourDelegateTypes.GetOrAdd(signature, (signature, managedMethodInner) => - CreateDelegateType(managedMethodInner, signature.HasThis, signature.ConstructedFromNative), + CreateDelegateType(managedMethodInner, signature), managedMethod); } - private static Type CreateDelegateType(MethodInfo managedMethodInner, bool addIntPtrForThis, bool addNamingDisambig) + private static Type CreateDelegateType(MethodInfo managedMethodInner, MethodSignature signature) { var newType = ModuleBuilder.DefineType( - "Il2CppToManagedDelegate_" + ExtractSignature(managedMethodInner) + (addIntPtrForThis ? "HasThis" : "") + - (addNamingDisambig ? "FromNative" : ""), TypeAttributes.Sealed | TypeAttributes.Public, + "Il2CppToManagedDelegate_" + managedMethodInner.DeclaringType.FullName + "_" + signature.GetHashCode() + (signature.HasThis ? "HasThis" : "") + + (signature.ConstructedFromNative ? "FromNative" : ""), TypeAttributes.Sealed | TypeAttributes.Public, typeof(MulticastDelegate)); newType.SetCustomAttribute(new CustomAttributeBuilder( typeof(UnmanagedFunctionPointerAttribute).GetConstructor(new[] { typeof(CallingConvention) })!, @@ -50,11 +50,11 @@ private static Type CreateDelegateType(MethodInfo managedMethodInner, bool addIn MethodAttributes.Public, CallingConventions.HasThis, new[] { typeof(object), typeof(IntPtr) }); ctor.SetImplementationFlags(MethodImplAttributes.CodeTypeMask); - var parameterOffset = addIntPtrForThis ? 1 : 0; + var parameterOffset = signature.HasThis ? 1 : 0; var managedParameters = managedMethodInner.GetParameters(); var parameterTypes = new Type[managedParameters.Length + 1 + parameterOffset]; - if (addIntPtrForThis) + if (signature.HasThis) parameterTypes[0] = typeof(IntPtr); parameterTypes[parameterTypes.Length - 1] = typeof(Il2CppMethodInfo*);