From 8c45728c1178ece7f352e36f1698b0fb922d2100 Mon Sep 17 00:00:00 2001 From: Meivyn <793322+Meivyn@users.noreply.github.com> Date: Wed, 17 May 2023 23:06:54 -0400 Subject: [PATCH] Do not virtualize compiler-generated stuff --- IPA.Injector/Virtualizer.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/IPA.Injector/Virtualizer.cs b/IPA.Injector/Virtualizer.cs index 16ae136b..6eeb9e3d 100644 --- a/IPA.Injector/Virtualizer.cs +++ b/IPA.Injector/Virtualizer.cs @@ -3,6 +3,7 @@ using Mono.Cecil.Rocks; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; namespace IPA.Injector @@ -69,11 +70,20 @@ namespace IPA.Injector } } + private TypeReference compilerGeneratedAttributeRef; private TypeReference inModreqRef; // private TypeReference outModreqRef; + private bool IsCompilerGenerated(Mono.Cecil.ICustomAttributeProvider customAttributeProvider) + { + compilerGeneratedAttributeRef ??= module.ImportReference(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)); + return customAttributeProvider.CustomAttributes.Any(ca => ca.AttributeType.FullName == compilerGeneratedAttributeRef.FullName); + } + private void VirtualizeType(TypeDefinition type) { + if (IsCompilerGenerated(type)) return; + if(type.IsSealed) { // Unseal @@ -108,7 +118,8 @@ namespace IPA.Injector && !method.IsConstructor && !method.IsSpecialName && !method.IsGenericInstance - && !method.HasOverrides) + && !method.HasOverrides + && !IsCompilerGenerated(method)) { if (!method.IsStatic) {