From 484bcce7d1b4c19dc4a0f06ec21ce11d8f6a7d04 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Tue, 28 Nov 2017 15:20:38 +0100 Subject: [PATCH] Use syntactic sugar for multicast delegates --- Il2CppDumper/Il2CppDumper.cs | 21 +++++++++++++++++++++ Il2CppInspector/Il2CppConstants.cs | 2 +- README.md | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Il2CppDumper/Il2CppDumper.cs b/Il2CppDumper/Il2CppDumper.cs index 87afcde..5f41462 100644 --- a/Il2CppDumper/Il2CppDumper.cs +++ b/Il2CppDumper/Il2CppDumper.cs @@ -46,6 +46,27 @@ namespace Il2CppInspector writer.Write("protected internal "); if (type.IsNestedFamANDAssem) writer.Write("[family and assembly] "); + + // Roll-up multicast delegates to use the 'delegate' syntactic sugar + if (type.IsClass && type.IsSealed && type.BaseType?.FullName == "System.MulticastDelegate") { + var del = type.DeclaredMethods.First(x => x.Name == "Invoke"); + writer.Write($"delegate {del.ReturnType.CSharpName} {type.Name}("); + + bool first = true; + foreach (var param in del.DeclaredParameters) { + if (!first) + writer.Write(", "); + first = false; + if (param.IsOptional) + writer.Write("optional "); + if (param.IsOut) + writer.Write("out "); + writer.Write($"{param.ParameterType.CSharpName} {param.Name}"); + } + writer.Write($"); // TypeDefIndex: {type.Index}; 0x{del.VirtualAddress:X8}\n"); + continue; + } + // An abstract sealed class is a static class if (type.IsAbstract && type.IsSealed) writer.Write("static "); diff --git a/Il2CppInspector/Il2CppConstants.cs b/Il2CppInspector/Il2CppConstants.cs index 5178dbb..98797b7 100644 --- a/Il2CppInspector/Il2CppConstants.cs +++ b/Il2CppInspector/Il2CppConstants.cs @@ -188,7 +188,7 @@ namespace Il2CppInspector "IntPtr", "UIntPtr", "None", - "delegate", + "Delegate", "object", "SZARRAY", // Processed separately "T", diff --git a/README.md b/README.md index 7fd8524..89766ae 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Extract types, methods, properties and fields from Unity IL2CPP binaries. * Supports ARMv7, ARMv7 Thumb T1 and x86 architectures regardless of file format * Supports metadata versions 21, 22, 23 and 24 * No manual reverse-engineering required; all data is calculated automatically -* Special language construct/syntax support for enumerations and events +* Syntax support for enumerations, events and delegates * **Il2CppInspector** re-usable class library for low-level access to IL2CPP binaries and metadata * **Il2CppReflector** re-usable class library for high-level .NET Reflection-style access to IL2CPP types and data as a tree model