From 99a7e2e8cbe8109366d8e2a490fc18ee959e4a85 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Fri, 14 Aug 2020 03:33:41 +0200 Subject: [PATCH] C#: Output async keyword for async methods (and suppress AsyncStateMachine) --- Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs | 4 +++- Il2CppInspector.Common/Reflection/MethodBase.cs | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs b/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs index fefa81e..a3f83aa 100644 --- a/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs +++ b/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs @@ -35,6 +35,7 @@ namespace Il2CppInspector.Outputs private const string CGAttribute = "System.Runtime.CompilerServices.CompilerGeneratedAttribute"; private const string FBAttribute = "System.Runtime.CompilerServices.FixedBufferAttribute"; private const string ExtAttribute = "System.Runtime.CompilerServices.ExtensionAttribute"; + private const string AsyncAttribute = "System.Runtime.CompilerServices.AsyncStateMachineAttribute"; private const string DMAttribute = "System.Reflection.DefaultMemberAttribute"; // Assembly attributes we have already emitted @@ -621,7 +622,8 @@ namespace Il2CppInspector.Outputs var writer = new StringBuilder(); // Attributes - writer.Append(method.CustomAttributes.Where(a => a.AttributeType.FullName != ExtAttribute).OrderBy(a => a.AttributeType.Name) + writer.Append(method.CustomAttributes.Where(a => a.AttributeType.FullName != ExtAttribute && a.AttributeType.FullName != AsyncAttribute) + .OrderBy(a => a.AttributeType.Name) .ToString(scope, prefix + "\t", emitPointer: !SuppressMetadata, mustCompile: MustCompile)); // IL2CPP doesn't seem to retain return type attributes diff --git a/Il2CppInspector.Common/Reflection/MethodBase.cs b/Il2CppInspector.Common/Reflection/MethodBase.cs index aad0a36..d2c95db 100644 --- a/Il2CppInspector.Common/Reflection/MethodBase.cs +++ b/Il2CppInspector.Common/Reflection/MethodBase.cs @@ -1,5 +1,5 @@ /* - Copyright 2017-2020 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com + Copyright 2017-2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty Copyright 2020 Robert Xiao - https://robertxiao.ca All rights reserved. @@ -285,6 +285,10 @@ namespace Il2CppInspector.Reflection if (Name == "op_Explicit") modifiers.Append("explicit "); + // Async depends on a compiler-generated attribute + if (GetCustomAttributes("System.Runtime.CompilerServices.AsyncStateMachineAttribute").Any()) + modifiers.Append("async "); + // Will include a trailing space return modifiers.ToString(); }