Skip to content

Commit

Permalink
Core: Cleanup fix for byref types
Browse files Browse the repository at this point in the history
  • Loading branch information
SamboyCoding committed Jan 11, 2024
1 parent 688f307 commit ec789f4
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions Cpp2IL.Core/Utils/Il2CppTypeToContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit ec789f4

Please sign in to comment.