From e0fe7fa1b9562040ca15f3098d1c573e2a17e2b4 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 20 Jun 2020 21:11:03 +0200 Subject: [PATCH] CS: Add unsafe modifier to struct constructors where necessary (CS0214) --- Il2CppInspector.Common/Reflection/ConstructorInfo.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Il2CppInspector.Common/Reflection/ConstructorInfo.cs b/Il2CppInspector.Common/Reflection/ConstructorInfo.cs index 43c22fc..4cb9518 100644 --- a/Il2CppInspector.Common/Reflection/ConstructorInfo.cs +++ b/Il2CppInspector.Common/Reflection/ConstructorInfo.cs @@ -16,6 +16,12 @@ namespace Il2CppInspector.Reflection public static readonly string TypeConstructorName = ".cctor"; + // Struct construvctors must initialize all non-literal fields in the struct + // If any of them are of an unsafe type, the constructor must also be declared unsafe + public override bool RequiresUnsafeContext => base.RequiresUnsafeContext || + (!IsAbstract && DeclaringType.IsValueType && + DeclaringType.DeclaredFields.Any(f => !f.IsLiteral && f.IsStatic == IsStatic && f.RequiresUnsafeContext)); + public override MemberTypes MemberType => MemberTypes.Constructor; public ConstructorInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : base(pkg, methodIndex, declaringType) { }