diff --git a/Il2CppInterop.Generator/Extensions/AsmResolverExtensions.cs b/Il2CppInterop.Generator/Extensions/AsmResolverExtensions.cs index 4b39a9ab..7788790f 100644 --- a/Il2CppInterop.Generator/Extensions/AsmResolverExtensions.cs +++ b/Il2CppInterop.Generator/Extensions/AsmResolverExtensions.cs @@ -63,12 +63,11 @@ private static Parameter GetArgument(this ILProcessor instructions, int argument public static Parameter AddParameter(this MethodDefinition method, TypeSignature parameterSignature, string parameterName, ParameterAttributes parameterAttributes = default) { - var parameterDefinition = new ParameterDefinition((ushort)(method.Signature!.ParameterTypes.Count + 1), parameterName, parameterAttributes); - method.Signature.ParameterTypes.Add(parameterSignature); - method.ParameterDefinitions.Add(parameterDefinition); - - method.Parameters.PullUpdatesFromMethodSignature(); - return method.Parameters.Single(parameter => parameter.Name == parameterName && parameter.ParameterType == parameterSignature); + var parameter = method.AddParameter(parameterSignature); + var parameterDefinition = parameter.GetOrCreateDefinition(); + parameterDefinition.Name = parameterName; + parameterDefinition.Attributes = parameterAttributes; + return parameter; } public static Parameter AddParameter(this MethodDefinition method, TypeSignature parameterSignature) diff --git a/Il2CppInterop.Generator/Extensions/CustomAttributeEx.cs b/Il2CppInterop.Generator/Extensions/CustomAttributeEx.cs index 97709c7e..fba48706 100644 --- a/Il2CppInterop.Generator/Extensions/CustomAttributeEx.cs +++ b/Il2CppInterop.Generator/Extensions/CustomAttributeEx.cs @@ -1,5 +1,6 @@ using AsmResolver; using AsmResolver.DotNet; +using AsmResolver.DotNet.Signatures; namespace Il2CppInterop.Generator.Extensions; @@ -25,13 +26,18 @@ public static int ExtractFieldOffset(this IHasCustomAttribute originalField) return ExtractInt(originalField, "FieldOffsetAttribute", "Offset"); } + public static string? GetElementAsString(this CustomAttributeArgument argument) + { + return argument.Element as Utf8String ?? argument.Element as string; + } + private static string? Extract(this IHasCustomAttribute originalMethod, string attributeName, string parameterName) { var attribute = originalMethod.CustomAttributes.SingleOrDefault(it => it.Constructor?.DeclaringType?.Name == attributeName); var field = attribute?.Signature?.NamedArguments.SingleOrDefault(it => it.MemberName == parameterName); - return (Utf8String?)field?.Argument.Element; + return field?.Argument.GetElementAsString(); } private static long ExtractLong(this IHasCustomAttribute originalMethod, string attributeName, string parameterName) diff --git a/Il2CppInterop.Generator/Passes/Pass70GenerateProperties.cs b/Il2CppInterop.Generator/Passes/Pass70GenerateProperties.cs index 5c842be5..921075f4 100644 --- a/Il2CppInterop.Generator/Passes/Pass70GenerateProperties.cs +++ b/Il2CppInterop.Generator/Passes/Pass70GenerateProperties.cs @@ -44,7 +44,7 @@ public static void DoPass(RewriteGlobalContext context) string? defaultMemberName = null; var defaultMemberAttributeAttribute = type.CustomAttributes.FirstOrDefault(it => it.AttributeType()?.Name == "AttributeAttribute" && it.Signature!.NamedArguments.Any(it => - it.MemberName == "Name" && (Utf8String?)it.Argument.Element == nameof(DefaultMemberAttribute))); + it.MemberName == "Name" && it.Argument.GetElementAsString() == nameof(DefaultMemberAttribute))); if (defaultMemberAttributeAttribute != null) { defaultMemberName = "Item";