From 41d232556030dff5e05a2e2470ad5fa34d968ce6 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 9 Nov 2019 22:32:32 +0100 Subject: [PATCH] Model: Handle C# method hiding ('new' keyword in method declarations) --- Il2CppInspector/Reflection/ConstructorInfo.cs | 3 +++ Il2CppInspector/Reflection/MethodBase.cs | 8 ++++++++ Il2CppInspector/Reflection/MethodInfo.cs | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Il2CppInspector/Reflection/ConstructorInfo.cs b/Il2CppInspector/Reflection/ConstructorInfo.cs index 771f5d5..7d12308 100644 --- a/Il2CppInspector/Reflection/ConstructorInfo.cs +++ b/Il2CppInspector/Reflection/ConstructorInfo.cs @@ -21,5 +21,8 @@ namespace Il2CppInspector.Reflection public ConstructorInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : base(pkg, methodIndex, declaringType) { } public override string ToString() => DeclaringType.Name + "(" + string.Join(", ", DeclaredParameters.Select(x => x.ParameterType.Name)) + ")"; + + public override string GetSignatureString() => Name + GetTypeParametersString() + + "(" + string.Join(",", DeclaredParameters.Select(x => x.GetSignatureString())) + ")"; } } \ No newline at end of file diff --git a/Il2CppInspector/Reflection/MethodBase.cs b/Il2CppInspector/Reflection/MethodBase.cs index 0114d95..219c54c 100644 --- a/Il2CppInspector/Reflection/MethodBase.cs +++ b/Il2CppInspector/Reflection/MethodBase.cs @@ -149,6 +149,12 @@ namespace Il2CppInspector.Reflection if ((Attributes & MethodAttributes.PinvokeImpl) != 0) modifiers.Append("extern "); + // Method hiding + if ((DeclaringType.BaseType?.GetAllMethods().Any(m => m.GetSignatureString() == GetSignatureString() && m.IsHideBySig) ?? false) + && (((Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.ReuseSlot && !IsVirtual) + || (Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot)) + modifiers.Append($"new "); + if (Name == "op_Implicit") modifiers.Append("implicit "); if (Name == "op_Explicit") @@ -164,6 +170,8 @@ namespace Il2CppInspector.Reflection public string GetTypeParametersString() => GenericTypeParameters == null? "" : "<" + string.Join(", ", GenericTypeParameters.Select(p => p.CSharpName)) + ">"; + public abstract string GetSignatureString(); + // List of operator overload metadata names // https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/operator-overloads public static Dictionary OperatorMethodNames = new Dictionary { diff --git a/Il2CppInspector/Reflection/MethodInfo.cs b/Il2CppInspector/Reflection/MethodInfo.cs index 37efd53..e59da54 100644 --- a/Il2CppInspector/Reflection/MethodInfo.cs +++ b/Il2CppInspector/Reflection/MethodInfo.cs @@ -31,7 +31,7 @@ namespace Il2CppInspector.Reflection // TODO: Generic arguments (and on ConstructorInfo) public override string ToString() => ReturnType.Name + " " + Name + "(" + string.Join(", ", DeclaredParameters.Select(x => x.ParameterType.Name)) + ")"; - public string GetSignatureString() => ReturnParameter.GetSignatureString() + " " + Name + GetTypeParametersString() + public override string GetSignatureString() => ReturnParameter.GetSignatureString() + " " + Name + GetTypeParametersString() + "(" + string.Join(",", DeclaredParameters.Select(x => x.GetSignatureString())) + ")"; } } \ No newline at end of file