Skip to content

Commit

Permalink
Il2CppInteropUtils support for generic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasuromi committed Mar 4, 2023
1 parent 20bc6ba commit 24f29f6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Il2CppInterop.Common/Il2CppInteropUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ public static class Il2CppInteropUtils
foreach (var (opCode, opArg) in MiniIlParser.Decode(body.GetILAsByteArray()))
{
if (opCode != OpCodes.Ldsfld) continue;
var fieldInfo = methodModule.ResolveField((int)opArg);
if (fieldInfo?.FieldType != typeof(IntPtr) || !fieldInfo.Name.StartsWith(prefix)) continue;
return fieldInfo;

var fieldInfo = methodModule.ResolveField((int)opArg, method.DeclaringType.GenericTypeArguments, method.GetGenericArguments());
if (fieldInfo?.FieldType != typeof(IntPtr)) continue;

if (fieldInfo.Name.StartsWith(prefix)) return fieldInfo;

// Resolve generic method info pointer fields
if (method.IsGenericMethod && fieldInfo.DeclaringType.Name.StartsWith("MethodInfoStoreGeneric_") && fieldInfo.Name == "Pointer") return fieldInfo;
}

return null;
Expand Down

0 comments on commit 24f29f6

Please sign in to comment.