Example #1
0
        internal static object?GetDefaultValue(int dataIndex, int typeIndex, Il2CppMetadata metadata, PE.PE theDll)
        {
            var pointer = metadata.GetDefaultValueFromIndex(dataIndex);

            if (pointer <= 0)
            {
                return(null);
            }

            var defaultValueType = theDll.types[typeIndex];

            metadata.Position = pointer;
            switch (defaultValueType.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN:
                return(metadata.ReadBoolean());

            case Il2CppTypeEnum.IL2CPP_TYPE_U1:
                return(metadata.ReadByte());

            case Il2CppTypeEnum.IL2CPP_TYPE_I1:
                return(metadata.ReadSByte());

            case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
                return(BitConverter.ToChar(metadata.ReadBytes(2), 0));

            case Il2CppTypeEnum.IL2CPP_TYPE_U2:
                return(metadata.ReadUInt16());

            case Il2CppTypeEnum.IL2CPP_TYPE_I2:
                return(metadata.ReadInt16());

            case Il2CppTypeEnum.IL2CPP_TYPE_U4:
                return(metadata.ReadUInt32());

            case Il2CppTypeEnum.IL2CPP_TYPE_I4:
                return(metadata.ReadInt32());

            case Il2CppTypeEnum.IL2CPP_TYPE_U8:
                return(metadata.ReadUInt64());

            case Il2CppTypeEnum.IL2CPP_TYPE_I8:
                return(metadata.ReadInt64());

            case Il2CppTypeEnum.IL2CPP_TYPE_R4:
                return(metadata.ReadSingle());

            case Il2CppTypeEnum.IL2CPP_TYPE_R8:
                return(metadata.ReadDouble());

            case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
                var len = metadata.ReadInt32();
                return(Encoding.UTF8.GetString(metadata.ReadBytes(len)));

            default:
                return(null);
            }
        }