Skip to content

Commit ec789f4

Browse files
committed
Core: Cleanup fix for byref types
1 parent 688f307 commit ec789f4

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

Cpp2IL.Core/Utils/Il2CppTypeToContext.cs

+16-19
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,24 @@ private static TypeAnalysisContext GetPrimitive(this SystemTypesContext context,
3939
{
4040
if (type == null)
4141
return null;
42+
43+
TypeAnalysisContext ret;
4244

4345
if (type.Type.IsIl2CppPrimitive())
44-
return context.AppContext.SystemTypes.GetPrimitive(type.Type);
45-
46-
if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_CLASS or Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE)
47-
{
48-
var typeDefContext = context.AppContext.ResolveContextForType(type.AsClass()) ?? throw new($"Could not resolve type context for type {type.AsClass().FullName}");
49-
50-
if (type.Byref == 1)
51-
// Byref types need to be wrapped
52-
return typeDefContext.MakeByReferenceType();
53-
54-
return typeDefContext;
55-
}
46+
ret = context.AppContext.SystemTypes.GetPrimitive(type.Type);
47+
else if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_CLASS or Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE)
48+
ret = context.AppContext.ResolveContextForType(type.AsClass()) ?? throw new($"Could not resolve type context for type {type.AsClass().FullName}");
49+
else if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST)
50+
ret = new GenericInstanceTypeAnalysisContext(type, context);
51+
else if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_BYREF or Il2CppTypeEnum.IL2CPP_TYPE_PTR or Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY or Il2CppTypeEnum.IL2CPP_TYPE_ARRAY)
52+
ret = WrappedTypeAnalysisContext.Create(type, context);
53+
else
54+
ret = new GenericParameterTypeAnalysisContext(type, context);
5655

57-
if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST)
58-
return new GenericInstanceTypeAnalysisContext(type, context);
59-
60-
if (type.Type is Il2CppTypeEnum.IL2CPP_TYPE_BYREF or Il2CppTypeEnum.IL2CPP_TYPE_PTR or Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY or Il2CppTypeEnum.IL2CPP_TYPE_ARRAY)
61-
return WrappedTypeAnalysisContext.Create(type, context);
62-
63-
return new GenericParameterTypeAnalysisContext(type, context);
56+
if (type.Byref == 1)
57+
//Byref types need to be wrapped in a byref context so that we don't have incorrect method signatures.
58+
ret = ret.MakeByReferenceType();
59+
60+
return ret;
6461
}
6562
}

0 commit comments

Comments
 (0)