添加泛型约束

This commit is contained in:
Perfare 2019-11-13 22:21:27 +08:00
parent b9fc241260
commit 0378425267
2 changed files with 8 additions and 0 deletions

View file

@ -615,8 +615,14 @@ namespace Il2CppDumper
var param = metadata.genericParameters[genericParameterIndex]; var param = metadata.genericParameters[genericParameterIndex];
var genericName = metadata.GetStringFromIndex(param.nameIndex); var genericName = metadata.GetStringFromIndex(param.nameIndex);
var genericParameter = new GenericParameter(genericName, iGenericParameterProvider); var genericParameter = new GenericParameter(genericName, iGenericParameterProvider);
genericParameter.Attributes = (GenericParameterAttributes)param.flags;
iGenericParameterProvider.GenericParameters.Add(genericParameter); iGenericParameterProvider.GenericParameters.Add(genericParameter);
genericParameterDic.Add(genericParameterIndex, genericParameter); genericParameterDic.Add(genericParameterIndex, genericParameter);
for (int i = 0; i < param.constraintsCount; ++i)
{
var il2CppType = il2cpp.types[metadata.constraintIndices[param.constraintsStart + i]];
genericParameter.Constraints.Add(new GenericParameterConstraint(GetTypeReference((MemberReference)iGenericParameterProvider, il2CppType)));
}
return genericParameter; return genericParameter;
} }
} }

View file

@ -30,6 +30,7 @@ namespace Il2CppDumper
public Il2CppGenericContainer[] genericContainers; public Il2CppGenericContainer[] genericContainers;
public Il2CppFieldRef[] fieldRefs; public Il2CppFieldRef[] fieldRefs;
public Il2CppGenericParameter[] genericParameters; public Il2CppGenericParameter[] genericParameters;
public int[] constraintIndices;
public Metadata(Stream stream, float version) : base(stream) public Metadata(Stream stream, float version) : base(stream)
{ {
@ -65,6 +66,7 @@ namespace Il2CppDumper
eventDefs = ReadMetadataClassArray<Il2CppEventDefinition>(metadataHeader.eventsOffset, metadataHeader.eventsCount); eventDefs = ReadMetadataClassArray<Il2CppEventDefinition>(metadataHeader.eventsOffset, metadataHeader.eventsCount);
genericContainers = ReadMetadataClassArray<Il2CppGenericContainer>(metadataHeader.genericContainersOffset, metadataHeader.genericContainersCount); genericContainers = ReadMetadataClassArray<Il2CppGenericContainer>(metadataHeader.genericContainersOffset, metadataHeader.genericContainersCount);
genericParameters = ReadMetadataClassArray<Il2CppGenericParameter>(metadataHeader.genericParametersOffset, metadataHeader.genericParametersCount); genericParameters = ReadMetadataClassArray<Il2CppGenericParameter>(metadataHeader.genericParametersOffset, metadataHeader.genericParametersCount);
constraintIndices = ReadClassArray<int>(metadataHeader.genericParameterConstraintsOffset, metadataHeader.genericParameterConstraintsCount / 4);
if (version > 16) if (version > 16)
{ {
stringLiterals = ReadMetadataClassArray<Il2CppStringLiteral>(metadataHeader.stringLiteralOffset, metadataHeader.stringLiteralCount); stringLiterals = ReadMetadataClassArray<Il2CppStringLiteral>(metadataHeader.stringLiteralOffset, metadataHeader.stringLiteralCount);