Skip to content

Commit

Permalink
Use method signature for delegate type
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasuromi committed Jan 14, 2023
1 parent 384d4ea commit df33064
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Il2CppInterop.Runtime/DelegateSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) })!,
Expand All @@ -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*);
Expand Down

0 comments on commit df33064

Please sign in to comment.