From ec789f4f6adc4b5db88a72c10a501fac026dd33a Mon Sep 17 00:00:00 2001 From: Sam Byass Date: Thu, 11 Jan 2024 15:57:35 +0000 Subject: [PATCH] Core: Cleanup fix for byref types --- Cpp2IL.Core/Utils/Il2CppTypeToContext.cs | 35 +++++++++++------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Cpp2IL.Core/Utils/Il2CppTypeToContext.cs b/Cpp2IL.Core/Utils/Il2CppTypeToContext.cs index 3db06cf7..b84e7653 100644 --- a/Cpp2IL.Core/Utils/Il2CppTypeToContext.cs +++ b/Cpp2IL.Core/Utils/Il2CppTypeToContext.cs @@ -39,27 +39,24 @@ private static TypeAnalysisContext GetPrimitive(this SystemTypesContext context, { if (type == null) return null; + + TypeAnalysisContext ret; if (type.Type.IsIl2CppPrimitive()) - return context.AppContext.SystemTypes.GetPrimitive(type.Type); - - if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_CLASS or Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE) - { - var typeDefContext = context.AppContext.ResolveContextForType(type.AsClass()) ?? throw new($"Could not resolve type context for type {type.AsClass().FullName}"); - - if (type.Byref == 1) - // Byref types need to be wrapped - return typeDefContext.MakeByReferenceType(); - - return typeDefContext; - } + ret = context.AppContext.SystemTypes.GetPrimitive(type.Type); + else if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_CLASS or Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE) + ret = context.AppContext.ResolveContextForType(type.AsClass()) ?? throw new($"Could not resolve type context for type {type.AsClass().FullName}"); + else if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST) + ret = new GenericInstanceTypeAnalysisContext(type, context); + else if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_BYREF or Il2CppTypeEnum.IL2CPP_TYPE_PTR or Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY or Il2CppTypeEnum.IL2CPP_TYPE_ARRAY) + ret = WrappedTypeAnalysisContext.Create(type, context); + else + ret = new GenericParameterTypeAnalysisContext(type, context); - if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST) - return new GenericInstanceTypeAnalysisContext(type, context); - - if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_BYREF or Il2CppTypeEnum.IL2CPP_TYPE_PTR or Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY or Il2CppTypeEnum.IL2CPP_TYPE_ARRAY) - return WrappedTypeAnalysisContext.Create(type, context); - - return new GenericParameterTypeAnalysisContext(type, context); + if (type.Byref == 1) + //Byref types need to be wrapped in a byref context so that we don't have incorrect method signatures. + ret = ret.MakeByReferenceType(); + + return ret; } }