public string GetGenericTypeParams(Il2CppGenericInst genericInst) { var typeNames = new List <string>(); var pointers = il2Cpp.ReadPointers(genericInst.type_argv, genericInst.type_argc); for (uint i = 0; i < genericInst.type_argc; ++i) { var oriType = il2Cpp.GetIl2CppType(pointers[i]); typeNames.Add(GetTypeName(oriType)); } return($"<{string.Join(", ", typeNames)}>"); }
private TypeReference GetTypeReference(MemberReference memberReference, Il2CppType il2CppType) { var moduleDefinition = memberReference.Module; switch (il2CppType.type) { case Il2CppTypeEnum.IL2CPP_TYPE_OBJECT: return(moduleDefinition.ImportReference(typeof(object))); case Il2CppTypeEnum.IL2CPP_TYPE_VOID: return(moduleDefinition.ImportReference(typeof(void))); case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN: return(moduleDefinition.ImportReference(typeof(bool))); case Il2CppTypeEnum.IL2CPP_TYPE_CHAR: return(moduleDefinition.ImportReference(typeof(char))); case Il2CppTypeEnum.IL2CPP_TYPE_I1: return(moduleDefinition.ImportReference(typeof(sbyte))); case Il2CppTypeEnum.IL2CPP_TYPE_U1: return(moduleDefinition.ImportReference(typeof(byte))); case Il2CppTypeEnum.IL2CPP_TYPE_I2: return(moduleDefinition.ImportReference(typeof(short))); case Il2CppTypeEnum.IL2CPP_TYPE_U2: return(moduleDefinition.ImportReference(typeof(ushort))); case Il2CppTypeEnum.IL2CPP_TYPE_I4: return(moduleDefinition.ImportReference(typeof(int))); case Il2CppTypeEnum.IL2CPP_TYPE_U4: return(moduleDefinition.ImportReference(typeof(uint))); case Il2CppTypeEnum.IL2CPP_TYPE_I: return(moduleDefinition.ImportReference(typeof(IntPtr))); case Il2CppTypeEnum.IL2CPP_TYPE_U: return(moduleDefinition.ImportReference(typeof(UIntPtr))); case Il2CppTypeEnum.IL2CPP_TYPE_I8: return(moduleDefinition.ImportReference(typeof(long))); case Il2CppTypeEnum.IL2CPP_TYPE_U8: return(moduleDefinition.ImportReference(typeof(ulong))); case Il2CppTypeEnum.IL2CPP_TYPE_R4: return(moduleDefinition.ImportReference(typeof(float))); case Il2CppTypeEnum.IL2CPP_TYPE_R8: return(moduleDefinition.ImportReference(typeof(double))); case Il2CppTypeEnum.IL2CPP_TYPE_STRING: return(moduleDefinition.ImportReference(typeof(string))); case Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF: return(moduleDefinition.ImportReference(typeof(TypedReference))); case Il2CppTypeEnum.IL2CPP_TYPE_CLASS: case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE: { var typeDefinition = typeDefinitionDic[il2CppType.data.klassIndex]; return(moduleDefinition.ImportReference(typeDefinition)); } case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY: { var arrayType = il2cpp.MapVATR <Il2CppArrayType>(il2CppType.data.array); var oriType = il2cpp.GetIl2CppType(arrayType.etype); return(new ArrayType(GetTypeReference(memberReference, oriType), arrayType.rank)); } case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST: { var genericClass = il2cpp.MapVATR <Il2CppGenericClass>(il2CppType.data.generic_class); var typeDefinition = typeDefinitionDic[genericClass.typeDefinitionIndex]; var genericInstanceType = new GenericInstanceType(moduleDefinition.ImportReference(typeDefinition)); var genericInst = il2cpp.MapVATR <Il2CppGenericInst>(genericClass.context.class_inst); var pointers = il2cpp.ReadPointers(genericInst.type_argv, genericInst.type_argc); foreach (var pointer in pointers) { var oriType = il2cpp.GetIl2CppType(pointer); genericInstanceType.GenericArguments.Add(GetTypeReference(memberReference, oriType)); } return(genericInstanceType); } case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY: { var oriType = il2cpp.GetIl2CppType(il2CppType.data.type); return(new ArrayType(GetTypeReference(memberReference, oriType))); } case Il2CppTypeEnum.IL2CPP_TYPE_VAR: { if (genericParameterDic.TryGetValue(il2CppType.data.genericParameterIndex, out var genericParameter)) { return(genericParameter); } var param = metadata.genericParameters[il2CppType.data.genericParameterIndex]; var genericName = metadata.GetStringFromIndex(param.nameIndex); if (memberReference is MethodDefinition methodDefinition) { genericParameter = new GenericParameter(genericName, methodDefinition.DeclaringType); methodDefinition.DeclaringType.GenericParameters.Add(genericParameter); genericParameterDic.Add(il2CppType.data.genericParameterIndex, genericParameter); return(genericParameter); } var typeDefinition = (TypeDefinition)memberReference; genericParameter = new GenericParameter(genericName, typeDefinition); typeDefinition.GenericParameters.Add(genericParameter); genericParameterDic.Add(il2CppType.data.genericParameterIndex, genericParameter); return(genericParameter); } case Il2CppTypeEnum.IL2CPP_TYPE_MVAR: { if (genericParameterDic.TryGetValue(il2CppType.data.genericParameterIndex, out var genericParameter)) { return(genericParameter); } var methodDefinition = (MethodDefinition)memberReference; var param = metadata.genericParameters[il2CppType.data.genericParameterIndex]; var genericName = metadata.GetStringFromIndex(param.nameIndex); genericParameter = new GenericParameter(genericName, methodDefinition); methodDefinition.GenericParameters.Add(genericParameter); genericParameterDic.Add(il2CppType.data.genericParameterIndex, genericParameter); return(genericParameter); } case Il2CppTypeEnum.IL2CPP_TYPE_PTR: { var oriType = il2cpp.GetIl2CppType(il2CppType.data.type); return(new PointerType(GetTypeReference(memberReference, oriType))); } default: return(moduleDefinition.ImportReference(typeof(object))); } }